[Bf-blender-cvs] [6f67257ee06] filebrowser_redesign: Make the column header interactive

Julian Eisel noreply at git.blender.org
Mon Jul 22 22:42:09 CEST 2019


Commit: 6f67257ee0630486cfdb92a5c22a3f424e9d0917
Author: Julian Eisel
Date:   Mon Jul 22 22:36:59 2019 +0200
Branches: filebrowser_redesign
https://developer.blender.org/rB6f67257ee0630486cfdb92a5c22a3f424e9d0917

Make the column header interactive

Clicking on the column header will sort the file list based on the
clicked column. Note that sorting by time only is not supported, sorting
by date already sorts by time and date.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index cc4dc4d00e0..fd84a4f1fc2 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -1825,6 +1825,7 @@ def km_file_browser_main(params):
          {"properties": [("mode", 'ADD')]}),
         ("file.rename", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True}, None),
         ("file.highlight", {"type": 'MOUSEMOVE', "value": 'ANY', "any": True}, None),
+        ("file.sort_column_ui_context", {"type": 'LEFTMOUSE', "value": 'ANY', "any": True}, None),
         ("file.filenum", {"type": 'NUMPAD_PLUS', "value": 'PRESS'},
          {"properties": [("increment", 1)]}),
         ("file.filenum", {"type": 'NUMPAD_PLUS', "value": 'PRESS', "shift": True},
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index ca26ff89d54..c593575e39a 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -45,9 +45,12 @@ typedef enum FileListColumns {
 } FileListColumns;
 
 typedef struct FileDetailsColumn {
-  float width;
   /** UI name for this column */
   const char *name;
+
+  float width;
+  /* The sort type to use when sorting by this column. */
+  int sort_type; /* eFileSortType */
 } FileDetailsColumn;
 
 typedef struct FileLayout {
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 6bd993b4175..8f78879fae9 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -698,37 +698,6 @@ static void draw_columnheader_background(const FileLayout *layout, const View2D
   immUnbindProgram();
 }
 
-static bool filelist_column_matches_sort(const FileSelectParams *params, FileListColumns column)
-{
-  switch (params->sort) {
-    case FILE_SORT_ALPHA:
-      return column == COLUMN_NAME;
-    case FILE_SORT_SIZE:
-      return column == COLUMN_SIZE;
-    case FILE_SORT_TIME:
-      return column == COLUMN_DATE;
-  }
-
-  return false;
-}
-
-static bool filelist_column_enabled(const FileSelectParams *params, FileListColumns column)
-{
-  switch (column) {
-    case COLUMN_NAME:
-      /* Always enabled */
-      return true;
-    case COLUMN_DATE:
-      return (params->details_flags & FILE_DETAILS_DATE) != 0;
-    case COLUMN_TIME:
-      return (params->details_flags & FILE_DETAILS_TIME) != 0;
-    case COLUMN_SIZE:
-      return (params->details_flags & FILE_DETAILS_SIZE) != 0;
-    default:
-      return false;
-  }
-}
-
 static void draw_columnheader_columns(const FileSelectParams *params,
                                       FileLayout *layout,
                                       const View2D *v2d,
@@ -744,16 +713,16 @@ static void draw_columnheader_columns(const FileSelectParams *params,
   sx = ofs_x + layout->tile_w;
   sy = v2d->cur.ymax;
 
-  for (FileListColumns column = COLUMN_MAX - 1; column >= 0; column--) {
-    if (!filelist_column_enabled(params, column)) {
+  for (FileListColumns column_type = COLUMN_MAX - 1; column_type >= 0; column_type--) {
+    if (!file_column_type_enabled(params, column_type)) {
       continue;
     }
-    const int width = (column == COLUMN_NAME) ?
-                          remaining_width :
-                          layout->details_columns[column].width + DETAILS_COLUMN_PADDING;
+    const FileDetailsColumn *column = &layout->details_columns[column_type];
+    const int width = (column_type == COLUMN_NAME) ? remaining_width :
+                                                     column->width + DETAILS_COLUMN_PADDING;
 
     /* Active sort type triangle */
-    if (filelist_column_matches_sort(params, column)) {
+    if (params->sort == column->sort_type) {
       float tri_color[4];
 
       rgba_uchar_to_float(tri_color, text_col);
@@ -766,16 +735,11 @@ static void draw_columnheader_columns(const FileSelectParams *params,
     sx -= width;
     remaining_width -= width;
 
-    file_draw_string(sx + ofs_x,
-                     sy,
-                     layout->details_columns[column].name,
-                     width,
-                     layout->columnheader_h,
-                     UI_STYLE_TEXT_LEFT,
-                     text_col);
+    file_draw_string(
+        sx + ofs_x, sy, column->name, width, layout->columnheader_h, UI_STYLE_TEXT_LEFT, text_col);
 
     /* Separator line */
-    if (column != COLUMN_NAME) {
+    if (column_type != COLUMN_NAME) {
       uint pos = GPU_vertformat_attr_add(
           immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
@@ -820,6 +784,7 @@ static const char *filelist_get_details_column_string(FileListColumns column,
           BLI_filelist_entry_datetime_to_string(
               NULL, file->entry->time, small_size, file->entry->time_str, file->entry->date_str);
         }
+
         return (column == COLUMN_DATE) ? file->entry->date_str : file->entry->time_str;
       }
       break;
@@ -830,6 +795,7 @@ static const char *filelist_get_details_column_string(FileListColumns column,
           BLI_filelist_entry_size_to_string(
               NULL, file->entry->size, small_size, file->entry->size_str);
         }
+
         return file->entry->size_str;
       }
       break;
@@ -852,23 +818,19 @@ static void draw_details_columns(const FileSelectParams *params,
   const bool update_stat_strings = small_size != SMALL_SIZE_CHECK(layout->curr_size);
   int sx = pos_x + layout->tile_w, sy = pos_y;
 
-  for (FileListColumns column = COLUMN_MAX - 1; column >= 0; column--) {
+  for (FileListColumns column_type = COLUMN_MAX - 1; column_type >= 0; column_type--) {
     /* Name column is not a detail column (should already be drawn), always skip here. */
-    if ((column == COLUMN_NAME) || !filelist_column_enabled(params, column)) {
+    if ((column_type == COLUMN_NAME) || !file_column_type_enabled(params, column_type)) {
       continue;
     }
     const char *str = filelist_get_details_column_string(
-        column, file, small_size, update_stat_strings);
+        column_type, file, small_size, update_stat_strings);
+    const FileDetailsColumn *column = &layout->details_columns[column_type];
 
-    sx -= (int)layout->details_columns[column].width + DETAILS_COLUMN_PADDING;
+    sx -= (int)column->width + DETAILS_COLUMN_PADDING;
     if (str) {
-      file_draw_string(sx + DETAILS_COLUMN_PADDING,
-                       sy,
-                       str,
-                       layout->details_columns[column].width,
-                       layout->tile_h,
-                       align,
-                       text_col);
+      file_draw_string(
+          sx + DETAILS_COLUMN_PADDING, sy, str, column->width, layout->tile_h, align, text_col);
     }
   }
 }
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 68412e2b21d..e2f31eb61eb 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -30,6 +30,7 @@ struct ARegion;
 struct ARegionType;
 struct FileSelectParams;
 struct SpaceFile;
+struct View2D;
 
 /* file_ops.c */
 struct ARegion *file_tools_region(struct ScrArea *sa);
@@ -69,6 +70,7 @@ typedef enum WalkSelectDirection {
 } WalkSelectDirections;
 
 void FILE_OT_highlight(struct wmOperatorType *ot);
+void FILE_OT_sort_column_ui_context(struct wmOperatorType *ot);
 void FILE_OT_select(struct wmOperatorType *ot);
 void FILE_OT_select_walk(struct wmOperatorType *ot);
 void FILE_OT_select_all(struct wmOperatorType *ot);
@@ -117,6 +119,15 @@ void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOpera
 
 /* filesel.c */
 void fileselect_file_set(SpaceFile *sfile, const int index);
+bool file_column_type_enabled(const FileSelectParams *params, FileListColumns column);
+bool file_column_header_is_inside(const struct View2D *v2d,
+                                  const FileLayout *layout,
+                                  int x,
+                                  int y);
+FileListColumns file_column_type_find_isect(const View2D *v2d,
+                                            const FileSelectParams *params,
+                                            FileLayout *layout,
+                                            int x);
 float file_string_width(const char *str);
 
 float file_font_pointsize(void);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 863b5b747dc..1326a81ef65 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1239,6 +1239,45 @@ void FILE_OT_highlight(struct wmOperatorType *ot)
   ot->poll = ED_operator_file_active;
 }
 
+static int file_column_sort_ui_context_invoke(bContext *C,
+                                              wmOperator *UNUSED(op),
+                                              const wmEvent *event)
+{
+  const ARegion *ar = CTX_wm_region(C);
+  SpaceFile *sfile = CTX_wm_space_file(C);
+
+  if (file_column_header_is_inside(&ar->v2d, sfile->layout, event->mval[0], event->mval[1])) {
+    const FileListColumns column_type = file_column_type_find_isect(
+        &ar->v2d, sfile->params, sfile->layout, event->mval[0]);
+
+    if (column_type != COLUMN_NONE) {
+      const FileDetailsColumn *column = &sfile->layout->details_columns[column_type];
+
+      if (column->sort_type != FILE_SORT_NONE) {
+        sfile->params->sort = sfile->layout->details_columns[column_type].sort_type;
+
+        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
+      }
+    }
+  }
+
+  return OPERATOR_PASS_THROUGH;
+}
+
+void FILE_OT_sort_column_ui_context(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Sort from Column";
+  ot->description = "Change sorting to use column under cursor";
+  ot->idname = "FILE_OT_sort_column_ui_context";
+
+  /* api callbacks */
+  ot->invoke = file_column_sort_ui_context_invoke;
+  ot->poll = ED_operator_file_active;
+
+  ot->flag = OPTYPE_INTERNAL;
+}
+
 int file_cancel_exec(b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list