[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34937] trunk/blender/source/blender/ editors/space_text: Split cursor_set into two operators:

Sergey Sharybin g.ulairi at gmail.com
Thu Feb 17 19:55:19 CET 2011


Revision: 34937
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34937
Author:   nazgul
Date:     2011-02-17 18:55:17 +0000 (Thu, 17 Feb 2011)
Log Message:
-----------
Split cursor_set into two operators:
- cursor_set which just sets cursor position immediatelly
- selection_set which could be used to select block of text

Now there're could be operators binded to mouse double-click event

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/space_text.c
    trunk/blender/source/blender/editors/space_text/text_intern.h
    trunk/blender/source/blender/editors/space_text/text_ops.c

Modified: trunk/blender/source/blender/editors/space_text/space_text.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/space_text.c	2011-02-17 16:17:40 UTC (rev 34936)
+++ trunk/blender/source/blender/editors/space_text/space_text.c	2011-02-17 18:55:17 UTC (rev 34937)
@@ -193,6 +193,7 @@
 	WM_operatortype_append(TEXT_OT_delete);
 	WM_operatortype_append(TEXT_OT_overwrite_toggle);
 
+	WM_operatortype_append(TEXT_OT_selection_set);
 	WM_operatortype_append(TEXT_OT_cursor_set);
 	WM_operatortype_append(TEXT_OT_scroll);
 	WM_operatortype_append(TEXT_OT_scroll_bar);
@@ -340,9 +341,10 @@
 
 	WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
 	WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
-	WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
+	WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", EVT_TWEAK_L, KM_ANY, 0, 0);
+	WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0);
 	WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
-	RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
+	RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
 	RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
 	RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
 

Modified: trunk/blender/source/blender/editors/space_text/text_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_intern.h	2011-02-17 16:17:40 UTC (rev 34936)
+++ trunk/blender/source/blender/editors/space_text/text_intern.h	2011-02-17 18:55:17 UTC (rev 34937)
@@ -142,6 +142,7 @@
 
 void TEXT_OT_scroll(struct wmOperatorType *ot);
 void TEXT_OT_scroll_bar(struct wmOperatorType *ot);
+void TEXT_OT_selection_set(struct wmOperatorType *ot);
 void TEXT_OT_cursor_set(struct wmOperatorType *ot);
 void TEXT_OT_line_number(struct wmOperatorType *ot);
 

Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c	2011-02-17 16:17:40 UTC (rev 34936)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c	2011-02-17 18:55:17 UTC (rev 34937)
@@ -2009,11 +2009,11 @@
 }
 
 /* quick enum for tsc->zone (scroller handles) */
