UI: Windows "Quick Access" items to File Browser System List #108431

Merged
Harley Acheson merged 5 commits from RedMser/blender:quick-access-fs-2 into main 2023-08-16 22:36:14 +02:00
Contributor

On the Windows platform add any Explorer "Quick Access" items to the
bottom of the File Browser "System" List in the sidebar.


Resurrection of D13971

Adds the Quick Access list of Windows Explorer to the file browser.

image

image

TODO

  • Only tested on Windows 10 and 11, should check Windows 8 as well.
  • While the UI isn't pretty, it seems to be beneficial to combine all entries into one longer list, and it saves space. Waiting for feedback from UI module.
  • Filter out .zip files.
On the Windows platform add any Explorer "Quick Access" items to the bottom of the File Browser "System" List in the sidebar. --- Resurrection of [D13971](https://archive.blender.org/developer/D13971) Adds the Quick Access list of Windows Explorer to the file browser. ![image](/attachments/aa4ff21b-a552-4ef1-a2e0-01662d5ffb0b) ![image](/attachments/9bbff68f-9985-46d6-bd11-4c84bb68b0e5) ### TODO - [ ] Only tested on Windows 10 and 11, should check Windows 8 as well. - [ ] While the UI isn't pretty, it seems to be beneficial to combine all entries into one longer list, and it saves space. Waiting for feedback from UI module. - [ ] Filter out `.zip` files.
RedMser changed title from UI: Add Quick Access to System List for Windows to File Browser: Add "Quick Access" items to sidebar on Windows 2023-05-30 18:39:47 +02:00
RedMser force-pushed quick-access-fs-2 from 0a21c70331 to 2ad0b76c13 2023-05-30 18:40:33 +02:00 Compare
Iliya Katushenock added this to the User Interface project 2023-05-30 18:40:50 +02:00
Iliya Katushenock added the
Platform
Windows
label 2023-05-30 18:40:57 +02:00
Brecht Van Lommel requested review from Harley Acheson 2023-05-30 19:09:03 +02:00
Brecht Van Lommel requested review from Ray molenkamp 2023-05-30 19:09:04 +02:00
Member

There's a few technical problems, the printf's, the goto's etc, but nothing unsurmountable, before we spend time on that i'd like the UI people to sign off on this first.

cc: @pablovazquez

There's a few technical problems, the printf's, the goto's etc, but nothing unsurmountable, before we spend time on that i'd like the UI people to sign off on this first. cc: @pablovazquez
Member

Interesting, but might need some thought.

Windows does put the "Quick Access" items at the top of the Navigation Pane (left side of Explorer windows). And also calls them "Frequent Folders" at times too.

image

But it is also variable in length and Windows treats it as a separate list that can be closed/open and we don't really have that option. So my initial gut feeling is that these items might be better appended to the end of the System list, not prepended to the top. That way they can get as long as you want but we'd continue to show consistent items at the top of the list.

Whenever this topic comes up about adding to these lists I start thinking about how I would prefer that "Volumes" and "System" were combined into a single list with a curated order. It would use some valuable space (the current gap between the two lists), and would allow to more quickly close them to better view the lists below.

Interesting, but might need some thought. Windows does put the "Quick Access" items at the top of the Navigation Pane (left side of Explorer windows). And also calls them "Frequent Folders" at times too. ![image](/attachments/70069e13-177e-4c20-b1a6-a6f7805a3cc9) But it is also variable in length and Windows treats it as a separate list that can be closed/open and we don't really have that option. So my initial gut feeling is that these items might be better appended to the end of the System list, not prepended to the top. That way they can get as long as you want but we'd continue to show consistent items at the top of the list. Whenever this topic comes up about adding to these lists I start thinking about how I would prefer that "Volumes" and "System" were combined into a single list with a curated order. It would use some valuable space (the current gap between the two lists), and would allow to more quickly close them to better view the lists below.
Member

Another reason to append the Quick Access items to the System list is because the current items area added with appropriate icons. When these items are added first they will get generic folder icons, even if you have Desktop or Documents in your list. When added afterward the items check for duplicates and icons.

Here is a quick (and barely tested) attempt to remove the "gotos":

diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 7b6745f2a09..93b9d58bae9 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -615,12 +615,105 @@ void fsmenu_read_bookmarks(FSMenu *fsmenu, const char *filepath)
     }
   }
   fclose(fp);
 }
 
 #ifdef WIN32
