private bool DoBindAction(BindAction action, bool fRepeat = false, QTabItem tab = null, IDLWrapper item = null) { if(fRepeat && !( action == BindAction.GoBack || action == BindAction.GoForward || action == BindAction.TransparencyPlus || action == BindAction.TransparencyMinus)) { return false; } if(tab == null) tab = CurrentTab; IntPtr ptr; switch(action) { case BindAction.GoBack: NavigateCurrentTab(true); break; case BindAction.GoForward: NavigateCurrentTab(false); break; case BindAction.GoFirst: NavigateToFirstOrLast(true); break; case BindAction.GoLast: NavigateToFirstOrLast(false); break; case BindAction.NextTab: if(tabControl1.SelectedIndex == tabControl1.TabCount - 1) { tabControl1.SelectedIndex = 0; } else { tabControl1.SelectedIndex++; } break; case BindAction.PreviousTab: if(tabControl1.SelectedIndex == 0) { tabControl1.SelectedIndex = tabControl1.TabCount - 1; } else { tabControl1.SelectedIndex--; } break; case BindAction.FirstTab: tabControl1.SelectedIndex = 0; break; case BindAction.LastTab: tabControl1.SelectedIndex = tabControl1.TabCount - 1; break; case BindAction.CloseCurrent: case BindAction.CloseTab: NowTabDragging = false; if(!tab.TabLocked) { if(tabControl1.TabCount > 1) { CloseTab(tab); } else { WindowUtils.CloseExplorer(ExplorerHandle, 1); } } break; case BindAction.CloseAllButCurrent: case BindAction.CloseAllButThis: CloseAllTabsExcept(tab); break; case BindAction.CloseLeft: case BindAction.CloseLeftTab: CloseLeftRight(true, tab.Index); break; case BindAction.CloseRight: case BindAction.CloseRightTab: CloseLeftRight(false, tab.Index); break; case BindAction.CloseWindow: WindowUtils.CloseExplorer(ExplorerHandle, 1); break; case BindAction.RestoreLastClosed: RestoreLastClosed(); break; case BindAction.CloneCurrent: case BindAction.CloneTab: CloneTabButton(tab, null, true, -1); break; case BindAction.TearOffCurrent: case BindAction.TearOffTab: if(tabControl1.TabCount > 1) { using(IDLWrapper wrapper = new IDLWrapper(tab.CurrentIDL)) { OpenNewWindow(wrapper); } CloseTab(tab); } break; case BindAction.LockCurrent: case BindAction.LockTab: tab.TabLocked = !tab.TabLocked; break; case BindAction.LockAll: bool lockState = tabControl1.TabPages.Any(t => t.TabLocked); tabControl1.TabPages.ForEach(t => t.TabLocked = !lockState); break; case BindAction.BrowseFolder: ChooseNewDirectory(); break; case BindAction.CreateNewGroup: CreateGroup(tab); break; case BindAction.ShowOptions: OptionsDialog.Open(); break; case BindAction.ShowToolbarMenu: // hmm. Rectangle tabRect = tabControl1.GetTabRect(tabControl1.TabCount - 1, true); contextMenuSys.Show(PointToScreen(new Point(tabRect.Right + 10, tabRect.Bottom - 10))); break; case BindAction.ShowTabMenuCurrent: if(tab.Index != -1) { ContextMenuedTab = tab; Rectangle rect = tabControl1.GetTabRect(tab.Index, true); contextMenuTab.Show(PointToScreen(new Point(rect.Right + 10, rect.Bottom - 10))); } break; case BindAction.ShowTabMenu: ContextMenuedTab = tab; contextMenuTab.Show(MousePosition); break; case BindAction.ShowGroupMenu: TryCallButtonBar(bbar => bbar.ClickItem(QTButtonBar.BII_GROUP)); break; case BindAction.ShowRecentTabsMenu: TryCallButtonBar(bbar => bbar.ClickItem(QTButtonBar.BII_RECENTTAB)); break; case BindAction.ShowUserAppsMenu: TryCallButtonBar(bbar => bbar.ClickItem(QTButtonBar.BII_APPLICATIONLAUNCHER)); break; case BindAction.CopySelectedPaths: if(listView.SubDirTipMenuIsShowing() || (subDirTip_Tab != null && subDirTip_Tab.MenuIsShowing)) { return false; } DoFileTools(0); break; case BindAction.CopySelectedNames: if(listView.SubDirTipMenuIsShowing() || (subDirTip_Tab != null && subDirTip_Tab.MenuIsShowing)) { return false; } DoFileTools(1); break; case BindAction.CopyCurrentFolderPath: DoFileTools(2); break; case BindAction.CopyCurrentFolderName: DoFileTools(3); break; case BindAction.ChecksumSelected: DoFileTools(4); break; case BindAction.ToggleTopMost: ToggleTopMost(); // todo: move v to < ? TryCallButtonBar(bbar => bbar.RefreshButtons()); break; case BindAction.TransparencyPlus: case BindAction.TransparencyMinus: { // TODO!!! int num9; int num10; byte num11; if(0x80000 != ((int)PInvoke.Ptr_OP_AND(PInvoke.GetWindowLongPtr(ExplorerHandle, -20), 0x80000))) { if(action == BindAction.TransparencyPlus) { return true; } PInvoke.SetWindowLongPtr(ExplorerHandle, -20, PInvoke.Ptr_OP_OR(PInvoke.GetWindowLongPtr(ExplorerHandle, -20), 0x80000)); PInvoke.SetLayeredWindowAttributes(ExplorerHandle, 0, 0xff, 2); } if(PInvoke.GetLayeredWindowAttributes(ExplorerHandle, out num9, out num11, out num10)) { IntPtr ptr3; if(action == BindAction.TransparencyPlus) { if(num11 > 0xf3) { num11 = 0xff; } else { num11 = (byte)(num11 + 12); } } else if(num11 < 0x20) { num11 = 20; } else { num11 = (byte)(num11 - 12); } PInvoke.SetLayeredWindowAttributes(ExplorerHandle, 0, num11, 2); // IM! //if(InstanceManager.TryGetButtonBarHandle(ExplorerHandle, out ptr3)) { // QTUtility2.SendCOPYDATASTRUCT(ptr3, (IntPtr)7, "track", (IntPtr)num11); //} if(num11 == 0xff) { PInvoke.SetWindowLongPtr(ExplorerHandle, -20, PInvoke.Ptr_OP_AND(PInvoke.GetWindowLongPtr(ExplorerHandle, -20), 0xfff7ffff)); } } } break; case BindAction.FocusFileList: listView.SetFocus(); break; case BindAction.FocusSearchBarReal: if(QTUtility.IsXP) return false; // todo, I don't think this works PInvoke.SetFocus(GetSearchBand_Edit()); break; case BindAction.FocusSearchBarBBar: TryCallButtonBar(bbar => bbar.FocusSearchBox()); break; case BindAction.ShowSDTSelected: if(!Config.Tips.ShowSubDirTips) return false; listView.ShowAndClickSubDirTip(); break; case BindAction.SendToTray: MinimizeToTray(); break; case BindAction.FocusTabBar: tabControl1.Focus(); tabControl1.FocusNextTab(false, true, false); break; case BindAction.NewTab: using(IDLWrapper wrapper = new IDLWrapper(Config.Window.DefaultLocation)) { OpenNewTab(wrapper, false, true); } break; case BindAction.NewWindow: using(IDLWrapper wrapper = new IDLWrapper(Config.Window.DefaultLocation)) { OpenNewWindow(wrapper); } break; // TODO all the blank ones case BindAction.NewFolder: break; case BindAction.NewFile: break; case BindAction.SwitchToLastActivated: if(lstActivatedTabs.Count > 1 && tabControl1.TabPages.Contains(lstActivatedTabs[lstActivatedTabs.Count - 2])) { try { tabControl1.SelectTab(lstActivatedTabs[lstActivatedTabs.Count - 2]); } catch(ArgumentException) { } } break; case BindAction.MergeWindows: MergeAllWindows(); break; case BindAction.ShowRecentFilesMenu: break; case BindAction.SortTabsByName: break; case BindAction.SortTabsByPath: break; case BindAction.SortTabsByActive: break; case BindAction.UpOneLevelTab: case BindAction.UpOneLevel: UpOneLevel(); // Hmm... break; case BindAction.Refresh: break; case BindAction.Paste: break; case BindAction.Maximize: break; case BindAction.Minimize: break; case BindAction.CopyTabPath: string currentPath = tab.CurrentPath; if(currentPath.IndexOf("???") != -1) { currentPath = currentPath.Substring(0, currentPath.IndexOf("???")); } QTUtility2.SetStringClipboard(currentPath); break; case BindAction.TabProperties: ShellMethods.ShowProperties(tab.CurrentIDL); break; case BindAction.ShowTabSubfolderMenu: break; case BindAction.ItemOpenInNewTab: case BindAction.ItemOpenInNewTabNoSel: case BindAction.ItemOpenInNewWindow: if(item.Available && item.HasPath && item.IsReadyIfDrive && !item.IsLinkToDeadFolder) { using(IDLWrapper linkWrapper = item.ResolveTargetIfLink()) { IDLWrapper actualItem = linkWrapper ?? item; if(actualItem.IsFolder) { if(action == BindAction.ItemOpenInNewWindow) { OpenNewWindow(actualItem); } else { OpenNewTab(actualItem, action == BindAction.ItemOpenInNewTabNoSel); } } } } break; case BindAction.ItemCut: case BindAction.ItemCopy: case BindAction.ItemDelete: break; case BindAction.ItemProperties: ShellMethods.ShowProperties(item.IDL); break; case BindAction.CopyItemPath: case BindAction.CopyItemName: case BindAction.ChecksumItem: break; } return true; }
internal bool OpenNewTab(IDLWrapper idlwGiven, bool blockSelecting = false, bool fForceNew = false) { // Check that the folder exists and is navigable. if(idlwGiven == null || !idlwGiven.Available || !idlwGiven.HasPath || !idlwGiven.IsReadyIfDrive || idlwGiven.IsLinkToDeadFolder) { SystemSounds.Hand.Play(); return false; } // If the IDL is a link, resolve it. Otherwise keep using the one we're given. using(IDLWrapper idlwLink = idlwGiven.ResolveTargetIfLink()) { IDLWrapper idlw = idlwLink ?? idlwGiven; // Recheck a few things if(!idlw.Available || !idlw.HasPath || !idlw.IsReadyIfDrive || !idlw.IsFolder) { SystemSounds.Hand.Play(); return false; } if(blockSelecting) { NowTabsAddingRemoving = true; } try { // Check if it's already open if(!fForceNew && Config.Tabs.NeverOpenSame) { QTabItem tabPage = tabControl1.TabPages.FirstOrDefault( item2 => item2.CurrentPath.PathEquals(idlw.Path)); if(tabPage != null) { if(Config.Tabs.ActivateNewTab) { tabControl1.SelectTab(tabPage); } TryCallButtonBar(bbar => bbar.RefreshButtons()); return false; } } // TODO // This entire block is a mystery to me, and I think it should be // removed. It's gone in Quizo's version. string path = idlw.Path; if(!idlw.Special && !path.StartsWith("::")) { string directoryName = Path.GetDirectoryName(path); if(!string.IsNullOrEmpty(directoryName)) { using(IDLWrapper wrapper = new IDLWrapper(directoryName)) { if(wrapper.Special && idlw.Available) { IShellFolder ppv = null; try { IntPtr ptr; if(PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) == 0) { using(IDLWrapper wrapper2 = new IDLWrapper(PInvoke.ILCombine(wrapper.PIDL, ptr))) { if(wrapper2.Available && wrapper2.HasPath) { if(!blockSelecting && Config.Tabs.ActivateNewTab) { NowTabCreated = true; tabControl1.SelectTab(CreateNewTab(wrapper2)); } else { CreateNewTab(wrapper2); TryCallButtonBar(bbar => bbar.RefreshButtons()); QTabItem.CheckSubTexts(tabControl1); } return true; } } } } catch { } finally { if(ppv != null) { Marshal.ReleaseComObject(ppv); } } } } } } // This should work for everything... if(!blockSelecting && Config.Tabs.ActivateNewTab) { NowTabCreated = true; tabControl1.SelectTab(CreateNewTab(idlw)); } else { CreateNewTab(idlw); TryCallButtonBar(bbar => bbar.RefreshButtons()); QTabItem.CheckSubTexts(tabControl1); } } finally { if(blockSelecting) { NowTabsAddingRemoving = false; } } } return true; }
internal void OpenNewWindow(IDLWrapper idlwGiven) { // Check that the folder exists and is navigable. if(idlwGiven == null || !idlwGiven.Available || !idlwGiven.HasPath || !idlwGiven.IsReadyIfDrive || idlwGiven.IsLinkToDeadFolder) { SystemSounds.Hand.Play(); return; } // If the IDL is a link, resolve it. Otherwise keep using the one we're given. using(IDLWrapper idlwLink = idlwGiven.ResolveTargetIfLink()) { IDLWrapper idlw = idlwLink ?? idlwGiven; // Recheck a few things if(!idlw.Available || !idlw.HasPath || !idlw.IsReadyIfDrive || !idlw.IsFolder) { SystemSounds.Hand.Play(); return; } bool isFolderTreeVisible = ShellBrowser.IsFolderTreeVisible(); bool fSameAsCurrent; using(IDLWrapper wrapper = ShellBrowser.GetShellPath()) { fSameAsCurrent = (wrapper == idlw); } // There's some weird magic going on here, but it's apparently necessary. // TODO: understand it SBSP wFlags = SBSP.NEWBROWSER; if(fSameAsCurrent) { if(isFolderTreeVisible) { if(CheckProcessID(ExplorerHandle, WindowUtils.GetShellTrayWnd()) || WindowUtils.IsExplorerProcessSeparated()) { PInvoke.SetRedraw(ExplorerHandle, false); ShowFolderTree(false); wFlags |= SBSP.EXPLOREMODE; new WaitTimeoutCallback(WaitTimeout).BeginInvoke(200, AsyncComplete_FolderTree, true); } else { QTUtility.fRestoreFolderTree = true; } } else { if(QTUtility.IsXP) { QTUtility.RestoreFolderTree_Hide = true; } wFlags |= SBSP.EXPLOREMODE; } } else if(isFolderTreeVisible) { QTUtility.fRestoreFolderTree = true; } StaticReg.SkipNextCapture = true; if(ShellBrowser.Navigate(idlw, wFlags) != 0) { QTUtility2.MakeErrorLog(null, string.Format("Failed navigation: {0}", idlw.Path)); MessageBox.Show(string.Format(QTUtility.TextResourcesDic["TabBar_Message"][0], idlw.Path)); StaticReg.CreateWindowGroup = string.Empty; StaticReg.SkipNextCapture = false; } QTUtility.fRestoreFolderTree = false; } }