private void RemoveServerToTreeView(SettingsServer settingsServer) { var servers = (ObservableCollection <Server>)TV.ItemsSource; Server server = servers.FirstOrDefault(s => s.Url.EqualsIgnoreCase(settingsServer.Url)); servers.Remove(server); }
private void TreeViewDelete_Click(object sender, RoutedEventArgs e) { var item = TV.SelectedItem as TreeItem; if (item != null) { if (this.ShowConfirm("Delete " + item.GetType().Name + " '" + item.DisplayName + "'?") == MessageBoxResult.No) { return; } var server = item as Server; if (server != null) { var settingsServer = new SettingsServer { Url = server.Url }; RemoveServerToTreeView(settingsServer); Settings.RemoveServer(settingsServer); Settings.SerializeToConfiguration(); } else if (item.Delete()) { if (item.Parent != null) { item.Parent.Reload(); } } } }
public Connect(SettingsServer server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } DataContext = server; InitializeComponent(); }
private void AddServerToTreeView(SettingsServer settingsServer) { var server = new Server(); server.DisplayName = settingsServer.Url; server.Cookie = settingsServer.Cookie; var servers = (ObservableCollection <Server>)TV.ItemsSource; servers.Add(server); }
private void Connect_Click(object sender, RoutedEventArgs e) { var server = new SettingsServer(); var dlg = new Connect(server); dlg.Owner = this; if (dlg.ShowDialog().GetValueOrDefault()) { Settings.AddServer(server); Settings.SerializeToConfiguration(); AddServerToTreeView(server); } }
public bool AddServer(SettingsServer server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } SettingsServer existing = GetServer(server.Url); if (existing != null) { return(false); } _servers.Add(server); return(true); }
public bool RemoveServer(SettingsServer server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } SettingsServer existing = GetServer(server.Url); if (existing == null) { return(false); } bool b = _servers.Remove(existing); return(b); }