+
+/* Add Windows Quick Access items to the System list. */
+static void fsmenu_add_windows_quick_access(struct FSMenu *fsmenu,
+                                            FSMenuCategory category,
+                                            FSMenuInsert flag)
+{
+  VARIANT var;
+  IShellDispatch *shell = NULL;
+  HRESULT hr;
+
+  /* Get shell COM object. */
+  hr = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_ALL, &IID_IShellDispatch, (void **)&shell);
+  if (FAILED(hr)) {
+    shell = NULL;
+  }
+
+  /* Open Quick Access folder. */
+  Folder *dir = NULL;
+  if (shell) {
+    VariantInit(&var);
+    V_VT(&var) = VT_BSTR;
+    V_BSTR(&var) = SysAllocString(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}");
+    hr = shell->lpVtbl->NameSpace(shell, var, &dir);
+    SysFreeString(V_BSTR(&var));
+    if (FAILED(hr)) {
+      dir = NULL;
+    }
+  }
+
+  /* Get FolderItems. */
+  FolderItems *items = NULL;
+  if (dir) {
+    hr = dir->lpVtbl->Items(dir, &items);
+    if (FAILED(hr)) {
+      items = NULL;
+    }
+  }
+
+  long count = 0;
+  if (items) {
+    hr = items->lpVtbl->get_Count(items, &count);
+    if (FAILED(hr)) {
+      count = 0;
+    }
+  }
+
+  /* Iterate through the folder. */
+  for (long i = 0; i < count; i++) {
+    FolderItem *item;
+
+    V_VT(&var) = VT_I4;
+    V_I4(&var) = i;
+    hr = items->lpVtbl->Item(items, var, &item);
+    if (FAILED(hr)) {
+      continue;
+    }
+
+    VARIANT_BOOL isFolder;
+    hr = item->lpVtbl->get_IsFolder(item, &isFolder);
+    /* Skip if it's not a folder. */
+    if (FAILED(hr) || isFolder == VARIANT_FALSE) {
+      item->lpVtbl->Release(item);
+      continue;
+    }
+
+    BSTR path = NULL;
+    hr = item->lpVtbl->get_Path(item, &path);
+    if (FAILED(hr)) {
+      path = NULL;
+    }
+
+    /* Add folder to the fsmenu. */
+    char utf_path[FILE_MAXDIR];
+    if (path) {
+      BLI_strncpy_wchar_as_utf8(utf_path, path, FILE_MAXDIR);
+      SysFreeString(path);
+      fsmenu_insert_entry(fsmenu, category, utf_path, NULL, ICON_FILE_FOLDER, flag);
+    }
+
+    item->lpVtbl->Release(item);
+  }
+
+  if (items) {
+    items->lpVtbl->Release(items);
+  }
+  if (dir) {
+    dir->lpVtbl->Release(dir);
+  }
+  if (shell) {
+    shell->lpVtbl->Release(shell);
+  }
+}
+
 /* Add a Windows known folder path to the System list. */
 static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
                                       FSMenuCategory category,
                                       REFKNOWNFOLDERID rfid,
                                       const char *name,
                                       const int icon,
@@ -771,12 +864,15 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
                                 FS_INSERT_LAST);
 
       /* These items are just put in path cache for thumbnail views and if bookmarked. */
 
       fsmenu_add_windows_folder(
           fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST);
