Пример #1
0
        internal static void DoPlugStart()
        {
            if (OnPlugReady != null)
            {
                OnPlugReady();
            }

            // subscribe to static events
            ProEnvironment.OnEnvironmentChange += FileExplorer.Instance.RebuildFileList;
            ProEnvironment.OnEnvironmentChange += DataBase.Instance.UpdateDatabaseInfo;
            ProEnvironment.OnEnvironmentChange += ParserHandler.ClearStaticData;

            Keywords.Instance.OnImport         += AutoCompletion.SetStaticItems;
            DataBase.Instance.OnDatabaseUpdate += AutoCompletion.SetStaticItems;
            AutoCompletion.OnUpdateStaticItems += ParserHandler.UpdateKnownStaticItems;

            ParserHandler.OnEndSendCompletionItems += AutoCompletion.SetDynamicItems;
            ParserHandler.OnStart += CodeExplorer.Instance.OnStart;
            ParserHandler.OnEndSendParserItems       += CodeExplorer.Instance.OnParseEndParserItems;
            ParserHandler.OnEndSendCodeExplorerItems += CodeExplorer.Instance.OnParseEndCodeExplorerItems;
            ParserHandler.OnEnd += CodeExplorer.Instance.OnParseEnd;

            ProExecutionHandleCompilation.OnEachCompilationOk += FilesInfo.ProExecutionHandleCompilationOnEachCompilationOk;

            // Clear the %temp% directory if we didn't do it properly last time
            Utils.DeleteDirectory(Config.FolderTemp, true);

            //Snippets.Init();
            FileTag.Import();

            // ask to disable the default autocompletion
            DelayedAction.StartNew(100, () => {
                if (!Npp.ConfXml.AskToDisableAutocompletionAndRestart())
                {
                    // check if an update was done
                    UpdateHandler.CheckForUpdateDone();
                }
            });

            // start checking for new updates
            UpdateHandler.StartCheckingForUpdate(); // async

            // Try to update the configuration from the distant shared folder
            ShareExportConf.StartCheckingForUpdates();

            // ReSharper disable once ObjectCreationAsStatement
            RecurentAction.StartNew(User.Ping, 1000 * 60 * 120);

            // Make sure to give the focus to scintilla on startup
            Sci.GrabFocus();
        }
Пример #2
0
        /// <summary>
        /// Called when the current document is saved,
        /// no matter if the document is a Progress file or not
        /// </summary>
        public static void DoNppDocumentSaved()
        {
            // the user can open a .txt and save it as a .p
            DoNppDocumentSwitched();

            // update function prototypes
            if (IsCurrentFileProgress)
            {
                ProGenerateCode.UpdateFunctionPrototypesIfNeeded(true);
            }

            // if it's a conf file, import it
            ShareExportConf.TryToImportFile(CurrentFilePath);
        }
Пример #3
0
        /// <summary>
        /// Called when the current document is saved,
        /// no matter if the document is a Progress file or not
        /// </summary>
        public static void DoNppDocumentSaved()
        {
            // if it's a conf file, import it
            ShareExportConf.TryToImportFile(Npp.CurrentFileInfo.Path);

            if (!Npp.CurrentFileInfo.IsProgress)
            {
                return;
            }

            // Display parser errors if any
            if (Config.Instance.DisplayParserErrorsOnSave && Npp.CurrentFileInfo.IsCompilable)
            {
                ProCodeFormat.DisplayParserErrors(true);
            }

            // update function prototypes
            ProGenerateCode.Factory.UpdateFunctionPrototypesIfNeeded(true);
        }
Пример #4
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;
            }
        }
