~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/FindInFilesDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
// THE SOFTWARE.
26
26
 
27
27
using System;
28
 
using System.Linq;
 
28
using System.Linq;
 
29
using System.Threading;
29
30
using MonoDevelop.Core;
30
31
using MonoDevelop.Ide.Gui;
31
32
using MonoDevelop.Components;
36
37
namespace MonoDevelop.Ide.FindInFiles
37
38
{
38
39
        public partial class FindInFilesDialog : Gtk.Dialog
39
 
        {
40
 
                bool writeScope = true;
41
 
                bool showReplace;
 
40
        {
 
41
                readonly bool writeScope = true;
 
42
                readonly bool showReplace;
42
43
                
43
44
                const int ScopeWholeSolution   = 0;
44
45
                const int ScopeCurrentProject  = 1;
52
53
                        comboboxScope.Active = ScopeDirectories;
53
54
                        comboboxentryPath.Entry.Text = directory;
54
55
                        writeScope = false;
55
 
                }
 
56
                }
 
57
 
 
58
                readonly ComboBoxEntry comboboxentryReplace;
 
59
                readonly Label labelReplace;
56
60
 
57
 
                ComboBoxEntry comboboxentryReplace;
58
 
                Label labelReplace;
59
61
                FindInFilesDialog (bool showReplace)
60
62
                {
61
63
                        this.showReplace = showReplace;
62
 
                        this.Build ();
63
 
                        this.Title = showReplace ? GettextCatalog.GetString ("Replace in Files") : GettextCatalog.GetString ("Find in Files");
64
 
                        this.TransientFor = IdeApp.Workbench.RootWindow;
65
 
                        if (!showReplace) {
66
 
                                buttonReplace.Destroy ();
67
 
                        }
68
 
 
 
64
                        Build ();
 
65
                        Title = showReplace ? GettextCatalog.GetString ("Replace in Files") : GettextCatalog.GetString ("Find in Files");
 
66
                        TransientFor = IdeApp.Workbench.RootWindow;
 
67
                        if (!showReplace)
 
68
                                buttonReplace.Destroy();
 
69
 
69
70
                        if (showReplace) {
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);
76
74
 
77
75
                                comboboxentryReplace = new ComboBoxEntry ();
78
76
                                tableFindAndReplace.Add (comboboxentryReplace);
79
77
 
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;
84
82
 
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;
91
89
 
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;
95
93
 
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;
99
97
 
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;
103
101
 
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;
107
105
 
114
112
                        buttonSearch.Clicked += HandleSearchClicked;
115
113
                        buttonClose.Clicked += ButtonCloseClicked;
116
114
                        buttonStop.Clicked += ButtonStopClicked;
117
 
                        ListStore scopeStore = new ListStore (typeof(string));
 
115
                        var scopeStore = new ListStore (typeof(string));
118
116
                        scopeStore.AppendValues (GettextCatalog.GetString ("Whole solution"));
119
117
                        scopeStore.AppendValues (GettextCatalog.GetString ("Current project"));
120
118
                        scopeStore.AppendValues (GettextCatalog.GetString ("All open files"));
129
127
                        InitFromProperties ();
130
128
 
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; 
138
136
                                                } else {
139
137
                                                        if (comboboxScope.Active == ScopeSelection)
140
138
                                                                comboboxScope.Active = ScopeCurrentDocument;
150
148
                        
151
149
                        Hidden += delegate { Destroy (); };
152
150
                        UpdateStopButton ();
153
 
                        this.searchentry1.Ready = true;
154
 
                        this.searchentry1.Visible = true;
155
 
                        this.searchentry1.IsCheckMenu = true;
156
 
                        
157
 
                        Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
158
 
                        
159
 
                        CheckMenuItem checkMenuItem = this.searchentry1.AddFilterOption (0, GettextCatalog.GetString ("Include binary files"));
 
151
                        searchentry1.Ready = true;
 
152
                        searchentry1.Visible = true;
 
153
                        searchentry1.IsCheckMenu = true;
 
154
                        
 
155
                        var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
 
156
                        
 
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);
164
162
                        };
165
163
                        
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 {
173
171
                        Child.Show ();
174
172
                }
175
173
 
176
 
                public override void Destroy ()
177
 
                {
178
 
                        base.Destroy ();
179
 
                }
180
 
 
181
174
                void ButtonCloseClicked (object sender, EventArgs e)
