Esempio n. 1
0
        public MacrosToolWindow() :
            base(null)
        {
            this.owningPackage    = VSMacrosPackage.Current;
            this.Caption          = Resources.ToolWindowTitle;
            this.BitmapResourceID = 301;
            this.BitmapIndex      = 1;

            // Instantiate Tool Window Toolbar
            this.ToolBar = new CommandID(GuidList.GuidVSMacrosCmdSet, PkgCmdIDList.MacrosToolWindowToolbar);

            Manager.CreateFileSystem();

            string macroDirectory = Manager.MacrosPath;

            // Create tree view root
            MacroFSNode root = new MacroFSNode(macroDirectory);

            // Make sure it is opened and selected by default
            root.IsExpanded = true;

            // Initialize Macros Control
            var macroControl = new MacrosControl(root);

            macroControl.Loaded += this.OnLoaded;
            this.Content         = macroControl;

            Manager.Instance.LoadFolderExpansion();
        }
Esempio n. 2
0
        public MacrosToolWindow()
            : base(null)
        {
            this.owningPackage = VSMacrosPackage.Current;
            this.Caption = Resources.ToolWindowTitle;
            this.BitmapResourceID = 301;
            this.BitmapIndex = 1;

            // Instantiate Tool Window Toolbar
            this.ToolBar = new CommandID(GuidList.GuidVSMacrosCmdSet, PkgCmdIDList.MacrosToolWindowToolbar);

            Manager.CreateFileSystem();

            string macroDirectory = Manager.MacrosPath;

            // Create tree view root
            MacroFSNode root = new MacroFSNode(macroDirectory);

            // Make sure it is opened and selected by default
            root.IsExpanded = true;

            // Initialize Macros Control
            var macroControl = new MacrosControl(root);
            macroControl.Loaded += this.OnLoaded;
            this.Content = macroControl;

            Manager.Instance.LoadFolderExpansion();
        }
Esempio n. 3
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;
     }
 }
Esempio n. 4
0
        public MacrosControl(MacroFSNode rootNode)
        {
            Current = this;

            MacroFSNode.RootNode = rootNode;

            // Let the UI bind to the view-model
            this.DataContext = new MacroFSNode[] { rootNode };
            this.InitializeComponent();
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
        }