Skip to content
Permalink
Browse files

Add keybinding for configurable new window (#216)

* Add keybind to open new configurable window

* Close new configurable window on cancel

* renamed event args
  • Loading branch information...
ericcornelissen authored and felixse committed Feb 28, 2019
1 parent ea21d37 commit c4fcd986c0cfec698b965f92cdbd057db7166563
@@ -0,0 +1,7 @@
namespace FluentTerminal.App.Services.EventArgs
{
public class NewWindowRequestedEventArgs : System.EventArgs
{
public bool ShowProfileSelection { get; set; }
}
}
@@ -156,6 +156,19 @@ public ICollection<KeyBinding> GetDefaultKeyBindings(Command command)
}
};

case Command.ConfigurableNewWindow:
return new List<KeyBinding>
{
new KeyBinding
{
Command = nameof(Command.ConfigurableNewWindow),
Ctrl = true,
Alt = false,
Shift = true,
Key = (int)ExtendedVirtualKey.N
}
};

case Command.ShowSettings:
return new List<KeyBinding>
{
@@ -60,7 +60,9 @@ public class MainViewModel : ViewModelBase
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
_keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), NewWindow);
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), () => NewWindow(false));
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewWindow), () => NewWindow(true));

_keyboardCommandService.RegisterCommandHandler(nameof(Command.ShowSettings), ShowSettings);
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ToggleFullScreen), ToggleFullScreen);

@@ -102,7 +104,7 @@ private void OnTerminalsCollectionChanged(object sender, NotifyCollectionChanged

public event EventHandler Closed;

public event EventHandler NewWindowRequested;
public event EventHandler<NewWindowRequestedEventArgs> NewWindowRequested;

public event EventHandler ShowSettingsRequested;

@@ -180,13 +182,20 @@ public Task AddTerminal(string startupDirectory, bool showProfileSelection, Guid

if (profile == null)
{
if (Terminals.Count == 0)
{
Closed?.Invoke(this, EventArgs.Empty);
_applicationView.TryClose();
}

return;
}
}
else if (profileId == Guid.Empty)
{
profile = _settingsService.GetDefaultShellProfile();
} else
}
else
{
profile = _settingsService.GetShellProfile(profileId);
}
@@ -213,9 +222,14 @@ private void CloseCurrentTab()
SelectedTerminal?.CloseCommand.Execute(null);
}

private void NewWindow()
private void NewWindow(bool showProfileSelection)
{
NewWindowRequested?.Invoke(this, EventArgs.Empty);
var args = new NewWindowRequestedEventArgs
{
ShowProfileSelection = showProfileSelection
};

NewWindowRequested?.Invoke(this, args);
}

private async void OnApplicationSettingsChanged(object sender, ApplicationSettings e)
@@ -4,6 +4,7 @@
using FluentTerminal.App.Services;
using FluentTerminal.App.Services.Adapters;
using FluentTerminal.App.Services.Dialogs;
using FluentTerminal.App.Services.EventArgs;
using FluentTerminal.App.Services.Implementation;
using FluentTerminal.App.ViewModels;
using FluentTerminal.App.Views;
@@ -119,7 +120,7 @@ protected override async void OnActivated(IActivatedEventArgs args)
}
else
{
await CreateNewTerminalWindow(parameter).ConfigureAwait(true);
await CreateNewTerminalWindow(parameter, false).ConfigureAwait(true);
}
}
}
@@ -151,7 +152,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
}
else if (_mainViewModels.Count == 0)
{
await CreateSecondaryView<MainViewModel>(typeof(MainPage), true, string.Empty).ConfigureAwait(true);
await CreateSecondaryView<MainViewModel>(typeof(MainPage), true, false, string.Empty).ConfigureAwait(true);
}
}

@@ -212,13 +213,13 @@ private async Task CreateMainView(Type pageType, INotifyPropertyChanged viewMode
Window.Current.Activate();
}

private async Task CreateNewTerminalWindow(string startupDirectory)
private async Task CreateNewTerminalWindow(string startupDirectory, bool showProfileSelection)
{
var id = await CreateSecondaryView<MainViewModel>(typeof(MainPage), true, startupDirectory).ConfigureAwait(true);
var id = await CreateSecondaryView<MainViewModel>(typeof(MainPage), true, showProfileSelection, startupDirectory).ConfigureAwait(true);
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id);
}

private async Task<int> CreateSecondaryView<TViewModel>(Type pageType, bool ExtendViewIntoTitleBar, object parameter)
private async Task<int> CreateSecondaryView<TViewModel>(Type pageType, bool ExtendViewIntoTitleBar, bool showProfileSelection, object parameter)
{
int windowId = 0;
TViewModel viewModel = default;
@@ -242,7 +243,7 @@ private async Task<int> CreateSecondaryView<TViewModel>(Type pageType, bool Exte
mainViewModel.ShowSettingsRequested += OnShowSettingsRequested;
mainViewModel.ShowAboutRequested += OnShowAboutRequested;
_mainViewModels.Add(mainViewModel);
await mainViewModel.AddTerminal(directory, false, Guid.Empty).ConfigureAwait(true);
await mainViewModel.AddTerminal(directory, showProfileSelection, Guid.Empty).ConfigureAwait(true);
}

if (viewModel is SettingsViewModel settingsViewModel)
@@ -271,9 +272,9 @@ private void OnMainViewModelClosed(object sender, EventArgs e)
}
}

private async void OnNewWindowRequested(object sender, EventArgs e)
private async void OnNewWindowRequested(object sender, NewWindowRequestedEventArgs e)
{
await CreateNewTerminalWindow(string.Empty).ConfigureAwait(true);
await CreateNewTerminalWindow(string.Empty, e.ShowProfileSelection).ConfigureAwait(true);
}

private void OnSettingsClosed(object sender, EventArgs e)
@@ -303,7 +304,7 @@ private async Task ShowSettings()
{
if (_settingsViewModel == null)
{
_settingsWindowId = await CreateSecondaryView<SettingsViewModel>(typeof(SettingsPage), true, null).ConfigureAwait(true);
_settingsWindowId = await CreateSecondaryView<SettingsViewModel>(typeof(SettingsPage), true, false, null).ConfigureAwait(true);
}
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(_settingsWindowId.Value);
}
@@ -28,6 +28,9 @@ public enum Command
[Description("New window")]
NewWindow,

[Description("Configurable new window")]
ConfigurableNewWindow,

[Description("Show settings")]
ShowSettings,

@@ -12,6 +12,7 @@ public class KeyBindings
public ICollection<KeyBinding> ChangeTabTitle { get; set; }
public ICollection<KeyBinding> CloseTab { get; set; }
public ICollection<KeyBinding> NewWindow { get; set; }
public ICollection<KeyBinding> ConfigurableNewWindow { get; set; }
public ICollection<KeyBinding> ShowSettings { get; set; }
public ICollection<KeyBinding> Copy { get; set; }
public ICollection<KeyBinding> Paste { get; set; }

0 comments on commit c4fcd98

Please sign in to comment.
You can’t perform that action at this time.