Esempio n. 1
0
        /// <inheritdoc />
        /// <returns>A comma-separated list of recognized syntax filter IDs</returns>
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           CultureInfo culture, object value)
        {
            if (value is string)
            {
                string filterIds      = value.ToString();
                var    allFilters     = BuildComponentManager.SyntaxFiltersFrom("All");
                var    definedFilters = BuildComponentManager.SyntaxFiltersFrom(filterIds);

                // Convert to None, All, AllButUsage, or Standard?  If not,
                // then convert to the list of defined filters that we know
                // about.
                if (definedFilters.Count == 0)
                {
                    filterIds = "None";
                }
                else
                if (definedFilters.Count == allFilters.Count)
                {
                    filterIds = "All";
                }
                else
                if (definedFilters.Count == allFilters.Count(
                        af => af.Id.IndexOf("usage", StringComparison.OrdinalIgnoreCase) == -1))
                {
                    filterIds = "AllButUsage";
                }
                else
                if (definedFilters.Count == 3 && (definedFilters.All(df => df.Id == "CSharp" ||
                                                                     df.Id == "VisualBasic" || df.Id == "CPlusPlus")))
                {
                    filterIds = "Standard";
                }
                else
                {
                    filterIds = String.Join(", ", definedFilters.Select(f => f.Id).ToArray());
                }

                return(filterIds);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Esempio n. 2
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            Collection <SyntaxFilterInfo> allFilters, definedFilters;
            IWindowsFormsEditorService    editorService;
            CheckedListBox ckbListBox;
            string         filterIds;

            // Only use the editor if we have a valid context
            if (context == null || provider == null || context.Instance == null ||
                value == null)
            {
                return(base.EditValue(context, provider, value));
            }

            editorService = (IWindowsFormsEditorService)provider.GetService(
                typeof(IWindowsFormsEditorService));

            if (editorService == null)
            {
                return(base.EditValue(context, provider, value));
            }

            allFilters     = BuildComponentManager.SyntaxFiltersFrom("All");
            definedFilters = BuildComponentManager.SyntaxFiltersFrom(value.ToString());

            using (ckbListBox = new CheckedListBox())
            {
                ckbListBox.BorderStyle  = BorderStyle.None;
                ckbListBox.CheckOnClick = true;

                // Tahoma 8pt prevents it from clipping the bottom of each item
                ckbListBox.Font = new Font("Tahoma", 8.0f);

                // Load the values into the checked list box
                foreach (SyntaxFilterInfo info in allFilters)
                {
                    ckbListBox.Items.Add(info.Id, definedFilters.Contains(info));
                }

                // Adjust the height of the list box to show all items or
                // at most twelve of them.
                if (ckbListBox.Items.Count < 12)
                {
                    ckbListBox.Height = ckbListBox.Items.Count *
                                        ckbListBox.ItemHeight;
                }
                else
                {
                    ckbListBox.Height = ckbListBox.Items.Count * 12;
                }

                // Display it and let the user edit the value
                editorService.DropDownControl(ckbListBox);

                // Get the selected syntax filter ID values and return them
                // as a comma-separated string.  This also checks for common
                // short-hand values and uses them if appropriate.
                if (ckbListBox.CheckedItems.Count == 0)
                {
                    value = "None";
                }
                else
                {
                    filterIds      = String.Join(", ", ckbListBox.CheckedItems.Cast <string>().ToArray());
                    definedFilters = BuildComponentManager.SyntaxFiltersFrom(filterIds);

                    // Convert to All, AllButUsage, or Standard?
                    if (definedFilters.Count == allFilters.Count)
                    {
                        filterIds = "All";
                    }
                    else
                    if (definedFilters.Count == allFilters.Count(
                            af => af.Id.IndexOf("usage", StringComparison.OrdinalIgnoreCase) == -1))
                    {
                        filterIds = "AllButUsage";
                    }
                    else
                    if (definedFilters.Count == 3 && (definedFilters.All(f => f.Id == "CSharp" ||
                                                                         f.Id == "VisualBasic" || f.Id == "CPlusPlus")))
                    {
                        filterIds = "Standard";
                    }

                    value = filterIds;
                }
            }

            return(value);
        }
Esempio n. 3
0
        /// <summary>
        /// Edit the selected build component's project configuration
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnConfigure_Click(object sender, EventArgs e)
        {
            BuildComponentConfiguration componentConfig;
            string newConfig, currentConfig, assembly,
                   key = (string)lbProjectComponents.SelectedItem;

            BuildComponentInfo info = BuildComponentManager.BuildComponents[key];

            componentConfig = currentConfigs[key];
            currentConfig   = componentConfig.Configuration;

            // If it doesn't have a configuration method, use the default
            // configuration editor.
            if (String.IsNullOrEmpty(info.ConfigureMethod))
            {
                using (ConfigurationEditorDlg dlg = new ConfigurationEditorDlg())
                {
                    dlg.Configuration = currentConfig;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        // Only store it if new or if it changed
                        newConfig = dlg.Configuration;

                        if (currentConfig != newConfig)
                        {
                            componentConfig.Configuration = newConfig;
                        }
                    }
                }

                return;
            }

            // Don't allow editing if set to "-"
            if (info.ConfigureMethod == "-")
            {
                MessageBox.Show("The selected component contains no " +
                                "editable configuration information",
                                Constants.AppName, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            try
            {
                // Change into the component's folder so that it has a
                // better chance of finding all of its dependencies.
                assembly = BuildComponentManager.ResolveComponentPath(
                    info.AssemblyPath);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                                  Path.GetFullPath(assembly)));

                // The exception is BuildAssemblerLibrary.dll which is in
                // the Sandcastle installation folder.  We'll have to resolve
                // that one manually.
                AppDomain.CurrentDomain.AssemblyResolve +=
                    new ResolveEventHandler(CurrentDomain_AssemblyResolve);

                // Load the type and get a reference to the static
                // configuration method.
                Assembly   asm       = Assembly.LoadFrom(assembly);
                Type       component = asm.GetType(info.TypeName);
                MethodInfo mi        = null;

                if (component != null)
                {
                    mi = component.GetMethod(info.ConfigureMethod,
                                             BindingFlags.Public | BindingFlags.Static);
                }

                if (component != null && mi != null)
                {
                    // Invoke the method to let it configure the settings
                    newConfig = (string)mi.Invoke(null, new object[] {
                        currentConfig
                    });

                    // Only store it if new or if it changed
                    if (currentConfig != newConfig)
                    {
                        componentConfig.Configuration = newConfig;
                    }
                }
                else
                {
                    MessageBox.Show(String.Format(CultureInfo.InvariantCulture,
                                                  "Unable to locate the '{0}' method in component " +
                                                  "'{1}' in assembly {2}", info.ConfigureMethod,
                                                  info.TypeName, assembly), Constants.AppName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (IOException ioEx)
            {
                System.Diagnostics.Debug.WriteLine(ioEx.ToString());
                MessageBox.Show(String.Format(CultureInfo.InvariantCulture,
                                              "A file access error occurred trying to configure the " +
                                              "component '{0}'.  Error: {1}", info.TypeName, ioEx.Message),
                                Constants.AppName, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                MessageBox.Show(String.Format(CultureInfo.InvariantCulture,
                                              "An error occurred trying to configure the component " +
                                              "'{0}'.  Error: {1}", info.TypeName, ex.Message),
                                Constants.AppName, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -=
                    new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }