Example #1
0
        /// <summary>
        /// Статическая процедура, вызываемая из MouseTimer_Task по срабатыванию MouseTimer для отображения подсказки при наведении мышкой на часть текста
        /// </summary>
        /// <param name="ActiveHMSEditor">Активный (вызвавший) элемент HMSEditor</param>
        public static void Task(HMSEditor ActiveHMSEditor)
        {
            var    TB    = ActiveHMSEditor.TB;
            Point  point = ActiveHMSEditor.MouseLocation;
            bool   debugMode  = TB.DebugMode;
            bool   selectMode = false;
            string expression = "";
            try {
                Place place = TB.PointToPlace(point);
                Range r = new Range(TB, place, place);
                if (r.IsStringOrCommentBefore()) return;
                if (r.IsErrorPlace) {
                    // Показываем инофрмацию об ошибке через ToolTip
                    ShowToolTip(TB, point, "Ошибка синтаксиса", "", "", TB.ErrorStyle.Message);
                    return;
                }
                if (debugMode && (TB.Selection.Start != TB.Selection.End) && TB.Selection.InRange(place)) {
                    expression = TB.SelectedText.Trim();
                    selectMode = true;
                }
                if (expression.Length == 0) {
                    expression = r.GetFragmentAroundThePlace(place).Text.Replace("#", "").Trim();
                }
                if (expression.Length == 0)
                    return;
                var item = ActiveHMSEditor.GetHMSItemByText(expression);
                if (item != null) {
                    // Если идёт отладка - проверяем, мы навели на переменную или свойство объекта?
                    if (debugMode && (OK4Evaluate(item) || selectMode)) {
                        // Проверяем тип объекта класса, может быть удобней представить в виде текста? (TStrings или TJsonObject)
                        string realExpression = expression;
                        expression = CheckTypeForToStringRules(item, expression);
                        ShowValue(TB, point, expression, realExpression);
                        return;
                    }
                    ShowToolTip(TB, point, item.ToolTipTitle, item.ToolTipText, "", item.Help);
                } else if (debugMode && !HMS.WordIsKeyword(expression)) {
                    ShowValue(TB, point, expression, expression);
                }

            } catch (Exception e) {
                HMS.LogError(e.ToString());
            }
        }
Example #2
0
 public AutocompleteMenu(FastColoredTextBox tb, HMSEditor ed)
 {
     // create a new popup and add the list view to it
     AutoClose = false;
     AutoSize  = false;
     Margin    = Padding.Empty;
     Padding   = Padding.Empty;
     BackColor = Color.White;
     listView  = new AutocompleteListView(tb);
     host      = new ToolStripControlHost(listView);
     host.Margin      = new Padding(2, 2, 2, 2);
     host.Padding     = Padding.Empty;
     host.AutoSize    = false;
     host.AutoToolTip = false;
     CalcSize();
     base.Items.Add(host);
     listView.Parent   = this;
     SearchPattern     = @"[\{\#\w\.]";
     MinFragmentLength = 2;
 }
Example #3
0
        public static void SetTheme(HMSEditor editor, string name)
        {
            if (Dict.ContainsKey(name)) {
                SetTheme(editor.Editor, name);
                Theme t = Dict[name];
                editor.ColorCurrentLine = t.LineHighlight;
                editor.ColorChangedLine = t.ChangedLines;

                // Для тёмных тем цвет изменённых строк меняем тоже на более тёмный
                uint icol = (uint)editor.Editor.IndentBackColor.ToArgb() & 0xFFFFFF;
                if (icol < 0x808080) editor.ColorChangedLine = ToColor("#024A02");

                editor.btnMarkChangedLines_Click(null, EventArgs.Empty);
            }
        }
Example #4
0
 protected override void OnEnter(EventArgs e)
 {
     ActiveEditor = this;
     base.OnEnter(e);
 }
