* layout.itemR now has icon_only option to show only icon
  in e.g. enums buttons, for uv editor header.
* Automatic key shortcuts in menus now show the shortcut even if
  operator properties don't match. Not sure this will work well
  everywhere, but seems to be working ok for now.
* Open recent now show shorter filenames instead of the whole
  file path.
* Tweak object Duplicate menu item.
This commit is contained in:
Brecht Van Lommel 2009-09-10 14:20:21 +00:00
parent 15d77f17a4
commit cfb6f35f9f
11 changed files with 91 additions and 40 deletions

View File

@ -126,9 +126,9 @@ class IMAGE_MT_uvs_transform(bpy.types.Menu):
def draw(self, context):
layout = self.layout
layout.item_enumO("tfm.transform", "mode", 'TRANSLATION')
layout.item_enumO("tfm.transform", "mode", 'ROTATION')
layout.item_enumO("tfm.transform", "mode", 'RESIZE')
layout.itemO("tfm.translate")
layout.itemO("tfm.rotate")
layout.itemO("tfm.resize")
class IMAGE_MT_uvs_mirror(bpy.types.Menu):
__space_type__ = 'IMAGE_EDITOR'
@ -136,9 +136,13 @@ class IMAGE_MT_uvs_mirror(bpy.types.Menu):
def draw(self, context):
layout = self.layout
layout.operator_context = "EXEC_REGION_WIN"
layout.item_enumO("uv.mirror", "axis", 'MIRROR_X') # "X Axis", M,
layout.item_enumO("uv.mirror", "axis", 'MIRROR_Y') # "Y Axis", M,
props= layout.itemO("tfm.mirror", text="X Axis", properties=True)
props.constraint_axis[0]= True
props= layout.itemO("tfm.mirror", text="Y Axis", properties=True)
props.constraint_axis[1]= True
class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
__space_type__ = 'IMAGE_EDITOR'
@ -233,14 +237,14 @@ class IMAGE_HT_header(bpy.types.Header):
if show_uvedit:
uvedit = sima.uv_editor
layout.itemR(uvedit, "pivot", text="")
layout.itemR(uvedit, "pivot", text="", icon_only=True)
layout.itemR(settings, "uv_sync_selection", text="")
if settings.uv_sync_selection:
layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
else:
layout.itemR(settings, "uv_selection_mode", text="", expand=True)
layout.itemR(uvedit, "sticky_selection_mode", text="")
layout.itemR(uvedit, "sticky_selection_mode", text="", icon_only=True)
pass
row = layout.row(align=True)

View File

@ -410,7 +410,7 @@ class VIEW3D_MT_OBJECT(bpy.types.Menu):
layout.itemS()
layout.itemO("object.duplicate")
layout.itemO("object.duplicate_move")
layout.item_booleanO("object.duplicate", "linked", True, text="Duplicate Linked")
layout.itemO("object.delete", text="Delete...")
layout.itemO("object.proxy_make", text="Make Proxy...")

View File

@ -54,6 +54,7 @@ char *BLI_last_slash(const char *string);
int BLI_add_slash(char *string);
void BLI_del_slash(char *string);
char *first_slash(char *string);
const char *BLI_short_filename(const char *string);
/* only for the sane unix world: direct calls to system functions :( */
#ifndef WIN32

View File

