public OutputModeEditor()
        {
            this.Content = new StackLayout
            {
                Padding = 5,
                Spacing = 5,
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                Items =
                {
                    new StackLayoutItem(editorContainer,    true),
                    new StackLayoutItem(outputModeSelector, HorizontalAlignment.Left)
                }
            };

            absoluteModeEditor.SettingsBinding.Bind(ProfileBinding.Child(p => p.AbsoluteModeSettings));
            relativeModeEditor.SettingsBinding.Bind(ProfileBinding.Child(p => p.RelativeModeSettings));

            outputModeSelector.SelectedItemBinding.Convert <PluginSettingStore>(
                c => PluginSettingStore.FromPath(c?.FullName),
                v => v?.GetTypeInfo()
                ).Bind(ProfileBinding.Child(c => c.OutputMode));

            outputModeSelector.SelectedValueChanged += (sender, e) => UpdateOutputMode(Profile?.OutputMode);

            App.Driver.AddConnectionHook(i => i.TabletsChanged += (sender, e) => UpdateTablet(e));
            UpdateTablet();
        }
        public OutputModeEditor()
        {
            this.Content = new StackLayout
            {
                Padding = 5,
                Spacing = 5,
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                Items =
                {
                    new StackLayoutItem(editorContainer,    true),
                    new StackLayoutItem(outputModeSelector, HorizontalAlignment.Left)
                }
            };

            outputModeSelector.SelectedValueChanged += (sender, args) =>
            {
                if (outputModeSelector.SelectedType is TypeInfo type)
                {
                    this.Store = new PluginSettingStore(type);
                }
            };

            outputModeSelector.SelectedTypeBinding.Bind(
                StoreBinding.Convert <TypeInfo>(
                    c => c?.GetPluginReference().GetTypeReference(),
                    t => PluginSettingStore.FromPath(t.FullName)
                    )
                );
        }
Esempio n. 3
0
        private void UpdateOutputMode(PluginSettingStore store)
        {
            bool showNull     = true;
            bool showAbsolute = false;
            bool showRelative = false;

            if (store != null)
            {
                App.Settings.OutputMode = store;
                var outputMode = store.GetPluginReference().GetTypeReference <IOutputMode>();
                showAbsolute = outputMode.IsSubclassOf(typeof(AbsoluteOutputMode));
                showRelative = outputMode.IsSubclassOf(typeof(RelativeOutputMode));
                showNull     = !(showAbsolute | showRelative);
            }
            switch (DesktopInterop.CurrentPlatform)
            {
            case PluginPlatform.Linux:
                noModeEditor.Visible       = showNull;
                absoluteModeEditor.Visible = showAbsolute;
                relativeModeEditor.Visible = showRelative;
                break;

            default:
                SetVisibilityWorkaround(absoluteModeEditor, showAbsolute, 0);
                SetVisibilityWorkaround(relativeModeEditor, showRelative, 1);
                SetVisibilityWorkaround(noModeEditor, showNull, 2);
                break;
            }
        }
Esempio n. 4
0
            public BindingDisplay(PluginSettingStore store)
            {
                var bindingCommand = new Command();

                bindingCommand.Executed += async(sender, e) =>
                {
                    var dialog = new BindingEditorDialog(Binding);
                    this.Binding = await dialog.ShowModalAsync(this);
                };
                var advancedBindingCommand = new Command();

                advancedBindingCommand.Executed += async(sender, e) =>
                {
                    var dialog = new AdvancedBindingEditorDialog(Binding);
                    this.Binding = await dialog.ShowModalAsync(this);
                };

                mainButton = new Button
                {
                    Command = bindingCommand
                };
                advancedButton = new Button
                {
                    Command = advancedBindingCommand,
                    Text    = "...",
                    Width   = 25
                };

                Spacing     = 5;
                Orientation = Orientation.Horizontal;
                Items.Add(new StackLayoutItem(mainButton, true));
                Items.Add(advancedButton);

                this.Binding = store;
            }
        public static Control GetControlForProperty(PluginSettingStore store, PropertyInfo property)
        {
            var           attr    = property.GetCustomAttribute <PropertyAttribute>();
            PluginSetting setting = store[property];

            if (setting == null)
            {
                setting = new PluginSetting(property, null);
                store.Settings.Add(setting);
            }

            var settingBinding = new DelegateBinding <PluginSetting>(
                () => store[property],
                (v) => store[property] = v
                );

            var control = GetControlForSetting(property, settingBinding);

            if (control != null)
            {
                // Apply all visual modifier attributes
                foreach (ModifierAttribute modifierAttr in property.GetCustomAttributes <ModifierAttribute>())
                {
                    control = ApplyModifierAttribute(control, modifierAttr);
                }

                control.Width = 400;
                return(new Group(attr.DisplayName ?? property.Name, control, Orientation.Horizontal, false));
            }
            else
            {
                throw new NullReferenceException($"{nameof(control)} is null. This is likely due to {property.PropertyType.Name} being an unsupported type.");
            }
        }