182
175
                {
183
176
                        Hide ();
210
203
 
211
204
                                //tableFindAndReplace.NRows = showReplace ? 4u : 3u;
212
205
 
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;
216
209
 
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;
220
213
                        }
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:"),
 
220
                                        UseUnderline = true, 
 
221
                                        Xalign = 0f
 
222
                                };
 
223
 
229
224
                                tableFindAndReplace.Add (labelPath);
230
225
 
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;
235
230
 
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);
242
237
 
243
238
                                labelPath.MnemonicWidget = comboboxentryPath;
244
239
 
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;
248
243
 
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;
256
250
 
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;
264
258
 
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),
 
262
                                        UseUnderline = true
 
263
                                };
 
264
 
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;
277
273
 
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;
281
277
 
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;
285
281
                        }
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 ();
289
285
                        ShowAll ();
290
286
                }
291
287
 
292
 
                protected override void OnSizeRequested (ref Gtk.Requisition requisition)
 
288
                protected override void OnSizeRequested (ref Requisition requisition)
293
289
                {
294
290
                        base.OnSizeRequested (ref requisition);
295
291
                        requisition.Width = Math.Max (480, requisition.Width);
296
 
                }
297
 
 
298
 
                void ComboboxentryPathDestroyed (object sender, EventArgs e)
 
292
                }
 
293
 
 
294
                static void ComboboxentryPathDestroyed (object sender, EventArgs e)
299
295
                {
300
296
                        StoreHistory ("MonoDevelop.FindReplaceDialogs.PathHistory", (ComboBoxEntry)sender);
301
297
                }
306
302
                                TransientFor = this,
307
303
                        };
308
304
                        
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;
314
310
                        
315
311
                        if (dlg.Run ())
316
 
                                this.comboboxentryPath.Entry.Text = dlg.SelectedFile;
317
 
                }
318
 
 
319
 
                void CheckbuttonRecursivelyDestroyed (object sender, EventArgs e)
 
312
                                comboboxentryPath.Entry.Text = dlg.SelectedFile;
 
313
                }
 
314
 
 
315
                static void CheckbuttonRecursivelyDestroyed (object sender, EventArgs e)
320
316
                {
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);
323
319
                }
324
320
 
325
321
                const char historySeparator = '\n';
326
322
                void InitFromProperties ()
327
323
                {
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);
330
326
 
331
327
                        //checkbuttonRecursively.Active    = properties.Get ("SearchPathRecursively", true);
345
341
                static void LoadHistory (string propertyName, ComboBoxEntry entry)
346
342
                {
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) {
365
360
 
366
361
                void StorePoperties ()
367
362
                {
368
 
                        Properties properties = (Properties)PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
 
363
                        var properties = PropertyService.Get ("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties ());
369
364
                        if (writeScope)
370
365
                                properties.Set ("Scope", comboboxScope.Active);
371
366
//                      properties.Set ("SearchPathRecursively", checkbuttonRecursively.Active);
382
377
                        //StoreHistory ("MonoDevelop.FindReplaceDialogs.FileMaskHistory", comboboxentryFileMask);
383
378
                }
384
379
 
385
 
                static void StoreHistory (string propertyName, Gtk.ComboBoxEntry comboBox)
 
380
                static void StoreHistory (string propertyName, ComboBoxEntry comboBox)
386
381
                {
387
 
                        ListStore store = (ListStore)comboBox.Model;
388
 
                        List<string> history = new List<string> ();
 
382
                        var store = (ListStore)comboBox.Model;
 
383
                        var history = new List<string> ();
389
384
                        TreeIter iter;
390
385
                        if (store.GetIterFirst (out iter)) {
391
386
                                do {
408
403
                        base.OnDestroyed ();
409
404
                }
410
405
                
411
 
                static FindInFilesDialog currentFindDialog = null;
 
406
                static FindInFilesDialog currentFindDialog;
412
407
                static bool IsCurrentDialogClosed {
413
408
                        get {
414
409
                                return currentFindDialog == null || !currentFindDialog.Visible;
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."));
458
453
                                        return null;
459
454
                                }
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 ();
465
464
                                } else {
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 ();
470
 
                                        } else {
471
 
                                                MessageService.ShowError (GettextCatalog.GetString ("Currently there is no open solution."));
472
 
                                        }
473
 
                                }
 
465
                                        MessageService.ShowError (GettextCatalog.GetString ("Currently there is no open solution."));
 
466
                                }
474
467
                                return null;
475
468
                        case ScopeAllOpenFiles:
476
469
                                return new AllOpenFilesScope ();
479
472
                                        MessageService.ShowError (string.Format (GettextCatalog.GetString ("Directory not found: {0}"), comboboxentryPath.Entry.Text));
480
473
                                        return null;
481
474
                                }
482
 
                                DirectoryScope directoryScope = new DirectoryScope (comboboxentryPath.Entry.Text, checkbuttonRecursively.Active);
 
475
                                var directoryScope = new DirectoryScope (comboboxentryPath.Entry.Text, checkbuttonRecursively.Active);
483
476
                                
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);
487
480
                                
