Skip to content

Commit

Permalink
Avoid showing dialog for find next / previous actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandreu committed Jun 30, 2019
1 parent 2b8e22c commit 409564e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion OfficeRibbonXEditor/Interfaces/IContentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface IContentDialogBase

public interface IContentDialog<in TPayload> : IContentDialogBase
{
void OnLoaded(TPayload payload);
bool OnLoaded(TPayload payload);
}
}
3 changes: 2 additions & 1 deletion OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public string Code
}
}

public void OnLoaded(string payload)
public bool OnLoaded(string payload)
{
this.Code = payload;
return true;
}
}
}
13 changes: 6 additions & 7 deletions OfficeRibbonXEditor/ViewModels/FindReplaceDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OfficeRibbonXEditor.ViewModels
{
public class FindReplaceDialogViewModel : DialogBase, IContentDialog<ValueTuple<Scintilla, FindReplaceAction>>
{
private CharacterRange searchRange;
private CharacterRange searchRange = new CharacterRange();

public FindReplaceDialogViewModel()
{
Expand Down Expand Up @@ -576,11 +576,10 @@ public SearchFlags GetSearchFlags()
return sf;
}

public void OnLoaded((Scintilla, FindReplaceAction) payload)
public bool OnLoaded((Scintilla, FindReplaceAction) payload)
{
var (editor, action) = payload;
this.Scintilla = editor;
this.searchRange = new CharacterRange();

switch (action)
{
Expand All @@ -592,13 +591,13 @@ public void OnLoaded((Scintilla, FindReplaceAction) payload)
break;
case FindReplaceAction.FindNext:
this.FindWrapper(false);
this.Close();
break;
return false;
case FindReplaceAction.FindPrevious:
this.FindWrapper(true);
this.Close();
break;
return false;
}

return true;
}

public virtual void MoveDialogAwayFromSelection()
Expand Down
3 changes: 2 additions & 1 deletion OfficeRibbonXEditor/ViewModels/GoToDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public int Target
set => this.Set(ref this.target, value);
}

public void OnLoaded(ScintillaLexer payload)
public bool OnLoaded(ScintillaLexer payload)
{
this.Lexer = payload;
return true;
}

private void ExecuteAcceptCommand()
Expand Down
15 changes: 14 additions & 1 deletion OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public MainWindowViewModel(IMessageBoxService messageBoxService, IFileDialogServ
this.GenerateCallbacksCommand = new RelayCommand(this.ExecuteGenerateCallbacksCommand);
this.GoToCommand = new RelayCommand(this.ExecuteGoToCommand);
this.FindCommand = new RelayCommand(() => this.LaunchDialog<FindReplaceDialogViewModel, (Scintilla, FindReplaceAction)>((this.Lexer.Editor.Scintilla, FindReplaceAction.Find)));
this.FindNextCommand = new RelayCommand(() => this.LaunchDialog<FindReplaceDialogViewModel, (Scintilla, FindReplaceAction)>((this.Lexer.Editor.Scintilla, FindReplaceAction.FindNext)));
this.FindPreviousCommand = new RelayCommand(() => this.LaunchDialog<FindReplaceDialogViewModel, (Scintilla, FindReplaceAction)>((this.Lexer.Editor.Scintilla, FindReplaceAction.FindPrevious)));

this.ReplaceCommand = new RelayCommand(() => this.LaunchDialog<FindReplaceDialogViewModel, (Scintilla, FindReplaceAction)>((this.Lexer.Editor.Scintilla, FindReplaceAction.Replace)));

this.ShowSettingsCommand = new RelayCommand(() => this.LaunchDialog<SettingsDialogViewModel, ScintillaLexer>(this.Lexer));
this.ShowAboutCommand = new RelayCommand(() => this.LaunchDialog<AboutDialogViewModel>(true));
this.RecentFileClickCommand = new RelayCommand<string>(this.FinishOpeningFile);
Expand Down Expand Up @@ -247,6 +251,10 @@ public TreeViewItemViewModel SelectedItem

public RelayCommand FindCommand { get; }

public RelayCommand FindNextCommand { get; }

public RelayCommand FindPreviousCommand { get; }

public RelayCommand ReplaceCommand { get; }

public RelayCommand<string> RecentFileClickCommand { get; }
Expand Down Expand Up @@ -350,7 +358,12 @@ public IContentDialog<TPayload> LaunchDialog<TDialog, TPayload>(TPayload payload
}

var content = (TDialog) baseContent;
content.OnLoaded(payload);
if (!content.OnLoaded(payload))
{
// This might happen if the dialog has an associated instant action for which it doesn't need to stay open, e.g. 'Find Next' in a FindReplaceDialog
return content;
}

this.LaunchingDialog?.Invoke(this, new LaunchDialogEventArgs { Content = content, ShowDialog = showDialog });
if (content.IsUnique)
{
Expand Down
3 changes: 2 additions & 1 deletion OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public SettingsDialogViewModel()
this.AcceptCommand = new RelayCommand(this.AcceptSettings);
}

public void OnLoaded(ScintillaLexer payload)
public bool OnLoaded(ScintillaLexer payload)
{
this.Lexer = payload;
this.LoadCurrent();
return true;
}

public ScintillaLexer Lexer { get; private set; }
Expand Down
8 changes: 4 additions & 4 deletions OfficeRibbonXEditor/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<KeyBinding Key="F" Modifiers="Control" Command="{Binding FindCommand}"/>
<!--TODO: This binding is temporary until the new FindReplaceDialog is fully implemented-->
<KeyBinding Key="F" Modifiers="Control+Shift" Command="{Binding ElementName=Window, Path=FindReplaceDialog, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='ShowFind'}"/>
<KeyBinding Key="F3" Modifiers="Shift" Command="{Binding ElementName=Window, Path=FindReplaceDialog.Window, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='FindPrevious'}"/>
<KeyBinding Key="F3" Command="{Binding ElementName=Window, Path=FindReplaceDialog.Window, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='FindNext'}"/>
<KeyBinding Key="F3" Modifiers="Shift" Command="{Binding FindPreviousCommand}"/>
<KeyBinding Key="F3" Command="{Binding FindNextCommand}"/>
<KeyBinding Key="H" Modifiers="Control" Command="{Binding ReplaceCommand}"/>
<KeyBinding Key="I" Modifiers="Control" Command="{Binding ElementName=Window, Path=FindReplaceDialog, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='ShowIncrementalSearch'}"/>

Expand Down Expand Up @@ -132,14 +132,14 @@
</MenuItem>
<MenuItem Header="Replace..." InputGestureText="Ctrl+H" Command="{Binding ReplaceCommand}"/>
<MenuItem Header="Incremental Search..." InputGestureText="Ctrl+I" Command="{Binding ElementName=Window, Path=FindReplaceDialog, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='ShowIncrementalSearch'}"/>
<MenuItem Header="Find Previous" InputGestureText="Shift+F3" Command="{Binding ElementName=Window, Path=FindReplaceDialog.Window, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='FindPrevious'}">
<MenuItem Header="Find Previous" InputGestureText="Shift+F3" Command="{Binding FindPreviousCommand}">
<MenuItem.Icon>
<Image Source="/Resources/Images/find_previous.png"
Width="{Binding Source={x:Static properties:Settings.Default}, Path=IconSize}"
Height="{Binding Source={x:Static properties:Settings.Default}, Path=IconSize}"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Find Next" InputGestureText="F3" Command="{Binding ElementName=Window, Path=FindReplaceDialog.Window, Converter={StaticResource MethodToCommandConverter}, ConverterParameter='FindNext'}">
<MenuItem Header="Find Next" InputGestureText="F3" Command="{Binding FindNextCommand}">
<MenuItem.Icon>
<Image Source="/Resources/Images/find_next.png"
Width="{Binding Source={x:Static properties:Settings.Default}, Path=IconSize}"
Expand Down

0 comments on commit 409564e

Please sign in to comment.