macOS/File Browser: Support external operations #107267

Open
Ankit Meel wants to merge 10 commits from ankitm/blender:ankitm/finderreveal into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Building upon blender/blender#104531,
This PR adds support for the following external operations:

  • open: open file in the default app
  • reveal in finder: opens a window with the file/folder selected
  • open in terminal: opens a terminal window with selected folder or parent folder
    of file.
  • get info: opens finder get info window of the file/folder.

image
image

Some UI text and variable rename cleanup has also been done after
review comments in #104531 .


open is not done using service since it shows a popup "blender wants to use the
restricted service "open" confirm/cancel" on every use. So not friendly
enough. sharedWorkspace is used instead

image

Though I'm not super keen on the location.. delete and rename also show up in context menu in Finder.

I'd only want to add reveal in finder and that too

  • in file menu for open file
  • and in base context menu in file browser (not under external submenu)
Building upon blender/blender#104531, This PR adds support for the following external operations: - open: open file in the default app - reveal in finder: opens a window with the file/folder selected - open in terminal: opens a terminal window with selected folder or parent folder of file. - get info: opens finder get info window of the file/folder. ![image](/attachments/d4a53783-6a7b-4d57-8f6a-1194e015da4b) ![image](/attachments/12432193-ed33-4d54-bae9-e20264d829b8) Some UI text and variable rename cleanup has also been done after review comments in #104531 . ------ open is not done using service since it shows a popup "blender wants to use the restricted service "open" confirm/cancel" on every use. So not friendly enough. sharedWorkspace is used instead ![image](/attachments/1a1830fc-5c95-46ec-bc3e-cdc88309bd5d) Though I'm not super keen on the location.. delete and rename also show up in context menu in Finder. I'd only want to add reveal in finder and that too - in file menu for open file - and in base context menu in file browser (not under external submenu)
Ankit Meel added 1 commit 2023-04-23 14:30:02 +02:00
Supports the following external operations:
- reveal in finder: opens a window with the file/folder selected
- open in terminal: opens a terminal window with folder or parent folder
  of file.
- get info: opens finder get info window of the file/folder.

open is not done since it shows a popup "blender wants to use the
restricted service "open" confirm/cancel" on every use. So not friendly
enough.
Ankit Meel added 1 commit 2023-04-23 14:31:50 +02:00
Ankit Meel requested review from Brecht Van Lommel 2023-04-23 14:31:50 +02:00
Ankit Meel requested review from Harley Acheson 2023-04-23 14:31:51 +02:00
Ankit Meel requested review from Julian Eisel 2023-04-23 14:31:51 +02:00
Ankit Meel added the
Module
User Interface
Platform
macOS
Interest
User Interface
labels 2023-04-23 14:32:14 +02:00
Ankit Meel added this to the User Interface project 2023-04-23 14:32:28 +02:00
Ankit Meel added 1 commit 2023-04-23 14:36:46 +02:00
Ankit Meel added 1 commit 2023-04-23 14:40:25 +02:00
Ankit Meel added 1 commit 2023-04-23 14:43:54 +02:00
Julian Eisel requested changes 2023-04-24 16:52:46 +02:00
@ -1790,0 +1780,4 @@
ICON_NONE,
#ifdef __APPLE__
"Reveal in Finder",
"Reveal location in Finder"
Member

How about "Display this file in a new Finder window"?

The existing descriptions here aren't great either, noted that in #104531.

How about `"Display this file in a new Finder window"`? The existing descriptions here aren't great either, noted that in #104531.
@ -1790,0 +1791,4 @@
ICON_NONE,
#ifdef __APPLE__
"Reveal in Finder",
"Reveal location in Finder"
Member

"Display this directory in a new Finder window"? (Is it the selected directory or the current directory?)

`"Display this directory in a new Finder window"`? (Is it the selected directory or the current directory?)
@ -1793,0 +1816,4 @@
ICON_NONE,
#ifdef __APPLE__
"Get Info",
"Open the Get Info window for this item"
Member

Use "file" instead of "item".