@ -84,6 +84,31 @@ char *BLI_last_slash(const char *string) {
else return lfslash;
}
static const char *last_slash_len(const char *string, int len) {
int a;
for(a=len-1; a>=0; a--)
if(string[a] == '/' || string[a] == '\\')
return &string[a];
return NULL;
}
const char *BLI_short_filename(const char *string) {
const char *ls, *lls;
ls= last_slash_len(string, strlen(string));
if(!ls)
return string;
lls= last_slash_len(string, ls-string);
if(lls)
return lls+1;
else
return ls+1;
}
/* adds a slash if there isnt one there alredy */
int BLI_add_slash(char *string) {
int len = strlen(string);

View File

@ -589,6 +589,7 @@ void UI_exit(void);
#define UI_ITEM_R_EXPAND 2
#define UI_ITEM_R_SLIDER 4
#define UI_ITEM_R_TOGGLE 8
#define UI_ITEM_R_ICON_ONLY 16
uiLayout *uiBlockLayout(uiBlock *block, int dir, int type, int x, int y, int size, int em, struct uiStyle *style);
void uiBlockSetCurLayout(uiBlock *block, uiLayout *layout);

View File

@ -443,7 +443,7 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon
uiBlockSetCurLayout(block, layout);
}
static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, char *uiname, int x, int y, int w, int h)
static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, char *uiname, int x, int y, int w, int h, int icon_only)
{
EnumPropertyItem *item;
const char *identifier;
@ -463,7 +463,7 @@ static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr,
value= item[a].value;
itemw= ui_text_icon_width(block->curlayout, name, icon, 0);
if(icon && strcmp(name, "") != 0)
if(icon && strcmp(name, "") != 0 && !icon_only)
uiDefIconTextButR(block, ROW, 0, icon, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
else if(icon)
uiDefIconButR(block, ROW, 0, icon, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
@ -477,7 +477,7 @@ static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr,
}
/* create label + button for RNA property */
static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int x, int y, int w, int h)
static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int x, int y, int w, int h, int icon_only)
{
uiLayout *sub;
uiBut *but;
@ -506,7 +506,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, i
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.");
}
else
but= uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w, h);
but= uiDefAutoButR(block, ptr, prop, index, (icon_only)? "": NULL, icon, x, y, w, h);
uiBlockSetCurLayout(block, layout);
return but;
@ -788,7 +788,7 @@ void uiItemO(uiLayout *layout, char *name, int icon, char *opname)
/* RNA property items */
static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int *r_w, int *r_h)
static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int icon_only, int *r_w, int *r_h)
{
PropertyType type;
PropertySubType subtype;
@ -799,9 +799,9 @@ static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PointerRNA
subtype= RNA_property_subtype(prop);
len= RNA_property_array_length(ptr, prop);
if(ELEM3(type, PROP_STRING, PROP_POINTER, PROP_ENUM) && !name[0])
if(ELEM3(type, PROP_STRING, PROP_POINTER, PROP_ENUM) && !name[0] && !icon_only)
name= "non-empty text";
else if(type == PROP_BOOLEAN && !name[0])
else if(type == PROP_BOOLEAN && !name[0] && !icon_only)
icon= ICON_DOT;
w= ui_text_icon_width(layout, name, icon, 0);
@ -823,7 +823,7 @@ static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PointerRNA
if(type == PROP_BOOLEAN && strcmp(name, "") != 0)
w += UI_UNIT_X/5;
else if(type == PROP_ENUM)
w += UI_UNIT_X/2;
w += UI_UNIT_X/4;
else if(type == PROP_FLOAT || type == PROP_INT)
w += UI_UNIT_X*3;
}
@ -838,7 +838,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
uiBut *but;
PropertyType type;
char namestr[UI_MAX_NAME_STR];
int len, w, h, slider, toggle, expand;
int len, w, h, slider, toggle, expand, icon_only;
if(!ptr->data || !prop)
return;
@ -872,9 +872,10 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
slider= (flag & UI_ITEM_R_SLIDER);
toggle= (flag & UI_ITEM_R_TOGGLE);
expand= (flag & UI_ITEM_R_EXPAND);
icon_only= (flag & UI_ITEM_R_ICON_ONLY);
/* get size */
ui_item_rna_size(layout, name, icon, ptr, prop, index, &w, &h);
ui_item_rna_size(layout, name, icon, ptr, prop, index, icon_only, &w, &h);
/* array property */
if(index == RNA_NO_INDEX && len > 0)
@ -883,7 +884,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
else if(type == PROP_ENUM && index == RNA_ENUM_VALUE) {
char *identifier= (char*)RNA_property_identifier(prop);
if(icon && strcmp(name, "") != 0)
if(icon && strcmp(name, "") != 0 && !icon_only)
uiDefIconTextButR(block, ROW, 0, icon, name, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
else if(icon)
uiDefIconButR(block, ROW, 0, icon, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
@ -892,10 +893,10 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
}
/* expanded enum */
else if(type == PROP_ENUM && expand)
ui_item_enum_row(layout, block, ptr, prop, name, 0, 0, w, h);
ui_item_enum_row(layout, block, ptr, prop, name, 0, 0, w, h, icon_only);
/* property with separate label */
else if(type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) {
but= ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h);
but= ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h, icon_only);
ui_but_add_search(but, ptr, prop, NULL, NULL);
}
/* single button */
@ -1160,8 +1161,8 @@ void uiItemPointerR(uiLayout *layout, char *name, int icon, struct PointerRNA *p
/* create button */
block= uiLayoutGetBlock(layout);
ui_item_rna_size(layout, name, icon, ptr, prop, 0, &w, &h);
but= ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h);
ui_item_rna_size(layout, name, icon, ptr, prop, 0, 0, &w, &h);
but= ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h, 0);
ui_but_add_search(but, ptr, prop, searchptr, searchprop);
}

View File

