Beispiel #1
0
        /// <summary>
        /// Creates child controls for this control
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // get prevalues, load them into the controls.
            var options = this.GetPreValueOptions <RenderMacroOptions>() ?? new RenderMacroOptions(true);

            this.AllowedMacros = Macro.GetAll().Select(m => m.Alias).ToList();

            // if the value of the macro tag is empty, assign the default value.
            if (string.IsNullOrEmpty(options.MacroTag))
            {
                options.MacroTag = RenderMacroOptions.DEFAULT_MACRO_TAG;
            }

            // set-up child controls
            this.MacroEditor = new MacroEditor(options.MacroTag, this.AllowedMacros)
            {
                ID = "MacroEditor"
            };
            this.ShowLabel = new CheckBox()
            {
                ID = "ShowLabel", Checked = options.ShowLabel
            };
            this.Styles = new Literal()
            {
                ID = "Styles", Text = "<style type='text/css'>.macroeditor h4, .macroeditor .macroDelete {display:none;}</style>"
            };

            // add the child controls
            this.Controls.AddPrevalueControls(this.ShowLabel, this.MacroEditor, this.Styles);
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// </summary>
        /// <param name="Sender">Event sender.</param>
        /// <param name="Args">Event args.</param>
        private void GenerateMacroCallback(object Sender, EventArgs Args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // マクロの種類を取得
            EditorSelecter SelecterDialog = new EditorSelecter();

            SelecterDialog.ShowDialog();

            if (SelecterDialog.DialogResult == DialogResult.OK)
            {
                // エディタを起動
                DialogResult DialogResult = DialogResult.None;
                string       EditResult   = string.Empty;
                switch (XmlFunctionLibrary.GetEditorType(SelecterDialog.MacroType))
                {
                case EditorType.MacroEditor:
                    MacroEditor MacroEditor = new MacroEditor(SelecterDialog.MacroType);
                    MacroEditor.ShowDialog();
                    DialogResult = MacroEditor.DialogResult;
                    EditResult   = MacroEditor.MacroString;
                    break;

                case EditorType.LogEditor:
                    LogEditor LogEditor = new LogEditor(SelecterDialog.MacroType);
                    LogEditor.ShowDialog();
                    DialogResult = LogEditor.DialogResult;
                    EditResult   = LogEditor.MacroString;
                    break;

                case EditorType.DelegateEditor:
                    DelegateEditor DelegateEditor = new DelegateEditor(SelecterDialog.MacroType);
                    DelegateEditor.ShowDialog();
                    DialogResult = DelegateEditor.DialogResult;
                    EditResult   = DelegateEditor.MacroString;
                    break;
                }

                if (DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult))
                {
                    // カーソル位置に結果の文字列を挿入
                    DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE));
                    Assumes.Present(Dte);
                    var Selection = (TextSelection)Dte.ActiveDocument.Selection;
                    Selection.Text = EditResult;

                    // カーソルの行を更新
                    Selection.SelectLine();
                    Selection.SmartFormat();
                    Selection.EndOfLine();
                }
            }
        }
