private MenuBar ConstructMenu()
        {
            var quitCommand = new Command {
                MenuText = "Exit", Shortcut = Keys.Escape
            };

            quitCommand.Executed += (_, _) => this.Close();

            var install = new Command {
                MenuText = "Install plugin...", Shortcut = Application.Instance.CommonModifier | Keys.O
            };

            install.Executed += PromptInstallPlugin;

            var refresh = new Command {
                MenuText = "Refresh", Shortcut = Application.Instance.CommonModifier | Keys.R
            };

            refresh.Executed += async(_, _) => await Refresh();

            var alternateSource = new Command {
                MenuText = "Use alternate source..."
            };

            alternateSource.Executed += async(sender, e) => await SwitchRepositorySource();

            var pluginsDirectory = new Command {
                MenuText = "Open plugins directory..."
            };

            pluginsDirectory.Executed += (sender, e) => DesktopInterop.OpenFolder(AppInfo.Current.PluginDirectory);

            return(new MenuBar()
            {
                QuitItem = quitCommand,
                ApplicationItems =
                {
                    install,
                    refresh,
                    alternateSource,
                    pluginsDirectory
                }
            });
        }
                public LinkButtonGroup(string header, string link, string text = null)
                {
                    var linkButton = new Button
                    {
                        Text    = text ?? header,
                        Width   = 175,
                        Enabled = !string.IsNullOrEmpty(link)
                    };

                    linkButton.Click += (sender, e) => DesktopInterop.Open(link);

                    this.Text    = header;
                    this.Content = new StackLayout
                    {
                        HorizontalContentAlignment = HorizontalAlignment.Right,
                        Items =
                        {
                            linkButton
                        }
                    };
                    this.Orientation = Orientation.Horizontal;
                }
Esempio n. 3
0
        public MetadataViewer()
        {
            actions = new StackLayout
            {
                Orientation = Orientation.Horizontal,
                Spacing     = 5,
                Items       =
                {
                    new StackLayoutItem
                    {
                        Expand  = true,
                        Control = uninstallButton = new Button(UninstallHandler)
                        {
                            Text = "Uninstall"
                        }
                    },
                    new StackLayoutItem
                    {
                        Expand  = true,
                        Control = installButton = new Button(InstallHandler)
                    }
                }
            };

            var installedBinding = new DelegateBinding <bool>(
                () =>
            {
                var contexts = AppInfo.PluginManager.GetLoadedPlugins();
                return(contexts.Any(t => PluginMetadata.Match(t.GetMetadata(), Metadata)));
            },
                addChangeEvent: (e) => MetadataChanged    += e,
                removeChangeEvent: (e) => MetadataChanged -= e
                );

            var updateableBinding = new DelegateBinding <bool>(
                () =>
            {
                var repo = PluginMetadataList.Repository;
                if (repo == null)
                {
                    return(false);
                }

                var updatableFromRepository = from meta in repo
                                              where PluginMetadata.Match(meta, Metadata)
                                              where meta.PluginVersion > Metadata.PluginVersion
                                              where CurrentDriverVersion >= meta.SupportedDriverVersion
                                              orderby meta.PluginVersion descending
                                              select meta;

                return(updatableFromRepository.Any());
            },
                addChangeEvent: (e) => MetadataChanged    += e,
                removeChangeEvent: (e) => MetadataChanged -= e
                );

            var installableBinding = new DelegateBinding <bool>(
                () => updateableBinding.GetValue() || !installedBinding.GetValue(),
                addChangeEvent: (e) => MetadataChanged    += e,
                removeChangeEvent: (e) => MetadataChanged += e
                );

            uninstallButton.GetEnabledBinding().Bind(installedBinding);
            installButton.TextBinding.Bind(updateableBinding.Convert(c => c ? "Update" : "Install"));
            installButton.GetEnabledBinding().Bind(installableBinding);

            content = new Scrollable
            {
                Content = new StackLayout
                {
                    Padding = 5,
                    Spacing = 5,
                    HorizontalContentAlignment = HorizontalAlignment.Stretch,
                    Items =
                    {
                        new AlignedGroup
                        {
                            Text    = "Name",
                            Content = name = new Label()
                        },
                        new AlignedGroup
                        {
                            Text    = "Owner",
                            Content = owner = new Label()
                        },
                        new AlignedGroup
                        {
                            Text    = "Description",
                            Content = description = new Label
                            {
                                Wrap = WrapMode.Word
                            }
                        },
                        new AlignedGroup
                        {
                            Text    = "Driver Version",
                            Content = driverVersion = new Label()
                        },
                        new AlignedGroup
                        {
                            Text    = "Plugin Version",
                            Content = pluginVersion = new Label()
                        },
                        new AlignedGroup
                        {
                            Text    = "Source Code Repository",
                            Content = sourceCode = new Button
                            {
                                Width = 175,
                                Text  = "Show source code"
                            }
                        },
                        new AlignedGroup
                        {
                            Text    = "Wiki",
                            Content = wiki = new Button
                            {
                                Width = 175,
                                Text  = "Show plugin wiki"
                            }
                        },
                        new AlignedGroup
                        {
                            Text    = "License",
                            Content = license = new Label()
                        },
                        new StackLayoutItem(null, true),
                        actions
                    }
                }
            };

            name.TextBinding.Bind(MetadataBinding.Child(c => c.Name));
            owner.TextBinding.Bind(MetadataBinding.Child(c => c.Owner));
            description.TextBinding.Bind(MetadataBinding.Child(c => c.Description));
            driverVersion.TextBinding.Bind(MetadataBinding.Child(c => c.SupportedDriverVersion).Convert(v => v?.ToString()));
            pluginVersion.TextBinding.Bind(MetadataBinding.Child(c => c.PluginVersion).Convert(v => v?.ToString()));
            license.TextBinding.Bind(MetadataBinding.Child(c => c.LicenseIdentifier));

            sourceCode.GetEnabledBinding().Bind(MetadataBinding.Child(c => c.RepositoryUrl).Convert(c => c != null));
            sourceCode.Click += (sender, e) => DesktopInterop.Open(Metadata.RepositoryUrl);

            wiki.GetEnabledBinding().Bind(MetadataBinding.Child(c => c.WikiUrl).Convert(c => c != null));
            wiki.Click += (sender, e) => DesktopInterop.Open(Metadata.WikiUrl);

            AppInfo.PluginManager.AssembliesChanged += HandleAssembliesChanged;
        }
