public SshProfilesPageViewModel(ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, ITrayProcessCommunicationService trayProcessCommunicationService, IApplicationDataContainer historyContainer) { _settingsService = settingsService; _dialogService = dialogService; _fileSystemService = fileSystemService; _applicationView = applicationView; _trayProcessCommunicationService = trayProcessCommunicationService; _historyContainer = historyContainer; CreateSshProfileCommand = new RelayCommand(CreateSshProfile); CloneCommand = new RelayCommand <SshProfileViewModel>(Clone); foreach (var sshProfile in _settingsService.GetSshProfiles()) { var viewModel = new SshProfileViewModel(sshProfile, settingsService, dialogService, fileSystemService, applicationView, _trayProcessCommunicationService, historyContainer, false); viewModel.Deleted += OnSshProfileDeleted; SshProfiles.Add(viewModel); } if (SshProfiles.Count == 0) { CreateSshProfile(); } SelectedSshProfile = SshProfiles.First(); }
private void OnSshProfileDeleted(object sender, EventArgs e) { if (sender is SshProfileViewModel sshProfile) { if (SelectedSshProfile == sshProfile) { SelectedSshProfile = SshProfiles.First(); } SshProfiles.Remove(sshProfile); _settingsService.DeleteSshProfile(sshProfile.Id); } }
private void OnSshProfileDeleted(object sender, EventArgs e) { if (sender is SshProfileViewModel shellProfile) { if (SelectedSshProfile == shellProfile) { SelectedSshProfile = SshProfiles.First(); } SshProfiles.Remove(shellProfile); if (shellProfile.IsDefault) { SshProfiles.First().IsDefault = true; _settingsService.SaveDefaultSshProfileId(SshProfiles.First().Id); } _settingsService.DeleteSshProfile(shellProfile.Id); } }
public SshProfilesPageViewModel(ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, ITrayProcessCommunicationService trayProcessCommunicationService) { _settingsService = settingsService; _dialogService = dialogService; _fileSystemService = fileSystemService; _applicationView = applicationView; _trayProcessCommunicationService = trayProcessCommunicationService; CreateSshProfileCommand = new RelayCommand(CreateSshProfile); CloneCommand = new RelayCommand <SshProfileViewModel>(Clone); var defaultSshProfileId = _settingsService.GetDefaultSshProfileId(); foreach (var sshProfile in _settingsService.GetSshProfiles()) { var viewModel = new SshProfileViewModel(sshProfile, settingsService, dialogService, fileSystemService, applicationView, _trayProcessCommunicationService, false); viewModel.Deleted += OnSshProfileDeleted; viewModel.SetAsDefault += OnSshProfileSetAsDefault; if (sshProfile.Id == defaultSshProfileId) { viewModel.IsDefault = true; } SshProfiles.Add(viewModel); } if (SshProfiles.Count == 0) { CreateSshProfile(); } SelectedSshProfile = SshProfiles.FirstOrDefault(p => p.IsDefault); if (SelectedSshProfile == null) { SelectedSshProfile = SshProfiles.First(); } }