Esempio n. 6
0
 public static void MigrateNamespace(PluginSettingStore store)
 {
     if (store != null)
     {
         store.Path = MigrateNamespace(store.Path);
     }
 }
Esempio n. 7
0
            private Control GetControlForProperty(PluginSettingStore store, PropertyInfo property)
            {
                var           attr    = property.GetCustomAttribute <PropertyAttribute>();
                PluginSetting setting = store[property];

                if (setting == null)
                {
                    setting = new PluginSetting(property, null);
                    store.Settings.Add(setting);
                }

                var control = GetControlForSetting(property, setting);

                if (control != null)
                {
                    // Apply all visual modifier attributes
                    foreach (ModifierAttribute modifierAttr in property.GetCustomAttributes <ModifierAttribute>())
                    {
                        control = ApplyModifierAttribute(control, modifierAttr);
                    }

                    return(new GroupBoxBase(
                               attr.DisplayName ?? property.Name,
                               control
                               ));
                }
                else
                {
                    throw new NullReferenceException($"{nameof(control)} is null. This is likely due to {property.PropertyType.Name} being an unsupported type.");
                }
            }
Esempio n. 8
0
        public static string GetFormattedBinding(PluginSettingStore store)
        {
            var pluginRef = store.GetPluginReference();
            var binding   = pluginRef.Construct <IBinding>();

            return($"{pluginRef.Name}: {binding.Property}");
        }
Esempio n. 9
0
        public OutputModeEditor()
        {
            UpdateOutputMode(App.Settings?.OutputMode);
            App.SettingsChanged += (settings) => UpdateOutputMode(settings?.OutputMode);

            outputModeSelector.SelectedModeChanged += (sender, pluginRef) =>
            {
                App.Settings.OutputMode = PluginSettingStore.FromPath(pluginRef.Path);
                UpdateOutputMode(App.Settings.OutputMode);
            };

            this.Content = outputPanel = new StackLayout
            {
                Padding = 5,
                Spacing = 5,
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                Items =
                {
                    new StackLayoutItem(absoluteModeEditor, true),
                    new StackLayoutItem(relativeModeEditor, true),
                    new StackLayoutItem(noModeEditor,       true),
                    new StackLayoutItem(outputModeSelector, HorizontalAlignment.Left, false)
                }
            };
        }
Esempio n. 10
0
 private static PluginSettingStore SafeMigrateNamespace(PluginSettingStore store, PluginSettingStore defaultStore = null)
 {
     MigrateNamespace(store);
     if ((store == null || PluginSettingStore.FromPath(store?.Path) == null) && defaultStore != null)
     {
         Log.Write("Settings", $"Invalid plugin path '{store?.Path ?? "null"}' has been changed to '{defaultStore.Path}'", LogLevel.Warning);
         store = defaultStore;
     }
     return(store);
 }
            protected override IEnumerable <Control> GetHeaderControlsForStore(PluginSettingStore store)
            {
                var enableButton = new CheckBox
                {
                    Text    = $"Enable {store.GetPluginReference().Name ?? store.Path}",
                    Checked = store.Enable
                };

                enableButton.CheckedChanged += (sender, e) => store.Enable = enableButton.Checked ?? false;
                yield return(enableButton);
            }
Esempio n. 12
0
            private string GetFriendlyDisplayString(PluginSettingStore store)
            {
                if (store == null || store["Property"] == null)
                {
                    return(null);
                }

                var property = store["Property"].GetValue <string>();
                var name     = store.GetPluginReference().Name;

                return($"{name}: {property}");
            }
Esempio n. 13
0
            private IEnumerable <Control> GetControlsForType(PluginSettingStore store, Type type)
            {
                var properties = from property in type.GetProperties()
                                 let attrs = property.GetCustomAttributes(true)
                                             where attrs.Any(a => a is PropertyAttribute)
                                             select property;

                foreach (var property in properties)
                {
                    yield return(GetControlForProperty(store, property));
                }
            }
Esempio n. 14
0
 private IEnumerable <Control> GetControlsForStore(PluginSettingStore store)
 {
     if (store != null)
     {
         var type = store.GetPluginReference().GetTypeReference <TSource>();
         return(GetControlsForType(store, type));
     }
     else
     {
         return(Array.Empty <Control>());
     }
 }
Esempio n. 15
0
            private string GetFriendlyDisplayString(PluginSettingStore store)
            {
                if (store == null)
                {
                    return(null);
                }

                var    name     = store.GetPluginReference().Name;
                string settings = string.Join(", ", store.Settings.Select(s => $"({s.Property}: {s.Value})"));

                return($"{name}: {settings}");
            }
Esempio n. 16
0
        public virtual void Refresh(PluginSettingStore store)
        {
            this.Items.Clear();

            foreach (var control in GetHeaderControlsForStore(store))
            {
                AddControl(control);
            }

            foreach (var control in GetControlsForStore(store))
            {
                this.Items.Add(control);
            }

            Store = store;
        }
