Ejemplo n.º 1
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ShellProfileAdded          += OnShellProfileAdded;
            _settingsService.ShellProfileDeleted        += OnShellProfileDeleted;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), () => AddTerminal(null, false, Guid.Empty));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), () => AddTerminal(null, true, Guid.Empty));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

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

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), () => AddTerminal(profile.WorkingDirectory, false, profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false, Guid.Empty));
            ShowAboutCommand    = new RelayCommand(ShowAbout);
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
Ejemplo n.º 2
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(Command.NewTab, () => AddTerminal(null, false));
            _keyboardCommandService.RegisterCommandHandler(Command.ConfigurableNewTab, () => AddTerminal(null, true));
            _keyboardCommandService.RegisterCommandHandler(Command.CloseTab, CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NextTab, SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(Command.PreviousTab, SelectPreviousTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NewWindow, NewWindow);
            _keyboardCommandService.RegisterCommandHandler(Command.ShowSettings, ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(Command.ToggleFullScreen, ToggleFullScreen);
            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false));
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            Terminals.CollectionChanged += OnTerminalsCollectionChanged;

            Title = "Fluent Terminal";

            _dispatcher = CoreApplication.GetCurrentView().Dispatcher;
            SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += OnCloseRequest;
        }
Ejemplo n.º 3
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(Command.NewTab, () => AddTerminal(null, false));
            _keyboardCommandService.RegisterCommandHandler(Command.ConfigurableNewTab, () => AddTerminal(null, true));
            _keyboardCommandService.RegisterCommandHandler(Command.CloseTab, CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NextTab, SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(Command.PreviousTab, SelectPreviousTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NewWindow, NewWindow);
            _keyboardCommandService.RegisterCommandHandler(Command.ShowSettings, ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(Command.ToggleFullScreen, ToggleFullScreen);
            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false));
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
Ejemplo n.º 4
0
        private void OnShellProfileAdded(ShellProfileAddedMessage message)
        {
            _keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(),
                                                           async() => await AddProfileByGuidAsync(message.ShellProfile.Id));

            UpdateDefaultShellProfile();
        }
Ejemplo n.º 5
0
        private void OnShellProfileAdded(ShellProfileAddedMessage message)
        {
            _keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(),
                                                           async() => await AddProfileByGuidAsync(message.ShellProfile.Id));

            UpdateDefaultShellProfile();

            ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
        }
