Merged from trunk with revision range 36835-37865,
[blender.git] / source / blender / editors / space_text / space_text.c
index 0b30587c5216e7446866e1bb675f1a334be36f42..550f2c937fd04af1a885b42e8680f727f8c145de 100644 (file)
@@ -1,5 +1,5 @@
-/**
- * $Id:
+/*
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008 Blender Foundation.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/space_text/space_text.c
+ *  \ingroup sptext
+ */
+
+
 #include <string.h>
 #include <stdio.h>
 
 #include "DNA_text_types.h"
 #include "DNA_object_types.h"
-#include "DNA_space_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
-#include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_screen.h"
 
 
 #include "RNA_access.h"
 
-#include "ED_markers.h"
 
 #include "text_intern.h"       // own include
 
 /* ******************** default callbacks for text space ***************** */
 
-static SpaceLink *text_new(const bContext *C)
+static SpaceLink *text_new(const bContext *UNUSED(C))
 {
        ARegion *ar;
        SpaceText *stext;
@@ -76,6 +76,7 @@ static SpaceLink *text_new(const bContext *C)
 
        stext->lheight= 12;
        stext->tabnumber= 4;
+       stext->margin_column= 80;
        
        /* header */
        ar= MEM_callocN(sizeof(ARegion), "header for text");
@@ -99,11 +100,12 @@ static void text_free(SpaceLink *sl)
        SpaceText *stext= (SpaceText*) sl;
        
        stext->text= NULL;
+       text_free_caches(stext);
 }
 
 
 /* spacetype; init callback */
-static void text_init(struct wmWindowManager *wm, ScrArea *sa)
+static void text_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
 {
 
 }
@@ -111,9 +113,11 @@ static void text_init(struct wmWindowManager *wm, ScrArea *sa)
 static SpaceLink *text_duplicate(SpaceLink *sl)
 {
        SpaceText *stextn= MEM_dupallocN(sl);
-       
+
        /* clear or remove stuff from old */
-       
+
+       stextn->drawcache= NULL; /* space need it's own cache */
+
        return (SpaceLink *)stextn;
 }
 
@@ -124,23 +128,33 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
        /* context changes */
        switch(wmn->category) {
                case NC_TEXT:
-                       if(!wmn->reference || wmn->reference == st->text) {
-                               ED_area_tag_redraw(sa);
-
-                               if(wmn->data == ND_CURSOR || wmn->action == NA_EDITED) {
-                                       ARegion *ar;
-
-                                       for(ar=sa->regionbase.first; ar; ar= ar->next)
-                                               if(ar->regiontype==RGN_TYPE_WINDOW)
-                                                       text_update_cursor_moved(st, ar);
-                               }
+                       /* check if active text was changed, no need to redraw if text isn't active
+                          reference==NULL means text was unlinked, should update anyway for this
+                          case -- no way to know was text active before unlinking or not */
+                       if(wmn->reference && wmn->reference != st->text)
+                               break;
+
+                       switch(wmn->data) {
+                               case ND_DISPLAY:
+                               case ND_CURSOR:
+                                       ED_area_tag_redraw(sa);
+                                       break;
+                       }
 
-                               if(wmn->action == NA_EDITED)
-                                       if(st->text)
+                       switch(wmn->action) {
+                               case NA_EDITED:
+                                       if(st->text) {
+                                               text_drawcache_tag_update(st, 1);
                                                text_update_edited(st->text);
+                                       }
+
+                                       ED_area_tag_redraw(sa);
+                                       /* no break -- fall down to tag redraw */
+                               case NA_ADDED:
+                               case NA_REMOVED:
+                                       ED_area_tag_redraw(sa);
+                                       break;
                        }
-                       else if(wmn->data == ND_DISPLAY)
-                               ED_area_tag_redraw(sa);
 
                        break;
                case NC_SPACE:
@@ -178,6 +192,7 @@ static void text_operatortypes(void)
 
        WM_operatortype_append(TEXT_OT_select_line);
        WM_operatortype_append(TEXT_OT_select_all);
+       WM_operatortype_append(TEXT_OT_select_word);
 
        WM_operatortype_append(TEXT_OT_jump);
        WM_operatortype_append(TEXT_OT_move);
@@ -185,6 +200,7 @@ static void text_operatortypes(void)
        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);
@@ -209,24 +225,55 @@ static void text_operatortypes(void)
 static void text_keymap(struct wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap;
+       wmKeyMapItem *kmi;
        
        keymap= WM_keymap_find(keyconf, "Text", SPACE_TEXT, 0);
        
        #ifdef __APPLE__
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
-       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_END);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", PREV_WORD);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", NEXT_WORD);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM);
+       
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
-       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_END);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", PREV_WORD);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", NEXT_WORD);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM);
+       
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", DEL_PREV_WORD);
+       
        WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0); 
        WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_find", FKEY, KM_PRESS, KM_OSKEY, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_OSKEY, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_find_set_selected", EKEY, KM_PRESS, KM_OSKEY, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_OSKEY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
        #endif
        
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
+       RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
+       RNA_boolean_set(kmi->ptr, "reverse", 0);
+       
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
+       RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
+       RNA_boolean_set(kmi->ptr, "reverse", 1);
+
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
+       RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
+       RNA_boolean_set(kmi->ptr, "reverse", 0);
+       
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
+       RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
+       RNA_boolean_set(kmi->ptr, "reverse", 1);
+       
        WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
