Example #1
0
        private void actReSharperChangeSignature_Execute(ExecuteEventArgs ea)
        {
            bool      allowPersistResponse = false;
            string    title     = "Change Signature";
            string    message   = "CodeRush includes several useful refactorings dedicated to changing signatures. Select from one of the signature-changing refactorings below.";
            Redirects redirects = new Redirects();

            redirects.AddRefactoring("Add Parameter", "Place caret inside the parameter list before invoking.");
            redirects.AddRefactoring("Create Overload", "Place caret on the member declaration before invoking.");
            redirects.AddRefactoring("Decompose Parameter", "Place caret on the parameter to decompose before invoking.");
            redirects.AddRefactoring("Introduce Parameter Object", "Select the parameters to consolidate before invoking.");
            redirects.AddRefactoring("Make Extension", "Place caret on a method signature with parameters to extend before invoking.");
            redirects.AddRefactoring("Make Member non-Static", "Place caret on a static member signature before invoking.");
            redirects.AddRefactoring("Make Member Static", "Place caret on an instance member signature that can be made static before invoking.");
            redirects.AddRefactoring("Promote to Parameter", "Place caret on a local or field variable that can be promoted to a parameter before invoking.");
            redirects.AddRefactoring("Reorder Parameters", "Place caret on a parameter that can be reordered before invoking.");
            redirects.AddRefactoring("Safe Rename", "Place caret on a public member before invoking.");

            FrmResharperCompatibility frmResharperCompatibility = new FrmResharperCompatibility(title, message, redirects, allowPersistResponse);

            frmResharperCompatibility.ShowDialog(CodeRush.IDE);
            if (frmResharperCompatibility.Result == CompatibilityResult.ExecuteCommand)
            {
                CodeRush.Command.Execute(frmResharperCompatibility.Command, frmResharperCompatibility.Parameters);
            }
        }
Example #2
0
        private void actReSharperSurroundWithTemplate_Execute(ExecuteEventArgs ea)
        {
            bool      allowPersistResponse = false;
            string    title     = "Surround With Template";
            string    message   = "CodeRush includes several built-in features to wrap and modify selections. There are keyboard shortcuts for many of these (just select the code you want to modify and press the specified key), and you can also access these from the right-click context menu. Select from one of the options below.";
            Redirects redirects = new Redirects();

            redirects.AddSelectionEmbedding("block", "Embeds a selection inside block delimiters (e.g., {} braces in C# or C++).");
            redirects.AddSelectionEmbedding("lock", "Embeds a selection inside a lock statement.");
            redirects.AddSelectionEmbedding("region", "Embeds a selection inside a region.");
            redirects.AddSelectionEmbedding("SyncLock", "Embeds a selection inside a SyncLock statement.");
            redirects.AddSelectionEmbedding("ToString", "Converts a selection to a string, escaping characters as needed.");
            redirects.AddSelectionEmbedding("try/catch", "Embeds a selection inside a try/catch block.");
            redirects.AddSelectionEmbedding("try/catch/finally", "Embeds a selection inside a try/catch/finally block.");
            redirects.AddSelectionEmbedding("try/finally", "Embeds a selection inside a try/finally block.");
            redirects.AddSelectionEmbedding("using", "Embeds a selection inside a using statement.");
            redirects.AddSelectionEmbedding("WaitCursor", "Embeds a selection inside code that displays an hourglass cursor while the code executes.");
            redirects.AddOptionsPage("Embedding Options && Customization", "Editor\\Selections\\Embedding", "Click this button to view, change, and create custom embeddings.");

            FrmResharperCompatibility frmResharperCompatibility = new FrmResharperCompatibility(title, message, redirects, allowPersistResponse);

            frmResharperCompatibility.ShowDialog(CodeRush.IDE);
            if (frmResharperCompatibility.Result == CompatibilityResult.ExecuteCommand)
            {
                CodeRush.Command.Execute(frmResharperCompatibility.Command, frmResharperCompatibility.Parameters);
            }
        }
        // private methods...
        #region AddRedirectControls
        private void AddRedirectControls(Redirects redirects)
        {
            const int INT_TopMargin           = 5;
            const int INT_SpaceBetweenButtons = 4;

            int yPos = lblOptions.Bottom + INT_TopMargin;

            int longestButtonTextWidth = 0;

            foreach (CompatibilityRedirect redirect in redirects)
            {
                Graphics graphics  = Graphics.FromHwnd(Handle);
                SizeF    rect      = graphics.MeasureString(redirect.ButtonText, Font);
                int      thisWidth = (int)Math.Ceiling(rect.Width);
                if (thisWidth > longestButtonTextWidth)
                {
                    longestButtonTextWidth = thisWidth;
                }
            }
            const int INT_ExplanationLabelMargin = 8; // Distance between disabled button and explaning label.
            int       xPos         = 8;
            int       buttonWidth  = longestButtonTextWidth + 16;
            int       longestWidth = buttonWidth;

            foreach (CompatibilityRedirect redirect in redirects)
            {
                RedirectButton button = new RedirectButton(redirect.Command, redirect.Parameters);
                pnlOptions.Controls.Add(button);
                button.Text    = redirect.ButtonText;
                button.Enabled = redirect.IsAvailable;
                button.Left    = xPos;
                button.Width   = buttonWidth;

                toolTip1.SetToolTip(button, redirect.Description);
                button.Top    = yPos;
                button.Click += new EventHandler(redirectButton_Click);

                if (!redirect.IsAvailable)
                {
                    Label explanationLabel = new Label();
                    pnlOptions.Controls.Add(explanationLabel);
                    explanationLabel.Top       = yPos;
                    explanationLabel.Left      = button.Right + INT_ExplanationLabelMargin;
                    explanationLabel.AutoSize  = true;
                    explanationLabel.Text      = redirect.AvailabilityHint;
                    explanationLabel.ForeColor = SystemColors.GrayText;
                    if (longestWidth < explanationLabel.Right)
                    {
                        longestWidth = explanationLabel.Right;
                    }
                }

                yPos += button.Height + INT_SpaceBetweenButtons;
            }
            pnlOptions.Height = yPos;
            pnlOptions.Width  = longestWidth;
        }