Пример #5
0
        private void RefreshList()
        {
            if (_isCheckingDistant)
            {
                return;
            }
            _isCheckingDistant = true;
            Task.Factory.StartNew(() => {
                try {
                    bool sharedDirOk = !string.IsNullOrEmpty(fl_directory.Text) && Directory.Exists(fl_directory.Text);

                    // update the info we have on each item of the list
                    ShareExportConf.UpdateList(fl_directory.Text);

                    // invoke on ui thread
                    if (IsHandleCreated)
                    {
                        BeginInvoke((Action) delegate {
                            // we save the directory in the historic
                            if (sharedDirOk)
                            {
                                var list = Config.Instance.SharedConfHistoric.Split(',').ToList();
                                if (list.Exists(s => s.Equals(fl_directory.Text)))
                                {
                                    list.Remove(fl_directory.Text);
                                }
                                list.Insert(0, fl_directory.Text);
                                if (list.Count > 2)
                                {
                                    list.RemoveAt(list.Count - 1);
                                }
                                Config.Instance.SharedConfHistoric = string.Join(",", list);
                                btHistoric.Visible = true;
                            }

                            var nbMaj   = 0;
                            var iNbLine = 0;

                            foreach (var confLine in ShareExportConf.List)
                            {
                                // open
                                ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["bto_" + iNbLine]).Enabled = confLine.LocalExists;

                                // import
                                ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["bti_" + iNbLine]).Enabled = confLine.OnImport != null && confLine.LocalExists;

                                if (confLine.IsDir)
                                {
                                    // hide export/delete
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["bte_" + iNbLine]).Hide();
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btd_" + iNbLine]).Hide();
                                }
                                else
                                {
                                    // export
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["bte_" + iNbLine]).Enabled = confLine.OnExport != null && !confLine.LocalExists;

                                    // delete
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btd_" + iNbLine]).Enabled = confLine.OnDelete != null && confLine.LocalExists;
                                }

                                // distant open
                                ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btz_" + iNbLine]).Enabled = confLine.DistantExists;

                                // fetch
                                ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btf_" + iNbLine]).Enabled = confLine.OnFetch != null && confLine.DistantExists && (confLine.DistantTime.CompareTo(confLine.LocalTime) != 0 || confLine.LocalNbFiles != confLine.DistantNbFiles);

                                // push
                                ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btp_" + iNbLine]).Enabled = confLine.OnPush != null && confLine.LocalExists && sharedDirOk && (confLine.DistantTime.CompareTo(confLine.LocalTime) != 0 || confLine.LocalNbFiles != confLine.DistantNbFiles);

                                ((HtmlLabel)scrollPanel.ContentPanel.Controls["datel_" + iNbLine]).Text = confLine.LocalExists ? confLine.LocalTime.ToString("yyyy-MM-dd HH:mm:ss") : (confLine.IsDir ? "" : @"Not exported");

                                ((HtmlLabel)scrollPanel.ContentPanel.Controls["dated_" + iNbLine]).Text = confLine.DistantExists ? confLine.DistantTime.ToString("yyyy-MM-dd HH:mm:ss") : @"Not found";

                                // maj button
                                if (confLine.NeedUpdate)
                                {
                                    nbMaj++;
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btm_" + iNbLine]).Show();
                                }
                                else
                                {
                                    ((YamuiButtonImage)scrollPanel.ContentPanel.Controls["btm_" + iNbLine]).Hide();
                                }

                                iNbLine++;
                            }

                            // download all button
                            if (nbMaj > 0)
                            {
                                btDownloadAll.Show();
                            }
                            else
                            {
                                btDownloadAll.Hide();
                            }
                        });
                    }
                } catch (Exception e) {
                    ErrorHandler.ShowErrors(e, "Error while fetching distant files");
                }
            });
            _isCheckingDistant = false;
        }
Пример #6
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();
            }
        }
