コード例 #1
0
        /// <summary>
        /// Deletes the file or folder from the disk. Folders will be recursively deleted.
        /// </summary>
        public virtual void Delete()
        {
            // Don't delete if we're not supposed to.
            if (!this.CanDelete)
            {
                return;
            }

            // First ask the user if he really wants to delete the item.
            PackageContext        context   = Package.Instance.Context;
            NativeResourceManager resources = context.NativeResources;
            string             title        = resources.GetString(ResourceId.IDS_DELETECONFIRMATION_TITLE, this.Caption);
            string             message      = resources.GetString(ResourceId.IDS_DELETECONFIRMATION, this.Caption);
            VsMessageBoxResult result       = context.ShowMessageBox(title, message, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_WARNING);

            if (result == VsMessageBoxResult.No)
            {
                return;
            }

            // Close the node first.
            this.Close();

            // Remove the node from the project.
            this.RemoveFromProject();

            // Attempt the delete the node from disk.
            try
            {
                if (this.IsFolder && Directory.Exists(this.AbsolutePath))
                {
                    Directory.Delete(this.AbsolutePath, true);
                }
                else if (this.IsFile && File.Exists(this.AbsolutePath))
                {
                    // Make sure the file is not read only, hidden, etc.
                    File.SetAttributes(this.AbsolutePath, FileAttributes.Normal);
                    File.Delete(this.AbsolutePath);
                }
            }
            catch (Exception e)
            {
                title   = resources.GetString(ResourceId.IDS_E_DELETEFROMPROJECT_TITLE);
                message = resources.GetString(ResourceId.IDS_E_DELETEFROMPROJECT, e.Message);
                context.ShowErrorMessageBox(title, message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Shows a yes/no dialog box with the No button selected by default.
        /// </summary>
        /// <param name="title">The first line of the message box (can be null).</param>
        /// <param name="message">The second line of the message box if <paramref name="title"/> is null; otherwise the first line.</param>
        /// <param name="icon">The icon to show on the message box.</param>
        /// <returns>true if the user clicked Yes; otherwise, false.</returns>
        public bool PromptYesNo(string title, string message, OLEMSGICON icon)
        {
            VsMessageBoxResult result = this.ShowMessageBox(title, message, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, icon);

            return(result == VsMessageBoxResult.Yes);
        }