492
485
 
493
486
                FilterOptions GetFilterOptions ()
494
487
                {
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;
500
 
                        return result;
 
488
                        return new FilterOptions {
 
489
                                FileMask = !string.IsNullOrEmpty (searchentry1.Query) ? searchentry1.Query : "*",
 
490
                                CaseSensitive = checkbuttonCaseSensitive.Active,
 
491
                                RegexSearch = checkbuttonRegexSearch.Active,
 
492
                                WholeWordsOnly = checkbuttonWholeWordsOnly.Active
 
493
                        };
501
494
                }
502
495
 
503
496
                static FindReplace find;
511
504
                {
512
505
                        SearchReplace (null);
513
506
//                      Hide ();
514
 
                }
515
 
                List<ISearchProgressMonitor> searchesInProgress = new List<ISearchProgressMonitor> ();
 
507
                }
 
508
 
 
509
                readonly List<ISearchProgressMonitor> searchesInProgress = new List<ISearchProgressMonitor> ();
516
510
                void UpdateStopButton ()
517
511
                {
518
512
                        buttonStop.Sensitive = searchesInProgress.Count > 0;
534
528
                                if (!MessageService.Confirm (GettextCatalog.GetString ("There is a search already in progress. Do you want to stop it?"), AlertButton.Stop))
535
529
                                        return;
536
530
                                lock (searchesInProgress) {
537
 
                                        foreach (IProgressMonitor mon in searchesInProgress)
 
531
                                        foreach (var mon in searchesInProgress)
538
532
                                                mon.AsyncOperation.Cancel ();
539
533
                                        searchesInProgress.Clear ();
540
534
                                }
564
558
                                return;
565
559
                        }
566
560
 
567
 
                        DispatchService.BackgroundDispatch (delegate {
568
 
                                DateTime timer = DateTime.Now;
569
 
                                string errorMessage = null;
570
 
                                
571
 
                                try {
572
 
                                        List<SearchResult> results = new List<SearchResult> ();
573
 
                                        foreach (SearchResult result in find.FindAll (scope, searchMonitor, pattern, replacePattern, options)) {
574
 
                                                if (searchMonitor.IsCancelRequested)
575
 
                                                        return;
576
 
                                                results.Add (result);
577
 
                                                if (results.Count > 10) {
578
 
                                                        Application.Invoke (delegate {
579
 
                                                                results.ForEach (r => searchMonitor.ReportResult (r));
580
 
                                                                results.Clear ();
581
 
                                                        });
582
 
                                                }
583
 
                                        }
584
 
                                        Application.Invoke (delegate {
585
 
                                                results.ForEach (r => searchMonitor.ReportResult (r));
586
 
                                                results.Clear ();
587
 
                                        });
588
 
                                } catch (Exception ex) {
589
 
                                        errorMessage = ex.Message;
590
 
                                        LoggingService.LogError ("Error while search", ex);
591
 
                                }
592
 
                                
593
 
                                string message;
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);
600
 
                                } else {
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);
605
 
                                }
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);
611
 
                                UpdateStopButton ();
612
 
                        });
 
561
                        DateTime timer = DateTime.Now;
 
562
                        string errorMessage = null;
 
563
                                
 
564
                        try {
 
565
                                var results = new List<SearchResult> ();
 
566
                                foreach (SearchResult result in find.FindAll (scope, searchMonitor, pattern, replacePattern, options)) {
 
567
                                        if (searchMonitor.IsCancelRequested)
 
568
                                                return;
 
569
                                        results.Add (result);
 
570
                                }
 
571
                                searchMonitor.ReportResults (results);
 
572
                        } catch (Exception ex) {
 
573
                                errorMessage = ex.Message;
 
574
                                LoggingService.LogError ("Error while search", ex);
 
575
                        }
 
576
                                
 
577
                        string message;
 
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);
 
584
                        } else {
 
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);
 
589
                        }
 
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);
 
594
                        UpdateStopButton ();
613
595
                }
614
596
        }
615
597
}