Esempio n. 17
0
 private void UpdateSelectedStore(PluginReference reference)
 {
     if (CollectionReference.TryGetTarget(out PluginSettingStoreCollection storeCollection))
     {
         if (storeCollection.FirstOrDefault(store => store.Path == reference.Path) is PluginSettingStore store)
         {
             settingStoreEditor.Refresh(store);
         }
         else
         {
             var newStore = new PluginSettingStore(reference.GetTypeReference <TSource>(), false);
             storeCollection.Add(newStore);
             settingStoreEditor.Refresh(newStore);
         }
     }
 }
Esempio n. 18
0
            public void Refresh(PluginSettingStore store)
            {
                this.Items.Clear();

                var enableButton = new CheckBox
                {
                    Text    = $"Enable {store.GetPluginReference().Name ?? store.Path}",
                    Checked = store.Enable
                };

                enableButton.CheckedChanged += (sender, e) => store.Enable = enableButton.Checked ?? false;
                AddControl(enableButton);

                foreach (var control in GetControlsForStore(store))
                {
                    this.Items.Add(control);
                }
            }
Esempio n. 19
0
        public static string Format(this PluginSettingStore store)
        {
            if (store == null || !store.Enable)
            {
                return(null);
            }

            IList <string> storeSettings = new List <string>();

            foreach (var setting in store.Settings)
            {
                storeSettings.Add(setting.Format());
            }

            string prefix = store.Name ?? store.Path;
            string suffix = storeSettings.Count == 0 ? null : string.Join(", ", storeSettings);

            return(string.IsNullOrEmpty(suffix) ? $"'{prefix}'" : $"'{prefix}: {suffix}'");
        }
Esempio n. 20
0
        private Control ConstructOutputModeSelector()
        {
            var control = new OutputModeSelector
            {
                Width = 300
            };

            control.SelectedModeChanged += (sender, mode) =>
            {
                App.Settings.OutputMode = PluginSettingStore.FromPath(mode.Path);
                UpdateOutputMode(mode);
            };
            App.SettingsChanged += (settings) =>
            {
                var mode = control.OutputModes.FirstOrDefault(t => t.Path == App.Settings.OutputMode?.Path) ?? AppInfo.PluginManager.GetPluginReference(typeof(AbsoluteMode));
                if (mode != null)
                {
                    control.SelectedIndex = control.OutputModes.IndexOf(mode);
                }
            };
            return(control);
        }
Esempio n. 21
0
            public BindingDisplay(PluginSettingStore store)
            {
                this.Binding = store;

                var bindingCommand = new Command();

                bindingCommand.Executed += async(sender, e) =>
                {
                    var dialog = new BindingEditorDialog(Binding);
                    this.Binding = await dialog.ShowModalAsync(this);
                };
                this.Command = bindingCommand;

                this.MouseDown += async(s, e) =>
                {
                    if (e.Buttons.HasFlag(MouseButtons.Alternate))
                    {
                        var dialog = new AdvancedBindingEditorDialog(Binding);
                        this.Binding = await dialog.ShowModalAsync(this);
                    }
                };
            }
Esempio n. 22
0
        private void UpdateOutputMode(PluginSettingStore store)
        {
            bool showAbsolute = false;
            bool showRelative = false;

            if (store != null)
            {
                App.Settings.OutputMode = store;
                var outputMode = store.GetPluginReference().GetTypeReference <IOutputMode>();
                showAbsolute = outputMode.IsSubclassOf(typeof(AbsoluteOutputMode));
                showRelative = outputMode.IsSubclassOf(typeof(RelativeOutputMode));
            }

            if (showAbsolute)
            {
                outputModeEditor.Content = absoluteModeEditor;
            }
            else if (showRelative)
            {
                outputModeEditor.Content = relativeModeEditor;
            }
        }
Esempio n. 23
0
 protected virtual IEnumerable <Control> GetHeaderControlsForStore(PluginSettingStore store)
 {
     return(Array.Empty <Control>());
 }
Esempio n. 24
0
            private IEnumerable <Control> GetControlsForStore(PluginSettingStore store)
            {
                var type = store.GetPluginReference().GetTypeReference <TSource>();

                return(GetControlsForType(store, type));
            }
Esempio n. 25
0
            public void UpdateSelectedMode(PluginSettingStore store)
            {
                var typeReference = store?.GetPluginReference().GetTypeReference();

                this.SelectedValue = typeReference;
            }
 public StoredPluginReference(PluginManager pluginManager, PluginSettingStore store)
     : base(pluginManager, store.Path)
 {
     PluginSettings = store;
 }
Esempio n. 27
0
 public DemoBindingDisplay()
     : base(PluginSettingStore.FromPath(typeof(OpenTabletDriver.Plugin.IBinding).FullName))
 {
     Width = 256;
 }