Ejemplo n.º 1
0
        public void beNotified(IntPtr notifyCode)
        {
            lock (typeof(UnmanagedExports))
            {
                try
                {
                    ScNotification nc          = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
                    string         contentFile = Npp.Editor.GetTabFile(nc.Header.IdFrom);

                    if (nc.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
                    {
                        PluginBase._funcItems.RefreshItems();
                        Plugin.RefreshToolbarImages();
                    }
                    else if (nc.Header.Code == (uint)SciMsg.SCN_CHARADDED)
                    {
                    }
                    else if (nc.Header.Code == (uint)NppMsg.NPPN_READY)
                    {
                        CSScriptIntegration.Initialize();
                        Plugin.InitView();
                    }
                    else if (nc.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
                    {
                        Marshal.FreeHGlobal(_ptrPluginName);
                        Plugin.CleanUp();
                    }

                    Plugin.OnNotification(nc);
                }
                catch { }//this is indeed the last line of defense as all CS-S calls have the error handling inside
            }
        }
 static void beNotified(IntPtr notifyCode)
 {
     try
     {
         ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
         if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
         {
             PluginBase._funcItems.RefreshItems();
             Main.SetToolBarIcon();
         }
         else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
         {
             Main.PluginCleanUp();
             Marshal.FreeHGlobal(_ptrPluginName);
         }
         else
         {
             Main.OnNotification(notification);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show($"{exception.Message}\r\n{exception.StackTrace}{(exception.InnerException == null ? string.Empty : $"\r\nInner Exception :\r\n{exception.InnerException.Message}\r\n{exception.InnerException.StackTrace}")}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
0
 public static void OnNotification(ScNotification notification)
 {
     if (notification.Header.Code == (uint)SciMsg.SCN_CHARADDED)
     {
         Kbg.Demo.Namespace.Main.doInsertHtmlCloseTag((char)notification.Character);
     }
 }
Ejemplo n.º 4
0
        private static void EnsureFirstWordIsSelected(ScNotification notification)
        {
            if (isPluginActive)
            {
                nppResource.ClearIndicator();

                if (notification.Header.Code == (ulong)SciMsg.SCN_UPDATEUI)
                {
                    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    var currentPosition  = scintillaGateway.GetCurrentPos();
                    if (currentPosition != lastPositionWhenUiUpdate)
                    {
                        if (scintillaGateway.GetSelectionEmpty())
                        {
                            lastPositionWhenUiUpdate = firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                        }
                    }
                    return;
                }

                if (notification.Header.Code == (ulong)SciMsg.SCN_MODIFIED)
                {
                    var isTextInsertedOrDeleted = (notification.ModificationType &
                                                   ((int)SciMsg.SC_MOD_INSERTTEXT | (int)SciMsg.SC_MOD_DELETETEXT)) > 0;
                    if (isTextInsertedOrDeleted)
                    {
                        lastPositionWhenUiUpdate = null;
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="notification"></param>
        public void OnNotification(ScNotification notification)
        {
            //Listen to any UI update to get informed about all file changes, chars added/removed etc.
            if (this.renderer.Visible)
            {
                if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI)
                {
                    UpdateMarkdownViewer();

                    //Update the scroll bar of the Viewer Panel only in case of vertical scrolls
                    if (this.configuration.SynchronizeScrolling && (notification.Updated & (uint)SciMsg.SC_UPDATE_V_SCROLL) != 0)
                    {
                        UpdateScrollBar();
                    }
                }
            }

            //If the renderer is visible or not but shouldn't be updated -> Check that nothing "interesting" happened
            if (!this.updateRenderer)
            {
                if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED)
                {
                    bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
                    bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;

                    //Track if any text modifications have been made
                    this.updateRenderer = this.updateRenderer || isInsert || isDelete;
                }
                else if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
                {
                    this.updateRenderer = true;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="notification"></param>
        public void OnNotification(ScNotification notification)
        {
            //Listen to any UI update to get informed about all file changes, chars added/removed etc.
            if (this.renderer.Visible)
            {
                //Check for updates
                if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI)
                {
                    //Update the view
                    Update((notification.Updated & (uint)SciMsg.SC_UPDATE_V_SCROLL) != 0);
                }
                else if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
                {
                    //Update the scintilla handle in all cases to keep track of which instance is active
                    UpdateEditorInformation();
                    this.Editor.CurrentBufferID = notification.Header.IdFrom;
                    Update(true, true);
                }
                else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED && !this.updateRenderer)
                {
                    bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
                    bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;

                    //Track if any text modifications have been made
                    this.updateRenderer = isInsert || isDelete;
                }
            }
        }
Ejemplo n.º 7
0
        public static void OnNotification(ScNotification notification)
        {
            if (notification.Header.Code == (ulong)NppMsg.NPPN_BUFFERACTIVATED)
            {
                isPluginActive = IsGitRebaseFile();
                return;
            }

            if (notification.Header.Code == (ulong)NppMsg.NPPN_FILEOPENED)
            {
                if (IsGitRebaseFile())
                {
                    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());

                    AddTextToRebaseFile(scintillaGateway);

                    DisableAutoCompletePopup(scintillaGateway);

                    SetSyntaxHighlighting();
                }

                return;
            }

            EnsureFirstWordIsSelected(notification);
        }
 public void OnNotification(ScNotification notification)
 {
     if (isPanelVisible)
     {
         if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI)
         {
             if (syncViewWithCaretPosition && lastCaretPosition != scintillaGateway.GetCurrentPos().Value)
             {
                 lastCaretPosition = scintillaGateway.GetCurrentPos().Value;
                 ScrollToElementAtLineNo(scintillaGateway.GetCurrentLineNumber());
             }
         }
         else
         if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
         {
             RenderMarkdown();
         }
         else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED)
         {
             bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
             bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;
             // Any modifications made ?
             if (isInsert || isDelete)
             {
                 lastTickCount = Environment.TickCount;
                 RenderMarkdown();
             }
         }
     }
 }
Ejemplo n.º 9
0
        public static void OnNotification(ScNotification notification)
        {
            // This method is invoked whenever something is happening in notepad++
            // use eg. as
            if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
            {
                if (SNDialogStruct.Form != null)
                {
                    ((FrmSNDlg)SNDialogStruct.Form).UpdateSNListBox();
                }
                SetCobolLikeWords(CobolLikeWords);
            }

            if (notification.Header.Code == (uint)NppMsg.NPPN_READY)
            {
                LoadMultipleVerticalLines(ShowVerticalLines);
            }
            // or
            //
            //if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED &&
            //    (notification.ModificationType == (int)SciMsg.SC_MOD_INSERTTEXT ||
            //     notification.ModificationType == (int)SciMsg.SC_MOD_DELETETEXT))
            //{
            //    UpdateSNList();
            //}
        }
Ejemplo n.º 10
0
        private void OnFoldNeeded(int firstLine, int lastLine, ScNotification scn)
        {
            var end = LineCount;

            while (GetLineIndentation(firstLine) != 0 && firstLine > 0)
            {
                firstLine--;
            }

            while (GetLineIndentation(lastLine) != 0 && lastLine > end)
            {
                lastLine--;
            }

            if (firstLine < 0 || lastLine > end)
            {
                return;
            }

            var ev = new FoldNeededEventArgs(firstLine, lastLine);
            var h  = FoldNeeded;

            if (h != null)
            {
                h(this, ev);
                Folding.Fold(ev.Regions);
            }
        }
 public void OnNotification(ScNotification notification)
 {
     if (isPanelVisible)
     {
         //if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI)
         //{
         //    bool scrollbarUpdated = (notification.Updated & (uint)SciMsg.SC_UPDATE_V_SCROLL) != 0;
         //    if (scrollbarUpdated)
         //    {
         //        UpdateScrollBar();
         //    }
         //}
         //else
         if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
         {
             RenderMarkdown();
         }
         else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED)
         {
             bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
             bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;
             // Any modifications made ?
             if (isInsert || isDelete)
             {
                 lastTickCount = Environment.TickCount;
                 RenderMarkdown();
             }
         }
     }
 }
Ejemplo n.º 12
0
        private LinkClickedEventArgs CreateLinkClickedEventArgs(ScNotification scn)
        {
            var sp  = GetWordBounds(scn.Position, -1);
            var ep  = GetWordBounds(scn.Position, 1);
            var src = GetTextRangeUnicode(sp < 0 ? 0 : sp, ep).Trim();

            return(new LinkClickedEventArgs(src));
        }
Ejemplo n.º 13
0
 public static void OnNotification(ScNotification notification)
 {
     // 1010u = ???
     if (notification.Header.Code == 1010u)
     {
         Main.bufferIsActivated();
     }
 }
Ejemplo n.º 14
0
        private void OnCharAdded(ScNotification scn)
        {
            var h = CharAdded;

            if (h != null)
            {
                h(this, new KeyPressEventArgs((Char)scn.Ch));
            }
        }
Ejemplo n.º 15
0
 public static void OnNotification(ScNotification notification)
 {
     if (notification.Header.Code == (uint)NppMsg.NPPN_FILESAVED)
     {
         HandleActivity(GetCurrentFile(), true);
     }
     else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED && (notification.ModificationType & (int)SciMsg.SC_MOD_INSERTTEXT) == (int)SciMsg.SC_MOD_INSERTTEXT)
     {
         HandleActivity(GetCurrentFile(), false);
     }
 }
Ejemplo n.º 16
0
 public static void OnNotification(ScNotification data)
 {
     foreach (ScriptInfo info in configuredScripts.Values)
     {
         if (info.Script != null && !(info.Script is NppScriptStub))
         {
             try { info.Script.OnNotification(data); }
             catch { } //does not matter what but we should not interrupt the SCNotification handling
         }
     }
 }
Ejemplo n.º 17
0
 public static void OnNotification(ScNotification notification)
 {
     // This method is invoked whenever something is happening in notepad++
     // use eg. as
     // if (notification.Header.Code == (uint)NppMsg.NPPN_xxx)
     // { ... }
     // or
     //
     // if (notification.Header.Code == (uint)SciMsg.SCNxxx)
     // { ... }
 }
Ejemplo n.º 18
0
        static void beNotified(IntPtr notifyCode)
        {
            ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));

            if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
            {
                Marshal.FreeHGlobal(_ptrPluginName);
            }
            else
            {
                Main.OnNotification(notification);
            }
        }
Ejemplo n.º 19
0
 public static void OnNotification(ScNotification notification)
 {
     switch ((NppMsg)notification.Header.Code)
     {
     case NppMsg.NPPN_BUFFERACTIVATED:
     {
         // todo: should be eventPublisher.publish(new event..) and objectExplorerPresenter should subscribe
         documentController.ActivateDocument(
             documentController.GetDocumentById(notification.Header.IdFrom));
     }
     break;
     }
 }
Ejemplo n.º 20
0
        public static void OnNotification(ScNotification notification)
        {
            switch (notification.Header.Code)
            {
            case (uint)NppMsg.NPPN_FILESAVED:
                HandleActivity(GetCurrentFile(), true);
                break;

            case (uint)SciMsg.SCN_MODIFIED when(notification.ModificationType& (int)SciMsg.SC_MOD_INSERTTEXT) == (int)SciMsg.SC_MOD_INSERTTEXT:
                HandleActivity(GetCurrentFile(), false);

                break;
            }
        }
        static void beNotified(IntPtr notifyCode)
        {
            ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));

            if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
            {
                PluginBase._funcItems.RefreshItems();
            }
            else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
            {
                Main.PluginCleanUp();
                Marshal.FreeHGlobal(_ptrPluginName);
            }
        }
