示例#1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="pluginInfo"><see cref="PipelinePluginInfo"/> to save.</param>
        /// <param name="settings">Object to access user settings.</param>
        public TempPipelinePluginSaver(PipelinePluginInfo pluginInfo, UserSettings settings)
        {
            PluginInfo    = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo));
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));

            existed = this.settings.SaveTempPipelinePlugin(PluginInfo);
        }
示例#2
0
        /// <summary>
        /// Adds all pipeline plugins to the given list, in display order if possible.
        /// </summary>
        /// <param name="plugins">List where to add plugins</param>
        /// <param name="settings"><see cref="UserSettings"/> used to fetch
        /// pipeline plugins.</param>
        /// <param name="pipelinePluginsOptions">What kind of pipeline plugins
        /// to add to the list.</param>
        private static void GetPipelinePlugins(List <Plugin> plugins, UserSettings settings,
                                               PipelinePluginsOptions pipelinePluginsOptions)
        {
            Debug.Assert(plugins != null);
            Debug.Assert(settings != null);

            List <PipelinePluginInfo> pluginInfos = new List <PipelinePluginInfo>();

            if ((pipelinePluginsOptions & PipelinePluginsOptions.FetchPipelinePlugins) != 0)
            {
                pluginInfos.AddRange(settings.PipelinePlugins);
            }
            if ((pipelinePluginsOptions & PipelinePluginsOptions.FetchTempPipelinePlugins) != 0)
            {
                // Temp pipeline plugins can actually override existing pipeline plugins.
                // This mimics the code in PathCopyCopyPluginsRegistry.cpp in the C++ project.
                pluginInfos = settings.TempPipelinePlugins.Union(pluginInfos).ToList();
            }
            if (pluginInfos.Count > 0)
            {
                if (plugins.Count > 0)
                {
                    plugins.Add(new SeparatorPlugin());
                }
                plugins.AddRange(PipelinePluginInfo.ToPlugins(pluginInfos));
            }
        }
示例#3
0
        /// <summary>
        /// Main method to use the form. Will show the form as a modal dialog,
        /// allowing the user to edit the given pipeline plugin. When the user
        /// is done, the method will return the new <see cref="PipelinePluginInfo"/>
        /// if the user accepted the changes.
        /// </summary>
        /// <param name="owner">Owner of this dialog. Can be <c>null</c>.</param>
        /// <param name="oldInfo">Info about a pipeline plugin. If set, we'll
        /// populate the form with the plugin's values to allow the user to
        /// edit the plugin.</param>
        /// <param name="switchToExpert">Upon exit, will indicate whether user
        /// chose to switch to Expert Mode.</param>
        /// <returns>Info about the new plugin that user edited. Will be
        /// <c>null</c> if user cancels editing.</returns>
        public PipelinePluginInfo EditPlugin(IWin32Window owner, PipelinePluginInfo oldInfo,
                                             out bool switchToExpert)
        {
            // Save old info so that the OnLoad event handler can use it.
            oldPluginInfo = oldInfo;

            // If a plugin info was specified, decode its pipeline immediately.
            // We want pipeline exceptions to propagate out *before* we show the form.
            if (oldPluginInfo != null)
            {
                oldPipeline = PipelineDecoder.DecodePipeline(oldPluginInfo.EncodedElements);
            }

            // Save plugin ID, or generate a new one if this is a new plugin.
            if (oldPluginInfo != null)
            {
                pluginId = oldPluginInfo.Id;
            }
            else
            {
                pluginId = Guid.NewGuid();
            }

            // Show the form and check result.
            DialogResult dialogRes = ShowDialog(owner);

            // If user saved, return the new info.
            Debug.Assert(dialogRes == DialogResult.Cancel || newPluginInfo != null);
            switchToExpert = dialogRes == DialogResult.Retry;
            return(dialogRes != DialogResult.Cancel ? newPluginInfo : null);
        }
        /// <summary>
        /// Edits our pipeline plugin.
        /// </summary>
        /// <returns>Info about pipeline plugin edited. Will be <c>null</c> if the
        /// user cancelled the editing.</returns>
        private PipelinePluginInfo Edit()
        {
            // Determine what form to show initially depending on the complexity of the pipeline
            // and the last edit mode used for the plugin.
            PipelinePluginInfo info = pluginInfo;
            bool advanced           = pluginInfo != null && pluginInfo.EditMode.HasValue
                ? pluginInfo.EditMode.Value == PipelinePluginEditMode.Expert
                : pipeline != null && !IsPipelineSimple(pipeline);

            // Loop until user is satisfied.
            bool switchMode = true;

            while (switchMode)
            {
                if (advanced)
                {
                    using (AdvancedPipelinePluginForm editForm = new AdvancedPipelinePluginForm()) {
                        info = editForm.EditPlugin(owner, info, out switchMode);
                    }
                }
                else
                {
                    using (PipelinePluginForm editForm = new PipelinePluginForm()) {
                        info = editForm.EditPlugin(owner, info, out switchMode);
                    }
                }
                if (switchMode)
                {
                    advanced = !advanced;
                }
            }

            return(info);
        }
