[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29921] trunk/blender: convenience functionality for browse button ( requested by Colin for the sequence editor, useful for managing files for the final edit)

Daniel Salazar - 3Developer.com zanqdo at gmail.com
Sun Jul 4 17:17:05 CEST 2010


Some time ago I changed a tool-tip for snapping tools in order to clarify
the action of Ctrl key in snapping. Immediatly Theeth or Matt told me we can
not use keys in tool-tips anymore since in blender 2.5's
flexible key-maps they aren't fixed and can change. Good enough... but Ive
seen many commits like this one that ignores this fact so I'd like to have a
concrete answer about this topic now. Is mentioning specific
key combinations on tool-tips acceptable or not?

pura vida
Daniel Salazar


On Sun, Jul 4, 2010 at 4:02 AM, Campbell Barton <ideasman42 at gmail.com>wrote:

> Revision: 29921
>
> http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29921
> Author:   campbellbarton
> Date:     2010-07-04 12:02:30 +0200 (Sun, 04 Jul 2010)
>
> Log Message:
> -----------
> 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.
>
> Modified Paths:
> --------------
>    trunk/blender/release/scripts/op/wm.py
>    trunk/blender/source/blender/editors/interface/interface_layout.c
>    trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
>
> Modified: trunk/blender/release/scripts/op/wm.py
> ===================================================================
> --- trunk/blender/release/scripts/op/wm.py      2010-07-04 09:48:35 UTC
> (rev 29920)
> +++ trunk/blender/release/scripts/op/wm.py      2010-07-04 10:02:30 UTC
> (rev 29921)
> @@ -430,6 +430,40 @@
>         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 @@
>     WM_OT_context_modal_mouse,
>
>     WM_OT_url_open,
> +    WM_OT_path_open,
>
>     WM_OT_doc_view,
>     WM_OT_doc_edit,
>
> Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
> ===================================================================
> --- trunk/blender/source/blender/editors/interface/interface_layout.c
> 2010-07-04 09:48:35 UTC (rev 29920)
> +++ trunk/blender/source/blender/editors/interface/interface_layout.c
> 2010-07-04 10:02:30 UTC (rev 29921)
> @@ -513,7 +513,7 @@
>                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);
>
> Modified: trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
> ===================================================================
> --- trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
>  2010-07-04 09:48:35 UTC (rev 29920)
> +++ trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
>  2010-07-04 10:02:30 UTC (rev 29921)
> @@ -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 @@
>
>        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 */
>
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>


More information about the Bf-committers mailing list