/// <summary> /// Applies new options to the config.xml and restart npp to take them into account /// </summary> /// <param name="options"></param> public void ApplyNewOptions(NppConfigXmlOptions options) { if (options == null) { return; } var encoding = TextEncodingDetect.GetFileEncoding(FileNppConfigXml); var fileContent = Utils.ReadAllText(FileNppConfigXml, encoding); fileContent = fileContent.Replace("autoCAction=\"" + AutocompletionMode + "\"", "autoCAction=\"" + (options.DisableDefaultAutocompletion ? 0 : 3) + "\""); fileContent = fileContent.Replace("name=\"Backup\" action=\"" + BackupMode + "\"", "name=\"Backup\" action=\"" + (options.EnableBackupOnSave ? 2 : 0) + "\""); fileContent = fileContent.Replace("enableMultiSelection=\"" + (MultiSelectionEnabled ? "yes" : "no") + "\"", "enableMultiSelection=\"" + (options.EnableMultiSelection ? "yes" : "no") + "\""); if (options.EnableBackupOnSave && (string.IsNullOrEmpty(CustomBackupDirectory) || !BackupUseCustomDir)) { fileContent = fileContent.Replace("options.EnableBackupOnSave", "enableMultiSelection=\"" + (options.EnableMultiSelection ? "yes" : "no") + "\""); var regex = new Regex(@"useCustumDir=""\w*?""\s+dir=""[^""]*?""", RegexOptions.Singleline | RegexOptions.IgnoreCase); var matches = regex.Match(fileContent); if (matches.Success) { fileContent = regex.Replace(fileContent, "useCustumDir=\"yes\" dir=\"" + Path.Combine(BackupDirectory, "saved") + "\""); } } var configCopyPath = Path.Combine(Config.FolderUpdate, "config.xml"); if (!Utils.FileWriteAllText(configCopyPath, fileContent, encoding)) { return; } // replace default config by its copy on npp shutdown _3PUpdater.Instance.AddFileToMove(configCopyPath, FileNppConfigXml); Restart(); }
/// <summary> /// Can be called at anytime to let the user modify notepad++ options /// </summary> internal void ModifyingNppConfig() { object options = new NppConfigXmlOptions { EnableMultiSelection = ConfXml.MultiSelectionEnabled, DisableDefaultAutocompletion = ConfXml.AutocompletionMode == 0, EnableBackupOnSave = ConfXml.BackupMode != 0 }; ModifyingNppConfig(options, false); }
/// <summary> /// Called when the plugin is first used, suggests default options for npp /// </summary> internal void FinishPluginInstall() { object options = new NppConfigXmlOptions { EnableMultiSelection = true, DisableDefaultAutocompletion = true, EnableBackupOnSave = true }; ModifyingNppConfig(options, true); }