Skip to content

Commit 3a8c7cf

Browse files
authored
Fix: Fixed an issue with drag and dropping items onto .ahk files (#14895)
1 parent 5ba7ad0 commit 3a8c7cf

File tree

6 files changed

+11
-39
lines changed

6 files changed

+11
-39
lines changed

src/Files.App/Data/Items/ListedItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public override string ToString()
366366
public bool IsAlternateStream => this is AlternateStreamItem;
367367
public bool IsGitItem => this is GitItem;
368368
public virtual bool IsExecutable => FileExtensionHelpers.IsExecutableFile(ItemPath);
369-
public virtual bool IsPythonFile => FileExtensionHelpers.IsPythonFile(ItemPath);
369+
public virtual bool IsScriptFile => FileExtensionHelpers.IsScriptFile(ItemPath);
370370
public bool IsPinned => App.QuickAccessManager.Model.PinnedFolders.Contains(itemPath);
371371
public bool IsDriveRoot => ItemPath == PathNormalization.GetPathRoot(ItemPath);
372372
public bool IsElevationRequired { get; set; }

src/Files.App/Helpers/Environment/SoftwareHelpers.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ public static bool IsVSInstalled()
3131
return true;
3232
}
3333

34-
public static bool IsPythonInstalled()
35-
{
36-
try
37-
{
38-
ProcessStartInfo psi = new ProcessStartInfo();
39-
psi.FileName = "python";
40-
psi.Arguments = "--version";
41-
psi.RedirectStandardOutput = true;
42-
psi.UseShellExecute = false;
43-
psi.CreateNoWindow = true;
44-
45-
using (Process process = Process.Start(psi))
46-
{
47-
using (StreamReader reader = process.StandardOutput)
48-
{
49-
string result = reader.ReadToEnd();
50-
return result.Contains("Python");
51-
}
52-
}
53-
}
54-
catch
55-
{
56-
return false;
57-
}
58-
}
59-
6034
private static bool ContainsName(RegistryKey? key, string find)
6135
{
6236
if (key is null)

src/Files.App/Utils/Storage/Operations/FilesystemHelpers.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public async Task<ReturnResult> PerformOperationTypeAsync(
233233
bool showDialog,
234234
bool registerHistory,
235235
bool isTargetExecutable = false,
236-
bool isTargetPythonFile = false)
236+
bool isTargetScriptFile = false)
237237
{
238238
try
239239
{
@@ -256,11 +256,9 @@ public async Task<ReturnResult> PerformOperationTypeAsync(
256256
else if (operation.HasFlag(DataPackageOperation.Link))
257257
{
258258
// Open with piggybacks off of the link operation, since there isn't one for it
259-
if (isTargetExecutable || isTargetPythonFile)
259+
if (isTargetExecutable || isTargetScriptFile)
260260
{
261261
var items = await GetDraggedStorageItems(packageView);
262-
if (isTargetPythonFile && !SoftwareHelpers.IsPythonInstalled())
263-
return ReturnResult.Cancelled;
264262
NavigationHelpers.OpenItemsWithExecutableAsync(associatedInstance, items, destination);
265263
return ReturnResult.Success;
266264
}

src/Files.App/Utils/Storage/Operations/IFilesystemHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public interface IFilesystemHelpers : IDisposable
114114
/// The <paramref name="destination"/> is NOT fullPath</param>
115115
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
116116
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
117-
Task<ReturnResult> PerformOperationTypeAsync(DataPackageOperation operation, DataPackageView packageView, string destination, bool showDialog, bool registerHistory, bool isDestinationExecutable = false, bool isDestinationPython = false);
117+
Task<ReturnResult> PerformOperationTypeAsync(DataPackageOperation operation, DataPackageView packageView, string destination, bool showDialog, bool registerHistory, bool isDestinationExecutable = false, bool isDestinationScript = false);
118118

119119
#region Copy
120120

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ private async void Item_DragOver(object sender, DragEventArgs e)
10261026
{
10271027
e.DragUIOverride.IsCaptionVisible = true;
10281028

1029-
if (item.IsExecutable || item.IsPythonFile)
1029+
if (item.IsExecutable || item.IsScriptFile)
10301030
{
10311031
e.DragUIOverride.Caption = $"{"OpenWith".GetLocalizedResource()} {item.Name}";
10321032
e.AcceptedOperation = DataPackageOperation.Link;
@@ -1104,7 +1104,7 @@ protected virtual async void Item_Drop(object sender, DragEventArgs e)
11041104

11051105
var item = GetItemFromElement(sender);
11061106
if (item is not null)
1107-
await ParentShellPageInstance!.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (item as ShortcutItem)?.TargetPath ?? item.ItemPath, false, true, item.IsExecutable, item.IsPythonFile);
1107+
await ParentShellPageInstance!.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (item as ShortcutItem)?.TargetPath ?? item.ItemPath, false, true, item.IsExecutable, item.IsScriptFile);
11081108

11091109
deferral.Complete();
11101110
}
@@ -1253,7 +1253,7 @@ protected void InitializeDrag(UIElement container, ListedItem item)
12531253
UninitializeDrag(container);
12541254
if ((item.PrimaryItemAttribute == StorageItemTypes.Folder && !RecycleBinHelpers.IsPathUnderRecycleBin(item.ItemPath))
12551255
|| item.IsExecutable
1256-
|| item.IsPythonFile)
1256+
|| item.IsScriptFile)
12571257
{
12581258
container.AllowDrop = true;
12591259
container.AddHandler(UIElement.DragOverEvent, Item_DragOverEventHandler, true);

src/Files.Shared/Helpers/FileExtensionHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ public static bool IsCertificateFile(string? filePathToCheck)
208208
}
209209

210210
/// <summary>
211-
/// Check if the file extension is a Python file.
211+
/// Check if the file extension is a Script file.
212212
/// </summary>
213213
/// <param name="filePathToCheck"></param>
214-
/// <returns><c>true</c> if the filePathToCheck is a python file; otherwise, <c>false</c>.</returns>
215-
public static bool IsPythonFile(string? filePathToCheck)
214+
/// <returns><c>true</c> if the filePathToCheck is a script file; otherwise, <c>false</c>.</returns>
215+
public static bool IsScriptFile(string? filePathToCheck)
216216
{
217-
return HasExtension(filePathToCheck, ".py");
217+
return HasExtension(filePathToCheck, ".py", ".ahk");
218218
}
219219

220220
}

0 commit comments

Comments
 (0)