~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SearchAndReplaceWidget.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
27
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
28
//
29
 
 
30
29
using System;
31
30
using System.Linq;
32
31
using System.Collections.Generic;
45
44
                const int  historyLimit = 20;
46
45
                const string seachHistoryProperty = "MonoDevelop.FindReplaceDialogs.FindHistory";
47
46
                const string replaceHistoryProperty = "MonoDevelop.FindReplaceDialogs.ReplaceHistory";
48
 
 
49
 
                internal static string searchPattern = String.Empty;
50
 
                internal static string replacePattern = String.Empty;
51
 
 
52
47
                public TextSegment SelectionSegment {
53
48
                        get;
54
49
                        set;
61
56
 
62
57
                readonly TextEditor textEditor;
63
58
                readonly Widget frame;
64
 
                readonly TextEditorContainer textEditorContainer;
65
 
 
66
59
                bool isReplaceMode = true;
67
 
                Widget [] replaceWidgets;
 
60
                Widget[] replaceWidgets;
68
61
                
69
62
                public bool IsCaseSensitive {
70
 
                        get { return PropertyService.Get ("IsCaseSensitive", true); }
 
63
                        get { return PropertyService.Get ("IsCaseSensitive", false); }
71
64
                        set { 
72
65
                                if (IsCaseSensitive != value)
73
66
                                        PropertyService.Set ("IsCaseSensitive", value); 
79
72
                }
80
73
                
81
74
                public const string DefaultSearchEngine = "default";
82
 
                public const string RegexSearchEngine   = "regex";
 
75
                public const string RegexSearchEngine = "regex";
 
76
 
83
77
                public static string SearchEngine {
84
78
                        get {
85
79
                                return PropertyService.Get ("BufferSearchEngine", DefaultSearchEngine);
88
82
                
89
83
                public string ReplacePattern {
90
84
                        get { return entryReplace.Text; }
91
 
                        set { entryReplace.Text = value; }
 
85
                        set { entryReplace.Text = value ?? ""; }
92
86
                }
93
87
                
94
88
                public string SearchPattern {
95
89
                        get { return searchEntry.Entry.Text; }
96
 
                        set { searchEntry.Entry.Text = value; }
 
90
                        set { searchEntry.Entry.Text = value ?? ""; }
97
91
                }
98
92
                
99
93
                public bool SearchFocused {
107
101
                        if (frame == null || textEditor == null)
108
102
                                return;
109
103
                        int newX = textEditor.Allocation.Width - Allocation.Width - 8;
110
 
                        TextEditorContainer.EditorContainerChild containerChild = ((TextEditorContainer.EditorContainerChild)textEditorContainer [frame]);
 
104
                        TextEditor.EditorContainerChild containerChild = ((TextEditor.EditorContainerChild)textEditor [frame]);
111
105
                        if (newX != containerChild.X) {
112
106
                                searchEntry.WidthRequest = textEditor.Allocation.Width / 3;
113
107
                                containerChild.X = newX;
114
 
                                textEditorContainer.QueueResize ();
 
108
                                textEditor.QueueResize ();
115
109
                        }
116
110
                }
 
111
 
 
112
                static string GetShortcut (object commandId)
 
113
                {
 
114
                        var key = IdeApp.CommandService.GetCommand (commandId).AccelKey;
 
115
                        if (string.IsNullOrEmpty (key))
 
116
                                return "";
 
117
                        var nextShortcut = KeyBindingManager.BindingToDisplayLabel (key, false);
 
118
                        return "(" + nextShortcut + ")";
 
119
                }
117
120
                
118
121
                public SearchAndReplaceWidget (TextEditor textEditor, Widget frame)
119
122
                {
 
123
                        if (textEditor == null)
 
124
                                throw new ArgumentNullException ("textEditor");
120
125
                        this.textEditor = textEditor;
121
 
                        textEditorContainer = textEditor.Parent as TextEditorContainer;
122
126
                        this.frame = frame;
123
 
                        textEditorContainer.SizeAllocated += HandleViewTextEditorhandleSizeAllocated;
 
127
                        textEditor.SizeAllocated += HandleViewTextEditorhandleSizeAllocated;
124
128
                        textEditor.TextViewMargin.SearchRegionsUpdated += HandleWidgetTextEditorTextViewMarginSearchRegionsUpdated;
125
129
                        textEditor.Caret.PositionChanged += HandleWidgetTextEditorCaretPositionChanged;
126
130
                        SizeAllocated += HandleViewTextEditorhandleSizeAllocated;
129
133
                        DisableAutomaticSearchPatternCaseMatch = false;
130
134
                        Build ();
131
135
                        buttonReplace.TooltipText = GettextCatalog.GetString ("Replace");
132
 
                        buttonSearchForward.TooltipText = GettextCatalog.GetString ("Find next");
133
 
                        buttonSearchBackward.TooltipText = GettextCatalog.GetString ("Find previous");
 
136
                        buttonSearchForward.TooltipText = GettextCatalog.GetString ("Find next {0}", GetShortcut (SearchCommands.FindNext));
 
137
                        buttonSearchBackward.TooltipText = GettextCatalog.GetString ("Find previous {0}", GetShortcut (SearchCommands.FindPrevious));
134
138
                        buttonSearchMode.TooltipText = GettextCatalog.GetString ("Toggle between search and replace mode");
135
139
                        searchEntry.Ready = true;
136
140
                        searchEntry.Visible = true;
157
161
                        if (Platform.IsMac) {
158
162
                                foreach (var eb in new [] { eventbox2, eventbox3, eventbox4, eventbox5, eventbox6 }) {
159
163
                                        eb.VisibleWindow = true;
160
 
                                        eb.ModifyBg (StateType.Normal, new Gdk.Color (230, 230, 230));
 
164
                                        eb.ModifyBg (StateType.Normal, new Gdk.Color (245, 245, 245));
161
165
                                }
162
166
                        }
163
167
 
164
168
                        if (String.IsNullOrEmpty (textEditor.SearchPattern)) {
165
 
                                textEditor.SearchPattern = searchPattern;
166
 
                        } else if (textEditor.SearchPattern != searchPattern) {
167
 
                                searchPattern = textEditor.SearchPattern;
 
169
                                textEditor.SearchPattern = SearchAndReplaceOptions.SearchPattern;
 
170
                        } else if (textEditor.SearchPattern != SearchAndReplaceOptions.SearchPattern) {
 
171
                                SearchAndReplaceOptions.SearchPattern = textEditor.SearchPattern;
168
172
                                //FireSearchPatternChanged ();
169
173
                        }
170
174
                        UpdateSearchPattern ();
180
184
                        
181
185
                        searchEntry.Entry.Changed += delegate {
182
186
                                SetSearchPattern (SearchPattern);
183
 
                                string oldPattern = searchPattern;
184
 
                                searchPattern = SearchPattern;
185
 
                                if (oldPattern != searchPattern)
 
187
                                string oldPattern = SearchAndReplaceOptions.SearchPattern;
 
188
                                SearchAndReplaceOptions.SearchPattern = SearchPattern;
 
189
                                if (oldPattern != SearchAndReplaceOptions.SearchPattern)
186
190
                                        UpdateSearchEntry ();
187
191
                                var history = GetHistory (seachHistoryProperty);
188
192
                                if (history.Count > 0 && history [0] == oldPattern) {
189
 
                                        ChangeHistory (seachHistoryProperty, searchPattern);
 
193
                                        ChangeHistory (seachHistoryProperty, SearchAndReplaceOptions.SearchPattern);
190
194
                                } else {
191
 
                                        UpdateSearchHistory (searchPattern);
 
195
                                        UpdateSearchHistory (SearchAndReplaceOptions.SearchPattern);
192
196
                                }
193
197
                        };
194
198
                        
195
 
                        entryReplace.Text = replacePattern;
 
199
                        entryReplace.Text = SearchAndReplaceOptions.ReplacePattern ?? "";
196
200
//                      entryReplace.Model = replaceHistory;
197
201
//                      RestoreReplaceHistory ();
198
202
                        
241
245
                        this.searchEntry.RequestMenu += HandleSearchEntryhandleRequestMenu;
242
246
                        
243
247
                        entryReplace.Changed += delegate {
244
 
                                replacePattern = ReplacePattern;
 
248
                                SearchAndReplaceOptions.ReplacePattern = ReplacePattern;
245
249
                                if (!inReplaceUpdate) 
246
250
                                        FireReplacePatternChanged ();
247
251
                        };
286
290
                                        SelectionSegment = textEditor.SelectionRange;
287
291
                                }
288
292
                        }
289
 
                        SetSearchPattern (searchPattern);
 
293
                        SetSearchPattern (SearchAndReplaceOptions.SearchPattern);
290
294
                        textEditor.HighlightSearchPattern = true;
291
295
                        textEditor.TextViewMargin.RefreshSearchMarker ();
292
296
                        if (textEditor.Document.ReadOnly) {
293
297
                                buttonSearchMode.Visible = false;
294
298
                                IsReplaceMode = false;
295
299
                        }
296
 
                        
 
300
 
 
301
                        SearchAndReplaceOptions.SearchPatternChanged += HandleSearchPatternChanged;
 
302
                        SearchAndReplaceOptions.ReplacePatternChanged += HandleReplacePatternChanged;
 
303
                }
 
304
 
 
305
                void HandleReplacePatternChanged (object sender, EventArgs e)
 
306
                {
 
307
                        ReplacePattern = SearchAndReplaceOptions.ReplacePattern;
 
308
                }
 
309
 
 
310
                void HandleSearchPatternChanged (object sender, EventArgs e)
 
311
                {
 
312
                        SearchPattern = SearchAndReplaceOptions.SearchPattern;
297
313
                }
298
314
 
299
315
                public bool DisableAutomaticSearchPatternCaseMatch {
331
347
                        }
332
348
                        textEditor.QueueDraw ();
333
349
                }
334
 
                
335
350
 
336
351
                void HandleSearchEntryhandleRequestMenu (object sender, EventArgs e)
337
352
                {
391
406
                                        recentItem.Name = item;
392
407
                                        recentItem.Activated += delegate (object mySender, EventArgs myE) {
393
408
                                                MenuItem cur = (MenuItem)mySender;
394
 
                                                searchPattern = ""; // force that the current pattern is stored in history and not replaced
 
409
                                                SearchAndReplaceOptions.SearchPattern = ""; // force that the current pattern is stored in history and not replaced
395
410
                                                searchEntry.Entry.Text = cur.Name;
396
411
                                                FilterHistory (seachHistoryProperty);
397
412
                                        };
418
433
                
419
434
                Gtk.Label resultInformLabel = new Gtk.Label ();
420
435
                Gtk.EventBox resultInformLabelEventBox;
421
 
                
422
 
                static Gdk.Cursor arrowCursor = new Gdk.Cursor (Gdk.CursorType.Arrow);
 
436
 
423
437
                protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
424
438
                {
425
 
                        GdkWindow.Cursor = arrowCursor;
 
439
                        GdkWindow.Cursor = null;
426
440
                        return base.OnEnterNotifyEvent (evnt);
427
441
                }
428
442
                
438
452
                
439
453
                public void UpdateSearchPattern ()
440
454
                {
441
 
                        searchEntry.Entry.Text = textEditor.SearchPattern;
 
455
                        searchEntry.Entry.Text = textEditor.SearchPattern ?? "";
442
456
                        SetSearchPattern (textEditor.SearchPattern);
443
 
                        searchPattern = textEditor.SearchPattern;
 
457
                        SearchAndReplaceOptions.SearchPattern = textEditor.SearchPattern;
444
458
//                      UpdateSearchEntry ();
445
459
                }
 
460
 
446
461
                int curSearchResult = -1;
447
462
                string curSearchPattern = null;
 
463
 
448
464
                private void OnNavigateKeyPressEvent (object o, KeyPressEventArgs args)
449
465
                {
450
466
                        args.RetVal = false;
451
467
                        switch (args.Event.Key) {
452
 
                                case Gdk.Key.Return:
453
 
                                case Gdk.Key.KP_Enter:/*
 
468
                        case Gdk.Key.Return:
 
469
                        case Gdk.Key.KP_Enter:/*
454
470
I think this is not needed, this code leads to a search twice bug when you hit return. 
455
471
But I leave it in in the case I've missed something. Mike
456
472
                                        if (o == buttonSearchBackward || o == buttonSearchForward) {
457
473
                                                if (!((Button)o).HasFocus)
458
474
                                                        ((Button)o).Click ();
459
475
                                        }*/
460
 
                                        break;
461
 
                                case Gdk.Key.Down:
462
 
                                case Gdk.Key.Up:
463
 
                                        if (o != searchEntry.Entry) {
464
 
                                                args.RetVal = true;
465
 
                                                return;
466
 
                                        }
467
 
                                        if ((args.Event.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask && o == searchEntry.Entry) {
468
 
                                                searchEntry.PopupFilterMenu ();
469
 
                                        } else {
470
 
                                                if (curSearchResult == -1)
471
 
                                                        curSearchPattern = searchEntry.Entry.Text;
 
476
                                break;
 
477
                        case Gdk.Key.Down:
 
478
                        case Gdk.Key.Up:
 
479
                                if (o != searchEntry.Entry) {
 
480
                                        args.RetVal = true;
 
481
                                        return;
 
482
                                }
 
483
                                if ((args.Event.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask && o == searchEntry.Entry) {
 
484
                                        searchEntry.PopupFilterMenu ();
 
485
                                } else {
 
486
                                        if (curSearchResult == -1)
 
487
                                                curSearchPattern = searchEntry.Entry.Text;
472
488
                                                
473
 
                                                List<string> history = GetHistory (seachHistoryProperty);
474
 
                                                if (history.Count > 0) {
475
 
                                                        curSearchResult += args.Event.Key == Gdk.Key.Up ? -1 : 1;
476
 
                                                        if (curSearchResult >= history.Count)
477
 
                                                                curSearchResult = -1;
478
 
                                                        if (curSearchResult == -1) {
479
 
                                                                searchEntry.Entry.Text = curSearchPattern;
480
 
                                                        } else {
481
 
                                                                if (curSearchResult < -1)
482
 
                                                                        curSearchResult = history.Count - 1;
 
489
                                        List<string> history = GetHistory (seachHistoryProperty);
 
490
                                        if (history.Count > 0) {
 
491
                                                curSearchResult += args.Event.Key == Gdk.Key.Up ? -1 : 1;
 
492
                                                if (curSearchResult >= history.Count)
 
493
                                                        curSearchResult = -1;
 
494
                                                if (curSearchResult == -1) {
 
495
                                                        searchEntry.Entry.Text = curSearchPattern;
 
496
                                                } else {
 
497
                                                        if (curSearchResult < -1)
 
498
                                                                curSearchResult = history.Count - 1;
483
499
                                                                
484
 
                                                                searchEntry.Entry.Text = history[curSearchResult];
485
 
                                                        }
486
 
                                                        searchEntry.Entry.Position = -1;
487
 
                                                }
488
 
                                        }
489
 
                                        args.RetVal = true;
490
 
                                        break;
491
 
                                case Gdk.Key.N:
492
 
                                case Gdk.Key.n:
493
 
                                        buttonSearchForward.GrabFocus ();
494
 
                                        buttonSearchForward.Click ();
495
 
                                        break;
496
 
                                case Gdk.Key.P:
497
 
                                case Gdk.Key.p:
498
 
                                        buttonSearchBackward.GrabFocus ();
499
 
                                        buttonSearchBackward.Click ();
500
 
                                        break;
501
 
                                case Gdk.Key.Escape:
502
 
                                        RemoveSearchWidget ();
503
 
                                        break;
504
 
                                case Gdk.Key.slash:
505
 
                                        searchEntry.GrabFocus ();
506
 
                                        break;
507
 
                                case Gdk.Key.ISO_Left_Tab:
508
 
                                        if (this.IsReplaceMode) {
509
 
                                                if (o == entryReplace) {
510
 
                                                        searchEntry.Entry.GrabFocus ();
511
 
                                                } else if (o == buttonReplace) {
512
 
                                                        entryReplace.GrabFocus ();
513
 
                                                } else if (o == buttonReplaceAll) {
514
 
                                                        buttonReplace.GrabFocus ();
515
 
                                                } else if (o == buttonSearchBackward) {
516
 
                                                        buttonReplaceAll.GrabFocus ();
517
 
                                                } else if (o == buttonSearchForward) {
518
 
                                                        buttonSearchBackward.GrabFocus ();
519
 
                                                } else {
520
 
                                                        buttonSearchForward.GrabFocus ();
521
 
                                                }
522
 
                                                args.RetVal = true;
523
 
                                        } else {
524
 
                                                if (o == buttonSearchBackward) {
525
 
                                                        searchEntry.Entry.GrabFocus ();
526
 
                                                } else if (o == buttonSearchForward) {
527
 
                                                        buttonSearchBackward.GrabFocus ();
528
 
                                                } else {
529
 
                                                        buttonSearchForward.GrabFocus ();
530
 
                                                }
531
 
                                                args.RetVal = true;
532
 
                                        }
533
 
                                        break;
534
 
                                case Gdk.Key.Tab: 
535
 
                                        if (this.IsReplaceMode) {
536
 
                                                if (o == entryReplace) {
537
 
                                                        buttonReplace.GrabFocus ();
538
 
                                                } else if (o == buttonReplace) {
539
 
                                                        buttonReplaceAll.GrabFocus ();
540
 
                                                } else if (o == buttonReplaceAll) {
541
 
                                                        buttonSearchBackward.GrabFocus ();
542
 
                                                } else if (o == buttonSearchBackward) {
543
 
                                                        buttonSearchForward.GrabFocus ();
544
 
                                                } else if (o == buttonSearchForward) {
545
 
//                                                      textEditor.GrabFocus ();
546
 
                                                        searchEntry.Entry.GrabFocus ();
547
 
                                                } else {
548
 
                                                        entryReplace.GrabFocus ();
549
 
                                                }
550
 
                                                args.RetVal = true;
551
 
                                        } else {
552
 
                                                if (o == buttonSearchBackward) {
553
 
                                                        buttonSearchForward.GrabFocus ();
554
 
                                                } else if (o == buttonSearchForward) {
555
 
                                                        searchEntry.Entry.GrabFocus ();
556
 
//                                                      textEditor.GrabFocus ();
557
 
                                                } else {
558
 
                                                        buttonSearchBackward.GrabFocus ();
559
 
                                                }
560
 
                                                args.RetVal = true;
561
 
                                        }
562
 
                                        break;
563
 
                                default:
564
 
                                        args.RetVal = true;
565
 
                                        break;
 
500
                                                        searchEntry.Entry.Text = history [curSearchResult];
 
501
                                                }
 
502
                                                searchEntry.Entry.Position = -1;
 
503
                                        }
 
504
                                }
 
505
                                args.RetVal = true;
 
506
                                break;
 
507
                        case Gdk.Key.N:
 
508
                        case Gdk.Key.n:
 
509
                                buttonSearchForward.GrabFocus ();
 
510
                                buttonSearchForward.Click ();
 
511
                                break;
 
512
                        case Gdk.Key.P:
 
513
                        case Gdk.Key.p:
 
514
                                buttonSearchBackward.GrabFocus ();
 
515
                                buttonSearchBackward.Click ();
 
516
                                break;
 
517
                        case Gdk.Key.Escape:
 
518
                                RemoveSearchWidget ();
 
519
                                break;
 
520
                        case Gdk.Key.slash:
 
521
                                searchEntry.GrabFocus ();
 
522
                                break;
 
523
                        case Gdk.Key.ISO_Left_Tab:
 
524
                                if (this.IsReplaceMode) {
 
525
                                        if (o == entryReplace) {
 
526
                                                searchEntry.Entry.GrabFocus ();
 
527
                                        } else if (o == buttonReplace) {
 
528
                                                entryReplace.GrabFocus ();
 
529
                                        } else if (o == buttonReplaceAll) {
 
530
                                                buttonReplace.GrabFocus ();
 
531
                                        } else if (o == buttonSearchBackward) {
 
532
                                                buttonReplaceAll.GrabFocus ();
 
533
                                        } else if (o == buttonSearchForward) {
 
534
                                                buttonSearchBackward.GrabFocus ();
 
535
                                        } else {
 
536
                                                buttonSearchForward.GrabFocus ();
 
537
                                        }
 
538
                                        args.RetVal = true;
 
539
                                } else {
 
540
                                        if (o == buttonSearchBackward) {
 
541
                                                searchEntry.Entry.GrabFocus ();
 
542
                                        } else if (o == buttonSearchForward) {
 
543
                                                buttonSearchBackward.GrabFocus ();
 
544
                                        } else {
 
545
                                                buttonSearchForward.GrabFocus ();
 
546
                                        }
 
547
                                        args.RetVal = true;
 
548
                                }
 
549
                                break;
 
550
                        case Gdk.Key.Tab: 
 
551
                                if (this.IsReplaceMode) {
 
552
                                        if (o == entryReplace) {
 
553
                                                buttonReplace.GrabFocus ();
 
554
                                        } else if (o == buttonReplace) {
 
555
                                                buttonReplaceAll.GrabFocus ();
 
556
                                        } else if (o == buttonReplaceAll) {
 
557
                                                buttonSearchBackward.GrabFocus ();
 
558
                                        } else if (o == buttonSearchBackward) {
 
559
                                                buttonSearchForward.GrabFocus ();
 
560
                                        } else if (o == buttonSearchForward) {
 
561
//                                                      textEditor.GrabFocus ();
 
562
                                                searchEntry.Entry.GrabFocus ();
 
563
                                        } else {
 
564
                                                entryReplace.GrabFocus ();
 
565
                                        }
 
566
                                        args.RetVal = true;
 
567
                                } else {
 
568
                                        if (o == buttonSearchBackward) {
 
569
                                                buttonSearchForward.GrabFocus ();
 
570
                                        } else if (o == buttonSearchForward) {
 
571
                                                searchEntry.Entry.GrabFocus ();
 
572
//                                                      textEditor.GrabFocus ();
 
573
                                        } else {
 
574
                                                buttonSearchBackward.GrabFocus ();
 
575
                                        }
 
576
                                        args.RetVal = true;
 
577
                                }
 
578
                                break;
 
579
                        default:
 
580
                                args.RetVal = true;
 
581
                                break;
566
582
                        }
567
583
                }
568
584
                
579
595
                                        buttonSearchMode.Visible = false;
580
596
                        }
581
597
                }
 
598
 
582
599
                protected override void OnFocusChildSet (Widget widget)
583
600
                {
584
601
                        base.OnFocusChildSet (widget);
592
609
                
593
610
                protected override void OnDestroyed ()
594
611
                {
 
612
                        SearchAndReplaceOptions.SearchPatternChanged -= HandleSearchPatternChanged;
 
613
                        SearchAndReplaceOptions.ReplacePatternChanged -= HandleReplacePatternChanged;
 
614
 
595
615
                        textEditor.TextViewMargin.HideSelection = false;
596
616
                        textEditor.Caret.PositionChanged -= HandleWidgetTextEditorCaretPositionChanged;
597
617
                        textEditor.TextViewMargin.SearchRegionsUpdated -= HandleWidgetTextEditorTextViewMarginSearchRegionsUpdated;
598
618
                        SizeAllocated -= HandleViewTextEditorhandleSizeAllocated;
599
 
                        textEditorContainer.SizeAllocated -= HandleViewTextEditorhandleSizeAllocated;
 
619
                        textEditor.SizeAllocated -= HandleViewTextEditorhandleSizeAllocated;
600
620
                        
601
621
                        // SearchPatternChanged -= UpdateSearchPattern;
602
622
                        ReplacePatternChanged -= UpdateReplacePattern;
619
639
                {
620
640
                        // vSave  = textEditor.VAdjustment.Value;
621
641
                        // hSave  = textEditor.HAdjustment.Value;
622
 
                        caretSave =  textEditor.Caret.Location;
 
642
                        caretSave = textEditor.Caret.Location;
623
643
                }
624
644
                
625
645
                void GotoResult (SearchResult result)
689
709
                        StoreHistory (propertyKey, history);
690
710
                }
691
711
                
692
 
                
693
 
                
694
712
                void SetIsCaseSensitive (bool value)
695
713
                {
696
714
                        IsCaseSensitive = value;
717
735
                
718
736
                string oldPattern;
719
737
                SearchResult result;
 
738
 
720
739
                void UpdateSearchEntry ()
721
740
                {
722
741
                        if (oldPattern != SearchPattern) {
740
759
                        
741
760
                        //      bool error = result == null && !String.IsNullOrEmpty (SearchPattern);
742
761
                        string errorMsg;
743
 
                        bool valid = textEditor.SearchEngine.IsValidPattern (searchPattern, out errorMsg);
 
762
                        bool valid = textEditor.SearchEngine.IsValidPattern (SearchAndReplaceOptions.SearchPattern, out errorMsg);
744
763
                        //      error |= !valid;
745
764
                        
746
765
                        if (!valid) {
777
796
                                textEditor.TextViewMargin.HideSelection = FocusChild == table;
778
797
                                textEditor.TextViewMargin.MainSearchResult = foundSegment;
779
798
                        }
780
 
                } 
 
799
                }
781
800
                
782
801
                void UpdateReplaceHistory (string item)
783
802
                {
784
803
                        UpdateHistory (replaceHistoryProperty, item);
785
804
                }
786
805
                
787
 
                
788
806
                void UpdateReplacePattern (object sender, EventArgs args)
789
807
                {
790
 
                        entryReplace.Text = replacePattern;
 
808
                        entryReplace.Text = SearchAndReplaceOptions.ReplacePattern ?? "";
791
809
                }
792
810
 
793
811
                internal void SetSearchPattern ()
796
814
                        
797
815
                        if (!String.IsNullOrEmpty (selectedText)) {
798
816
                                SetSearchPattern (selectedText);
799
 
                                SearchAndReplaceWidget.searchPattern = selectedText;
 
817
                                SearchAndReplaceOptions.SearchPattern = selectedText;
800
818
                                SearchAndReplaceWidget.UpdateSearchHistory (selectedText);
801
819
                                textEditor.TextViewMargin.MainSearchResult = textEditor.SelectionRange;
802
820
                        }
806
824
                {
807
825
                        textEditor.SearchPattern = searchPattern;
808
826
                }
809
 
                
810
827
 
811
828
                public static SearchResult FindNext (TextEditor textEditor)
812
829
                {
 
830
                        textEditor.SearchPattern = SearchAndReplaceOptions.SearchPattern;
813
831
                        SearchResult result = textEditor.FindNext (true);
814
832
                        textEditor.CenterToCaret ();
815
833
 
817
835
                                IdeApp.Workbench.StatusBar.ShowError (GettextCatalog.GetString ("Search pattern not found"));
818
836
                        } else if (result.SearchWrapped) {
819
837
                                IdeApp.Workbench.StatusBar.ShowMessage (
820
 
                                        new Image (Stock.Find, IconSize.Menu),
 
838
                                        Stock.Find,
821
839
                                        GettextCatalog.GetString ("Reached bottom, continued from top")
822
840
                                );
823
841
                        } else {
828
846
 
829
847
                public static SearchResult FindPrevious (TextEditor textEditor)
830
848
                {
 
849
                        textEditor.SearchPattern = SearchAndReplaceOptions.SearchPattern;
831
850
                        SearchResult result = textEditor.FindPrevious (true);
832
851
 
833
852
                        textEditor.CenterToCaret ();
835
854
                                IdeApp.Workbench.StatusBar.ShowError (GettextCatalog.GetString ("Search pattern not found"));
836
855
                        } else if (result.SearchWrapped) {
837
856
                                IdeApp.Workbench.StatusBar.ShowMessage (
838
 
                                        new Image (Stock.Find, IconSize.Menu),
 
857
                                        Stock.Find,
839
858
                                        GettextCatalog.GetString ("Reached top, continued from bottom")
840
859
                                );
841
860
                        } else {
847
866
                public void Replace ()
848
867
                {
849
868
                        textEditor.Replace (ReplacePattern);
 
869
                        textEditor.CenterToCaret ();
850
870
                        textEditor.GrabFocus ();
851
871
                }
852
872
                
861
881
                                                                        "Found and replaced {0} occurrences", number, number));
862
882
                        }
863
883
                        textEditor.GrabFocus ();
 
884
                        textEditor.CenterToCaret ();
864
885
                }
865
886
 
866
887
                internal static bool inReplaceUpdate = false;
 
888
 
867
889
                internal static void FireReplacePatternChanged ()
868
890
                {
869
891
                        inReplaceUpdate = true;