private void tscbbConnectionsFile_SelectedIndexChanged(object sender, EventArgs e) { var cbbValue = tscbbConnectionsFile.SelectedItem; var connectionFile = cbbValue as ConnectionFile; bool loadConnections = true; // If null, then we selected an action rather than a connection file if (connectionFile == null) { tscbbConnectionsFile.SelectedIndexChanged -= tscbbConnectionsFile_SelectedIndexChanged; tscbbConnectionsFile.SelectedIndex = currentIndex; tscbbConnectionsFile.SelectedIndexChanged += tscbbConnectionsFile_SelectedIndexChanged; // It can be a new file if (cbbValue.ToString() == "<Create new connection file>") { var nfd = new NewConnectionFileDialog(); if (nfd.ShowDialog(this) == DialogResult.OK) { ConnectionManager.ConfigurationFile = nfd.CreatedFilePath; var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, ConnectionsList.Instance.Files.First(f => f.Path == nfd.CreatedFilePath)); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; tsbMoveToExistingFile.Enabled = tscbbConnectionsFile.Items.Count > 3; } else { loadConnections = false; } } // Or an existing file else { var afd = new AddConnectionFileDialog(); if (afd.ShowDialog(this) == DialogResult.OK) { var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, ConnectionsList.Instance.Files.First(f => f.Path == afd.OpenedFilePath)); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; } else { loadConnections = false; } } } else { currentIndex = tscbbConnectionsFile.SelectedIndex; // Or it is a connection file so we load it for the connection manager ConnectionManager.ConfigurationFile = connectionFile.Path; tsbRemoveConnectionList.Enabled = ConnectionManager.Instance.ConnectionsList.Name != "Default"; connectionFile.LastUsed = DateTime.Now; tsbMoveToExistingFile.DropDownItems.Clear(); foreach (var file in ConnectionsList.Instance.Files.OrderBy(k => k.Name)) { if (connectionFile.Path == file.Path) { continue; } tsbMoveToExistingFile.DropDownItems.Add(new ToolStripButton { Text = file.Name, Tag = file, Size = new Size(155,22), AutoSize = true }); } } if (loadConnections) { LoadConnectionFile(); } ConnectionsList.Instance.Save(); }
private void tscbbConnectionsFile_SelectedIndexChanged(object sender, EventArgs e) { var cbbValue = tscbbConnectionsFile.SelectedItem; var connectionFile = cbbValue as ConnectionFile; bool loadConnections = true; // If null, then we selected an action rather than a connection file if (connectionFile == null) { tscbbConnectionsFile.SelectedIndexChanged -= tscbbConnectionsFile_SelectedIndexChanged; tscbbConnectionsFile.SelectedIndex = currentIndex; tscbbConnectionsFile.SelectedIndexChanged += tscbbConnectionsFile_SelectedIndexChanged; // It can be a new file if (cbbValue.ToString() == "<Create new connection file>") { var nfd = new NewConnectionFileDialog(); if (nfd.ShowDialog(this) == DialogResult.OK) { ConnectionManager.ConfigurationFile = nfd.CreatedFilePath; var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, ConnectionsList.Instance.Files.First(f => f.Path == nfd.CreatedFilePath)); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; tsbMoveToExistingFile.Enabled = tscbbConnectionsFile.Items.Count > 3; } else { loadConnections = false; } } // Or an existing file else { var afd = new AddConnectionFileDialog(); if (afd.ShowDialog(this) == DialogResult.OK) { var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, afd.OpenedFile); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; } else { loadConnections = false; } } } else { if (!ConnectionManager.FileExists(connectionFile.Path)) { CleanFileList(connectionFile); return; } currentIndex = tscbbConnectionsFile.SelectedIndex; // Or it is a connection file so we load it for the connection manager ConnectionManager.ConfigurationFile = connectionFile.Path; tsbRemoveConnectionList.Enabled = tscbbConnectionsFile.Items.Count > 3; connectionFile.LastUsed = DateTime.Now; tsbMoveToExistingFile.DropDownItems.Clear(); foreach (var file in ConnectionsList.Instance.Files.OrderBy(k => k.Name)) { if (connectionFile.Path == file.Path || Uri.IsWellFormedUriString(file.Path, UriKind.Absolute)) { continue; } tsbMoveToExistingFile.DropDownItems.Add(new ToolStripButton { Text = file.Name, Tag = file, Size = new Size(155, 22), AutoSize = true }); } } if (loadConnections) { LoadConnectionFile(); } ConnectionsList.Instance.Save(); }
private void tscbbConnectionsFile_SelectedIndexChanged(object sender, EventArgs e) { var cbbValue = tscbbConnectionsFile.SelectedItem; var connectionFile = cbbValue as ConnectionFile; bool loadConnections = true; // If null, then we selected an action rather than a connection file if (connectionFile == null) { tscbbConnectionsFile.SelectedIndexChanged -= tscbbConnectionsFile_SelectedIndexChanged; tscbbConnectionsFile.SelectedIndex = currentIndex; tscbbConnectionsFile.SelectedIndexChanged += tscbbConnectionsFile_SelectedIndexChanged; // It can be a new file if (cbbValue.ToString() == "<Create new connection file>") { var nfd = new NewConnectionFileDialog(); if (nfd.ShowDialog(this) == DialogResult.OK) { ConnectionManager.ConfigurationFile = nfd.CreatedFilePath; var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, ConnectionsList.Instance.Files.First(f => f.Path == nfd.CreatedFilePath)); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; } else { loadConnections = false; } } // Or an existing file else { var afd = new AddConnectionFileDialog(); if (afd.ShowDialog(this) == DialogResult.OK) { var newIndex = tscbbConnectionsFile.Items.Count - 2; tscbbConnectionsFile.Items.Insert(newIndex, ConnectionsList.Instance.Files.First(f => f.Path == afd.OpenedFilePath)); tscbbConnectionsFile.SelectedIndex = newIndex; tsbRemoveConnectionList.Enabled = true; } else { loadConnections = false; } } } else { currentIndex = tscbbConnectionsFile.SelectedIndex; // Or it is a connection file so we load it for the connection manager ConnectionManager.ConfigurationFile = connectionFile.Path; tsbRemoveConnectionList.Enabled = ConnectionManager.Instance.ConnectionsList.Name != "Default"; connectionFile.LastUsed = DateTime.Now; } if (loadConnections) { LoadConnectionFile(); } ConnectionsList.Instance.Save(); }