[Bf-blender-cvs] [77719bf] master: File Browser: autocomplete keeps focus in the file field when entering a folder.

Brecht Van Lommel noreply at git.blender.org
Fri Nov 29 17:50:22 CET 2013


Commit: 77719bfd0669cc675ad729f4c51672173842faca
Author: Brecht Van Lommel
Date:   Fri Nov 22 01:35:38 2013 +0100
http://developer.blender.org/rB77719bfd0669cc675ad729f4c51672173842faca

File Browser: autocomplete keeps focus in the file field when entering a folder.

There is a bunch of internal refactoring going on too:
* No longer use operators to handle these directory and file fields, only makes
  things more complicated than they should be.
* Handle autocomplete partial/full match deeper in the UI code
* Directory field still does not keep focus, that's for another time to fix,
  you can already do pretty quick keyboard only navigation with the file field.

Reviewed By: elubie

Differential Revision: http://developer.blender.org/D29

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/editors/space_text/space_text.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 665c4dd..9d541b5 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -321,7 +321,7 @@ typedef struct uiSearchItems uiSearchItems;
 typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
 typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
 typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
-typedef bool (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
+typedef int (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
 typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
 typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
 
@@ -474,7 +474,6 @@ uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x, i
 uiBut *uiDefButR_prop(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip);
 uiBut *uiDefButO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x, int y, short width, short height, const char *tip);
 uiBut *uiDefButO_ptr(uiBlock *block, int type, struct wmOperatorType *ot, int opcontext, const char *str, int x, int y, short width, short height, const char *tip);
-uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip);
 
 uiBut *uiDefIconBut(uiBlock *block, 
                     int type, int retval, int icon,
@@ -634,8 +633,9 @@ void    uiBlockSetDrawExtraFunc(uiBlock *block,
                                 void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect),
                                 void *arg1, void *arg2);
 
-bool UI_textbutton_activate_event(const struct bContext *C, struct ARegion *ar,
-                                  const void *rna_poin_data, const char *rna_prop_id);
+bool UI_textbutton_activate_rna(const struct bContext *C, struct ARegion *ar,
+                                const void *rna_poin_data, const char *rna_prop_id);
+bool UI_textbutton_activate_but(const struct bContext *C, uiBut *but);
 
 void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but);
 
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 74d439d..c82026e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3112,45 +3112,6 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, int type, wmOperatorType *
 	return but;
 }
 
