void explorerBrowser_NavigationPending(object sender, NavigationPendingEventArgs args)
        {
            // fail navigation if check selected (this must be synchronous)
            args.Cancel = this.failNavigationCheckBox.Checked;


            // This portion is BeginInvoked to decouple the ExplorerBrowser UI from this UI
            BeginInvoke(new MethodInvoker(delegate()
            {
                // update event history text box
                string message = "";
                string location = (args.PendingLocation == null) ? "(unknown)" : args.PendingLocation.Name;
                if (args.Cancel)
                {
                    message = "Navigation Failing. Pending Location = " + location;
                }
                else
                {
                    message = "Navigation Pending. Pending Location = " + location;
                }
                this.eventHistoryTextBox.Text =
                    this.eventHistoryTextBox.Text + message + "\n";
            }));
        }
Ejemplo n.º 2
0
        void Explorer_NavigationPending(object sender, NavigationPendingEventArgs e)
        {

            if (fsw_AC != null)
                fsw_AC.Dispose();

            e.Cancel = IsCancel;
            if (IsAfterRename)
                breadcrumbBarControl1.ExitEditMode();

            try
            {
            
                this.Title = "Better Explorer - " + e.PendingLocation.GetDisplayName(DisplayNameType.Default);



                Dispatcher.BeginInvoke(DispatcherPriority.Render, (ThreadStart)(() =>
                                    {
                                        ConstructMoveToCopyToMenu();
                                        if (e.PendingLocation.IsFileSystemObject || e.PendingLocation.IsNetDrive || e.PendingLocation.ParsingName.StartsWith(@"\\"))
                                        {

                                            try
                                            {
                                                fsw_AC = new FileSystemWatcher(e.PendingLocation.ParsingName);
                                                fsw_AC.EnableRaisingEvents = true;
                                                fsw_AC.Created += new FileSystemEventHandler(fsw_AC_Created);
                                                fsw_AC.Deleted += new FileSystemEventHandler(fsw_AC_Deleted);
                                            }
                                            catch
                                            {

                                            }
                                        }

                                        if (e.PendingLocation.IsFileSystemObject)
	                                    {
		                                    btnSizeChart.IsEnabled = true;
	                                    }
                                        else
	                                    {
                                            btnSizeChart.IsEnabled = false;
	                                    }

                                        this.breadcrumbBarControl1.LoadDirectory(e.PendingLocation);
                                        this.breadcrumbBarControl1.LastPath = e.PendingLocation.ParsingName;
                                        IntPtr pIDL = IntPtr.Zero;

                                        try
                                        {
                                            uint iAttribute;
                                            SHParseDisplayName(e.PendingLocation.ParsingName,
                                                IntPtr.Zero, out pIDL, (uint)0, out iAttribute);

                                            WindowsAPI.SHFILEINFO sfi = new WindowsAPI.SHFILEINFO();
                                            IntPtr Res = IntPtr.Zero;
                                            if (pIDL != IntPtr.Zero)
                                            {
                                                if (!e.PendingLocation.IsFileSystemObject)
                                                {
                                                    Res = WindowsAPI.SHGetFileInfo(pIDL, 0, ref sfi, (uint)Marshal.SizeOf(sfi), WindowsAPI.SHGFI.IconLocation | WindowsAPI.SHGFI.SmallIcon | WindowsAPI.SHGFI.PIDL);
                                                }

                                            }

                                            if (e.PendingLocation.IsFileSystemObject)
                                            {
                                                WindowsAPI.SHGetFileInfo(e.PendingLocation.ParsingName, 0, ref sfi, (uint)Marshal.SizeOf(sfi), (uint)WindowsAPI.SHGFI.IconLocation | (uint)WindowsAPI.SHGFI.SmallIcon);

                                            }
                                            JumpTask JTask = new JumpTask();
                                            JTask.ApplicationPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                                            JTask.Arguments = "\"" + e.PendingLocation.ParsingName + "\"";
                                            JTask.Title = e.PendingLocation.GetDisplayName(DisplayNameType.Default);
                                            JTask.IconResourcePath = sfi.szDisplayName;
                                            JTask.IconResourceIndex = sfi.iIcon;
                                            JumpList.AddToRecentCategory(JTask);
                                            AppJL.Apply();

                                        }
                                        finally
                                        {

                                            if (pIDL != IntPtr.Zero)
                                                Marshal.FreeCoTaskMem(pIDL);
                                        }

                                        try
                                        {

                                            //CloseableTabItem it = new CloseableTabItem();
                                            //CreateTabbarRKMenu(it);
                                            e.PendingLocation.Thumbnail.CurrentSize = new System.Windows.Size(16, 16);
                                            e.PendingLocation.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
                                            (tabControl1.SelectedItem as CloseableTabItem).Header = e.PendingLocation.GetDisplayName(DisplayNameType.Default);
                                            (tabControl1.SelectedItem as CloseableTabItem).TabIcon = e.PendingLocation.Thumbnail.BitmapSource;
                                            (tabControl1.SelectedItem as CloseableTabItem).Path = e.PendingLocation;
                                            if (!isGoingBackOrForward)
                                            {
                                                (tabControl1.SelectedItem as CloseableTabItem).log.CurrentLocation = e.PendingLocation;
                                            }

                                            isGoingBackOrForward = false;

                                            leftNavBut.IsEnabled = (tabControl1.SelectedItem as CloseableTabItem).log.CanNavigateBackwards;
                                            rightNavBut.IsEnabled = (tabControl1.SelectedItem as CloseableTabItem).log.CanNavigateForwards;

                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).DragEnter += new DragEventHandler(newt_DragEnter);
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).DragLeave += new DragEventHandler(newt_DragLeave);
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).DragOver += new DragEventHandler(newt_DragOver);
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).Drop += new DragEventHandler(newt_Drop);
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).AllowDrop = true;
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).Index = CurrentTabIndex;
                                            //(tabControl1.Items[CurrentTabIndex] as CloseableTabItem).CloseTab += new RoutedEventHandler(cti_CloseTab);
                                            //tabControl1.Items[CurrentTabIndex] = it;
                                            //tabControl1.SelectedIndex = CurrentTabIndex;


                                        }
                                        catch (Exception)
                                        {

                                        }
                                        bool isinLibraries = false;
                                        if (e.PendingLocation.Parent != null)
                                        {
                                            if (e.PendingLocation.Parent.ParsingName ==
                                                  KnownFolders.Libraries.ParsingName)
                                            {
                                                isinLibraries = true;
                                            }
                                            else
                                            {
                                                isinLibraries = false;
                                            }
                                        }

                                        btnCreateFolder.IsEnabled = e.PendingLocation.IsFileSystemObject ||
                                            (e.PendingLocation.ParsingName == KnownFolders.Libraries.ParsingName) ||
                                            (isinLibraries);

                                        if (e.PendingLocation.ParsingName == KnownFolders.Libraries.ParsingName)
                                        {
                                            btnCreateFolder.Header = FindResource("btnNewLibraryCP");  //"New Library";
                                            stNewFolder.Title = FindResource("btnNewLibraryCP").ToString();//"New Library";
                                            stNewFolder.Text = "Creates a new library in the current folder.";
                                            stNewFolder.Image = new BitmapImage(new Uri(@"/BetterExplorer;component/Images/newlib32.png", UriKind.Relative));
                                            btnCreateFolder.LargeIcon = @"..\Images\newlib32.png";
                                            btnCreateFolder.Icon = @"..\Images\newlib16.png";
                                        }
                                        else
                                        {
                                            btnCreateFolder.Header = FindResource("btnNewFolderCP");//"New Folder";
                                            stNewFolder.Title = FindResource("btnNewFolderCP").ToString(); //"New Folder";
                                            stNewFolder.Text = "Creates a new folder in the current folder";
                                            stNewFolder.Image = new BitmapImage(new Uri(@"/BetterExplorer;component/Images/folder_new32.png", UriKind.Relative));
                                            btnCreateFolder.LargeIcon = @"..\Images\folder_new32.png";
                                            btnCreateFolder.Icon = @"..\Images\folder_new16.png";
                                        }
                                        if (e.PendingLocation.IsFolder && !e.PendingLocation.IsDrive &&
                                            !e.PendingLocation.IsSearchFolder)
                                        {
                                            //ctgFolderTools.Visibility = Visibility.Visible;
                                        }

                                        if (e.PendingLocation.ParsingName.Contains(KnownFolders.Libraries.ParsingName) &&
                                            e.PendingLocation.ParsingName != KnownFolders.Libraries.ParsingName)
                                        {
                                            ctgLibraries.Visibility = System.Windows.Visibility.Visible;
                                            ctgFolderTools.Visibility = System.Windows.Visibility.Collapsed;
                                            ctgImage.Visibility = System.Windows.Visibility.Collapsed;
                                            ctgArchive.Visibility = System.Windows.Visibility.Collapsed;
                                            ctgExe.Visibility = System.Windows.Visibility.Collapsed;
                                            inLibrary = true;

                                            try
                                            {
                                                ShellLibrary lib =
                                                    ShellLibrary.Load(e.PendingLocation.GetDisplayName(DisplayNameType.Default), false);
                                                IsFromSelectionOrNavigation = true;
                                                chkPinNav.IsChecked = lib.IsPinnedToNavigationPane;
                                                IsFromSelectionOrNavigation = false;
                                                foreach (ShellObject item in lib)
                                                {
                                                    MenuItem miItem = new MenuItem();
                                                    miItem.Header = item.GetDisplayName(DisplayNameType.Default);
                                                    miItem.Tag = item;
                                                    item.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
                                                    item.Thumbnail.CurrentSize = new System.Windows.Size(16, 16);
                                                    miItem.Icon = item.Thumbnail.BitmapSource;
                                                    miItem.GroupName = "GRDS1";
                                                    miItem.IsCheckable = true;
                                                    miItem.IsChecked = (item.ParsingName == lib.DefaultSaveFolder);
                                                    miItem.Click += new RoutedEventHandler(miItem_Click);
                                                    btnDefSave.Items.Add(miItem);
                                                }

                                                btnDefSave.IsEnabled = !(lib.Count == 0);
                                                lib.Close();
                                            }
                                            catch
                                            {

                                            }
                                        }
                                        else
                                        {
                                            if (!e.PendingLocation.ParsingName.ToLowerInvariant().EndsWith("library-ms"))
                                            {
                                                btnDefSave.Items.Clear();
                                                ctgLibraries.Visibility = System.Windows.Visibility.Collapsed;
                                                inLibrary = false;
                                            }
                                            //MessageBox.Show("Not in Library");
                                        }
                                        if (e.PendingLocation.IsDrive)
                                        {
                                            ctgDrive.Visibility = System.Windows.Visibility.Visible;
                                            inDrive = true;
                                            //MessageBox.Show("In Drive");
                                        }
                                        else
                                        {
                                            ctgDrive.Visibility = System.Windows.Visibility.Collapsed;
                                            inDrive = false;
                                            //MessageBox.Show("Not In Drive");
                                        }
                                        if (isinLibraries)
                                        {
                                            ctgFolderTools.Visibility = Visibility.Collapsed;
                                        }

                                    }
                                ));

                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
            catch (Exception exe)
            {
                ShellObject ne = e.PendingLocation;
                bool isinLibraries = false;
                bool itisLibraries = false;

                if (ne.Parent.ParsingName == KnownFolders.Libraries.ParsingName)
                {
                    isinLibraries = true;
                }
                else
                {
                    isinLibraries = false;
                }

                if (ne.ParsingName == KnownFolders.Libraries.ParsingName)
                {
                    itisLibraries = true;
                }
                else
                {
                    itisLibraries = false;
                }

                //if (MessageBox.Show("An error occurred while loading a folder. Please report this issue at http://bexplorer.codeplex.com/. \r\n\r\nHere is some information about the folder being loaded:\r\n\r\nName: " + ne.GetDisplayName(DisplayNameType.Default) + "\r\nLocation: " + ne.ParsingName +
                //    "\r\n\r\nFolder, Drive, or Library: " + GetYesNoFromBoolean(ne.IsFolder) + "\r\nDrive: " + GetYesNoFromBoolean(ne.IsDrive) + "\r\nNetwork Drive: " + GetYesNoFromBoolean(ne.IsNetDrive) + "\r\nRemovable: " + GetYesNoFromBoolean(ne.IsRemovable) +
                //    "\r\nSearch Folder: " + GetYesNoFromBoolean(ne.IsSearchFolder) + "\r\nShared: " + GetYesNoFromBoolean(ne.IsShared) + "\r\nShortcut: " + GetYesNoFromBoolean(ne.IsLink) + "\r\nLibrary: " + GetYesNoFromBoolean(isinLibraries) + "\r\nLibraries Folder: " + GetYesNoFromBoolean(itisLibraries) +
                //    "\r\n\r\n Would you like to see additional information? Click No to try continuing the program.", "Error Occurred on Completing Navigation", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                //{
                //    MessageBox.Show("An error occurred while loading a folder. Please report this issue at http://bexplorer.codeplex.com/. \r\n\r\nHere is additional information about the error: \r\n\r\n" + exe.Message + "\r\n\r\n" + exe.ToString(), "Additional Error Data", MessageBoxButton.OK, MessageBoxImage.Error);
                //}
            }

            Explorer.ExplorerSetFocus();

            //if (Itmpop.Visibility == System.Windows.Visibility.Visible)
            //{
            //    Itmpop.Visibility = System.Windows.Visibility.Hidden;
            //}
        }
 private void browser_NavigationPending(object sender, NavigationPendingEventArgs e)
 {
     updateButtonStatus();
 }