Ejemplo n.º 22
0
 public static void OnNotification(ScNotification notification)
 {
     if (notification.Header.EventType == NppEventType.NPPN_WORDSTYLESUPDATED)
     {
         if (QueryWindow != null && Settings.UseNppStyling)
         {
             QueryWindow.ApplyStyling(true);
         }
     }
     // This method is invoked whenever something is happening in notepad++. Use as:
     // if (notification.Header.Code == (uint)NppMsg.NPPN_xxx) {...}
     // (or SciMsg.SCNxxx)
     //Trace.TraceInformation($"Npp notification received: {notification.Header.EventType}");
 }
Ejemplo n.º 23
0
        private void OnStyleNeeded(ScNotification scn)
        {
            var endStyled = Ref.Send(Sci.SCI_GETENDSTYLED);
            var sline     = LookupLine(Ref.Send(Sci.SCI_LINEFROMPOSITION, endStyled));
            var eline     = Ref.Send(Sci.SCI_LINEFROMPOSITION, scn.Position);

            var sp = Ref.Send(Sci.SCI_POSITIONFROMLINE, sline);
            var ep = Ref.Send(Sci.SCI_GETLINEENDPOSITION, eline);


            //System.Diagnostics.Debug.WriteLine("Styling " + (cc++));
            Style(sp, ep, false);
            OnFoldNeeded(sline, eline, scn);
        }