示例#5
0
        /// <summary>
        /// Saves a temporary pipeline plugin to the temp pipeline plugins key.
        /// </summary>
        /// <param name="pluginInfo"><see cref="PipelinePluginInfo"/> to save.</param>
        public void SaveTempPipelinePlugin(PipelinePluginInfo pluginInfo)
        {
            Debug.Assert(pluginInfo != null);

            List <PipelinePluginInfo> pluginInfos = new List <PipelinePluginInfo>();

            pluginInfos.Add(pluginInfo);
            SavePipelinePlugins(pluginInfos, userTempPipelinePluginsKey, false, false);
        }
示例#6
0
        /// <summary>
        /// Removes a temp pipeline plugin from the registry.
        /// </summary>
        /// <param name="pluginInfo">Plugin info for the pipeline
        /// plugin to destroy.</param>
        public void Remove(PipelinePluginInfo pluginInfo)
        {
            int index = tempPipelinePluginSavers.FindIndex(saver => saver.PluginInfo == pluginInfo);

            if (index >= 0)
            {
                tempPipelinePluginSavers[index].Dispose();
                tempPipelinePluginSavers.RemoveAt(index);
            }
        }
示例#7
0
        /// <summary>
        /// Removes a temporary pipeline plugin from the temp pipeline plugins key.
        /// </summary>
        /// <param name="pluginInfo"><see cref="PipelinePluginInfo"/> to remove.</param>
        public void DeleteTempPipelinePlugin(PipelinePluginInfo pluginInfo)
        {
            Debug.Assert(pluginInfo != null);

            try {
                userTempPipelinePluginsKey.DeleteSubKeyTree(pluginInfo.Id.ToString("B"));
            } catch (ArgumentException) {
                // The subkey did not exist, so no need to "remove" it.
            }
        }
        /// <summary>
        /// Private constructor called via <see cref="EditPlugin"/>.
        /// </summary>
        /// <param name="owner">Owner to use for new forms. Can be <c>null</c>.</param>
        /// <param name="oldInfo">Info about pipeline plugin to edit. If <c>null</c>,
        /// a new pipeline plugin will be edited.</param>
        private PipelinePluginEditor(IWin32Window owner, PipelinePluginInfo oldInfo)
        {
            // Save owner for any form we create.
            this.owner = owner;

            // Save old plugin info if we have one.
            pluginInfo = oldInfo;

            // If a plugin info was specified, decode its pipeline immediately.
            // We want pipeline exceptions to propagate out *before* we show a form.
            if (pluginInfo != null)
            {
                pipeline = PipelineDecoder.DecodePipeline(pluginInfo.EncodedElements);
            }
        }
