diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-01 02:33:35 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-01 02:33:35 +0300 |
commit | 6cc89b9d4e6ab17bea0631b1be800dd9a022db23 (patch) | |
tree | 356e3649b94ec7f5a144f1fa6304f5646c4b9bf1 /source/blender/blenkernel/intern | |
parent | 2469305376856e0f53b4ffdbe2bf2576fa25809c (diff) |
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 37 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 122 |
3 files changed, 36 insertions, 124 deletions
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 07937d0a901..fc338e1bc95 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -164,6 +164,21 @@ SpaceLink *CTX_wm_space_data(const bContext *C) return (C->wm.area)? C->wm.area->spacedata.first: NULL; } +ARegion *CTX_wm_region(const bContext *C) +{ + return C->wm.region; +} + +void *CTX_wm_region_data(const bContext *C) +{ + return (C->wm.region)? C->wm.region->regiondata: NULL; +} + +struct uiBlock *CTX_wm_ui_block(const bContext *C) +{ + return C->wm.block; +} + View3D *CTX_wm_view3d(const bContext *C) { if(C->wm.area && C->wm.area->spacetype==SPACE_VIEW3D) @@ -179,19 +194,18 @@ RegionView3D *CTX_wm_region_view3d(const bContext *C) return NULL; } -ARegion *CTX_wm_region(const bContext *C) +struct SpaceText *CTX_wm_space_text(const bContext *C) { - return C->wm.region; + if(C->wm.area && C->wm.area->spacetype==SPACE_TEXT) + return C->wm.area->spacedata.first; + return NULL; } -void *CTX_wm_region_data(const bContext *C) +struct SpaceImage *CTX_wm_space_image(const bContext *C) { - return (C->wm.region)? C->wm.region->regiondata: NULL; -} - -struct uiBlock *CTX_wm_ui_block(const bContext *C) -{ - return C->wm.block; + if(C->wm.area && C->wm.area->spacetype==SPACE_IMAGE) + return C->wm.area->spacedata.first; + return NULL; } void CTX_wm_manager_set(bContext *C, wmWindowManager *wm) @@ -444,6 +458,11 @@ struct ImBuf *CTX_data_edit_image_buffer(const bContext *C) return ctx_data_pointer_get(C, CTX_DATA_EDIT_IMAGE_BUFFER); } +struct Text *CTX_data_edit_text(const bContext *C) +{ + return ctx_data_pointer_get(C, CTX_DATA_EDIT_TEXT); +} + struct EditBone *CTX_data_active_bone(const bContext *C) { return ctx_data_pointer_get(C, CTX_DATA_ACTIVE_BONE); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 7d7d98095c6..30cb4016061 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -108,7 +108,6 @@ void BKE_free_editfont(Curve *cu) /* don't free curve itself */ void free_curve(Curve *cu) { - freeNurblist(&cu->nurb); BLI_freelistN(&cu->bev); freedisplist(&cu->disp); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 999e1744ae6..47a33bdee66 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -65,9 +65,6 @@ A text should relate to a file as follows - (Text *)->flags has the following bits TXT_ISDIRTY - should always be set if the file in mem. differs from the file on disk, or if there is no file on disk. - TXT_ISTMP - should always be set if the (Text *)->name file has not - been written before, and attempts to save should result - in "Save over?" TXT_ISMEM - should always be set if the Text has not been mapped to a file, in which case (Text *)->name may be NULL or garbage. TXT_ISEXT - should always be set if the Text is not to be written into @@ -130,7 +127,6 @@ static void txt_delete_line(Text *text, TextLine *line); /***/ -static char *txt_cut_buffer= NULL; static unsigned char undoing; /* allow to switch off undoing externally */ @@ -179,7 +175,7 @@ Text *add_empty_text(char *name) ta->undo_buf= MEM_mallocN(ta->undo_len, "undo buf"); ta->nlines=1; - ta->flags= TXT_ISDIRTY | TXT_ISTMP | TXT_ISMEM; + ta->flags= TXT_ISDIRTY | TXT_ISMEM; ta->lines.first= ta->lines.last= NULL; ta->markers.first= ta->markers.last= NULL; @@ -257,8 +253,6 @@ int reopen_text(Text *text) text->undo_len= TXT_INIT_UNDO; text->undo_buf= MEM_mallocN(text->undo_len, "undo buf"); - text->flags= TXT_ISTMP; - fseek(fp, 0L, SEEK_END); len= ftell(fp); fseek(fp, 0L, SEEK_SET); @@ -347,9 +341,6 @@ Text *add_text(char *file, const char *relpath) ta->lines.first= ta->lines.last= NULL; ta->markers.first= ta->markers.last= NULL; ta->curl= ta->sell= NULL; - -/* ta->flags= TXT_ISTMP | TXT_ISEXT; */ - ta->flags= TXT_ISTMP; fseek(fp, 0L, SEEK_END); len= ftell(fp); @@ -430,7 +421,7 @@ Text *copy_text(Text *ta) tan->name= MEM_mallocN(strlen(ta->name)+1, "text_name"); strcpy(tan->name, ta->name); - tan->flags = ta->flags | TXT_ISDIRTY | TXT_ISTMP; + tan->flags = ta->flags | TXT_ISDIRTY; tan->lines.first= tan->lines.last= NULL; tan->markers.first= tan->markers.last= NULL; @@ -1056,11 +1047,6 @@ void txt_sel_line (Text *text) /* Cut and paste functions */ /***************************/ -void txt_print_cutbuffer (void) -{ - printf ("Cut buffer\n--\n%s\n--\n", txt_cut_buffer); -} - char *txt_to_buf (Text *text) { int length; @@ -1165,15 +1151,6 @@ int txt_find_string(Text *text, char *findstr, int wrap) return 0; } -void txt_cut_sel (Text *text) -{ - if (!G.background) /* Python uses txt_cut_sel, which it should not, working around for now */ - ; //XXX txt_copy_clipboard(text); - - txt_delete_sel(text); - txt_make_dirty(text); -} - char *txt_sel_to_buf (Text *text) { char *buf; @@ -1251,85 +1228,6 @@ char *txt_sel_to_buf (Text *text) return buf; } -void txt_copy_sel (Text *text) -{ - int length=0; - TextLine *tmp, *linef, *linel; - int charf, charl; - - if (!text) return; - if (!text->curl) return; - if (!text->sell) return; - - if (!txt_has_sel(text)) return; - - if (txt_cut_buffer) MEM_freeN(txt_cut_buffer); - txt_cut_buffer= NULL; - - if (text->curl==text->sell) { - linef= linel= text->curl; - - if (text->curc < text->selc) { - charf= text->curc; - charl= text->selc; - } else{ - charf= text->selc; - charl= text->curc; - } - } else if (txt_get_span(text->curl, text->sell)<0) { - linef= text->sell; - linel= text->curl; - - charf= text->selc; - charl= text->curc; - } else { - linef= text->curl; - linel= text->sell; - - charf= text->curc; - charl= text->selc; - } - - if (linef == linel) { - length= charl-charf; - - txt_cut_buffer= MEM_mallocN(length+1, "cut buffera"); - - BLI_strncpy(txt_cut_buffer, linef->line + charf, length+1); - } else { - length+= linef->len - charf; - length+= charl; - length++; /* For the '\n' */ - - tmp= linef->next; - while (tmp && tmp!= linel) { - length+= tmp->len+1; - tmp= tmp->next; - } - - txt_cut_buffer= MEM_mallocN(length+1, "cut bufferb"); - - strncpy(txt_cut_buffer, linef->line+ charf, linef->len-charf); - length= linef->len-charf; - - txt_cut_buffer[length++]='\n'; - - tmp= linef->next; - while (tmp && tmp!=linel) { - strncpy(txt_cut_buffer+length, tmp->line, tmp->len); - length+= tmp->len; - - txt_cut_buffer[length++]='\n'; - - tmp= tmp->next; - } - strncpy(txt_cut_buffer+length, linel->line, charl); - length+= charl; - - txt_cut_buffer[length]=0; - } -} - void txt_insert_buf(Text *text, char *in_buffer) { int i=0, l=0, j, u, len; @@ -1380,16 +1278,6 @@ void txt_insert_buf(Text *text, char *in_buffer) undoing= u; } -void txt_free_cut_buffer(void) -{ - if (txt_cut_buffer) MEM_freeN(txt_cut_buffer); -} - -void txt_paste(Text *text) -{ - txt_insert_buf(text, txt_cut_buffer); -} - /******************/ /* Undo functions */ /******************/ @@ -2394,6 +2282,12 @@ int txt_add_char (Text *text, char add) return 1; } +void txt_delete_selected(Text *text) +{ + txt_delete_sel(text); + txt_make_dirty(text); +} + int txt_replace_char (Text *text, char add) { char del; |