File tree Expand file tree Collapse file tree 3 files changed +47
-28
lines changed Expand file tree Collapse file tree 3 files changed +47
-28
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,12 @@ public class Result
29
29
/// </summary>
30
30
public string ActionKeywordAssigned { get ; set ; }
31
31
32
- public string CopyText { get ; set ; } = String . Empty ;
33
- public string FileCopy { get ; set ; } = String . Empty ;
32
+ /// <summary>
33
+ /// This holds the text which can be provided by plugin to be copied to the
34
+ /// user's clipboard when Ctrl + C is pressed on a result. If the text is a file/directory path
35
+ /// flow will copy the actual file/folder instead of just the path text.
36
+ /// </summary>
37
+ public string CopyText { get ; set ; } = string . Empty ;
34
38
35
39
/// <summary>
36
40
/// This holds the text which can be provided by plugin to help Flow autocomplete text
Original file line number Diff line number Diff line change 20
20
using System . Windows . Media ;
21
21
using Flow . Launcher . Infrastructure . Hotkey ;
22
22
using Flow . Launcher . Plugin . SharedCommands ;
23
- using System . IO ;
24
23
25
24
namespace Flow . Launcher
26
25
{
@@ -55,37 +54,15 @@ public MainWindow()
55
54
}
56
55
private void OnCopy ( object sender , ExecutedRoutedEventArgs e )
57
56
{
58
-
59
57
if ( QueryTextBox . SelectionLength == 0 )
60
58
{
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 ) ;
82
60
83
61
}
84
- else if ( ! String . IsNullOrEmpty ( QueryTextBox . Text ) )
62
+ else if ( ! string . IsNullOrEmpty ( QueryTextBox . Text ) )
85
63
{
86
- System . Windows . Clipboard . SetDataObject ( QueryTextBox . SelectedText ) ;
64
+ _viewModel . ResultCopy ( QueryTextBox . SelectedText ) ;
87
65
}
88
- e . Handled = false ;
89
66
}
90
67
private async void OnClosing ( object sender , CancelEventArgs e )
91
68
{
Original file line number Diff line number Diff line change 19
19
using Microsoft . VisualStudio . Threading ;
20
20
using System . Threading . Channels ;
21
21
using ISavable = Flow . Launcher . Plugin . ISavable ;
22
+ using System . IO ;
23
+ using System . Collections . Specialized ;
22
24
23
25
namespace Flow . Launcher . ViewModel
24
26
{
@@ -873,6 +875,42 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
873
875
Results . AddResults ( resultsForUpdates , token ) ;
874
876
}
875
877
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
+
876
914
#endregion
877
915
}
878
916
}
You can’t perform that action at this time.
0 commit comments