@ -108,7 +108,12 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
break;
case PROP_ENUM:
but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
if(icon && name && strcmp(name, "") == 0)
but= uiDefIconButR(block, MENU, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
else if(icon)
but= uiDefIconTextButR(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
else
but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
break;
case PROP_STRING:
if(icon && name && strcmp(name, "") == 0)

View File

@ -1122,7 +1122,7 @@ void OBJECT_OT_convert(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "keep_original", 0, "Keep Original", "Keep original objects instead of replacing them.");
}
/************************** Add Duplicate **********************/
/**************************** Duplicate ************************/
/*
dupflag: a flag made from constants declared in DNA_userdef_types.h

View File

@ -176,7 +176,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(LATTICE_OT_make_regular);
/* macros */
ot= WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Add Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
ot= WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
if(ot) {
WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
WM_operatortype_macro_define(ot, "TFM_OT_translate");

View File

@ -242,33 +242,41 @@ static char *wm_keymap_item_to_string(wmKeymapItem *kmi, char *str, int len)
return str;
}
static wmKeymapItem *wm_keymap_item_find_handlers(ListBase *handlers, const char *opname, int opcontext, IDProperty *properties)
static wmKeymapItem *wm_keymap_item_find_handlers(ListBase *handlers, const char *opname, int opcontext, IDProperty *properties, int compare_props)
{
wmEventHandler *handler;
wmKeymapItem *kmi;
/* find keymap item in handlers */
for(handler=handlers->first; handler; handler=handler->next)
if(handler->keymap)
for(kmi=handler->keymap->first; kmi; kmi=kmi->next)
if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0])
if(kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data))
for(handler=handlers->first; handler; handler=handler->next) {
if(handler->keymap) {
for(kmi=handler->keymap->first; kmi; kmi=kmi->next) {
if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0]) {
if(compare_props) {
if(kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data))
return kmi;
}
else
return kmi;
}
}
}
}
return NULL;
}
static wmKeymapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties)
static wmKeymapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int compare_props)
{
wmKeymapItem *found= NULL;
/* look into multiple handler lists to find the item */
if(CTX_wm_window(C))
found= wm_keymap_item_find_handlers(&CTX_wm_window(C)->handlers, opname, opcontext, properties);
found= wm_keymap_item_find_handlers(&CTX_wm_window(C)->handlers, opname, opcontext, properties, compare_props);
if(CTX_wm_area(C) && found==NULL)
found= wm_keymap_item_find_handlers(&CTX_wm_area(C)->handlers, opname, opcontext, properties);
found= wm_keymap_item_find_handlers(&CTX_wm_area(C)->handlers, opname, opcontext, properties, compare_props);
if(found==NULL) {
if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
@ -279,12 +287,12 @@ static wmKeymapItem *wm_keymap_item_find(const bContext *C, const char *opname,
break;
if(ar)
found= wm_keymap_item_find_handlers(&ar->handlers, opname, opcontext, properties);
found= wm_keymap_item_find_handlers(&ar->handlers, opname, opcontext, properties, compare_props);
}
}
else {
if(CTX_wm_region(C))
found= wm_keymap_item_find_handlers(&CTX_wm_region(C)->handlers, opname, opcontext, properties);
found= wm_keymap_item_find_handlers(&CTX_wm_region(C)->handlers, opname, opcontext, properties, compare_props);
}
}
@ -293,7 +301,10 @@ static wmKeymapItem *wm_keymap_item_find(const bContext *C, const char *opname,
char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, char *str, int len)
{
wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties);
wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties, 1);
if(!found)
found= wm_keymap_item_find(C, opname, opcontext, properties, 0);
if(found) {
wm_keymap_item_to_string(found, str, len);
@ -306,7 +317,10 @@ char *WM_key_event_operator_string(const bContext *C, const char *opname, int op
/* searches context and changes keymap item, if found */
void WM_key_event_operator_change(const bContext *C, const char *opname, int opcontext, IDProperty *properties, short key, short modifier)
{
wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties);
wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties, 1);
if(!found)
found= wm_keymap_item_find(C, opname, opcontext, properties, 0);
if(found) {
keymap_event_set(found, key, KM_PRESS, modifier, 0);

View File

@ -837,7 +837,7 @@ static EnumPropertyItem *open_recentfile_itemf(bContext *C, PointerRNA *ptr, int
for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
tmp.value= i+ofs+1;
tmp.identifier= recent->filename;
tmp.name= recent->filename;
tmp.name= BLI_short_filename(recent->filename);
RNA_enum_item_add(&item, &totitem, &tmp);
}