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. 46
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs
  2. 40
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

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

@ -25,6 +25,10 @@ namespace SearchAndReplace @@ -25,6 +25,10 @@ namespace SearchAndReplace
public static string SearchPattern = 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;
public static void ShowSingleInstance(SearchAndReplaceMode searchAndReplaceMode)
@ -82,6 +86,9 @@ namespace SearchAndReplace @@ -82,6 +86,9 @@ namespace SearchAndReplace
SetSearchAndReplaceMode();
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)
@ -94,29 +101,35 @@ namespace SearchAndReplace @@ -94,29 +101,35 @@ namespace SearchAndReplace
{
if (e.KeyData == Keys.Escape) {
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)
{
if (!searchButton.Checked) {
searchButton.Checked = true;
replaceButton.Checked = false;
SetSearchAndReplaceMode();
Focus();
EnableSearchMode(true);
}
}
void ReplaceButtonClick(object sender, EventArgs e)
{
if (!replaceButton.Checked) {
replaceButton.Checked = true;
searchButton.Checked = false;
SetSearchAndReplaceMode();
Focus();
EnableSearchMode(false);
}
}
void EnableSearchMode(bool enable)
{
searchButton.Checked = enable;
replaceButton.Checked = !enable;
SetSearchAndReplaceMode();
Focus();
}
void SetSearchAndReplaceMode()
{
searchAndReplacePanel.SearchAndReplaceMode = searchButton.Checked ? SearchAndReplaceMode.Search : SearchAndReplaceMode.Replace;
@ -126,5 +139,22 @@ namespace SearchAndReplace @@ -126,5 +139,22 @@ namespace SearchAndReplace
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 @@ -40,8 +40,8 @@ namespace SearchAndReplace
switch (searchAndReplaceMode) {
case SearchAndReplaceMode.Search:
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm"));
Get<Button>("findAll").Click += FindAllButtonClicked;
Get<Button>("bookmarkAll").Click += BookmarkAllButtonClicked;
Get<Button>("findAll").Click += FindAllButtonClicked;
break;
case SearchAndReplaceMode.Replace:
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.ReplacePanel.xfrm"));
@ -50,10 +50,12 @@ namespace SearchAndReplace @@ -50,10 +50,12 @@ namespace SearchAndReplace
break;
}
Get<ComboBox>("find").TextChanged += FindPatternChanged;
ControlDictionary["findNextButton"].Click += FindNextButtonClicked;
ControlDictionary["lookInBrowseButton"].Click += LookInBrowseButtonClicked;
((Form)Parent).AcceptButton = (Button)ControlDictionary["findNextButton"];
SetOptions();
EnableButtons(HasFindPattern);
RightToLeftConverter.ReConvertRecursive(this);
ResumeLayout(false);
}
@ -440,5 +442,41 @@ namespace SearchAndReplace @@ -440,5 +442,41 @@ namespace SearchAndReplace
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