Skip to content

Commit 1c65232

Browse files
committed
Get access link type
1 parent 76972d3 commit 1c65232

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
using System.Windows;
77
using System.Windows.Forms;
88
using Flow.Launcher.Plugin.Explorer.Helper;
9+
using Flow.Launcher.Plugin.Explorer.Search;
910
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
1011

1112
namespace Flow.Launcher.Plugin.Explorer.Views;
1213

1314
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
1415
{
16+
private ResultType _accessLinkType = ResultType.Folder;
17+
1518
private string _selectedPath;
1619
public string SelectedPath
1720
{
@@ -25,6 +28,7 @@ public string SelectedPath
2528
if (string.IsNullOrEmpty(_selectedName))
2629
{
2730
SelectedName = _selectedPath.GetPathName();
31+
_accessLinkType = GetResultType(_selectedPath);
2832
}
2933
}
3034
}
@@ -67,6 +71,7 @@ public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks
6771
IsEdit = true;
6872
_selectedName = selectedAccessLink.Name;
6973
_selectedPath = selectedAccessLink.Path;
74+
_accessLinkType = GetResultType(_selectedPath);
7075
SelectedAccessLink = selectedAccessLink;
7176
QuickAccessLinks = quickAccessLinks;
7277
InitializeComponent();
@@ -109,7 +114,7 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
109114
var updatedLink = new AccessLink
110115
{
111116
Name = SelectedName,
112-
Type = SelectedAccessLink.Type,
117+
Type = _accessLinkType,
113118
Path = SelectedPath
114119
};
115120
QuickAccessLinks[index] = updatedLink;
@@ -123,6 +128,7 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
123128
var newAccessLink = new AccessLink
124129
{
125130
Name = SelectedName,
131+
Type = _accessLinkType,
126132
Path = SelectedPath
127133
};
128134
QuickAccessLinks.Add(newAccessLink);
@@ -143,19 +149,49 @@ private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
143149
CheckPathExists = true
144150
};
145151

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;
150157
}
151158
else // Folder selection
152159
{
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+
}
154172

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))
156183
{
157-
SelectedPath = folderBrowserDialog.SelectedPath;
184+
return ResultType.Volume;
158185
}
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;
159195
}
160196
}
161197

0 commit comments

Comments
 (0)