public TerminalViewModel(int id, ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, string startupDirectory, ShellProfile shellProfile)
        {
            Id    = id;
            Title = DefaultTitle;

            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.KeyBindingsChanged         += OnKeyBindingsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _keyboardCommandService = keyboardCommandService;
            _applicationSettings    = applicationSettings;
            _startupDirectory       = startupDirectory;
            _shellProfile           = shellProfile;
            _resizeOverlayTimer     = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 2)
            };
            _resizeOverlayTimer.Tick += OnResizeOverlayTimerFinished;

            CloseCommand            = new RelayCommand(async() => await InvokeCloseRequested().ConfigureAwait(false));
            FindNextCommand         = new RelayCommand(async() => await FindNext().ConfigureAwait(false));
            FindPreviousCommand     = new RelayCommand(async() => await FindPrevious().ConfigureAwait(false));
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);

            _dispatcher = CoreApplication.GetCurrentView().Dispatcher;
        }
Esempio n. 2
0
        /// <summary>
        /// to be called by view when ready
        /// </summary>
        /// <param name="shellProfile"></param>
        /// <param name="size"></param>
        /// <param name="sessionType"></param>
        public async Task <TerminalResponse> StartShellProcess(ShellProfile shellProfile, TerminalSize size, SessionType sessionType, string termState)
        {
            if (!_requireShellProcessStart && !string.IsNullOrEmpty(termState))
            {
                OutputReceived?.Invoke(this, Encoding.UTF8.GetBytes(termState));
            }

            _trayProcessCommunicationService.SubscribeForTerminalOutput(Id, t => OutputReceived?.Invoke(this, t));

            if (_requireShellProcessStart)
            {
                var response = await _trayProcessCommunicationService.CreateTerminal(Id, size, shellProfile, sessionType).ConfigureAwait(true);

                if (response.Success)
                {
                    FallbackTitle = response.ShellExecutableName;
                    SetTitle(FallbackTitle);
                }
                return(response);
            }
            else
            {
                return(await _trayProcessCommunicationService.PauseTerminalOutput(Id, false));
            }
        }
Esempio n. 3
0
        private async Task CreateTerminal(ShellProfile profile, NewTerminalLocation location, ActivationViewSwitcher viewSwitcher = null)
        {
            if (!_alreadyLaunched)
            {
                var viewModel = _container.Resolve <MainViewModel>();
                await viewModel.AddTerminalAsync(profile);
                await CreateMainView(typeof(MainPage), viewModel, true).ConfigureAwait(true);
            }
            else if (location == NewTerminalLocation.Tab && _mainViewModels.Count > 0)
            {
                MainViewModel item = _mainViewModels.FirstOrDefault(o => o.ApplicationView.Id == _activeWindowId);
                if (item == null)
                {
                    item = _mainViewModels.Last();
                }

                await item.AddTerminalAsync(profile);
                await ShowAsStandaloneAsync(item, viewSwitcher);
            }
            else
            {
                var viewModel = await CreateNewTerminalWindow().ConfigureAwait(true);

                await viewModel.AddTerminalAsync(profile);
                await ShowAsStandaloneAsync(viewModel, viewSwitcher);
            }
        }
Esempio n. 4
0
 public void Migrate(ShellProfile profile)
 {
     while (profile.MigrationVersion < ShellProfile.CurrentMigrationVersion)
     {
         ApplyMigrationStep(profile, profile.MigrationVersion + 1);
     }
 }
        public ShellProfileViewModel(ShellProfile shellProfile, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService)
        {
            _shellProfile      = shellProfile;
            _settingsService   = settingsService;
            _dialogService     = dialogService;
            _fileSystemService = fileSystemService;

            TabThemes = new ObservableCollection <TabTheme>(settingsService.GetTabThemes());

            Id               = shellProfile.Id;
            Name             = shellProfile.Name;
            Arguments        = shellProfile.Arguments;
            Location         = shellProfile.Location;
            WorkingDirectory = shellProfile.WorkingDirectory;
            SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id == shellProfile.TabThemeId);
            PreInstalled     = shellProfile.PreInstalled;

            SetDefaultCommand                = new RelayCommand(SetDefault);
            DeleteCommand                    = new AsyncCommand(Delete, CanDelete);
            EditCommand                      = new RelayCommand(Edit);
            CancelEditCommand                = new AsyncCommand(CancelEdit);
            SaveChangesCommand               = new RelayCommand(SaveChanges);
            BrowseForCustomShellCommand      = new AsyncCommand(BrowseForCustomShell);
            BrowseForWorkingDirectoryCommand = new AsyncCommand(BrowseForWorkingDirectory);
        }
