[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16112] branches/soc-2008-quorn/source/ blender: Got rid of the horrible blocking UI problems with Find and Replace by using a blockhandler panel .
Ian Thompson
quornian at googlemail.com
Thu Aug 14 18:22:25 CEST 2008
Revision: 16112
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16112
Author: quorn
Date: 2008-08-14 18:22:25 +0200 (Thu, 14 Aug 2008)
Log Message:
-----------
Got rid of the horrible blocking UI problems with Find and Replace by using a blockhandler panel. The panel is shown when find is invoked with Alt F (or from the menu). Successive presses of Alt F search again, while the panel is visible. Alt H does the same for replace. (Ctrl F and Ctrl H also work - more like other editors)
Modified Paths:
--------------
branches/soc-2008-quorn/source/blender/blenkernel/BKE_text.h
branches/soc-2008-quorn/source/blender/include/BIF_space.h
branches/soc-2008-quorn/source/blender/include/blendef.h
branches/soc-2008-quorn/source/blender/src/drawtext.c
branches/soc-2008-quorn/source/blender/src/header_text.c
Modified: branches/soc-2008-quorn/source/blender/blenkernel/BKE_text.h
===================================================================
--- branches/soc-2008-quorn/source/blender/blenkernel/BKE_text.h 2008-08-14 15:37:47 UTC (rev 16111)
+++ branches/soc-2008-quorn/source/blender/blenkernel/BKE_text.h 2008-08-14 16:22:25 UTC (rev 16112)
@@ -87,7 +87,7 @@
void txt_backspace_word (struct Text *text);
int txt_add_char (struct Text *text, char add);
int txt_replace_char (struct Text *text, char add);
-void txt_find_panel (struct SpaceText *st, int again, int flags);
+void find_and_replace (struct SpaceText *st, short mode);
void run_python_script (struct SpaceText *st);
int jumptoline_interactive (struct SpaceText *st);
void txt_export_to_object (struct Text *text);
@@ -153,11 +153,8 @@
#define UNDO_UNCOMMENT 035
/* Find and replace flags */
-#define TXT_FIND_REPLACE 0x01
+#define TXT_FIND_WRAP 0x01
#define TXT_FIND_ALLTEXTS 0x02
-#define TXT_FIND_WRAP 0x04
-#define TXT_FIND_MARKALL 0x08
-#define TXT_FIND_KEEP 0x10
/* Marker flags */
#define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */
Modified: branches/soc-2008-quorn/source/blender/include/BIF_space.h
===================================================================
--- branches/soc-2008-quorn/source/blender/include/BIF_space.h 2008-08-14 15:37:47 UTC (rev 16111)
+++ branches/soc-2008-quorn/source/blender/include/BIF_space.h 2008-08-14 16:22:25 UTC (rev 16112)
@@ -83,6 +83,9 @@
/* nodes handler codes */
#define NODES_HANDLER_GREASEPENCIL 80
+/* text handler codes */
+#define TEXT_HANDLER_FIND 90
+
/* theme codes */
#define B_ADD_THEME 3301
#define B_DEL_THEME 3302
Modified: branches/soc-2008-quorn/source/blender/include/blendef.h
===================================================================
--- branches/soc-2008-quorn/source/blender/include/blendef.h 2008-08-14 15:37:47 UTC (rev 16111)
+++ branches/soc-2008-quorn/source/blender/include/blendef.h 2008-08-14 16:22:25 UTC (rev 16112)
@@ -379,6 +379,11 @@
#define B_SYNTAX 509
#define B_WORDWRAP 510
#define B_TEXTPLUGINS 511
+#define B_PASTEFIND 512
+#define B_PASTEREPLACE 513
+#define B_TEXTREPLACE 514
+#define B_TEXTFIND 515
+#define B_TEXTMARKALL 516
/* SCRIPT: 525 */
#define B_SCRIPTBROWSE 526
Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-08-14 15:37:47 UTC (rev 16111)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-08-14 16:22:25 UTC (rev 16112)
@@ -149,9 +149,9 @@
static void confirm_suggestion(Text *text, int skipleft);
#define TXT_MAXFINDSTR 255
-static int last_find_flags= TXT_FIND_WRAP | TXT_FIND_KEEP;
-static char *last_find_string= NULL;
-static char *last_repl_string= NULL;
+static int g_find_flags= TXT_FIND_WRAP;
+static char *g_find_str= NULL;
+static char *g_replace_str= NULL;
static int doc_scroll= 0;
static double last_check_time= 0;
@@ -217,8 +217,8 @@
void free_txt_data(void) {
txt_free_cut_buffer();
- if (last_find_string) MEM_freeN(last_find_string);
- if (last_repl_string) MEM_freeN(last_repl_string);
+ if (g_find_str) MEM_freeN(g_find_str);
+ if (g_replace_str) MEM_freeN(g_replace_str);
if (temp_char_buf) MEM_freeN(temp_char_buf);
if (temp_char_accum) MEM_freeN(temp_char_accum);
}
@@ -1458,6 +1458,163 @@
}
}
+static short check_blockhandler(SpaceText *st, short handler) {
+ short a;
+ for(a=0; a<SPACE_MAXHANDLER; a+=2)
+ if (st->blockhandler[a]==handler) return 1;
+ return 0;
+}
+
+static void text_panel_find(short cntrl) // TEXT_HANDLER_FIND
+{
+ uiBlock *block;
+
+ if (!g_find_str || !g_replace_str) {
+ g_find_str= MEM_mallocN(TXT_MAXFINDSTR+1, "find_string");
+ g_replace_str= MEM_mallocN(TXT_MAXFINDSTR+1, "replace_string");
+ g_find_str[0]= g_replace_str[0]= '\0';
+ }
+
+ block= uiNewBlock(&curarea->uiblocks, "text_panel_find", UI_EMBOSS, UI_HELV, curarea->win);
+ uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
+ uiSetPanelHandler(TEXT_HANDLER_FIND); // for close and esc
+ if(uiNewPanel(curarea, block, "Find & Replace", "Text", curarea->winx-230, curarea->winy-130, 260, 120)==0) return;
+
+ uiBlockBeginAlign(block);
+ uiDefButC(block, TEX, 0, "Find: ", 0,80,220,20, g_find_str, 0,(float)TXT_MAXFINDSTR, 0,0, "");
+ uiDefIconBut(block, BUT, B_PASTEFIND, ICON_TEXT, 220,80,20,20, NULL, 0,0,0,0, "Copy from selection");
+ uiDefButC(block, TEX, 0, "Replace: ", 0,60,220,20, g_replace_str, 0,(float)TXT_MAXFINDSTR, 0,0, "");
+ uiDefIconBut(block, BUT, B_PASTEREPLACE, ICON_TEXT, 220,60,20,20, NULL, 0,0,0,0, "Copy from selection");
+ uiBlockEndAlign(block);
+ uiDefButBitI(block, TOG, TXT_FIND_WRAP, 0,"Wrap Around", 0,30,110,20,&g_find_flags,0,0,0,0,"Wrap search around current text");
+ uiDefButBitI(block, TOG, TXT_FIND_ALLTEXTS,0,"Search All Texts", 110,30,130,20,&g_find_flags,0,0,0,0,"Search in each text");
+ uiDefBut(block, BUT, B_TEXTFIND, "Find", 0,0,50,20, NULL, 0,0,0,0, "Find next");
+ uiDefBut(block, BUT, B_TEXTREPLACE, "Replace/Find", 50,0,110,20, NULL, 0,0,0,0, "Replace then find next");
+ uiDefBut(block, BUT, B_TEXTMARKALL, "Mark All", 160,0,80,20, NULL, 0,0,0,0, "Mark each occurrence to edit all from one");
+}
+
+/* mode: 0 find only, 1 replace/find, 2 mark all occurrences */
+void find_and_replace(SpaceText *st, short mode) {
+ char *tmp;
+ Text *start= NULL, *text= st->text;
+ int flags, first= 1;
+
+ if (!check_blockhandler(st, TEXT_HANDLER_FIND)) {
+ toggle_blockhandler(st->area, TEXT_HANDLER_FIND, UI_PNL_TO_MOUSE);
+ return;
+ }
+
+ if (!g_find_str || !g_replace_str) return;
+ if (g_find_str[0] == '\0') return;
+ flags= g_find_flags;
+ if (flags & TXT_FIND_ALLTEXTS) flags ^= TXT_FIND_WRAP;
+
+ do {
+ if (first)
+ txt_clear_markers(text, TMARK_GRP_FINDALL);
+ first= 0;
+
+ /* Replace current */
+ if (mode && txt_has_sel(text)) {
+ tmp= txt_sel_to_buf(text);
+ if (strcmp(g_find_str, tmp)==0) {
+ if (mode==1) {
+ txt_insert_buf(text, g_replace_str);
+ if (st->showsyntax) txt_format_line(st, text->curl, 1);
+ } else if (mode==2) {
+ char clr[4];
+ BIF_GetThemeColor4ubv(TH_SHADE2, clr);
+ if (txt_find_marker(text, text->curl, text->selc, TMARK_GRP_FINDALL)) {
+ if (tmp) MEM_freeN(tmp), tmp=NULL;
+ break;
+ }
+ txt_add_marker(text, text->curl, text->curc, text->selc, clr, TMARK_GRP_FINDALL | TMARK_EDITALL);
+ }
+ }
+ MEM_freeN(tmp);
+ tmp= NULL;
+ }
+
+ /* Find next */
+ if (txt_find_string(text, g_find_str, flags & TXT_FIND_WRAP)) {
+ pop_space_text(st);
+ } else if (flags & TXT_FIND_ALLTEXTS) {
+ if (text==start) break;
+ if (!start) start= text;
+ if (text->id.next)
+ text= st->text= text->id.next;
+ else
+ text= st->text= G.main->text.first;
+ txt_move_toline(text, 0, 0);
+ pop_space_text(st);
+ first= 1;
+ } else {
+ okee("Text not found: %s", g_find_str);
+ break;
+ }
+ } while (mode==2);
+}
+
+static void do_find_buttons(val) {
+ Text *text;
+ SpaceText *st;
+ int do_draw= 0;
+ char *tmp;
+
+ st= curarea->spacedata.first;
+ if (!st || st->spacetype != SPACE_TEXT) return;
+ text= st->text;
+ if (!text) return;
+
+ switch (val) {
+ case B_PASTEFIND:
+ if (!g_find_str) break;
+ tmp= txt_sel_to_buf(text);
+ strncpy(g_find_str, tmp, TXT_MAXFINDSTR);
+ MEM_freeN(tmp);
+ do_draw= 1;
+ break;
+ case B_PASTEREPLACE:
+ if (!g_replace_str) break;
+ tmp= txt_sel_to_buf(text);
+ strncpy(g_replace_str, tmp, TXT_MAXFINDSTR);
+ MEM_freeN(tmp);
+ do_draw= 1;
+ break;
+ case B_TEXTFIND:
+ find_and_replace(st, 0);
+ do_draw= 1;
+ break;
+ case B_TEXTREPLACE:
+ find_and_replace(st, 1);
+ do_draw= 1;
+ break;
+ case B_TEXTMARKALL:
+ find_and_replace(st, 2);
+ do_draw= 1;
+ break;
+ }
+}
+
+static void text_blockhandlers(ScrArea *sa)
+{
+ SpaceText *st= sa->spacedata.first;
+ short a;
+
+ /* warning; blocks need to be freed each time, handlers dont remove */
+ uiFreeBlocksWin(&sa->uiblocks, sa->win);
+
+ for(a=0; a<SPACE_MAXHANDLER; a+=2) {
+ /* clear action value for event */
+ switch(st->blockhandler[a]) {
+ case TEXT_HANDLER_FIND:
+ text_panel_find(st->blockhandler[a+1]);
+ break;
+ }
+ }
+ uiDrawBlocksPanels(sa, 0);
+}
+
void drawtextspace(ScrArea *sa, void *spacedata)
{
SpaceText *st= curarea->spacedata.first;
@@ -1470,6 +1627,9 @@
if (st==NULL || st->spacetype != SPACE_TEXT) return;
+ bwin_clear_viewmat(sa->win); /* clear buttons view */
+ glLoadIdentity();
+
BIF_GetThemeColor3fv(TH_BACK, col);
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
@@ -1541,7 +1701,10 @@
draw_textscroll(st);
draw_documentation(st);
draw_suggestion_list(st);
-
+
+ bwin_scalematrix(sa->win, st->blockscale, st->blockscale, st->blockscale);
+ text_blockhandlers(sa);
+
curarea->win_swap= WIN_BACK_OK;
}
@@ -1913,163 +2076,6 @@
}
}
-static short find_and_replace_popup(short focus)
-{
- uiBlock *block;
- ListBase listb={0, 0};
- short x1,y1;
- short ret=0;
- char *editfindvar=NULL, *editreplvar=NULL; /* dont edit the original text, incase we cancel the popup */
-
- block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
- uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_ENTER_OK);
-
- x1= curarea->winrct.xmax - 240;
- y1= curarea->winrct.ymin;
-
- editfindvar = MEM_callocN(TXT_MAXFINDSTR+1, "findvar");
- editreplvar = MEM_callocN(TXT_MAXFINDSTR+1, "replvar");
- BLI_strncpy(editfindvar, last_find_string, TXT_MAXFINDSTR);
- BLI_strncpy(editreplvar, last_repl_string, TXT_MAXFINDSTR);
-
- uiDefButC(block, TEX, 1, "Find: ", x1+5,y1+85,225,20, editfindvar, 0,(float)TXT_MAXFINDSTR, 0, 0, "");
- uiDefButC(block, TEX, 2, "Replace: ", x1+5,y1+60,225,20, editreplvar, 0,(float)TXT_MAXFINDSTR, 0, 0, "");
- uiDefButBitI(block, TOG, TXT_FIND_WRAP, 3,"Wrap", x1+ 5,y1+35,60,20,&last_find_flags,0,0,0,0,"Wrap search around current text");
- uiDefButBitI(block, TOG, TXT_FIND_ALLTEXTS,4,"All Texts", x1+ 65,y1+35,70,20,&last_find_flags,0,0,0,0,"Search all texts");
- uiDefButBitI(block, TOG, TXT_FIND_KEEP, 5,"Keep Visible",x1+135,y1+35,95,20,&last_find_flags,0,0,0,0,"Keep the find panel visible");
- uiDefBut(block, BUT, 6, "Replace/Find", x1+ 5,y1+10,90,20, NULL, 0, 0, 0, 0, "Replace then find next");
- uiDefBut(block, BUT, 7, "Find", x1+ 95,y1+10,60,20, NULL, 0, 0, 0, 0, "Find next");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list