Use "file" instead of "item".
Author
Member

Test comment

Test comment
Member

This is awesome.

There seems to be one omission here though. As far as I knew the existing code on Mac for "Open" used "WM_OT_path_open", which is python subprocess.check_call(["open", filepath]). If given a document filepath it should open up the associated program with that file loaded. That is definitely how it works on Windows and on Linux (demonstrated by Pablo in Blender Today). But looking at your changes here it looks like "open" and "folder open" are doing the same thing, just opening up a Finder window that contains the file with both described the same as "Reveal location in Finder".

Of course I could be wrong about the behavior of subprocess.check_call(["open", filepath]) as I don't have a mac but fairly certain we were using that to open up your web browser from an html file. Does it show the warning you posted for other uses of "WM_OT_path_open"? For example right-clicking on an input that contains a filepath and there should be "open" that has a description of "Open File Externally"

One thing I'd recommend is trying to unify these as much as possible between platforms. So if an operation is similar we should try to name and describe them similarly. Even though I do prefer to use language expected on each platform.

For example we might consider changing FILE_EXTERNAL_OPERATION_FOLDER_CMD ("CMD") to FILE_EXTERNAL_OPERATION_FOLDER_TERMINAL ("TERMINAL") as that fits both well and a bit more generic. Similarly FILE_EXTERNAL_OPERATION_PROPERTIES ("PROPERTIES") might be better as FILE_EXTERNAL_OPERATION_INFO ("INFO"). A more generic descriptor for FILE_EXTERNAL_OPERATION_RUNAS ("RUNAS") might be FILE_EXTERNAL_OPERATION_SUDO ("SUDO")?

Then perhaps standardize on such words as "folder" (instead of directory) and keep as much as possible the same, but still varying by platform when needed.

This is awesome. There seems to be one omission here though. As far as I knew the existing code on Mac for "Open" used "WM_OT_path_open", which is python `subprocess.check_call(["open", filepath])`. If given a document filepath it should open up the associated program with that file loaded. That is definitely how it works on Windows and on Linux (demonstrated by Pablo in Blender Today). But looking at your changes here it looks like "open" and "folder open" are doing the same thing, just opening up a Finder window that contains the file with both described the same as "Reveal location in Finder". Of course I could be wrong about the behavior of `subprocess.check_call(["open", filepath])` as I don't have a mac but fairly certain we were using that to open up your web browser from an html file. Does it show the warning you posted for other uses of "WM_OT_path_open"? For example right-clicking on an input that contains a filepath and there should be "open" that has a description of "Open File Externally" One thing I'd recommend is trying to unify these as much as possible between platforms. So if an operation is similar we should try to name and describe them similarly. Even though I do prefer to use language expected on each platform. For example we might consider changing `FILE_EXTERNAL_OPERATION_FOLDER_CMD` ("CMD") to `FILE_EXTERNAL_OPERATION_FOLDER_TERMINAL` ("TERMINAL") as that fits both well and a bit more generic. Similarly `FILE_EXTERNAL_OPERATION_PROPERTIES` ("PROPERTIES") might be better as `FILE_EXTERNAL_OPERATION_INFO` ("INFO"). A more generic descriptor for `FILE_EXTERNAL_OPERATION_RUNAS` ("RUNAS") might be `FILE_EXTERNAL_OPERATION_SUDO` ("SUDO")? Then perhaps standardize on such words as "folder" (instead of directory) and keep as much as possible the same, but still varying by platform when needed.
Author
Member

To open the file using WM_OT_path_open, Context would need to be passed to storage_apple.mm. The confirmation popup doesn't show up.
To open the file using service, it's cleaner in code but the popup shows up.

I'll check again

Agree with the renames of enums and descriptions, will change that. FILE_EXTERNAL_OPERATION_RUNAS is not a thing on mac at all.. so will not do that.

