public void NewMacro() { MacroFSNode macro = this.SelectedMacro; macro.IsExpanded = true; string basePath = Path.Combine(macro.FullPath, "New Macro"); string extension = ".js"; string path = basePath + extension; // Increase count until filename is available (e.g. 'New Macro (2).js') int count = 2; while (File.Exists(path)) { path = basePath + " (" + count++ + ")" + extension; } // Create the file File.WriteAllText(path, "/// <reference path=\"" + Manager.IntellisensePath + "\" />"); // Refresh the tree MacroFSNode.RefreshTree(); // Select new node MacroFSNode node = MacroFSNode.SelectNode(path); node.IsExpanded = true; node.IsEditable = true; }
public void Refresh(bool reloadShortcut = true) { // If the shortcuts have been modified, ask to save them if (this.shortcutsDirty && reloadShortcut) { VSConstants.MessageBoxResult result = this.ShowMessageBox(Resources.ShortcutsChanged, OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL); switch (result) { case VSConstants.MessageBoxResult.IDCANCEL: return; case VSConstants.MessageBoxResult.IDYES: this.SaveShortcuts(); break; } } // Recreate file system to ensure that the required files exist CreateFileSystem(); MacroFSNode.RefreshTree(); this.LoadShortcuts(); }
/// <summary> /// Notifies clients of changes made to a directory. /// </summary> /// <param name="dir"> /// Name of the directory that had a change. /// </param> public int DirectoryChanged(string dir) { MacroFSNode node = MacroFSNode.FindNodeFromFullPath(dir); if (node != null) { // Refresh tree rooted at the changed directory MacroFSNode.RefreshTree(node); } return(VSConstants.S_OK); }
public void NewFolder() { MacroFSNode macro = this.SelectedMacro; macro.IsExpanded = true; string basePath = Path.Combine(macro.FullPath, "New Folder"); string path = basePath; int count = 2; while (Directory.Exists(path)) { path = basePath + " (" + count++ + ")"; } Directory.CreateDirectory(path); MacroFSNode.RefreshTree(); MacroFSNode node = MacroFSNode.SelectNode(path); node.IsEditable = true; }
public void MoveItem(MacroFSNode sourceItem, MacroFSNode targetItem) { string sourcePath = sourceItem.FullPath; string targetPath = Path.Combine(targetItem.FullPath, sourceItem.Name); string extension = ".js"; MacroFSNode selected; // We want to expand the node and all its parents if it was expanded before OR if it is a file bool wasExpanded = sourceItem.IsExpanded; try { // Move on disk if (sourceItem.IsDirectory) { System.IO.Directory.Move(sourcePath, targetPath); } else { targetPath = targetPath + extension; System.IO.File.Move(sourcePath, targetPath); // Close in the editor this.Reopen(sourcePath, targetPath); } // Move shortcut as well if (sourceItem.Shortcut != MacroFSNode.None) { int shortcutNumber = sourceItem.Shortcut; Manager.Shortcuts[shortcutNumber] = targetPath; } } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) { throw; } targetPath = sourceItem.FullPath; Manager.Instance.ShowMessageBox(e.Message); } CreateCurrentMacro(); // Refresh tree MacroFSNode.RefreshTree(); // Restore previously selected node selected = MacroFSNode.SelectNode(targetPath); selected.IsExpanded = wasExpanded; selected.Parent.IsExpanded = true; // Notify change in shortcut selected.Shortcut = MacroFSNode.ToFetch; // Make editable if the macro is the current macro if (sourceItem.FullPath == Manager.CurrentMacroPath) { selected.IsEditable = true; } }
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; }