/// <summary>
        /// Create the editor.
        /// </summary>
        public ScintillaEditForm()
        {
            applicationManager = ApplicationManager.GetInstance();
            documentManager = DocumentManager.GetInstance();
            _settingsManager = SettingsManager.GetInstance();
            _macroManager = MacroManager.GetInstance();
            _mainForm = applicationManager.MainForm;

            scintilla = new Scintilla();
            ((ISupportInitialize)(scintilla)).BeginInit();
            scintilla.Dock = DockStyle.Fill;
            scintilla.Name = "scintilla";
            scintilla.TabIndex = 0;
            scintilla.Enter += new EventHandler(Scintilla_Enter);
            scintilla.Leave += new EventHandler(Scintilla_Leave);
            scintilla.MouseClick += new MouseEventHandler(Scintilla_MouseClick);
            scintilla.ModifiedChanged += new EventHandler(Scintilla_ModifiedChanged);
            scintilla.KeyUp += new KeyEventHandler(Scintilla_KeyUp);
            ((ISupportInitialize)(scintilla)).EndInit();
            scintilla.MacroRecord += new EventHandler<MacroRecordEventArgs>(Scintilla_MacroRecord);

            if (!applicationManager.ClientProfile.HaveFlag(
                ClientFlags.EditorDisableDragAndDropFileOpen))
            {
                scintilla.AllowDrop = true;
                scintilla.FileDrop += new EventHandler<FileDropEventArgs>(Scintilla_FileDrop);
            }

            FormClosing += new FormClosingEventHandler(ScintillaEditForm_FormClosing);
        }
Beispiel #2
0
        /// <summary>
        /// Get a reference to the MacroManager singleton.
        /// </summary>
        /// <returns>A reference to the MacroManager.</returns>
        public static MacroManager GetInstance()
        {
            if (_singleton == null)
            {
                _singleton = new MacroManager();
            }

            return(_singleton);
        }
