Esempio n. 1
0
        /// <summary>
        /// Called when the control is initially loaded. We populate our controls here.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // First load list of plugins to display in the listbox for the base
            // plugin. We only load default and COM plugins for this since we
            // don't want a pipeline plugin to be based off another (for now at least).
            List <Plugin> plugins;

            using (UserSettings settings = new UserSettings()) {
                plugins = PluginsRegistry.GetPluginsInDefaultOrder(settings, false);
            }

            // Add all plugins to the list box.
            BasePluginLst.Items.AddRange(plugins.ToArray());

            // Validate base plugin ID.
            Guid?basePluginId = element.PluginID;

            if (plugins.Find(pl => pl.Id == basePluginId) == null)
            {
                // Invalid, clear it so that we'll fall back
                // on the default below.
                basePluginId = null;
            }

            // If we didn't find a base plugin ID yet, use the "Long Path" plugin ID.
            if (basePluginId == null)
            {
                basePluginId = new Guid(Resources.LONG_PATH_PLUGIN_ID);
            }

            // Scan list of plugins to select the base plugin.
            for (int i = 0; i < BasePluginLst.Items.Count; ++i)
            {
                if (!(BasePluginLst.Items[i] is SeparatorPlugin) &&
                    ((Plugin)BasePluginLst.Items[i]).Id == basePluginId)
                {
                    // This is the default plugin, select it and break.
                    BasePluginLst.SelectedIndex = i;
                    break;
                }
            }
            Debug.Assert(BasePluginLst.SelectedIndex != -1);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the form is loaded. We use this opportunity to populate
        /// the controls with info about a plugin we're editing, if we have one.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void PipelinePluginForm_Load(object sender, EventArgs e)
        {
            // First load list of plugins to display in the listbox for the base
            // plugin. We only load default and COM plugins for this since we
            // don't want a pipeline plugin to be based off another (for now at least).
            List <Plugin> plugins = PluginsRegistry.GetPluginsInDefaultOrder(Settings, false);

            // Add all plugins to the list box.
            BasePluginLst.Items.AddRange(plugins.ToArray());

            // Check if we have a plugin info to load.
            Guid?basePluginId = null;

            if (oldPluginInfo != null)
            {
                Debug.Assert(oldPipeline != null);

                // Populate our controls.
                NameTxt.Text = oldPluginInfo.Description;
                PipelineElement element = oldPipeline.Elements.Find(el => el is ApplyPluginPipelineElement);
                if (element != null)
                {
                    basePluginId = ((ApplyPluginPipelineElement)element).PluginID;
                }
                if (oldPipeline.Elements.Find(el => el is OptionalQuotesPipelineElement) != null)
                {
                    QuotesChk.Checked         = true;
                    OptionalQuotesChk.Checked = true;
                }
                else if (oldPipeline.Elements.Find(el => el is QuotesPipelineElement) != null)
                {
                    QuotesChk.Checked = true;
                }
                EmailLinksChk.Checked = oldPipeline.Elements.Find(el => el is EmailLinksPipelineElement) != null;
                if (oldPipeline.Elements.Find(el => el is EncodeURICharsPipelineElement) != null)
                {
                    EncodeURIWhitespaceChk.Checked = true;
                    EncodeURICharsChk.Checked      = true;
                }
                else if (oldPipeline.Elements.Find(el => el is EncodeURIWhitespacePipelineElement) != null)
                {
                    EncodeURIWhitespaceChk.Checked = true;
                }
                RemoveExtChk.Checked = oldPipeline.Elements.Find(el => el is RemoveExtPipelineElement) != null;
                if (oldPipeline.Elements.Find(el => el is BackToForwardSlashesPipelineElement) != null)
                {
                    BackToForwardSlashesRadio.Checked = true;
                }
                else if (oldPipeline.Elements.Find(el => el is ForwardToBackslashesPipelineElement) != null)
                {
                    ForwardToBackslashesRadio.Checked = true;
                }
                else
                {
                    Debug.Assert(NoSlashesChangeRadio.Checked);
                }
                element = oldPipeline.Elements.Find(el => el is RegexPipelineElement);
                if (element != null)
                {
                    UseRegexChk.Checked   = true;
                    IgnoreCaseChk.Enabled = true;
                    TestRegexBtn.Enabled  = true;
                    RegexPipelineElement regexElement = (RegexPipelineElement)element;
                    FindTxt.Text          = regexElement.Regex;
                    ReplaceTxt.Text       = regexElement.Format;
                    IgnoreCaseChk.Checked = regexElement.IgnoreCase;
                }
                else
                {
                    Debug.Assert(!IgnoreCaseChk.Enabled);
                    Debug.Assert(!TestRegexBtn.Enabled);
                    element = oldPipeline.Elements.Find(el => el is FindReplacePipelineElement);
                    if (element != null)
                    {
                        FindTxt.Text    = ((FindReplacePipelineElement)element).OldValue;
                        ReplaceTxt.Text = ((FindReplacePipelineElement)element).NewValue;
                    }
                }

                // "Copy on same line" is a little special since it could be any string.
                element           = oldPipeline.Elements.Find(el => el is PathsSeparatorPipelineElement);
                oldPathsSeparator = (element as PathsSeparatorPipelineElement)?.PathsSeparator;
                if (oldPathsSeparator == PipelinePluginEditor.PATHS_SEPARATOR_ON_SAME_LINE)
                {
                    CopyOnSameLineChk.Checked = true;
                }
                else if (!String.IsNullOrEmpty(oldPathsSeparator))
                {
                    CopyOnSameLineChk.Enabled = false;
                }

                element = oldPipeline.Elements.Find(el => el is ExecutablePipelineElement);
                if (element != null)
                {
                    LaunchExecutableChk.Checked = true;
                    ExecutableTxt.Text          = ((ExecutablePipelineElement)element).Executable;
                }
                else
                {
                    element = oldPipeline.Elements.Find(el => el is ExecutableWithFilelistPipelineElement);
                    if (element != null)
                    {
                        LaunchExecutableChk.Checked = true;
                        WithFilelistChk.Checked     = true;
                        ExecutableTxt.Text          = ((ExecutableWithFilelistPipelineElement)element).Executable;
                    }
                    else
                    {
                        Debug.Assert(!ExecutableLbl.Enabled);
                        Debug.Assert(!ExecutableTxt.Enabled);
                        Debug.Assert(!BrowserForExecutableBtn.Enabled);
                    }
                }
            }

            // Validate base plugin ID if found.
            if (basePluginId != null)
            {
                if (plugins.Find(pl => pl.Id == basePluginId) == null)
                {
                    // Invalid, clear it so that we'll fall back
                    // on the default below.
                    basePluginId = null;
                }
            }

            // If we didn't find a base plugin ID yet, use the "Long Path" plugin ID.
            if (basePluginId == null)
            {
                basePluginId = new Guid(Resources.LONG_PATH_PLUGIN_ID);
            }

            // Scan list of plugins to select the base plugin.
            for (int i = 0; i < BasePluginLst.Items.Count; ++i)
            {
                if (!(BasePluginLst.Items[i] is SeparatorPlugin) &&
                    ((Plugin)BasePluginLst.Items[i]).Id == basePluginId)
                {
                    // This is the default plugin, select it and break.
                    BasePluginLst.SelectedIndex = i;
                    break;
                }
            }
            Debug.Assert(BasePluginLst.SelectedIndex != -1);

            // Immediately update plugin info so that preview box is initially filled.
            UpdatePluginInfo();
        }