示例#9
0
        /// <summary>
        /// Adds all pipeline plugins to the given list, in display order if possible.
        /// </summary>
        /// <param name="plugins">List where to add plugins</param>
        /// <param name="settings"><see cref="UserSettings"/> used to fetch
        /// pipeline plugins.</param>
        private static void GetPipelinePlugins(List <Plugin> plugins, UserSettings settings)
        {
            Debug.Assert(plugins != null);
            Debug.Assert(plugins != null);

            List <PipelinePluginInfo> pluginInfos = settings.PipelinePlugins;

            if (pluginInfos.Count > 0)
            {
                if (plugins.Count > 0)
                {
                    plugins.Add(new SeparatorPlugin());
                }
                plugins.AddRange(PipelinePluginInfo.ToPlugins(pluginInfos));
            }
        }
        /// <summary>
        /// Updates <see cref="newPluginInfo"/> with the contents of the
        /// form's controls. Also updates the preview box.
        /// </summary>
        private void UpdatePluginInfo()
        {
            // Create new pipeline and copy elements back from the binding list.
            Pipeline pipeline = new Pipeline();

            pipeline.Elements.AddRange(elements);

            // Create new plugin info and save encoded elements.
            PipelinePluginInfo pluginInfo = new PipelinePluginInfo {
                Id              = pluginId,
                Description     = NameTxt.Text,
                EncodedElements = pipeline.Encode(),
                RequiredVersion = pipeline.RequiredVersion,
                EditMode        = PipelinePluginEditMode.Expert,
            };

            Debug.Assert(!pluginInfo.Global);

            // Save plugin info and pipeline, then update preview and min version.
            newPluginInfo      = pluginInfo;
            newPipeline        = pipeline;
            PreviewCtrl.Plugin = newPluginInfo.ToPlugin();
            Version requiredVersion = newPipeline.RequiredVersion;
            int     numComponents;

            if (requiredVersion.Revision > 0)
            {
                numComponents = 4;
            }
            else if (requiredVersion.Build > 0)
            {
                numComponents = 3;
            }
            else
            {
                numComponents = 2;
            }
            MinVersionLbl.Text = string.Format(CultureInfo.CurrentCulture,
                                               MinVersionLbl.Tag as string, requiredVersion.ToString(numComponents));
        }
        /// <summary>
        /// Updates <see cref="newPluginInfo"/> with the contents of the
        /// form's controls. Also updates the preview box.
        /// </summary>
        private void UpdatePluginInfo()
        {
            // Create new pipeline and copy elements back from the binding list.
            Pipeline pipeline = new Pipeline();

            pipeline.Elements.AddRange(elements);

            // Create new plugin info and save encoded elements.
            PipelinePluginInfo pluginInfo = new PipelinePluginInfo();

            pluginInfo.Id              = pluginId;
            pluginInfo.Description     = NameTxt.Text;
            pluginInfo.EncodedElements = pipeline.Encode();
            pluginInfo.RequiredVersion = pipeline.RequiredVersion;
            pluginInfo.EditMode        = PipelinePluginEditMode.Expert;
            Debug.Assert(!pluginInfo.Global);

            // Save plugin info and pipeline, then update preview.
            newPluginInfo      = pluginInfo;
            newPipeline        = pipeline;
            PreviewCtrl.Plugin = newPluginInfo.ToPlugin();
        }
示例#12
0
        /// <summary>
        /// Main method to use the form. Will show the form as a modal dialog,
        /// allowing the user to edit the given pipeline plugin. When the user
        /// is done, the method will return the new <see cref="PipelinePluginInfo"/>
        /// if the user accepted the changes.
        /// </summary>
        /// <param name="owner">Owner of this dialog. Can be <c>null</c>.</param>
        /// <param name="settings">Object to access user settings. If <c>null</c>,
        /// a new <see cref="UserSettings"/> object will be created.</param>
        /// <param name="oldInfo">Info about a pipeline plugin. If set, we'll
        /// populate the form with the plugin's values to allow the user to
        /// edit the plugin.</param>
        /// <returns>Info about the new plugin that user edited. Will be
        /// <c>null</c> if user cancels editing.</returns>
        public PipelinePluginInfo EditPlugin(IWin32Window owner,
                                             UserSettings settings, PipelinePluginInfo oldInfo)
        {
            // Save settings object or create one if we didn't get one.
            this.settings = settings ?? new UserSettings();

            // Save old info so that the OnLoad event handler can use it.
            pluginInfo = oldInfo;

            // If a plugin info was specified, decode its pipeline immediately.
            // We want pipeline exceptions to propagate out *before* we show the form.
            if (pluginInfo != null)
            {
                pipeline = PipelineDecoder.DecodePipeline(pluginInfo.EncodedElements);
            }

            // Show the form and check result.
            DialogResult dialogRes = ShowDialog(owner);

            // If user saved, return the new info.
            Debug.Assert(dialogRes != DialogResult.OK || pluginInfo != null);
            return(dialogRes == DialogResult.OK ? pluginInfo : null);
        }
