1
////////////////////////////////////////////////////////////////////////////////
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).
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.
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.
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
21
////////////////////////////////////////////////////////////////////////////////
24
#include "replacenexttextcmd.h"
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) {}
30
void ReplaceNextTextCmd::Execute() {
31
if (*replace == *pattern) {
32
MessageDialog *d = new MessageDialog(
33
GetMainWindow()->GetWidget(),
34
MessageDialog::ERROR);
36
"replace next: find and replace text are identical");
37
GetMainWindow()->SetStatus(
38
"aborted: identical find and replace");
42
int i = view->GetCurrentShapeNr();
44
i = view->NrOfShapes()-1;
47
view->SetCurrentShapeNr(i);
48
GShape *shape = view->GetNextShape(pattern,
49
caseSensitive, substring, nameOnly);
54
if (shape->HasNameString(pattern, caseSensitive,
57
if (shape->IsTextShape())
58
ts = (TextShape *)shape;
60
ts = ((GShape *)shape)->GetName();
62
Point *pt = new Point(shape->GetWidth(),
65
const string *name = ts->GetString();
67
oldStrings->add(new string(copy));
68
if (substring || *pattern == copy) {
69
r = copy.replace(*pattern, *replace,
78
List<TextShape *> tshapes;
79
if (shape->HasString(pattern, caseSensitive,
80
substring, &tshapes)) {
81
for (tshapes.first(); !tshapes.done();
83
TextShape *ts = tshapes.cur();
85
Point *pt = new Point(shape->GetWidth(),
89
string(*(ts->GetString())));
90
const string *name = ts->GetString();
92
if (substring || *pattern == copy) {
93
r += copy.replace(*pattern,
103
view->SelectShape(shape);
104
string txt = "replace next: pattern found, made ";
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();
117
GetMainWindow()->SetStatus("replace next: pattern not found");