Ejemplo n.º 24
0
        public static void OnNotification(ScNotification notification)
        {
            if (IsPluginDisabled)
            {
                return;
            }

            var notificationType = notification.Header.Code;

            if (notificationType == (uint)NppMsg.NPPN_READY)
            {
                Logger.Info("NPPN_READY");

                if (!ProcessInit())
                {
                    DisablePlugin();
                }

                return;
            }

            if (!_isPluginInited)
            {
                return;
            }

            switch (notificationType)
            {
            case (uint)NppMsg.NPPN_BUFFERACTIVATED:
                // NPPN_BUFFERACTIVATED = switching tabs/open file/reload file/etc
                var gateway = PluginBase.GetGatewayFactory().Invoke();
                SearchEngine.SwitchContext(gateway.GetFullCurrentPath());
                break;

            case (uint)SciMsg.SCN_SAVEPOINTREACHED:
                // пользователь сохранил изменения в текущем файле (ctrl + s)
                SearchEngine.FireSaveFile();
                break;

            case (uint)SciMsg.SCN_UPDATEUI:
            {
                // SCROLL/INPUT/COLLAPSE and other events
                _linksHighlighter.MarkUpdated();
                break;
            }
            }
        }
Ejemplo n.º 25
0
        public static void OnNotification(ScNotification notification)
        {
            // This method is invoked whenever something is happening in notepad++
            // use eg. as
            // if (notification.Header.Code == (uint)NppMsg.NPPN_xxx)
            // { ... }
            // or
            //
            // if (notification.Header.Code == (uint)SciMsg.SCNxxx)
            // { ... }

            /*
             * before load
             * before open
             * file opened
             */

            uint   code   = notification.Header.Code;
            IntPtr idFrom = notification.Header.IdFrom;

            if (code == (uint)NppMsg.NPPN_READY)
            {
                npe.OnPluginReady();
            }
            else if (code == (uint)NppMsg.NPPN_FILEBEFOREOPEN)
            {
                npe.OnBeforeOpen(idFrom);
            }
            else if (code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
            {
                npe.OnBufferActivated(idFrom);
            }
            else if (code == (uint)NppMsg.NPPN_FILESAVED)
            {
                npe.OnFileSaved(idFrom);
            }
            else if (code == (uint)NppMsg.NPPN_FILECLOSED)
            {
                npe.OnFileClosed(idFrom);
            }
            else if (code == (uint)NppMsg.NPPN_LANGCHANGED)
            {
                npe.OnLangChanged(idFrom);
            }
        }
        public void Execute(ScNotification notification)
        {
            if (notification.Header.Code != (ulong)SciMsg.SCN_UPDATEUI)
            {
                return;
            }
            if (notification.Updated != (int)SciMsg.SC_UPDATE_SELECTION)
            {
                return;
            }

            var scintillaGateway = gatewayFactory();
            var selectionLength  = scintillaGateway.GetSelectionLength();

            if (selectionLength != GuidHelperConstants.StartPartOfGuidLength &&
                selectionLength != GuidHelperConstants.EndPartOfGuidLength)
            {
                return;
            }

            var anchor           = scintillaGateway.GetAnchor();
            var currentPos       = scintillaGateway.GetCurrentPos();
            var absolutePosStart = Position.Min(anchor, currentPos);
            var lineNumber       = scintillaGateway.LineFromPosition(absolutePosStart);
            var lineContent      = scintillaGateway.GetLine(lineNumber);

            var absolutePosOfLine = scintillaGateway.PositionFromLine(lineNumber);
            var relativeLineOfset = (absolutePosStart - absolutePosOfLine).Value;

            var isLeftToRigthSelection = currentPos > anchor;

            switch (selectionLength)
            {
            case GuidHelperConstants.StartPartOfGuidLength:
                FirstPartOfGuidPossiblySelected(relativeLineOfset, lineContent, absolutePosOfLine, isLeftToRigthSelection, scintillaGateway, absolutePosStart);
                break;

            case GuidHelperConstants.EndPartOfGuidLength:
                LastPartOfGuidPossiblySelected(relativeLineOfset, lineContent, absolutePosStart, isLeftToRigthSelection, scintillaGateway);
                break;
            }
        }
Ejemplo n.º 27
0
 public static void OnNotification(ScNotification notification)
 {
 }
Ejemplo n.º 28
0
 public static void OnNotification(ScNotification data)
 {
 }
Ejemplo n.º 29
0
 public virtual void OnNotification(ScNotification notification)
 {
 }
Ejemplo n.º 30
0
 /// <summary>
 /// This method is invoked whenever something is happening in notepad++
 /// use eg. as
 /// if (notification.Header.Code == (uint)NppMsg.NPPN_xxx)
 /// { ... }
 /// or
 ///
 /// if (notification.Header.Code == (uint)SciMsg.SCNxxx)
 /// { ... }
 /// </summary>
 /// <param name="notification"></param>
 public static void OnNotification(ScNotification notification)
 {
     MarkdownViewer.OnNotification(notification);
 }