public ControlRecentApplicationRow(ImageList imageList, string id) { InitializeComponent(); ImageList = imageList; ID = id; Application = ApplicationControl.GetApplicationByID(ID); LayoutControl(); UpdateControl(); }
private void StopRecent_Click(object sender, EventArgs e) { try { ToolStripItem item = (ToolStripItem)sender; Application application = ApplicationControl.GetApplicationByID((string)item.Tag); if (application != null) { ApplicationControl.StopApplication(application); } else { ApplicationControl.StopApplicationsBySet((string)item.Tag); } } catch (Exception ex) { FormUtilities.ShowError(this, ex); } }
private void RemoveApplications() { if (listViewApplications.SelectedItems.Count > 0) { _discardEvents = true; foreach (ListViewItem item in listViewApplications.SelectedItems) { Application application = (Application)item.Tag; _config.Applications.Remove(application); _config.RecentUsages.Where(recent => (recent.ID == application.ID.ToString())) .ToList().ForEach(recent => _config.RecentUsages.Remove(recent)); listViewApplications.Items.Remove(item); } _config.RecentUsages.Where(recent => (ApplicationControl.GetApplicationByID(recent.ID) == null && !_config.Sets.Contains(recent.ID))) .ToList().ForEach(recent => _config.RecentUsages.Remove(recent)); RegistryHandler.SaveConfiguration(_config); _discardEvents = false; UpdateSetList(); UpdateSelectedApplicationInfo(); EnableControls(true); } }
private void UpdateSystemTrayContextMenuRecents() { // make sure top [max count] recent items are in correct order List <RecentUsage> recentUsages = _config.RecentUsages.Take(Configuration.MAX_VISIBLE_RECENT_USAGE_COUNT).OrderBy(recent => recent.Name).ToList(); foreach (RecentUsage recentUsage in recentUsages) { Application application = ApplicationControl.GetApplicationByID(recentUsage.ID); bool applicationIsRunning = (application != null ? application.IsRunning : false); Image image = imageList.Images[application != null ? (applicationIsRunning ? 0 : 1) : 2]; int menuIndex = toolStripMenuItemSystemTrayRecent.DropDownItems.Cast <ToolStripItem>().Select(item => item.Text).ToList().IndexOf(recentUsage.Name); int correctIndex = recentUsages.IndexOf(recentUsage); if (menuIndex == -1) { // recent item does not exist in context menu ToolStripMenuItem recentItem = new ToolStripMenuItem(recentUsage.Name, image); toolStripMenuItemSystemTrayRecent.DropDownItems.Insert(correctIndex, recentItem); if (application == null || !applicationIsRunning) { ToolStripItem recentStartItem = new ToolStripMenuItem("Start") { Tag = recentUsage.ID }; recentStartItem.Click += StartRecent_Click; recentItem.DropDownItems.Add(recentStartItem); } ToolStripItem recentRestartItem = new ToolStripMenuItem("Restart") { Tag = recentUsage.ID }; recentRestartItem.Click += RestartRecent_Click; recentItem.DropDownItems.Add(recentRestartItem); if (application == null || applicationIsRunning) { ToolStripItem recentStopItem = new ToolStripMenuItem("Stop") { Tag = recentUsage.ID }; recentStopItem.Click += StopRecent_Click; recentItem.DropDownItems.Add(recentStopItem); } } else { // recent item exist in context menu, verify position and status ToolStripMenuItem recentItem = (ToolStripMenuItem)toolStripMenuItemSystemTrayRecent.DropDownItems[menuIndex]; recentItem.Image = image; if (menuIndex != correctIndex) { toolStripMenuItemSystemTrayRecent.DropDownItems.RemoveAt(menuIndex); toolStripMenuItemSystemTrayRecent.DropDownItems.Insert(correctIndex, recentItem); } if (application != null) { ToolStripItem recentStartItem = recentItem.DropDownItems.Cast <ToolStripItem>().FirstOrDefault(item => (item.Text == "Start")); if (applicationIsRunning && recentStartItem != null) { recentStartItem.Click -= StartRecent_Click; recentItem.DropDownItems.Remove(recentStartItem); } else if (!applicationIsRunning && recentStartItem == null) { recentStartItem = new ToolStripMenuItem("Start") { Tag = recentUsage.ID }; recentStartItem.Click += StartRecent_Click; recentItem.DropDownItems.Insert(0, recentStartItem); } ToolStripItem recentStopItem = recentItem.DropDownItems.Cast <ToolStripItem>().FirstOrDefault(item => (item.Text == "Stop")); if (!applicationIsRunning && recentStopItem != null) { recentStopItem.Click -= StopRecent_Click; recentItem.DropDownItems.Remove(recentStopItem); } else if (applicationIsRunning && recentStopItem == null) { recentStopItem = new ToolStripMenuItem("Stop") { Tag = recentUsage.ID }; recentStopItem.Click += StopRecent_Click; recentItem.DropDownItems.Add(recentStopItem); } } } } // remove items exceeding [max count] for (int i = Configuration.MAX_VISIBLE_RECENT_USAGE_COUNT; i < toolStripMenuItemSystemTrayRecent.DropDownItems.Count; i++) { ToolStripMenuItem recentItem = (ToolStripMenuItem)toolStripMenuItemSystemTrayRecent.DropDownItems[Configuration.MAX_VISIBLE_RECENT_USAGE_COUNT]; ToolStripItem recentStartItem = recentItem.DropDownItems.Cast <ToolStripItem>().FirstOrDefault(item => (item.Text == "Start")); if (recentStartItem != null) { recentStartItem.Click -= StartRecent_Click; } ToolStripItem recentRestartItem = recentItem.DropDownItems.Cast <ToolStripItem>().FirstOrDefault(item => (item.Text == "Restart")); if (recentRestartItem != null) { recentRestartItem.Click -= RestartRecent_Click; } ToolStripItem recentStopItem = recentItem.DropDownItems.Cast <ToolStripItem>().FirstOrDefault(item => (item.Text == "Stop")); if (recentStopItem != null) { recentStopItem.Click -= StopRecent_Click; } recentItem.DropDownItems.Clear(); toolStripMenuItemSystemTrayRecent.DropDownItems.RemoveAt(Configuration.MAX_VISIBLE_RECENT_USAGE_COUNT); } }