/// <summary>
        /// Confirm button for both add and update
        /// </summary>
        private void ConfirmButtonOnClick(object sender, RoutedEventArgs e)
        {
            string title = WebSearchName.Text;

            if (string.IsNullOrEmpty(title))
            {
                string warning = _context.API.GetTranslation("wox_plugin_websearch_input_title");
                MessageBox.Show(warning);
                return;
            }

            string url = Url.Text;

            if (string.IsNullOrEmpty(url))
            {
                string warning = _context.API.GetTranslation("wox_plugin_websearch_input_url");
                MessageBox.Show(warning);
                return;
            }

            string newActionKeyword = Actionword.Text.Trim();

            if (_isUpdate)
            {
                try
                {
                    _plugin.NotifyActionKeywordsUpdated(_webSearch.ActionKeyword, newActionKeyword);
                }
                catch (WoxPluginException exception)
                {
                    MessageBox.Show(exception.Message);
                    return;
                }
            }
            else
            {
                try
                {
                    _plugin.NotifyActionKeywordsAdded(newActionKeyword);
                }
                catch (WoxPluginException exception)
                {
                    MessageBox.Show(exception.Message);
                    return;
                }

                _settings.WebSearches.Add(_webSearch);
            }

            _webSearch.ActionKeyword = newActionKeyword;
            _webSearch.Enabled       = EnableCheckBox.IsChecked ?? false;
            _webSearch.Url           = url;
            _webSearch.Title         = title;

            _settingWindow.ReloadWebSearchView();
            Close();
        }
Exemple #2
0
        /// <summary>
        /// Confirm button for both add and update
        /// </summary>
        private void btnConfirm_OnClick(object sender, RoutedEventArgs e)
        {
            string title = tbTitle.Text;

            if (string.IsNullOrEmpty(title))
            {
                string warning = _context.API.GetTranslation("wox_plugin_websearch_input_title");
                MessageBox.Show(warning);
                return;
            }

            string url = tbUrl.Text;

            if (string.IsNullOrEmpty(url))
            {
                string warning = _context.API.GetTranslation("wox_plugin_websearch_input_url");
                MessageBox.Show(warning);
                return;
            }

            string newActionKeyword = tbActionword.Text.Trim();

            if (_isUpdate)
            {
                try
                {
                    _plguin.NotifyActionKeywordsUpdated(_updateWebSearch.ActionKeyword, newActionKeyword);
                }
                catch (WoxPluginException exception)
                {
                    MessageBox.Show(exception.Message);
                    return;
                }

                _updateWebSearch.ActionKeyword = newActionKeyword;
                _updateWebSearch.IconPath      = tbIconPath.Text;
                _updateWebSearch.Enabled       = cbEnable.IsChecked ?? false;
                _updateWebSearch.Url           = url;
                _updateWebSearch.Title         = title;
            }
            else
            {
                try
                {
                    _plguin.NotifyActionKeywordsAdded(newActionKeyword);
                }
                catch (WoxPluginException exception)
                {
                    MessageBox.Show(exception.Message);
                    return;
                }
                WebSearchStorage.Instance.WebSearches.Add(new WebSearch
                {
                    ActionKeyword = newActionKeyword,
                    Enabled       = cbEnable.IsChecked ?? false,
                    IconPath      = tbIconPath.Text,
                    Url           = url,
                    Title         = title
                });
            }

            WebSearchStorage.Instance.Save();
            _settingWindow.ReloadWebSearchView();
            Close();
        }