/// <summary> /// Unpin by internal PinnedApp object. These objects are stored by PinnedManager /// </summary> public void Unpin(PinnedApp app) { Apps.Remove(app); if (File.Exists(app.Shortcut)) { File.Delete(app.Shortcut); } }
public TaskbarPinnedButton(PinnedApp app) : base() { this.EnableDragging = true; this.AddedToTaskbar = DateTime.MinValue; InitializeComponent(); _app = app; _toolTip = new ToolTip(); }
/// <summary> /// Remove a pinned button /// </summary> /// <param name="app">Pinned application</param> public void RemovePinnedButton(PinnedApp app) { var button = _taskbarPinnedButtons.Find(tpb => tpb.Tag == app); if (button != null) { this.Controls.Remove(button); _groups.RemoveFromGroup(app.Path, button); _taskbarPinnedButtons.Remove(button); ArrangeButtons(); } }
private void ReorderPinnedButtons() { TaskbarPropertiesManager.Instance.Properties.PinnedPrograms.Clear(); this._taskbarPinnedButtons.Sort((x, y) => this.Controls.GetChildIndex(x).CompareTo(this.Controls.GetChildIndex(y))); foreach (var item in this._taskbarPinnedButtons) { TaskbarPinnedButton pinnedButton = item as TaskbarPinnedButton; PinnedApp pinnedApp = pinnedButton.Tag as PinnedApp; TaskbarPropertiesManager.Instance.Properties.PinnedPrograms.Add(pinnedApp.Shortcut); } try { TaskbarPropertiesManager.Instance.Save(); } catch { // bury... log ? } }
/// <summary> /// Add a new pinned button /// </summary> /// <param name="app">Pinned application</param> /// <param name="processMenu">Context menu</param> private void AddPinnedButton(PinnedApp app, ContextMenuStrip processMenu, bool saveOrder) { var button = new TaskbarPinnedButton(app); this.Controls.Add(button); button.Tag = app; button.Init(); button.AutoSize = false; button.Padding = new System.Windows.Forms.Padding(0); button.Margin = new System.Windows.Forms.Padding(0); button.ContextMenuStrip = processMenu; _groups.AddToGroup(app.Path, button); _taskbarPinnedButtons.Add(button); ArrangeButtons(); if (saveOrder) { ReorderPinnedButtons(); } }
private void processMenu_Opening(object sender, CancelEventArgs e) { if (tooltipManager.ToolTipWindow.Visible) { tooltipManager.ToolTipWindow.ForceHide(); } ContextMenuStrip menu = sender as ContextMenuStrip; BaseTaskbarButton baseButton = menu.SourceControl as BaseTaskbarButton; baseButton.Hover = true; if (menu.SourceControl is TaskbarButton) { TaskbarButton button = menu.SourceControl as TaskbarButton; SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; tsmiLaunch.Image = proc.SmallIcon.ConvertToBitmap(false); Process p = ProcessUtil.GetProcessByWindowHandle(proc.Handle); ProcessModule module = p.MainModule; if (module != null) { string fileDescription = System.Diagnostics.FileVersionInfo.GetVersionInfo(module.FileName).FileDescription; tsmiLaunch.Text = string.IsNullOrEmpty(fileDescription) ? (module.FileName ?? p.MainWindowTitle) : fileDescription.Clamp(Constants.MaxProgramNameLength); tsmiLaunch.Tag = new ProcessFullPath { FileName = module.FileName, Arguments = ProcessUtil.GetCommandLineArguments(module.ModuleName) }; tsmiLaunch.Visible = true; if (PinnedManager.Instance.IsPinned(p)) { tsmiPin.Visible = false; tsmiUnpin.Visible = true; } else { tsmiPin.Visible = true; tsmiUnpin.Visible = false; } } else { tsmiLaunch.Visible = false; tsmiPin.Visible = false; tsmiUnpin.Visible = false; } tsmiCloseWindow.Visible = true; } else { TaskbarPinnedButton pinnedButton = menu.SourceControl as TaskbarPinnedButton; PinnedApp app = pinnedButton.Tag as PinnedApp; tsmiCloseWindow.Visible = false; tsmiLaunch.Image = app.Icon.ResizeBitmap(ButtonConstants.SmallIconSize, ButtonConstants.SmallIconSize); tsmiLaunch.Text = string.IsNullOrEmpty(app.Name) ? "Unknown application" : app.Name.Clamp(Constants.MaxProgramNameLength); tsmiLaunch.Tag = new ProcessFullPath { FileName = app.Path, Arguments = app.Arguments }; tsmiLaunch.Visible = !string.IsNullOrEmpty(app.Path); if (PinnedManager.Instance.IsPinned(app)) { tsmiPin.Visible = false; tsmiUnpin.Visible = true; } else { tsmiPin.Visible = true; tsmiUnpin.Visible = false; } } }
public bool IsPinned(PinnedApp app) { return(Apps.Exists(pa => pa.Path.Equals(app.Path, StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Add a new pinned button /// </summary> /// <param name="app">Pinned application</param> /// <param name="processMenu">Context menu</param> public void AddPinnedButton(PinnedApp app, ContextMenuStrip processMenu) { AddPinnedButton(app, processMenu, true); }