Revision: 16766
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16766
Author:   campbellbarton
Date:     2008-09-27 17:32:28 +0200 (Sat, 27 Sep 2008)

Log Message:
-----------
text editor changes
* out of sync text dosnt automatically popup a menu anymore since it was too 
easy to click on it without intending to, moved this to an alert button on the 
header.
* "_" character was acting as a delimiter, but in python its not.
* renamed "File" to "Text" (so as not to confuse with blenders file menu)
* added redraw_alltext function to remove many duplicate loops where every text 
display is redrawn.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/text.c
    trunk/blender/source/blender/include/BIF_drawtext.h
    trunk/blender/source/blender/src/drawtext.c
    trunk/blender/source/blender/src/header_text.c

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c       2008-09-27 
10:08:19 UTC (rev 16765)
+++ trunk/blender/source/blender/blenkernel/intern/text.c       2008-09-27 
15:32:28 UTC (rev 16766)
@@ -577,13 +577,14 @@
 /* 0:whitespace, 1:punct, 2:alphanumeric */
 static short txt_char_type (char ch)
 {
-       if (ch <= ' ') return 0;
-       if (ch <= '/') return 1;
-       if (ch <= '9') return 2;
-       if (ch <= '@') return 1;
-       if (ch <= 'Z') return 2;
-       if (ch <= '`') return 1;
-       if (ch <= 'z') return 2;
+       if (ch <= ' ') return 0; /* 32 */
+       if (ch <= '/') return 1; /* 47 */
+       if (ch <= '9') return 2; /* 57 */
+       if (ch <= '@') return 1; /* 64 */
+       if (ch <= 'Z') return 2; /* 90 */
+       if (ch == '_') return 2; /* 95, dont delimit '_' */
+       if (ch <= '`') return 1; /* 96 */
+       if (ch <= 'z') return 2; /* 122 */
        return 1;
 }
 

Modified: trunk/blender/source/blender/include/BIF_drawtext.h
===================================================================
--- trunk/blender/source/blender/include/BIF_drawtext.h 2008-09-27 10:08:19 UTC 
(rev 16765)
+++ trunk/blender/source/blender/include/BIF_drawtext.h 2008-09-27 15:32:28 UTC 
(rev 16766)
@@ -39,7 +39,6 @@
 
 void free_textspace(struct SpaceText *st);
 
-int txt_file_modified(struct Text *text);
 void txt_write_file(struct Text *text);
 void add_text_fs(char *file);
 

Modified: trunk/blender/source/blender/src/drawtext.c
===================================================================
--- trunk/blender/source/blender/src/drawtext.c 2008-09-27 10:08:19 UTC (rev 
16765)
+++ trunk/blender/source/blender/src/drawtext.c 2008-09-27 15:32:28 UTC (rev 
16766)
@@ -30,22 +30,12 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#ifndef _WIN32
-#include <unistd.h>
-#else
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif   
 #include "MEM_guardedalloc.h"
-#include "PIL_time.h"
 
 #include "BMF_Api.h"
 
@@ -88,6 +78,8 @@
 #include "blendef.h" 
 #include "winlay.h"
 
