private void _OverlaysLoadingThreadRun() { while (true) { try { Int32 index = 0; if (!ThreadRun_Helper(this._OverlayQueue, false, ref index)) { continue; } //Thread.Sleep(9); var shoTemp = this._ShellViewEx.Items[index]; var sho = FileSystemListItem.ToFileSystemItem(shoTemp.ParentHandle, shoTemp.PIDL); Int32 overlayIndex = 0; this._Small.GetIconIndexWithOverlay(sho.PIDL, out overlayIndex); shoTemp.OverlayIconIndex = overlayIndex; //if (sho.IsFolder && sho.IsShared) shoTemp.IsShared = true; if (overlayIndex > 0) { if (!this._RedrawQueue.Contains(index)) { this._RedrawQueue.Enqueue(index); } //this._ShellViewEx.RedrawItem(index); } sho.Dispose(); shoTemp.Dispose(); } catch { } } }
private void InitializeInitialTabs() { var InitialTabs = Utilities.GetRegistryValue("OpenedTabs", "").ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (InitialTabs.Length == 0 || !_IsrestoreTabs) { var sho = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, tcMain.StartUpLocation.ToShellParsingName()); if (tcMain.Items.OfType <Wpf.Controls.TabItem>().Any()) { NavigationController(sho); } else { var tab = tcMain.NewTab(sho, true); this.SelectTab(tab); } } if (_IsrestoreTabs) { isOnLoad = true; int i = 0; foreach (string str in InitialTabs) { try { i++; if (str.ToLowerInvariant() == "::{22877a6d-37a1-461a-91b0-dbda5aaebc99}") { continue; } var tab = tcMain.NewTab(FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, str.ToShellParsingName()), i == InitialTabs.Length); if (i == InitialTabs.Length) { this.SelectTab(tab); bcbc.SetPathWithoutNavigate(str); } } catch { //AddToLog(String.Format("Unable to load {0} into a tab!", str)); MessageBox.Show("BetterExplorer is unable to load one of the tabs from your last session. Your other tabs are perfectly okay though! \r\n\r\nThis location was unable to be loaded: " + str, "Unable to Create New Tab", MessageBoxButton.OK, MessageBoxImage.Error); } } if (tcMain.Items.Count == 0) { tcMain.NewTab(); string idk = tcMain.StartUpLocation.StartsWith("::") ? tcMain.StartUpLocation.ToShellParsingName() : tcMain.StartUpLocation.Replace("\"", ""); NavigationController(FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, idk)); (tcMain.SelectedItem as Wpf.Controls.TabItem).ShellObject = _ShellListView.CurrentFolder; (tcMain.SelectedItem as Wpf.Controls.TabItem).ToolTip = _ShellListView.CurrentFolder.ParsingName.Replace("%20", " ").Replace("%3A", ":").Replace("%5C", @"\"); } isOnLoad = false; } }
public override void PostRenameItem(uint dwFlags, IShellItem psiItem, string pszNewName, uint hrRename, IShellItem psiNewlyCreated) { this._View.Invoke((Action)(() => { if (hrRename == 2555912 && psiItem != null && psiNewlyCreated != null) { var oldItem = FileSystemListItem.InitializeWithIShellItem(this._View.LVHandle, psiItem); var newItem = FileSystemListItem.InitializeWithIShellItem(this._View.LVHandle, psiNewlyCreated); this._View.UpdateItem(oldItem, newItem); } this._View.IsRenameInProgress = false; })); }
private void _IconsLoadingThreadRun() { while (true) { if (this._ShellViewEx != null && this._ShellViewEx.IsSearchNavigating) { Thread.Sleep(5); //F.Application.DoEvents(); } var index = 0; if (!ThreadRun_Helper(this._IconsForRetreval, false, ref index)) { continue; } var sho = this._ShellViewEx.Items[index]; if (!sho.IsIconLoaded) { try { var temp = FileSystemListItem.ToFileSystemItem(sho.ParentHandle, sho.ParsingName.ToShellParsingName()); var icon = temp.GetHBitmap(this._CurrentSize, false, true); var shieldOverlay = 0; if (sho.ShieldedIconIndex == -1) { if ((temp.GetShield() & IExtractIconPWFlags.GIL_SHIELD) != 0) { shieldOverlay = this._ShieldIconIndex; } sho.ShieldedIconIndex = shieldOverlay; } if (icon != IntPtr.Zero || shieldOverlay > 0) { sho.IsIconLoaded = true; Gdi32.DeleteObject(icon); if (!this._RedrawQueue.Contains(index)) { this._RedrawQueue.Enqueue(index); } } //Catch File not found exception since it happens if the file is laready deleted } catch (FileNotFoundException) { } } } }
void Initialize(IListItemEx[] items) { this._Items = items; IntPtr[] pidls = new IntPtr[items.Length]; IListItemEx parent = null; for (int n = 0; n < items.Length; ++n) { pidls[n] = items[n].ILPidl; if (parent == null) { if (items[n].ParsingName.Equals(ShellItem.Desktop.ParsingName)) { parent = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, ShellItem.Desktop.Pidl); } else { parent = items[n].Parent; } } else if (!items[n].Parent.Equals(parent)) { throw new Exception("All shell items must have the same parent"); } } if (items.Length == 0) { var desktop = KnownFolders.Desktop as ShellItem; var ishellViewPtr = desktop.GetIShellFolder().CreateViewObject(IntPtr.Zero, typeof(IShellView).GUID); var view = Marshal.GetObjectForIUnknown(ishellViewPtr) as IShellView; view.GetItemObject(SVGIO.SVGIO_BACKGROUND, typeof(IContextMenu).GUID, out _Result); Marshal.ReleaseComObject(view); } else { parent.GetIShellFolder().GetUIObjectOf(IntPtr.Zero, (uint)pidls.Length, pidls, typeof(IContextMenu).GUID, 0, out _Result); } m_ComInterface = (IContextMenu)Marshal.GetTypedObjectForIUnknown(_Result, typeof(IContextMenu)); m_ComInterface2 = m_ComInterface as IContextMenu2; m_ComInterface3 = m_ComInterface as IContextMenu3; m_MessageWindow = new MessageWindow(this); }
/// <summary> /// Creates a new tab starting at the libraries folder /// </summary> public void NewTab() { IListItemEx DefPath; if (StartUpLocation.StartsWith("::") && !StartUpLocation.Contains(@"\")) { DefPath = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, "shell:" + StartUpLocation); } else { try { DefPath = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, StartUpLocation); } catch { DefPath = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, ((ShellItem)KnownFolders.Libraries).ParsingName.ToShellParsingName()); } } NewTab(DefPath, true); }
public ImageListEx(Int32 size) { var ptr = IntPtr.Zero; this._CurrentSize = size; ptr = ComCtl32.ImageList_Create(size, size, 0x00000020 | 0x00010000 | 0x00020000, 0, 1); this._IImageList = (IImageList2)Marshal.GetObjectForIUnknown(ptr); this.Handle = ptr; this._IconLoadingThread = new Thread(_IconsLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.Normal }; this._IconLoadingThread.IsBackground = true; this._IconLoadingThread.SetApartmentState(ApartmentState.STA); this._IconLoadingThread.Start(); this._IconCacheLoadingThread = new Thread(_IconCacheLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; this._IconCacheLoadingThread.SetApartmentState(ApartmentState.STA); this._IconCacheLoadingThread.IsBackground = true; this._IconCacheLoadingThread.Start(); this._OverlaysLoadingThread = new Thread(_OverlaysLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; this._OverlaysLoadingThread.SetApartmentState(ApartmentState.STA); this._OverlaysLoadingThread.IsBackground = true; this._OverlaysLoadingThread.Start(); this._UpdateSubitemValuesThread = new Thread(_UpdateSubitemValuesThreadRun) { Priority = ThreadPriority.BelowNormal }; this._UpdateSubitemValuesThread.SetApartmentState(ApartmentState.STA); this._UpdateSubitemValuesThread.IsBackground = true; this._UpdateSubitemValuesThread.Start(); this._RedrawingThread = new Thread(_RedrawingThreadRun) { IsBackground = true, Priority = ThreadPriority.Normal }; this._RedrawingThread.SetApartmentState(ApartmentState.STA); this._RedrawingThread.IsBackground = true; this._RedrawingThread.Start(); var defIconInfo = new Shell32.SHSTOCKICONINFO() { cbSize = (UInt32)Marshal.SizeOf(typeof(Shell32.SHSTOCKICONINFO)) }; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_APPLICATION, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._ExeFallBackIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_SHIELD, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._ShieldIconIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_SHARE, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._SharedIconIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_FOLDER, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._FolderFallBackIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_DOCNOASSOC, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._DefaultFallBackIndex = defIconInfo.iSysIconIndex; var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); this._VideAddornerWide = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Path.Combine(basePath, "video_addorner_wide.png")); this._VideAddorner = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Path.Combine(basePath, "video_addorner.png")); }
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> private void SingleInstanceCallback(Object sender, InstanceCallbackEventArgs args) { if (args == null || this.Dispatcher == null) { return; } var startUpLocation = Settings.BESettings.StartupLocation; Action <Boolean> d = x => { var win = this.MainWindow as MainWindow; var windowsActivate = new CombinedWindowActivator(); if (!x || win == null) { return; } win.StateChanged += this.Win_StateChanged; if (args.CommandLineArgs == null || !args.CommandLineArgs.Any()) { return; } if (args.CommandLineArgs.Length == 1) { win.Visibility = Visibility.Visible; windowsActivate.ActivateForm(win, null, IntPtr.Zero); } else { if (args.CommandLineArgs[1] == "/nw") { new MainWindow() { IsMultipleWindowsOpened = true }.Show(); } else { IListItemEx sho; if (args.CommandLineArgs[1] == "t") { win.Visibility = Visibility.Visible; windowsActivate.ActivateForm(win, null, IntPtr.Zero); sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName()); } else { sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, args.CommandLineArgs[1].ToShellParsingName()); } if (!IsStartMinimized || win.tcMain.Items.Count == 0) { this.CreateInitialTab(win, sho); } else if (Settings.BESettings.IsRestoreTabs) { win.tcMain.Items.Clear(); this.CreateInitialTab(win, sho); } else if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { if (args.CommandLineArgs[1] == "t") { this.CreateInitialTab(win, sho); } else { var cmd = args.CommandLineArgs[1]; sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, cmd.ToShellParsingName()); this.CreateInitialTab(win, sho); } } else { this.CreateInitialTab(win, sho); } } windowsActivate.ActivateForm(win, null, IntPtr.Zero); } }; this.Dispatcher.BeginInvoke(d, true); }
/// <summary> /// Constructs the copy/move to menu for tabs /// </summary> private void ConstructMoveToCopyToMenu() { this.btnMoveto.Items.Clear(); this.btnCopyto.Items.Clear(); var sod = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Desktop).Pidl); var bmpSourceDesktop = sod.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default); var otherLocationMove = Utilities.Build_MenuItem(this.FindResource("miOtherDestCP"), onClick: new RoutedEventHandler(this.btnmtOther_Click)); var otherLocationCopy = Utilities.Build_MenuItem(this.FindResource("miOtherDestCP"), onClick: new RoutedEventHandler(this.btnctOther_Click)); var mimDesktop = Utilities.Build_MenuItem(this.FindResource("btnctDesktopCP"), icon: bmpSourceDesktop, onClick: new RoutedEventHandler(this.btnmtDesktop_Click)); var micDesktop = Utilities.Build_MenuItem(this.FindResource("btnctDesktopCP"), icon: bmpSourceDesktop, onClick: new RoutedEventHandler(this.btnctDesktop_Click)); MenuItem mimDocuments = new MenuItem(), micDocuments = new MenuItem(); try { var sodc = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Documents).Pidl); var bmpSourceDocuments = sodc.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default); mimDocuments = Utilities.Build_MenuItem(this.FindResource("btnctDocumentsCP"), icon: bmpSourceDocuments, onClick: new RoutedEventHandler(this.btnmtDocuments_Click)); micDocuments = Utilities.Build_MenuItem(this.FindResource("btnctDocumentsCP"), icon: bmpSourceDocuments, onClick: new RoutedEventHandler(this.btnctDocuments_Click)); } catch (Exception) { mimDocuments = null; micDocuments = null; // catch the exception in case the user deleted that basic folder somehow } MenuItem mimDownloads = new MenuItem(), micDownloads = new MenuItem(); try { var sodd = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, ((ShellItem)KnownFolders.Downloads).Pidl); var bmpSourceDownloads = sodd.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default); mimDownloads = Utilities.Build_MenuItem(this.FindResource("btnctDownloadsCP"), icon: bmpSourceDownloads, onClick: new RoutedEventHandler(this.btnmtDounloads_Click)); micDownloads = Utilities.Build_MenuItem(this.FindResource("btnctDownloadsCP"), icon: bmpSourceDownloads, onClick: new RoutedEventHandler(this.btnctDounloads_Click)); } catch (Exception) { micDownloads = null; mimDownloads = null; // catch the exception in case the user deleted that basic folder somehow } if (mimDocuments != null) { this.btnMoveto.Items.Add(mimDocuments); } if (mimDownloads != null) { this.btnMoveto.Items.Add(mimDownloads); } this.btnMoveto.Items.Add(mimDesktop); this.btnMoveto.Items.Add(new Separator()); if (micDocuments != null) { this.btnCopyto.Items.Add(micDocuments); } if (micDownloads != null) { this.btnCopyto.Items.Add(micDownloads); } this.btnCopyto.Items.Add(micDesktop); this.btnCopyto.Items.Add(new Separator()); foreach (var item in this.tcMain.Items.OfType <Wpf.Controls.TabItem>()) { var isAdditem = true; item.ShellObject = item.ShellObject.Clone(); foreach (var mii in this.btnCopyto.Items.OfType <MenuItem>().Where(x => x.Tag != null)) { if ((mii.Tag as IListItemEx).Equals(item.ShellObject)) { isAdditem = false; } } if (isAdditem && item.ShellObject.IsFileSystem) { try { var so = item.ShellObject; var bmpSource = so.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default); this.btnMoveto.Items.Add(Utilities.Build_MenuItem(item.ShellObject.DisplayName, item.ShellObject, bmpSource, onClick: new RoutedEventHandler(this.mim_Click))); this.btnCopyto.Items.Add(Utilities.Build_MenuItem(item.ShellObject.DisplayName, item.ShellObject, bmpSource, onClick: new RoutedEventHandler(this.mico_Click))); } catch { // Do nothing if ShellItem is not available anymore and close the problematic item // tcMain.RemoveTabItem(item); } } } this.btnMoveto.Items.Add(new Separator()); this.btnMoveto.Items.Add(otherLocationMove); this.btnCopyto.Items.Add(new Separator()); this.btnCopyto.Items.Add(otherLocationCopy); }
/// <summary> /// GetContainerForItemOverride /// </summary> /// <returns></returns> protected override DependencyObject GetContainerForItemOverride() { return(new TabItem(FileSystemListItem.ToFileSystemItem(IntPtr.Zero, ((ShellItem)KnownFolders.Desktop).ParsingName))); }
/// <summary> /// Creates a new tab, optionally selects it then returns it /// </summary> /// <param name="Location">The file path of the new Tab</param> /// <param name="IsNavigate">Do you want the new tab to be selected?</param> /// <returns></returns> public TabItem NewTab(string Location, bool IsNavigate = false) => NewTab(FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Location.ToShellParsingName()), IsNavigate);
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> /// private void SingleInstanceCallback(Object sender, InstanceCallbackEventArgs args) { if (args == null || Dispatcher == null) { return; } var startUpLocation = Utilities.GetRegistryValue("StartUpLoc", KnownFolders.Libraries.ParsingName).ToString(); Action <Boolean> d = x => { var win = MainWindow as MainWindow; var windowsActivate = new CombinedWindowActivator(); if (!x) { return; } if (win == null) { return; } win.StateChanged += Win_StateChanged; if (args?.CommandLineArgs == null || !args.CommandLineArgs.Any()) { return; } if (args.CommandLineArgs.Length == 1) { win.Visibility = Visibility.Visible; //if (win.WindowState == WindowState.Minimized) { // User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, User32.ShowWindowCommands.Restore); //} //User32.ForceForegroundWindow(win); windowsActivate.ActivateForm(win, null, IntPtr.Zero); } else { if (args.CommandLineArgs[1] == "/nw") { new MainWindow() { IsMultipleWindowsOpened = true }.Show(); } else { IListItemEx sho = null; if (args.CommandLineArgs[1] == "t") { win.Visibility = Visibility.Visible; //if (win.WindowState == WindowState.Minimized) // User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, // User32.ShowWindowCommands.Restore); windowsActivate.ActivateForm(win, null, IntPtr.Zero); sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName()); } else { sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, args.CommandLineArgs[1].ToShellParsingName()); } if (!IsStartMinimized || win.tcMain.Items.Count == 0) { CreateInitialTab(win, sho); } else if ((Int32)Utilities.GetRegistryValue("IsRestoreTabs", "1") == 0) { win.tcMain.Items.Clear(); CreateInitialTab(win, sho); } else if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { if (args.CommandLineArgs[1] == "t") { CreateInitialTab(win, sho); } else { var cmd = args.CommandLineArgs[1]; sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, cmd.ToShellParsingName()); CreateInitialTab(win, sho); } } else { CreateInitialTab(win, sho); } } //User32.ForceForegroundWindow(win); windowsActivate.ActivateForm(win, null, IntPtr.Zero); } }; Dispatcher.BeginInvoke(d, true); }
public Wpf.Controls.TabItem NewTab(string Location, bool IsNavigate = false) { return(NewTab(FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Location.ToShellParsingName()), IsNavigate)); }