Пример #7
0
        internal static void DoPlugStart()
        {
            if (OnPlugReady != null)
            {
                OnPlugReady();
            }

            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            // subscribe to static events
            ProEnvironment.OnEnvironmentChange += FileExplorer.Instance.RebuildFileList;
            ProEnvironment.OnEnvironmentChange += DataBase.Instance.UpdateDatabaseInfo;
            ProEnvironment.OnEnvironmentChange += ParserHandler.ClearStaticData;

            Keywords.Instance.OnImport         += AutoCompletion.SetStaticItems;
            DataBase.Instance.OnDatabaseUpdate += AutoCompletion.SetStaticItems;
            AutoCompletion.OnUpdateStaticItems += ParserHandler.UpdateKnownStaticItems;

            ParserHandler.OnStart += CodeExplorer.Instance.OnStart;
            ParserHandler.OnEndSendCompletionItems   += AutoCompletion.SetDynamicItems;
            ParserHandler.OnEndSendParserItems       += CodeExplorer.Instance.OnParseEndParserItems;
            ParserHandler.OnEndSendParserItems       += SyntaxFolding.OnParseEndParserItems;
            ParserHandler.OnEndSendCodeExplorerItems += CodeExplorer.Instance.OnParseEndCodeExplorerItems;
            ParserHandler.OnEnd += CodeExplorer.Instance.OnParseEnd;

            ProExecutionHandleCompilation.OnEachCompilationOk += OpenedFilesInfo.ProExecutionHandleCompilationOnEachCompilationOk;

            // Clear the %temp% directory if we didn't do it properly last time
            Utils.DeleteDirectory(Config.FolderTemp, true);

            //Snippets.Init();
            FileCustomInfo.Import();

            DelayedAction.StartNew(100, () => {
                if (Config.Instance.InstallStep == 0)
                {
                    Config.Instance.InstallStep++;

                    // we are at the first notepad++ start
                    Npp.ConfXml.FinishPluginInstall(); // will apply npp options and restart npp
                    return;
                }
                if (Config.Instance.InstallStep == 1)
                {
                    Config.Instance.InstallStep++;

                    // global options applied, we are at the second startup
                    UserCommunication.NotifyUnique("welcome", "Thank you for installing 3P, you are awesome!<br><br>If this is your first look at 3P you should probably read the <b>getting started</b> section of the home page by clicking " + "go".ToHtmlLink("on this link right here") + ".<br><br><div align='right'>And as always... Enjoy!</div>", MessageImg.MsgInfo, "Fresh install", "Hello and welcome aboard!", args => {
                        Appli.ToggleView();
                        UserCommunication.CloseUniqueNotif("welcome");
                        args.Handled = true;
                    });
                }
                else if (!Config.Instance.NppStoppedCorrectly)
                {
                    // Npp didn't stop correctly, if the backup mode is activated, inform the user
                    if (Npp.ConfXml.BackupMode > 0)
                    {
                        UserCommunication.Notify("It seems that notepad++ didn't stop correctly.<br>If you lost some modifications, don't forget that you have a backup folder here :<br><br><div>" + Npp.ConfXml.BackupDirectory.ToHtmlLink() + "</div>" + (Npp.ConfXml.BackupUseCustomDir ? "<div>" + Npp.ConfXml.CustomBackupDirectory.ToHtmlLink() + "</div>" : ""), MessageImg.MsgInfo, "Notepad++ crashed", "Backup folder location");
                    }
                }

                Config.Instance.NppStoppedCorrectly = false;

                // check if an update was done and start checking for new updates
                Updater <MainUpdaterWrapper> .Instance.CheckForUpdateDoneAndStartCheckingForUpdates();

                if (Updater <ProlintUpdaterWrapper> .Instance.LocalVersion.IsHigherVersionThan("v0"))
                {
                    Updater <ProlintUpdaterWrapper> .Instance.StartCheckingForUpdate();
                }
                if (Updater <ProparseUpdaterWrapper> .Instance.LocalVersion.IsHigherVersionThan("v0"))
                {
                    Updater <ProparseUpdaterWrapper> .Instance.StartCheckingForUpdate();
                }

                // Try to update the configuration from the distant shared folder
                ShareExportConf.StartCheckingForUpdates();
            });

            // check if npp version is meeting current recommended version
            if (!string.IsNullOrEmpty(Npp.SoftwareStringVersion) && !Npp.SoftwareStringVersion.IsHigherOrEqualVersionThan(Config.RequiredNppVersion))
            {
                if (!Config.Instance.NppOutdatedVersion)
                {
                    UserCommunication.Notify("This version of 3P has been developed for Notepad++ " + Config.RequiredNppVersion + ", your version (" + Npp.SoftwareStringVersion + ") is outdated.<br><br>Using an outdated version, you might encounter bugs that would not occur otherwise.<br>Try to update your version of Notepad++ as soon as possible, or use 3P at your own risks.<br><br><a href='https://notepad-plus-plus.org/download/'>Download the latest version of Notepad++ here</a>", MessageImg.MsgHighImportance, "Outdated version", "3P requirements are not met");
                    Config.Instance.NppOutdatedVersion = true;
                }
            }
            else
            {
                Config.Instance.NppOutdatedVersion = false;
            }

            // ReSharper disable once ObjectCreationAsStatement
            RecurentAction.StartNew(User.Ping, 1000 * 60 * 120);

            // Make sure to give the focus to scintilla on startup
            Sci.GrabFocus();

            DelayedAction.StartNew(1000, Config.Save);
        }