To open the file using WM_OT_path_open, Context would need to be passed to storage_apple.mm. The confirmation popup doesn't show up. To open the file using service, it's cleaner in code but the popup shows up. I'll check again Agree with the renames of enums and descriptions, will change that. FILE_EXTERNAL_OPERATION_RUNAS is not a thing on mac at all.. so will not do that.
Ankit Meel changed title from macOS/File Browser: Support external operations to WIP: macOS/File Browser: Support external operations 2023-04-25 07:02:01 +02:00
Ankit Meel added 1 commit 2023-04-29 15:29:32 +02:00
Ankit Meel added 1 commit 2023-04-29 15:35:25 +02:00
Ankit Meel requested review from Ray molenkamp 2023-04-29 17:30:22 +02:00
Ankit Meel added 1 commit 2023-04-30 06:53:53 +02:00
Julian Eisel requested changes 2023-04-30 13:44:45 +02:00
Julian Eisel left a comment
Member

Mostly fine, although I can’t say much about the Obj-C code. Just some polishing for user messages needed.

Mostly fine, although I can’t say much about the Obj-C code. Just some polishing for user messages needed.
@ -118,2 +118,4 @@
* \{ */
/**
* All operations may not be supported on all platforms.
Member

“Not all operations may be supported on all platforms.”

“Not all operations may be supported on all platforms.”
ankitm marked this conversation as resolved
@ -1790,0 +1779,4 @@
"OPEN",
ICON_NONE,
"Open",
"Open the file in its default application"},
Member

“Open this file…” (like the other descriptions).

“Open **this** file…” (like the other descriptions).
ankitm marked this conversation as resolved
@ -1790,0 +1788,4 @@
"Reveal this file in a new Finder window"
#else
"Reveal in File Explorer",
"Open this file in system file browser"
Member

“in a system file browser“

“in **a** system file browser“
ankitm marked this conversation as resolved
@ -1790,0 +1791,4 @@
"Open this file in system file browser"
#endif
},
{FILE_EXTERNAL_OPERATION_EDIT, "EDIT", ICON_NONE, "Edit", "Edit the file"},
Member

“…this file…”

“…this file…”
ankitm marked this conversation as resolved
Member

I'm not understanding the change of FILE_EXTERNAL_OPERATION_FOLDER_OPEN to FILE_EXTERNAL_OPERATION_FILE_REVEAL

Some of these operations are on documents and some are on folder paths. If the subject is a folder though then there is no file to be "revealed", and we are simply "opening" the "folder".

I can understand perhaps wanting to add a new operation though, where the subject is a file and the operation opens its containing folder and then ensures that the file is in view and/or highlighted in some way. But I don't see having an FILE_EXTERNAL_OPERATION_FILE_REVEAL operation on a directory path, with enum value "FOLDER_OPEN" that doesn't match and a description that includes "Open this file" (neither verb nor subject matching).

I'm not understanding the change of `FILE_EXTERNAL_OPERATION_FOLDER_OPEN` to `FILE_EXTERNAL_OPERATION_FILE_REVEAL` Some of these operations are on documents and some are on folder paths. If the subject is a folder though then there is no file to be "revealed", and we are simply "opening" the "folder". I can understand perhaps wanting to add a new operation though, where the subject is a file and the operation opens its containing folder and then ensures that the file is in view and/or highlighted in some way. But I don't see having an `FILE_EXTERNAL_OPERATION_FILE_REVEAL` operation on a directory path, with enum value "FOLDER_OPEN" that doesn't match and a description that includes "Open this file" (neither verb nor subject matching).
Author
Member

reveal in finder: opens a window with the file/folder selected

On windows, the file path is also passed down instead of just root. So it can be used to match OS behaviour

But I don't see having an FILE_EXTERNAL_OPERATION_FILE_REVEAL operation on a directory path, with enum value "FOLDER_OPEN" that doesn't match and a description that includes "Open this file" (neither verb nor subject matching).

My bad missed it

> reveal in finder: opens a window with the file/folder selected On windows, the file path is also passed down instead of just root. So it can be used to match OS behaviour > But I don't see having an FILE_EXTERNAL_OPERATION_FILE_REVEAL operation on a directory path, with enum value "FOLDER_OPEN" that doesn't match and a description that includes "Open this file" (neither verb nor subject matching). My bad missed it
Member

On windows, the file path is also passed down instead of just root. So it can be used to match OS behaviour

Still not following. I am in File Browser and I right-click on a folder. There is no "file" to "reveal", just a "folder" to "open".

> On windows, the file path is also passed down instead of just root. So it can be used to match OS behaviour Still not following. I am in File Browser and I right-click on a **folder**. There is no "file" to "reveal", just a "folder" to "open".
Ankit Meel added 1 commit 2023-05-01 14:37:01 +02:00
Ankit Meel changed title from WIP: macOS/File Browser: Support external operations to macOS/File Browser: Support external operations 2023-05-01 14:37:21 +02:00
Member

I am very pleased to see the list of operations expanded more than I expected, but I didn't test for that. So I am hoping you can add a case for FILE_EXTERNAL_OPERATION_FILE_REVEAL at the very end of the switch in windows_operation_string and just have it return "".

And then just add a check for empty operation in BLI_windows_external_operation_supported, by just starting that function with:

  if (operation == NULL || operation[0] == 0) {
    return false;
  }

That should be enough for this to work correctly on Windows.

In the file_external_operation enum for FILE_EXTERNAL_OPERATION_FOLDER_OPEN for not Apple the name should be "Open in File Explorer" as we don't use "reveal" anywhere for that type of operation.

In file_os_operations_menu_item you have replaced FILE_EXTERNAL_OPERATION_FOLDER_OPEN with FILE_EXTERNAL_OPERATION_FILE_REVEAL but we need the former on Windows. Otherwise we don't get the option to open the containing folder for a document.

I have some concern about uses of "File Explorer" for non-Apple cases. I love that you use "Finder" for Apple, but at least FILE_EXTERNAL_OPERATION_FOLDER_OPEN should work for Linux and that might be confusing. We could add an else for Windows for the specific phrase or use something more generic.

I am **very pleased** to see the list of operations expanded more than I expected, but I didn't test for that. So I am _hoping_ you can add a case for `FILE_EXTERNAL_OPERATION_FILE_REVEAL` at the very end of the switch in `windows_operation_string` and just have it return "". And then just add a check for empty operation in `BLI_windows_external_operation_supported`, by just starting that function with: ```C if (operation == NULL || operation[0] == 0) { return false; } ``` That should be enough for this to work correctly on Windows. In the file_external_operation enum for `FILE_EXTERNAL_OPERATION_FOLDER_OPEN` for **not** Apple the name should be "Open in File Explorer" as we don't use "reveal" anywhere for that type of operation. In `file_os_operations_menu_item` you have replaced `FILE_EXTERNAL_OPERATION_FOLDER_OPEN` with `FILE_EXTERNAL_OPERATION_FILE_REVEAL` but we need the former on Windows. Otherwise we don't get the option to open the containing folder for a document. I have _some_ concern about uses of "File Explorer" for non-Apple cases. I love that you use "Finder" for Apple, but at least FILE_EXTERNAL_OPERATION_FOLDER_OPEN should work for Linux and that might be confusing. We could add an else for Windows for the specific phrase or use something more generic.
Ankit Meel added 1 commit 2023-05-01 18:43:51 +02:00
Raul Fernandez Hernandez approved these changes 2024-03-02 18:10:49 +01:00
First-time contributor

Nice! I would also like see a "Copy full path to clipboard" item being added. I don't think this is supported in any way in the current Blender version, right? I often need to obtain the full file path for use in scripts, etc.

Nice! I would also like see a "Copy full path to clipboard" item being added. I don't think this is supported in any way in the current Blender version, right? I often need to obtain the full file path for use in scripts, etc.
This pull request has changes conflicting with the target branch.
  • source/blender/blenlib/intern/fileops.c
  • source/blender/blenlib/intern/winstuff.c
  • source/blender/editors/space_file/file_ops.c

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u ankitm/finderreveal:ankitm-ankitm/finderreveal
git checkout ankitm-ankitm/finderreveal
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107267
No description provided.