예제 #1
0
 /// <summary>
 /// Sets the active script editor (#0 or #1).
 /// (In split window mode, #0 is the bottom one, #1 is the top one; in single window mode, #0 only is shown.)
 /// </summary>
 /// <param name="main">If true, sets editor #0 as the active one, otherwise sets #1.</param>
 private void SetActiveScriptEditor(bool main)
 {
     if (main || !_scriptEditor1.Visible)
     {
         if (_activeScriptEditor == _scriptEditor0)
         {
             return;
         }
         _activeScriptEditor             = _scriptEditor0;
         _scriptEditor1.IsSelectedEditor = false;
     }
     else
     {
         if (_activeScriptEditor == _scriptEditor1)
         {
             return;
         }
         _activeScriptEditor             = _scriptEditor1;
         _scriptEditor0.IsSelectedEditor = false;
     }
     rbnMain.BeginUpdate();
     //
     _activeScriptEditor.IsSelectedEditor = true;
     _activeScriptEditor.TextBox.Focus();
     CurrentScriptItemChanged(_activeScriptEditor, EventArgs.Empty);
     //
     rbnMain.EndUpdate();
 }
예제 #2
0
 private void _insertTemplate(ScriptEditorControl sec, string text)
 {
     if (sec != null)
     {
         sec.InsertTemplate(text);
         sec.TextBox.Focus();
     }
 }