Пример #8
0
        /// <summary>
        /// Called on npp ready
        /// </summary>
        internal static bool DoNppReady()
        {
            try {
                // need to set some values in the yamuiThemeManager
                ThemeManager.OnStartUp();

                // init an empty form, this gives us a Form to hook onto if we want to do stuff on the UI thread
                // from a back groundthread with BeginInvoke()
                // once this method is done, we are able to publish notifications
                UserCommunication.Init();

                // if the UDL is not installed
                if (!Style.InstallUdl(true))
                {
                    Style.InstallUdl();
                }
                else
                {
                    // first use message?
                    if (Config.Instance.UserFirstUse)
                    {
                        UserCommunication.NotifyUnique("welcome", "<div>Dear user,<br><br>Thank you for installing 3P, you are awesome!<br><br>If this is your first look at 3P I invite you to read the <b>Getting started</b> section of the home page by clicking <a href='go'>on this link right here</a>.<br><br></div><div align='right'>Enjoy!</div>", MessageImg.MsgInfo, "Information", "Hello and welcome aboard!", args => {
                            Appli.ToggleView();
                            UserCommunication.CloseUniqueNotif("welcome");
                            args.Handled = true;
                        });
                        Config.Instance.UserFirstUse = false;
                    }
                }

                // check Npp version, 3P requires version 6.8 or higher
                if (!String.IsNullOrEmpty(Npp.GetNppVersion) && !Npp.GetNppVersion.IsHigherVersionThan("6.7"))
                {
                    UserCommunication.Notify("Dear user,<br><br>Your version of notepad++ (" + Npp.GetNppVersion + ") is outdated.<br>3P <b>requires</b> the version <b>6.8</b> or above, <b>there are known issues with inferior versions</b>. Please upgrade to an up-to-date version of Notepad++ or use 3P at your own risks.<br><br><a href='https://notepad-plus-plus.org/download/'>Download the lastest version of Notepad++ here</a>", MessageImg.MsgError, "Outdated version", "3P requirements are not met");
                }

                // Check if an update has been done and start checking for new updates
                UpdateHandler.CheckForUpdateDone();
                UpdateHandler.StartCheckingForUpdate(); // async

                // Try to update the configuration from the distant shared folder
                ShareExportConf.StartCheckingForUpdates();

                // ReSharper disable once ObjectCreationAsStatement
                new ReccurentAction(User.Ping, 1000 * 60 * 120);

                // code explorer
                if (Config.Instance.CodeExplorerAutoHideOnNonProgressFile)
                {
                    CodeExplorer.Toggle(Abl.IsCurrentProgressFile);
                }
                else if (Config.Instance.CodeExplorerVisible)
                {
                    CodeExplorer.Toggle();
                }

                // File explorer
                if (Config.Instance.FileExplorerAutoHideOnNonProgressFile)
                {
                    FileExplorer.Toggle(Abl.IsCurrentProgressFile);
                }
                else if (Config.Instance.FileExplorerVisible)
                {
                    FileExplorer.Toggle();
                }

                return(true);
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Plugin startup");
            }
            return(false);
        }