This class contains very generic wrappers for basic Notepad++ functionality.
Пример #1
0
        public static void OnSciModified(SCNotification nc)
        {
            bool deletedText = (nc.modificationType & (int)SciMsg.SC_MOD_DELETETEXT) != 0;

            // if the text has changed
            if (deletedText || (nc.modificationType & (int)SciMsg.SC_MOD_INSERTTEXT) != 0)
            {
                // observe modifications to lines (MANDATORY)
                Npp.UpdateLinesInfo(nc, !deletedText);

                // parse
                ParserHandler.ParseCurrentDocument();
            }

            // did the user supress 1 char?
            if (deletedText && nc.length == 1)
            {
                AutoComplete.UpdateAutocompletion();
            }
        }
Пример #2
0
        /// <summary>
        /// Called when the user switches tab document,
        /// no matter if the document is a Progress file or not
        /// </summary>
        public static void DoNppBufferActivated(bool initiating = false)
        {
            // if the file has just been opened
            var currentFile = Npp.GetCurrentFilePath();

            if (!_openedFileList.Contains(currentFile))
            {
                _openedFileList.Add(currentFile);

                // need to auto change encoding?
                if (Config.Instance.AutoSwitchEncodingTo != NppEncodingFormat._Automatic_default && !string.IsNullOrEmpty(Config.Instance.AutoSwitchEncodingForFilePatterns))
                {
                    if (Npp.GetCurrentFilePath().TestAgainstListOfPatterns(Config.Instance.AutoSwitchEncodingForFilePatterns))
                    {
                        NppMenuCmd cmd;
                        if (Enum.TryParse(((int)Config.Instance.AutoSwitchEncodingTo).ToString(), true, out cmd))
                        {
                            Npp.RunCommand(cmd);
                        }
                    }
                }
            }

            // deactivate show space for conf files
            if (ShareExportConf.IsFileExportedConf(CurrentFilePath))
            {
                if (Npp.ViewWhitespace != WhitespaceMode.Invisible && !Npp.ViewEol)
                {
                    Npp.ViewWhitespace = _whitespaceMode;
                }
            }

            DoNppDocumentSwitched(initiating);

            // activate show space for conf files
            if (ShareExportConf.IsFileExportedConf(CurrentFilePath))
            {
                Npp.ViewWhitespace = WhitespaceMode.VisibleAlways;
            }
        }