Esempio n. 3
0
        /// <summary>
        /// Called when the control is initially loaded. We populate our controls here.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // First load list of plugins to display in the listbox for the base plugin.
            List <Plugin> plugins;

            using (UserSettings settings = new UserSettings()) {
                // If we're instructed to include pipeline plugins, we actually want *temp*
                // pipeline plugins saved by the MainForm, in order to get the most recent
                // snapshot of pipeline plugins.
                var pipelinePluginsOptions = includePipelinePlugins
                    ? PipelinePluginsOptions.FetchTempPipelinePlugins : PipelinePluginsOptions.FetchNone;
                List <Plugin> pluginsInDefaultOrder = PluginsRegistry.GetPluginsInDefaultOrder(settings, pipelinePluginsOptions);
                if (!includePipelinePlugins)
                {
                    // Sufficient when not using pipeline plugins.
                    plugins = pluginsInDefaultOrder;
                }
                else
                {
                    // Create sorted dictionary of all plugins from the list above, to be able to perform lookups.
                    SortedDictionary <Guid, Plugin> dictionaryOfAllPlugins = new SortedDictionary <Guid, Plugin>();
                    foreach (Plugin plugin in pluginsInDefaultOrder)
                    {
                        if (!dictionaryOfAllPlugins.ContainsKey(plugin.Id))
                        {
                            dictionaryOfAllPlugins.Add(plugin.Id, plugin);
                        }
                    }

                    // Use UI display order from settings to order the plugins.
                    // (See MainForm.LoadSettings for some more details on this process)
                    List <Guid> uiDisplayOrder = settings.UIDisplayOrder;
                    if (uiDisplayOrder == null)
                    {
                        // No display order, just use all plugins in default order
                        uiDisplayOrder = pluginsInDefaultOrder.Select(plugin => plugin.Id).ToList();
                    }
                    SortedSet <Guid> uiDisplayOrderAsSet = new SortedSet <Guid>(uiDisplayOrder);
                    plugins = PluginsRegistry.OrderPluginsToDisplay(dictionaryOfAllPlugins,
                                                                    uiDisplayOrder, uiDisplayOrderAsSet, pluginsInDefaultOrder);
                }
            }

            // Add all plugins to the list box.
            BasePluginLst.Items.AddRange(plugins.ToArray());

            // Validate base plugin ID.
            Guid?basePluginId = element.PluginID;

            if (plugins.Find(pl => pl.Id == basePluginId) == null)
            {
                // Invalid, clear it so that we'll fall back
                // on the default below.
                basePluginId = null;
            }

            // If we didn't find a base plugin ID yet, use the "Long Path" plugin ID.
            if (basePluginId == null)
            {
                basePluginId = new Guid(Resources.LONG_PATH_PLUGIN_ID);
            }

            // Scan list of plugins to select the base plugin.
            for (int i = 0; i < BasePluginLst.Items.Count; ++i)
            {
                if (!(BasePluginLst.Items[i] is SeparatorPlugin) &&
                    ((Plugin)BasePluginLst.Items[i]).Id == basePluginId)
                {
                    // This is the default plugin, select it and break.
                    BasePluginLst.SelectedIndex = i;
                    break;
                }
            }
            Debug.Assert(BasePluginLst.SelectedIndex != -1);
        }
        /// <summary>
        /// Called when the form is loaded. We use this opportunity to populate
        /// the controls with info about a plugin we're editing, if we have one.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void PipelinePluginForm_Load(object sender, EventArgs e)
        {
            // First load list of plugins in default order for the base plugin.
            // Note: we want *temp* pipeline plugins in order to use those saved by the MainForm,
            // in order to get the most recent snapshot of pipeline plugins.
            List <Plugin> pluginsInDefaultOrder = PluginsRegistry.GetPluginsInDefaultOrder(
                Settings, PipelinePluginsOptions.FetchTempPipelinePlugins);

            // Create sorted dictionary of all plugins from the list above, to be able to perform lookups.
            SortedDictionary <Guid, Plugin> dictionaryOfAllPlugins = new SortedDictionary <Guid, Plugin>();

            foreach (Plugin plugin in pluginsInDefaultOrder)
            {
                if (!dictionaryOfAllPlugins.ContainsKey(plugin.Id))
                {
                    dictionaryOfAllPlugins.Add(plugin.Id, plugin);
                }
            }

            // Use UI display order from settings to order the plugins.
            // (See MainForm.LoadSettings for some more details on this process)
            List <Guid> uiDisplayOrder = Settings.UIDisplayOrder;

            if (uiDisplayOrder == null)
            {
                // No display order, just use all plugins in default order
                uiDisplayOrder = pluginsInDefaultOrder.Select(plugin => plugin.Id).ToList();
            }
            SortedSet <Guid> uiDisplayOrderAsSet = new SortedSet <Guid>(uiDisplayOrder);
            List <Plugin>    plugins             = PluginsRegistry.OrderPluginsToDisplay(dictionaryOfAllPlugins,
                                                                                         uiDisplayOrder, uiDisplayOrderAsSet, pluginsInDefaultOrder);

            // Add all plugins to the list box.
            BasePluginLst.Items.AddRange(plugins.ToArray());

            // Check if we have a plugin info to load.
            Guid?basePluginId = null;

            if (oldPluginInfo != null)
            {
                Debug.Assert(oldPipeline != null);

                // Populate our controls.
                NameTxt.Text = oldPluginInfo.Description;
                PipelineElement element = oldPipeline.Elements.Find(el => el is PipelineElementWithPluginID);
                if (element != null)
                {
                    basePluginId = ((PipelineElementWithPluginID)element).PluginID;
                }
                if (oldPipeline.Elements.Find(el => el is OptionalQuotesPipelineElement) != null)
                {
                    QuotesChk.Checked         = true;
                    OptionalQuotesChk.Checked = true;
                }
                else if (oldPipeline.Elements.Find(el => el is QuotesPipelineElement) != null)
                {
                    QuotesChk.Checked = true;
                }
                EmailLinksChk.Checked = oldPipeline.Elements.Find(el => el is EmailLinksPipelineElement) != null;
                if (oldPipeline.Elements.Find(el => el is EncodeURICharsPipelineElement) != null)
                {
                    EncodeURIWhitespaceChk.Checked = true;
                    EncodeURICharsChk.Checked      = true;
                }
                else if (oldPipeline.Elements.Find(el => el is EncodeURIWhitespacePipelineElement) != null)
                {
                    EncodeURIWhitespaceChk.Checked = true;
                }
                RemoveExtChk.Checked = oldPipeline.Elements.Find(el => el is RemoveExtPipelineElement) != null;
                if (oldPipeline.Elements.Find(el => el is BackToForwardSlashesPipelineElement) != null)
                {
                    BackToForwardSlashesRadio.Checked = true;
                }
                else if (oldPipeline.Elements.Find(el => el is ForwardToBackslashesPipelineElement) != null)
                {
                    ForwardToBackslashesRadio.Checked = true;
                }
                else
                {
                    Debug.Assert(NoSlashesChangeRadio.Checked);
                }
                element = oldPipeline.Elements.Find(el => el is RegexPipelineElement);
                if (element != null)
                {
                    UseRegexChk.Checked   = true;
                    IgnoreCaseChk.Enabled = true;
                    TestRegexBtn.Enabled  = true;
                    RegexPipelineElement regexElement = (RegexPipelineElement)element;
                    FindTxt.Text          = regexElement.Regex;
                    ReplaceTxt.Text       = regexElement.Format;
                    IgnoreCaseChk.Checked = regexElement.IgnoreCase;
                }
                else
                {
                    Debug.Assert(!IgnoreCaseChk.Enabled);
                    Debug.Assert(!TestRegexBtn.Enabled);
                    element = oldPipeline.Elements.Find(el => el is FindReplacePipelineElement);
                    if (element != null)
                    {
                        FindTxt.Text    = ((FindReplacePipelineElement)element).OldValue;
                        ReplaceTxt.Text = ((FindReplacePipelineElement)element).NewValue;
                    }
                }
                if (oldPipeline.Elements.Find(el => el is UnexpandEnvironmentStringsPipelineElement) != null)
                {
                    UnexpandEnvStringsChk.Checked = true;
                }

                // "Copy on same line" is a little special since it could be any string.
                element           = oldPipeline.Elements.Find(el => el is PathsSeparatorPipelineElement);
                oldPathsSeparator = (element as PathsSeparatorPipelineElement)?.PathsSeparator;
                if (oldPathsSeparator == PipelinePluginEditor.PATHS_SEPARATOR_ON_SAME_LINE)
                {
                    CopyOnSameLineChk.Checked = true;
                }
                else if (!string.IsNullOrEmpty(oldPathsSeparator))
                {
                    CopyOnSameLineChk.Enabled = false;
                }

                RecursiveCopyChk.Checked = oldPipeline.Elements.Find(el => el is RecursiveCopyPipelineElement) != null;
                element = oldPipeline.Elements.Find(el => el is ExecutablePipelineElement);
                if (element != null)
                {
                    LaunchExecutableChk.Checked = true;
                    ExecutableTxt.Text          = ((ExecutablePipelineElement)element).Executable;
                }
                else
                {
                    element = oldPipeline.Elements.Find(el => el is ExecutableWithFilelistPipelineElement);
                    if (element != null)
                    {
                        LaunchExecutableChk.Checked = true;
                        WithFilelistChk.Checked     = true;
                        ExecutableTxt.Text          = ((ExecutableWithFilelistPipelineElement)element).Executable;
                    }
                    else
                    {
                        Debug.Assert(!ExecutableLbl.Enabled);
                        Debug.Assert(!ExecutableTxt.Enabled);
                        Debug.Assert(!BrowserForExecutableBtn.Enabled);
                    }
                }
            }

            // Validate base plugin ID if found.
            if (basePluginId != null)
            {
                if (plugins.Find(pl => pl.Id == basePluginId) == null)
                {
                    // Invalid, clear it so that we'll fall back
                    // on the default below.
                    basePluginId = null;
                }
            }

            // If we didn't find a base plugin ID yet, use the "Long Path" plugin ID.
            if (basePluginId == null)
            {
                basePluginId = new Guid(Resources.LONG_PATH_PLUGIN_ID);
            }

            // Scan list of plugins to select the base plugin.
            for (int i = 0; i < BasePluginLst.Items.Count; ++i)
            {
                if (!(BasePluginLst.Items[i] is SeparatorPlugin) &&
                    ((Plugin)BasePluginLst.Items[i]).Id == basePluginId)
                {
                    // This is the default plugin, select it and break.
                    BasePluginLst.SelectedIndex = i;
                    break;
                }
            }
            Debug.Assert(BasePluginLst.SelectedIndex != -1);

            // Immediately update plugin info so that preview box is initially filled.
            UpdatePluginInfo();
        }