-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from TheJoeFin/dev
v4.7
- Loading branch information
Showing
26 changed files
with
866 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using Text_Grab.Utilities; | ||
|
||
namespace Text_Grab.Models; | ||
|
||
public record WebSearchUrlModel | ||
{ | ||
public string Name { get; set; } = string.Empty; | ||
public string Url { get; set; } = string.Empty; | ||
|
||
private WebSearchUrlModel? defaultSearcher; | ||
|
||
public WebSearchUrlModel DefaultSearcher | ||
{ | ||
get | ||
{ | ||
defaultSearcher ??= GetDefaultSearcher(); | ||
return defaultSearcher; | ||
} | ||
set | ||
{ | ||
defaultSearcher = value; | ||
SaveDefaultSearcher(defaultSearcher); | ||
} | ||
} | ||
|
||
public override string ToString() => Name; | ||
|
||
private List<WebSearchUrlModel> webSearchers = []; | ||
|
||
public List<WebSearchUrlModel> WebSearchers | ||
{ | ||
get | ||
{ | ||
if (webSearchers.Count == 0) | ||
webSearchers = GetWebSearchUrls(); | ||
|
||
return webSearchers; | ||
} | ||
set | ||
{ | ||
webSearchers = value; | ||
SaveWebSearchUrls(webSearchers); | ||
} | ||
} | ||
|
||
private WebSearchUrlModel GetDefaultSearcher() | ||
{ | ||
string searcherName = AppUtilities.TextGrabSettings.DefaultWebSearch; | ||
if (string.IsNullOrWhiteSpace(searcherName)) | ||
return WebSearchers[0]; | ||
|
||
WebSearchUrlModel? searcher = WebSearchers | ||
.FirstOrDefault(searcher => searcher.Name == searcherName); | ||
|
||
return searcher ?? WebSearchers[0]; | ||
} | ||
|
||
private void SaveDefaultSearcher(WebSearchUrlModel webSearchUrl) | ||
{ | ||
AppUtilities.TextGrabSettings.DefaultWebSearch = webSearchUrl.Name; | ||
AppUtilities.TextGrabSettings.Save(); | ||
} | ||
|
||
private static List<WebSearchUrlModel> GetDefaultWebSearchUrls() | ||
{ | ||
return | ||
[ | ||
new() { Name = "Google", Url = "https://www.google.com/search?q=" }, | ||
new() { Name = "Bing", Url = "https://www.bing.com/search?q=" }, | ||
new() { Name = "DuckDuckGo", Url = "https://duckduckgo.com/?q=" }, | ||
new() { Name = "Brave", Url = "https://search.brave.com/search?q=" }, | ||
new() { Name = "GitHub Code", Url = "https://github.com/search?type=code&q=" }, | ||
new() { Name = "GitHub Repos", Url = "https://github.com/search?type=repositories&q=" }, | ||
]; | ||
} | ||
|
||
public static List<WebSearchUrlModel> GetWebSearchUrls() | ||
{ | ||
string json = AppUtilities.TextGrabSettings.WebSearchItemsJson; | ||
if (string.IsNullOrWhiteSpace(json)) | ||
return GetDefaultWebSearchUrls(); | ||
List<WebSearchUrlModel>? webSearchUrls = JsonSerializer.Deserialize<List<WebSearchUrlModel>>(json); | ||
if (webSearchUrls is null || webSearchUrls.Count == 0) | ||
return GetDefaultWebSearchUrls(); | ||
|
||
return webSearchUrls; | ||
} | ||
|
||
public static void SaveWebSearchUrls(List<WebSearchUrlModel> webSearchUrls) | ||
{ | ||
string json = JsonSerializer.Serialize(webSearchUrls); | ||
AppUtilities.TextGrabSettings.WebSearchItemsJson = json; | ||
AppUtilities.TextGrabSettings.Save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.