6
6
using System . Windows ;
7
7
using System . Windows . Forms ;
8
8
using Flow . Launcher . Plugin . Explorer . Helper ;
9
+ using Flow . Launcher . Plugin . Explorer . Search ;
9
10
using Flow . Launcher . Plugin . Explorer . Search . QuickAccessLinks ;
10
11
11
12
namespace Flow . Launcher . Plugin . Explorer . Views ;
12
13
13
14
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
14
15
{
16
+ private ResultType _accessLinkType = ResultType . Folder ;
17
+
15
18
private string _selectedPath ;
16
19
public string SelectedPath
17
20
{
@@ -25,6 +28,7 @@ public string SelectedPath
25
28
if ( string . IsNullOrEmpty ( _selectedName ) )
26
29
{
27
30
SelectedName = _selectedPath . GetPathName ( ) ;
31
+ _accessLinkType = GetResultType ( _selectedPath ) ;
28
32
}
29
33
}
30
34
}
@@ -67,6 +71,7 @@ public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks
67
71
IsEdit = true ;
68
72
_selectedName = selectedAccessLink . Name ;
69
73
_selectedPath = selectedAccessLink . Path ;
74
+ _accessLinkType = GetResultType ( _selectedPath ) ;
70
75
SelectedAccessLink = selectedAccessLink ;
71
76
QuickAccessLinks = quickAccessLinks ;
72
77
InitializeComponent ( ) ;
@@ -109,7 +114,7 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
109
114
var updatedLink = new AccessLink
110
115
{
111
116
Name = SelectedName ,
112
- Type = SelectedAccessLink . Type ,
117
+ Type = _accessLinkType ,
113
118
Path = SelectedPath
114
119
} ;
115
120
QuickAccessLinks [ index ] = updatedLink ;
@@ -123,6 +128,7 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
123
128
var newAccessLink = new AccessLink
124
129
{
125
130
Name = SelectedName ,
131
+ Type = _accessLinkType ,
126
132
Path = SelectedPath
127
133
} ;
128
134
QuickAccessLinks . Add ( newAccessLink ) ;
@@ -143,19 +149,49 @@ private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
143
149
CheckPathExists = true
144
150
} ;
145
151
146
- if ( openFileDialog . ShowDialog ( ) == true )
147
- {
148
- SelectedPath = openFileDialog . FileName ;
149
- }
152
+ if ( openFileDialog . ShowDialog ( ) != System . Windows . Forms . DialogResult . OK ||
153
+ string . IsNullOrEmpty ( openFileDialog . FileName ) )
154
+ return ;
155
+
156
+ SelectedPath = openFileDialog . FileName ;
150
157
}
151
158
else // Folder selection
152
159
{
153
- var folderBrowserDialog = new FolderBrowserDialog ( ) ;
160
+ var folderBrowserDialog = new FolderBrowserDialog
161
+ {
162
+ ShowNewFolderButton = true
163
+ } ;
164
+
165
+ if ( folderBrowserDialog . ShowDialog ( ) != System . Windows . Forms . DialogResult . OK ||
166
+ string . IsNullOrEmpty ( folderBrowserDialog . SelectedPath ) )
167
+ return ;
168
+
169
+ SelectedPath = folderBrowserDialog . SelectedPath ;
170
+ }
171
+ }
154
172
155
- if ( folderBrowserDialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
173
+ private static ResultType GetResultType ( string path )
174
+ {
175
+ // Check if the path is a file or folder
176
+ if ( System . IO . File . Exists ( path ) )
177
+ {
178
+ return ResultType . File ;
179
+ }
180
+ else if ( System . IO . Directory . Exists ( path ) )
181
+ {
182
+ if ( string . Equals ( System . IO . Path . GetPathRoot ( path ) , path , StringComparison . OrdinalIgnoreCase ) )
156
183
{
157
- SelectedPath = folderBrowserDialog . SelectedPath ;
184
+ return ResultType . Volume ;
158
185
}
186
+ else
187
+ {
188
+ return ResultType . Folder ;
189
+ }
190
+ }
191
+ else
192
+ {
193
+ // This should not happen, but just in case, we assume it's a folder
194
+ return ResultType . Folder ;
159
195
}
160
196
}
161
197
0 commit comments