+
+      /* Last add Quick Access items to avoid duplicates and use icons if available. */
+      fsmenu_add_windows_quick_access(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_INSERT_LAST);
     }
   }
 #elif defined(__APPLE__)
   {
     /* We store some known macOS system paths and corresponding icons
      * and names in the FS_CATEGORY_OTHER (not displayed directly) category. */


Another reason to **append** the Quick Access items to the System list is because the current items area added with appropriate icons. When these items are added first they will get generic folder icons, even if you have Desktop or Documents in your list. When added afterward the items check for duplicates and icons. Here is a quick (and barely tested) attempt to remove the "gotos": ```Diff diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 7b6745f2a09..93b9d58bae9 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -615,12 +615,105 @@ void fsmenu_read_bookmarks(FSMenu *fsmenu, const char *filepath) } } fclose(fp); } #ifdef WIN32 + +/* Add Windows Quick Access items to the System list. */ +static void fsmenu_add_windows_quick_access(struct FSMenu *fsmenu, + FSMenuCategory category, + FSMenuInsert flag) +{ + VARIANT var; + IShellDispatch *shell = NULL; + HRESULT hr; + + /* Get shell COM object. */ + hr = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_ALL, &IID_IShellDispatch, (void **)&shell); + if (FAILED(hr)) { + shell = NULL; + } + + /* Open Quick Access folder. */ + Folder *dir = NULL; + if (shell) { + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"); + hr = shell->lpVtbl->NameSpace(shell, var, &dir); + SysFreeString(V_BSTR(&var)); + if (FAILED(hr)) { + dir = NULL; + } + } + + /* Get FolderItems. */ + FolderItems *items = NULL; + if (dir) { + hr = dir->lpVtbl->Items(dir, &items); + if (FAILED(hr)) { + items = NULL; + } + } + + long count = 0; + if (items) { + hr = items->lpVtbl->get_Count(items, &count); + if (FAILED(hr)) { + count = 0; + } + } + + /* Iterate through the folder. */ + for (long i = 0; i < count; i++) { + FolderItem *item; + + V_VT(&var) = VT_I4; + V_I4(&var) = i; + hr = items->lpVtbl->Item(items, var, &item); + if (FAILED(hr)) { + continue; + } + + VARIANT_BOOL isFolder; + hr = item->lpVtbl->get_IsFolder(item, &isFolder); + /* Skip if it's not a folder. */ + if (FAILED(hr) || isFolder == VARIANT_FALSE) { + item->lpVtbl->Release(item); + continue; + } + + BSTR path = NULL; + hr = item->lpVtbl->get_Path(item, &path); + if (FAILED(hr)) { + path = NULL; + } + + /* Add folder to the fsmenu. */ + char utf_path[FILE_MAXDIR]; + if (path) { + BLI_strncpy_wchar_as_utf8(utf_path, path, FILE_MAXDIR); + SysFreeString(path); + fsmenu_insert_entry(fsmenu, category, utf_path, NULL, ICON_FILE_FOLDER, flag); + } + + item->lpVtbl->Release(item); + } + + if (items) { + items->lpVtbl->Release(items); + } + if (dir) { + dir->lpVtbl->Release(dir); + } + if (shell) { + shell->lpVtbl->Release(shell); + } +} + /* Add a Windows known folder path to the System list. */ static void fsmenu_add_windows_folder(struct FSMenu *fsmenu, FSMenuCategory category, REFKNOWNFOLDERID rfid, const char *name, const int icon, @@ -771,12 +864,15 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks) FS_INSERT_LAST); /* These items are just put in path cache for thumbnail views and if bookmarked. */ fsmenu_add_windows_folder( fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST); + + /* Last add Quick Access items to avoid duplicates and use icons if available. */ + fsmenu_add_windows_quick_access(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_INSERT_LAST); } } #elif defined(__APPLE__) { /* We store some known macOS system paths and corresponding icons * and names in the FS_CATEGORY_OTHER (not displayed directly) category. */ ```
RedMser force-pushed quick-access-fs-2 from 2ad0b76c13 to 75ae4e8e25 2023-06-16 15:34:45 +02:00 Compare
Author
Contributor

@Harley Thanks for fixing up the code! I carried over your changes, as well as adding a bit of logic to filter out library folders (.library-ms) since those show up as greyed-out files.

Can someone test if this works on Windows 11 (or start buildbot)? I can't copy my Win10 build to my Win11 PC and don't have a development environment set up there either.

UPDATE: Tried on Windows 11, and it seems to include recently opened .zip files as well which should probably be filtered out.

@Harley Thanks for fixing up the code! I carried over your changes, as well as adding a bit of logic to filter out library folders (`.library-ms`) since those show up as greyed-out files. Can someone test if this works on Windows 11 (or start buildbot)? I can't copy my Win10 build to my Win11 PC and don't have a development environment set up there either. UPDATE: Tried on Windows 11, and it seems to include recently opened `.zip` files as well which should probably be filtered out.
Member

@blender-bot package windows

@blender-bot package windows
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR108431) when ready.
Member

