File tree Expand file tree Collapse file tree 2 files changed +41
-26
lines changed Expand file tree Collapse file tree 2 files changed +41
-26
lines changed Original file line number Diff line number Diff line change 2020using System . Windows . Media ;
2121using Flow . Launcher . Infrastructure . Hotkey ;
2222using Flow . Launcher . Plugin . SharedCommands ;
23- using System . IO ;
2423
2524namespace Flow . Launcher
2625{
@@ -55,37 +54,15 @@ public MainWindow()
5554 }
5655 private void OnCopy ( object sender , ExecutedRoutedEventArgs e )
5756 {
58-
5957 if ( QueryTextBox . SelectionLength == 0 )
6058 {
61- var results = _viewModel . Results ;
62- var result = results . SelectedItem ? . Result ;
63- if ( result != null )
64- {
65- string copyText = String . IsNullOrEmpty ( result . CopyText ) ? result . SubTitle : result . CopyText ;
66- if ( File . Exists ( copyText ) || Directory . Exists ( copyText ) )
67- {
68-
69- System . Collections . Specialized . StringCollection paths = new System . Collections . Specialized . StringCollection ( ) ;
70- paths . Add ( copyText ) ;
71-
72- System . Windows . Clipboard . SetFileDropList ( paths ) ;
73-
74- }
75- else
76- {
77- System . Windows . Clipboard . SetDataObject ( copyText . ToString ( ) ) ;
78- }
79-
80- e . Handled = true ;
81- }
59+ _viewModel . ResultCopy ( string . Empty ) ;
8260
8361 }
84- else if ( ! String . IsNullOrEmpty ( QueryTextBox . Text ) )
62+ else if ( ! string . IsNullOrEmpty ( QueryTextBox . Text ) )
8563 {
86- System . Windows . Clipboard . SetDataObject ( QueryTextBox . SelectedText ) ;
64+ _viewModel . ResultCopy ( QueryTextBox . SelectedText ) ;
8765 }
88- e . Handled = false ;
8966 }
9067 private async void OnClosing ( object sender , CancelEventArgs e )
9168 {
Original file line number Diff line number Diff line change 1919using Microsoft . VisualStudio . Threading ;
2020using System . Threading . Channels ;
2121using ISavable = Flow . Launcher . Plugin . ISavable ;
22+ using System . IO ;
23+ using System . Collections . Specialized ;
2224
2325namespace Flow . Launcher . ViewModel
2426{
@@ -873,6 +875,42 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
873875 Results . AddResults ( resultsForUpdates , token ) ;
874876 }
875877
878+ /// <summary>
879+ /// This is the global copy method for an individual result. If no text is passed,
880+ /// the method will work out what is to be copied based on the result, so plugin can offer the text
881+ /// to be copied via the result model. If the text is a directory/file path,
882+ /// then actual file/folder will be copied instead.
883+ /// The result's subtitle text is the default text to be copied
884+ /// </summary>
885+ public void ResultCopy ( string stringToCopy )
886+ {
887+ if ( string . IsNullOrEmpty ( stringToCopy ) )
888+ {
889+ var result = Results . SelectedItem ? . Result ;
890+ if ( result != null )
891+ {
892+ string copyText = string . IsNullOrEmpty ( result . CopyText ) ? result . SubTitle : result . CopyText ;
893+ if ( File . Exists ( copyText ) || Directory . Exists ( copyText ) )
894+ {
895+
896+ var paths = new StringCollection ( ) ;
897+ paths . Add ( copyText ) ;
898+
899+ Clipboard . SetFileDropList ( paths ) ;
900+
901+ }
902+ else
903+ {
904+ Clipboard . SetDataObject ( copyText . ToString ( ) ) ;
905+ }
906+ }
907+
908+ return ;
909+ }
910+
911+ Clipboard . SetDataObject ( stringToCopy ) ;
912+ }
913+
876914 #endregion
877915 }
878916}
You can’t perform that action at this time.
0 commit comments