예제 #3
0
        public ScriptEditorFormEx(
            MainForm mainForm,
            C1FlexReport report,
            string scriptContextName,
            // either this:
            ITypeDescriptorContext typeDescriptorContext,
            // or these two:
            object propertyOwner,
            string propertyName,
            // if non-null, used instead of derived name for display ONLY (does not affect script item key)
            string displayName,
            //
            bool isScript)
            : this()
        {
            System.Diagnostics.Debug.Assert(typeDescriptorContext != null || (propertyOwner != null && !string.IsNullOrEmpty(propertyName)));

            AutoScaleMode       = AutoScaleMode.None;
            Font                = MainForm.DefaultAppFont;
            _mainForm           = mainForm;
            _report             = report;
            _contexts           = new EditorScriptContextCollection(this, report, _mainForm.FlexDesigner);
            _activeScriptEditor = _scriptEditor0;
            //
            rbnMain.BeginUpdate();
            //
            _scriptEditor1.TextBox.Font          = _scriptEditor0.TextBox.Font = _mainForm._scriptEditorFont;
            _scriptEditor1.EditorBackgroundColor = _scriptEditor0.EditorBackgroundColor = _mainForm._scriptEditorBackColor;
            _scriptEditor1.EditorTextColor       = _scriptEditor0.EditorTextColor = _mainForm._scriptEditorForeColor;
            _scriptEditor1.SyntaxAutoCheck       = _scriptEditor0.SyntaxAutoCheck = _mainForm._syntaxCheck;
            _scriptEditor1.AutoSaveCurrentScript = _scriptEditor0.AutoSaveCurrentScript = _mainForm._scriptEditorAutoSave;
            // init options in ribbon UI:
            rbEditorFontName.Text             = _mainForm._scriptEditorFont.Name;
            rbBackgroundColor.Color           = _mainForm._scriptEditorBackColor;
            rbTextColor.Color                 = _mainForm._scriptEditorForeColor;
            rbSyntaxHighlight.Checked         = _mainForm._syntaxColoring;
            rbSyntaxAutoCheck.Checked         = _mainForm._syntaxCheck;
            rbAutoSave.Checked                = _mainForm._scriptEditorAutoSave;
            rbDataSourceFilterWarning.Checked = _mainForm._scriptEditorDataSourceFilterWarning;
            // font size:
            for (int i = c_minFontSize; i <= c_maxFontSize; ++i)
            {
                rbFontSize.Items.Add(i.ToString());
            }
            rbFontSize.Text = ((int)Math.Round(_scriptEditor0.EditorFont.Size)).ToString();

            _scriptEditor0.TextBox.GotFocus         += ScriptEditorGotFocus;
            _scriptEditor0.CurrentScriptItemChanged += CurrentScriptItemChanged;
            _scriptEditor0.CurrentScriptTextChanged += CurrentScriptTextChanged;
            _scriptEditor0.ScriptWritten            += ScriptWritten;
            _scriptEditor0.TextSelectionChanged     += TextSelectionChanged;
            _scriptEditor0.SyntaxCheckNeeded        += SyntaxCheckNeeded;

            _scriptEditor1.TextBox.GotFocus         += ScriptEditorGotFocus;
            _scriptEditor1.CurrentScriptItemChanged += CurrentScriptItemChanged;
            _scriptEditor1.CurrentScriptTextChanged += CurrentScriptTextChanged;
            _scriptEditor1.ScriptWritten            += ScriptWritten;
            _scriptEditor1.TextSelectionChanged     += TextSelectionChanged;
            _scriptEditor1.SyntaxCheckNeeded        += SyntaxCheckNeeded;

            _scriptItems = new EditorScriptItemCollection(_report, _contexts, _mainForm.FlexDesigner);

            // initial mode we start with:
            bool splitWindowMode = _mainForm._scriptEditorSplitWindowDistance > 0;

            // script data context:
            EditorScriptContextBase context = _contexts.GetContext(scriptContextName);

            System.Diagnostics.Debug.Assert(context != null);

            // this is patchy but will do for now:
            // - if we are being called from prop grid, then we have EditContext and edit that;
            // - else, if we are called to edit an expression - this is creating a new field;
            // - else, the big "Edit Scripts" button was pressed, and we default to GlobalScripts.

            EditorScriptItem scriptItem;

            if (typeDescriptorContext != null)
            {
                scriptItem = EditorScriptItem.FromTypeDescriptorContext(typeDescriptorContext, context, isScript, displayName);
            }
            else
            {
                scriptItem = EditorScriptItem.FromObjectProperty(propertyOwner, propertyName, context, isScript, displayName);
            }

            // A script item may not be "collected" if it is a new calc field being added, or e.g. in Maps there are many expressions:
            if (!_scriptItems.ContainsKey(scriptItem.Key))
            {
                scriptItem.EnsureTopKey();
                _scriptItems.Add(scriptItem.Key, scriptItem);
            }

            _scriptEditor0.Init(mainForm, _report, _scriptItems);
            _scriptEditor1.Init(mainForm, _report, _scriptItems);

            // _scriptItemKey is used ONLY for returning the script with which we were called:
            _scriptItemKey = scriptItem.Key;
            if (splitWindowMode)
            {
                _scriptEditor1.SetCurrentScriptItem(_scriptItemKey, Forms.ScriptEditorControl.SetCurrentScriptItemContext.Initial);
                if (_scriptItems.ContainsKey(_mainForm._scriptEditorLastItemKey0))
                {
                    _scriptEditor0.SetCurrentScriptItem(_mainForm._scriptEditorLastItemKey0, Forms.ScriptEditorControl.SetCurrentScriptItemContext.Initial);
                }
                else
                {
                    _scriptEditor0.SetCurrentScriptItem(_scriptItemKey, Forms.ScriptEditorControl.SetCurrentScriptItemContext.Initial);
                }
            }
            else
            {
                _scriptEditor0.SetCurrentScriptItem(_scriptItemKey, Forms.ScriptEditorControl.SetCurrentScriptItemContext.Initial);
                _scriptEditor1.SetCurrentScriptItem(_scriptItemKey, Forms.ScriptEditorControl.SetCurrentScriptItemContext.Initial);
            }

            // Apply main window's theme:
            var tl    = new C1ThemeLocator(_mainForm.Theme);
            var theme = tl.GetTheme();

            if (theme != null)
            {
                C1ThemeController.ApplyThemeToControlTree(this, theme);
                C1ThemeController.ApplyThemeToObject(contextMenu, theme);
            }

            // Set up script editors' glyphs - splitter and close window:
            _scriptEditor0.GlyphBox.Cursor = Cursors.HSplit;
            _scriptEditor1.GlyphBox.Image  = Properties.Resources.SplitWindowClose_16x16;

            _splitter.SplitterMoved                     += Splitter_SplitterMoved;
            _scriptEditor0.GlyphBox.MouseEnter          += GlyphBox0_MouseEnter;
            _scriptEditor0.GlyphBox.MouseLeave          += GlyphBox0_MouseLeave;
            _scriptEditor0.GlyphBox.MouseDown           += GlyphBox0_MouseDown;
            _scriptEditor0.GlyphBox.MouseMove           += GlyphBox0_MouseMove;
            _scriptEditor0.GlyphBox.MouseUp             += GlyphBox0_MouseUp;
            _scriptEditor0.GlyphBox.MouseCaptureChanged += GlyphBox0_MouseCaptureChanged;
            _scriptEditor1.GlyphBox.MouseDown           += GlyphBox1_MouseDown;

            // Ready to start:
            UpdateStatusBar();
            //
            rbnMain.EndUpdate();
            //
        }