Example #4
0
        public void TryCommandElseRedirectToCommunity(string title, string Action, string WikiPage)
        {
            if (ActionExists(Action))
            {
                CodeRush.Command.Execute(Action);
                return;
            }
            bool      allowPersistResponse = false;
            string    message   = "This feature is not supplied by CodeRush directly. However a community plugin exists to provide an equivalent function.";
            Redirects redirects = new Redirects();

            redirects.AddLink(String.Format("Visit {0} page on the Community plugin site to retrieve this plugin.", WikiPage), GetWikiPage(WikiPage));

            FrmResharperCompatibility frmResharperCompatibility = new FrmResharperCompatibility(title, message, redirects, allowPersistResponse);

            frmResharperCompatibility.ShowDialog(CodeRush.IDE);
            if (frmResharperCompatibility.Result == CompatibilityResult.ExecuteCommand && frmResharperCompatibility.Command == "ShowURL")
            {
                CodeRush.ShowURL(frmResharperCompatibility.Parameters);
            }
        }
        // constructors...
        #region FrmResharperCompatibility(string message, Redirects redirects, bool allowPersistResponse)
        public FrmResharperCompatibility(string title, string message, Redirects redirects, bool allowPersistResponse)
        {
            InitializeComponent();

            ClearFields();

            int optionsHeight = 0;
            int optionsWidth  = 0;

            if (redirects != null)
            {
                AddRedirectControls(redirects);
                chkAlwaysPerformThisAction.Visible = allowPersistResponse;
                optionsHeight   = pnlOptions.Height;
                optionsWidth    = pnlOptions.Width;
                pnlOptions.Dock = DockStyle.Fill;
            }
            else
            {
                pnlOptions.Visible = false;
                chkAlwaysPerformThisAction.Visible = false;
            }

            if (optionsWidth > ClientSize.Width)
            {
                Width += optionsWidth - ClientSize.Width;
            }

            lblTitle.Text             = title;
            lblCompatibilityNote.Text = message;

            int desiredHeight = pnlTop.Height + optionsHeight + pnlBottom.Height;
            int deltaHeight   = desiredHeight - ClientSize.Height;

            Height     += deltaHeight;
            MinimumSize = new Size(Width, Height);
        }