Пример #3
0
        public static bool MouseMessageHandler(WinApi.Messages message, Win32Api.MOUSEHOOKSTRUCT mouseStruct)
        {
            switch (message)
            {
            // middle click : go to definition
            case WinApi.Messages.WM_MBUTTONDOWN:
                if (Npp.CurrentFileInfo.IsProgress)
                {
                    if (KeyboardMonitor.GetModifiers.IsCtrl)
                    {
                        Npp.GoBackFromDefinition();
                    }
                    else
                    {
                        ProMisc.GoToDefinition(true);
                    }
                }
                return(true);

            //break;
            // (CTRL + ) Right click : show main menu
            case WinApi.Messages.WM_RBUTTONUP:
                if (KeyboardMonitor.GetModifiers.IsCtrl)
                {
                    // we need the cursor to be in scintilla but not on the application or the autocompletion!
                    if ((!Appli.IsVisible || !Appli.IsMouseIn()) &&
                        (!InfoToolTip.IsVisible || !InfoToolTip.IsMouseIn()) &&
                        (!AutoCompletion.IsVisible || !AutoCompletion.IsMouseIn()))
                    {
                        AppliMenu.ShowMainMenu(true);
                        return(true);
                    }
                }
                break;
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Called when the user enters any character in npp
        /// </summary>
        /// <param name="c"></param>
        public static void OnSciCharTyped(char c)
        {
            // CTRL + S : char code 19
            if (c == (char)19)
            {
                Npp.Undo();
                Npp.SaveCurrentDocument();
                return;
            }

            // we are still entering a keyword
            if (Abl.IsCharAllowedInVariables(c))
            {
                ActionsAfterUpdateUi.Enqueue(() => {
                    OnCharAddedWordContinue(c);
                });
            }
            else
            {
                ActionsAfterUpdateUi.Enqueue(() => {
                    OnCharAddedWordEnd(c);
                });
            }
        }
Пример #5
0
        /// <summary>
        /// Called when the user switches tab document
        /// You can use Npp.CurrentFile and Npp.PreviousFile in this method
        /// </summary>
        public static void DoNppBufferActivated(bool initiating = false)
        {
            // Apply options to npp and scintilla depending if we are on a progress file or not
            ApplyOptionsForScintilla();

            // if the file has just been opened
            if (!_openedFileList.Contains(Npp.CurrentFileInfo.Path))
            {
                _openedFileList.Add(Npp.CurrentFileInfo.Path);

                // need to auto change encoding?
                if (Config.Instance.AutoSwitchEncodingTo != NppEncodingFormat._Automatic_default && !string.IsNullOrEmpty(Config.Instance.AutoSwitchEncodingForFilePatterns))
                {
                    if (Npp.CurrentFileInfo.Path.TestAgainstListOfPatterns(Config.Instance.AutoSwitchEncodingForFilePatterns))
                    {
                        NppMenuCmd cmd;
                        if (Enum.TryParse(((int)Config.Instance.AutoSwitchEncodingTo).ToString(), true, out cmd))
                        {
                            Npp.RunCommand(cmd);
                        }
                    }
                }
            }

            // activate show space for conf files / deactivate if coming from a conf file
            if (ShareExportConf.IsFileExportedConf(Npp.PreviousFileInfo.Path))
            {
                if (Sci.ViewWhitespace != WhitespaceMode.Invisible && !Sci.ViewEol)
                {
                    Sci.ViewWhitespace = _whitespaceMode;
                }
            }
            if (ShareExportConf.IsFileExportedConf(Npp.CurrentFileInfo.Path))
            {
                Sci.ViewWhitespace = WhitespaceMode.VisibleAlways;
            }

            // close popups..
            ClosePopups();

            if (initiating)
            {
                // make sure to use the ProEnvironment and colorize the error counter
                OpenedFilesInfo.UpdateFileStatus();
            }
            else
            {
                if (Config.Instance.CodeExplorerAutoHideOnNonProgressFile)
                {
                    CodeExplorer.Instance.Toggle(Npp.CurrentFileInfo.IsProgress);
                }
                if (Config.Instance.FileExplorerAutoHideOnNonProgressFile)
                {
                    FileExplorer.Instance.Toggle(Npp.CurrentFileInfo.IsProgress);
                }
            }

            // Update info on the current file
            OpenedFilesInfo.UpdateErrorsInScintilla();
            ProEnvironment.Current.ReComputeProPath();

            AutoCompletion.SetStaticItems();

            // Parse the document
            ParserHandler.ParseDocumentNow();

            // publish the event
            if (OnDocumentChangedEnd != null)
            {
                OnDocumentChangedEnd();
            }
        }
Пример #6
0
        public static bool MouseMessageHandler(WinApi.Messages message, Win32Api.MOUSEHOOKSTRUCT mouseStruct)
        {
            switch (message)
            {
            // middle click : go to definition
            case WinApi.Messages.WM_MBUTTONDOWN:
                if (Npp.CurrentFileInfo.IsProgress)
                {
                    if (KeyboardMonitor.GetModifiers.IsCtrl)
                    {
                        Npp.GoBackFromDefinition();
                    }
                    else
                    {
                        ProMisc.GoToDefinition(true);
                    }
                }
                return(true);

            //break;
            // (CTRL + ) Right click : show main menu
            case WinApi.Messages.WM_RBUTTONUP:
                if (KeyboardMonitor.GetModifiers.IsCtrl)
                {
                    // we need the cursor to be in scintilla but not on the application or the autocompletion!
                    if ((!Appli.IsVisible || !Appli.IsMouseIn()) &&
                        (!InfoToolTip.IsVisible || !InfoToolTip.IsMouseIn()) &&
                        (!AutoCompletion.IsVisible || !AutoCompletion.IsMouseIn()))
                    {
                        AppliMenu.ShowMainMenu(true);
                        return(true);
                    }
                }
                break;
            }

            // HACK: The following is to handle the MOVE/RESIZE event of npp's window.
            // It would be cleaner to use a WndProc bypass but it costs too much... this is a cheaper solution
            switch (message)
            {
            case WinApi.Messages.WM_NCLBUTTONDOWN:
                if (!WinApi.GetWindowRect(Npp.CurrentSci.Handle).Contains(Cursor.Position))
                {
                    MouseMonitor.Instance.Add(WinApi.Messages.WM_MOUSEMOVE);
                }
                break;

            case WinApi.Messages.WM_LBUTTONUP:
            case WinApi.Messages.WM_NCLBUTTONUP:
                if (MouseMonitor.Instance.Remove(WinApi.Messages.WM_MOUSEMOVE))
                {
                    if (OnNppWindowsMove != null)
                    {
                        OnNppWindowsMove();
                    }
                }
                break;

            case WinApi.Messages.WM_MOUSEMOVE:
                if (OnNppWindowsMove != null)
                {
                    OnNppWindowsMove();
                }
                break;
            }

            return(false);
        }
Пример #7
0
 /// <summary>
 /// Called when the plugin can set new shorcuts to the toolbar in notepad++
 /// </summary>
 internal static void DoNppNeedToolbarImages()
 {
     Npp.SetToolbarImage(ImageResources.Logo16x16, AppliMenu.MainMenuCommandIndex);
     Npp.SetToolbarImage(ImageResources.FileExplorer16x16, FileExplorer.Instance.DockableCommandIndex);
     Npp.SetToolbarImage(ImageResources.CodeExplorer16x16, CodeExplorer.Instance.DockableCommandIndex);
 }
Пример #8
0
        /// <summary>
        /// Called when the user has finished entering a word
        /// Called after the UI has updated, allows to correctly read the text style, to correct
        /// the indentation w/o it being erased and so on...
        /// </summary>
        /// <param name="c"></param>
        public static void OnCharAddedWordEnd(char c)
        {
            try {
                // we finished entering a keyword
                var curPos = Npp.CurrentPosition;
                int offset;
                if (c == '\n')
                {
                    offset  = curPos - Npp.GetLine().Position;
                    offset += (Npp.GetTextOnLeftOfPos(curPos - offset, 2).Equals("\r\n")) ? 2 : 1;
                }
                else
                {
                    offset = 1;
                }
                var searchWordAt    = curPos - offset;
                var keyword         = Npp.GetKeyword(searchWordAt);
                var isNormalContext = Style.IsCarretInNormalContext(searchWordAt);

                if (!String.IsNullOrWhiteSpace(keyword) && isNormalContext)
                {
                    string replacementWord = null;

                    // automatically insert selected keyword of the completion list
                    if (Config.Instance.AutoCompleteInsertSelectedSuggestionOnWordEnd && keyword.ContainsAtLeastOneLetter())
                    {
                        if (AutoComplete.IsVisible)
                        {
                            var lastSugg = AutoComplete.GetCurrentSuggestion();
                            if (lastSugg != null)
                            {
                                replacementWord = lastSugg.DisplayText;
                            }
                        }
                    }

                    // replace abbreviation by completekeyword
                    if (Config.Instance.CodeReplaceAbbreviations)
                    {
                        var fullKeyword = Keywords.GetFullKeyword(replacementWord ?? keyword);
                        if (fullKeyword != null)
                        {
                            replacementWord = fullKeyword;
                        }
                    }

                    // replace the last keyword by the correct case
                    var casedKeyword = AutoComplete.CorrectKeywordCase(replacementWord ?? keyword, searchWordAt);
                    if (casedKeyword != null)
                    {
                        replacementWord = casedKeyword;
                    }

                    if (replacementWord != null)
                    {
                        Npp.ReplaceKeywordWrapped(replacementWord, -offset);
                    }
                }


                // replace semicolon by a point
                if (c == ';' && Config.Instance.CodeReplaceSemicolon && isNormalContext)
                {
                    Npp.ModifyTextAroundCaret(-1, 0, ".");
                }

                // handles the autocompletion
                AutoComplete.UpdateAutocompletion();
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in OnCharAddedWordEnd");
            }
        }
Пример #9
0
        public static void DoNppDocumentSwitched(bool initiating = false)
        {
            // update current file info
            IsPreviousFileProgress = IsCurrentFileProgress;
            IsCurrentFileProgress  = Abl.IsCurrentProgressFile;
            CurrentFilePath        = Npp.GetCurrentFilePath();
            CurrentFileObject      = FilesInfo.GetFileInfo(CurrentFilePath);

            // accept advanced notifications only if the current file is a progress file
            CurrentFileAllowed = IsCurrentFileProgress;

            // update current scintilla
            Npp.UpdateScintilla();

            // Apply options to npp and scintilla depending if we are on a progress file or not
            ApplyOptionsForScintilla();

            // close popups..
            ClosePopups();

            // Update info on the current file
            FilesInfo.UpdateErrorsInScintilla();

            // refresh file explorer currently opened file
            FileExplorer.RedrawFileExplorerList();

            if (!initiating)
            {
                if (Config.Instance.CodeExplorerAutoHideOnNonProgressFile)
                {
                    CodeExplorer.Toggle(IsCurrentFileProgress);
                }
                if (Config.Instance.FileExplorerAutoHideOnNonProgressFile)
                {
                    FileExplorer.Toggle(IsCurrentFileProgress);
                }
            }
            else
            {
                // make sure to use the ProEnvironment and colorize the error counter
                FilesInfo.UpdateFileStatus();
                ProEnvironment.Current.ReComputeProPath();
            }

            if (IsCurrentFileProgress)
            {
                // Need to compute the propath again, because we take into account relative path
                ProEnvironment.Current.ReComputeProPath();

                // rebuild lines info (MANDATORY)
                Npp.RebuildLinesInfo();
            }

            // Parse the document
            ParserHandler.ParseCurrentDocument(true);

            // publish the event
            if (OnDocumentChangedEnd != null)
            {
                OnDocumentChangedEnd();
            }
        }