Esempio n. 4
0
        private MenuBar ConstructMenu()
        {
            var quitCommand = new Command {
                MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q
            };

            quitCommand.Executed += (sender, e) => Application.Instance.Quit();

            var aboutCommand = new Command {
                MenuText = "About...", Shortcut = Keys.F1
            };

            aboutCommand.Executed += (sender, e) => AboutDialog.ShowDialog(this);

            var resetSettings = new Command {
                MenuText = "Reset to defaults"
            };

            resetSettings.Executed += async(sender, e) => await ResetSettingsDialog();

            var loadSettings = new Command {
                MenuText = "Load settings...", Shortcut = Application.Instance.CommonModifier | Keys.O
            };

            loadSettings.Executed += async(sender, e) => await LoadSettingsDialog();

            var saveSettingsAs = new Command {
                MenuText = "Save settings as...", Shortcut = Application.Instance.CommonModifier | Keys.Shift | Keys.S
            };

            saveSettingsAs.Executed += async(sender, e) => await SaveSettingsDialog();

            var saveSettings = new Command {
                MenuText = "Save settings", Shortcut = Application.Instance.CommonModifier | Keys.S
            };

            saveSettings.Executed += async(sender, e) => await SaveSettings();

            var applySettings = new Command {
                MenuText = "Apply settings", Shortcut = Application.Instance.CommonModifier | Keys.Enter
            };

            applySettings.Executed += async(sender, e) => await ApplySettings();

            var refreshPresets = new Command {
                MenuText = "Refresh presets"
            };

            refreshPresets.Executed += async(sender, e) => await RefreshPresets();

            var savePreset = new Command {
                MenuText = "Save as preset..."
            };

            savePreset.Executed += async(sender, e) => await SavePresetDialog();

            var detectTablet = new Command {
                MenuText = "Detect tablet", Shortcut = Application.Instance.CommonModifier | Keys.D
            };

            detectTablet.Executed += async(sender, e) => await DetectTablet();

            var showTabletDebugger = new Command {
                MenuText = "Tablet debugger..."
            };

            showTabletDebugger.Executed += (sender, e) => App.Current.DebuggerWindow.Show();

            var deviceStringReader = new Command {
                MenuText = "Device string reader..."
            };

            deviceStringReader.Executed += (sender, e) => App.Current.StringReaderWindow.Show();

            var configurationEditor = new Command {
                MenuText = "Open Configuration Editor...", Shortcut = Application.Instance.CommonModifier | Keys.E
            };

            configurationEditor.Executed += (sender, e) => App.Current.ConfigEditorWindow.Show();

            var pluginManager = new Command {
                MenuText = "Open Plugin Manager..."
            };

            pluginManager.Executed += (sender, e) => App.Current.PluginManagerWindow.Show();

            var wikiUrl = new Command {
                MenuText = "Open Wiki..."
            };

            wikiUrl.Executed += (sender, e) => DesktopInterop.Open(WikiUrl);

            var showGuide = new Command {
                MenuText = "Show guide..."
            };

            showGuide.Executed += (sender, e) => App.Current.StartupGreeterWindow.Show();

            var exportDiagnostics = new Command {
                MenuText = "Export diagnostics..."
            };

            exportDiagnostics.Executed += async(sender, e) => await ExportDiagnostics();

            return(new MenuBar
            {
                Items =
                {
                    // File submenu
                    new ButtonMenuItem
                    {
                        Text = "&File",
                        Items =
                        {
                            loadSettings,
                            saveSettings,
                            saveSettingsAs,
                            resetSettings,
                            applySettings,
                            new SeparatorMenuItem(),
                            refreshPresets,
                            savePreset,
                            new ButtonMenuItem
                            {
                                Text = "Presets",
                                Items =
                                {
                                    new ButtonMenuItem
                                    {
                                        Text = "No presets loaded",
                                        Enabled = false
                                    }
                                }
                            }
                        }
                    },
                    // Tablets submenu
                    new ButtonMenuItem
                    {
                        Text = "Tablets",
                        Items =
                        {
                            detectTablet,
                            showTabletDebugger,
                            deviceStringReader,
                            configurationEditor
                        }
                    },
                    // Plugins submenu
                    new ButtonMenuItem
                    {
                        Text = "Plugins",
                        Items =
                        {
                            pluginManager
                        }
                    },
                    new ButtonMenuItem
                    {
                        Text = "&Help",
                        Items =
                        {
                            wikiUrl,
                            exportDiagnostics,
                            showGuide
                        }
                    }
                },
                ApplicationItems =
                {
                    // application (OS X) or file menu (others)
                },
                QuitItem = quitCommand,
                AboutItem = aboutCommand
            });
        }
 private void ShowPluginFolder(object sender, EventArgs e)
 {
     DesktopInterop.Open(SelectedPlugin.Directory.FullName);
 }