forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFRInDocDialog.cs
More file actions
777 lines (742 loc) · 35 KB
/
FRInDocDialog.cs
File metadata and controls
777 lines (742 loc) · 35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using PluginCore.Localization;
using FlashDevelop.Utilities;
using FlashDevelop.Helpers;
using PluginCore.FRService;
using PluginCore.Managers;
using PluginCore.Controls;
using PluginCore.Helpers;
using ScintillaNet;
using PluginCore;
namespace FlashDevelop.Dialogs
{
public class FRInDocDialog : SmartForm
{
private System.Windows.Forms.Label infoLabel;
private System.Windows.Forms.Label findLabel;
private System.Windows.Forms.Label lookLabel;
private System.Windows.Forms.Label replaceLabel;
private System.Windows.Forms.CheckBox useRegexCheckBox;
private System.Windows.Forms.CheckBox escapedCheckBox;
private System.Windows.Forms.CheckBox matchCaseCheckBox;
private System.Windows.Forms.CheckBox wholeWordCheckBox;
private System.Windows.Forms.GroupBox optionsGroupBox;
private System.Windows.Forms.PictureBox infoPictureBox;
private System.Windows.Forms.ComboBox replaceComboBox;
private System.Windows.Forms.ComboBox lookComboBox;
private System.Windows.Forms.ComboBox findComboBox;
private System.Windows.Forms.Button replaceAllButton;
private System.Windows.Forms.Button bookmarkAllButton;
private System.Windows.Forms.Button findPrevButton;
private System.Windows.Forms.Button findNextButton;
private System.Windows.Forms.Button replaceButton;
private System.Windows.Forms.Button closeButton;
private System.Boolean lookupIsDirty = false;
private SearchMatch currentMatch = null;
public FRInDocDialog()
{
this.Owner = Globals.MainForm;
this.Font = Globals.Settings.DefaultFont;
this.FormGuid = "24910809-a60a-4b7c-8d2a-d53a363f595f";
this.InitializeComponent();
this.InitializeProperties();
this.ApplyLocalizedTexts();
ScaleHelper.AdjustForHighDPI(this);
}
#region Windows Forms Designer Generated Code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.replaceButton = new System.Windows.Forms.Button();
this.findNextButton = new System.Windows.Forms.Button();
this.wholeWordCheckBox = new System.Windows.Forms.CheckBox();
this.matchCaseCheckBox = new System.Windows.Forms.CheckBox();
this.closeButton = new System.Windows.Forms.Button();
this.findPrevButton = new System.Windows.Forms.Button();
this.findComboBox = new System.Windows.Forms.ComboBox();
this.findLabel = new System.Windows.Forms.Label();
this.escapedCheckBox = new System.Windows.Forms.CheckBox();
this.useRegexCheckBox = new System.Windows.Forms.CheckBox();
this.infoPictureBox = new System.Windows.Forms.PictureBox();
this.infoLabel = new System.Windows.Forms.Label();
this.optionsGroupBox = new System.Windows.Forms.GroupBox();
this.replaceComboBox = new System.Windows.Forms.ComboBox();
this.replaceLabel = new System.Windows.Forms.Label();
this.replaceAllButton = new System.Windows.Forms.Button();
this.lookComboBox = new System.Windows.Forms.ComboBox();
this.lookLabel = new System.Windows.Forms.Label();
this.bookmarkAllButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.infoPictureBox)).BeginInit();
this.optionsGroupBox.SuspendLayout();
this.SuspendLayout();
//
// replaceButton
//
this.replaceButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.replaceButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.replaceButton.Location = new System.Drawing.Point(277, 112);
this.replaceButton.Name = "replaceButton";
this.replaceButton.Size = new System.Drawing.Size(95, 23);
this.replaceButton.TabIndex = 8;
this.replaceButton.Text = "&Replace";
this.replaceButton.Click += new System.EventHandler(this.ReplaceButtonClick);
//
// findNextButton
//
this.findNextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.findNextButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.findNextButton.Location = new System.Drawing.Point(277, 22);
this.findNextButton.Name = "findNextButton";
this.findNextButton.Size = new System.Drawing.Size(95, 23);
this.findNextButton.TabIndex = 5;
this.findNextButton.Text = "Find &Next";
this.findNextButton.Click += new System.EventHandler(this.FindNextButtonClick);
//
// wholeWordCheckBox
//
this.wholeWordCheckBox.AutoSize = true;
this.wholeWordCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.wholeWordCheckBox.Location = new System.Drawing.Point(12, 18);
this.wholeWordCheckBox.Name = "wholeWordCheckBox";
this.wholeWordCheckBox.Size = new System.Drawing.Size(92, 18);
this.wholeWordCheckBox.TabIndex = 1;
this.wholeWordCheckBox.Text = " &Whole word";
this.wholeWordCheckBox.CheckedChanged += new System.EventHandler(this.LookupChanged);
//
// matchCaseCheckBox
//
this.matchCaseCheckBox.AutoSize = true;
this.matchCaseCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.matchCaseCheckBox.Location = new System.Drawing.Point(12, 40);
this.matchCaseCheckBox.Name = "matchCaseCheckBox";
this.matchCaseCheckBox.Size = new System.Drawing.Size(89, 18);
this.matchCaseCheckBox.TabIndex = 2;
this.matchCaseCheckBox.Text = " Match &case";
this.matchCaseCheckBox.CheckedChanged += new System.EventHandler(this.LookupChanged);
//
// closeButton
//
this.closeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.closeButton.Location = new System.Drawing.Point(277, 172);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(95, 23);
this.closeButton.TabIndex = 10;
this.closeButton.Text = "&Close";
this.closeButton.Click += new System.EventHandler(this.CloseButtonClick);
//
// findPrevButton
//
this.findPrevButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.findPrevButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.findPrevButton.Location = new System.Drawing.Point(277, 52);
this.findPrevButton.Name = "findPrevButton";
this.findPrevButton.Size = new System.Drawing.Size(95, 23);
this.findPrevButton.TabIndex = 6;
this.findPrevButton.Text = "Find &Previous";
this.findPrevButton.Click += new System.EventHandler(this.FindPrevButtonClick);
//
// findComboBox
//
this.findComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.findComboBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.findComboBox.Location = new System.Drawing.Point(13, 23);
this.findComboBox.Name = "findComboBox";
this.findComboBox.Size = new System.Drawing.Size(252, 21);
this.findComboBox.TabIndex = 1;
this.findComboBox.TextChanged += new System.EventHandler(this.LookupChanged);
this.findComboBox.TextChanged += new EventHandler(this.FindComboBoxTextChanged);
//
// findLabel
//
this.findLabel.AutoSize = true;
this.findLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.findLabel.Location = new System.Drawing.Point(14, 8);
this.findLabel.Name = "findLabel";
this.findLabel.Size = new System.Drawing.Size(58, 13);
this.findLabel.TabIndex = 0;
this.findLabel.Text = "Find what:";
//
// escapedCheckBox
//
this.escapedCheckBox.AutoSize = true;
this.escapedCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.escapedCheckBox.Location = new System.Drawing.Point(115, 40);
this.escapedCheckBox.Name = "escapedCheckBox";
this.escapedCheckBox.Size = new System.Drawing.Size(129, 18);
this.escapedCheckBox.TabIndex = 4;
this.escapedCheckBox.Text = " &Escaped characters";
this.escapedCheckBox.CheckedChanged += new System.EventHandler(this.LookupChanged);
//
// useRegexCheckBox
//
this.useRegexCheckBox.AutoSize = true;
this.useRegexCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.useRegexCheckBox.Location = new System.Drawing.Point(115, 18);
this.useRegexCheckBox.Name = "useRegexCheckBox";
this.useRegexCheckBox.Size = new System.Drawing.Size(132, 18);
this.useRegexCheckBox.TabIndex = 3;
this.useRegexCheckBox.Text = " &Regular expressions";
this.useRegexCheckBox.CheckedChanged += new System.EventHandler(this.LookupChanged);
//
// infoPictureBox
//
this.infoPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.infoPictureBox.BackColor = System.Drawing.SystemColors.Control;
this.infoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.infoPictureBox.Location = new System.Drawing.Point(14, 202);
this.infoPictureBox.Name = "infoPictureBox";
this.infoPictureBox.Size = new System.Drawing.Size(16, 16);
this.infoPictureBox.TabIndex = 12;
this.infoPictureBox.TabStop = false;
//
// infoLabel
//
this.infoLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.infoLabel.AutoSize = true;
this.infoLabel.BackColor = System.Drawing.SystemColors.Control;
this.infoLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.infoLabel.ForeColor = System.Drawing.SystemColors.ControlText;
this.infoLabel.Location = new System.Drawing.Point(36, 203);
this.infoLabel.Name = "infoLabel";
this.infoLabel.Size = new System.Drawing.Size(130, 13);
this.infoLabel.TabIndex = 0;
this.infoLabel.Text = "No suitable results found.";
//
// optionsGroupBox
//
this.optionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.optionsGroupBox.Controls.Add(this.useRegexCheckBox);
this.optionsGroupBox.Controls.Add(this.escapedCheckBox);
this.optionsGroupBox.Controls.Add(this.wholeWordCheckBox);
this.optionsGroupBox.Controls.Add(this.matchCaseCheckBox);
this.optionsGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.optionsGroupBox.Location = new System.Drawing.Point(13, 128);
this.optionsGroupBox.Name = "optionsGroupBox";
this.optionsGroupBox.Size = new System.Drawing.Size(252, 67);
this.optionsGroupBox.TabIndex = 4;
this.optionsGroupBox.TabStop = false;
this.optionsGroupBox.Text = " Options";
//
// replaceComboBox
//
this.replaceComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.replaceComboBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.replaceComboBox.Location = new System.Drawing.Point(13, 62);
this.replaceComboBox.Name = "replaceComboBox";
this.replaceComboBox.Size = new System.Drawing.Size(252, 21);
this.replaceComboBox.TabIndex = 2;
this.replaceComboBox.TextChanged += new System.EventHandler(this.LookupChanged);
//
// replaceLabel
//
this.replaceLabel.AutoSize = true;
this.replaceLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.replaceLabel.Location = new System.Drawing.Point(14, 47);
this.replaceLabel.Name = "replaceLabel";
this.replaceLabel.Size = new System.Drawing.Size(72, 13);
this.replaceLabel.TabIndex = 16;
this.replaceLabel.Text = "Replace with:";
//
// replaceAllButton
//
this.replaceAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.replaceAllButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.replaceAllButton.Location = new System.Drawing.Point(277, 142);
this.replaceAllButton.Name = "replaceAllButton";
this.replaceAllButton.Size = new System.Drawing.Size(95, 23);
this.replaceAllButton.TabIndex = 9;
this.replaceAllButton.Text = "Replace &All";
this.replaceAllButton.Click += new System.EventHandler(this.ReplaceAllButtonClick);
//
// lookComboBox
//
this.lookComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.lookComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.lookComboBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lookComboBox.Items.AddRange(new object[] {
"Full source code",
"Current selection",
"Code and strings",
"Comments only",
"Strings only"});
this.lookComboBox.Location = new System.Drawing.Point(13, 101);
this.lookComboBox.Name = "lookComboBox";
this.lookComboBox.Size = new System.Drawing.Size(252, 21);
this.lookComboBox.TabIndex = 3;
this.lookComboBox.TextChanged += new System.EventHandler(this.LookupChanged);
//
// lookLabel
//
this.lookLabel.AutoSize = true;
this.lookLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lookLabel.Location = new System.Drawing.Point(14, 86);
this.lookLabel.Name = "lookLabel";
this.lookLabel.Size = new System.Drawing.Size(44, 13);
this.lookLabel.TabIndex = 19;
this.lookLabel.Text = "Look in:";
//
// bookmarkAllButton
//
this.bookmarkAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.bookmarkAllButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bookmarkAllButton.Location = new System.Drawing.Point(277, 82);
this.bookmarkAllButton.Name = "bookmarkAllButton";
this.bookmarkAllButton.Size = new System.Drawing.Size(95, 23);
this.bookmarkAllButton.TabIndex = 7;
this.bookmarkAllButton.Text = "&Bookmark All";
this.bookmarkAllButton.Click += new System.EventHandler(this.BookmarkAllButtonClick);
//
// FRInDocDialog
//
this.AcceptButton = this.findNextButton;
this.CancelButton = this.closeButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(384, 228);
this.MinimumSize = new System.Drawing.Size(384, 268);
//this.MaximumSize = new System.Drawing.Size(1000, 268);
this.Controls.Add(this.bookmarkAllButton);
this.Controls.Add(this.replaceComboBox);
this.Controls.Add(this.lookComboBox);
this.Controls.Add(this.lookLabel);
this.Controls.Add(this.replaceAllButton);
this.Controls.Add(this.replaceLabel);
this.Controls.Add(this.optionsGroupBox);
this.Controls.Add(this.findComboBox);
this.Controls.Add(this.infoPictureBox);
this.Controls.Add(this.infoLabel);
this.Controls.Add(this.findPrevButton);
this.Controls.Add(this.replaceButton);
this.Controls.Add(this.closeButton);
this.Controls.Add(this.findLabel);
this.Controls.Add(this.findNextButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FRInDocDialog";
this.ShowInTaskbar = false;
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = " Find And Replace";
this.Load += new System.EventHandler(this.DialogLoad);
this.VisibleChanged += new System.EventHandler(this.VisibleChange);
this.Closing += new System.ComponentModel.CancelEventHandler(this.DialogClosing);
((System.ComponentModel.ISupportInitialize)(this.infoPictureBox)).EndInit();
this.optionsGroupBox.ResumeLayout(false);
this.optionsGroupBox.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
#region Methods And Event Handlers
/// <summary>
/// Inits the default properties
/// </summary>
private void InitializeProperties()
{
this.lookComboBox.SelectedIndex = 0;
}
/// <summary>
/// Applies the localized texts
/// </summary>
private void ApplyLocalizedTexts()
{
this.lookLabel.Text = TextHelper.GetString("Info.LookIn");
this.findLabel.Text = TextHelper.GetString("Info.FindWhat");
this.replaceLabel.Text = TextHelper.GetString("Info.ReplaceWith");
this.findNextButton.Text = TextHelper.GetString("Label.FindNext");
this.findPrevButton.Text = TextHelper.GetString("Label.FindPrevious");
this.bookmarkAllButton.Text = TextHelper.GetString("Label.BookmarkAll");
this.replaceAllButton.Text = TextHelper.GetString("Label.ReplaceAll");
this.replaceButton.Text = TextHelper.GetString("Label.Replace").Replace("...", "");
this.closeButton.Text = TextHelper.GetString("Label.Close").Replace("&", "");
this.lookComboBox.Items[0] = TextHelper.GetString("Info.FullSourceCode");
this.lookComboBox.Items[1] = TextHelper.GetString("Info.CurrentSelection");
this.lookComboBox.Items[2] = TextHelper.GetString("Info.CodeAndStrings");
this.lookComboBox.Items[3] = TextHelper.GetString("Info.CommentsOnly");
this.lookComboBox.Items[4] = TextHelper.GetString("Info.StringsOnly");
this.optionsGroupBox.Text = " " + TextHelper.GetString("Label.Options");
this.matchCaseCheckBox.Text = " " + TextHelper.GetString("Label.MatchCase");
this.wholeWordCheckBox.Text = " " + TextHelper.GetString("Label.WholeWord");
this.escapedCheckBox.Text = " " + TextHelper.GetString("Label.EscapedCharacters");
this.useRegexCheckBox.Text = " " + TextHelper.GetString("Label.RegularExpressions");
this.Text = " " + TextHelper.GetString("Title.FindAndReplaceDialog");
}
/// <summary>
/// Set the case of the text to search
/// </summary>
public void SetMatchCase(Boolean matchCase)
{
this.matchCaseCheckBox.CheckedChanged -= new EventHandler(this.LookupChanged);
this.matchCaseCheckBox.Checked = matchCase; // Change the value...
this.matchCaseCheckBox.CheckedChanged += new EventHandler(this.LookupChanged);
}
/// <summary>
/// Set the whole word prop of the text to search
/// </summary>
public void SetWholeWord(Boolean wholeWord)
{
this.wholeWordCheckBox.CheckedChanged -= new EventHandler(this.LookupChanged);
this.wholeWordCheckBox.Checked = wholeWord; // Change the value...
this.wholeWordCheckBox.CheckedChanged += new EventHandler(this.LookupChanged);
}
/// <summary>
/// Set the text to search
/// </summary>
public void SetFindText(String text)
{
this.findComboBox.TextChanged -= new EventHandler(this.FindComboBoxTextChanged);
this.findComboBox.Text = text; // Change the value...
this.findComboBox.TextChanged += new EventHandler(this.FindComboBoxTextChanged);
}
/// <summary>
/// When the text changes, synchronizes the find controls
/// </summary>
private void FindComboBoxTextChanged(Object sender, EventArgs e)
{
Globals.MainForm.SetFindText(this, this.findComboBox.Text);
}
/// <summary>
/// If there is a word selected, insert it to the find box
/// </summary>
private void UpdateFindText()
{
ScintillaControl sci = Globals.SciControl;
if (this.useRegexCheckBox.Checked) return;
if (sci != null && sci.SelText.Length > 0 && !this.lookupIsDirty)
{
this.findComboBox.Text = sci.SelText;
this.lookupIsDirty = false;
}
}
/// <summary>
/// Finds the next result based on direction
/// </summary>
public void FindNext(Boolean forward, Boolean update, Boolean simple)
{
this.currentMatch = null;
if (update) this.UpdateFindText();
if (Globals.SciControl == null) return;
ScintillaControl sci = Globals.SciControl;
List<SearchMatch> matches = this.GetResults(sci, simple);
if (matches != null && matches.Count != 0)
{
FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
SearchMatch match = FRDialogGenerics.GetNextDocumentMatch(sci, matches, forward, false);
if (match != null)
{
this.currentMatch = match;
FRDialogGenerics.SelectMatch(sci, match);
this.lookupIsDirty = false;
}
if (this.Visible)
{
Int32 index = FRDialogGenerics.GetMatchIndex(match, matches);
String message = TextHelper.GetString("Info.ShowingResult");
String formatted = String.Format(message, index, matches.Count);
this.ShowMessage(formatted, 0);
}
}
else
{
if (this.Visible)
{
String message = TextHelper.GetString("Info.NoMatchesFound");
this.ShowMessage(message, 0);
}
}
this.SelectText();
}
public void FindNext(Boolean forward, Boolean update)
{
this.FindNext(forward, update, false);
}
public void FindNext(Boolean forward)
{
this.FindNext(forward, true);
}
/// <summary>
/// Finds the next result specified by user input
/// </summary>
private void FindNextButtonClick(Object sender, System.EventArgs e)
{
this.FindNext(true, false);
}
/// <summary>
/// Finds the previous result specified by user input
/// </summary>
private void FindPrevButtonClick(Object sender, System.EventArgs e)
{
this.FindNext(false, false);
}
/// <summary>
/// Bookmarks all results
/// </summary>
private void BookmarkAllButtonClick(Object sender, System.EventArgs e)
{
if (Globals.SciControl == null) return;
ScintillaControl sci = Globals.SciControl;
List<SearchMatch> matches = this.GetResults(sci);
if (matches != null && this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0)
{
Int32 end = sci.MBSafeCharPosition(sci.SelectionEnd);
Int32 start = sci.MBSafeCharPosition(sci.SelectionStart);
matches = FRDialogGenerics.FilterMatches(matches, start, end);
}
if (matches != null && matches.Count != 0)
{
FRDialogGenerics.BookmarkMatches(sci, matches);
String message = TextHelper.GetString("Info.MatchesBookmarked");
this.ShowMessage(message, 0);
}
else
{
String message = TextHelper.GetString("Info.NothingToBookmark");
this.ShowMessage(message, 0);
}
}
/// <summary>
/// Replaces the next result specified by user input
/// </summary>
private void ReplaceButtonClick(Object sender, System.EventArgs e)
{
if (Globals.SciControl == null) return;
ScintillaControl sci = Globals.SciControl;
if (sci.SelText.Length == 0) this.FindNext(true);
else
{
String replaceWith = this.GetReplaceText(currentMatch);
sci.ReplaceSel(replaceWith);
FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
FRDialogGenerics.UpdateComboBoxItems(this.replaceComboBox);
String message = TextHelper.GetString("Info.SelectedReplaced");
this.ShowMessage(message, 0);
this.lookupIsDirty = false;
this.FindNext(true);
}
}
/// <summary>
/// Replaces all results specified by user input
/// </summary>
private void ReplaceAllButtonClick(Object sender, System.EventArgs e)
{
if (Globals.SciControl == null) return;
ScintillaControl sci = Globals.SciControl;
List<SearchMatch> matches = this.GetResults(sci);
if (matches != null && this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0)
{
Int32 end = sci.MBSafeCharPosition(sci.SelectionEnd);
Int32 start = sci.MBSafeCharPosition(sci.SelectionStart);
matches = FRDialogGenerics.FilterMatches(matches, start, end);
}
if (matches != null)
{
sci.BeginUndoAction();
try
{
for (Int32 i = 0; i < matches.Count; i++)
{
FRDialogGenerics.SelectMatch(sci, matches[i]);
String replaceWith = this.GetReplaceText(matches[i]);
FRSearch.PadIndexes(matches, i, matches[i].Value, replaceWith);
sci.EnsureVisible(sci.CurrentLine);
sci.ReplaceSel(replaceWith);
}
}
finally
{
sci.EndUndoAction();
}
FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
FRDialogGenerics.UpdateComboBoxItems(this.replaceComboBox);
String message = TextHelper.GetString("Info.ReplacedMatches");
String formatted = String.Format(message, matches.Count);
this.ShowMessage(formatted, 0);
this.lookupIsDirty = false;
}
}
/// <summary>
/// Closes the find and replace dialog
/// </summary>
private void CloseButtonClick(Object sender, System.EventArgs e)
{
this.Close();
}
/// <summary>
/// Marks the lookup as dirty
/// </summary>
private void LookupChanged(Object sender, System.EventArgs e)
{
if (this.Visible)
{
this.lookupIsDirty = true;
this.currentMatch = null;
}
if (sender == this.matchCaseCheckBox && !Globals.Settings.DisableFindOptionSync)
{
Globals.MainForm.SetMatchCase(this, this.matchCaseCheckBox.Checked);
}
if (sender == this.wholeWordCheckBox && !Globals.Settings.DisableFindOptionSync)
{
Globals.MainForm.SetWholeWord(this, this.wholeWordCheckBox.Checked);
}
}
/// <summary>
/// Some event handling when showing the form
/// </summary>
private void VisibleChange(Object sender, System.EventArgs e)
{
if (this.Visible) this.SelectText();
else this.lookupIsDirty = false;
}
/// <summary>
/// Just hides the dialog window when closing
/// </summary>
private void DialogClosing(Object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Globals.CurrentDocument.Activate();
this.Hide();
}
/// <summary>
/// Setups the dialog on load
/// </summary>
private void DialogLoad(Object sender, EventArgs e)
{
String message = TextHelper.GetString("Info.NoMatches");
this.ShowMessage(message, 0);
this.CenterToParent();
}
/// <summary>
/// Process shortcuts
/// </summary>
protected override Boolean ProcessDialogKey(Keys keyData)
{
if (keyData == (Keys.Control | Keys.F))
{
this.findComboBox.Focus();
return true;
}
else if ((keyData & Keys.KeyCode) == Keys.Enter && (keyData & Keys.Shift) > 0)
{
this.FindNext(false, false);
return true;
}
return base.ProcessDialogKey(keyData);
}
/// <summary>
/// Gets the replacement text and escapes it if needed
/// </summary>
private String GetReplaceText(SearchMatch match)
{
String replace = this.replaceComboBox.Text;
if (this.escapedCheckBox.Checked) replace = FRSearch.Unescape(replace);
if (this.useRegexCheckBox.Checked) replace = FRSearch.ExpandGroups(replace, match);
return replace;
}
/// <summary>
/// Gets search results for a document
/// </summary>
private List<SearchMatch> GetResults(ScintillaControl sci, Boolean simple)
{
if (IsValidPattern())
{
String pattern = this.findComboBox.Text;
FRSearch search = new FRSearch(pattern);
search.NoCase = !this.matchCaseCheckBox.Checked;
search.Filter = SearchFilter.None;
search.SourceFile = sci.FileName;
if (!simple)
{
search.IsRegex = this.useRegexCheckBox.Checked;
search.IsEscaped = this.escapedCheckBox.Checked;
search.WholeWord = this.wholeWordCheckBox.Checked;
if (this.lookComboBox.SelectedIndex == 2)
{
search.Filter = SearchFilter.OutsideCodeComments;
}
else if (this.lookComboBox.SelectedIndex == 3)
{
search.Filter = SearchFilter.InCodeComments | SearchFilter.OutsideStringLiterals;
}
else if (this.lookComboBox.SelectedIndex == 4)
{
search.Filter = SearchFilter.InStringLiterals | SearchFilter.OutsideCodeComments;
}
}
return search.Matches(sci.Text);
}
return null;
}
private List<SearchMatch> GetResults(ScintillaControl sci)
{
return this.GetResults(sci, false);
}
/// <summary>
/// Control user pattern
/// </summary>
private bool IsValidPattern()
{
String pattern = this.findComboBox.Text;
if (pattern.Length == 0) return false;
if (this.useRegexCheckBox.Checked)
{
try
{
new Regex(pattern);
}
catch (Exception ex)
{
ErrorManager.ShowInfo(ex.Message);
return false;
}
}
return true;
}
/// <summary>
/// Shows the info message in dialog
/// </summary>
private void ShowMessage(String msg, Int32 img)
{
Image image = FRDialogGenerics.GetImage(img);
this.infoPictureBox.Image = image;
this.infoLabel.Text = msg;
}
/// <summary>
/// Selects the text in the textfield.
/// </summary>
private void SelectText()
{
if (this.findComboBox.Text.Length == 0)
{
this.findComboBox.Select();
this.findComboBox.SelectAll();
}
else
{
this.replaceComboBox.Select();
this.replaceComboBox.SelectAll();
}
}
/// <summary>
/// Update the dialog args when show is called
/// </summary>
public new void Show()
{
base.Show();
this.lookupIsDirty = false;
this.UpdateFindText();
}
#endregion
}
}