Ejemplo n.º 6
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(Command.NewTab, () => AddTerminal(null, false));
            _keyboardCommandService.RegisterCommandHandler(Command.ConfigurableNewTab, () => AddTerminal(null, true));
            _keyboardCommandService.RegisterCommandHandler(Command.CloseTab, CloseCurrentTab);

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                Command switchCmd = Command.SwitchToTerm1 + i;
                int     tabNumber = i;
                Action  handler   = () => SelectTabNumber(tabNumber);
                _keyboardCommandService.RegisterCommandHandler(switchCmd, handler);
            }
            _keyboardCommandService.RegisterCommandHandler(Command.NextTab, SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(Command.PreviousTab, SelectPreviousTab);

            _keyboardCommandService.RegisterCommandHandler(Command.NewWindow, NewWindow);
            _keyboardCommandService.RegisterCommandHandler(Command.ShowSettings, ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(Command.ToggleFullScreen, ToggleFullScreen);
            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false));
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
Ejemplo n.º 7
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IClipboardService clipboardService, ICommandHistoryService commandHistoryService, IAcceleratorKeyValidator acceleratorKeyValidator)
        {
            MessengerInstance.Register <ApplicationSettingsChangedMessage>(this, OnApplicationSettingsChanged);
            MessengerInstance.Register <CurrentThemeChangedMessage>(this, OnCurrentThemeChanged);
            MessengerInstance.Register <ShellProfileAddedMessage>(this, OnShellProfileAdded);
            MessengerInstance.Register <ShellProfileDeletedMessage>(this, OnShellProfileDeleted);
            MessengerInstance.Register <ShellProfileChangedMessage>(this, OnShellProfileChanged);
            MessengerInstance.Register <DefaultShellProfileChangedMessage>(this, OnDefaultShellProfileChanged);
            MessengerInstance.Register <TerminalOptionsChangedMessage>(this, OnTerminalOptionsChanged);
            MessengerInstance.Register <CommandHistoryChangedMessage>(this, OnCommandHistoryChanged);
            MessengerInstance.Register <KeyBindingsChangedMessage>(this, OnKeyBindingChanged);

            _settingsService = settingsService;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService           = dialogService;
            ApplicationView          = applicationView;
            _clipboardService        = clipboardService;
            _keyboardCommandService  = keyboardCommandService;
            _commandHistoryService   = commandHistoryService;
            _acceleratorKeyValidator = acceleratorKeyValidator;

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), async() => await AddDefaultProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshTab), async() => await AddSshProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshWindow), async() => await AddSshProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandTab), async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandWindow), async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), async() => await AddSelectedProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewWindow), async() => await AddSelectedProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async() => await SelectedTerminal.EditTitleAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async() => await AddTabAsync(SelectedTerminal.ShellProfile.Clone()));

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                // ReSharper disable once InconsistentNaming
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

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

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddProfileByGuidAsync(profile.Id));
            }

            foreach (SshProfile profile in _settingsService.GetSshProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddProfileByGuidAsync(profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddDefaultTabCommand = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));

            ApplicationView.CloseRequested += OnCloseRequest;
            ApplicationView.Closed         += OnClosed;
            Terminals.CollectionChanged    += OnTerminalsCollectionChanged;

            LoadKeyBindings();

            _newDefaultTabCommand        = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
            _newDefaultWindowCommand     = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Window));
            _newRemoteTabCommand         = new RelayCommand(async() => await AddSshProfileAsync(NewTerminalLocation.Tab));
            _newRemoteWindowCommand      = new RelayCommand(async() => await AddSshProfileAsync(NewTerminalLocation.Window));
            _newQuickLaunchTabCommand    = new RelayCommand(async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
            _newQuickLaunchWindowCommand = new RelayCommand(async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));

            _settingsCommand = new RelayCommand(ShowSettings);
            _aboutCommand    = new RelayCommand(async() => await _dialogService.ShowAboutDialogAsync());
            _quitCommand     = new AsyncCommand(() => _trayProcessCommunicationService.QuitApplicationAsync());

            _defaultProfile = _settingsService.GetDefaultShellProfile();

            CreateMenuViewModel();
        }
Ejemplo n.º 8
0
 private void OnShellProfileAdded(object sender, ShellProfile e)
 {
     _keyboardCommandService.RegisterCommandHandler(e.Id.ToString(), () => AddTerminal(e.WorkingDirectory, false, e.Id));
 }