Just wanted to expound a bit more on why I like this.

I personally feel that the immediate user benefit is relatively minor. But I REALLY like idea of having this code in. First because others might later disagree with me that the benefit is minor and/or might want to make these items more prominent. The code would be in place and there aren't that many people familiar with the Windows API.

But the second reason is that this also fits with my desire to eventually, one day, get a "computer home" listing in the main area of File Browser. In a nutshell this means that the ultimate parent of all drives would a single listing of all drives, shares, bookmarks, etc. Similar to the "This PC" list on Windows. This way the File Browser could, be used without the left-side panels if the available area is constrained.

Just wanted to expound a bit more on why I like this. I personally feel that the immediate user benefit is _relatively_ minor. But I REALLY like idea of having this code in. First because others might later disagree with me that the benefit is minor and/or might want to make these items more prominent. The code would be in place and there aren't that many people familiar with the Windows API. But the second reason is that this also fits with my desire to eventually, one day, get a "computer home" listing in the main area of File Browser. In a nutshell this means that the ultimate parent of all drives would a single listing of all drives, shares, bookmarks, etc. Similar to the "This PC" list on Windows. This way the File Browser could, be used without the left-side panels if the available area is constrained.
Member

This works quite well.

This works quite well.
Harley Acheson approved these changes 2023-06-30 00:34:09 +02:00
Member

@LazyDodo - What do you think of the code?

@LazyDodo - What do you think of the code?
Harley Acheson added 1 commit 2023-08-16 01:08:00 +02:00
Harley Acheson added 1 commit 2023-08-16 01:09:58 +02:00
First-time contributor

Will we ever be able to rearrange those panels and keep Bookmarks or Recent permanently at the top?

Will we ever be able to rearrange those panels and keep Bookmarks or Recent permanently at the top?
Member

Given this is a C++ file now, some more cleanups can be done, WRL was already used in the trackpad code, so that be safe to use, comutil for the _variant_t and _bstr_t types is new (but should be safe), we'd definitely have to check with the bots

#  include <comdef.h>
#  include <comutil.h>
#  include <wrl.h>


...

