Пример #1
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));
        }
Пример #2
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));
        }