コード例 #1
0
        private static void CommonTagAction(Action <FileTagObject> performAction)
        {
            var filename = Path.GetFileName(Plug.CurrentFilePath);

            if (FileTag.Contains(filename))
            {
                var fileInfo = FileTag.GetLastFileTag(filename);
                Npp.BeginUndoAction();
                performAction(fileInfo);
                Npp.EndUndoAction();
            }
            else
            {
                UserCommunication.Notify("No info available for this file, please fill the file info form first!", MessageImg.MsgToolTip, "Insert modification tags", "No info available", 4);
                Appli.Appli.GoToPage(PageNames.FileInfo);
            }
        }
コード例 #2
0
        /// <summary>
        /// If no selection, comment the line of the caret
        /// If selection, comment the selection as a block
        /// </summary>
        public static void ToggleComment()
        {
            Npp.BeginUndoAction();

            // for each selection (limit selection number)
            for (var i = 0; i < Npp.Selection.Count; i++)
            {
                var selection = Npp.GetSelection(i);

                int  startPos;
                int  endPos;
                bool singleLineComm = false;
                if (selection.Caret == selection.Anchor)
                {
                    // comment line
                    var thisLine = new Npp.Line(Npp.LineFromPosition(selection.Caret));
                    startPos       = thisLine.IndentationPosition;
                    endPos         = thisLine.EndPosition;
                    singleLineComm = true;
                }
                else
                {
                    startPos = selection.Start;
                    endPos   = selection.End;
                }

                var toggleMode = ToggleCommentOnRange(startPos, endPos);
                if (toggleMode == 3)
                {
                    selection.SetPosition(startPos + 3);
                }

                // correct selection...
                if (!singleLineComm && toggleMode == 2)
                {
                    selection.End += 2;
                }
            }

            Npp.EndUndoAction();
        }
コード例 #3
0
        /// <summary>
        /// This method checks if the current document contains function prototypes that are not updated
        /// and correct them if needed
        /// </summary>
        /// <remarks>This method is costly because we parse everything potentially X times, but it's much simpler this way...</remarks>
        public static void UpdateFunctionPrototypesIfNeeded(bool silent = false)
        {
            if (_ignoredFiles.Contains(Plug.CurrentFilePath) || Config.Instance.DisablePrototypeAutoUpdate)
            {
                if (silent)
                {
                    return;
                }
                _ignoredFiles.Remove(Plug.CurrentFilePath);
            }

            List <ParsedImplementation> listOfOutDatedProto;
            List <ParsedImplementation> listOfSoloImplementation;
            List <ParsedPrototype>      listOfUselessProto;

            StringBuilder outputMessage = new StringBuilder();

            var nbLoop       = 0;
            var nbNotCreated = 0;
            var nbThingsDone = 0;
            var nbToDo       = GetPrototypesLists(out listOfOutDatedProto, out listOfSoloImplementation, out listOfUselessProto);

            // if there is at least 1 thing to do
            if (nbToDo > 0)
            {
                Npp.BeginUndoAction();

                // Add proto
                if (listOfSoloImplementation.Count > 0)
                {
                    var tempMes = new StringBuilder("The following function prototypes have been created :");

                    while (listOfSoloImplementation.Count > nbNotCreated && nbLoop <= nbToDo)
                    {
                        if (AddPrototypes(ref tempMes, listOfSoloImplementation[nbNotCreated]))
                        {
                            nbThingsDone++;
                        }
                        else
                        {
                            nbNotCreated++;
                        }

                        GetPrototypesLists(out listOfOutDatedProto, out listOfSoloImplementation, out listOfUselessProto);
                        nbLoop++;
                    }
                    tempMes.Append("<br><br>");
                    if (nbThingsDone > 0)
                    {
                        outputMessage.Append(tempMes);
                    }
                }

                // delete proto
                if (listOfUselessProto.Count > 0)
                {
                    outputMessage.Append("The following prototypes have been deleted :");
                    while (listOfUselessProto.Count > 0 && nbLoop <= nbToDo)
                    {
                        if (DeletePrototypes(ref outputMessage, listOfUselessProto[0]))
                        {
                            nbThingsDone++;
                        }

                        GetPrototypesLists(out listOfOutDatedProto, out listOfSoloImplementation, out listOfUselessProto);
                        nbLoop++;
                    }
                    outputMessage.Append("<br><br>");
                }

                // update proto
                if (listOfOutDatedProto.Count > 0 && nbLoop <= nbToDo)
                {
                    outputMessage.Append("The following functions have had their prototype synchronized :");
                    while (listOfOutDatedProto.Count > 0)
                    {
                        if (UpdatePrototypes(ref outputMessage, listOfOutDatedProto[0]))
                        {
                            nbThingsDone++;
                        }

                        GetPrototypesLists(out listOfOutDatedProto, out listOfSoloImplementation, out listOfUselessProto);
                        nbLoop++;
                    }
                    outputMessage.Append("<br><br>");
                }

                Npp.EndUndoAction();
            }

            if (nbThingsDone == 0)
            {
                if (!silent)
                {
                    if (nbNotCreated == 0)
                    {
                        UserCommunication.Notify("There was nothing to be done :<br>All the prototypes match their implementation", MessageImg.MsgInfo, "Function prototypes", "Everything is synchronized", 5);
                    }
                    else
                    {
                        UserCommunication.Notify("Failed to find the prototype for " + nbNotCreated + " function implementations<br>Your document is not correctly formatted for 3P to automatically create them :<br><i>The block _UIB-PREPROCESSOR-BLOCK is missing or the procedure can't be opened in the appbuilder!</i><br><br>Please correct your document manually, then they will all be updated correctly" + ProCodeFormat.GetParserErrorDescription(), MessageImg.MsgHighImportance, "Function prototypes", "Failed to create prototypes");
                    }
                }
            }
            else
            {
                outputMessage.Append("<i>");
                outputMessage.Append("CTRL + Z will cancel the above-mentionned modifications<br>");
                outputMessage.Append(Plug.CurrentFilePath.ToHtmlLink("Click here to stop auto-updating the prototypes for this file"));
                outputMessage.Append("</i>");
                UserCommunication.NotifyUnique("Prototype_synchro", outputMessage.ToString(), MessageImg.MsgOk, "Function prototypes", "Synchronization done", args => {
                    var split = args.Link.Split('#');
                    if (split.Length == 2)
                    {
                        Npp.GotoPos(split[0], Int32.Parse(split[1]));
                        args.Handled = true;
                    }
                    else
                    {
                        if (!_ignoredFiles.Contains(args.Link))
                        {
                            _ignoredFiles.Add(args.Link);
                            UserCommunication.NotifyUnique("Prototype_synchro", "Automatic prototype updates stopped for the file :<br>" + Plug.CurrentFilePath + "<br><br><i>This is effective until you restart Notepad++<br>You can also trigger an update manually to restart the auto-update</i>", MessageImg.MsgInfo, "Function prototypes", "Synchronization stopped", null, 5);
                        }
                    }
                }, 5);
            }
        }