private void contextMenuNotifyIcon_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if ((e.ClickedItem is ToolStripSeparator)) { return; } if (e.ClickedItem.Tag is IntPtr) { ShowExplorerWindow((IntPtr)e.ClickedItem.Tag, true); } else { if ((int)e.ClickedItem.Tag == 0) { RestoreAllWindowsFromTray(); } else // Close all { notifyIcon.Visible = false; contextMenuNotifyIcon.Hide(); var handles = dicNotifyIcon.Values.Select(i => i.ExplorerHandle).ToList(); dicNotifyIcon.Clear(); // <--- important, clear the dict first! // otherwise, the closing windows will try to call back // and we'll deadlock foreach (IntPtr ptr in handles) { WindowUtils.CloseExplorer(ptr, 2); } } } }
public bool ExecuteCommand(Commands command, object arg) { if (tabBar != null) { IntPtr ptr; switch (command) { case Commands.GoBack: case Commands.GoForward: if (arg is int) { return(tabBar.NavigateToIndex(command == Commands.GoBack, (int)arg)); } break; case Commands.GoUpOneLevel: tabBar.UpOneLevel(); return(true); case Commands.RefreshBrowser: tabBar.Explorer.Refresh(); return(true); case Commands.CloseCurrentTab: return(tabBar.CloseTab(tabBar.CurrentTab)); case Commands.CloseLeft: case Commands.CloseRight: tabBar.CloseLeftRight(command == Commands.CloseLeft, -1); return(true); case Commands.CloseAllButCurrent: tabBar.CloseAllTabsExcept(tabBar.CurrentTab); return(true); case Commands.CloseAllButOne: { TabWrapper wrapper = arg as TabWrapper; if (wrapper == null) { break; } tabBar.CloseAllTabsExcept(wrapper.Tab); return(true); } case Commands.CloseWindow: // 关闭窗口 2 indiff /* using (RegistryKey key = Registry.CurrentUser.CreateSubKey(RegConst.Root)) * { * string[] list = (from QTabItem item2 in tabControl1.TabPages * where item2.TabLocked * select item2.CurrentPath).ToArray(); * * MessageBox.Show(String.Join(",", list)); * QTUtility2.WriteRegBinary(list, "TabsLocked", key); * }*/ WindowUtils.CloseExplorer(tabBar.ExplorerHandle, 2); return(true); case Commands.UndoClose: tabBar.RestoreLastClosed(); return(true); case Commands.BrowseFolder: tabBar.ChooseNewDirectory(); return(true); case Commands.ToggleTopMost: tabBar.ToggleTopMost(); TryCallButtonBar(bbar => bbar.RefreshButtons()); return(true); case Commands.FocusFileList: tabBar.listView.SetFocus(); return(true); case Commands.OpenTabBarOptionDialog: OptionsDialog.Open(); return(true); case Commands.OpenButtonBarOptionDialog: OptionsDialog.Open(); // todo: open at bbar page return(true); case Commands.IsFolderTreeVisible: return(tabBar.ShellBrowser.IsFolderTreeVisible()); case Commands.IsButtonBarVisible: return(InstanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr)); case Commands.ShowFolderTree: if (!QTUtility.IsXP || !(arg is bool)) { break; } tabBar.ShowFolderTree((bool)arg); return(true); case Commands.ShowButtonBar: if (!InstanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr)) { } break; case Commands.MD5: if (!(arg is string[])) { break; } if (md5Form == null) { md5Form = new FileHashComputerForm(); } if (md5Form.InvokeRequired) { md5Form.Invoke(new FormMethodInvoker(ShowMD5FormCore), new object[] { arg }); } else { ShowMD5FormCore(arg); } return(true); case Commands.ShowProperties: { if ((arg == null) || !(arg is Address)) { break; } Address address = (Address)arg; using (IDLWrapper wrapper = new IDLWrapper(address)) { if (!wrapper.Available) { break; } ShellMethods.ShowProperties(wrapper.IDL, tabBar.ExplorerHandle); return(true); } } case Commands.SetModalState: if (((arg == null) || !(arg is bool)) || !((bool)arg)) { tabBar.NowModalDialogShown = false; break; } tabBar.NowModalDialogShown = true; break; case Commands.SetSearchBoxStr: return(arg != null && arg is string && TryCallButtonBar(bbar => bbar.SetSearchBarText((string)arg))); case Commands.ReorderTabsByName: case Commands.ReorderTabsByPath: case Commands.ReorderTabsByActv: case Commands.ReorderTabsRevers: if (tabBar.tabControl1.TabCount > 1) { bool fDescending = ((arg != null) && (arg is bool)) && ((bool)arg); tabBar.ReorderTab(((int)command) - 0x18, fDescending); } break; } } return(false); }