Example #5
0
 public void Editor_MouseMove(object sender, MouseEventArgs e)
 {
     if (EnableMouseHelp || (EnableEvaluateByMouse && DebugMode)) {
         if (MouseLocation == e.Location) {
             // Mouse stopped
         } else {
             // Mouse mooving
             MouseLocation = e.Location;
             ActiveEditor = this;
             if (ValueHint.Visible) ValueHint.Visible = false;
             MouseTimer.Change(DebugMode ? 450 : 800, Timeout.Infinite); // Show help tooltip from mouse cursor
         }
     }
 }
Example #6
0
        public static void SetTheme(HMSEditor editor, string name, System.Windows.Forms.ToolStripItemCollection MenuItems)
        {
            if (Dict.ContainsKey(name)) {
                SetTheme(editor.TB, name);
                Theme t = Dict[name];
                editor.TB.CurrentLineColor = t.LineHighlight;
                //editor.Editor.ChangedLineColor = t.ChangedLines;

                //Color c1 = MixColor(0.5, t.KeywordStyle.GetRTF().ForeColor, t.StringStyle.GetRTF().ForeColor);
                HmsToolTip.ColorBackgrnd = MediaColor(0xF0, t.Background);

                //editor.PopupMenu.BackColor = t.Background;
                //editor.PopupMenu.ForeColor = t.Foreground;

                // Для тёмных тем цвет изменённых строк меняем тоже на более тёмный
                //if (editor.Editor.IndentBackColor.GetBrightness() < 0.5) editor.Editor.ChangedLineColor = ToColor("#024A02");

                foreach (var i in MenuItems) {
                    var b = i as System.Windows.Forms.ToolStripMenuItem;
                    if (b != null) b.Checked = b.Text == name;
                }
                editor.btnMarkChangedLines_Click(null, EventArgs.Empty);
            }
        }
Example #7
0
 private void Editor_SelectionChanged(object sender, EventArgs e)
 {
     HideToolTip4Function();
     ActiveEditor = this;
 }
Example #8
0
 private void Editor_MouseMove(object sender, MouseEventArgs e)
 {
     if (MouseTimerEnable) {
         if (MouseLocation == e.Location) {
             // Mouse stopped
         } else {
             // Mouse mooving
             MouseLocation = e.Location;
             ActiveEditor  = this;
             if (ValueHint.Visible) ValueHint.Visible = false;
             MouseTimer.Change(800, Timeout.Infinite); // Show help tooltip from mouse cursor
         }
     }
 }
Example #9
0
 public HMSEditor(IntPtr hWnd)
 {
     hWndScriptFrame = hWnd;
     InitializeComponent();
     SetAutoCompleteMenu();
     Editor.LostFocus += Editor_LostFocus;
     tsMain.Visible = false; // for attached default is not visible, restore saved value in LoadSettings()
     Themes.Init();
     ActiveEditor     = this;
 }
Example #10
0
 // Constructors
 public HMSEditor()
 {
     InitializeComponent();
     SetAutoCompleteMenu();
     Themes.Init();
     ActiveEditor     = this;
 }
Example #11
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing) {
         if (EditBox != null && !EditBox.IsDisposed) EditBox.Dispose();
     }
     EditBox = null;
 }
Example #12
0
        public uint CreateEditor(IntPtr aParent, IntPtr aScriptFrame, int aScriptMode, ref IntPtr aEditor)
        {
            try {
                EditBox = new HMSEditor(aScriptFrame, aScriptMode);
                NativeMethods.SetParent(EditBox.Handle, aParent);

                LoadSettings();
                aEditor = EditBox.Handle;

            } catch (Exception e) {
                MessageBox.Show("Ошибка создания окна редактора.\n\n" + e, HMSEditor.Title);
                Dispose();
                return HRESULT.E_UNEXPECTED;
            }
            return HRESULT.S_OK;
        }
