/// <summary> /// Populates the settings panel with the settings of a given plugin. /// </summary> /// <param name="plugin">The plugin whose settings to display</param> private void PopulateSettings(Plugin plugin) { SettingsGrid.RowDefinitions.Clear(); SettingsGrid.Children.Clear(); for (int i = 0; i < plugin.Settings.Count; i++) { Setting s = plugin.Settings[i]; // add row SettingsGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // create label TextBlock tb = new TextBlock() { Text = plugin.T(s.ID), Margin = new Thickness(5, 5, 10, 5), VerticalAlignment = VerticalAlignment.Center }; tb.SetBinding(TextBlock.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(tb, i); Grid.SetColumn(tb, 0); SettingsGrid.Children.Add(tb); FrameworkElement control = null; // create control if (s.Type == typeof(Boolean)) { // checkbox control = new CheckBox() { Height = 15 }; control.SetBinding(CheckBox.IsCheckedProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Color)) { // color selector control = new ColorPicker() { ShowAvailableColors = false, ShowStandardColors = true, Width = 50, }; if (s.PossibleValues != null) { ColorConverter converter = new ColorConverter(); ((ColorPicker)control).AvailableColors.Clear(); foreach (Color c in s.PossibleValues) { System.Windows.Media.Color color = (System.Windows.Media.Color)converter.Convert(c, null, null, null); ((ColorPicker)control).AvailableColors.Add(new ColorItem(color, c.Name)); } } control.SetBinding(ColorPicker.SelectedColorProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay, Converter = new ColorConverter() }); } else if (s.PossibleValues != null) { // dropdown control = new ComboBox(); foreach (Object val in s.PossibleValues) { try { String content = val.ToString(); if (s.Type == typeof(String)) content = plugin.T(val.ToString()); ((ComboBox)control).Items.Add(new ComboBoxItem { Content = content, Name = val.ToString() }); } catch (Exception exc) { U.L(LogLevel.Warning, "PLUGIN", "Could not add combobox item in plugin settings: " + exc.Message); } } ((ComboBox)control).SelectedValuePath = "Name"; control.SetBinding(ComboBox.SelectedValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(String)) { // text input control = new TextBox() { MaxWidth = 400, MinWidth = 250 }; control.SetBinding(TextBox.TextProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Int32)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Int32)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) ((Slider)control).Minimum = (Int32)s.Minimum; control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new IntegerUpDown(); control.SetBinding(IntegerUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } else if (s.Type == typeof(Double)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Double)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) ((Slider)control).Minimum = (Double)s.Minimum; control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new DoubleUpDown(); control.SetBinding(DoubleUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } if (control != null) { control.Margin = new Thickness(0, 5, 0, 5); control.VerticalAlignment = VerticalAlignment.Center; control.HorizontalAlignment = HorizontalAlignment.Left; control.SetBinding(FrameworkElement.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(control, i); Grid.SetColumn(control, 1); SettingsGrid.Children.Add(control); } } }
/// <summary> /// Populates the status label panel with the status labels of a given plugin. /// </summary> /// <param name="plugin">The plugin whose status labels to display</param> private void PopulateLabels(Plugin plugin) { StatusLabelGrid.RowDefinitions.Clear(); for (int i=0; i < 5; i++) StatusLabelGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); while (StatusLabelGrid.Children.Count > 10) StatusLabelGrid.Children.RemoveAt(10); PluginName.Text = plugin.T("Name"); PluginDescription.Text = plugin.T("Description"); PluginAuthor.Text = plugin.Author; PluginVersion.Text = plugin.Version.ToString(); PluginType.Text = U.T(plugin.Type); PluginEnabled.Click -= PluginEnabled_Click; PluginEnabled.IsChecked = PluginManager.IsActive(plugin); PluginEnabled.Click += PluginEnabled_Click; if (plugin.StatusLabels != null) for (int i = 0; i < plugin.StatusLabels.Count; i++) { StatusLabel s = plugin.StatusLabels[i]; // add row StatusLabelGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // create label TextBlock label = new TextBlock() { Text = plugin.T(s.Label), Margin = new Thickness(5, 5, 10, 5), VerticalAlignment = VerticalAlignment.Center }; Grid.SetRow(label, i + 5); Grid.SetColumn(label, 0); StatusLabelGrid.Children.Add(label); // create status TextBlock status = new TextBlock() { Text = plugin.T(s.Status), Margin = new Thickness(0, 5, 0, 5), VerticalAlignment = VerticalAlignment.Center }; Grid.SetRow(status, i + 5); Grid.SetColumn(status, 1); StatusLabelGrid.Children.Add(status); currentStatusLabels.Add(s, status); s.PropertyChanged += PluginStatus_PropertyChanged; } }