Ejemplo n.º 1
0
        /// <summary>
        /// Selects the <paramref name="tab"/> and navigates to it correctly if and only if it is not already selected
        /// </summary>
        /// <param name="tab">The tab you want to select</param>
        private void SelectTab(Wpf.Controls.TabItem tab)
        {
            if (tab != null && (!tab.ShellObject.Equals(this._ShellListView.CurrentFolder) || tab.ShellObject.IsSearchFolder))
            {
                this.tcMain.isGoingBackOrForward = true;
                this.NavigationController(tab.ShellObject);
                var selectedItem = tab; //TODO: Find out if we can replace [selectedItem] with [tab]
                selectedItem.Header      = tab.ShellObject.DisplayName;
                selectedItem.Icon        = tab.ShellObject.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);
                selectedItem.ShellObject = tab.ShellObject;
                var selectedPaths = selectedItem?.SelectedItems;
                if (selectedPaths == null || !selectedPaths.Any())
                {
                    return;
                }

                foreach (var path in selectedPaths)
                {
                    var sho = this._ShellListView.Items.FirstOrDefault(w => w.ParsingName == path);
                    if (sho != null && sho.Equals(this._ShellListView.Items[sho.ItemIndex]))
                    {
                        this._ShellListView.SelectItemByIndex(sho.ItemIndex, true);
                        selectedPaths.Remove(path);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ShowUC(UserControl uc, string header)
        {
            bool add = true;

            /*
             * if (tc_Child.Items.Count > 0)
             * {
             *  foreach (TabItem item in tc_Child.Items)
             *  {
             *      if (item.Header.ToString().Trim() == header)
             *      {
             *          add = false;
             *          tc_Child.SelectedItem = item;
             *          break;
             *      }
             *  }
             * }
             * if (add)
             * {
             *  TabItem ti = new TabItem();
             *  ti.Header = "  " + header + "  ";
             *  ti.FontSize = 16;
             *  ti.FontWeight = FontWeights.Bold;
             *  uc.Height = tc_Child.ActualHeight < uc.Height ? tc_Child.ActualHeight : uc.Height;
             *  uc.Width = tc_Child.ActualWidth < uc.Width ? tc_Child.ActualWidth : uc.Width;
             *  ti.Content = uc;
             *  tc_Child.Items.Add(ti);
             *  tc_Child.SelectedItem = ti;
             * }*/
            //带关闭功能的TabControl
            if (tc_Child2.Items.Count > 0)
            {
                foreach (Wpf.Controls.TabItem item in tc_Child2.Items)
                {
                    if (item.Header.ToString().Trim() == header)
                    {
                        add = false;
                        tc_Child2.SelectedItem = item;
                        break;
                    }
                }
            }
            if (add)
            {
                Wpf.Controls.TabItem ti = new Wpf.Controls.TabItem();
                ti.Header     = "  " + header + "  ";
                ti.FontSize   = 16;
                ti.FontWeight = FontWeights.Bold;
                uc.Height     = tc_Child2.ActualHeight < uc.Height ? tc_Child2.ActualHeight : uc.Height;
                uc.Width      = tc_Child2.ActualWidth < uc.Width ? tc_Child2.ActualWidth : uc.Width;
                ti.Content    = uc;
                tc_Child2.Items.Add(ti);
                tc_Child2.SelectedItem = ti;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates initial tab
        /// </summary>
        /// <param name="win">The main window</param>
        /// <param name="sho">The shell object used for tab creation</param>
        private void CreateInitialTab(MainWindow win, IListItemEx sho)
        {
            var bmpSource = sho.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);
            var newt      = new Wpf.Controls.TabItem(sho)
            {
                Header = sho.DisplayName,
                Icon   = bmpSource
            };

            newt.PreviewMouseMove += this.Newt_PreviewMouseMove;
            newt.ToolTip           = sho.ParsingName.Replace("%20", " ").Replace("%3A", ":").Replace("%5C", @"\");
            win.tcMain.CloneTabItem(newt);
        }
Ejemplo n.º 4
0
 private void SelectTab(Wpf.Controls.TabItem tab)
 {
     if (tab == null)
     {
         return;
     }
     //tab.ShellObject = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, tab.ShellObject.PIDL);
     if (!tab.ShellObject.Equals(this._ShellListView.CurrentFolder) || tab.ShellObject.IsSearchFolder)
     {
         tcMain.isGoingBackOrForward = true;
         NavigationController(tab.ShellObject);
         var selectedItem = tab;
         selectedItem.Header = tab.ShellObject.DisplayName;
         var bmpSource = tab.ShellObject.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);
         selectedItem.Icon        = bmpSource;
         selectedItem.ShellObject = tab.ShellObject;
         if (selectedItem != null)
         {
             var selectedPaths = selectedItem.SelectedItems;
             if (selectedPaths != null && selectedPaths.Any())
             {
                 foreach (var path in selectedPaths.ToArray())
                 {
                     var sho = this._ShellListView.Items.ToArray().FirstOrDefault(w => w.ParsingName == path);
                     if (sho != null)
                     {
                         var index = sho.ItemIndex;
                         if (sho.Equals(this._ShellListView.Items[index]))
                         {
                             this._ShellListView.SelectItemByIndex(index, true);
                             selectedPaths.Remove(path);
                         }
                     }
                 }
             }
             else
             {
                 //this._ShellListView.ScrollToTop();
             }
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Closes a tab in the queries tab. If the source is modified (i.e. dirty)
        /// the user is asked if he wants to discard changes.
        /// </summary>
        /// <param name="source">The tab item that is to be closed</param>
        /// <param name="args">Not used.</param>
        public bool CloseQueryTab(Wpf.Controls.TabItem item)
        {
            var content = item.Content as QueryEditor;

            if (content.IsModified)
            {
                // Ask the user if he wants to discard the changes.
                MessageBoxResult result = MessageBox.Show("Discard unsaved changes?", "Unsaved changes", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result != MessageBoxResult.Yes)
                {
                    return(false);
                }
            }

            if (item.Parent is TabControl)
            {
                // TODO: Should the structure containing the mapping of name to highest value index
                // be updated too?
                this.CachedQueryResult.Remove(item.Content as QueryEditor);
                // tabControl.Items.Remove(item);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /*
         * private event EventHandler<TabItemCancelEventArgs> TabItemClosing;
         * private event EventHandler<TabItemEventArgs> TabItemClosed;
         */
        #endregion Events

        #region Tab Stuff

        public Wpf.Controls.TabItem NewTab(IListItemEx DefPath, bool IsNavigate)
        {
            this.IsInTabDragDrop = false;
            SelectNewTabOnCreate = false;
            var newt = new Wpf.Controls.TabItem(DefPath)
            {
                Header    = DefPath.DisplayName,
                Icon      = DefPath.ThumbnailSource(16, BExplorer.Shell.Interop.ShellThumbnailFormatOption.IconOnly, BExplorer.Shell.Interop.ShellThumbnailRetrievalOption.Default),
                ToolTip   = DefPath.ParsingName.Replace("%20", " ").Replace("%3A", ":").Replace("%5C", @"\"),
                AllowDrop = true
            };

            newt.DragEnter        += new DragEventHandler(newt_DragEnter);
            newt.DragOver         += new DragEventHandler(newt_DragOver);
            newt.PreviewMouseMove += new MouseEventHandler(newt_PreviewMouseMove);
            newt.PreviewMouseUp   += newt_PreviewMouseDown;
            newt.Drop             += new DragEventHandler(newt_Drop);
            newt.DragLeave        += newt_Leave;
            newt.GiveFeedback     += newt_GiveFeedback;

            //TODO: Try to remove this Try Catch
            try {
                Items.Add(newt);
                //IsSelectionHandled = false;
                if (IsNavigate)
                {
                    SelectNewTabOnCreate = true;
                    this.SelectedItem    = newt;
                }
            }
            catch (Exception) {
            }

            ConstructMoveToCopyToMenu();
            this.IsInTabDragDrop = true;
            return(newt);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates initial tab
 /// </summary>
 /// <param name="win">The main window</param>
 /// <param name="sho">The shell object used for tab creation</param>
 private void CreateInitialTab(MainWindow win, IListItemEx sho) {
   var bmpSource = sho.ThumbnailSource(16, ShellThumbnailFormatOption.IconOnly, ShellThumbnailRetrievalOption.Default);
   var newt = new Wpf.Controls.TabItem(sho) {
     Header = sho.DisplayName,
     Icon = bmpSource
   };
   newt.PreviewMouseMove += this.Newt_PreviewMouseMove;
   newt.ToolTip = sho.ParsingName.Replace("%20", " ").Replace("%3A", ":").Replace("%5C", @"\");
   win.tcMain.CloneTabItem(newt);
 }
Ejemplo n.º 8
0
        public TabItem CreateNewQueryTabItem(string name, string path, string text)
        {
            // If the user has already opened a tab by this name, and the text
            // is the same, then that tab is returned. If there is an existing one, but
            // the content has been changed, a a new one is created and the name is
            // made unambiguous by adding an index.

            foreach (Wpf.Controls.TabItem tab in this.view.queryTabPage.Items)
            {
                if (string.CompareOrdinal(tab.Title, name) == 0)
                {
                    // The name is already in use, but is not changed (since no ending "*").
                    return(tab);
                }
                if (string.CompareOrdinal(tab.Title, name + "*") == 0)
                {
                    // The name is already in use, and is modified (since ending "*").
                    name = this.NewQueryTabTitle(name);
                }
            }

            // It is vital that the IsModified call is made after the text is set.
#pragma warning disable IDE0017 // Simplify object initialization
            var editor = new QueryEditor(this);
#pragma warning restore IDE0017 // Simplify object initialization
            editor.Text       = text;
            editor.IsModified = false;

            var item = new Wpf.Controls.TabItem()
            {
                Header  = name,
                Tag     = path,
                ToolTip = "Unsaved " + name,
                Content = editor,
            };

            item.GotFocus       += this.QueryTabGotFocus;
            item.ToolTipOpening += this.QueryTabToolTip;

            // Add it to the tab page
            this.view.queryTabPage.Items.Add(item);

            this.CachedQueryResult[editor] = "";

            // Wire up the modified event on the editor to update the tab title
            var dpd = DependencyPropertyDescriptor.FromProperty(QueryEditor.IsModifiedProperty, typeof(QueryEditor));

            // Wire in code that updates the title as the content transitions
            // from modified to not modified.
            dpd.AddValueChanged(editor, (o, e) =>
            {
                var qe = o as QueryEditor;

                if (qe.IsModified)
                {
                    item.Title += "*";
                }
                else
                {
                    if (item.Title != null)
                    {
                        item.Title = item.Title.TrimEnd(new[] { '*' });
                    }
                }
            });

            return(item);
        }