~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/dg/replacenexttextcmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1997, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "gshape.h"
 
23
#include "diagram.h"
 
24
#include "replacenexttextcmd.h"
 
25
 
 
26
ReplaceNextTextCmd::ReplaceNextTextCmd(ShapeView *v,
 
27
        const string *p, const string *o, bool c, bool s, bool n): 
 
28
        ReplaceTextCmd(v, p, o, c, s, n) {}
 
29
 
 
30
void ReplaceNextTextCmd::Execute() {
 
31
        if (*replace == *pattern) {
 
32
                MessageDialog *d = new MessageDialog(
 
33
                        GetMainWindow()->GetWidget(), 
 
34
                        MessageDialog::ERROR);
 
35
                d->Show("Error", 
 
36
                        "replace next: find and replace text are identical");
 
37
                GetMainWindow()->SetStatus(
 
38
                        "aborted: identical find and replace");
 
39
                Abort();
 
40
                return;
 
41
        }
 
42
        int i = view->GetCurrentShapeNr();
 
43
        if (i == 0)
 
44
                i = view->NrOfShapes()-1;
 
45
        else
 
46
                i--;
 
47
        view->SetCurrentShapeNr(i);
 
48
        GShape *shape = view->GetNextShape(pattern, 
 
49
                                        caseSensitive, substring, nameOnly);
 
50
        if (shape) {
 
51
                view->DeselectAll();
 
52
                int r = 0;
 
53
                if (nameOnly) {
 
54
                        if (shape->HasNameString(pattern, caseSensitive, 
 
55
                                                 substring)) {
 
56
                                TextShape *ts;
 
57
                                if (shape->IsTextShape())
 
58
                                        ts = (TextShape *)shape;
 
59
                                else
 
60
                                        ts = ((GShape *)shape)->GetName();
 
61
                                textShapes->add(ts);
 
62
                                Point *pt = new Point(shape->GetWidth(), 
 
63
                                                        shape->GetHeight()); 
 
64
                                oldSizes->add(pt);
 
65
                                const string *name = ts->GetString();
 
66
                                string copy = *name;
 
67
                                oldStrings->add(new string(copy));
 
68
                                if (substring || *pattern == copy) {
 
69
                                        r = copy.replace(*pattern, *replace, 
 
70
                                                         caseSensitive);
 
71
                                        if (copy != *name) 
 
72
                                                GetDiagram()->
 
73
                                                        SetText(ts, &copy);
 
74
                                }
 
75
                        }
 
76
                }
 
77
                else {
 
78
                        List<TextShape *> tshapes;
 
79
                        if (shape->HasString(pattern, caseSensitive, 
 
80
                                                substring, &tshapes)) {
 
81
                                for (tshapes.first(); !tshapes.done(); 
 
82
                                        tshapes.next()) {
 
83
                                        TextShape *ts = tshapes.cur();
 
84
                                        textShapes->add(ts);
 
85
                                        Point *pt = new Point(shape->GetWidth(),
 
86
                                                        shape->GetHeight()); 
 
87
                                        oldSizes->add(pt);
 
88
                                        oldStrings->add(new 
 
89
                                                string(*(ts->GetString())));
 
90
                                        const string *name = ts->GetString();
 
91
                                        string copy = *name;
 
92
                                        if (substring || *pattern == copy) {
 
93
                                                r += copy.replace(*pattern, 
 
94
                                                        *replace, 
 
95
                                                        caseSensitive);
 
96
                                                if (copy != *name)
 
97
                                                        GetDiagram()->
 
98
                                                            SetText(ts, &copy);
 
99
                                        }
 
100
                                }
 
101
                        }
 
102
                }
 
103
                view->SelectShape(shape);
 
104
                string txt = "replace next: pattern found, made "; 
 
105
                txt += r;
 
106
                txt += " replacement";
 
107
                txt += ((r==1?"":"s"));
 
108
                GetMainWindow()->SetStatus(&txt);
 
109
                const Point *pt = shape->GetPosition();
 
110
                double x = Scale(pt->x);
 
111
                double y = Scale(pt->y);
 
112
                GetMainWindow()->ShowPosition(int(0.5 + x), int(0.5 + y));
 
113
                GetDocument()->IncChanges();
 
114
                SetCmdDone(True);
 
115
        }
 
116
        else
 
117
                GetMainWindow()->SetStatus("replace next: pattern not found");
 
118
}