Skip to content

Commit

Permalink
Check file exists for PresentFileExternally
Browse files Browse the repository at this point in the history
mac's native method will not open file if file is not exists

in this case, we fallback to `OpenFileExternally`, so that we can show the folder and without highlight

Co-Authored-By: PercyDan <[email protected]>
  • Loading branch information
cdwcgt and PercyDan54 committed Aug 26, 2024
1 parent 6badea3 commit c1fd956
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions osu.Framework/Platform/MacOS/MacOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using osu.Framework.Extensions;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Logging;
using osu.Framework.Platform.MacOS.Native;

namespace osu.Framework.Platform.MacOS
Expand Down Expand Up @@ -53,6 +53,29 @@ protected override void Swap()
Renderer.WaitUntilIdle();
}

public override bool PresentFileExternally(string filename)
{
string folderPath = Path.GetDirectoryName(filename);

if (folderPath == null)
{
Logger.Log($"Failed to get directory for {filename}", level: LogLevel.Debug);
return false;
}

if (!File.Exists(filename) && !Directory.Exists(filename))
{
Logger.Log($"Cannot find file for '{filename}'", level: LogLevel.Debug);

// Open the folder without the file selected if we can't find the file
OpenFileExternally(folderPath);
return true;
}

Finder.OpenFolderAndSelectItem(filename);
return true;
}

protected override IEnumerable<InputHandler> CreateAvailableInputHandlers()
{
var handlers = base.CreateAvailableInputHandlers();
Expand All @@ -67,11 +90,6 @@ protected override IEnumerable<InputHandler> CreateAvailableInputHandlers()
return handlers;
}

public override bool PresentFileExternally(string filename)
{
return Finder.OpenFolderAndSelectItem(filename.TrimDirectorySeparator());
}

public override IEnumerable<KeyBinding> PlatformKeyBindings => KeyBindings;

/// <summary>
Expand Down

0 comments on commit c1fd956

Please sign in to comment.