Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-03-01 02:33:35 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-03-01 02:33:35 +0300
commit6cc89b9d4e6ab17bea0631b1be800dd9a022db23 (patch)
tree356e3649b94ec7f5a144f1fa6304f5646c4b9bf1 /source/blender/blenkernel
parent2469305376856e0f53b4ffdbe2bf2576fa25809c (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')
-rw-r--r--source/blender/blenkernel/BKE_context.h14
-rw-r--r--source/blender/blenkernel/BKE_text.h17
-rw-r--r--source/blender/blenkernel/intern/context.c37
-rw-r--r--source/blender/blenkernel/intern/curve.c1
-rw-r--r--source/blender/blenkernel/intern/text.c122
5 files changed, 49 insertions, 142 deletions
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index a95b436d016..e384900e0cb 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -50,11 +50,14 @@ struct RegionView3D;
struct StructRNA;
struct ToolSettings;
struct Image;
+struct Text;
struct ImBuf;
struct EditBone;
struct bPoseChannel;
struct wmWindow;
struct wmWindowManager;
+struct SpaceText;
+struct SpaceImage;
/* Structs */
@@ -83,6 +86,8 @@ enum {
CTX_DATA_EDIT_IMAGE,
CTX_DATA_EDIT_IMAGE_BUFFER,
+ CTX_DATA_EDIT_TEXT,
+
CTX_DATA_SELECTED_NODES,
CTX_DATA_SELECTED_BONES,
@@ -132,12 +137,15 @@ struct wmWindow *CTX_wm_window(const bContext *C);
struct bScreen *CTX_wm_screen(const bContext *C);
struct ScrArea *CTX_wm_area(const bContext *C);
struct SpaceLink *CTX_wm_space_data(const bContext *C);
-struct View3D *CTX_wm_view3d(const bContext *C);
-struct RegionView3D *CTX_wm_region_view3d(const bContext *C);
struct ARegion *CTX_wm_region(const bContext *C);
void *CTX_wm_region_data(const bContext *C);
struct uiBlock *CTX_wm_ui_block(const bContext *C);
+struct View3D *CTX_wm_view3d(const bContext *C);
+struct RegionView3D *CTX_wm_region_view3d(const bContext *C);
+struct SpaceText *CTX_wm_space_text(const bContext *C);
+struct SpaceImage *CTX_wm_space_image(const bContext *C);
+
void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
void CTX_wm_window_set(bContext *C, struct wmWindow *win);
void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */
@@ -196,6 +204,8 @@ struct Object *CTX_data_edit_object(const bContext *C);
struct Image *CTX_data_edit_image(const bContext *C);
struct ImBuf *CTX_data_edit_image_buffer(const bContext *C);
+struct Text *CTX_data_edit_text(const bContext *C);
+
int CTX_data_selected_nodes(const bContext *C, ListBase *list);
struct EditBone *CTX_data_active_bone(const bContext *C);
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index 856abf74011..d288c0b6516 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -47,8 +47,6 @@ int reopen_text (struct Text *text);
struct Text* add_text (char *file, const char *relpath);
struct Text* copy_text (struct Text *ta);
-void txt_free_cut_buffer (void);
-
char* txt_to_buf (struct Text *text);
void txt_clean_text (struct Text *text);
void txt_order_cursors (struct Text *text);
@@ -70,14 +68,11 @@ void txt_move_to (struct Text *text, unsigned int line, unsigned int ch, short
void txt_pop_sel (struct Text *text);
void txt_delete_char (struct Text *text);
void txt_delete_word (struct Text *text);
-void txt_copy_sel (struct Text *text);
+void txt_delete_selected (struct Text *text);
void txt_sel_all (struct Text *text);
void txt_sel_line (struct Text *text);
-void txt_print_cutbuffer (void);
-void txt_cut_sel (struct Text *text);
char* txt_sel_to_buf (struct Text *text);
void txt_insert_buf (struct Text *text, char *in_buffer);
-void txt_paste (struct Text *text);
void txt_print_undo (struct Text *text);
void txt_undo_add_toop (struct Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc);
void txt_do_undo (struct Text *text);
@@ -87,9 +82,6 @@ void txt_backspace_char (struct Text *text);
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 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);
void txt_export_to_objects(struct Text *text);
void unindent (struct Text *text);
@@ -97,9 +89,6 @@ void comment (struct Text *text);
void indent (struct Text *text);
void uncomment (struct Text *text);
int setcurr_tab (struct Text *text);
-void convert_tabs (struct SpaceText *st, int tab);
-void txt_copy_clipboard (struct Text *text);
-void txt_paste_clipboard (struct Text *text);
void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, char color[4], int group, int flags);
short txt_clear_marker_region (struct Text *text, struct TextLine *line, int start, int end, int group, int flags);
@@ -152,10 +141,6 @@ struct TextMarker *txt_next_marker_color (struct Text *text, struct TextMarker *
#define UNDO_COMMENT 034
#define UNDO_UNCOMMENT 035
-/* Find and replace flags */
-#define TXT_FIND_WRAP 0x01
-#define TXT_FIND_ALLTEXTS 0x02
-
/* Marker flags */
#define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */
#define TMARK_EDITALL 0x02 /* Edit all markers of the same group as one */
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;