Esempio n. 6
0
 private string GetWorkingDirectory(ShellProfile configuration)
 {
     if (string.IsNullOrWhiteSpace(configuration.WorkingDirectory) || !Directory.Exists(configuration.WorkingDirectory))
     {
         return(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
     }
     return(configuration.WorkingDirectory);
 }
        public ShellProfileSelectionDialog(ISettingsService settingsService)
        {
            Profiles        = settingsService.GetShellProfiles();
            SelectedProfile = Profiles.First();
            this.InitializeComponent();
            var currentTheme = settingsService.GetCurrentTheme();

            RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background);
        }
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, ShellProfile shellProfile,
                                 IApplicationView applicationView, IClipboardService clipboardService, string terminalState = null)
        {
            MessengerInstance.Register <ApplicationSettingsChangedMessage>(this, OnApplicationSettingsChanged);
            MessengerInstance.Register <CurrentThemeChangedMessage>(this, OnCurrentThemeChanged);
            MessengerInstance.Register <TerminalOptionsChangedMessage>(this, OnTerminalOptionsChanged);
            MessengerInstance.Register <KeyBindingsChangedMessage>(this, OnKeyBindingsChanged);

            SettingsService = settingsService;

            _terminalOptions = SettingsService.GetTerminalOptions();

            TrayProcessCommunicationService = trayProcessCommunicationService;

            DialogService           = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            ApplicationView         = applicationView;
            ClipboardService        = clipboardService;

            ShellProfile  = shellProfile;
            TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId);

            TabThemes = new ObservableCollection <TabTheme>(SettingsService.GetTabThemes());
            TabTheme  = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

            CloseCommand            = new AsyncCommand(TryCloseAsync, CanExecuteCommand);
            CloseLeftTabsCommand    = new RelayCommand(CloseLeftTabs, CanExecuteCommand);
            CloseRightTabsCommand   = new RelayCommand(CloseRightTabs, CanExecuteCommand);
            CloseOtherTabsCommand   = new RelayCommand(CloseOtherTabs, CanExecuteCommand);
            FindNextCommand         = new RelayCommand(FindNext, CanExecuteCommand);
            FindPreviousCommand     = new RelayCommand(FindPrevious, CanExecuteCommand);
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel, CanExecuteCommand);
            SelectTabThemeCommand   = new RelayCommand <string>(SelectTabTheme, CanExecuteCommand);
            EditTitleCommand        = new AsyncCommand(EditTitleAsync, CanExecuteCommand);
            DuplicateTabCommand     = new RelayCommand(DuplicateTab, CanExecuteCommand);
            CopyCommand             = new AsyncCommand(Copy, () => HasSelection);
            PasteCommand            = new AsyncCommand(Paste);
            CopyLinkCommand         = new AsyncCommand(() => CopyTextAsync(HoveredUri), () => !string.IsNullOrWhiteSpace(HoveredUri));
            ShowSearchPanelCommand  = new RelayCommand(() => ShowSearchPanel = true, () => !ShowSearchPanel);
            if (!string.IsNullOrEmpty(terminalState))
            {
                Restore(terminalState);
            }

            Terminal = new Terminal(TrayProcessCommunicationService, _terminalId);
            Terminal.KeyboardCommandReceived += Terminal_KeyboardCommandReceived;
            Terminal.OutputReceived          += Terminal_OutputReceived;
            Terminal.SizeChanged             += Terminal_SizeChanged;
            Terminal.TitleChanged            += Terminal_TitleChanged;
            Terminal.Exited += Terminal_Exited;
            Terminal.Closed += Terminal_Closed;

            ContextMenu = BuidContextMenu();
        }
