📄 replacedialog.cs
字号:
// ReplaceDialog.cs
// Copyright (C) 2000 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using SharpDevelop.Gui;
using SharpDevelop.Internal.Text;
using SharpDevelop.Internal.Text.Search;
using SharpDevelop.Tool.Data;
namespace SharpDevelop.Gui.Dialogs {
public class ReplaceDialog : System.Windows.Forms.Form {
private System.ComponentModel.Container components;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox OptionCombo;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox FindComboBox;
private System.Windows.Forms.Label label1;
private MainWindow main;
public ReplaceDialog(MainWindow main)
{
InitializeComponent();
Find.Main = main;
this.main = main;
button1.Click += new System.EventHandler(ClickFind);
button5.Click += new System.EventHandler(ClickReplace);
button6.Click += new System.EventHandler(ClickReplaceAll);
button3.Click += new System.EventHandler(Close);
CancelButton = button3;
MaximizeBox = MinimizeBox = false;
FormBorderStyle = FormBorderStyle.FixedDialog;
ShowInTaskbar = false;
Owner = main;
StartPosition = FormStartPosition.CenterParent;
Icon = null;
Show();
FindComboBox.Focus();
}
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.button3 = new System.Windows.Forms.Button();
this.FindComboBox = new System.Windows.Forms.ComboBox();
this.button4 = new System.Windows.Forms.Button();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.OptionCombo = new System.Windows.Forms.ComboBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
comboBox1.Text = "";
comboBox1.Location = new System.Drawing.Point(95, 37);
comboBox1.Size = new System.Drawing.Size(264, 21);
comboBox1.TabIndex = 2;
button1.Location = new System.Drawing.Point(367, 8);
button1.Size = new System.Drawing.Size(96, 24);
button1.TabIndex = 12;
button1.Text = Resource.GetString("Dialog.NewProject.SearchReplace.FindNextButton");
button3.Location = new System.Drawing.Point(368, 104);
button3.Size = new System.Drawing.Size(96, 24);
button3.TabIndex = 15;
button3.Text = Resource.GetString("Global.CloseButtonText");
button4.Location = new System.Drawing.Point(368, 152);
button4.Size = new System.Drawing.Size(96, 24);
button4.TabIndex = 16;
button4.Text = Resource.GetString("Global.HelpButtonText");
button5.Location = new System.Drawing.Point(368, 40);
button5.Size = new System.Drawing.Size(96, 24);
button5.TabIndex = 13;
button5.Text = Resource.GetString("Dialog.NewProject.SearchReplace.ReplaceButton");
button6.Location = new System.Drawing.Point(368, 72);
button6.Size = new System.Drawing.Size(96, 24);
button6.TabIndex = 14;
button6.Text = Resource.GetString("Dialog.NewProject.SearchReplace.ReplaceAllButton");
radioButton1.Location = new System.Drawing.Point(8, 16);
radioButton1.Size = new System.Drawing.Size(64, 16);
radioButton1.TabIndex = 0;
radioButton1.Text = Resource.GetString("Dialog.NewProject.SearchReplace.Up");
radioButton1.Checked = true;
radioButton2.Location = new System.Drawing.Point(64, 16);
radioButton2.Size = new System.Drawing.Size(64, 16);
radioButton2.TabIndex = 1;
radioButton2.Text = Resource.GetString("Dialog.NewProject.SearchReplace.Down");
FindComboBox.Text = "";
FindComboBox.Location = new System.Drawing.Point(95, 12);
FindComboBox.Size = new System.Drawing.Size(264, 21);
FindComboBox.TabIndex = 1;
checkBox3.Location = new System.Drawing.Point(23, 142);
checkBox3.Text = Resource.GetString("Dialog.NewProject.SearchReplace.WrapEnd");
checkBox3.Size = new System.Drawing.Size(112, 25);
// checkBox3.AccessibleRole = System.Windows.Forms.AccessibleRoles.CheckButton;
checkBox3.TabIndex = 8;
checkBox3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
checkBox2.Location = new System.Drawing.Point(23, 118);
checkBox2.Text = Resource.GetString("Dialog.NewProject.SearchReplace.WholeWord");
checkBox2.Size = new System.Drawing.Size(112, 25);
// checkBox2.AccessibleRole = System.Windows.Forms.AccessibleRoles.CheckButton;
checkBox2.TabIndex = 7;
checkBox2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.Text = Resource.GetString("Dialog.NewProject.SearchReplace.ReplaceDialogName");
//@design this.TrayLargeIcon = true;
//@design this.TrayHeight = 0;
// this.TopMost = true;
this.ClientSize = new System.Drawing.Size(434 + 42, 183);
checkBox1.Location = new System.Drawing.Point(23, 94);
checkBox1.Text = Resource.GetString("Dialog.NewProject.SearchReplace.CaseSensitive");
checkBox1.Size = new System.Drawing.Size(112, 25);
// checkBox1.AccessibleRole = System.Windows.Forms.AccessibleRoles.CheckButton;
checkBox1.TabIndex = 6;
checkBox1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
label1.Location = new System.Drawing.Point(2, 16);
label1.Text = Resource.GetString("Dialog.NewProject.SearchReplace.FindWhat");
label1.Size = new System.Drawing.Size(74, 12);
label1.TabIndex = 0;
OptionCombo.Text = "";
OptionCombo.Location = new System.Drawing.Point(208, 91);
OptionCombo.Size = new System.Drawing.Size(144, 21);
// OptionCombo.Style = System.Windows.Forms.ComboBoxStyle.DropDownList;
OptionCombo.TabIndex = 9;
OptionCombo.Items.Add(Resource.GetString("Global.Location.currentfile"));
OptionCombo.Items.Add(Resource.GetString("Global.Location.allopenfiles"));
OptionCombo.Items.Add(Resource.GetString("Global.Location.wholeproject"));
OptionCombo.SelectedIndex = 0;
groupBox1.Location = new System.Drawing.Point(175, 118);
groupBox1.TabIndex = 11;
groupBox1.TabStop = false;
groupBox1.Text = Resource.GetString("Dialog.NewProject.SearchReplace.DirectionText");
groupBox1.Size = new System.Drawing.Size(134, 40);
label2.Location = new System.Drawing.Point(148, 94);
label2.Text = Resource.GetString("Dialog.NewProject.SearchReplace.SearchIn");
label2.Size = new System.Drawing.Size(60, 14);
label2.TabIndex = 10;
label3.Location = new System.Drawing.Point(2, 40);
label3.Text = Resource.GetString("Dialog.NewProject.SearchReplace.ReplaceWith");
label3.Size = new System.Drawing.Size(74, 14);
label3.TabIndex = 13;
this.Controls.Add(button6);
this.Controls.Add(button5);
this.Controls.Add(label3);
this.Controls.Add(comboBox1);
this.Controls.Add(groupBox1);
this.Controls.Add(label2);
this.Controls.Add(OptionCombo);
this.Controls.Add(checkBox3);
this.Controls.Add(checkBox2);
this.Controls.Add(checkBox1);
this.Controls.Add(button4);
this.Controls.Add(button3);
this.Controls.Add(button1);
this.Controls.Add(FindComboBox);
this.Controls.Add(label1);
groupBox1.Controls.Add(radioButton2);
groupBox1.Controls.Add(radioButton1);
}
private void Close(object sender, System.EventArgs e)
{
Close();
}
private void SetFind()
{
Find.search.BigOnly = !checkBox1.Checked;
Find.search.What = FindComboBox.Text;
Find.search.WholeWords = checkBox2.Checked;
Find.WrapAtTheEnd = checkBox3.Checked;
}
void SetUpReplace()
{
Find find = null;
switch (OptionCombo.SelectedIndex){
case 0:
find = new FindInBuffer();
break;
case 1:
find = new FindInAllOpenFiles();
break;
case 2:
find = new FindInWholeProject();
break;
}
Find.search.BigOnly = !checkBox1.Checked;
Find.search.What = FindComboBox.Text;
Find.search.WholeWords = checkBox2.Checked;
Find.WrapAtTheEnd = checkBox3.Checked;
// lastIndex = OptionCombo.SelectedIndex;
Find replace = new Replace(find, comboBox1.Text);
// replace.main = main;
FindDialog.find = replace;
}
private void ClickFind(object sender, System.EventArgs e)
{
SetUpReplace();
Replace replace = ((Replace)FindDialog.find);
if(!replace.FindNext())
MessageBox.Show(Resource.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"));
}
private void ClickReplace(object sender, System.EventArgs e)
{
SetUpReplace();
Replace replace = ((Replace)FindDialog.find);
replace.ReplaceMatching();
ClickFind(null, null);
}
private void ClickReplaceAll(object sender, System.EventArgs e)
{
Find find = null;
switch (OptionCombo.SelectedIndex) {
case 0:
find = new FindInBuffer();
break;
case 1:
find = new FindInAllOpenFiles();
break;
case 2:
find = new FindInWholeProject();
break;
}
Find.search.BigOnly = !checkBox1.Checked;
Find.search.What = FindComboBox.Text;
Find.search.WholeWords = checkBox2.Checked;
Find.WrapAtTheEnd = checkBox3.Checked;
// lastIndex = OptionCombo.SelectedIndex;
Replace replace = new Replace(find, comboBox1.Text);
// replace.main = main;
FindDialog.find = replace;
int counter = 0;
TextBuffer buffer = main.ActiveContentWindow.TextArea.Buffer;
while (replace.FindNext()) {
replace.ReplaceMatching();
++counter;
if (buffer != main.ActiveContentWindow.TextArea.Buffer) {
buffer.UndoStack.UndoLast(counter);
buffer = main.ActiveContentWindow.TextArea.Buffer;
counter = 0;
}
}
buffer.UndoStack.UndoLast(counter);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -