Exemplo n.º 1
0
 private void TreeViewItem_DragLeave(object sender, DragEventArgs e)
 {
     if (this.isDragging || e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         // Remove highlight on DragLeave
         TreeViewItem item = sender as TreeViewItem;
         MacrosControl.SetIsTreeViewItemDropOver(item, false);
         e.Handled = true;
     }
 }
Exemplo n.º 2
0
        private void TreeViewItem_DragEnter(object sender, DragEventArgs e)
        {
            if (this.isDragging || e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // Highlight item on DragEnter
                TreeViewItem item = sender as TreeViewItem;

                if ((MacroFSNode)item.Header != MacroFSNode.RootNode)
                {
                    MacrosControl.SetIsTreeViewItemDropOver(item, true);
                }
                e.Handled = true;
            }
        }
Exemplo n.º 3
0
        private void TreeViewItem_Drop(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;
            e.Handled = true;

            // Get target node
            TreeViewItem targetItem = this.GetNearestContainer(e.OriginalSource as UIElement);
            MacroFSNode  target     = targetItem.Header as MacroFSNode;

            if (e.Data.GetDataPresent(typeof(MacroFSNode)) && this.isDragging)
            {
                // Get dragged node
                MacroFSNode dragged = e.Data.GetData(typeof(MacroFSNode)) as MacroFSNode;

                if (target != null && dragged != null && target != dragged)
                {
                    if (!target.IsDirectory)
                    {
                        target = target.Parent;
                    }

                    Manager.Instance.MoveItem(dragged, target);
                }
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] droppedFiles = e.Data.GetData(DataFormats.FileDrop, true) as string[];

                if (!target.IsDirectory)
                {
                    target = target.Parent;
                }

                foreach (string s in droppedFiles)
                {
                    string filename = Path.GetFileNameWithoutExtension(s);

                    // If the file is a macro file
                    if (Path.GetExtension(s) == ".js")
                    {
                        string destPath = Path.Combine(target.FullPath, filename + ".js");
                        VSConstants.MessageBoxResult result = VSConstants.MessageBoxResult.IDYES;

                        if (File.Exists(destPath))
                        {
                            string message = string.Format(VSMacros.Resources.DragDropFileExists, filename);
                            result = Manager.Instance.ShowMessageBox(message, OLEMSGBUTTON.OLEMSGBUTTON_YESNO);
                        }

                        if (result == VSConstants.MessageBoxResult.IDYES)
                        {
                            File.Copy(s, destPath, true);
                        }
                    }
                    else if (Path.GetExtension(s) == "")
                    {
                        string destPath = Path.Combine(target.FullPath, filename);
                        VSConstants.MessageBoxResult result = VSConstants.MessageBoxResult.IDYES;

                        if (Directory.Exists(destPath))
                        {
                            string message = string.Format(VSMacros.Resources.DragDropFileExists, filename);
                            result = Manager.Instance.ShowMessageBox(message, OLEMSGBUTTON.OLEMSGBUTTON_YESNO);
                        }

                        if (result == VSConstants.MessageBoxResult.IDYES)
                        {
                            Manager.DirectoryCopy(s, destPath, true);
                        }
                    }
                }

                // Unset IsTreeViewItemDropOver for target
                MacrosControl.SetIsTreeViewItemDropOver(targetItem, false);

                MacroFSNode.RefreshTree(target);
            }

            this.isDragging = false;
        }