Esempio n. 9
0
        private void AddShellProfile(ShellProfile shellProfile)
        {
            var viewModel = new ShellProfileViewModel(shellProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider, true);

            viewModel.EditCommand.Execute(null);
            viewModel.SetAsDefault += OnShellProfileSetAsDefault;
            viewModel.Deleted      += OnShellProfileDeleted;
            ShellProfiles.Add(viewModel);
            SelectedShellProfile = viewModel;
        }
Esempio n. 10
0
        private void Clone(ShellProfileViewModel shellProfile)
        {
            var cloned = new ShellProfile(shellProfile.Model)
            {
                Id           = Guid.NewGuid(),
                PreInstalled = false,
                Name         = $"Copy of {shellProfile.Name}"
            };

            AddShellProfile(cloned);
        }
Esempio n. 11
0
        /// <summary>
        /// to be called by view when ready
        /// </summary>
        /// <param name="shellProfile"></param>
        /// <param name="size"></param>
        /// <param name="sessionType"></param>
        public async Task StartShellProcess(ShellProfile shellProfile, TerminalSize size, SessionType sessionType)
        {
            _trayProcessCommunicationService.SubscribeForTerminalOutput(Id, t => OutputReceived?.Invoke(this, t));
            var response = await _trayProcessCommunicationService.CreateTerminal(Id, size, shellProfile, sessionType).ConfigureAwait(true);

            if (response.Success)
            {
                FallbackTitle = response.ShellExecutableName;
                SetTitle(FallbackTitle);
            }
        }
Esempio n. 12
0
        public void MarkUsed(ShellProfile profile)
        {
            var history = GetRawHistory();

            var existing = history.FirstOrDefault(c =>
                                                  string.Equals(c.Value, profile.Name, StringComparison.OrdinalIgnoreCase));

            if (existing == null)
            {
                existing = new ExecutedCommand
                {
                    Value     = profile.Name,
                    IsProfile = GetAllProfiles().Any(p =>
                                                     string.Equals(p.Name, profile.Name, StringComparison.OrdinalIgnoreCase))
                };

                if (!existing.IsProfile)
                {
                    existing.ShellProfile = profile;
                }

                var overflow = history.Count - MaxHistory + 1;

                if (overflow > 0)
                {
                    // We already have max number of commands in history, so we need to delete some
                    // Let's first try with cleanup
                    CleanupHistory();

                    overflow = history.Count - MaxHistory + 1;

                    if (overflow > 0)
                    {
                        // We will remove the oldest commands
                        var toRemove = history.OrderBy(c => c.LastExecution).ThenBy(c => c.ExecutionCount)
                                       .Take(overflow).ToList();

                        foreach (var command in toRemove)
                        {
                            history.Remove(command);

                            Delete(command);
                        }
                    }
                }

                history.Add(existing);
            }

            existing.LastExecution = DateTime.UtcNow;
            existing.ExecutionCount++;

            Save(existing);
        }
        private void CreateShellProfile()
        {
            var shellProfile = new ShellProfile
            {
                Id           = Guid.NewGuid(),
                PreInstalled = false,
                Name         = "New profile",
                KeyBindings  = new List <KeyBinding>()
            };

            AddShellProfile(shellProfile);
        }
        public async Task <CreateTerminalResponse> CreateTerminal(TerminalSize size, ShellProfile shellProfile)
        {
            var request = new CreateTerminalRequest
            {
                Size    = size,
                Profile = shellProfile
            };

            var responseMessage = await _appServiceConnection.SendMessageAsync(CreateMessage(request));

            return(JsonConvert.DeserializeObject <CreateTerminalResponse>(responseMessage[MessageKeys.Content]));
        }
Esempio n. 15
0
        public void SaveShellProfile(ShellProfile shellProfile, bool newShell = false)
        {
            _shellProfiles.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile);

            // When saving the shell profile, we also need to update keybindings for everywhere.
            KeyBindingsChanged?.Invoke(this, System.EventArgs.Empty);

            if (newShell)
            {
                ShellProfileAdded?.Invoke(this, shellProfile);
            }
        }
