示例#1
0
        internal SettingsWindow(ProgramSettings settings)
        {
            InitializeComponent();

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, e) => Close()));

            LoadTabs(settings);
        }
        public ProgramSettingsCommandProvider(ProgramSettings programSettings, CompositionContainer compositionContainer)
        {
            this.programSettings = programSettings;
            this.compositionContainer = compositionContainer;

            Recompose();

            this.compositionContainer.ExportsChanged += Recompose;
        }
示例#3
0
        private void LoadTabs(ProgramSettings settings)
        {
            var commandProvider = settings.CommandProvider;

            Resources["commandProvider"] = commandProvider;

            AddTab(
                new DefaultCommandsEditor(commandProvider, settings.FeatureRegistry, settings.DefaultCommands),
                "Defaults"
            );

            foreach (var plugin in settings.Plugins) {
                var editor = plugin.GetEditor(commandProvider);

                if (editor == null) {
                    continue;
                }

                AddTab(editor, plugin.Name);
            }
        }
示例#4
0
文件: App.xaml.cs 项目: strager/NoCap
        private void Load()
        {
            var commandRunner = new CommandRunner();

            Log.Info("Loading extension manager");
            this.extensionManager = new ExtensionManager(Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Extensions")));

            Log.Info("Loading application settings");
            this.applicationSettings = new ApplicationSettings(new ProgramSettingsDataSerializer(this.extensionManager));

            ProgramSettingsData settingsData = null;

            try {
                settingsData = this.applicationSettings.LoadSettingsData();
            } catch (SerializationException e) {
                Log.Warn("Loading settings failed", e);

                if (this.guiMode) {
                    MessageBox.Show(
                        "An error occurred loading your NoCap settings.  Settings will be restored to their defaults.",
                        "Error loading settings",
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation
                    );
                }
            }

            bool loadCommandDefaults = false;

            if (settingsData == null) {
                Log.Debug("Application settings not found; using defaults");

                settingsData = new ProgramSettingsData();

                loadCommandDefaults = true;
            }

            this.settings = ProgramSettings.Create(settingsData, commandRunner, this.extensionManager);

            var featureRegistry = this.settings.FeatureRegistry;

            // TODO Move elsewhere
            featureRegistry.Register(CommandFeatures.ImageUploader, "Image uploader");
            featureRegistry.Register(CommandFeatures.UrlShortener,  "Url shortener" );
            featureRegistry.Register(CommandFeatures.FileUploader,  "File uploader" );
            featureRegistry.Register(CommandFeatures.TextUploader,  "Text uploader" );

            if (loadCommandDefaults) {
                this.settings.LoadCommandDefaults();
            }
        }
示例#5
0
        public static ProgramSettings Create(ProgramSettingsData settingsData, CommandRunner commandRunner, ExtensionManager extensionManager)
        {
            var settings = new ProgramSettings(settingsData);
            settings.Initialize(commandRunner, extensionManager);

            return settings;
        }