Example #13
0
 private static string SafeEval(HMSEditor activeEditor, string expression)
 {
     string value = "";
     System.Windows.Forms.MethodInvoker action = delegate {
         value = activeEditor.EvalVariableValue(expression);
     };
     if (activeEditor.InvokeRequired)
         activeEditor.Invoke(action);
     else
         action();
     return value;
 }
Example #14
0
        /// <summary>
        /// Статическая процедура, вызываемая из MouseTimer_Task по срабатыванию MouseTimer для отображения подсказки при наведении мышкой на часть текста
        /// </summary>
        /// <param name="ActiveHMSEditor">Активный (вызвавший) элемент HMSEditor</param>
        public static void Task(HMSEditor ActiveHMSEditor)
        {
            if (ActiveHMSEditor.Locked) return;
            try {
                var    Editor = ActiveHMSEditor.Editor;
                Point  point  = ActiveHMSEditor.MouseLocation;
                int iStartLine = ActiveHMSEditor.Editor.YtoLineIndex(0);
                int CharHeight = ActiveHMSEditor.Editor.CharHeight;
                int i = point.Y / CharHeight;
                int iLine = iStartLine + i;
                if ((iLine + 1) > ActiveHMSEditor.Editor.LinesCount) return;
                Place place  = ActiveHMSEditor.PointToPlace(point);
                string line   = Editor.Lines[iLine];
                string value  = "";
                bool evalSelection = false;
                if (Editor.DebugMode && (Editor.SelectedText.Length > 2)) {
                    Place selStart = Editor.Selection.Start;
                    Place selEnd   = Editor.Selection.End;
                    // Если указатель мыши в области виделения, то будем вычислять выдиление
                    evalSelection  = (selStart.iLine == iLine) && (selStart.iChar >= place.iChar) && (selEnd.iChar <= iLine);
                }

                Range r = new Range(Editor, place, place);
                Range fragment = r.GetFragmentLookedLeft();
                string text = fragment.Text.Replace("#", "");
                if (text.Length == 0) return;

                HMSItem item = ActiveHMSEditor.GetHMSItemByText(text); // Поиск известного элемента HMSItem по части текста
                if (item != null && !string.IsNullOrEmpty(item.Text)) {
                    point.Offset(0, Editor.CharHeight-4);
                    // Если идёт отладка - проверяем, мы навели на переменную или свойство объекта?
                    if (Editor.DebugMode && (evalSelection || OK4Evaluate(item)) ) {
                        if (evalSelection) {
                            text = Editor.SelectedText;
                        } else {
                            // проверяем, если это index свойство - то нудно вычислять значение с переданным индексом, поэтому дополняем значением [...]
                            if (item.ImageIndex == Images.Enum) {
                                Match m = Regex.Match(line, text + @"\[.*?\]");
                                if (m.Success) text = m.Value;
                            } else if (item.ImageIndex == Images.Function) {
                                Match m = Regex.Match(line, text + @"\(.*?\)");
                                if (m.Success) text = m.Value;
                            }
                            // Проверяем тип объекта класса, может быть удобней представить в виде текста? (TStrings или TJsonObject)
                            text = CheckTypeForToStringRules(item.Type, text);
                        }
                        // Вычсиление выражения
                        value = ActiveHMSEditor.EvalVariableValue(text);
                        // Внедряемся в поток - показываем вплывающее окно со значением
                        Editor.Invoke((System.Windows.Forms.MethodInvoker)delegate {
                            ActiveHMSEditor.ValueHint.ShowValue(Editor, value, point);
                        });
                        return;
                    }
                    // Показываем инофрмацию о функции или переменной через ToolTip
                    Editor.Invoke((System.Windows.Forms.MethodInvoker)delegate {
                        var tip = Editor.ToolTip;
                        tip.ToolTipTitle = item.ToolTipTitle;
                        tip.Help         = item.Help;
                        tip.Value        = value;
                        tip.Show(item.ToolTipText + " ", Editor, point, 10000);
                    });
                }
            } catch (Exception e) {
                HMS.LogError(e.ToString());
            }
        }