static void fsmenu_add_windows_quick_access(struct FSMenu *fsmenu,
                                            FSMenuCategory category,
                                            FSMenuInsert flag)
{
  Microsoft::WRL::ComPtr<IShellDispatch> shell;
  if (FAILED(CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_ALL, IID_PPV_ARGS(shell.GetAddressOf()))))
  {
    return;
  }

  /* Open Quick Access folder. */
  Microsoft::WRL::ComPtr<Folder> dir;
  if (FAILED(shell->NameSpace(_variant_t(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"),
                              dir.GetAddressOf())))
  {
    return;
  }

  /* Get FolderItems. */
  Microsoft::WRL::ComPtr<FolderItems> items;
  if (FAILED(dir->Items(items.GetAddressOf()))) {
    return;
  }

  long count = 0;
  if (FAILED(items->get_Count(&count))) {
    return;
  }

  /* Iterate through the folder. */
  for (long i = 0; i < count; i++) {
    Microsoft::WRL::ComPtr<FolderItem> item;

    if (FAILED(items->Item(_variant_t(i), item.GetAddressOf()))) {
      continue;
    }

    VARIANT_BOOL isFolder;
    /* Skip if it's not a folder. */
    if (FAILED(item->get_IsFolder(&isFolder)) || isFolder == VARIANT_FALSE) {
      continue;
    }

    _bstr_t path;
    if (FAILED(item->get_Path(path.GetAddress()))) {
      continue;
    }

    char utf_path[FILE_MAXDIR];
    BLI_strncpy_wchar_as_utf8(utf_path, path, FILE_MAXDIR);

    /* Skip library folders since they are not currently supported. */
    if (!BLI_strcasestr(utf_path, ".library-ms")) {
      /* Add folder to the fsmenu. */
      fsmenu_insert_entry(fsmenu, category, utf_path, NULL, ICON_FILE_FOLDER, flag);
    }
  }
}
Given this is a C++ file now, some more cleanups can be done, WRL was already used in the trackpad code, so that be safe to use, comutil for the `_variant_t` and `_bstr_t` types is new (but should be safe), we'd definitely have to check with the bots ``` # include <comdef.h> # include <comutil.h> # include <wrl.h> ... static void fsmenu_add_windows_quick_access(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuInsert flag) { Microsoft::WRL::ComPtr<IShellDispatch> shell; if (FAILED(CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_ALL, IID_PPV_ARGS(shell.GetAddressOf())))) { return; } /* Open Quick Access folder. */ Microsoft::WRL::ComPtr<Folder> dir; if (FAILED(shell->NameSpace(_variant_t(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"), dir.GetAddressOf()))) { return; } /* Get FolderItems. */ Microsoft::WRL::ComPtr<FolderItems> items; if (FAILED(dir->Items(items.GetAddressOf()))) { return; } long count = 0; if (FAILED(items->get_Count(&count))) { return; } /* Iterate through the folder. */ for (long i = 0; i < count; i++) { Microsoft::WRL::ComPtr<FolderItem> item; if (FAILED(items->Item(_variant_t(i), item.GetAddressOf()))) { continue; } VARIANT_BOOL isFolder; /* Skip if it's not a folder. */ if (FAILED(item->get_IsFolder(&isFolder)) || isFolder == VARIANT_FALSE) { continue; } _bstr_t path; if (FAILED(item->get_Path(path.GetAddress()))) { continue; } char utf_path[FILE_MAXDIR]; BLI_strncpy_wchar_as_utf8(utf_path, path, FILE_MAXDIR); /* Skip library folders since they are not currently supported. */ if (!BLI_strcasestr(utf_path, ".library-ms")) { /* Add folder to the fsmenu. */ fsmenu_insert_entry(fsmenu, category, utf_path, NULL, ICON_FILE_FOLDER, flag); } } } ```
Harley Acheson added 2 commits 2023-08-16 19:40:11 +02:00
Member

@blender-bot build

@blender-bot build
Ray molenkamp approved these changes 2023-08-16 21:56:13 +02:00
Member

Thanks @RedMser !!

Thanks @RedMser !!
Harley Acheson changed title from File Browser: Add "Quick Access" items to sidebar on Windows to UI: Windows "Quick Access" items to File Browser System List 2023-08-16 22:31:28 +02:00
Harley Acheson merged commit f1e7fe5492 into main 2023-08-16 22:36:14 +02:00
Author
Contributor

Thanks for the review and also for updating my very rudimentary code! Exciting to get to use this feature myself :D

Thanks for the review and also for updating my very rudimentary code! Exciting to get to use this feature myself :D
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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#108431
No description provided.