Esempio n. 16
0
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, ShellProfile shellProfile,
                                 IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService, string terminalState = null)
        {
            SettingsService = settingsService;
            SettingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            SettingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            SettingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            SettingsService.KeyBindingsChanged         += OnKeyBindingsChanged;

            _terminalOptions = SettingsService.GetTerminalOptions();

            TrayProcessCommunicationService = trayProcessCommunicationService;

            DialogService           = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            ApplicationView         = applicationView;
            ClipboardService        = clipboardService;

            ShellProfile  = shellProfile;
            TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId);

            TabThemes = new ObservableCollection <TabTheme>(SettingsService.GetTabThemes());
            TabTheme  = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

            CloseCommand            = new RelayCommand(async() => await TryClose().ConfigureAwait(false));
            CloseLeftTabsCommand    = new RelayCommand(CloseLeftTabs);
            CloseRightTabsCommand   = new RelayCommand(CloseRightTabs);
            CloseOtherTabsCommand   = new RelayCommand(CloseOtherTabs);
            FindNextCommand         = new RelayCommand(FindNext);
            FindPreviousCommand     = new RelayCommand(FindPrevious);
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);
            SelectTabThemeCommand   = new RelayCommand <string>(SelectTabTheme);
            EditTitleCommand        = new AsyncCommand(EditTitle);
            DuplicateTabCommand     = new RelayCommand(DuplicateTab);

            if (!String.IsNullOrEmpty(terminalState))
            {
                Restore(terminalState);
            }

            Terminal = new Terminal(TrayProcessCommunicationService, _terminalId);
            Terminal.KeyboardCommandReceived += Terminal_KeyboardCommandReceived;
            Terminal.OutputReceived          += Terminal_OutputReceived;
            Terminal.SizeChanged             += Terminal_SizeChanged;
            Terminal.TitleChanged            += Terminal_TitleChanged;
            Terminal.Exited += Terminal_Exited;
            Terminal.Closed += Terminal_Closed;

            Overlay = new OverlayViewModel(dispatcherTimer);
        }
Esempio n. 17
0
        private void CreateShellProfile()
        {
            var shellProfile = new ShellProfile
            {
                Id           = Guid.NewGuid(),
                PreInstalled = false,
                Name         = "New profile",
                KeyBindings  = new List <KeyBinding>(),
                UseConPty    = _settingsService.GetApplicationSettings().UseConPty
            };

            AddShellProfile(shellProfile);
        }
        public async Task <ShellProfile> GetCustomCommandAsync(ShellProfile input = null)
        {
            ViewModel = new CommandProfileProviderViewModel(_settingsService, _applicationView,
                                                            _trayProcessCommunicationService, _historyService, input);

            SetupFocus();

            _showDialogOperation = ShowAsync();

            var result = await _showDialogOperation.AsTask().ContinueWith(t => _dialogResult);

            return(result != ContentDialogResult.Primary ? null : ViewModel.Model);
        }
        public ShellProfileSelectionDialog(ISettingsService settingsService)
        {
            Profiles = new ObservableCollection <ShellProfile>(settingsService.GetAllProfiles().OrderBy(p => p.Name));

            SelectedProfile = Profiles.First();

            InitializeComponent();

            PrimaryButtonText   = I18N.TranslateWithFallback("OK", "OK");
            SecondaryButtonText = I18N.TranslateWithFallback("Cancel", "Cancel");

            var currentTheme = settingsService.GetCurrentTheme();

            RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background);
        }
Esempio n. 20
0
        private void UpdateDefaultShellProfile()
        {
            var defaultProfile = _settingsService.GetDefaultShellProfile();

            // We need to rebuild the menu only if default profile Id or Name is changed
            var changeMenu = _defaultProfile == null || !_defaultProfile.Id.Equals(defaultProfile.Id) ||
                             !string.Equals(_defaultProfile.Name, defaultProfile.Name, StringComparison.Ordinal);

            _defaultProfile = defaultProfile;

            if (changeMenu)
            {
                ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true);
            }
        }
        public Task <ShellProfile> GetCustomCommandAsync(ShellProfile input = null)
        {
            ViewModel = new CommandProfileProviderViewModel(_settingsService, _applicationView,
                                                            _trayProcessCommunicationService, _historyService, input);

            SetupFocus();

            _showDialogOperation = ShowAsync();

            return(_showDialogOperation.AsTask().ContinueWith(t =>
                                                              (t.Status == TaskStatus.Canceled || t.Status == TaskStatus.RanToCompletion) &&
                                                              _dialogResult == ContentDialogResult.Primary
                    ? ViewModel.Model
                    : null));
        }
