LoginSignup
1
1

More than 5 years have passed since last update.

ファイル参照URLをパスURLに変換する

Last updated at Posted at 2015-04-28

Problem

10.10 Yosemite 以降では,ファイルのドラッグ&ドロップ時にパスではなく,ファイル参照がクリップボードにキャプチャされるようになりました。
ファイル参照,つまり /.file/id=xxxxxx.xxxxx のような値が入ってきます。
困ります。

Solution

NSTableViewDataSource であれば AcceptDrop あたりで,NSView であれば PerformDragOperation で変換してやります。
10.9以前でもこのまま動作します。

PerformDragOperation.cs
public override bool PerformDragOperation(NSDraggingInfo sender)
{
    var pboard = sender.DraggingPasteboard;
    var typeExists = pboard.Types.Any(x => x == "NSFilenamesPboardType");
    if(!typeExists)
        return false;

    var items = pboard.PasteboardItems;
    var urls = items.Select(x => new NSUrl(x.GetStringForType("public.file-url")).Path);

    return true;
}

Conclusion

Xamarin.Mac ではよくあることです。
特に10.10環境で使いやすいAPIがぐっと増えた一方,破壊的変更も多々あります。
UnifiedAPIであれば10.9 APIレベルを中心に作っていくのがよいと思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1