+#include <sys/stat.h>
+
 /***********************/ /*
 
 Notes on word-wrap
@@ -133,6 +125,7 @@
 void winqreadtextspace(struct ScrArea *sa, void *spacedata, struct BWinEvent 
*evt);
 void txt_copy_selectbuffer (Text *text);
 void draw_brackets(SpaceText *st);
+void redraw_alltext(void);
 
 static void get_selection_buffer(Text *text);
 static int check_bracket(char ch);
@@ -152,7 +145,6 @@
 static char *g_replace_str= NULL;
 
 static int doc_scroll= 0;
-static double last_check_time= 0;
 static int jump_to= 0;
 static double last_jump= 0;
 
@@ -1763,60 +1755,6 @@
        st->text= NULL;
 }
 
-/* returns 0 if file on disk is the same or Text is in memory only
-   returns 1 if file has been modified on disk since last local edit
-   returns 2 if file on disk has been deleted
-   -1 is returned if an error occurs
-*/
-int txt_file_modified(Text *text)
-{
-       struct stat st;
-       int result;
-       char file[FILE_MAXDIR+FILE_MAXFILE];
-
-       if (!text || !text->name)
-               return 0;
-
-       BLI_strncpy(file, text->name, FILE_MAXDIR+FILE_MAXFILE);
-       BLI_convertstringcode(file, G.sce);
-
-       if (!BLI_exists(file))
-               return 2;
-
-       result = stat(file, &st);
-       
-       if(result == -1)
-               return -1;
-
-       if((st.st_mode & S_IFMT) != S_IFREG)
-               return -1;
-
-       if (st.st_mtime > text->mtime)
-               return 1;
-
-       return 0;
-}
-
-void txt_ignore_modified(Text *text) {
-       struct stat st;
-       int result;
-       char file[FILE_MAXDIR+FILE_MAXFILE];
-
-       if (!text || !text->name) return;
-
-       BLI_strncpy(file, text->name, FILE_MAXDIR+FILE_MAXFILE);
-       BLI_convertstringcode(file, G.sce);
-
-       if (!BLI_exists(file)) return;
-
-       result = stat(file, &st);
-       
-       if(result == -1 || (st.st_mode & S_IFMT) != S_IFREG)
-               return;
-
-       text->mtime= st.st_mtime;
-}
-
 static void save_mem_text(char *str)
 {
        SpaceText *st= curarea->spacedata.first;
@@ -2459,18 +2397,9 @@
                }
        }
 
-       if (draw) {
-               ScrArea *sa;
-               
-               for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-                       SpaceText *st= sa->spacedata.first;
-                       
-                       if (st && st->spacetype==SPACE_TEXT) {
-                               scrarea_queue_redraw(sa);
-                       }
-               }
-       }
-
+       if (draw)
+               redraw_alltext();
+       
        return swallow;
 }
 
@@ -2632,81 +2561,13 @@
                }
        }
        
-       if (draw) {
-               ScrArea *sa;
-               
-               for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-                       SpaceText *st= sa->spacedata.first;
-                       
-                       if (st && st->spacetype==SPACE_TEXT) {
-                               scrarea_queue_redraw(sa);
-                       }
-               }
-       }
+       if (draw)
+               redraw_alltext();
+       
        return swallow;
 }
 
-static short do_modification_check(SpaceText *st) {
-       Text *text= st->text;
 
-       if (last_check_time < PIL_check_seconds_timer() - 2.0) {
-               switch (txt_file_modified(text)) {
-               case 1:
-                       /* Modified locally and externally, ahhh. Offer more 
possibilites. */
-                       if (text->flags & TXT_ISDIRTY) {
-                               switch (pupmenu("File Modified Outside and 
Inside Blender %t|Load outside changes (ignore local changes) %x0|Save local 
changes (ignore outside changes) %x1|Make text internal (separate copy) %x2")) {
-                               case 0:
-                                       reopen_text(text);
-                                       if (st->showsyntax) txt_format_text(st);
-                                       return 1;
-                               case 1:
-                                       txt_write_file(text);
-                                       return 1;
-                               case 2:
-                                       text->flags |= TXT_ISMEM | TXT_ISDIRTY 
| TXT_ISTMP;
-                                       MEM_freeN(text->name);
-                                       text->name= NULL;
-                                       return 1;
-                               }
-                       } else {
-                               switch (pupmenu("File Modified Outside Blender 
%t|Reload from disk %x0|Make text internal (separate copy) %x1|Ignore %x2")) {
-                               case 0:
-                                       if (text->compiled) 
BPY_free_compiled_text(text);
-                                               text->compiled = NULL;
-                                       reopen_text(text);
-                                       if (st->showsyntax) txt_format_text(st);
-                                       return 1;
-                               case 1:
-                                       text->flags |= TXT_ISMEM | TXT_ISDIRTY 
| TXT_ISTMP;
-                                       MEM_freeN(text->name);
-                                       text->name= NULL;
-                                       return 1;
-                               case 2:
-                                       txt_ignore_modified(text);
-                                       return 1;
-                               }
-                       }
-                       break;
-               case 2:
-                       switch (pupmenu("File Deleted Outside Blender %t|Make 
text internal %x0|Recreate file %x1")) {
-                       case 0:
-                               text->flags |= TXT_ISMEM | TXT_ISDIRTY | 
TXT_ISTMP;
-                               MEM_freeN(text->name);
-                               text->name= NULL;
-                               return 1;
-                       case 1:
-                               txt_write_file(text);
-                               return 1;
-                       }
-                       break;
-               default:
-                       break;
-               }
-               last_check_time = PIL_check_seconds_timer();
-       }
-       return 0;
-}
-
 void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
@@ -3315,19 +3176,8 @@
                }
        }
 
-       if (do_modification_check(st)) do_draw= 1;
-
-       if (do_draw) {
-               ScrArea *sa;
-               
-               for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-                       SpaceText *st= sa->spacedata.first;
-                       
-                       if (st && st->spacetype==SPACE_TEXT) {
-                               scrarea_queue_redraw(sa);
-                       }
-               }
-       }
+       if (do_draw)
+               redraw_alltext();
 }
 
 void draw_brackets(SpaceText *st)