-#if 0 /* UNUSED */
-static uiBut *UNUSED_FUNCTION(ui_def_but_operator) (uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x, int y, short width, short height, const char *tip)
-{
-	wmOperatorType *ot = WM_operatortype_find(opname, 0);
-	if (str == NULL && ot == NULL) str = opname;
-	return ui_def_but_operator_ptr(block, type, ot, opcontext, str, x, y, width, height, tip);
-}
-#endif
-
-static uiBut *ui_def_but_operator_text(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
-{
-	uiBut *but;
-	wmOperatorType *ot;
-	
-	ot = WM_operatortype_find(opname, 0);
-
-	if (!str) {
-		if (ot) str = ot->name;
-		else str = opname;
-	}
-	
-	if ((!tip || tip[0] == '\0') && ot && ot->description) {
-		tip = ot->description;
-	}
-
-	but = ui_def_but(block, type, -1, str, x, y, width, height, poin, min, max, a1, a2, tip);
-	but->optype = ot;
-	but->opcontext = opcontext;
-	but->flag &= ~UI_BUT_UNDO; /* no need for ui_is_but_rna_undo(), we never need undo here */
-
-	if (!ot) {
-		but->flag |= UI_BUT_DISABLED;
-		but->lock = TRUE;
-		but->lockstr = "";
-	}
-
-	return but;
-}
-
 uiBut *uiDefBut(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
 {
 	uiBut *but = ui_def_but(block, type, retval, str, x, y, width, height, poin, min, max, a1, a2, tip);
@@ -3342,13 +3303,6 @@ uiBut *uiDefButO(uiBlock *block, int type, const char *opname, int opcontext, co
 	return uiDefButO_ptr(block, type, ot, opcontext, str, x, y, width, height, tip);
 }
 
-uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2,  const char *tip)
-{
-	uiBut *but = ui_def_but_operator_text(block, type, opname, opcontext, str, x, y, width, height, poin, min, max, a1, a2, tip);
-	ui_check_but(but);
-	return but;
-}
-
 /* if a1==1.0 then a2 is an extra icon blending factor (alpha 0.0 - 1.0) */
 uiBut *uiDefIconBut(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2,  const char *tip)
 {
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 4701cd5..ee6663d 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -421,7 +421,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
 		after->func_arg2 = but->func_arg2;
 
 		after->funcN = but->funcN;
-		after->func_argN = MEM_dupallocN(but->func_argN);
+		after->func_argN = (but->func_argN) ? MEM_dupallocN(but->func_argN) : NULL;
 
 		after->rename_func = but->rename_func;
 		after->rename_arg1 = but->rename_arg1;
@@ -1922,10 +1922,10 @@ static bool ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directi
 	return changed;
 }
 
-static bool ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData *data)
+static int ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
 	char *str;
-	bool changed = true;
+	int changed;
 
 	str = data->str;
 
@@ -2332,7 +2332,12 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
 			case TABKEY:
 				/* there is a key conflict here, we can't tab with autocomplete */
 				if (but->autocomplete_func || data->searchbox) {
-					changed = ui_textedit_autocomplete(C, but, data);
+					int autocomplete = ui_textedit_autocomplete(C, but, data);
+					changed = autocomplete != AUTOCOMPLETE_NO_MATCH;
+
+					if(autocomplete == AUTOCOMPLETE_FULL_MATCH)
+						button_activate_state(C, but, BUTTON_STATE_EXIT);
+
 					update = true;  /* do live update for tab key */
 				}
 				/* the hotkey here is not well defined, was G.qual so we check all */
@@ -8033,8 +8038,8 @@ void UI_remove_popup_handlers_all(bContext *C, ListBase *handlers)
 	WM_event_free_ui_handler_all(C, handlers, ui_handler_popup, ui_handler_remove_popup);
 }
 
-bool UI_textbutton_activate_event(const bContext *C, ARegion *ar,
-                                  const void *rna_poin_data, const char *rna_prop_id)
+bool UI_textbutton_activate_rna(const bContext *C, ARegion *ar,
+                                const void *rna_poin_data, const char *rna_prop_id)
 {
 	uiBlock *block;
 	uiBut *but = NULL;
@@ -8062,6 +8067,31 @@ bool UI_textbutton_activate_event(const bContext *C, ARegion *ar,
 	}
 }
 
+bool UI_textbutton_activate_but(const bContext *C, uiBut *actbut)
+{
+	ARegion *ar = CTX_wm_region(C);
+	uiBlock *block;
+	uiBut *but = NULL;
+	
+	for (block = ar->uiblocks.first; block; block = block->next) {
+		for (but = block->buttons.first; but; but = but->next)
+			if (but == actbut && but->type == TEX)
+				break;
+
+		if (but)
+			break;
+	}
+	
+	if (but) {
+		uiButActiveOnly(C, ar, block, but);
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+
+
 void ui_button_clipboard_free(void)
 {
 	curvemapping_free_data(&but_copypaste_curve);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 3cee9a7..a12c4a3 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -479,7 +479,7 @@ ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBu
 bool ui_searchbox_inside(struct ARegion *ar, int x, int y);
 int  ui_searchbox_find_index(struct ARegion *ar, const char *name);
 void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, const bool reset);
-bool ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but, char *str);
+int ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but, char *str);
 void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event);
 bool ui_searchbox_apply(uiBut *but, struct ARegion *ar);
 void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index b4d99b9..a6216b4 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1051,7 +1051,7 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, const bool reset)
 	ED_region_tag_redraw(ar);
 }
 
-bool ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
+int ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
 {
 	uiSearchboxData *data = ar->regiondata;
 	int match = AUTOCOMPLETE_NO_MATCH;
@@ -1064,7 +1064,8 @@ bool ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
 		match = autocomplete_end(data->items.autocpl, str);
 		data->items.autocpl = NULL;
 	}
-	return match != AUTOCOMPLETE_NO_MATCH;
+
+	return match;
 }
 
 static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
diff --git a/source/blender/editors/space_file/file_draw.c b/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list