示例#1
0
 private void SearchResults_Drop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(typeof(TreeViewEntryItemModel)))
     {
         var item     = e.Data.GetData(typeof(TreeViewEntryItemModel)) as TreeViewEntryItemModel;
         var treeView = sender as TreeView;
         if (treeView == null || item == null)
         {
             return;
         }
         var treeViewItem = treeView.FindItemFromSource((DependencyObject)e.OriginalSource);
         TreeViewEntryItemModel dropTarget = null;
         if (treeViewItem != null)
         {
             dropTarget = treeViewItem.Header as TreeViewEntryItemModel;
             if (dropTarget == null)
             {
                 return;
             }
         }
         if (item != dropTarget)
         {
             this.MainViewModel.TreeViewModel.MoveTreeItem(item, dropTarget, this.MainViewModel.WorkspaceDirectoryModel.CurrentWorkspaceDirectory);
         }
     }
 }
示例#2
0
        public void HandleDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(TreeViewEntryItemModel)))
            {
                var item     = e.Data.GetData(typeof(TreeViewEntryItemModel)) as TreeViewEntryItemModel;
                var treeView = sender as TreeView;

                if (treeView == null || item == null)
                {
                    return;
                }

                var treeViewItem = treeView.FindItemFromSource((DependencyObject)e.OriginalSource);

                TreeViewEntryItemModel dropTarget = null;

                if (treeViewItem != null)
                {
                    dropTarget = treeViewItem.Header as TreeViewEntryItemModel;
                    if (dropTarget == null)
                    {
                        return;
                    }
                }

                if (item != dropTarget)
                {
                    this.commandExecutor.ExecuteWithParam <MoveItemCommand, Tuple <TreeViewEntryItemModel, TreeViewEntryItemModel> >(Tuple.Create(item, dropTarget));
                }
            }
            this.ClearDragStartPoint();
        }
        public bool ExpandAndSelectCurrentlyOpenedItem()
        {
            string path = this.iseIntegrator.SelectedFilePath;

            if (path == null)
            {
                return(false);
            }

            var selectedItem = this.treeViewModel.SelectedItem;

            if (selectedItem != null && selectedItem.Path.StartsWith(path))
            {
                return(true);
            }

            TreeViewEntryItemModel item = this.treeViewModel.FindTreeViewEntryItemByPath(path);

            if (item == null)
            {
                return(false);
            }

            this.projectExplorerWindow.SearchResultsTreeView.ExpandAndSelectItem(item);
            return(true);
        }
        private void SetDotSourceVisibility(StretchingTreeView treeView, TreeViewEntryItemModel item)
        {
            MenuItem dotSourceMenuItem = this.FindMenuItem(treeView.ContextMenu.Items, "Dot Source");

            if (dotSourceMenuItem != null)
            {
                dotSourceMenuItem.Visibility = item.NodeType == NodeType.Directory || item.NodeType == NodeType.Intermediate || iseIntegrator.SelectedFilePath == null
                    ? Visibility.Collapsed : Visibility.Visible;
            }
        }
        private TreeViewEntryItemModel GetParentFileItem(TreeViewEntryItemModel selectedItem)
        {
            var item = selectedItem;

            while (item.NodeType != NodeType.File && item.Parent != null)
            {
                item = item.Parent;
            }
            if (item.NodeType == NodeType.File)
            {
                return(item);
            }
            return(null);
        }
        private void SetIncludeAndExcludeVisibility(StretchingTreeView treeView, TreeViewEntryItemModel item)
        {
            MenuItem includeMenuItem = this.FindMenuItem(treeView.ContextMenu.Items, "Include");
            MenuItem excludeMenuItem = this.FindMenuItem(treeView.ContextMenu.Items, "Exclude");

            if (includeMenuItem != null && excludeMenuItem != null)
            {
                if (item.IsExcluded)
                {
                    includeMenuItem.Visibility = filesPatternProvider.ExcludePaths.Contains(item.Path) ? Visibility.Visible : Visibility.Collapsed;
                    excludeMenuItem.Visibility = Visibility.Collapsed;
                }
                else
                {
                    includeMenuItem.Visibility = Visibility.Collapsed;
                    excludeMenuItem.Visibility = Visibility.Visible;
                }
            }
        }