-static enum {
+enum {
 	SCROLLHANDLE_BAR,
 	SCROLLHANDLE_MIN_OUTSIDE,
 	SCROLLHANDLE_MAX_OUTSIDE
-} TextScrollerHandle_Zone;
+};
 
 typedef struct TextScroll {
 	short old[2];
@@ -2286,13 +2286,13 @@
 	RNA_def_int(ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll.", -100, 100);
 }
 
-/******************* set cursor operator **********************/
+/******************* set selection operator **********************/
 
-typedef struct SetCursor {
+typedef struct SetSelection {
 	int selecting;
 	int selc, sell;
 	short old[2];
-} SetCursor;
+} SetSelection;
 
 static void set_cursor_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel) 
 {
@@ -2458,10 +2458,10 @@
 {
 	SpaceText *st= CTX_wm_space_text(C);
 	ARegion *ar= CTX_wm_region(C);
-	SetCursor *scu= op->customdata;
+	SetSelection *ssel= op->customdata;
 
 	if(event->mval[1]<0 || event->mval[1]>ar->winy) {
-		int d= (scu->old[1]-event->mval[1])*st->pix_per_line;
+		int d= (ssel->old[1]-event->mval[1])*st->pix_per_line;
 		if(d) screen_skip(st, ar, d);
 
 		set_cursor_to_pos(st, ar, event->mval[0], event->mval[1]<0?0:ar->winy, 1);
@@ -2485,8 +2485,8 @@
 		text_update_cursor_moved(C);
 		WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
 
-		scu->old[0]= event->mval[0];
-		scu->old[1]= event->mval[1];
+		ssel->old[0]= event->mval[0];
+		ssel->old[1]= event->mval[1];
 	} 
 }
 
@@ -2494,7 +2494,7 @@
 {
 	SpaceText *st= CTX_wm_space_text(C);
 	Text *text= st->text;
-	SetCursor *scu= op->customdata;
+	SetSelection *ssel= op->customdata;
 	int linep2, charp2;
 	char *buffer;
 
@@ -2507,29 +2507,29 @@
 	linep2= txt_get_span(st->text->lines.first, st->text->sell);
 	charp2= st->text->selc;
 		
-	if(scu->sell!=linep2 || scu->selc!=charp2)
-		txt_undo_add_toop(st->text, UNDO_STO, scu->sell, scu->selc, linep2, charp2);
+	if(ssel->sell!=linep2 || ssel->selc!=charp2)
+		txt_undo_add_toop(st->text, UNDO_STO, ssel->sell, ssel->selc, linep2, charp2);
 
 	text_update_cursor_moved(C);
 	WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
 
-	MEM_freeN(scu);
+	MEM_freeN(ssel);
 }
 
-static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
 	SpaceText *st= CTX_wm_space_text(C);
 	ARegion *ar= CTX_wm_region(C);
-	SetCursor *scu;
+	SetSelection *ssel;
 
-	op->customdata= MEM_callocN(sizeof(SetCursor), "SetCursor");
-	scu= op->customdata;
-	scu->selecting= RNA_boolean_get(op->ptr, "select");
+	op->customdata= MEM_callocN(sizeof(SetSelection), "SetCursor");
+	ssel= op->customdata;
+	ssel->selecting= RNA_boolean_get(op->ptr, "select");
 
-	scu->old[0]= event->mval[0];
-	scu->old[1]= event->mval[1];
+	ssel->old[0]= event->mval[0];
+	ssel->old[1]= event->mval[1];
 
-	if(!scu->selecting) {
+	if(!ssel->selecting) {
 		int curl= txt_get_span(st->text->lines.first, st->text->curl);
 		int curc= st->text->curc;			
 		int linep2, charp2;
@@ -2543,8 +2543,8 @@
 			txt_undo_add_toop(st->text, UNDO_CTO, curl, curc, linep2, charp2);
 	}
 
-	scu->sell= txt_get_span(st->text->lines.first, st->text->sell);
-	scu->selc= st->text->selc;
+	ssel->sell= txt_get_span(st->text->lines.first, st->text->sell);
+	ssel->selc= st->text->selc;
 
 	WM_event_add_modal_handler(C, op);
 
@@ -2553,7 +2553,7 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
-static int set_cursor_modal(bContext *C, wmOperator *op, wmEvent *event)
+static int set_selection_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
 	switch(event->type) {
 		case LEFTMOUSE:
@@ -2569,27 +2569,69 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
-static int set_cursor_cancel(bContext *C, wmOperator *op)
+static int set_selection_cancel(bContext *C, wmOperator *op)
 {
 	set_cursor_exit(C, op);
 	return OPERATOR_FINISHED;
 }
 
+void TEXT_OT_selection_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Set Selection";
+	ot->idname= "TEXT_OT_selection_set";
+	ot->description= "Set cursor selection";
+
+	/* api callbacks */
+	ot->invoke= set_selection_invoke;
+	ot->modal= set_selection_modal;
+	ot->cancel= set_selection_cancel;
+	ot->poll= text_region_edit_poll;
+
+	/* properties */
+	RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor.");
+}
+
+/******************* set cursor operator **********************/
+
+static int set_cursor_exec(bContext *C, wmOperator *op)
+{
+	SpaceText *st= CTX_wm_space_text(C);
+	ARegion *ar= CTX_wm_region(C);
+	int x= RNA_int_get(op->ptr, "x");
+	int y= RNA_int_get(op->ptr, "y");
+
+	set_cursor_to_pos(st, ar, x, y, 0);
+
+	text_update_cursor_moved(C);
+	WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
+
+	return OPERATOR_FINISHED;
+}
+
+static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	RNA_int_set(op->ptr, "x", event->mval[0]);
+	RNA_int_set(op->ptr, "y", event->mval[1]);
+
+	return set_cursor_exec(C, op);
+}
+
 void TEXT_OT_cursor_set(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name= "Set Cursor";
 	ot->idname= "TEXT_OT_cursor_set";
-	ot->description= "Set cursor selection";
-	
+	ot->description= "Set cursor position";
+
 	/* api callbacks */
 	ot->invoke= set_cursor_invoke;
-	ot->modal= set_cursor_modal;
-	ot->cancel= set_cursor_cancel;
+	ot->exec= set_cursor_exec;
 	ot->poll= text_region_edit_poll;
 
 	/* properties */
-	RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor.");
+	RNA_def_boolean(ot->srna, "x", 0, "X", "X-coordinate to set cursor to.");
+	RNA_def_boolean(ot->srna, "y", 0, "Y", "X-coordinate to set cursor to.");
 }
 
 /******************* line number operator **********************/




More information about the Bf-blender-cvs mailing list