forked from bartvdbraak/blender
convenience functionality for browse button (requested by Colin for the sequence editor, useful for managing files for the final edit)
- Holding Alt while clocking on the browse button opens a file browser with the containing dir. - Holding Shift opens the file its self in the default application. obscure but at least theres a tooltip so its not totally hidden.
This commit is contained in:
parent
ce94f52dbc
commit
8e97e561a9
@ -430,6 +430,40 @@ class WM_OT_url_open(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class WM_OT_path_open(bpy.types.Operator):
|
||||
"Open a path in a file browser"
|
||||
bl_idname = "wm.path_open"
|
||||
bl_label = ""
|
||||
|
||||
filepath = StringProperty(name="File Path", maxlen= 1024)
|
||||
|
||||
def execute(self, context):
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
filepath = bpy.utils.expandpath(self.properties.filepath)
|
||||
filepath = os.path.normpath(filepath)
|
||||
|
||||
if not os.path.exists(filepath):
|
||||
self.report({'ERROR'}, "File '%s' not found" % filepath)
|
||||
return {'CANCELLED'}
|
||||
|
||||
if sys.platform == 'win32':
|
||||
subprocess.Popen(['start', filepath], shell= True)
|
||||
elif sys.platform == 'darwin':
|
||||
subprocess.Popen(['open', filepath])
|
||||
else:
|
||||
try:
|
||||
subprocess.Popen(['xdg-open', filepath])
|
||||
except OSError:
|
||||
# xdg-open *should* be supported by recent Gnome, KDE, Xfce
|
||||
pass
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
|
||||
class WM_OT_doc_view(bpy.types.Operator):
|
||||
'''Load online reference docs'''
|
||||
bl_idname = "wm.doc_view"
|
||||
@ -562,6 +596,7 @@ classes = [
|
||||
WM_OT_context_modal_mouse,
|
||||
|
||||
WM_OT_url_open,
|
||||
WM_OT_path_open,
|
||||
|
||||
WM_OT_doc_view,
|
||||
WM_OT_doc_edit,
|
||||
|
@ -513,7 +513,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, i
|
||||
uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w-UI_UNIT_X, h);
|
||||
|
||||
/* BUTTONS_OT_file_browse calls uiFileBrowseContextProperty */
|
||||
but= uiDefIconButO(block, BUT, "BUTTONS_OT_file_browse", WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, "Browse for file or directory");
|
||||
but= uiDefIconButO(block, BUT, "BUTTONS_OT_file_browse", WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL);
|
||||
}
|
||||
else if(subtype == PROP_DIRECTION) {
|
||||
uiDefButR(block, BUT_NORMAL, 0, name, x, y, 100, 100, ptr, RNA_property_identifier(prop), index, 0, 0, -1, -1, NULL);
|
||||
|
@ -32,7 +32,10 @@
|
||||
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
#include "BLI_fileops.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h" /* G.sce only */
|
||||
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
@ -120,30 +123,53 @@ static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
if(!prop)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
|
||||
fbo->ptr= ptr;
|
||||
fbo->prop= prop;
|
||||
op->customdata= fbo;
|
||||
|
||||
str= RNA_property_string_get_alloc(&ptr, prop, 0, 0);
|
||||
RNA_string_set(op->ptr, "filepath", str);
|
||||
MEM_freeN(str);
|
||||
|
||||
if(RNA_struct_find_property(op->ptr, "relative_path"))
|
||||
if(!RNA_property_is_set(op->ptr, "relative_path"))
|
||||
RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
|
||||
/* useful yet irritating feature, Shift+Click to open the file
|
||||
* Alt+Click to browse a folder in the OS's browser */
|
||||
if(event->shift || event->alt) {
|
||||
PointerRNA props_ptr;
|
||||
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
if(event->alt) {
|
||||
char *lslash= BLI_last_slash(str);
|
||||
if(lslash)
|
||||
*lslash= '\0';
|
||||
}
|
||||
|
||||
|
||||
WM_operator_properties_create(&props_ptr, "WM_OT_path_open");
|
||||
RNA_string_set(&props_ptr, "filepath", str);
|
||||
WM_operator_name_call(C, "WM_OT_path_open", WM_OP_EXEC_DEFAULT, &props_ptr);
|
||||
WM_operator_properties_free(&props_ptr);
|
||||
|
||||
MEM_freeN(str);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
|
||||
fbo->ptr= ptr;
|
||||
fbo->prop= prop;
|
||||
op->customdata= fbo;
|
||||
|
||||
RNA_string_set(op->ptr, "filepath", str);
|
||||
MEM_freeN(str);
|
||||
|
||||
if(RNA_struct_find_property(op->ptr, "relative_path"))
|
||||
if(!RNA_property_is_set(op->ptr, "relative_path"))
|
||||
RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
|
||||
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
}
|
||||
|
||||
void BUTTONS_OT_file_browse(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Accept";
|
||||
ot->description="Open a file browser";
|
||||
ot->description="Open a file browser, Hold Shift to open the file, Alt to browse containing directory";
|
||||
ot->idname= "BUTTONS_OT_file_browse";
|
||||
|
||||
/* api callbacks */
|
||||
|
Loading…
Reference in New Issue
Block a user