private async void MainBrowserWindow_Loaded(object sender, RoutedEventArgs e) { try { DataTransfer dt = new DataTransfer(); string searchEngineName = await dt.GetSelectedEngineAttribute("name"); prefix = await dt.GetSelectedEngineAttribute("prefix"); SearchBar.PlaceholderText = "Search With " + searchEngineName + "..."; } catch { } }
/// <summary> /// Does a search with the search engine selected in settings, or goes to a Url. /// </summary> private async void Search() { // Get an instance of the Data Transfer class. DataTransfer dt = new DataTransfer(); // Returns a true or false if the url bar has a host type (set in the xml settings file). bool hasUrlType = await dt.HasUrlType(SearchBar.Text); // If there is a type the navigate the current selected web view to the destination and adds https to the beginning. if (hasUrlType) { // If the url doesn't contain http or https the add it to the beginning. if (!SearchBar.Text.Contains("http://") || !SearchBar.Text.Contains("https://")) { currentSelectedWebView.Navigate(new Uri("https://www." + SearchBar.Text)); } else { SearchBar.Text = "https://www." + SearchBar.Text; } // Change the search text to the url. SearchBar.Text = currentSelectedWebView.Source.AbsoluteUri; } else { // Set the global veriable "prefix" to the selected engine. prefix = await dt.GetSelectedEngineAttribute("prefix"); if (currentSelectedTab != null) { // add the prefix if it's not a settings page. if (currentSelectedTab.Name != "settingsTab") { if (currentSelectedWebView == null) // Posible error if no tab, could cause crash. <<Fix Needed>> { // search with the prefix of the selected search engine on the default. webBrowser.Source = new Uri(prefix + SearchBar.Text); } else { // search with the prefix of the selected search engine on the current currentSelectedWebView.Source = new Uri(prefix + SearchBar.Text); } } } else { } } }
private async void Setup() { DataTransfer dt = new DataTransfer(); List <string> engineList = await dt.SearchEngineList("name"); foreach (var item in engineList) { ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = item; searchEngineCombo.Items.Add(comboBoxItem); if (await dt.GetSelectedEngineAttribute("name") == item) { searchEngineCombo.SelectedItem = comboBoxItem; } } }
private void SetSelectedEngine() { DataTransfer dt = new DataTransfer(); searchEngineCombo.SelectedItem = dt.GetSelectedEngineAttribute("name"); }