Beispiel #3
0
        public static Macro OpenMacro(IWin32Window dialogowner, out string filename)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.InitialDirectory = Settings.Default.MacroDirectory;
            d.Title            = "Open PhotoTagStudio macro";
            d.Filter           = FILE_DIALOG_FILTER;
            if (d.ShowDialog(dialogowner) == DialogResult.OK)
            {
                MacroEditor.RememberFileAndDirectory(d.FileName);

                filename = d.FileName;
                return(OpenMacroFromFile(d.FileName));
            }

            filename = "";
            return(null);
        }
    private void buttonNewMacro_Click(object sender, EventArgs e)
    {
      MacroEditor macroEditor = new MacroEditor();
      macroEditor.ShowDialog(this);

      RefreshMacroList();
    }
    private void EditMacro()
    {
      if (listViewMacro.SelectedItems.Count != 1)
        return;

      try
      {
        string command = listViewMacro.SelectedItems[0].Text;
        string fileName = Path.Combine(TV2BlasterPlugin.FolderMacros, command + Common.FileExtensionMacro);

        if (File.Exists(fileName))
        {
          MacroEditor macroEditor = new MacroEditor(command);
          macroEditor.ShowDialog(this);
        }
        else
        {
          RefreshMacroList();

          throw new FileNotFoundException("Macro file missing", fileName);
        }
      }
      catch (Exception ex)
      {
        Log.Error(ex);
        MessageBox.Show(this, ex.Message, "Failed to edit macro", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }
    private void EditMacro(object sender, EventArgs e)
    {
      if (listViewMacro.SelectedItems.Count != 1)
        return;

      string command = listViewMacro.SelectedItems[0].Text;
      string fileName = Path.Combine(Program.FolderMacros, command + Common.FileExtensionMacro);

      if (File.Exists(fileName))
      {
        MacroEditor macroEditor = new MacroEditor(command);
        macroEditor.ShowDialog(this);
      }
      else
      {
        MessageBox.Show(this, "File not found: " + fileName, "Macro file missing", MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
        RefreshMacroList();
      }
    }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// </summary>
        /// <param name="Sender">Event sender.</param>
        /// <param name="Args">Event args.</param>
        private void EditMacroCallback(object Sender, EventArgs Args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE));

            Assumes.Present(Dte);
            var ActiveDocument = Dte.ActiveDocument;

            if (ActiveDocument != null)
            {
                // 一旦カーソル位置の行を全て選択
                var Selection = (TextSelection)ActiveDocument.Selection;
                Selection.SelectLine();

                // マクロの名前だけ選択
                string        TargetType = string.Empty;
                List <string> MacroTypes = new List <string>(XmlFunctionLibrary.GetMacroTypes(true, true, false));
                foreach (var MacroType in MacroTypes)
                {
                    if (Selection.Text.Contains(MacroType))
                    {
                        TargetType = MacroType;
                        break;
                    }
                }

                Selection.StartOfLine();
                Selection.LineUp();

                while (true)
                {
                    if (Selection.Text.Contains(TargetType))
                    {
                        break;
                    }
                    Selection.WordRight(true);
                }
                Selection.WordLeft();
                Selection.WordRight(true);

                TargetType = Selection.Text;

                // サポートしてなかったらエラー
                MacroTypes.Clear();
                MacroTypes.AddRange(XmlFunctionLibrary.GetMacroTypes(false, false, true));
                if (!MacroTypes.Contains(TargetType))
                {
                    string SupportedMacros = string.Empty;
                    for (int Index = 0; Index < MacroTypes.Count; Index++)
                    {
                        SupportedMacros += MacroTypes[Index] + "\r\n";
                    }

                    MessageBox.Show(
                        TargetType + " is not a supported macro",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    return;
                }

                // マクロの中身だけ選択する
                string TargetParameters = string.Empty;
                bool   bIsInString      = false;
                int    Depth            = 0;
                while (true)
                {
                    Selection.CharRight(true);

                    var LastChar = Selection.Text[Selection.Text.Length - 1];

                    // マクロ名以降のみを取得
                    TargetParameters += LastChar;

                    // 文字列中はカウントしない
                    if (LastChar == '\"')
                    {
                        bIsInString = !bIsInString;
                    }

                    // カッコの深さをカウント
                    if (!bIsInString && LastChar == '(')
                    {
                        Depth++;
                    }
                    else if (!bIsInString && LastChar == ')')
                    {
                        Depth--;
                    }

                    // カッコの数が合ったら終了
                    if (Depth <= 0)
                    {
                        break;
                    }

                    // カッコの数が合わなかった時の対策
                    if (Selection.ActivePoint.AtEndOfLine)
                    {
                        break;
                    }
                }

                // 文字列中に"が入っている場合はエラー
                if (StringFunctionLibrary.CountOfChar(TargetParameters, '\"') % 2 != 0)
                {
                    MessageBox.Show(
                        "The string literal contains double quotes\r\n" +
                        "Remove the double quotes inside the string literal to edit the macro",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    return;
                }

                if (!string.IsNullOrEmpty(TargetParameters))
                {
                    // エディタを起動
                    DialogResult DialogResult = DialogResult.None;
                    string       EditResult   = string.Empty;
                    switch (XmlFunctionLibrary.GetEditorType(TargetType))
                    {
                    case EditorType.MacroEditor:
                        MacroEditor MacroEditor = new MacroEditor(TargetType, TargetParameters);
                        MacroEditor.ShowDialog();
                        DialogResult = MacroEditor.DialogResult;
                        EditResult   = MacroEditor.MacroString;
                        break;

                    case EditorType.LogEditor:
                        LogEditor LogEditor = new LogEditor(TargetType, TargetParameters);
                        LogEditor.ShowDialog();
                        DialogResult = LogEditor.DialogResult;
                        EditResult   = LogEditor.MacroString;
                        break;

                    case EditorType.DelegateEditor:
                        DelegateEditor DelegateEditor = new DelegateEditor(TargetType, TargetParameters);
                        DelegateEditor.ShowDialog();
                        DialogResult = DelegateEditor.DialogResult;
                        EditResult   = DelegateEditor.MacroString;
                        break;
                    }

                    if (ActiveDocument != null && DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult))
                    {
                        // カーソル位置に結果の文字列を挿入
                        Selection.Text = EditResult;

                        // カーソルの行を更新
                        Selection.SelectLine();
                        Selection.SmartFormat();
                        Selection.EndOfLine();
                    }
                }
            }
        }