[Bf-blender-cvs] [53792e32e7d] master: UI: Show more information in open file tooltip

Juanfran Matheu noreply at git.blender.org
Wed Oct 14 21:02:10 CEST 2020


Commit: 53792e32e7dc75bcbb6551a5c99192dd8e4787ff
Author: Juanfran Matheu
Date:   Wed Oct 14 13:57:31 2020 -0500
Branches: master
https://developer.blender.org/rB53792e32e7dc75bcbb6551a5c99192dd8e4787ff

UI: Show more information in open file tooltip

This shows the file's full path, its modification date, and its size in
the tooltips for the open recent fiels menu. When no file path is set,
the original operator description is used.

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

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

M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index ffafa1e5c0c..7c9baa2fc26 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -2373,6 +2373,41 @@ struct FileRuntime {
   bool is_untrusted;
 };
 
+static char *wm_open_mainfile_description(struct bContext *UNUSED(C),
+                                          struct wmOperatorType *UNUSED(op),
+                                          struct PointerRNA *params)
+{
+  if (!RNA_struct_property_is_set(params, "filepath")) {
+    return NULL;
+  }
+
+  /* Filepath. */
+  char path[FILE_MAX];
+  RNA_string_get(params, "filepath", path);
+
+  BLI_stat_t stats;
+  if (BLI_stat(path, &stats) == -1) {
+    return BLI_sprintfN("%s\n\n%s", path, N_("File Not Found"));
+  }
+
+  /* Date. */
+  char date_st[16];
+  char time_st[8];
+  bool is_today, is_yesterday;
+  BLI_filelist_entry_datetime_to_string(
+      NULL, (int64_t)stats.st_mtime, false, time_st, date_st, &is_today, &is_yesterday);
+  if (is_today || is_yesterday) {
+    BLI_strncpy(date_st, is_today ? N_("Today") : N_("Yesterday"), sizeof(date_st));
+  }
+
+  /* Size. */
+  char size_str[16];
+  BLI_filelist_entry_size_to_string(NULL, (uint64_t)stats.st_size, false, size_str);
+
+  return BLI_sprintfN(
+      "%s\n\n%s: %s %s\n%s: %s", path, N_("Modified"), date_st, time_st, N_("Size"), size_str);
+}
+
 static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op)
 {
   struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata;
@@ -2430,6 +2465,7 @@ void WM_OT_open_mainfile(wmOperatorType *ot)
   ot->name = "Open";
   ot->idname = "WM_OT_open_mainfile";
   ot->description = "Open a Blender file";
+  ot->get_description = wm_open_mainfile_description;
 
   ot->invoke = wm_open_mainfile_invoke;
   ot->exec = wm_open_mainfile_exec;



More information about the Bf-blender-cvs mailing list