示例#13
0
 /// <summary>
 /// Adds a temp pipeline plugin, saving it to the registry.
 /// </summary>
 /// <param name="pluginInfo">Plugin info for the pipeline
 /// plugin to save.</param>
 public void Add(PipelinePluginInfo pluginInfo)
 {
     // If we already have this plugin, destroy it, then add it again.
     Remove(pluginInfo);
     tempPipelinePluginSavers.Add(new TempPipelinePluginSaver(pluginInfo, settings));
 }
示例#14
0
        /// <summary>
        /// Updates <see cref="newPluginInfo"/> with the contents of the
        /// form's controls. Also updates the preview box.
        /// </summary>
        private void UpdatePluginInfo()
        {
            // Create a pipeline based on form controls.
            Pipeline pipeline = new Pipeline();

            if (LaunchExecutableChk.Checked)
            {
                if (WithFilelistChk.Checked)
                {
                    pipeline.Elements.Add(new ExecutableWithFilelistPipelineElement(ExecutableTxt.Text));
                }
                else
                {
                    pipeline.Elements.Add(new ExecutablePipelineElement(ExecutableTxt.Text));
                }
            }
            if (CopyOnSameLineChk.Enabled)
            {
                if (CopyOnSameLineChk.Checked)
                {
                    pipeline.Elements.Add(new PathsSeparatorPipelineElement(PipelinePluginEditor.PATHS_SEPARATOR_ON_SAME_LINE));
                }
            }
            else
            {
                // Copy non-standard value we had earlier
                Debug.Assert(!String.IsNullOrEmpty(oldPathsSeparator));
                pipeline.Elements.Add(new PathsSeparatorPipelineElement(oldPathsSeparator));
            }
            if (BasePluginLst.SelectedIndex != -1)
            {
                pipeline.Elements.Add(new ApplyPluginPipelineElement(
                                          ((Plugin)BasePluginLst.SelectedItem).Id));
            }
            if (FindTxt.Text.Length > 0)
            {
                if (UseRegexChk.Checked)
                {
                    pipeline.Elements.Add(new RegexPipelineElement(FindTxt.Text, ReplaceTxt.Text, IgnoreCaseChk.Checked));
                }
                else
                {
                    pipeline.Elements.Add(new FindReplacePipelineElement(FindTxt.Text, ReplaceTxt.Text));
                }
            }
            if (BackToForwardSlashesRadio.Checked)
            {
                pipeline.Elements.Add(new BackToForwardSlashesPipelineElement());
            }
            else if (ForwardToBackslashesRadio.Checked)
            {
                pipeline.Elements.Add(new ForwardToBackslashesPipelineElement());
            }
            if (RemoveExtChk.Checked)
            {
                pipeline.Elements.Add(new RemoveExtPipelineElement());
            }
            if (OptionalQuotesChk.Checked)
            {
                pipeline.Elements.Add(new OptionalQuotesPipelineElement());
            }
            else if (QuotesChk.Checked)
            {
                pipeline.Elements.Add(new QuotesPipelineElement());
            }
            if (EmailLinksChk.Checked)
            {
                pipeline.Elements.Add(new EmailLinksPipelineElement());
            }
            if (EncodeURIWhitespaceChk.Checked)
            {
                if (EncodeURICharsChk.Enabled && EncodeURICharsChk.Checked)
                {
                    pipeline.Elements.Add(new EncodeURICharsPipelineElement());
                }
                else
                {
                    pipeline.Elements.Add(new EncodeURIWhitespacePipelineElement());
                }
            }

            // Create new plugin info and save encoded elements.
            PipelinePluginInfo pluginInfo = new PipelinePluginInfo();

            pluginInfo.Id              = pluginId;
            pluginInfo.Description     = NameTxt.Text;
            pluginInfo.EncodedElements = pipeline.Encode();
            pluginInfo.RequiredVersion = pipeline.RequiredVersion;
            pluginInfo.EditMode        = PipelinePluginEditMode.Simple;
            Debug.Assert(!pluginInfo.Global);

            // Save plugin info in newPluginInfo and update preview.
            newPluginInfo      = pluginInfo;
            PreviewCtrl.Plugin = newPluginInfo.ToPlugin();
        }
        /// <summary>
        /// Edits a new or existing pipeline plugin.
        /// </summary>
        /// <param name="owner">Owner to use for new forms. Can be <c>null</c>.</param>
        /// <param name="oldInfo">Info about pipeline plugin to edit. If <c>null</c>,
        /// a new pipeline plugin will be edited.</param>
        /// <returns>Info about pipeline plugin edited. Will be <c>null</c> if the
        /// user cancelled the editing.</returns>
        public static PipelinePluginInfo EditPlugin(IWin32Window owner, PipelinePluginInfo oldInfo)
        {
            PipelinePluginEditor editor = new PipelinePluginEditor(owner, oldInfo);

            return(editor.Edit());
        }
