Subversion Repositories fastphp

Rev

Rev 49 | Rev 83 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 49 Rev 67
Line 49... Line 49...
49
      TFindDirection = (sdDefault, sdForwards, sdBackwards);
49
      TFindDirection = (sdDefault, sdForwards, sdBackwards);
50
 
50
 
51
    procedure OnFind(Sender: TObject); virtual;
51
    procedure OnFind(Sender: TObject); virtual;
52
    procedure OnReplace(Sender: TObject); virtual;
52
    procedure OnReplace(Sender: TObject); virtual;
53
 
53
 
54
    procedure DoFind(dialog: TFindDialog; direction: TFindDirection);
54
    procedure DoFind(dialog: TFindDialog; direction: TFindDirection); overload;
55
    procedure DoReplace(dialog: TReplaceDialog; direction: TFindDirection);
55
    procedure DoReplace(dialog: TReplaceDialog; direction: TFindDirection);
56
 
56
 
57
    function GetDirection(dialog: TFindDialog): TFindDirection;
57
    function GetDirection(dialog: TFindDialog): TFindDirection;
58
 
58
 
59
  public
59
  public
Line 137... Line 137...
137
 
137
 
138
  found := fEditor.SearchReplace(dialog.FindText, '', opt) > 0;
138
  found := fEditor.SearchReplace(dialog.FindText, '', opt) > 0;
139
 
139
 
140
  if not found then
140
  if not found then
141
  begin
141
  begin
-
 
142
    // TODO: If single replace was chosen, behave like Notepad and select the last replaced word
142
    if direction = sdForwards then
143
    if direction = sdForwards then
143
      MessageDlg('End of document reached.', mtInformation, [mbOk], 0)
144
      MessageDlg('End of document reached.', mtInformation, [mbOk], 0)
144
    else
145
    else
145
      MessageDlg('Begin of document reached.', mtInformation, [mbOk], 0);
146
      MessageDlg('Begin of document reached.', mtInformation, [mbOk], 0);
146
  end;
147
  end;
Line 151... Line 152...
151
procedure TSynEditFindReplace.DoReplace(dialog: TReplaceDialog; direction: TFindDirection);
152
procedure TSynEditFindReplace.DoReplace(dialog: TReplaceDialog; direction: TFindDirection);
152
var
153
var
153
  opt: TSynSearchOptions;
154
  opt: TSynSearchOptions;
154
  numReplacements: integer;
155
  numReplacements: integer;
155
begin
156
begin
-
 
157
  try
156
  if direction = sdDefault then direction := GetDirection(dialog);
158
    if direction = sdDefault then direction := GetDirection(dialog);
157
 
159
 
158
  opt := [];
160
    opt := [];
159
  if frMatchCase in dialog.Options then Include(opt, ssoMatchCase);
161
    if frMatchCase in dialog.Options then Include(opt, ssoMatchCase);
160
  if frWholeWord in dialog.Options then Include(opt, ssoWholeWord);
162
    if frWholeWord in dialog.Options then Include(opt, ssoWholeWord);
Line 163... Line 165...
163
  if direction = sdBackwards then Include(opt, ssoBackwards);
165
    if direction = sdBackwards then Include(opt, ssoBackwards);
164
  Include(opt, ssoPrompt); // TODO: test. geht nicht?
166
    Include(opt, ssoPrompt); // TODO: test. geht nicht?
165
  if fEditor.SelAvail then Include(opt, ssoSelectedOnly);
167
    if fEditor.SelAvail then Include(opt, ssoSelectedOnly);
166
  Exclude(opt, ssoEntireScope); // TODO: ok?
168
    Exclude(opt, ssoEntireScope); // TODO: ok?
167
 
169
 
-
 
170
    if not (ssoReplaceAll in opt) then
-
 
171
    begin
-
 
172
      if fEditor.SelLength = 0 then
-
 
173
      begin
-
 
174
        DoFind(dialog, sdForwards);
-
 
175
        exit;
-
 
176
      end;
-
 
177
    end;
-
 
178
 
168
  fEditor.BeginUpdate; // TODO: geht nicht?
179
    fEditor.BeginUpdate; // TODO: geht nicht?
169
  //fEditor.BeginUndoBlock;
180
    //fEditor.BeginUndoBlock;
170
  try
181
    try
171
    numReplacements := fEditor.SearchReplace(dialog.FindText, dialog.ReplaceText, opt);
182
      numReplacements := fEditor.SearchReplace(dialog.FindText, dialog.ReplaceText, opt);
172
  finally
183
    finally
173
    //fEditor.EndUndoBlock;
184
      //fEditor.EndUndoBlock;
174
    fEditor.EndUpdate;
185
      fEditor.EndUpdate;
175
  end;
186
    end;
176
 
187
 
-
 
188
    if not (ssoReplaceAll in opt) then
-
 
189
    begin
-
 
190
      DoFind(dialog, sdForwards);
-
 
191
    end
-
 
192
    else
-
 
193
    begin
177
  ShowMessageFmt('%d replaced.', [numReplacements]);
194
      ShowMessageFmt('%d replaced.', [numReplacements]);
178
 
195
    end;
-
 
196
  finally
179
  if fAutofocus and fEditor.CanFocus then fEditor.SetFocus;
197
    if fAutofocus and fEditor.CanFocus then fEditor.SetFocus;
180
end;
198
  end;
-
 
199
end;
181
 
200
 
182
procedure TSynEditFindReplace.OnFind(Sender: TObject);
201
procedure TSynEditFindReplace.OnFind(Sender: TObject);
183
begin
202
begin
184
  DoFind(Sender as TFindDialog, sdDefault);
203
  DoFind(Sender as TFindDialog, sdDefault);
185
end;
204
end;