private void deleteButton_Click(object sender, EventArgs e)
        {
            var macro = macroListBox.SelectedItem as SavedMacro;

            if (macro != null)
            {
                SavedMacros.DeleteMacro(macro.Guid);
                macros.Remove(macro);
            }
        }
        private void LoadSelectedMacro()
        {
            var macro = macroListBox.SelectedItem as SavedMacro;

            if (macro != null)
            {
                Macro.CurrentMacro = SavedMacros.GetSavedMacro(macro.Guid);
                Close();
            }
        }
        private void ShowRenameMacroDialog(SavedMacro macro)
        {
            var dialog = new SaveMacroDialog(macro.Name);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                SavedMacros.RenameMacro(macro.Guid, dialog.MacroName);
                macro.Name = dialog.MacroName;
                macros.ResetItem(macroListBox.SelectedIndex);
            }
        }
Ejemplo n.º 4
0
        private void MoveDownButton_Click(object sender, EventArgs e)
        {
            var macro = macroListBox.SelectedItem as SavedMacro;
            var index = macros.IndexOf(macro);

            if (index < macros.Count - 1)
            {
                var temp = macros[index + 1];
                macros[index + 1]          = macro;
                macros[index]              = temp;
                macroListBox.SelectedIndex = index + 1;
                SavedMacros.SaveMacroList(macros);
            }
        }
Ejemplo n.º 5
0
        // Executes the menu commands and does the recording of other commands
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == GuidList.guidToolsGroup)
            {
                // Record/stop
                if (nCmdID == PkgCmdIDList.idRecordMacro)
                {
                    if (Macro.CurrentMacro == null || !Macro.CurrentMacro.IsRecording)
                    {
                        Macro.StartNew();
                        AdornmentManager.ShowVisual();
                    }
                    else
                    {
                        Macro.CurrentMacro.StopRecording();
                        Macro.SaveToFile(Macro.CurrentMacro, Path.Combine(VSTextMacrosPackage.Current.MacroDirectory, "Current.xml"));
                        AdornmentManager.HideVisual();
                    }

                    return(VSConstants.S_OK);
                }

                // Playback
                if (nCmdID == PkgCmdIDList.idPlaybackMacro)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't playback: no macro was recorded");
                    }
                    else if (Macro.CurrentMacro.IsRecording)
                    {
                        MessageBox.Show("Can't playback: a macro is currently recording. Stop recording first.");
                    }
                    else
                    {
                        Playback(Macro.CurrentMacro);
                    }

                    return(VSConstants.S_OK);
                }

                // Playback multiple times
                if (nCmdID == PkgCmdIDList.idPlaybackMacroMultipleTimes)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't playback: no macro was recorded");
                    }
                    else if (Macro.CurrentMacro.IsRecording)
                    {
                        MessageBox.Show("Can't playback: a macro is currently recording. Stop recording first.");
                    }
                    else
                    {
                        var dlg = new RepeatMacroMultipleTimesDialog();
                        dlg.ShowDialog();
                        Playback(Macro.CurrentMacro, dlg.Times);
                    }

                    return(VSConstants.S_OK);
                }

                // Save macro
                if (nCmdID == PkgCmdIDList.idSaveMacro)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't save macro: no macro was recorded");
                    }
                    else if (Macro.CurrentMacro.IsRecording)
                    {
                        MessageBox.Show("Can't save macro: a macro is currently recording. Stop recording first.");
                    }
                    else
                    {
                        ShowSaveMacroDialog(Macro.CurrentMacro);
                    }

                    return(VSConstants.S_OK);
                }

                // Open saved macros
                if (nCmdID == PkgCmdIDList.idOpenSavedMacros)
                {
                    var list   = SavedMacros.GetMacroList();
                    var dialog = new SavedMacrosDialog(list);
                    dialog.ShowDialog();
                    return(VSConstants.S_OK);
                }
            }

            // Are we recording?
            if (Macro.CurrentMacro != null && Macro.CurrentMacro.IsRecording)
            {
                // Recordable command?
                if (RecordableCommands.Commands.ContainsKey(pguidCmdGroup) && RecordableCommands.Commands[pguidCmdGroup].Contains(nCmdID))
                {
                    // For the TYPECHAR command, read the actual character code
                    if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
                    {
                        Macro.CurrentMacro.AddCommand(pguidCmdGroup, nCmdID, nCmdexecopt, GetTypedChar(pvaIn));
                    }
                    else
                    {
                        Macro.CurrentMacro.AddCommand(pguidCmdGroup, nCmdID, nCmdexecopt, null);
                    }
                }
#if DEBUG
                else
                {
                    Trace.WriteLine(string.Format("Not recorded - Guid: {0}, ID: {1}, Opts: {2}, In: {3}", pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn != IntPtr.Zero ? "yes" : "no"));
                }
#endif
            }

            return(Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        // Updates menus states
        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            if (pguidCmdGroup == GuidList.guidMacrosCmdSet)
            {
                // Arguments check
                if (prgCmds == null)
                {
                    return(VSConstants.E_POINTER);
                }

                for (int i = 0; i < cCmds; i++)
                {
                    // Updates the text of the 'Start/Stop Recording' menu item
                    if (prgCmds[i].cmdID == PkgCmdIDList.idRecordMacro)
                    {
                        string menuText;
                        if (Macro.CurrentMacro == null || !Macro.CurrentMacro.IsRecording)
                        {
                            menuText = "&Start recording macro";
                        }
                        else
                        {
                            menuText = "&Stop recording macro";
                        }

                        // Copy the text to the OLECMDTEXT structure
                        if (pCmdText != IntPtr.Zero)
                        {
                            var cmdText = (OLECMDTEXT)Marshal.PtrToStructure(pCmdText, typeof(OLECMDTEXT));
                            if (cmdText.cmdtextf == (uint)OLECMDTEXTF.OLECMDTEXTF_NAME)
                            {
                                SetText(pCmdText, menuText);
                            }
                        }

                        // Enable the menu
                        prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                    }

                    // Enables/disables the 'Playback' and 'Save Macro' menu items
                    if (prgCmds[i].cmdID == PkgCmdIDList.idPlaybackMacro || prgCmds[i].cmdID == PkgCmdIDList.idPlaybackMacroMultipleTimes || prgCmds[i].cmdID == PkgCmdIDList.idSaveMacro)
                    {
                        if (Macro.CurrentMacro == null || Macro.CurrentMacro.IsRecording)
                        {
                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED);
                        }
                        else
                        {
                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                        }
                    }
                }

                return(VSConstants.S_OK);
            }

            if (pguidCmdGroup == GuidList.guidMacrosRunSavedCmdSet)
            {
                // Arguments check
                if (prgCmds == null)
                {
                    return(VSConstants.E_POINTER);
                }

                for (int i = 0; i < cCmds; i++)
                {
                    if (prgCmds[i].cmdID >= PkgCmdIDList.idRunSavedMacro1 && prgCmds[i].cmdID <= PkgCmdIDList.idRunSavedMacro5)
                    {
                        var index   = prgCmds[i].cmdID - PkgCmdIDList.idRunSavedMacro1;
                        var macros  = SavedMacros.GetMacroList();
                        var enabled = index < macros.Count;

                        if (enabled)
                        {
                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                        }
                        else
                        {
                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED);
                        }
                    }
                }

                return(VSConstants.S_OK);
            }

            return(Next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText));
        }
