UI: Externally open file and path from context menu

Adds two buttons to context (RMB) menu of path buttons:
* "Open File Externally" to open a file in an external app (only visible if path contains a filename)
* "Open Location Externally" to open a path in an external file browser

The functionallity for this was already there, just hidden behind Shift/Alt click of file_browse button (folder icon next to path button).
This commit is contained in:
Julian Eisel
2016-12-13 16:45:07 +01:00
parent ec2fd74f47
commit c1267bb800

View File

@@ -50,6 +50,7 @@
#include "BLI_math.h"
#include "BLI_listbase.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_cursor_utf8.h"
@@ -6703,6 +6704,35 @@ void ui_panel_menu(bContext *C, ARegion *ar, Panel *pa)
UI_popup_menu_end(C, pup);
}
static void ui_but_menu_add_path_operators(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop)
{
const PropertySubType subtype = RNA_property_subtype(prop);
wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
char filepath[FILE_MAX];
char dir[FILE_MAXDIR];
char file[FILE_MAXFILE];
PointerRNA props_ptr;
BLI_assert(ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH));
RNA_property_string_get(ptr, prop, filepath);
BLI_split_dirfile(filepath, dir, file, sizeof(dir), sizeof(file));
if (file[0]) {
BLI_assert(subtype == PROP_FILEPATH);
props_ptr = uiItemFullO_ptr(
layout, ot, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open File Externally"),
ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
RNA_string_set(&props_ptr, "filepath", filepath);
}
props_ptr = uiItemFullO_ptr(
layout, ot, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Location Externally"),
ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
RNA_string_set(&props_ptr, "filepath", dir);
}
static bool ui_but_menu(bContext *C, uiBut *but)
{
uiPopupMenu *pup;
@@ -6731,6 +6761,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
if (but->rnapoin.data && but->rnaprop) {
PointerRNA *ptr = &but->rnapoin;
PropertyRNA *prop = but->rnaprop;
const PropertyType type = RNA_property_type(prop);
const PropertySubType subtype = RNA_property_subtype(prop);
bool is_anim = RNA_property_animateable(ptr, prop);
bool is_editable = RNA_property_editable(ptr, prop);
/*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */
@@ -6901,6 +6933,11 @@ static bool ui_but_menu(bContext *C, uiBut *but)
ICON_NONE, "UI_OT_copy_data_path_button");
uiItemS(layout);
if (type == PROP_STRING && ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH)) {
ui_but_menu_add_path_operators(layout, ptr, prop);
uiItemS(layout);
}
}
/* Operator buttons */