@@ -3582,3 +3432,19 @@
 
        if (st->showsyntax) txt_format_text(st);
 }
+
+void redraw_alltext(void)
+{
+       ScrArea *sa;
+       
+       if(!G.curscreen)
+               return;
+       
+       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
+               SpaceText *st= sa->spacedata.first;
+               
+               if (st && st->spacetype==SPACE_TEXT) {
+                       scrarea_queue_redraw(sa);
+               }
+       }
+}

Modified: trunk/blender/source/blender/src/header_text.c
===================================================================
--- trunk/blender/source/blender/src/header_text.c      2008-09-27 10:08:19 UTC 
(rev 16765)
+++ trunk/blender/source/blender/src/header_text.c      2008-09-27 15:32:28 UTC 
(rev 16766)
@@ -76,6 +76,22 @@
 #include "blendef.h"
 #include "mydevice.h"
 
+#include "PIL_time.h"
+
+/* file time checking */
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#include <io.h>
+#include "BLI_winstuff.h"
+#endif
+
+extern void redraw_alltext(void); /* defined in drawtext.c */
+
 void do_text_buttons(unsigned short event)
 {
        SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg 
here */
@@ -362,12 +378,8 @@
        default:
                break;
        }
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       
+       redraw_alltext();
 }
 
 /* action executed after clicking in Edit menu */
@@ -428,12 +440,7 @@
                break;
        }
 
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       redraw_alltext();
 }
 
 /* action executed after clicking in View menu */
@@ -459,13 +466,8 @@
                default:
                        break;
        }
-
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       
+       redraw_alltext();
 }
 
 /* action executed after clicking in Select menu */
@@ -490,12 +492,7 @@
                break;
        }
 
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       redraw_alltext();
 }
 
 /* action executed after clicking in Markers menu */
@@ -541,12 +538,7 @@
                break;
        }
 
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       redraw_alltext();
 }
 
 /* action executed after clicking in Format menu */
@@ -614,12 +606,7 @@
                break;
        }
 
-       for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               SpaceText *st= sa->spacedata.first;
-               if (st && st->spacetype==SPACE_TEXT) {
-                       scrarea_queue_redraw(sa);
-               }
-       }
+       redraw_alltext();
 }
 
 /* View menu */
@@ -861,6 +848,133 @@
        return block;
 }
 
+
+/* text sync functions */
+
+/* returns 0 if file on disk is the same or Text is in memory only
+   returns 1 if file has been modified on disk since last local edit
+   returns 2 if file on disk has been deleted
+   -1 is returned if an error occurs
+*/
+static int txt_file_modified(Text *text)
+{
+       struct stat st;
+       int result;
+       char file[FILE_MAXDIR+FILE_MAXFILE];
+
+       if (!text || !text->name)
+               return 0;
+
+       BLI_strncpy(file, text->name, FILE_MAXDIR+FILE_MAXFILE);
+       BLI_convertstringcode(file, G.sce);
+
+       if (!BLI_exists(file))
+               return 2;
+
+       result = stat(file, &st);
+       
+       if(result == -1)
+               return -1;
+
+       if((st.st_mode & S_IFMT) != S_IFREG)
+               return -1;
+
+       if (st.st_mtime > text->mtime)
+               return 1;
+
+       return 0;
+}
+
+static void txt_ignore_modified(Text *text) {
+       struct stat st;
+       int result;
+       char file[FILE_MAXDIR+FILE_MAXFILE];
+

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to