private void Init(bool selectEnd) { // Initialize the report comboBox. _driverReportSpec.LoadList(string.Empty); comboReport.Items.Insert(0, string.Empty); comboReport.SelectedItem = string.Empty; // Value for keeping track of the previously selected tool // Used to check if the tool meets requirements before allowing you to navigate away from it. PreviouslySelectedIndex = -1; // Reload the tool list Removelist.Clear(); ToolList = Settings.Default.ToolList .Select(t => new ToolDescription(t)) .ToList(); RefreshListBox(); if (ToolList.Count == 0) { listTools.SelectedIndex = -1; btnRemove.Enabled = false; btnMoveUp.Enabled = false; btnMoveDown.Enabled = false; } else { listTools.SelectedIndex = selectEnd ? ToolList.Count - 1 : 0; btnRemove.Enabled = true; } Unsaved = false; }
/// <summary> /// Remove the currently selected value. /// </summary> public void Remove() { int spot = listTools.SelectedIndex; if (spot >= Settings.Default.ToolList.Count && !Unsaved) { //Removing a newly added tool } else { Unsaved = true; } Removelist.Add(ToolList[spot]); ToolList.RemoveAt(spot); RefreshListBox(); if (ToolList.Count == 0) { textTitle.Text = string.Empty; textCommand.Text = string.Empty; textArguments.Text = string.Empty; textInitialDirectory.Text = string.Empty; btnRemove.Enabled = false; PreviouslySelectedIndex = -1; cbOutputImmediateWindow.CheckState = CheckState.Unchecked; comboReport.SelectedItem = string.Empty; } // If the removed Index was the last in the list, the selected index is the new last element. else if (spot == ToolList.Count) { // If the removed Index was the last in the list, the selected index is the new last element. listTools.SelectedIndex = spot - 1; } else { listTools.SelectedIndex = spot; //In this case the selected index doesn't actually change so the textBoxes still need to be updated. ToolDescription highlighted = ToolList[listTools.SelectedIndex]; textTitle.Text = highlighted.Title; textCommand.Text = highlighted.Command; textArguments.Text = highlighted.Arguments; textInitialDirectory.Text = highlighted.InitialDirectory; cbOutputImmediateWindow.CheckState = highlighted.OutputToImmediateWindow ? CheckState.Checked : CheckState.Unchecked; comboReport.SelectedItem = ComboContainsTitle(highlighted.ReportTitle) ? highlighted.ReportTitle : string.Empty; } }