Browse Source

Search and Replace dialog buttons disabled if no find pattern entered. Search/replace keyboard shortcuts now switch between the search/replace tabs when the search and replace dialog has the focus.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1574 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
4c06781d2e
  1. 44
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs
  2. 40
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

44
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs

@ -25,6 +25,10 @@ namespace SearchAndReplace
public static string SearchPattern = String.Empty; public static string SearchPattern = String.Empty;
public static string ReplacePattern = String.Empty; public static string ReplacePattern = String.Empty;
Keys searchKeyboardShortcut = Keys.None;
Keys replaceKeyboardShortcut = Keys.None;
const string SearchMenuAddInPath = "/SharpDevelop/Workbench/MainMenu/Search";
static SearchAndReplaceDialog Instance; static SearchAndReplaceDialog Instance;
public static void ShowSingleInstance(SearchAndReplaceMode searchAndReplaceMode) public static void ShowSingleInstance(SearchAndReplaceMode searchAndReplaceMode)
@ -82,6 +86,9 @@ namespace SearchAndReplace
SetSearchAndReplaceMode(); SetSearchAndReplaceMode();
FormLocationHelper.Apply(this, "ICSharpCode.SharpDevelop.Gui.SearchAndReplaceDialog.Location", false); FormLocationHelper.Apply(this, "ICSharpCode.SharpDevelop.Gui.SearchAndReplaceDialog.Location", false);
searchKeyboardShortcut = GetKeyboardShortcut(SearchMenuAddInPath, "Find");
replaceKeyboardShortcut = GetKeyboardShortcut(SearchMenuAddInPath, "Replace");
} }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
@ -94,28 +101,34 @@ namespace SearchAndReplace
{ {
if (e.KeyData == Keys.Escape) { if (e.KeyData == Keys.Escape) {
Close(); Close();
} else if (searchKeyboardShortcut == e.KeyData && !searchButton.Checked) {
EnableSearchMode(true);
} else if (replaceKeyboardShortcut == e.KeyData && !replaceButton.Checked) {
EnableSearchMode(false);
} }
} }
void SearchButtonClick(object sender, EventArgs e) void SearchButtonClick(object sender, EventArgs e)
{ {
if (!searchButton.Checked) { if (!searchButton.Checked) {
searchButton.Checked = true; EnableSearchMode(true);
replaceButton.Checked = false;
SetSearchAndReplaceMode();
Focus();
} }
} }
void ReplaceButtonClick(object sender, EventArgs e) void ReplaceButtonClick(object sender, EventArgs e)
{ {
if (!replaceButton.Checked) { if (!replaceButton.Checked) {
replaceButton.Checked = true; EnableSearchMode(false);
searchButton.Checked = false; }
}
void EnableSearchMode(bool enable)
{
searchButton.Checked = enable;
replaceButton.Checked = !enable;
SetSearchAndReplaceMode(); SetSearchAndReplaceMode();
Focus(); Focus();
} }
}
void SetSearchAndReplaceMode() void SetSearchAndReplaceMode()
{ {
@ -126,5 +139,22 @@ namespace SearchAndReplace
this.ClientSize = new Size(430, 385); this.ClientSize = new Size(430, 385);
} }
} }
/// <summary>
/// Gets the keyboard shortcut for the menu item with the given addin tree
/// path and given codon id.
/// </summary>
Keys GetKeyboardShortcut(string path, string id)
{
AddInTreeNode node = AddInTree.GetTreeNode(path);
if (node != null) {
foreach (Codon codon in node.Codons) {
if (codon.Id == id) {
return MenuCommand.ParseShortcut(codon.Properties["shortcut"]);
}
}
}
return Keys.None;
}
} }
} }

40
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

@ -40,8 +40,8 @@ namespace SearchAndReplace
switch (searchAndReplaceMode) { switch (searchAndReplaceMode) {
case SearchAndReplaceMode.Search: case SearchAndReplaceMode.Search:
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm")); SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm"));
Get<Button>("findAll").Click += FindAllButtonClicked;
Get<Button>("bookmarkAll").Click += BookmarkAllButtonClicked; Get<Button>("bookmarkAll").Click += BookmarkAllButtonClicked;
Get<Button>("findAll").Click += FindAllButtonClicked;
break; break;
case SearchAndReplaceMode.Replace: case SearchAndReplaceMode.Replace:
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.ReplacePanel.xfrm")); SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.ReplacePanel.xfrm"));
@ -50,10 +50,12 @@ namespace SearchAndReplace
break; break;
} }
Get<ComboBox>("find").TextChanged += FindPatternChanged;
ControlDictionary["findNextButton"].Click += FindNextButtonClicked; ControlDictionary["findNextButton"].Click += FindNextButtonClicked;
ControlDictionary["lookInBrowseButton"].Click += LookInBrowseButtonClicked; ControlDictionary["lookInBrowseButton"].Click += LookInBrowseButtonClicked;
((Form)Parent).AcceptButton = (Button)ControlDictionary["findNextButton"]; ((Form)Parent).AcceptButton = (Button)ControlDictionary["findNextButton"];
SetOptions(); SetOptions();
EnableButtons(HasFindPattern);
RightToLeftConverter.ReConvertRecursive(this); RightToLeftConverter.ReConvertRecursive(this);
ResumeLayout(false); ResumeLayout(false);
} }
@ -440,5 +442,41 @@ namespace SearchAndReplace
ignoreSelectionChanges = false; ignoreSelectionChanges = false;
} }
} }
/// <summary>
/// Enables the various find, bookmark and replace buttons
/// depending on whether any find string has been entered. The buttons
/// are disabled otherwise.
/// </summary>
void EnableButtons(bool enabled)
{
if (searchAndReplaceMode == SearchAndReplaceMode.Replace) {
Get<Button>("replace").Enabled = enabled;
Get<Button>("replaceAll").Enabled = enabled;
} else {
Get<Button>("bookmarkAll").Enabled = enabled;
Get<Button>("findAll").Enabled = enabled;
}
ControlDictionary["findNextButton"].Enabled = enabled;
}
/// <summary>
/// Returns true if the string entered in the find or replace text box
/// is not an empty string.
/// </summary>
bool HasFindPattern {
get {
return Get<ComboBox>("find").Text.Length != 0;
}
}
/// <summary>
/// Updates the enabled/disabled state of the search and replace buttons
/// after the search or replace text has changed.
/// </summary>
void FindPatternChanged(object source, EventArgs e)
{
EnableButtons(HasFindPattern);
}
} }
} }

Loading…
Cancel
Save