UI: File Browser Volumes and System Lists Icons
authorHarley Acheson <harley.acheson@gmail.com>
Fri, 6 Dec 2019 21:10:30 +0000 (13:10 -0800)
committerHarley Acheson <harley.acheson@gmail.com>
Fri, 6 Dec 2019 21:10:30 +0000 (13:10 -0800)
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

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

index 958052c8f25f47b749164d9f2a11417b0a77b786..543a45e85c2c7e8a5afac677aab2df7042947f8f 100644 (file)
@@ -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'
index 48d256476e033063ef9b8f13104cdafe5e2da75e..98e1e99116f73b783835912bfde83292d99d7c32 100644 (file)
@@ -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__ */
index ab5fdfd69e05ed57f01514c74cd977c15f6326e6..5f25316cf25315c829a7aeb6de74c91eda146379 100644 (file)
@@ -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;
 
index b26769f2118e93ffbe5203979352c1b40ae27739..77e6266b8306e2b6c0a7ed666f2ed9479eceab5f 100644 (file)
@@ -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);
     }
 
index 7faa2b883f203908d785aba36288f4039ef57fcd..f9506da39a8b5632996e29a3bef9d94d29f4a828 100644 (file)
@@ -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_SYSTEM, mnt->mnt_dir, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
           }
 
           found = 1;
@@ -674,7 +715,8 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
                 label = *label_test ? label_test : dirname;
               }
               BLI_snprintf(line, sizeof(line), "%s%s/", name, dirname);
-              fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, label, FS_INSERT_SORTED);
+              fsmenu_insert_entry(
+                  fsmenu, FS_CATEGORY_SYSTEM, line, label, ICON_NETWORK_DRIVE, FS_INSERT_SORTED);
               found = 1;
             }
           }
@@ -685,7 +727,8 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
 
       /* fallback */
       if (!found) {
-        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, FS_INSERT_SORTED);
+        fsmenu_insert_entry(
+            fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
       }
     }
   }
index a86a552f9f915c52817315aaaa7dfaa89ebc53ea..a33783b19058803e33755b232bc2c6580d109047 100644 (file)
@@ -42,6 +42,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
                          enum FSMenuCategory category,
                          const char *path,
                          const char *name,
+                         const int icon,
                          const enum FSMenuInsert flag);
 
 /** Refresh 'valid' status of given menu entry */
index 7b0f3bf708c2dce1b35c9d245fec8adcc342b675..c26ba5b022da503e0e93af3a3fc327a5d8ad6892 100644 (file)
@@ -2312,6 +2312,18 @@ static int rna_FileBrowser_FSMenuEntry_name_get_editable(PointerRNA *ptr,
   return fsm->save ? PROP_EDITABLE : 0;
 }
 
+static int rna_FileBrowser_FSMenuEntry_icon_get(PointerRNA *ptr)
+{
+  FSMenuEntry *fsm = ptr->data;
+  return ED_fsmenu_entry_get_icon(fsm);
+}
+
+static void rna_FileBrowser_FSMenuEntry_icon_set(PointerRNA *ptr, int value)
+{
+  FSMenuEntry *fsm = ptr->data;
+  ED_fsmenu_entry_set_icon(fsm, value);
+}
+
 static bool rna_FileBrowser_FSMenuEntry_use_save_get(PointerRNA *ptr)
 {
   FSMenuEntry *fsm = ptr->data;
@@ -5573,6 +5585,11 @@ static void rna_def_filemenu_entry(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Name", "");
   RNA_def_struct_name_property(srna, prop);
 
+  prop = RNA_def_property(srna, "icon", PROP_INT, PROP_NONE);
+  RNA_def_property_int_funcs(
+      prop, "rna_FileBrowser_FSMenuEntry_icon_get", "rna_FileBrowser_FSMenuEntry_icon_set", NULL);
+  RNA_def_property_ui_text(prop, "Icon", "");
+
   prop = RNA_def_property(srna, "use_save", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_funcs(prop, "rna_FileBrowser_FSMenuEntry_use_save_get", NULL);
   RNA_def_property_ui_text(
index a6d3adacc14a0b33488b9d207a9f45a8f29ffbfd..42433c9f843f4d2a900f2da9d659607dd704672f 100644 (file)
@@ -261,7 +261,6 @@ void WM_init(bContext *C, int argc, const char **argv)
 
   ED_spacetypes_init(); /* editors/space_api/spacetype.c */
 
-  ED_file_init(); /* for fsmenu */
   ED_node_init_butfuncs();
 
   BLF_init();
@@ -306,6 +305,9 @@ void WM_init(bContext *C, int argc, const char **argv)
   /* Call again to set from userpreferences... */
   BLT_lang_set(NULL);
 
+  /* For fsMenu. Called here so can include user preference paths if needed. */
+  ED_file_init();
+
   /* That one is generated on demand, we need to be sure it's clear on init. */
   IMB_thumb_clear_translations();