[Bf-blender-cvs] [7c2217cd126] master: UI: File Browser Volumes and System Lists Icons

Harley Acheson noreply at git.blender.org
Fri Dec 6 22:21:55 CET 2019


Commit: 7c2217cd126a97df9b1c305f79a605f25c06a229
Author: Harley Acheson
Date:   Fri Dec 6 13:10:30 2019 -0800
Branches: master
https://developer.blender.org/rB7c2217cd126a97df9b1c305f79a605f25c06a229

UI: File Browser Volumes and System Lists Icons

Allows each File Browser list item in Volumes and System to use individual icons.

Differential Revision: https://developer.blender.org/D5802

Reviewed by Julian Eisel

===================================================================

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/editors/space_file/fsmenu.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/intern/wm_init_exit.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 958052c8f25..543a45e85c2 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -165,24 +165,15 @@ class FILEBROWSER_UL_dir(UIList):
     def draw_item(self, _context, layout, _data, item, icon, _active_data, active_propname, _index):
         direntry = item
         # space = context.space_data
-        icon = 'NONE'
-        if active_propname == "system_folders_active":
-            icon = 'DISK_DRIVE'
-        if active_propname == "system_bookmarks_active":
-            icon = 'BOOKMARKS'
-        if active_propname == "bookmarks_active":
-            icon = 'BOOKMARKS'
-        if active_propname == "recent_folders_active":
-            icon = 'FILE_FOLDER'
 
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             row = layout.row(align=True)
             row.enabled = direntry.is_valid
             # Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
             if direntry.is_property_readonly("name"):
-                row.label(text=direntry.name, icon=icon)
+                row.label(text=direntry.name, icon_value=icon)
             else:
-                row.prop(direntry, "name", text="", emboss=False, icon=icon)
+                row.prop(direntry, "name", text="", emboss=False, icon_value=icon)
 
         elif self.layout_type == 'GRID':
             layout.alignment = 'CENTER'
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 48d256476e0..98e1e99116f 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -159,7 +159,7 @@ typedef struct FSMenuEntry {
   char name[256]; /* FILE_MAXFILE */
   short save;
   short valid;
-  short pad[2];
+  int icon;
 } FSMenuEntry;
 
 typedef enum FSMenuCategory {
@@ -197,4 +197,7 @@ void ED_fsmenu_entry_set_path(struct FSMenuEntry *fsentry, const char *path);
 char *ED_fsmenu_entry_get_name(struct FSMenuEntry *fsentry);
 void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name);
 
+int ED_fsmenu_entry_get_icon(struct FSMenuEntry *fsentry);
+void ED_fsmenu_entry_set_icon(struct FSMenuEntry *fsentry, const int icon);
+
 #endif /* __ED_FILESELECT_H__ */
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index ab5fdfd69e0..5f25316cf25 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2153,6 +2153,9 @@ int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, const bool big
   else if (RNA_struct_is_a(ptr->type, &RNA_TextureSlot)) {
     id = RNA_pointer_get(ptr, "texture").data;
   }
+  else if (RNA_struct_is_a(ptr->type, &RNA_FileBrowserFSMenuEntry)) {
+    return RNA_int_get(ptr, "icon");
+  }
   else if (RNA_struct_is_a(ptr->type, &RNA_DynamicPaintSurface)) {
     DynamicPaintSurface *surface = ptr->data;
 
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index b26769f2118..77e6266b830 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -45,6 +45,8 @@
 #include "ED_select_utils.h"
 
 #include "UI_interface.h"
+#include "UI_interface_icons.h"
+#include "UI_resources.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -952,7 +954,8 @@ static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
   if (params->dir[0] != '\0') {
     char name[FILE_MAX];
 
-    fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, NULL, FS_INSERT_SAVE);
+    fsmenu_insert_entry(
+        fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, NULL, ICON_FILE_FOLDER, FS_INSERT_SAVE);
     BLI_make_file_string(
         "/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
     fsmenu_write_file(fsmenu, name);
@@ -1572,6 +1575,7 @@ int file_exec(bContext *C, wmOperator *exec_op)
                           FS_CATEGORY_RECENT,
                           sfile->params->dir,
                           NULL,
+                          ICON_FILE_FOLDER,
                           FS_INSERT_SAVE | FS_INSERT_FIRST);
     }
 
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 7faa2b883f2..f9506da39a8 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -46,6 +46,8 @@
 
 #include "WM_api.h"
 #include "WM_types.h"
+#include "UI_interface_icons.h"
+#include "UI_resources.h"
 
 #ifdef __APPLE__
 #  include <Carbon/Carbon.h>
@@ -162,6 +164,16 @@ void ED_fsmenu_entry_set_path(struct FSMenuEntry *fsentry, const char *path)
   }
 }
 
+int ED_fsmenu_entry_get_icon(struct FSMenuEntry *fsentry)
+{
+  return (fsentry->icon) ? fsentry->icon : ICON_FILE_FOLDER;
+}
+
+void ED_fsmenu_entry_set_icon(struct FSMenuEntry *fsentry, const int icon)
+{
+  fsentry->icon = icon;
+}
+
 static void fsmenu_entry_generate_name(struct FSMenuEntry *fsentry, char *name, size_t name_size)
 {
   int offset = 0;
@@ -258,6 +270,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
                          FSMenuCategory category,
                          const char *path,
                          const char *name,
+                         const int icon,
                          FSMenuInsert flag)
 {
   FSMenuEntry *fsm_prev;
@@ -328,6 +341,9 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
   else {
     fsm_iter->name[0] = '\0';
   }
+
+  ED_fsmenu_entry_set_icon(fsm_iter, icon);
+
   fsmenu_entry_refresh_valid(fsm_iter);
 
   if (fsm_prev) {
@@ -459,7 +475,7 @@ void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename)
         if (BLI_exists(line))
 #endif
         {
-          fsmenu_insert_entry(fsmenu, category, line, name, FS_INSERT_SAVE);
+          fsmenu_insert_entry(fsmenu, category, line, name, ICON_FILE_FOLDER, FS_INSERT_SAVE);
         }
       }
       /* always reset name. */
@@ -504,7 +520,24 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
           name = tmps;
         }
 
-        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, name, FS_INSERT_SORTED);
+        int icon = ICON_DISK_DRIVE;
+        switch (GetDriveType(tmps)) {
+          case DRIVE_REMOVABLE:
+            icon = ICON_EXTERNAL_DRIVE;
+            break;
+          case DRIVE_CDROM:
+            icon = ICON_DISC;
+            break;
+          case DRIVE_FIXED:
+          case DRIVE_RAMDISK:
+            icon = ICON_DISK_DRIVE;
+            break;
+          case DRIVE_REMOTE:
+            icon = ICON_NETWORK_DRIVE;
+            break;
+        }
+
+        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, name, icon, FS_INSERT_SORTED);
       }
     }
 
@@ -512,10 +545,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
     if (read_bookmarks) {
       SHGetSpecialFolderPathW(0, wline, CSIDL_PERSONAL, 0);
       BLI_strncpy_wchar_as_utf8(line, wline, FILE_MAXDIR);
-      fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, FS_INSERT_SORTED);
+      fsmenu_insert_entry(
+          fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_DOCUMENTS, FS_INSERT_SORTED);
       SHGetSpecialFolderPathW(0, wline, CSIDL_DESKTOPDIRECTORY, 0);
       BLI_strncpy_wchar_as_utf8(line, wline, FILE_MAXDIR);
-      fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, FS_INSERT_SORTED);
+      fsmenu_insert_entry(
+          fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_DESKTOP, FS_INSERT_SORTED);
     }
   }
 #else
@@ -546,7 +581,8 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
       /* Add end slash for consistency with other platforms */
       BLI_add_slash(defPath);
 
-      fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, defPath, NULL, FS_INSERT_SORTED);
+      fsmenu_insert_entry(
+          fsmenu, FS_CATEGORY_SYSTEM, defPath, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
     }
 
     CFRelease(volEnum);
@@ -586,7 +622,8 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
         /* Exclude "all my files" as it makes no sense in blender fileselector */
         /* Exclude "airdrop" if wlan not active as it would show "" ) */
         if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
-          fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, FS_INSERT_LAST);
+          fsmenu_insert_entry(
+              fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
         }
 
         CFRelease(pathString);
@@ -604,10 +641,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
 
     if (read_bookmarks && home) {
       BLI_snprintf(line, sizeof(line), "%s/", home);
-      fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, FS_INSERT_SORTED);
+      fsmenu_insert_entry(
+          fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_HOME, FS_INSERT_SORTED);
       BLI_snprintf(line, sizeof(line), "%s/Desktop/", home);
       if (BLI_exists(line)) {
-        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, FS_INSERT_SORTED);
+        fsmenu_insert_entry(
+            fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_DESKTOP, FS_INSERT_SORTED);
       }
     }
 
@@ -641,10 +680,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
           len = strlen(mnt->mnt_dir);
           if (len && mnt->mnt_dir[len - 1] != '/') {
             BLI_snprintf(line, sizeof(line), "%s/", mnt->mnt_dir);
-            fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, NULL, FS_INSERT_SORTED);
+            fsmenu_insert_entry(
+                fsmenu, FS_CATEGORY_SYSTEM, line, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
           }
           else {
-            fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, NULL, FS_INSERT_SORTED);
+            fsmenu_insert_entry(
+                fsmenu, FS_CATEGORY

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list