示例#16
0
        /// <summary>
        /// Called when the form is about to close. If user pressed OK, we save
        /// the content of the plugin here.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void PipelinePluginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // If user chose to press OK, save plugin info.
            if (this.DialogResult == DialogResult.OK)
            {
                // Make sure user has entered a name.
                if (!String.IsNullOrEmpty(NameTxt.Text))
                {
                    // Create a pipeline based on form controls.
                    if (pipeline == null)
                    {
                        pipeline = new Pipeline();
                    }
                    else
                    {
                        pipeline.Clear();
                    }
                    if (CopyOnSameLineChk.Enabled)
                    {
                        if (CopyOnSameLineChk.Checked)
                        {
                            pipeline.Elements.Add(new PathsSeparatorPipelineElement(PATHS_SEPARATOR_ON_SAME_LINE));
                        }
                    }
                    else
                    {
                        // Copy non-standard value we had earlier
                        Debug.Assert(!String.IsNullOrEmpty(pathsSeparator));
                        pipeline.Elements.Add(new PathsSeparatorPipelineElement(pathsSeparator));
                    }
                    if (BasePluginLst.SelectedIndex != -1)
                    {
                        pipeline.Elements.Add(new ApplyPluginPipelineElement(
                                                  ((Plugin)BasePluginLst.SelectedItem).Id));
                    }
                    if (FindTxt.Text.Length > 0)
                    {
                        if (UseRegexChk.Checked)
                        {
                            pipeline.Elements.Add(new RegexPipelineElement(FindTxt.Text, ReplaceTxt.Text, IgnoreCaseChk.Checked));
                        }
                        else
                        {
                            pipeline.Elements.Add(new FindReplacePipelineElement(FindTxt.Text, ReplaceTxt.Text));
                        }
                    }
                    if (BackToForwardSlashesRadio.Checked)
                    {
                        pipeline.Elements.Add(new BackToForwardSlashesPipelineElement());
                    }
                    else if (ForwardToBackslashesRadio.Checked)
                    {
                        pipeline.Elements.Add(new ForwardToBackslashesPipelineElement());
                    }
                    if (QuotesChk.Checked)
                    {
                        pipeline.Elements.Add(new QuotesPipelineElement());
                    }
                    if (EmailLinksChk.Checked)
                    {
                        pipeline.Elements.Add(new EmailLinksPipelineElement());
                    }
                    if (EncodeURIWhitespaceChk.Checked)
                    {
                        if (EncodeURICharsChk.Enabled && EncodeURICharsChk.Checked)
                        {
                            pipeline.Elements.Add(new EncodeURICharsPipelineElement());
                        }
                        else
                        {
                            pipeline.Elements.Add(new EncodeURIWhitespacePipelineElement());
                        }
                    }

                    // Create plugin info if we don't already have one.
                    if (pluginInfo == null)
                    {
                        pluginInfo    = new PipelinePluginInfo();
                        pluginInfo.Id = Guid.NewGuid();
                    }

                    // Save info in plugin info wrapper.
                    pluginInfo.Description     = NameTxt.Text;
                    pluginInfo.EncodedElements = pipeline.Encode();
                    pluginInfo.RequiredVersion = pipeline.RequiredVersion;
                    Debug.Assert(!pluginInfo.Global);
                }
                else
                {
                    // Warn user that we need a non-empty name.
                    MessageBox.Show(Resources.PipelinePluginForm_EmptyName, Resources.PipelinePluginForm_MsgTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    NameTxt.Focus();
                    e.Cancel = true;
                }
            }
        }