Ejemplo n.º 7
0
        // Executes the menu commands and does the recording of other commands
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == GuidList.guidMacrosCmdSet)
            {
                // Record/stop
                if (nCmdID == PkgCmdIDList.idRecordMacro)
                {
                    if (Macro.CurrentMacro == null || !Macro.CurrentMacro.IsRecording)
                    {
                        StartRecording();
                    }
                    else
                    {
                        StopRecording();
                    }

                    return(VSConstants.S_OK);
                }

                // Playback
                if (nCmdID == PkgCmdIDList.idPlaybackMacro)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't playback: no macro was recorded");
                    }
                    else
                    {
                        if (Macro.CurrentMacro.IsRecording)
                        {
                            StopRecording();
                        }
                        Playback(Macro.CurrentMacro);
                    }

                    return(VSConstants.S_OK);
                }

                // Playback multiple times
                if (nCmdID == PkgCmdIDList.idPlaybackMacroMultipleTimes)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't playback: no macro was recorded");
                    }
                    else
                    {
                        if (Macro.CurrentMacro.IsRecording)
                        {
                            StopRecording();
                        }

                        var dlg = new RepeatMacroMultipleTimesDialog();
                        dlg.ShowDialog();
                        Playback(Macro.CurrentMacro, dlg.Times);
                    }

                    return(VSConstants.S_OK);
                }

                // Save macro
                if (nCmdID == PkgCmdIDList.idSaveMacro)
                {
                    if (Macro.CurrentMacro == null)
                    {
                        MessageBox.Show("Can't save macro: no macro was recorded");
                    }
                    else
                    {
                        if (Macro.CurrentMacro.IsRecording)
                        {
                            StopRecording();
                        }

                        ShowSaveMacroDialog(Macro.CurrentMacro);
                    }

                    return(VSConstants.S_OK);
                }

                // Open saved macros
                if (nCmdID == PkgCmdIDList.idOpenSavedMacros)
                {
                    var list   = SavedMacros.GetMacroList();
                    var dialog = new SavedMacrosDialog(list);
                    dialog.ShowDialog();
                    return(VSConstants.S_OK);
                }
            }

            if (pguidCmdGroup == GuidList.guidMacrosRunSavedCmdSet)
            {
                // Run saved macro #
                if (nCmdID >= PkgCmdIDList.idRunSavedMacro1 && nCmdID <= PkgCmdIDList.idRunSavedMacro5)
                {
                    var index     = nCmdID - PkgCmdIDList.idRunSavedMacro1;
                    var macroList = SavedMacros.GetMacroList();
                    if (index < macroList.Count)
                    {
                        var macro = SavedMacros.GetSavedMacro(macroList[(int)index].Guid);
                        Playback(macro);
                    }

                    return(VSConstants.S_OK);
                }
            }

            // Are we recording?
            if (Macro.CurrentMacro != null && Macro.CurrentMacro.IsRecording)
            {
                // Recordable command?
                if (RecordableCommands.Commands.ContainsKey(pguidCmdGroup) && RecordableCommands.Commands[pguidCmdGroup].Contains(nCmdID))
                {
                    // For the TYPECHAR command, read the actual character code
                    if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
                    {
                        Macro.CurrentMacro.AddCommand(pguidCmdGroup, nCmdID, nCmdexecopt, GetTypedChar(pvaIn));
                    }
                    else
                    {
                        Macro.CurrentMacro.AddCommand(pguidCmdGroup, nCmdID, nCmdexecopt, null);
                    }
                }
#if DEBUG
                else
                {
                    Trace.WriteLine(string.Format("Not recorded - Guid: {0}, ID: {1}, Opts: {2}, In: {3}", pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn != IntPtr.Zero ? "yes" : "no"));
                }
#endif
            }

            return(Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }