Beispiel #1
0
 /// <summary>
 ///     Runs this instance.
 /// </summary>
 /// <remarks></remarks>
 public virtual void Run(RunMode mode)
 {
     if (_form == null)
     {
         _form = CreatePluginForm();
     }
     if (_form is Window)
     {
         if (mode == RunMode.Normal)
         {
             ((Window)_form).Show();
         }
         else
         {
             ((Window)_form).ShowDialog();
         }
         ((Window)_form).Activate();
     }
     if ((_form is Form))
     {
         if (mode == RunMode.Normal)
         {
             ((Form)_form).Show();
         }
         else
         {
             ((Form)_form).ShowDialog();
         }
         ((Form)_form).Activate();
     }
     PleaseWaitDialog.Close();
 }
Beispiel #2
0
        /// <summary>
        ///     Creates the plugin form.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        private IPluginForm CreatePluginForm()
        {
            IPluginForm f = CreatePluginFormInternal();

            //f.Plugin = this;
            ApplyThemes();
            //f.Closed += (s, e) =>
            //{
            //    _form = null;
            //};
            return(f);
        }
Beispiel #3
0
    public bool RequestOptions(IPluginForm optionForm)
    {
        PluginFormInfo info = _pluginFormLoader.FormToInfo(optionForm);

        var pluginDialog = new PluginDialog
        {
            DataContext = info,
            Owner       = Application.Current.MainWindow,
        };
        var result = pluginDialog.ShowDialog() == true;

        _pluginFormLoader.InfoToForm(info);
        return(result);
    }
Beispiel #4
0
 public bool Register(IPluginForm aPlugin)
 {
     return(true);
 }
Beispiel #5
0
    public PluginFormInfo FormToInfo(IPluginForm form)
    {
        Dictionary <string, PluginFormGroup> groups = new();

        foreach (var property in form.GetType().GetProperties())
        {
            var boolAttribute = property.GetCustomAttribute <BoolOptionAttribute>();
            if (boolAttribute != null && property.PropertyType == typeof(bool))
            {
                GetOrAdd(groups, boolAttribute.Group).Items.Add(new BoolPluginFormItem(
                                                                    member: property,
                                                                    displayName: boolAttribute.DisplayName,
                                                                    description: boolAttribute.Description,
                                                                    value: (bool)(property.GetValue(form))
                                                                    ));
                continue;
            }

            var intAttribute = property.GetCustomAttribute <IntOptionAttribute>();
            if (intAttribute != null && property.PropertyType == typeof(int))
            {
                GetOrAdd(groups, intAttribute.Group).Items.Add(new IntPluginFormItem(
                                                                   member: property,
                                                                   displayName: intAttribute.DisplayName,
                                                                   description: intAttribute.Description,
                                                                   value: (int)property.GetValue(form),
                                                                   minValue: intAttribute.MinimumValue,
                                                                   maxValue: intAttribute.MaximumValue
                                                                   ));
                continue;
            }

            var stringAttribute = property.GetCustomAttribute <StringOptionAttribute>();
            if (stringAttribute != null && property.PropertyType == typeof(string))
            {
                GetOrAdd(groups, stringAttribute.Group).Items.Add(new StringPluginFormItem(
                                                                      member: property,
                                                                      displayName: stringAttribute.DisplayName,
                                                                      description: stringAttribute.Description,
                                                                      value: property.GetValue(form) as string,
                                                                      maxLength: stringAttribute.MaxLength
                                                                      ));
                continue;
            }

            var comboAttribute = property.GetCustomAttribute <CollectionOptionAttribute>();
            if (comboAttribute != null)
            {
                ICollection values = comboAttribute.Mode switch
                {
                    CollectionOptionAttribute.ItemsSourceMode.Collection => comboAttribute.ItemsSource,
                    CollectionOptionAttribute.ItemsSourceMode.MemberName => form.GetType().GetProperty(comboAttribute.ItemsSourcePropertyName).GetValue(form) as ICollection,
                    _ => throw new System.Exception($"Invalid {typeof(CollectionOptionAttribute.ItemsSourceMode).FullName}"),
                };

                GetOrAdd(groups, comboAttribute.Group).Items.Add(new CollectionPluginFormItem(
                                                                     member: property,
                                                                     displayName: comboAttribute.DisplayName,
                                                                     description: comboAttribute.Description,
                                                                     value: property.GetValue(form),
                                                                     values: values
                                                                     ));
            }

            var textAttribute = property.GetCustomAttribute <TextAttribute>();
            if (textAttribute != null)
            {
                GetOrAdd(groups, textAttribute.Group).Items.Add(new TextPluginFormItem(
                                                                    Value: property.GetValue(form) as string
                                                                    ));
            }
        }

        if (groups.TryGetValue("", out var ungrouped))
        {
            return(new(form, ungrouped.Items, groups.Values.Where(i => i.GroupName != "").ToList()));
        }
        return(new(form, new(), groups.Values.ToList()));
    }