示例#7
0
        public void LocateFileInTree()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                string path = this.MainViewModel.IseIntegrator.SelectedFilePath;
                if (path == null)
                {
                    return;
                }
                var selectedItem = this.SearchResults.SelectedItem as TreeViewEntryItemModel;
                if (selectedItem != null && selectedItem.Path.StartsWith(path))
                {
                    return;
                }
                TreeViewEntryItemModel item = this.MainViewModel.TreeViewModel.FindTreeViewEntryItemByPath(path);
                if (item == null)
                {
                    return;
                }

                SearchResults.ExpandAndSelectItem(item);
            });
        }
        private void EndRenamingTreeItem(string newValue, bool save, TreeViewEntryItemModel selectedItem)
        {
            if (!save || String.IsNullOrEmpty(newValue) || selectedItem == null)
            {
                return;
            }

            try
            {
                string oldPath = selectedItem.Path;
                string newPath = this.GenerateNewPath(selectedItem.Path, newValue);
                bool   closed  = this.iseIntegrator.CloseFile(oldPath);
                fileSystemOperationsService.RenameFileOrDirectory(oldPath, newPath);
                if (closed)
                {
                    this.iseIntegrator.GoToFile(newPath);
                }
            }
            catch (Exception e)
            {
                this.treeViewModel.PathOfItemToSelectOnRefresh = null;
                this.messageBoxHelper.ShowError("Failed to rename: " + e.Message);
            }
        }
        private void EndAddingTreeItem(string newValue, bool save, TreeViewEntryItemModel selectedItem)
        {
            if (selectedItem == null)
            {
                return;
            }
            if (!save || String.IsNullOrEmpty(newValue))
            {
                this.documentHierarchyFactory.RemoveTemporaryNode(selectedItem.Node);
                this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                return;
            }
            var   newPath = this.GenerateNewPath(selectedItem.Path, newValue);
            INode newNode = null;

            if (this.treeViewModel.FindTreeViewEntryItemByPath(newPath) != null)
            {
                this.documentHierarchyFactory.RemoveTemporaryNode(selectedItem.Node);
                this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                this.messageBoxHelper.ShowError("Item '" + newPath + "' already exists.");
                return;
            }
            if (selectedItem.NodeType == NodeType.Directory)
            {
                try
                {
                    newNode = this.documentHierarchyFactory.UpdateTemporaryNode(selectedItem.Node, newPath);
                    var parent = selectedItem.Parent;
                    this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                    selectedItem = this.treeViewModel.CreateTreeViewEntryItemModel(newNode, parent, true);
                    this.filesPatternProvider.AddAdditionalPath(newPath);
                    fileSystemOperationsService.CreateDirectory(newPath);
                }
                catch (Exception e)
                {
                    if (newNode != null)
                    {
                        newNode.Remove();
                    }
                    if (selectedItem != null)
                    {
                        this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                    }
                    this.treeViewModel.PathOfItemToSelectOnRefresh = null;
                    this.messageBoxHelper.ShowError("Failed to create directory '" + newPath + "': " + e.Message);
                }
            }
            else if (selectedItem.NodeType == NodeType.File)
            {
                try
                {
                    newNode = this.documentHierarchyFactory.UpdateTemporaryNode(selectedItem.Node, newPath);
                    var parent = selectedItem.Parent;
                    this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                    selectedItem = this.treeViewModel.CreateTreeViewEntryItemModel(newNode, parent, true);
                    this.filesPatternProvider.AddAdditionalPath(newPath);
                    fileSystemOperationsService.CreateFile(newPath);
                    this.iseIntegrator.GoToFile(newPath);
                }
                catch (Exception e)
                {
                    if (newNode != null)
                    {
                        newNode.Remove();
                    }
                    if (selectedItem != null)
                    {
                        this.treeViewModel.DeleteTreeViewEntryItemModel(selectedItem);
                    }
                    this.treeViewModel.PathOfItemToSelectOnRefresh = null;
                    this.messageBoxHelper.ShowError("Failed to create file '" + newPath + "': " + e.Message);
                }
            }
        }
示例#10
0
 /// <summary>
 /// Searches a TreeView for the provided object and selects it if found
 /// </summary>
 /// <param name="treeView">The TreeView containing the item</param>
 /// <param name="item">The item to search and select</param>
 public static void ExpandAndSelectItem(this TreeView treeView, TreeViewEntryItemModel item)
 {
     ExpandAndSelectItemContainer(treeView, item);
 }
示例#11
0
        /// <summary>
        /// Finds the provided object in an ItemsControl's children and selects it
        /// </summary>
        /// <param name="parentContainer">The parent container whose children will be searched for the selected item</param>
        /// <param name="itemToSelect">The item to select</param>
        /// <returns>True if the item is found and selected, false otherwise</returns>
        private static bool ExpandAndSelectItemContainer(ItemsControl parentContainer, TreeViewEntryItemModel itemToSelect)
        {
            IList <TreeViewItem> applicableParents = new List <TreeViewItem>();

            //check all items at the current level
            foreach (TreeViewEntryItemModel item in parentContainer.Items)
            {
                if (itemToSelect.Path.StartsWith(item.Path))
                {
                    var currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                    //if the data item matches the item we want to select, set the corresponding
                    //TreeViewItem IsSelected to true
                    if (item == itemToSelect && currentContainer != null)
                    {
                        currentContainer.IsSelected = true;
                        currentContainer.BringIntoView();

                        //the item was found
                        return(true);
                    }
                    else
                    {
                        applicableParents.Add(currentContainer);
                    }
                }
            }

            //if we get to this point, the selected item was not found at the current level, so we must check the children
            foreach (TreeViewItem currentContainer in applicableParents)
            {
                //if children exist
                if (currentContainer != null && currentContainer.Items.Count > 0)
                {
                    //keep track of if the TreeViewItem was expanded or not
                    bool wasExpanded = currentContainer.IsExpanded;

                    //expand the current TreeViewItem so we can check its child TreeViewItems
                    currentContainer.IsExpanded = true;

                    //if the TreeViewItem child containers have not been generated, we must listen to
                    //the StatusChanged event until they are
                    if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                    {
                        //store the event handler in a variable so we can remove it (in the handler itself)
                        EventHandler eh = null;
                        eh = delegate
                        {
                            if (currentContainer.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                            {
                                if (ExpandAndSelectItemContainer(currentContainer, itemToSelect) == false)
                                {
                                    //The assumption is that code executing in this EventHandler is the result of the parent not
                                    //being expanded since the containers were not generated.
                                    //since the itemToSelect was not found in the children, collapse the parent since it was previously collapsed
                                    currentContainer.IsExpanded = false;
                                }

                                //remove the StatusChanged event handler since we just handled it (we only needed it once)
                                currentContainer.ItemContainerGenerator.StatusChanged -= eh;
                            }
                        };
                        currentContainer.ItemContainerGenerator.StatusChanged += eh;
                    }
                    else //otherwise the containers have been generated, so look for item to select in the children
                    {
                        if (ExpandAndSelectItemContainer(currentContainer, itemToSelect) == false)
                        {
                            //restore the current TreeViewItem's expanded state
                            currentContainer.IsExpanded = wasExpanded;
                        }
                        else //otherwise the node was found and selected, so return true
                        {
                            return(true);
                        }
                    }
                }
            }

            //no item was found
            return(false);
        }