@@ -52,10 +52,7 @@ public partial class EditTextWindow : Wpf.Ui.Controls.FluentWindow
52
52
public static RoutedCommand ToggleCaseCmd = new ( ) ;
53
53
public static RoutedCommand UnstackCmd = new ( ) ;
54
54
public static RoutedCommand UnstackGroupCmd = new ( ) ;
55
- public static RoutedCommand GoogleSearchCmd = new ( ) ;
56
- public static RoutedCommand BingSearchCmd = new ( ) ;
57
- public static RoutedCommand DuckDuckGoSearchCmd = new ( ) ;
58
- public static RoutedCommand GitHubSearchCmd = new ( ) ;
55
+ public static RoutedCommand WebSearchCmd = new ( ) ;
59
56
public bool LaunchedFromNotification = false ;
60
57
private CancellationTokenSource ? cancellationTokenForDirOCR ;
61
58
private string historyId = string . Empty ;
@@ -138,10 +135,7 @@ public static Dictionary<string, RoutedCommand> GetRoutedCommands()
138
135
{ nameof ( InsertSelectionOnEveryLineCmd ) , InsertSelectionOnEveryLineCmd } ,
139
136
{ nameof ( OcrPasteCommand ) , OcrPasteCommand } ,
140
137
{ nameof ( MakeQrCodeCmd ) , MakeQrCodeCmd } ,
141
- { nameof ( GoogleSearchCmd ) , GoogleSearchCmd } ,
142
- { nameof ( BingSearchCmd ) , BingSearchCmd } ,
143
- { nameof ( DuckDuckGoSearchCmd ) , DuckDuckGoSearchCmd } ,
144
- { nameof ( GitHubSearchCmd ) , GitHubSearchCmd } ,
138
+ { nameof ( WebSearchCmd ) , WebSearchCmd } ,
145
139
} ;
146
140
}
147
141
@@ -244,7 +238,7 @@ public async Task OcrAllImagesInFolder(string folderPath, OcrDirectoryOptions op
244
238
stopwatch . Start ( ) ;
245
239
Mouse . OverrideCursor = System . Windows . Input . Cursors . Wait ;
246
240
247
- List < AsyncOcrFileResult > ocrFileResults = new ( ) ;
241
+ List < AsyncOcrFileResult > ocrFileResults = [ ] ;
248
242
foreach ( string path in imageFiles )
249
243
{
250
244
AsyncOcrFileResult ocrFileResult = new ( path ) ;
@@ -899,7 +893,7 @@ private void HideBottomBarMenuItem_Click(object sender, RoutedEventArgs e)
899
893
900
894
private void InsertSelectionOnEveryLine ( object ? sender = null , ExecutedRoutedEventArgs ? e = null )
901
895
{
902
- string [ ] splitString = PassedTextControl . Text . Split ( new string [ ] { System . Environment . NewLine } , StringSplitOptions . None ) ;
896
+ string [ ] splitString = PassedTextControl . Text . Split ( [ Environment . NewLine ] , StringSplitOptions . None ) ;
903
897
string selectionText = PassedTextControl . SelectedText ;
904
898
int initialSelectionStart = PassedTextControl . SelectionStart ;
905
899
int selectionPositionInLine = PassedTextControl . SelectionStart ;
@@ -995,6 +989,18 @@ private async void GitHubSearchExecuted(object sender, ExecutedRoutedEventArgs e
995
989
_ = await Windows . System . Launcher . LaunchUriAsync ( new Uri ( string . Format ( $ "https://github.com/search?q={ searchStringUrlSafe } ") ) ) ;
996
990
}
997
991
992
+ private async void WebSearchExecuted ( object sender , ExecutedRoutedEventArgs e )
993
+ {
994
+ string possibleSearch = PassedTextControl . SelectedText ;
995
+ string searchStringUrlSafe = WebUtility . UrlEncode ( possibleSearch ) ;
996
+
997
+ if ( e . Parameter is not WebSearchUrlModel webSearcher )
998
+ return ;
999
+
1000
+ Uri searchUri = new ( $ "{ webSearcher . Url } { searchStringUrlSafe } ") ;
1001
+ _ = await Windows . System . Launcher . LaunchUriAsync ( searchUri ) ;
1002
+ }
1003
+
998
1004
private void keyedCtrlF ( object sender , ExecutedRoutedEventArgs e )
999
1005
{
1000
1006
WindowUtilities . LaunchFullScreenGrab ( PassedTextControl ) ;
@@ -1152,7 +1158,7 @@ private async void LoadLanguageMenuItems(MenuItem captureMenuItem)
1152
1158
private void LoadRecentTextHistory ( )
1153
1159
{
1154
1160
List < HistoryInfo > grabsHistories = Singleton < HistoryService > . Instance . GetEditWindows ( ) ;
1155
- grabsHistories = grabsHistories . OrderByDescending ( x => x . CaptureDateTime ) . ToList ( ) ;
1161
+ grabsHistories = [ .. grabsHistories . OrderByDescending ( x => x . CaptureDateTime ) ] ;
1156
1162
1157
1163
OpenRecentMenuItem . Items . Clear ( ) ;
1158
1164
@@ -1777,7 +1783,7 @@ private void SetFontFromSettings()
1777
1783
if ( DefaultSettings . IsFontItalic )
1778
1784
PassedTextControl . FontStyle = FontStyles . Italic ;
1779
1785
1780
- TextDecorationCollection tdc = new ( ) ;
1786
+ TextDecorationCollection tdc = [ ] ;
1781
1787
if ( DefaultSettings . IsFontUnderline ) tdc . Add ( TextDecorations . Underline ) ;
1782
1788
if ( DefaultSettings . IsFontStrikeout ) tdc . Add ( TextDecorations . Strikethrough ) ;
1783
1789
PassedTextControl . TextDecorations = tdc ;
@@ -1883,6 +1889,20 @@ private void SetupRoutedCommands()
1883
1889
RoutedCommand duplicateLine = new ( ) ;
1884
1890
_ = duplicateLine . InputGestures . Add ( new KeyGesture ( Key . D , ModifierKeys . Control ) ) ;
1885
1891
_ = CommandBindings . Add ( new CommandBinding ( duplicateLine , DuplicateSelectedLine ) ) ;
1892
+
1893
+ List < WebSearchUrlModel > searchers = WebSearchUrlModel . GetDefaultWebSearchUrls ( ) ;
1894
+
1895
+ foreach ( WebSearchUrlModel searcher in searchers )
1896
+ {
1897
+ MenuItem searchItem = new ( )
1898
+ {
1899
+ Header = $ "Search with { searcher . Name } ...",
1900
+ Command = WebSearchCmd ,
1901
+ CommandParameter = searcher ,
1902
+ } ;
1903
+
1904
+ WebSearchCollection . Items . Add ( searchItem ) ;
1905
+ }
1886
1906
}
1887
1907
1888
1908
private void SingleLineCmdCanExecute ( object sender , CanExecuteRoutedEventArgs e )
0 commit comments