52
53
comboboxScope.Active = ScopeDirectories;
53
54
comboboxentryPath.Entry.Text = directory;
54
55
writeScope = false;
58
readonly ComboBoxEntry comboboxentryReplace;
59
readonly Label labelReplace;
57
ComboBoxEntry comboboxentryReplace;
59
61
FindInFilesDialog (bool showReplace)
61
63
this.showReplace = showReplace;
63
this.Title = showReplace ? GettextCatalog.GetString ("Replace in Files") : GettextCatalog.GetString ("Find in Files");
64
this.TransientFor = IdeApp.Workbench.RootWindow;
66
buttonReplace.Destroy ();
65
Title = showReplace ? GettextCatalog.GetString ("Replace in Files") : GettextCatalog.GetString ("Find in Files");
66
TransientFor = IdeApp.Workbench.RootWindow;
68
buttonReplace.Destroy();
70
71
tableFindAndReplace.NRows = 4;
71
labelReplace = new Label ();
72
labelReplace.Text = GettextCatalog.GetString ("_Replace:");
73
labelReplace.Xalign = 0f;
74
labelReplace.UseUnderline = true;
72
labelReplace = new Label {Text = GettextCatalog.GetString("_Replace:"), Xalign = 0f, UseUnderline = true};
75
73
tableFindAndReplace.Add (labelReplace);
77
75
comboboxentryReplace = new ComboBoxEntry ();
78
76
tableFindAndReplace.Add (comboboxentryReplace);
80
Gtk.Table.TableChild childLabel = (Gtk.Table.TableChild)this.tableFindAndReplace[this.labelReplace];
78
var childLabel = (Table.TableChild)tableFindAndReplace[labelReplace];
81
79
childLabel.TopAttach = 1;
82
80
childLabel.BottomAttach = 2;
83
childLabel.XOptions = childLabel.YOptions = (Gtk.AttachOptions)4;
81
childLabel.XOptions = childLabel.YOptions = (AttachOptions)4;
85
Gtk.Table.TableChild childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.comboboxentryReplace];
83
var childCombo = (Table.TableChild)tableFindAndReplace[comboboxentryReplace];
86
84
childCombo.TopAttach = 1;
87
85
childCombo.BottomAttach = 2;
88
86
childCombo.LeftAttach = 1;
89
87
childCombo.RightAttach = 2;
90
childCombo.XOptions = childCombo.YOptions = (Gtk.AttachOptions)4;
88
childCombo.XOptions = childCombo.YOptions = (AttachOptions)4;
92
childLabel = (Gtk.Table.TableChild)this.tableFindAndReplace[this.labelScope];
90
childLabel = (Table.TableChild)tableFindAndReplace[labelScope];
93
91
childLabel.TopAttach = 2;
94
92
childLabel.BottomAttach = 3;
96
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.hbox2];
94
childCombo = (Table.TableChild)tableFindAndReplace[hbox2];
97
95
childCombo.TopAttach = 2;
98
96
childCombo.BottomAttach = 3;
100
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.labelFileMask];
98
childCombo = (Table.TableChild)tableFindAndReplace[labelFileMask];
101
99
childCombo.TopAttach = 3;
102
100
childCombo.BottomAttach = 4;
104
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.searchentry1];
102
childCombo = (Table.TableChild)tableFindAndReplace[searchentry1];
105
103
childCombo.TopAttach = 3;
106
104
childCombo.BottomAttach = 4;
129
127
InitFromProperties ();
131
129
if (IdeApp.Workbench.ActiveDocument != null) {
132
ITextBuffer view = IdeApp.Workbench.ActiveDocument.GetContent<ITextBuffer> ();
130
var view = IdeApp.Workbench.ActiveDocument.GetContent<ITextBuffer> ();
133
131
if (view != null) {
134
132
string selectedText = view.SelectedText;
135
133
if (!string.IsNullOrEmpty (selectedText)) {
136
if (selectedText.Contains ('\n')) {
137
comboboxScope.Active = ScopeSelection;
134
if (selectedText.Any (c => c == '\n' || c == '\r')) {
135
// comboboxScope.Active = ScopeSelection;
139
137
if (comboboxScope.Active == ScopeSelection)
140
138
comboboxScope.Active = ScopeCurrentDocument;
151
149
Hidden += delegate { Destroy (); };
152
150
UpdateStopButton ();
153
this.searchentry1.Ready = true;
154
this.searchentry1.Visible = true;
155
this.searchentry1.IsCheckMenu = true;
157
Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
159
CheckMenuItem checkMenuItem = this.searchentry1.AddFilterOption (0, GettextCatalog.GetString ("Include binary files"));
151
searchentry1.Ready = true;
152
searchentry1.Visible = true;
153
searchentry1.IsCheckMenu = true;
155
var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
157
CheckMenuItem checkMenuItem = searchentry1.AddFilterOption (0, GettextCatalog.GetString ("Include binary files"));
160
158
checkMenuItem.DrawAsRadio = false;
161
159
checkMenuItem.Active = properties.Get ("IncludeBinaryFiles", false);
162
160
checkMenuItem.Toggled += delegate {
163
161
properties.Set ("IncludeBinaryFiles", checkMenuItem.Active);
166
CheckMenuItem checkMenuItem1 = this.searchentry1.AddFilterOption (1, GettextCatalog.GetString ("Include hidden files and directories"));
164
CheckMenuItem checkMenuItem1 = searchentry1.AddFilterOption (1, GettextCatalog.GetString ("Include hidden files and directories"));
167
165
checkMenuItem1.DrawAsRadio = false;
168
166
checkMenuItem1.Active = properties.Get ("IncludeHiddenFiles", false);
169
167
checkMenuItem1.Toggled += delegate {
211
204
//tableFindAndReplace.NRows = showReplace ? 4u : 3u;
213
Gtk.Table.TableChild childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.labelFileMask];
206
var childCombo = (Table.TableChild)tableFindAndReplace[labelFileMask];
214
207
childCombo.TopAttach = tableFindAndReplace.NRows - 3;
215
208
childCombo.BottomAttach = tableFindAndReplace.NRows - 2;
217
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.searchentry1];
210
childCombo = (Table.TableChild)tableFindAndReplace[searchentry1];
218
211
childCombo.TopAttach = tableFindAndReplace.NRows - 3;
219
212
childCombo.BottomAttach = tableFindAndReplace.NRows - 2;
222
215
if (comboboxScope.Active == ScopeDirectories) {
223
216
// DirectoryScope
224
217
tableFindAndReplace.NRows = showReplace ? 6u : 5u;
225
labelPath = new Label ();
226
labelPath.LabelProp = GettextCatalog.GetString ("_Path:");
227
labelPath.UseUnderline = true;
228
labelPath.Xalign = 0f;
218
labelPath = new Label {
219
LabelProp = GettextCatalog.GetString("_Path:"),
229
224
tableFindAndReplace.Add (labelPath);
231
Gtk.Table.TableChild childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[labelPath];
226
var childCombo = (Table.TableChild)tableFindAndReplace[labelPath];
232
227
childCombo.TopAttach = tableFindAndReplace.NRows - 3;
233
228
childCombo.BottomAttach = tableFindAndReplace.NRows - 2;
234
childCombo.XOptions = childCombo.YOptions = (Gtk.AttachOptions)4;
229
childCombo.XOptions = childCombo.YOptions = (AttachOptions)4;
236
231
hboxPath = new HBox ();
237
Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
232
var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
238
233
comboboxentryPath = new ComboBoxEntry ();
239
234
comboboxentryPath.Destroyed += ComboboxentryPathDestroyed;
240
235
LoadHistory ("MonoDevelop.FindReplaceDialogs.PathHistory", comboboxentryPath);
243
238
labelPath.MnemonicWidget = comboboxentryPath;
245
Gtk.Box.BoxChild boxChild = (Gtk.Box.BoxChild)hboxPath[comboboxentryPath];
240
var boxChild = (Box.BoxChild)hboxPath[comboboxentryPath];
246
241
boxChild.Position = 0;
247
242
boxChild.Expand = boxChild.Fill = true;
249
buttonBrowsePaths = new Button ();
250
buttonBrowsePaths.Label = "...";
244
buttonBrowsePaths = new Button { Label = "..." };
251
245
buttonBrowsePaths.Clicked += ButtonBrowsePathsClicked;
252
246
hboxPath.PackStart (buttonBrowsePaths);
253
boxChild = (Gtk.Box.BoxChild)hboxPath[buttonBrowsePaths];
247
boxChild = (Box.BoxChild)hboxPath[buttonBrowsePaths];
254
248
boxChild.Position = 1;
255
249
boxChild.Expand = boxChild.Fill = false;
257
251
tableFindAndReplace.Add (hboxPath);
258
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[hboxPath];
252
childCombo = (Table.TableChild)tableFindAndReplace[hboxPath];
259
253
childCombo.TopAttach = tableFindAndReplace.NRows - 3;
260
254
childCombo.BottomAttach = tableFindAndReplace.NRows - 2;
261
255
childCombo.LeftAttach = 1;
262
256
childCombo.RightAttach = 2;
263
childCombo.XOptions = childCombo.YOptions = (Gtk.AttachOptions)4;
257
childCombo.XOptions = childCombo.YOptions = (AttachOptions)4;
265
checkbuttonRecursively = new CheckButton ();
266
checkbuttonRecursively.Label = GettextCatalog.GetString ("Re_cursively");
267
checkbuttonRecursively.Active = properties.Get ("SearchPathRecursively", true);
268
checkbuttonRecursively.UseUnderline = true;
259
checkbuttonRecursively = new CheckButton {
260
Label = GettextCatalog.GetString ("Re_cursively"),
261
Active = properties.Get ("SearchPathRecursively", true),
269
265
checkbuttonRecursively.Destroyed += CheckbuttonRecursivelyDestroyed;
270
266
tableFindAndReplace.Add (checkbuttonRecursively);
271
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[checkbuttonRecursively];
267
childCombo = (Table.TableChild)tableFindAndReplace[checkbuttonRecursively];
272
268
childCombo.TopAttach = tableFindAndReplace.NRows - 2;
273
269
childCombo.BottomAttach = tableFindAndReplace.NRows - 1;
274
270
childCombo.LeftAttach = 1;
275
271
childCombo.RightAttach = 2;
276
childCombo.XOptions = childCombo.YOptions = (Gtk.AttachOptions)4;
272
childCombo.XOptions = childCombo.YOptions = (AttachOptions)4;
278
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.labelFileMask];
274
childCombo = (Table.TableChild)tableFindAndReplace[labelFileMask];
279
275
childCombo.TopAttach = tableFindAndReplace.NRows - 1;
280
276
childCombo.BottomAttach = tableFindAndReplace.NRows;
282
childCombo = (Gtk.Table.TableChild)this.tableFindAndReplace[this.searchentry1];
278
childCombo = (Table.TableChild)tableFindAndReplace[searchentry1];
283
279
childCombo.TopAttach = tableFindAndReplace.NRows - 1;
284
280
childCombo.BottomAttach = tableFindAndReplace.NRows;
286
Requisition req = this.SizeRequest ();
287
this.Resize (req.Width, req.Height);
282
Requisition req = SizeRequest ();
283
Resize (req.Width, req.Height);
288
284
// this.QueueResize ();
292
protected override void OnSizeRequested (ref Gtk.Requisition requisition)
288
protected override void OnSizeRequested (ref Requisition requisition)
294
290
base.OnSizeRequested (ref requisition);
295
291
requisition.Width = Math.Max (480, requisition.Width);
298
void ComboboxentryPathDestroyed (object sender, EventArgs e)
294
static void ComboboxentryPathDestroyed (object sender, EventArgs e)
300
296
StoreHistory ("MonoDevelop.FindReplaceDialogs.PathHistory", (ComboBoxEntry)sender);
306
302
TransientFor = this,
309
string defaultFolder = this.comboboxentryPath.Entry.Text;
305
string defaultFolder = comboboxentryPath.Entry.Text;
310
306
if (string.IsNullOrEmpty (defaultFolder))
311
307
defaultFolder = IdeApp.ProjectOperations.ProjectsDefaultPath;
312
308
if (!string.IsNullOrEmpty (defaultFolder))
313
309
dlg.CurrentFolder = defaultFolder;
316
this.comboboxentryPath.Entry.Text = dlg.SelectedFile;
319
void CheckbuttonRecursivelyDestroyed (object sender, EventArgs e)
312
comboboxentryPath.Entry.Text = dlg.SelectedFile;
315
static void CheckbuttonRecursivelyDestroyed (object sender, EventArgs e)
321
Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
317
var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
322
318
properties.Set ("SearchPathRecursively", ((CheckButton)sender).Active);
325
321
const char historySeparator = '\n';
326
322
void InitFromProperties ()
328
Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
324
var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
329
325
comboboxScope.Active = properties.Get ("Scope", ScopeWholeSolution);
331
327
//checkbuttonRecursively.Active = properties.Get ("SearchPathRecursively", true);
345
341
static void LoadHistory (string propertyName, ComboBoxEntry entry)
347
343
entry.Entry.Completion = new EntryCompletion ();
348
ListStore store = new ListStore (typeof(string));
344
var store = new ListStore (typeof(string));
349
345
entry.Entry.Completion.Model = store;
350
346
entry.Model = store;
351
347
entry.Entry.ActivatesDefault = true;
352
if (entry.TextColumn != 0)
353
entry.TextColumn = 0;
354
string history = PropertyService.Get<string> (propertyName);
348
entry.TextColumn = 0;
349
var history = PropertyService.Get<string> (propertyName);
355
350
if (!string.IsNullOrEmpty (history)) {
356
351
string[] items = history.Split (historySeparator);
357
352
foreach (string item in items) {
453
448
case ScopeSelection:
454
449
return new SelectionScope ();
455
450
case ScopeWholeSolution:
456
if (IdeApp.ProjectOperations.CurrentSelectedSolution == null) {
451
if (!IdeApp.Workspace.IsOpen) {
457
452
MessageService.ShowError (GettextCatalog.GetString ("Currently there is no open solution."));
460
455
return new WholeSolutionScope ();
461
456
case ScopeCurrentProject:
462
MonoDevelop.Projects.Project currentSelectedProject = IdeApp.ProjectOperations.CurrentSelectedProject;
463
if (currentSelectedProject != null) {
464
return new WholeProjectScope (currentSelectedProject);
457
MonoDevelop.Projects.Project currentSelectedProject = IdeApp.ProjectOperations.CurrentSelectedProject;
458
if (currentSelectedProject != null)
459
return new WholeProjectScope (currentSelectedProject);
460
if (IdeApp.Workspace.IsOpen && IdeApp.ProjectOperations.CurrentSelectedSolution != null) {
461
AlertButton alertButton = MessageService.AskQuestion (GettextCatalog.GetString ("Currently there is no project selected. Search in the solution instead ?"), AlertButton.Yes, AlertButton.No);
462
if (alertButton == AlertButton.Yes)
463
return new WholeSolutionScope ();
466
if (IdeApp.ProjectOperations.CurrentSelectedSolution != null) {
467
AlertButton alertButton = MessageService.AskQuestion (GettextCatalog.GetString ("Currently there is no project selected. Search in the solution instead ?"), AlertButton.Yes, AlertButton.No);
468
if (alertButton == AlertButton.Yes)
469
return new WholeSolutionScope ();
471
MessageService.ShowError (GettextCatalog.GetString ("Currently there is no open solution."));
465
MessageService.ShowError (GettextCatalog.GetString ("Currently there is no open solution."));
475
468
case ScopeAllOpenFiles:
476
469
return new AllOpenFilesScope ();
479
472
MessageService.ShowError (string.Format (GettextCatalog.GetString ("Directory not found: {0}"), comboboxentryPath.Entry.Text));
482
DirectoryScope directoryScope = new DirectoryScope (comboboxentryPath.Entry.Text, checkbuttonRecursively.Active);
475
var directoryScope = new DirectoryScope (comboboxentryPath.Entry.Text, checkbuttonRecursively.Active);
484
Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
477
var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
485
478
directoryScope.IncludeBinaryFiles = properties.Get ("IncludeBinaryFiles", false);
486
479
directoryScope.IncludeHiddenFiles = properties.Get ("IncludeHiddenFiles", false);
493
486
FilterOptions GetFilterOptions ()
495
FilterOptions result = new FilterOptions ();
496
result.FileMask = !string.IsNullOrEmpty (searchentry1.Query) ? searchentry1.Query : "*";
497
result.CaseSensitive = checkbuttonCaseSensitive.Active;
498
result.RegexSearch = checkbuttonRegexSearch.Active;
499
result.WholeWordsOnly = checkbuttonWholeWordsOnly.Active;
488
return new FilterOptions {
489
FileMask = !string.IsNullOrEmpty (searchentry1.Query) ? searchentry1.Query : "*",
490
CaseSensitive = checkbuttonCaseSensitive.Active,
491
RegexSearch = checkbuttonRegexSearch.Active,
492
WholeWordsOnly = checkbuttonWholeWordsOnly.Active
503
496
static FindReplace find;
567
DispatchService.BackgroundDispatch (delegate {
568
DateTime timer = DateTime.Now;
569
string errorMessage = null;
572
List<SearchResult> results = new List<SearchResult> ();
573
foreach (SearchResult result in find.FindAll (scope, searchMonitor, pattern, replacePattern, options)) {
574
if (searchMonitor.IsCancelRequested)
576
results.Add (result);
577
if (results.Count > 10) {
578
Application.Invoke (delegate {
579
results.ForEach (r => searchMonitor.ReportResult (r));
584
Application.Invoke (delegate {
585
results.ForEach (r => searchMonitor.ReportResult (r));
588
} catch (Exception ex) {
589
errorMessage = ex.Message;
590
LoggingService.LogError ("Error while search", ex);
594
if (errorMessage != null) {
595
message = GettextCatalog.GetString ("The search could not be finished: {0}", errorMessage);
596
searchMonitor.ReportError (message, null);
597
} else if (searchMonitor.IsCancelRequested) {
598
message = GettextCatalog.GetString ("Search cancelled.");
599
searchMonitor.ReportWarning (message);
601
string matches = string.Format (GettextCatalog.GetPluralString ("{0} match found", "{0} matches found", find.FoundMatchesCount), find.FoundMatchesCount);
602
string files = string.Format (GettextCatalog.GetPluralString ("in {0} file.", "in {0} files.", find.SearchedFilesCount), find.SearchedFilesCount);
603
message = GettextCatalog.GetString ("Search completed.") + Environment.NewLine + matches + " " + files;
604
searchMonitor.ReportSuccess (message);
606
searchMonitor.ReportStatus (message);
607
searchMonitor.Log.WriteLine (GettextCatalog.GetString ("Search time: {0} seconds."), (DateTime.Now - timer).TotalSeconds);
608
searchMonitor.Dispose ();
609
lock (searchesInProgress)
610
searchesInProgress.Remove (searchMonitor);
561
DateTime timer = DateTime.Now;
562
string errorMessage = null;
565
var results = new List<SearchResult> ();
566
foreach (SearchResult result in find.FindAll (scope, searchMonitor, pattern, replacePattern, options)) {
567
if (searchMonitor.IsCancelRequested)
569
results.Add (result);
571
searchMonitor.ReportResults (results);
572
} catch (Exception ex) {
573
errorMessage = ex.Message;
574
LoggingService.LogError ("Error while search", ex);
578
if (errorMessage != null) {
579
message = GettextCatalog.GetString ("The search could not be finished: {0}", errorMessage);
580
searchMonitor.ReportError (message, null);
581
} else if (searchMonitor.IsCancelRequested) {
582
message = GettextCatalog.GetString ("Search cancelled.");
583
searchMonitor.ReportWarning (message);
585
string matches = string.Format (GettextCatalog.GetPluralString ("{0} match found", "{0} matches found", find.FoundMatchesCount), find.FoundMatchesCount);
586
string files = string.Format (GettextCatalog.GetPluralString ("in {0} file.", "in {0} files.", find.SearchedFilesCount), find.SearchedFilesCount);
587
message = GettextCatalog.GetString ("Search completed.") + Environment.NewLine + matches + " " + files;
588
searchMonitor.ReportSuccess (message);
590
searchMonitor.ReportStatus (message);
591
searchMonitor.Log.WriteLine (GettextCatalog.GetString ("Search time: {0} seconds."), (DateTime.Now - timer).TotalSeconds);
592
searchMonitor.Dispose ();
593
searchesInProgress.Remove (searchMonitor);