Ejemplo n.º 9
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ShellProfileAdded          += OnShellProfileAdded;
            _settingsService.ShellProfileDeleted        += OnShellProfileDeleted;
            _settingsService.SshProfileAdded            += OnSshProfileAdded;
            _settingsService.SshProfileDeleted          += OnSshProfileDeleted;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService          = dialogService;
            ApplicationView         = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), async() => await AddLocalTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshTab), async() => await AddSshTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandTab), async() => await AddCustomCommandTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), async() => await AddConfigurableTerminal());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async() => await SelectedTerminal.EditTitle());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.SavedSshNewTab), async() => await AddSavedSshTerminalAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.SavedSshNewWindow), () => NewWindow(NewWindowAction.ShowSshProfileSelection));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshWindow), () => NewWindow(NewWindowAction.ShowSshInfoDialog));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandWindow), () => NewWindow(NewWindowAction.ShowCustomCommandDialog));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async() => await AddTerminalAsync(SelectedTerminal.ShellProfile.Clone()));

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                // ReSharper disable once InconsistentNaming
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), () => NewWindow(NewWindowAction.StartDefaultLocalTerminal));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewWindow), () => NewWindow(NewWindowAction.ShowProfileSelection));

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

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddLocalTabOrWindowAsync(profile.Id));
            }

            foreach (SshProfile profile in _settingsService.GetSshProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddSshTabOrWindowAsync(profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddLocalShellCommand = new RelayCommand(async() => await AddLocalTabAsync());
            AddSshShellCommand   = new RelayCommand(async() => await AddSshTabAsync());
            AddQuickShellCommand = new RelayCommand(async() => await AddCustomCommandTabAsync());
            ShowAboutCommand     = new RelayCommand(ShowAbout);
            ShowSettingsCommand  = new RelayCommand(ShowSettings);

            ApplicationView.CloseRequested += OnCloseRequest;
            ApplicationView.Closed         += OnClosed;
            Terminals.CollectionChanged    += OnTerminalsCollectionChanged;
        }
Ejemplo n.º 10
0
 private void OnShellProfileAdded(object sender, ShellProfile e)
 {
     _keyboardCommandService.RegisterCommandHandler(e.Id.ToString(), () => AddLocalTabOrWindowAsync(e.Id));
 }
Ejemplo n.º 11
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IClipboardService clipboardService, ICommandHistoryService commandHistoryService)
        {
            _settingsService = settingsService;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService          = dialogService;
            ApplicationView         = applicationView;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _commandHistoryService  = commandHistoryService;

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), async() => await AddDefaultProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshTab), async() => await AddSshProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshWindow), async() => await AddSshProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandTab), async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandWindow), async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async() => await SelectedTerminal.EditTitleAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async() => await AddTabAsync(SelectedTerminal.ShellProfile.Clone()));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ReconnectTab), async() => { if (SelectedTerminal.ReconnectTabCommand.CanExecute(null))
                                                                                                      {
                                                                                                          await SelectedTerminal.ReconnectTabAsync();
                                                                                                      }
                                                           });

            // empty command handlers for copy and paste so that the main window does not execute these when copy keyboard shortcut is used in a popup search panel
            // in such a case an exception would be thrown if no handlers are available so these empty ones mitigate that. Also there is no need for these on the main window anyway
            // so leaving them empty is fine.
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.Paste), () => { });
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.Copy), () => { });

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                // ReSharper disable once InconsistentNaming
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

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

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddProfileByGuidAsync(profile.Id));
            }

            foreach (SshProfile profile in _settingsService.GetSshProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddProfileByGuidAsync(profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            UseAcrylicBackground = options.UseAcrylicBackground;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddDefaultTabCommand = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));

            ApplicationView.CloseRequested += OnCloseRequest;
            ApplicationView.Closed         += OnClosed;
            Terminals.CollectionChanged    += OnTerminalsCollectionChanged;

            LoadKeyBindings();

            _newDefaultTabCommand        = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Tab));
            _newDefaultWindowCommand     = new RelayCommand(async() => await AddDefaultProfileAsync(NewTerminalLocation.Window));
            _newRemoteTabCommand         = new RelayCommand(async() => await AddSshProfileAsync(NewTerminalLocation.Tab));
            _newRemoteWindowCommand      = new RelayCommand(async() => await AddSshProfileAsync(NewTerminalLocation.Window));
            _newQuickLaunchTabCommand    = new RelayCommand(async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Tab));
            _newQuickLaunchWindowCommand = new RelayCommand(async() => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window));

            _settingsCommand = new RelayCommand(ShowSettings);
            _aboutCommand    = new AsyncRelayCommand(_dialogService.ShowAboutDialogAsync);
            _quitCommand     = new AsyncRelayCommand(_trayProcessCommunicationService.QuitApplicationAsync);

            _defaultProfile = _settingsService.GetDefaultShellProfile();

            CreateMenuViewModel();

            WeakReferenceMessenger.Default.RegisterAll(this);
        }
Ejemplo n.º 12
0
 private void OnShellProfileAdded(ShellProfileAddedMessage message)
 {
     _keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(),
                                                    () => AddLocalTabOrWindowAsync(message.ShellProfile.Id));
 }