diff options
author | Juanfran Matheu <jfmatheu> | 2020-10-14 21:57:31 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-10-14 21:57:31 +0300 |
commit | 53792e32e7dc75bcbb6551a5c99192dd8e4787ff (patch) | |
tree | 11f595a96f73a944122e5c83514e3b4343a3fa2f /source/blender/windowmanager | |
parent | adc02910618c38c956c499e496278768ea0e041f (diff) |
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
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 36 |
1 files changed, 36 insertions, 0 deletions
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; |