示例#1
0
 // Starts a new macro in record mode
 public static void StartNew()
 {
     CurrentMacro = new Macro
     {
         IsRecording = true
     };
 }
示例#2
0
 // Loads the current macro from a file
 public static void LoadFromFile(string filename)
 {
     CurrentMacro = new Macro
     {
         Commands = XmlHelpers.Deserialize<List<MacroCommand>>(File.ReadAllText(filename))
     };
 }
示例#3
0
 // Saves the current macro to a file
 public static void SaveToFile(Macro macro, string filename)
 {
     File.WriteAllText(filename, XmlHelpers.Serialize(macro.Commands));
 }
示例#4
0
文件: Macro.cs 项目: xps/VSTextMacros
 // Saves the current macro to a file
 public static void SaveToFile(Macro macro, string filename)
 {
     File.WriteAllText(filename, XmlHelpers.Serialize(macro.Commands));
 }
示例#5
0
        // Replays a macro
        private void Playback(Macro macro, int times = 1)
        {
            var pvaIn = Marshal.AllocCoTaskMem(16);
            try
            {
                for (int i = 0; i < times; i++)
                {
                    foreach (var command in macro.Commands)
                    {
                        var pguidCmdGroup = command.CommandGroup;

                        if (command.Character != null)
                        {
                            Marshal.GetNativeVariantForObject((ushort)command.Character, pvaIn);
                            Next.Exec(ref pguidCmdGroup, command.CommandID, command.CommandOptions, pvaIn, IntPtr.Zero);
                        }
                        else
                            Next.Exec(ref pguidCmdGroup, command.CommandID, command.CommandOptions, IntPtr.Zero, IntPtr.Zero);
                    }
                }
            }
            finally
            {
                if (pvaIn != IntPtr.Zero)
                    Marshal.FreeCoTaskMem(pvaIn);
            }
        }
示例#6
0
        // Saves the given macro under the given name
        public static void SaveMacro(Macro macro, string name, string guid = null)
        {
            // Get the list
            var list = GetMacroList();

            // Update the list item or add a new one
            if (guid != null && list.Any(x => x.Guid == guid))
                list.SingleOrDefault(x => x.Guid == guid).Name = name;
            else
                list.Add(new SavedMacro(guid = Guid.NewGuid().ToString(), name));

            // Save the macro
            Macro.SaveToFile(macro, GetMacroFilename(guid));

            // Update the list
            SaveMacroList(list);
        }
示例#7
0
 // Shows the save macro dialog
 private void ShowSaveMacroDialog(Macro macro, string name = null)
 {
     var dialog = new SaveMacroDialog(name);
     if (dialog.ShowDialog() == DialogResult.OK)
         SavedMacros.SaveMacro(macro, dialog.MacroName);
 }