Beispiel #1
0
        public void Delete()
        {
            MacroFSNode macro = this.SelectedMacro;

            // Don't delete if macro is being edited
            if (macro.IsEditable)
            {
                return;
            }

            string path = macro.FullPath;

            FileSystemInfo file;
            string         fileName = Path.GetFileNameWithoutExtension(path);
            string         message;

            if (macro.IsDirectory)
            {
                file    = new DirectoryInfo(path);
                message = string.Format(VSMacros.Resources.DeleteFolder, fileName);
            }
            else
            {
                file    = new FileInfo(path);
                message = string.Format(VSMacros.Resources.DeleteMacro, fileName);
            }

            if (file.Exists)
            {
                VSConstants.MessageBoxResult result;
                result = this.ShowMessageBox(message, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL);

                if (result == VSConstants.MessageBoxResult.IDOK)
                {
                    try
                    {
                        // Delete file or directory from disk
                        Manager.DeleteFileOrFolder(path);

                        // Delete file from collection
                        macro.Delete();
                    }
                    catch (Exception e)
                    {
                        this.ShowMessageBox(e.Message);
                    }
                }
            }
            else
            {
                macro.Delete();
            }
        }
        /// <summary>
        /// Notifies clients of changes made to one or more files.
        /// </summary>
        /// <param name="numberOfFilesChanged">
        /// Number of files changed.
        /// </param>
        /// <param name="files">
        /// Array of file names.
        /// </param>
        /// <param name="typesOfChange">
        /// Array of flags indicating the type of changes. <see cref="_VSFILECHANGEFLAGS" />.
        public int FilesChanged(uint numberOfFilesChanged, string[] files, uint[] changeTypes)
        {
            // Go over each file and treat the change appropriately
            for (int i = 0; i < files.Length; i++)
            {
                string             path   = files[i];
                _VSFILECHANGEFLAGS change = (_VSFILECHANGEFLAGS)changeTypes[i];

                // _VSFILECHANGEFLAGS.VSFILECHG_Add is handled by DirectoryChanged
                // Only handle _VSFILECHANGEFLAGS.VSFILECHG_Del here
                if (change == _VSFILECHANGEFLAGS.VSFILECHG_Del)
                {
                    MacroFSNode node = MacroFSNode.FindNodeFromFullPath(path);
                    if (node != null)
                    {
                        node.Delete();
                    }
                }
            }

            return(VSConstants.S_OK);
        }