Esempio n. 22
0
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, string startupDirectory, ShellProfile shellProfile,
                                 IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            SettingsService = settingsService;
            SettingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            SettingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            SettingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            SettingsService.KeyBindingsChanged         += OnKeyBindingsChanged;

            TrayProcessCommunicationService = trayProcessCommunicationService;

            DialogService           = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            StartupDirectory        = startupDirectory;
            ApplicationView         = applicationView;
            ClipboardService        = clipboardService;

            ShellProfile  = shellProfile;
            TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId);

            TabThemes = new ObservableCollection <TabTheme>(SettingsService.GetTabThemes());
            TabTheme  = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

            _resizeOverlayTimer          = dispatcherTimer;
            _resizeOverlayTimer.Interval = new TimeSpan(0, 0, 2);
            _resizeOverlayTimer.Tick    += OnResizeOverlayTimerFinished;

            CloseCommand            = new RelayCommand(async() => await TryClose().ConfigureAwait(false));
            FindNextCommand         = new RelayCommand(FindNext);
            FindPreviousCommand     = new RelayCommand(FindPrevious);
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);
            SelectTabThemeCommand   = new RelayCommand <string>(SelectTabTheme);
            EditTitleCommand        = new AsyncCommand(EditTitle);

            if (!string.IsNullOrWhiteSpace(StartupDirectory))
            {
                ShellProfile.WorkingDirectory = StartupDirectory;
            }

            Terminal = new Terminal(TrayProcessCommunicationService);
            Terminal.KeyboardCommandReceived += Terminal_KeyboardCommandReceived;
            Terminal.OutputReceived          += Terminal_OutputReceived;
            Terminal.SizeChanged             += Terminal_SizeChanged;
            Terminal.TitleChanged            += Terminal_TitleChanged;
            Terminal.Closed += Terminal_Closed;
        }
        public async Task <ShellProfile> GetCustomCommandAsync(ShellProfile input = null)
        {
            ViewModel = new CommandProfileProviderViewModel(_settingsService, _applicationView,
                                                            _trayProcessCommunicationService, _historyContainer, input);

            SetupFocus();

            if (await ShowAsync() != ContentDialogResult.Primary)
            {
                return(null);
            }

            ViewModel.Model.Tag = new DelayedHistorySaver(ViewModel);

            return(ViewModel.Model);
        }
Esempio n. 24
0
        public void SaveShellProfile(ShellProfile shellProfile, bool newShell = false)
        {
            _shellProfiles.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile);

            // When saving the shell profile, we also need to update keybindings for everywhere.
            Messenger.Default.Send(new KeyBindingsChangedMessage());

            if (newShell)
            {
                Messenger.Default.Send(new ShellProfileAddedMessage(shellProfile));
            }
            else
            {
                Messenger.Default.Send(new ShellProfileChangedMessage(shellProfile));
            }
        }
