Page MenuHome

Recent files menu: dynamic tooltip showing filepath
ClosedPublic

Authored by Juanfran Matheu (jfmatheu) on Sep 27 2020, 5:42 PM.
Tokens
"Dat Boi" token, awarded by shader."Love" token, awarded by pablovazquez."Love" token, awarded by SavMartin."Love" token, awarded by harley."Love" token, awarded by juang3d.

Details

Summary

Hi, I made this little patch to add filepath as tooltip description dynamically for menu items in File > Open Recent...
it should not break when not having a filepath as param, in that case will show the original tooltip description.

This idea is taken from a RSC proposal, see:
https://blender.community/c/rightclickselect/B2gbbc/

Video:

Diff Detail

Event Timeline

Juanfran Matheu (jfmatheu) requested review of this revision.Sep 27 2020, 5:42 PM
Juanfran Matheu (jfmatheu) created this revision.

What's wrong with the python tooltips? IIRC it shows the filepath.

Might be best to just ADD your "get_description" and leave the existing "description" there. Then inside your "get_description" just return NULL if there isn't a filepath. That way it would just return the existing "Open a Blender File" in that case.

Note that you can test for that "filepath" without reading it, like...

if (RNA_struct_property_is_set(params, "filepath")) {
  char path[FILE_MAX];
  RNA_string_get(params, "filepath", path);
  return BLI_strdup(path);
}
return NULL;

Just in case you appreciate the inspiration, you can get something like the following:

with this:

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")) {
    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"));
    }

    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));
    }

    char size_str[16];
    BLI_filelist_entry_size_to_string(NULL, (uint64_t)stats.st_size, false, size_str);
    char bytes_str[64];
    BLI_str_format_uint64_grouped(bytes_str, (uint64_t)stats.st_size);

    return BLI_sprintfN("%s\n\n%s: %s %s\n%s: %s (%s %s)",
                        path,
                        N_("Modified"),
                        date_st,
                        time_st,
                        N_("Size"),
                        size_str,
                        bytes_str,
                        N_("bytes"));
  }
  return NULL;
}
  • Removed size in bytes.
  • Remove brackets in file not found description.

Works well for me! Just a small tweak that could be made when committing. I think this is fine for Bcon2.

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

You can reduce indentation in the entire function by returning early here.

  • Better indentation.
Juanfran Matheu (jfmatheu) marked an inline comment as done.Sep 29 2020, 4:31 PM
This revision is now accepted and ready to land.Sep 29 2020, 4:43 PM