Beispiel #1
0
        public override T GetPanel <T>(params object[] parameters)
        {
            try
            {
                var launcherPanel = new LauncherPanel();
                LauncherContext = launcherPanel.DataContext as LauncherContext;

                var settingsManager          = VA.SettingsManager;
                var applicationListSettings  = settingsManager[Constants.ApplicationList];
                var directoryListSettings    = settingsManager[Constants.DirectoryList];
                var searchEngineListSettings = settingsManager[Constants.SearchEngineList];
                var websiteListSettings      = settingsManager[Constants.WebsiteList];

                if (LauncherContext != null)
                {
                    LauncherContext.AddFileAction = async() =>
                    {
                        try
                        {
                            var openFileDialog = new OpenFileDialog();
                            if (openFileDialog.ShowDialog() == true)
                            {
                                var window       = VA.Components.Get <SettingsWindow>();
                                var selectedPath = openFileDialog.FileName;
                                var selectedName = await window.GetInput(StringResource.LauncherPlugin_AddFileTitle, StringResource.LauncherPlugin_AddFileMessage, Path.GetFileNameWithoutExtension(selectedPath));

                                if (selectedName != null)
                                {
                                    applicationListSettings.Add(new Variable(selectedName, selectedPath));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            VA.Logger.Error(exception);
                        }
                    };

                    LauncherContext.AddFolderAction = async() =>
                    {
                        try
                        {
                            var folderBrowserDialog = new FolderBrowserDialog();
                            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                            {
                                var window       = VA.Components.Get <SettingsWindow>();
                                var selectedPath = folderBrowserDialog.SelectedPath;
                                var selectedName = await window.GetInput(StringResource.LauncherPlugin_AddFolderTitle, StringResource.LauncherPlugin_AddFolderMessage,
                                                                         SynUtility.Directory.GetName(selectedPath));

                                if (selectedName != null)
                                {
                                    directoryListSettings.Add(new Variable(selectedName, selectedPath));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            VA.Logger.Error(exception);
                        }
                    };

                    LauncherContext.AddSearchEngineAction = async() =>
                    {
                        try
                        {
                            var window          = VA.Components.Get <SettingsWindow>();
                            var searchEngineUrl = await window.GetInput(StringResource.LauncherPlugin_AddSearchEngineAddressTitle, StringResource.LauncherPlugin_AddSearchEngineAddressMessage);

                            if (searchEngineUrl != null)
                            {
                                var searchEngineName = await window.GetInput(StringResource.LauncherPlugin_AddSearchEngineNameTitle, StringResource.LauncherPlugin_AddSearchEngineNameMessage);

                                if (searchEngineName != null)
                                {
                                    searchEngineListSettings.Add(new Variable(searchEngineName, searchEngineUrl));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            VA.Logger.Error(exception);
                        }
                    };

                    LauncherContext.AddWebsiteAction = async() =>
                    {
                        try
                        {
                            var window     = VA.Components.Get <SettingsWindow>();
                            var websiteUrl = await window.GetInput(StringResource.LauncherPlugin_AddWebsiteAddressTitle, StringResource.LauncherPlugin_AddWebsiteAddressMessage);

                            if (websiteUrl != null)
                            {
                                var websiteName = await window.GetInput(StringResource.LauncherPlugin_AddWebsiteNameTitle, StringResource.LauncherPlugin_AddWebsiteNameMessage);

                                if (websiteName != null)
                                {
                                    websiteListSettings.Add(new Variable(websiteName, websiteUrl));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            VA.Logger.Error(exception);
                        }
                    };

                    UpdateApplicationView.Invoke();
                    UpdateDirectoryView.Invoke();
                    UpdateSearchEngineView.Invoke();
                    UpdateWebsiteView.Invoke();
                    Settings.ApplyToProperties(LauncherContext);
                }
                return(launcherPanel as T);
            }
            catch (Exception exception)
            {
                VA.Logger.Error(exception);
            }

            return(null);
        }
Beispiel #2
0
        public LauncherPlugin()
        {
            try
            {
                var settingsManager = VA.SettingsManager;

                var applicationListSettings  = settingsManager[Constants.ApplicationList];
                var directoryListSettings    = settingsManager[Constants.DirectoryList];
                var searchEngineListSettings = settingsManager[Constants.SearchEngineList];
                var websiteListSettings      = settingsManager[Constants.WebsiteList];

                if (applicationListSettings != null)
                {
                    foreach (var shortcutFile in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "*.lnk", SearchOption.AllDirectories))
                    {
                        var fullPath = ShortcutFile.ResolveShortcut(shortcutFile);
                        var fileName = Path.GetFileNameWithoutExtension(fullPath);
                        if (!string.IsNullOrEmpty(fullPath) && !string.IsNullOrEmpty(fileName))
                        {
                            applicationListSettings.Add(fileName, () => fullPath);
                        }
                    }
                }

                if (directoryListSettings != null)
                {
                    directoryListSettings.Add("document", () => SynUtility.Directory.GetPath(SpecialFolders.MyDocuments));
                    directoryListSettings.Add("music", () => SynUtility.Directory.GetPath(SpecialFolders.MyMusic));
                    directoryListSettings.Add("pictures", () => SynUtility.Directory.GetPath(SpecialFolders.MyPictures));
                    directoryListSettings.Add("desktop", () => SynUtility.Directory.GetPath(SpecialFolders.Desktop));
                    directoryListSettings.Add("wallpapers", () => SynUtility.Directory.GetPath(SpecialFolders.Wallpaper));
                    directoryListSettings.Add("videos", () => SynUtility.Directory.GetPath(SpecialFolders.MyVideos));
                }

                var bot = VA.Components.Get <SimlBot>();
                bot.Adapters.Add(new AppAdapter());
                bot.Adapters.Add(new FolderAdapter());
                bot.Adapters.Add(new SearchSiteAdapter());
                bot.Adapters.Add(new WebsiteAdapter());

                if (applicationListSettings != null)
                {
                    applicationListSettings.SettingsChanged += delegate
                    {
                        UpdateApplicationView.Invoke();
                        CreateMap(applicationListSettings);
                        VA.SettingsManager.Save(applicationListSettings);
                    };
                }

                if (directoryListSettings != null)
                {
                    directoryListSettings.SettingsChanged += delegate
                    {
                        UpdateDirectoryView.Invoke();
                        CreateMap(directoryListSettings);
                        VA.SettingsManager.Save(directoryListSettings);
                    };
                }

                if (searchEngineListSettings != null)
                {
                    searchEngineListSettings.SettingsChanged += delegate
                    {
                        UpdateSearchEngineView.Invoke();
                        CreateMap(searchEngineListSettings);
                        VA.SettingsManager.Save(searchEngineListSettings);
                    };
                }

                if (websiteListSettings != null)
                {
                    websiteListSettings.SettingsChanged += delegate
                    {
                        UpdateWebsiteView.Invoke();
                        CreateMap(websiteListSettings);
                        VA.SettingsManager.Save(websiteListSettings);
                    };
                }

                RefreshMaps();
            }
            catch (Exception exception)
            {
                VA.Logger.Error(exception);
            }
        }