Esempio n. 25
0
        private void InitializeViewModelProperties(ShellProfile shellProfile)
        {
            SelectedTerminalTheme = TerminalThemes.FirstOrDefault(t => t.Id == shellProfile.TerminalThemeId);
            Id               = shellProfile.Id;
            Name             = shellProfile.Name;
            Arguments        = shellProfile.Arguments;
            Location         = shellProfile.Location;
            WorkingDirectory = shellProfile.WorkingDirectory;
            SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id == shellProfile.TabThemeId);
            PreInstalled     = shellProfile.PreInstalled;

            KeyBindings.Clear();
            foreach (var keyBinding in shellProfile.KeyBindings.Select(x => new KeyBinding(x)).ToList())
            {
                KeyBindings.Add(keyBinding);
            }
        }
        public async Task <ShellProfile> GetCustomCommandAsync(ShellProfile input = null)
        {
            var vm = new CommandProfileProviderViewModel(_settingsService, _applicationView,
                                                         _trayProcessCommunicationService, _historyContainer, input);

            DataContext = vm;

            if (await ShowAsync() != ContentDialogResult.Primary)
            {
                return(null);
            }

            vm = (CommandProfileProviderViewModel)DataContext;

            vm.SaveToHistory();

            return(vm.Model);
        }
        public async Task <CreateTerminalResponse> CreateTerminal(TerminalSize size, ShellProfile shellProfile)
        {
            var request = new CreateTerminalRequest
            {
                Size    = size,
                Profile = shellProfile
            };

            var message = new ValueSet
            {
                { MessageKeys.Type, MessageTypes.CreateTerminalRequest },
                { MessageKeys.Content, JsonConvert.SerializeObject(request) }
            };

            var responseMessage = await _appServiceConnection.SendMessageAsync(message);

            return(JsonConvert.DeserializeObject <CreateTerminalResponse>((string)responseMessage.Message[MessageKeys.Content]));
        }
Esempio n. 28
0
        private async Task CreateTerminal(ShellProfile profile, NewTerminalLocation location)
        {
            if (!_alreadyLaunched)
            {
                var viewModel = _container.Resolve <MainViewModel>();
                viewModel.AddTerminal(profile);
                await CreateMainView(typeof(MainPage), viewModel, true).ConfigureAwait(true);
            }
            else if (location == NewTerminalLocation.Tab && _mainViewModels.Count > 0)
            {
                _mainViewModels.Last().AddTerminal(profile);
            }
            else
            {
                var viewModel = await CreateNewTerminalWindow().ConfigureAwait(true);

                viewModel.AddTerminal(profile);
            }
        }
Esempio n. 29
0
        private void CreateShellProfile()
        {
            var shellProfile = new ShellProfile
            {
                Id           = Guid.NewGuid(),
                PreInstalled = false,
                Name         = "New profile"
            };

            _settingsService.SaveShellProfile(shellProfile);

            var viewModel = new ShellProfileViewModel(shellProfile, _settingsService, _dialogService);

            viewModel.EditCommand.Execute(null);
            viewModel.SetAsDefault += OnShellProfileSetAsDefault;
            viewModel.Deleted      += OnShellProfileDeleted;
            ShellProfiles.Add(viewModel);
            SelectedShellProfile = viewModel;
        }
        public ShellProfileViewModel(ShellProfile shellProfile, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, IDefaultValueProvider defaultValueProvider, Boolean isNew)
        {
            Model                 = shellProfile;
            _settingsService      = settingsService;
            _dialogService        = dialogService;
            _fileSystemService    = fileSystemService;
            _applicationView      = applicationView;
            _defaultValueProvider = defaultValueProvider;
            _isNew                = isNew;

            _settingsService.ThemeAdded   += OnThemeAdded;
            _settingsService.ThemeDeleted += OnThemeDeleted;

            TabThemes = new ObservableCollection <TabTheme>(settingsService.GetTabThemes());

            TerminalThemes = new ObservableCollection <TerminalTheme>
            {
                new TerminalTheme
                {
                    Id   = Guid.Empty,
                    Name = "Default"
                }
            };
            foreach (var theme in _settingsService.GetThemes())
            {
                TerminalThemes.Add(theme);
            }

            KeyBindings = new KeyBindingsViewModel(shellProfile.Id.ToString(), _dialogService, string.Empty, false);

            InitializeViewModelProperties(shellProfile);

            SetDefaultCommand                = new RelayCommand(SetDefault);
            DeleteCommand                    = new AsyncCommand(Delete, CanDelete);
            EditCommand                      = new RelayCommand(Edit);
            CancelEditCommand                = new AsyncCommand(CancelEdit);
            SaveChangesCommand               = new RelayCommand(SaveChanges);
            AddKeyboardShortcutCommand       = new AsyncCommand(AddKeyboardShortcut);
            BrowseForCustomShellCommand      = new AsyncCommand(BrowseForCustomShell);
            BrowseForWorkingDirectoryCommand = new AsyncCommand(BrowseForWorkingDirectory);
            RestoreDefaultsCommand           = new AsyncCommand(RestoreDefaults);
        }