@@ -239,21 +286,25 @@ static void text_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
 
+       WM_keymap_add_item(keymap, "TEXT_OT_cut", DELKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0);
+
        if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic
                RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1);
 
-       WM_keymap_add_item(keymap, "TEXT_OT_jump", GKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_find", FKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0);
        
        WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_ALT, 0);
 
        WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
+       RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0)->ptr, "split_lines", 1);
 
        WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_select_word", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
        
 
        WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0);
@@ -261,13 +312,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
 
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
-       
-       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_BEGIN);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
-       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_BEGIN);
+       
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_END);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "type", LINE_END);
-       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
@@ -276,6 +324,8 @@ static void text_keymap(struct wmKeyConfig *keyconf)
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_BOTTOM);
 
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
@@ -287,37 +337,44 @@ static void text_keymap(struct wmKeyConfig *keyconf)
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_BOTTOM);
 
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR);
+       RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", DEL_PREV_CHAR); /* same as above [#26623] */
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
        RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
-
+       
        WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0);
 
        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_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);
 
-       WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
-
        WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_line_break", PADENTER, KM_PRESS, 0, 0);
 
+       WM_keymap_add_menu(keymap, "TEXT_MT_toolbox", RIGHTMOUSE, KM_PRESS, KM_ANY, 0);
+       
        WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
 }
 
+const char *text_context_dir[] = {"edit_text", NULL};
+
 static int text_context(const bContext *C, const char *member, bContextDataResult *result)
 {
        SpaceText *st= CTX_wm_space_text(C);
 
        if(CTX_data_dir(member)) {
-               static const char *dir[] = {"edit_text", NULL};
-               CTX_data_dir_set(result, dir);
+               CTX_data_dir_set(result, text_context_dir);
                return 1;
        }
        else if(CTX_data_equals(member, "edit_text")) {
@@ -334,12 +391,18 @@ static int text_context(const bContext *C, const char *member, bContextDataResul
 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
        wmKeyMap *keymap;
+       ListBase *lb;
        
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
        
        /* own keymap */
        keymap= WM_keymap_find(wm->defaultconf, "Text", SPACE_TEXT, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+       
+       /* add drop boxes */
+       lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
+       
+       WM_event_add_dropbox_handler(&ar->handlers, lb);
 }
 
 static void text_main_area_draw(const bContext *C, ARegion *ar)
@@ -347,14 +410,12 @@ static void text_main_area_draw(const bContext *C, ARegion *ar)
        /* draw entirely, view changes should be handled here */
        SpaceText *st= CTX_wm_space_text(C);
        //View2D *v2d= &ar->v2d;
-       float col[3];
        
        /* clear and setup matrix */
-       UI_GetThemeColor3fv(TH_BACK, col);
-       glClearColor(col[0], col[1], col[2], 0.0);
+       UI_ThemeClearColor(TH_BACK);
        glClear(GL_COLOR_BUFFER_BIT);
        
-       // UI_view2d_view_ortho(C, v2d);
+       // UI_view2d_view_ortho(v2d);
                
        /* data... */
        draw_text_main(st, ar);
@@ -365,15 +426,45 @@ static void text_main_area_draw(const bContext *C, ARegion *ar)
        /* scrollers? */
 }
 
-static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
+static void text_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
 {
        WM_cursor_set(win, BC_TEXTEDITCURSOR);
 }
 
+
+
+/* ************* dropboxes ************* */
+
+static int text_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
+{
+       if(drag->type==WM_DRAG_PATH)
+               if(ELEM(drag->icon, ICON_FILE_SCRIPT, ICON_FILE_BLANK)) /* rule might not work? */
+                       return 1;
+       return 0;
+}
+
+static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+       /* copy drag path to properties */
+       RNA_string_set(drop->ptr, "filepath", drag->path);
+}
+
+/* this region dropbox definition */
+static void text_dropboxes(void)
+{
+       ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
+       
+       WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
+
+}
+
+/* ************* end drop *********** */
+
+
 /****************** header region ******************/
 
 /* add handlers, stuff you only do once or on area/region changes */
-static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
+static void text_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
 {
        ED_region_header_init(ar);
 }
@@ -405,6 +496,7 @@ void ED_spacetype_text(void)
        ARegionType *art;
        
        st->spaceid= SPACE_TEXT;
+       strncpy(st->name, "Text", BKE_ST_MAXNAME);
        
        st->new= text_new;
        st->free= text_free;
@@ -414,6 +506,7 @@ void ED_spacetype_text(void)
        st->keymap= text_keymap;
        st->listener= text_listener;
        st->context= text_context;
+       st->dropboxes = text_dropboxes;
        
        /* regions: main window */
        art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
@@ -427,8 +520,8 @@ void ED_spacetype_text(void)
        /* regions: properties */
        art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
        art->regionid = RGN_TYPE_UI;
-       art->minsizex= UI_COMPACT_PANEL_WIDTH;
-       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
+       art->prefsizex= UI_COMPACT_PANEL_WIDTH;
+       art->keymapflag= ED_KEYMAP_UI;
        
        art->init= text_properties_area_init;
        art->draw= text_properties_area_draw;
@@ -437,8 +530,8 @@ void ED_spacetype_text(void)
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
        art->regionid = RGN_TYPE_HEADER;
-       art->minsizey= HEADERY;
-       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
+       art->prefsizey= HEADERY;
+       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
        
        art->init= text_header_area_init;
        art->draw= text_header_area_draw;