Beispiel #3
0
        private void ActivatePlugin()
        {
            /*
             * As this plugin only provides support for a scintilla object, not
             * a form or any other UI it must not register any document types
             * or set any document handlers.
             * On its own this plugin will gracefully reject calls to open
             * documents via the 'no handler register' alert so it is safe to
             * include standalone but without a UI it won't be much use!
             */

            UserContent.DeployContent(Constants.PLUGIN_NAME);

            _applicationManager = ApplicationManager.GetInstance();

            _applicationManager.RegisterOptionsPageFactory(
                delegate { return(new EditorOptionsPage()); });

            _applicationManager.RegisterOptionsPageFactory(
                delegate { return(new GlobalOptionsPage()); });

            _macroManager = MacroManager.GetInstance();

            /*
             * Define the snippets folder.
             */

            _snippetsFolderPath = Path.Combine(
                ApplicationManager.GetInstance().QuickSharpUserHome,
                Constants.SNIPPETS_FOLDER);

            /*
             * Keyboard Shortcuts Note
             *
             * Most menu commands are the sole access point for editor functions and are
             * enabled and disabled according to the state determined by their action state
             * handlers. In most cases the state of these commands changes only when the documents
             * are opened, closed or activated. This is important because the shortcut keys
             * only work when the corresponding menu is enabled; often a shortcut key is accessed
             * before the menu is opened (at which point the state is updated) and must be in the
             * correct state when the doucment is opened or activated. However, the status of
             * some commands (clipboard or selection dependent) changes continuously during
             * editing and it is not feasible to have these updated only when the menus are opened.
             * These commands are represented in the menus using text-only shortcut key assignments
             * and are activated using the key mappings provided by the Scintilla editor,
             * not via the menus. The action state handlers for these actions are provided only
             * to maintain the correct visual state of the corresponding menu commands.
             *
             * This means that, whereas other menu-based commands can have their shortcut
             * keys re-mapped simply by changing the assignment on the menu item, these cannot:
             * the shortcut keys presented on the menus must match the Scintilla mappings. (See
             * 'commands.cs' in the ScintillaNet project to see the relevant mappings.)
             */

            #region Menu Creation

            bool enableCodeFeatures = !_applicationManager.ClientProfile.
                                      HaveFlag(ClientFlags.EditorDisableCodeFeatures);

            /*
             * File Menu
             */

            #region Create Items

            _fileMenuPageSetup = MenuTools.CreateMenuItem(
                Constants.UI_FILE_MENU_PAGE_SETUP,
                Resources.MainFileMenuPageSetup,
                Resources.PageSetup,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _fileMenuPrintPreview = MenuTools.CreateMenuItem(
                Constants.UI_FILE_MENU_PRINT_PREVIEW,
                Resources.MainFileMenuPrintPreview,
                null,
                Keys.None, null,
                UI_EDIT_MENU_ITEM_Click);

            _fileMenuPrint = MenuTools.CreateMenuItem(
                Constants.UI_FILE_MENU_PRINT,
                Resources.MainFileMenuPrint,
                Resources.Print,
                Keys.Control | Keys.P, null, UI_EDIT_MENU_ITEM_Click,
                true);

            #endregion

            _fileMenu = _mainForm.GetMenuItemByName(
                QuickSharp.Core.Constants.UI_FILE_MENU);

            int i = _fileMenu.DropDownItems.IndexOfKey(
                QuickSharp.Core.Constants.UI_FILE_MENU_SAVE_ALL);

            if (i != -1)
            {
                i++; // Insert after
                _fileMenu.DropDownItems.Insert(i, _fileMenuPrint);
                _fileMenu.DropDownItems.Insert(i, _fileMenuPrintPreview);
                _fileMenu.DropDownItems.Insert(i, _fileMenuPageSetup);
            }

            /*
             * Edit Menu
             */

            #region Create Items

            _editMenu = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU,
                Resources.MainEditMenu,
                null,
                Keys.None, null, null);

            _editMenuUndo = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_UNDO,
                Resources.MainEditMenuUndo,
                Resources.Undo,
                Keys.None, "Ctrl+Z", UI_EDIT_MENU_ITEM_Click);

            _editMenuRedo = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_REDO,
                Resources.MainEditMenuRedo,
                Resources.Redo,
                Keys.None, "Ctrl+Y", UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuCut = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_CUT,
                Resources.MainEditMenuCut,
                Resources.Cut,
                Keys.None, "Ctrl+X", UI_EDIT_MENU_ITEM_Click);

            _editMenuCopy = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_COPY,
                Resources.MainEditMenuCopy,
                Resources.Copy,
                Keys.None, "Ctrl+C", UI_EDIT_MENU_ITEM_Click);

            _editMenuPaste = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_PASTE,
                Resources.MainEditMenuPaste,
                Resources.Paste,
                Keys.None, "Ctrl+V", UI_EDIT_MENU_ITEM_Click);

            _editMenuSelectAll = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_SELECT_ALL,
                Resources.MainEditMenuSelectAll,
                null,
                Keys.None, "Ctrl+A", UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuFind = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_FIND,
                Resources.MainEditMenuFind,
                Resources.Find,
                Keys.Control | Keys.F, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuReplace = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_REPLACE,
                Resources.MainEditMenuReplace,
                null,
                Keys.Control | Keys.H, null, UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuGoTo = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_GOTO,
                Resources.MainEditMenuGoTo,
                null,
                Keys.Control | Keys.G, null, UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuMacros = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MACROS,
                Resources.MainEditMenuMacros,
                null,
                Keys.None, null, null);

            _editMenuMacroRecord = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MACRO_RECORD,
                Resources.MainEditMenuMacroStartRecord,
                null,
                Keys.Control | Keys.Shift | Keys.R, null,
                UI_EDIT_MENU_ITEM_Click);

            _editMenuMacroPlay = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MACRO_PLAY,
                Resources.MainEditMenuMacroPlay,
                null,
                Keys.Control | Keys.Shift | Keys.P, null,
                UI_EDIT_MENU_ITEM_Click);

            _editMenuMacroLoad = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MACRO_LOAD,
                Resources.MainEditMenuMacroLoad,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuMacroSave = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MACRO_SAVE,
                Resources.MainEditMenuMacroSave,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuSnippets = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_SNIPPETS,
                Resources.MainEditMenuSnippets,
                null,
                Keys.None, null, null);

            _editMenuSnippetsManage = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MANAGE_SNIPPETS,
                Resources.MainEditMenuManageSnippets,
                null,
                Keys.None, null, UI_EDIT_MENU_MANAGE_SNIPPETS_Click);

            _editMenuBookmarks = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_BOOKMARKS,
                Resources.MainEditMenuBookmarks,
                null,
                Keys.None, null, null);

            _editMenuBookmarkToggle = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_TOGGLE_BOOKMARK,
                Resources.MainEditMenuToggleBookmark,
                null,
                Keys.F3,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuBookmarksClear = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_CLEAR_BOOKMARKS,
                Resources.MainEditMenuClearBookmarks,
                null,
                Keys.Shift | Keys.F3,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuBookmarkNext = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_NEXT_BOOKMARK,
                Resources.MainEditMenuNextBookmark,
                null,
                Keys.F4,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuBookmarkPrevious = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_PREV_BOOKMARK,
                Resources.MainEditMenuPreviousBookmark,
                null,
                Keys.Shift | Keys.F4,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuFolding = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_FOLDING,
                Resources.MainEditMenuFolding,
                null,
                Keys.None, null, null);

            _editMenuFoldToggle = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_TOGGLE_FOLD,
                Resources.MainEditMenuToggleFold,
                null,
                Keys.F8,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuFoldCollapseAll = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_COLLAPSE_ALL,
                Resources.MainEditMenuCollapseAll,
                null,
                Keys.Control | Keys.F8,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuFoldExpandAll = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_EXPAND_ALL,
                Resources.MainEditMenuExpandAll,
                null,
                Keys.Shift | Keys.F8,
                null, UI_EDIT_MENU_ITEM_Click);

            _editMenuEncoding = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ENCODING,
                Resources.MainEditMenuEncoding,
                null,
                Keys.None, null, null);

            _editMenuEncodingANSI = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ENCODING_ANSI,
                Resources.MainEditMenuEncodingANSI,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuEncodingUTF8 = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ENCODING_UTF8,
                Resources.MainEditMenuEncodingUTF8,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuEncodingUTF16BE = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ENCODING_UTF16BE,
                Resources.MainEditMenuEncodingUTF16BE,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuEncodingUTF16LE = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ENCODING_UTF16LE,
                Resources.MainEditMenuEncodingUTF16LE,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuLineEnding = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_LINE_ENDING,
                Resources.MainEditMenuLineEnding,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuLineEndingCRLF = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_LINE_ENDING_CRLF,
                Resources.MainEditMenuLineEndingCRLF,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuLineEndingLF = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_LINE_ENDING_LF,
                Resources.MainEditMenuLineEndingLF,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuLineEndingCR = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_LINE_ENDING_CR,
                Resources.MainEditMenuLineEndingCR,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuAdvanced = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_ADVANCED,
                Resources.MainEditMenuAdvanced,
                null,
                Keys.None, null, null,
                true);

            _editMenuMakeUppercase = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MAKE_UPPERCASE,
                Resources.MainEditMenuMakeUppercase,
                null,
                Keys.None, "Ctrl+Shift+U", UI_EDIT_MENU_ITEM_Click);

            _editMenuMakeLowercase = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_MAKE_LOWERCASE,
                Resources.MainEditMenuMakeLowercase,
                null,
                Keys.None, "Ctrl+U", UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuLineComment = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_LINE_COMMENT,
                Resources.MainEditMenuLineComment,
                null,
                Keys.Control | Keys.Q, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuBlockComment = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_BLOCK_COMMENT,
                Resources.MainEditMenuBlockComment,
                null,
                Keys.Control | Keys.Shift | Keys.Q, null,
                UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuViewWhitespace = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_VIEW_WHITESPACE,
                Resources.MainEditMenuViewWhitespace,
                null,
                Keys.Control | Keys.W, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuTrimWhitespace = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_TRIM_WHITESPACE,
                Resources.MainEditMenuTrimWhitespace,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click,
                true);

            _editMenuWordWrap = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_WORD_WRAP,
                Resources.MainEditMenuWordWrap,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click);

            _editMenuSetReadOnly = MenuTools.CreateMenuItem(
                Constants.UI_EDIT_MENU_SET_READ_ONLY,
                Resources.MainEditMenuSetReadOnly,
                null,
                Keys.None, null, UI_EDIT_MENU_ITEM_Click,
                true);

            #endregion

            int fileMenuIndex =
                _mainForm.MainMenu.Items.IndexOf(_fileMenu);

            if (fileMenuIndex == -1)
            {
                _mainForm.MainMenu.Items.Add(_editMenu);
            }
            else
            {
                _mainForm.MainMenu.Items.Insert(
                    fileMenuIndex + 1, _editMenu);
            }

            _editMenu.DropDownItems.Add(_editMenuUndo);
            _editMenu.DropDownItems.Add(_editMenuRedo);
            _editMenu.DropDownItems.Add(_editMenuCut);
            _editMenu.DropDownItems.Add(_editMenuCopy);
            _editMenu.DropDownItems.Add(_editMenuPaste);
            _editMenu.DropDownItems.Add(_editMenuSelectAll);
            _editMenu.DropDownItems.Add(_editMenuFind);
            _editMenu.DropDownItems.Add(_editMenuReplace);
            _editMenu.DropDownItems.Add(_editMenuGoTo);
            _editMenu.DropDownItems.Add(_editMenuMacros);
            _editMenuMacros.DropDownItems.Add(_editMenuMacroRecord);
            _editMenuMacros.DropDownItems.Add(_editMenuMacroPlay);
            _editMenuMacros.DropDownItems.Add(_editMenuMacroLoad);
            _editMenuMacros.DropDownItems.Add(_editMenuMacroSave);

            if (Directory.Exists(_snippetsFolderPath))
            {
                _editMenu.DropDownItems.Add(_editMenuSnippets);
                _editMenuSnippets.DropDownItems.Add(_editMenuSnippetsManage);
            }

            _editMenu.DropDownItems.Add(_editMenuBookmarks);
            _editMenuBookmarks.DropDownItems.Add(_editMenuBookmarkToggle);
            _editMenuBookmarks.DropDownItems.Add(_editMenuBookmarksClear);
            _editMenuBookmarks.DropDownItems.Add(_editMenuBookmarkNext);
            _editMenuBookmarks.DropDownItems.Add(_editMenuBookmarkPrevious);
            _editMenu.DropDownItems.Add(_editMenuFolding);
            _editMenuFolding.DropDownItems.Add(_editMenuFoldToggle);
            _editMenuFolding.DropDownItems.Add(_editMenuFoldCollapseAll);
            _editMenuFolding.DropDownItems.Add(_editMenuFoldExpandAll);
            _editMenu.DropDownItems.Add(_editMenuEncoding);
            _editMenuEncoding.DropDownItems.Add(_editMenuEncodingANSI);
            _editMenuEncoding.DropDownItems.Add(_editMenuEncodingUTF8);
            _editMenuEncoding.DropDownItems.Add(_editMenuEncodingUTF16BE);
            _editMenuEncoding.DropDownItems.Add(_editMenuEncodingUTF16LE);
            _editMenu.DropDownItems.Add(_editMenuLineEnding);
            _editMenuLineEnding.DropDownItems.Add(_editMenuLineEndingCRLF);
            _editMenuLineEnding.DropDownItems.Add(_editMenuLineEndingCR);
            _editMenuLineEnding.DropDownItems.Add(_editMenuLineEndingLF);
            _editMenu.DropDownItems.Add(_editMenuAdvanced);
            _editMenuAdvanced.DropDownItems.Add(_editMenuMakeUppercase);
            _editMenuAdvanced.DropDownItems.Add(_editMenuMakeLowercase);

            if (enableCodeFeatures)
            {
                _editMenuAdvanced.DropDownItems.Add(_editMenuLineComment);
                _editMenuAdvanced.DropDownItems.Add(_editMenuBlockComment);
            }

            _editMenuAdvanced.DropDownItems.Add(_editMenuViewWhitespace);
            _editMenuAdvanced.DropDownItems.Add(_editMenuTrimWhitespace);
            _editMenuAdvanced.DropDownItems.Add(_editMenuWordWrap);
            _editMenuAdvanced.DropDownItems.Add(_editMenuSetReadOnly);

            #endregion

            _fileMenu.DropDownOpening +=
                new EventHandler(UI_FILE_MENU_DropDownOpening);
            _editMenu.DropDownOpening +=
                new EventHandler(UI_EDIT_MENU_DropDownOpening);
            _editMenuSnippets.DropDownOpening +=
                new EventHandler(UI_EDIT_MENU_SNIPPETS_DropDownOpening);
            _editMenuSnippets.Enabled          = false;
            _editMenuEncoding.DropDownOpening +=
                new EventHandler(UI_EDIT_MENU_ENCODING_DropDownOpening);
            _editMenuLineEnding.DropDownOpening +=
                new EventHandler(UI_EDIT_MENU_LINE_ENDING_DropDownOpening);

            _cursorPositionIndicator      = new ToolStripStatusLabel();
            _cursorPositionIndicator.Name =
                Constants.UI_STATUSBAR_CURSOR_POSITION_INDICATOR;
            _cursorPositionIndicator.Spring    = true;
            _cursorPositionIndicator.TextAlign = ContentAlignment.MiddleRight;

            _mainForm.StatusBar.Items.Add(_cursorPositionIndicator);

            _mainForm.ClientWindow.ActiveDocumentChanged +=
                new EventHandler(ClientWindow_ActiveDocumentChanged);

            /*
             * Create initial version of the snippets menu to
             * activate the shortcuts keys.
             */

            CreateSnippetsMenu();
        }