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
This commit is contained in:
Brecht Van Lommel 2009-02-28 23:33:35 +00:00
parent 2469305376
commit 6cc89b9d4e
49 changed files with 15483 additions and 425 deletions

@ -771,14 +771,16 @@ extern GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
/**
* Return the data from the clipboad
* @return clipboard data
* @param return the selection instead, X11 only feature
* @return clipboard data
*/
extern GHOST_TUns8* GHOST_getClipboard(int flag);
extern GHOST_TUns8* GHOST_getClipboard(int selection);
/**
* Put data to the Clipboard
* @param set the selection instead, X11 only feature
*/
extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int flag);
extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection);
#ifdef __cplusplus
}

@ -356,12 +356,12 @@ public:
* @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
*
*/
virtual GHOST_TUns8* getClipboard(int flag) const = 0;
virtual GHOST_TUns8* getClipboard(bool selection) const = 0;
/**
* Put data to the Clipboard
*/
virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const = 0;
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
protected:
/**

@ -810,15 +810,15 @@ GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
return result;
}
GHOST_TUns8* GHOST_getClipboard(int flag)
GHOST_TUns8* GHOST_getClipboard(int selection)
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->getClipboard(flag);
return system->getClipboard(selection);
}
void GHOST_putClipboard(GHOST_TInt8 *buffer, int flag)
void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
system->putClipboard(buffer, flag);
system->putClipboard(buffer, selection);
}

@ -284,18 +284,18 @@ public:
/**
* Returns the selection buffer
* @param flag Only used on X11
* @return Returns the clipboard data
* @param selection Only used on X11
* @return Returns the clipboard data
*
*/
virtual GHOST_TUns8* getClipboard(int flag) const = 0;
virtual GHOST_TUns8* getClipboard(bool selection) const = 0;
/**
* Put data to the Clipboard
* @param buffer The buffer to copy to the clipboard
* @param flag The clipboard to copy too only used on X11
* @param buffer The buffer to copy to the clipboard
* @param selection The clipboard to copy too only used on X11
*/
virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const = 0;
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
protected:
/**

@ -1119,7 +1119,7 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
return err;
}
GHOST_TUns8* GHOST_SystemCarbon::getClipboard(int flag) const
GHOST_TUns8* GHOST_SystemCarbon::getClipboard(bool selection) const
{
PasteboardRef inPasteboard;
PasteboardItemID itemID;
@ -1158,9 +1158,9 @@ GHOST_TUns8* GHOST_SystemCarbon::getClipboard(int flag) const
}
}
void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, int flag) const
void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, bool selection) const
{
if(flag == 1) {return;} //If Flag is 1 means the selection and is used on X11
if(selection) {return;} // for copying the selection, used on X11
PasteboardRef inPasteboard;
CFDataRef textData = NULL;

@ -169,10 +169,10 @@ public:
/**
* Returns Clipboard data
* @param flag Indicate which buffer to return
* @return Returns the selected buffer
* @param selection Indicate which buffer to return
* @return Returns the selected buffer
*/
virtual GHOST_TUns8* getClipboard(int flag) const;
virtual GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard

@ -913,7 +913,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
return lResult;
}
GHOST_TUns8* GHOST_SystemWin32::getClipboard(int flag) const
GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const
{
char *buffer;
char *temp_buff;
@ -943,9 +943,10 @@ GHOST_TUns8* GHOST_SystemWin32::getClipboard(int flag) const
}
}
void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, int flag) const
void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
{
if(flag == 1) {return;} //If Flag is 1 means the selection and is used on X11
if(selection) {return;} // for copying the selection, used on X11
if (OpenClipboard(NULL)) {
HLOCAL clipbuffer;
char *data;

@ -170,17 +170,17 @@ public:
/**
* Returns unsinged char from CUT_BUFFER0
* @param flag Flag is not used on win32 on used on X11
* @return Returns the Clipboard
* @param selection Used by X11 only
* @return Returns the Clipboard
*/
virtual GHOST_TUns8* getClipboard(int flag) const;
virtual GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param flag Flag is not used on win32 on used on X11
* @return No return
* @param selection Used by X11 only
* @return No return
*/
virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const;
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
protected:
/**

@ -1006,7 +1006,7 @@ convertXKey(
GHOST_TUns8*
GHOST_SystemX11::
getClipboard(int flag
getClipboard(bool selection
) const {
//Flag
//0 = Regular clipboard 1 = selection
@ -1027,7 +1027,7 @@ getClipboard(int flag
compound_text = XInternAtom(m_display, "COMPOUND_TEXT", False);
//lets check the owner and if it is us then return the static buffer
if(flag == 0) {
if(!selection) {
Primary_atom = XInternAtom(m_display, "CLIPBOARD", False);
owner = XGetSelectionOwner(m_display, Primary_atom);
if (owner == m_window) {
@ -1077,14 +1077,14 @@ getClipboard(int flag
void
GHOST_SystemX11::
putClipboard(
GHOST_TInt8 *buffer, int flag) const
GHOST_TInt8 *buffer, bool selection) const
{
static Atom Primary_atom;
Window m_window, owner;
if(!buffer) {return;}
if(flag == 0) {
if(!selection) {
Primary_atom = XInternAtom(m_display, "CLIPBOARD", False);
if(txt_cut_buffer) { free((void*)txt_cut_buffer); }

@ -202,18 +202,17 @@ public:
/**
* Returns unsinged char from CUT_BUFFER0
* @param flag Flag indicates which buffer to return 0 for clipboard 1 for selection
* @return Returns the Clipboard indicated by Flag
* @param selection Get selection, X11 only feature
* @return Returns the Clipboard indicated by Flag
*/
GHOST_TUns8*
getClipboard(int flag) const;
GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param buffer The buffer to copy to the clipboard
* @param flag Flag indicates which buffer to set ownership of 0 for clipboard 1 for selection
* @param selection Set the selection into the clipboard, X11 only feature
*/
virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const;
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Atom used for ICCCM, WM-spec and Motif.

Binary file not shown.

@ -29,6 +29,8 @@
#ifndef BLF_API_H
#define BLF_API_H
struct rctf;
int BLF_init(void);
void BLF_exit(void);
@ -41,7 +43,7 @@ void BLF_position(float x, float y, float z);
void BLF_size(int size, int dpi);
void BLF_draw(char *str);
void BLF_boundbox(char *str, rctf *box);
void BLF_boundbox(char *str, struct rctf *box);
float BLF_width(char *str);
float BLF_height(char *str);
void BLF_rotation(float angle);

@ -12,11 +12,11 @@ incs += ' ' + env['BF_GETTEXT_INC']
defs = ''
if env['WITH_BF_INTERNATIONAL']:
defs += ' WITH_FREETYPE2'
defs = 'FTGL_STATIC_LIBRARY'
defs += 'FTGL_STATIC_LIBRARY'
if sys.platform == 'win32':
defs += ' _WIN32 USE_GETTEXT_DLL'
if env['WITH_BF_INTERNATIONAL']:
defs += ' WITH_FREETYPE2'
env.BlenderLib ( 'bf_blenfont', sources, Split(incs), Split(defs), libtype=['core'], priority=[210] )

@ -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);

@ -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 */

@ -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);

@ -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);

@ -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);
@ -348,9 +342,6 @@ Text *add_text(char *file, const char *relpath)
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);
fseek(fp, 0L, SEEK_SET);
@ -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;

@ -2551,7 +2551,7 @@ static void direct_link_text(FileData *fd, Text *text)
ln= ln->next;
}
text->flags = (text->flags|TXT_ISTMP) & ~TXT_ISEXT;
text->flags = (text->flags) & ~TXT_ISEXT;
text->id.us= 1;
}
@ -5643,6 +5643,11 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
break;
}
case SPACE_TEXT:
{
SpaceText *st= (SpaceText *)sl;
st->flags |= ST_FIND_WRAP;
}
//case SPACE_XXX: // FIXME... add other ones
// memcpy(&ar->v2d, &((SpaceXxx *)sl)->v2d, sizeof(View2D));

@ -44,7 +44,6 @@ enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD,
void FONT_OT_insert_text(struct wmOperatorType *ot);
void FONT_OT_line_break(struct wmOperatorType *ot);
void FONT_OT_insert_lorem(struct wmOperatorType *ot);
void FONT_OT_text_to_object(struct wmOperatorType *ot);
void FONT_OT_toggle_case(struct wmOperatorType *ot);
void FONT_OT_set_case(struct wmOperatorType *ot);

@ -99,7 +99,6 @@ void ED_operatortypes_curve(void)
WM_operatortype_append(FONT_OT_insert_text);
WM_operatortype_append(FONT_OT_line_break);
WM_operatortype_append(FONT_OT_insert_lorem);
WM_operatortype_append(FONT_OT_text_to_object);
WM_operatortype_append(FONT_OT_toggle_case);
WM_operatortype_append(FONT_OT_set_case);

@ -463,182 +463,96 @@ void FONT_OT_paste_buffer(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/******************* XXX text to object operator ********************/
/******************* text to object operator ********************/
static void txt_export_to_object(Scene *scene, Object *obedit, Text *text)
static void txt_add_object(bContext *C, TextLine *firstline, int totline, float offset[3])
{
ID *id;
Scene *scene= CTX_data_scene(C);
Curve *cu;
Object *obedit;
Base *base;
struct TextLine *tmp;
int nchars = 0;
// char sdir[FILE_MAXDIR];
// char sfile[FILE_MAXFILE];
int nchars = 0, a;
if(!text || !text->lines.first) return;
obedit= add_object(scene, OB_FONT);
base= scene->basact;
id = (ID *)text;
if(obedit && obedit->type==OB_FONT) return;
// XXX check_editmode(OB_FONT);
add_object(scene, OB_FONT);
ED_object_base_init_from_view(NULL, BASACT); // XXX
obedit= BASACT->object;
ED_object_base_init_from_view(C, base);
where_is_object(scene, obedit);
obedit->loc[0] += offset[0];
obedit->loc[1] += offset[1];
obedit->loc[2] += offset[2];
cu= obedit->data;
/*
// renames object, careful with long filenames.
if(text->name) {
//ID *find_id(char *type, char *name)
BLI_split_dirfile(text->name, sdir, sfile);
// rename_id((ID *)obedit, sfile);
rename_id((ID *)cu, sfile);
id->us++;
}
*/
cu->vfont= get_builtin_font();
cu->vfont->id.us++;
tmp= text->lines.first;
while(cu->len<MAXTEXT && tmp) {
for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++)
nchars += strlen(tmp->line) + 1;
tmp = tmp->next;
}
if(cu->str) MEM_freeN(cu->str);
if(cu->strinfo) MEM_freeN(cu->strinfo);
cu->str= MEM_mallocN(nchars+4, "str");
cu->str= MEM_callocN(nchars+4, "str");
cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
cu->totbox= cu->actbox= 1;
cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
cu->tb[0].w = cu->tb[0].h = 0.0;
tmp= text->lines.first;
strcpy(cu->str, tmp->line);
cu->len= strlen(tmp->line);
cu->pos= cu->len;
cu->str[0]= '\0';
cu->len= 0;
cu->pos= 0;
tmp= tmp->next;
while(cu->len<MAXTEXT && tmp) {
strcat(cu->str, "\n");
for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++) {
strcat(cu->str, tmp->line);
cu->len+= strlen(tmp->line) + 1;
cu->len+= strlen(tmp->line);
if(tmp->next) {
strcat(cu->str, "\n");
cu->len++;
}
cu->pos= cu->len;
tmp= tmp->next;
}
make_editText(obedit);
ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR); // XXX
WM_event_add_notifier(C, NC_OBJECT|NA_ADDED, obedit);
}
static void txt_export_to_objects(Scene *scene, Object *obedit, Text *text)
void ED_text_to_object(bContext *C, Text *text, int split_lines)
{
RegionView3D *rv3d= NULL; // XXX
ID *id;
Curve *cu;
struct TextLine *curline;
int nchars;
int linenum = 0;
float offset[3] = {0.0,0.0,0.0};
RegionView3D *rv3d= CTX_wm_region_view3d(C);
TextLine *line;
float offset[3];
int linenum= 0;
if(!text || !text->lines.first) return;
id = (ID *)text;
if(split_lines) {
for(line=text->lines.first; line; line=line->next) {
/* skip lines with no text, but still make space for them */
if(line->line[0] == '\0') {
linenum++;
continue;
}
if(obedit && obedit->type==OB_FONT) return;
// XXX check_editmode(OB_FONT);
/* do the translation */
offset[0] = 0;
offset[1] = -linenum;
offset[2] = 0;
if(rv3d)
Mat4Mul3Vecfl(rv3d->viewinv, offset);
txt_add_object(C, line, 1, offset);
curline = text->lines.first;
while(curline){
/*skip lines with no text, but still make space for them*/
if(curline->line[0] == '\0'){
linenum++;
curline = curline->next;
continue;
}
nchars = 0;
add_object(scene, OB_FONT);
ED_object_base_init_from_view(NULL, BASACT); // XXX
obedit= BASACT->object;
where_is_object(scene, obedit);
/* Do the translation */
offset[0] = 0;
offset[1] = -linenum;
offset[2] = 0;
Mat4Mul3Vecfl(rv3d->viewinv, offset);
obedit->loc[0] += offset[0];
obedit->loc[1] += offset[1];
obedit->loc[2] += offset[2];
/* End Translation */
cu= obedit->data;
cu->vfont= get_builtin_font();
cu->vfont->id.us++;
nchars = strlen(curline->line) + 1;
if(cu->str) MEM_freeN(cu->str);
if(cu->strinfo) MEM_freeN(cu->strinfo);
cu->str= MEM_mallocN(nchars+4, "str");
cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
cu->totbox= cu->actbox= 1;
cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
cu->tb[0].w = cu->tb[0].h = 0.0;
strcpy(cu->str, curline->line);
cu->len= strlen(curline->line);
cu->pos= cu->len;
make_editText(obedit);
ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR); // XXX
linenum++;
curline = curline->next;
}
}
else {
offset[0]= 0.0f;
offset[1]= 0.0f;
offset[2]= 0.0f;
static int text_to_object_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *obedit= CTX_data_edit_object(C);
Text *text= NULL; /// XXX retrieve this ..
if(RNA_boolean_get(op->ptr, "split_lines"))
txt_export_to_objects(scene, obedit, text);
else
txt_export_to_object(scene, obedit, text);
return OPERATOR_FINISHED;
}
void FONT_OT_text_to_object(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Text to Object";
ot->idname= "FONT_OT_text_to_object";
/* api callbacks */
ot->exec= text_to_object_exec;
ot->poll= ED_operator_editfont; // XXX not correct
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text.");
txt_add_object(C, text->lines.first, BLI_countlist(&text->lines), offset);
}
}
/********************** utilities ***************************/

File diff suppressed because it is too large Load Diff

@ -28,12 +28,13 @@
#ifndef ED_CURVE_H
#define ED_CURVE_H
struct wmWindowManager;
struct Scene;
struct Object;
struct bContext;
struct Base;
struct bContext;
struct Object;
struct Scene;
struct Text;
struct View3D;
struct wmWindowManager;
/* curve_ops.c */
void ED_operatortypes_curve(void);
@ -57,5 +58,7 @@ void make_editText (struct Object *obedit);
void load_editText (struct Object *obedit);
void free_editText (struct Object *obedit);
void ED_text_to_object(struct bContext *C, struct Text *text, int split_lines);
#endif /* ED_CURVE_H */

@ -49,5 +49,8 @@ extern char datatoc_Bfont[];
extern int datatoc_bfont_ttf_size;
extern char datatoc_bfont_ttf[];
extern int datatoc_bmonofont_ttf_size;
extern char datatoc_bmonofont_ttf[];
#endif /* ED_DATAFILES_H */

@ -0,0 +1,36 @@
/**
* $Id:
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef ED_TEXT_H
#define ED_TEXT_H
struct bContext;
void ED_text_undo_step(struct bContext *C, int step);
#endif /* ED_TEXT_H */

@ -415,7 +415,7 @@ typedef void (*uiIDPoinFunc)(struct bContext *C, struct ID *id, int event);
uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, char *str,
short x1, short y1, short x2, short y2, void *idpp, char *tip);
int uiDefIDPoinButs(uiBlock *block, struct Main *main, struct ID *parid, struct ID **id_p, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, int events);
int uiDefIDPoinButs(uiBlock *block, struct Main *main, struct ID *parid, struct ID *id, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, int events);
uiBut *uiDefPulldownBut(uiBlock *block, uiBlockCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip);
uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip);

@ -659,7 +659,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if(mode=='v') {
/* extract first line from clipboard in case of multi-line copies */
char *p = NULL; /* XXX 2.48 getClipboard(0); */
char *p = WM_clipboard_text_get(0);
if(p) {
int i = 0;
while (*p && *p!='\r' && *p!='\n' && i<UI_MAX_DRAW_STR) {
@ -667,6 +667,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
p++;
}
buf[i]= 0;
MEM_freeN(p);
}
}
@ -676,7 +677,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if(but->poin==NULL && but->rnapoin.data==NULL);
else if(mode=='c') {
sprintf(buf, "%f", ui_get_but_val(but));
/* XXX 2.48 putClipboard(buf, 0); */
WM_clipboard_text_set(buf, 0);
}
else {
if (sscanf(buf, " %lf ", &val) == 1) {
@ -696,7 +697,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
ui_get_but_vectorf(but, rgb);
sprintf(buf, "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
/* XXX 2.48 putClipboard(buf, 0); */
WM_clipboard_text_set(buf, 0);
}
else {
@ -716,7 +717,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
else if(mode=='c') {
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
BLI_strncpy(buf, data->str, UI_MAX_DRAW_STR);
/* XXX 2.48 putClipboard(data->str, 0); */
WM_clipboard_text_set(data->str, 0);
data->cancel= 1;
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
@ -1065,7 +1066,7 @@ static int ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData
static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste, int copy, int cut)
{
char buf[UI_MAX_DRAW_STR]={0};
char *str, *p;
char *str, *p, *pbuf;
int len, x, y, i, changed= 0;
str= data->str;
@ -1074,10 +1075,11 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
/* paste */
if (paste) {
/* extract the first line from the clipboard */
p = NULL; /* XXX 2.48 getClipboard(0); */
p = pbuf= WM_clipboard_text_get(0);
if(p && p[0]) {
while (*p && *p!='\r' && *p!='\n' && i<UI_MAX_DRAW_STR) {
i= 0;
while (*p && *p!='\r' && *p!='\n' && i<UI_MAX_DRAW_STR-1) {
buf[i++]=*p;
p++;
}
@ -1102,6 +1104,9 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
changed= 1;
}
if(pbuf)
MEM_freeN(pbuf);
}
/* cut & copy */
else if (copy || cut) {
@ -1112,7 +1117,8 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
else
buf[(x - but->selsta)] = str[x];
}
/* XXX 2.48 putClipboard(buf, 0); */
WM_clipboard_text_set(buf, 0);
/* for cut only, delete the selection afterwards */
if(cut)
@ -1279,9 +1285,9 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
if(event->ctrl || event->oskey) {
if(event->type == VKEY)
changed= ui_textedit_copypaste(but, data, 1, 0, 0);
else if(event->type == XKEY)
changed= ui_textedit_copypaste(but, data, 0, 1, 0);
else if(event->type == CKEY)
changed= ui_textedit_copypaste(but, data, 0, 1, 0);
else if(event->type == XKEY)
changed= ui_textedit_copypaste(but, data, 0, 0, 1);
retval= WM_UI_HANDLER_BREAK;

@ -405,7 +405,7 @@ int uiDefAutoButsRNA(uiBlock *block, PointerRNA *ptr)
typedef struct uiIDPoinParams {
uiIDPoinFunc func;
ID **id_p;
ID *id;
short id_code;
short browsenr;
} uiIDPoinParams;
@ -416,13 +416,17 @@ static void idpoin_cb(bContext *C, void *arg_params, void *arg_event)
ListBase *lb;
uiIDPoinParams *params= (uiIDPoinParams*)arg_params;
uiIDPoinFunc func= params->func;
ID **id_p= params->id_p;
ID *id= *id_p, *idtest;
ID *id= params->id, *idtest;
int nr, event= GET_INT_FROM_POINTER(arg_event);
bmain= CTX_data_main(C);
lb= wich_libbase(bmain, params->id_code);
if(event == UI_ID_BROWSE && params->browsenr == 32767)
event= UI_ID_ADD_NEW;
else if(event == UI_ID_BROWSE && params->browsenr == 32766)
event= UI_ID_OPEN;
switch(event) {
case UI_ID_RENAME:
if(id) test_idbutton(id->name+2);
@ -442,17 +446,18 @@ static void idpoin_cb(bContext *C, void *arg_params, void *arg_event)
for(idtest=lb->first, nr=1; idtest; idtest=idtest->next, nr++) {
if(nr==params->browsenr) {
if(*id_p == idtest)
if(id == idtest)
return;
*id_p= idtest;
id= idtest;
break;
}
}
break;
}
case UI_ID_DELETE:
*id_p= NULL;
id= NULL;
break;
case UI_ID_FAKE_USER:
if(id) {
@ -480,21 +485,20 @@ static void idpoin_cb(bContext *C, void *arg_params, void *arg_event)
}
if(func)
func(C, *id_p, event);
func(C, id, event);
}
int uiDefIDPoinButs(uiBlock *block, Main *bmain, ID *parid, ID **id_p, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, int events)
int uiDefIDPoinButs(uiBlock *block, Main *bmain, ID *parid, ID *id, int id_code, short *pin_p, int x, int y, uiIDPoinFunc func, int events)
{
ListBase *lb;
uiBut *but;
ID *id= *id_p;
uiIDPoinParams *params, *dup_params;
char *str=NULL, str1[10];
int len, oldcol, add_addbutton=0;
/* setup struct that we will pass on with the buttons */
params= MEM_callocN(sizeof(uiIDPoinParams), "uiIDPoinParams");
params->id_p= id_p;
params->id= id;
params->id_code= id_code;
params->func= func;

@ -1563,6 +1563,7 @@ static void saction_idpoin_handle(bContext *C, ID *id, int event)
switch (event) {
case UI_ID_BROWSE:
case UI_ID_DELETE:
saction->action= (bAction*)id;
/* we must set this action to be the one used by active object (if not pinned) */
if (saction->pin == 0)
obact->adt->action= saction->action;
@ -1691,7 +1692,7 @@ void action_header_buttons(const bContext *C, ARegion *ar)
//uiClearButLock();
/* NAME ETC (it is assumed that */
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&saction->action, ID_AC, &saction->pin, xco, yco,
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)saction->action, ID_AC, &saction->pin, xco, yco,
saction_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE|UI_ID_FAKE_USER|UI_ID_ALONE|UI_ID_PIN);
xco += 8;

@ -686,7 +686,7 @@ static void sima_idpoin_handle(bContext *C, ID *id, int event)
switch(event) {
case UI_ID_BROWSE:
case UI_ID_DELETE:
ED_space_image_set(C, sima, scene, obedit, sima->image);
ED_space_image_set(C, sima, scene, obedit, (Image*)id);
ED_undo_push(C, "Assign Image UV");
break;
case UI_ID_RENAME:
@ -768,7 +768,7 @@ void image_header_buttons(const bContext *C, ARegion *ar)
/* image select */
pinflag= (show_render)? 0: UI_ID_PIN;
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&sima->image, ID_IM, &sima->pin, xco, yco,
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)sima->image, ID_IM, &sima->pin, xco, yco,
sima_idpoin_handle, UI_ID_BROWSE|UI_ID_BROWSE_RENDER|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE|pinflag);
xco += 8;

@ -333,7 +333,6 @@ static void do_info_buttons(bContext *C, void *arg, int event)
static void screen_idpoin_handle(bContext *C, ID *id, int event)
{
switch(event) {
case UI_ID_BROWSE:
/* exception: can't set screens inside of area/region handers */
@ -360,7 +359,6 @@ static void screen_idpoin_handle(bContext *C, ID *id, int event)
static void scene_idpoin_handle(bContext *C, ID *id, int event)
{
switch(event) {
case UI_ID_BROWSE:
/* exception: can't set screens inside of area/region handers */
@ -391,7 +389,6 @@ void info_header_buttons(const bContext *C, ARegion *ar)
wmWindow *win= CTX_wm_window(C);
bScreen *screen= CTX_wm_screen(C);
ScrArea *sa= CTX_wm_area(C);
SpaceInfo *si= sa->spacedata.first;
uiBlock *block;
int xco, yco= 3;
@ -433,13 +430,11 @@ void info_header_buttons(const bContext *C, ARegion *ar)
uiBlockSetEmboss(block, UI_EMBOSS);
if(screen->full==NULL) {
si->screen= win->screen;
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->screen, ID_SCR, NULL, xco, yco,
if(screen->full==0) {
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)win->screen, ID_SCR, NULL, xco, yco,
screen_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
xco += 8;
si->scene= screen->scene;
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->scene, ID_SCE, NULL, xco, yco,
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)screen->scene, ID_SCE, NULL, xco, yco,
scene_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
xco += 8;
}

@ -43,7 +43,9 @@ CPPFLAGS += -I../../windowmanager
CPPFLAGS += -I../../blenloader
CPPFLAGS += -I../../blenkernel
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../blenfont
CPPFLAGS += -I../../makesdna
CPPFLAGS += -I../../makesrna
CPPFLAGS += -I../../imbuf
CPPFLAGS += -I../../python
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include

@ -5,5 +5,9 @@ sources = env.Glob('*.c')
incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
incs += ' #/intern/bmfont ../../python ../../makesrna ../../blenfont'
if not env['WITH_BF_PYTHON']:
defs.append('DISABLE_PYTHON')
env.BlenderLib ( 'bf_editors_space_text', sources, Split(incs), [], libtype=['core'], priority=[95] )

@ -34,6 +34,7 @@
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "MEM_guardedalloc.h"
@ -57,6 +58,8 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "RNA_access.h"
#include "ED_markers.h"
#include "text_intern.h" // own include
@ -71,7 +74,6 @@ static SpaceLink *text_new(const bContext *C)
stext= MEM_callocN(sizeof(SpaceText), "inittext");
stext->spacetype= SPACE_TEXT;
/* header */
ar= MEM_callocN(sizeof(ARegion), "header for text");
@ -85,9 +87,6 @@ static SpaceLink *text_new(const bContext *C)
BLI_addtail(&stext->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
/* channel list region XXX */
return (SpaceLink *)stext;
}
@ -115,7 +114,185 @@ static SpaceLink *text_duplicate(SpaceLink *sl)
return (SpaceLink *)stextn;
}
static void text_listener(ScrArea *sa, wmNotifier *wmn)
{
SpaceText *st= sa->spacedata.first;
/* 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) {
ARegion *ar;
for(ar=sa->regionbase.first; ar; ar= ar->next)
if(ar->regiontype==RGN_TYPE_WINDOW)
text_update_cursor_moved(st, ar);
}
}
else if(wmn->data == ND_DISPLAY)
ED_area_tag_redraw(sa);
break;
}
}
static void text_operatortypes(void)
{
WM_operatortype_append(TEXT_OT_new);
WM_operatortype_append(TEXT_OT_open);
WM_operatortype_append(TEXT_OT_reload);
WM_operatortype_append(TEXT_OT_save);
WM_operatortype_append(TEXT_OT_save_as);
WM_operatortype_append(TEXT_OT_make_internal);
WM_operatortype_append(TEXT_OT_run_script);
WM_operatortype_append(TEXT_OT_refresh_pyconstraints);
WM_operatortype_append(TEXT_OT_paste);
WM_operatortype_append(TEXT_OT_copy);
WM_operatortype_append(TEXT_OT_cut);
WM_operatortype_append(TEXT_OT_convert_whitespace);
WM_operatortype_append(TEXT_OT_uncomment);
WM_operatortype_append(TEXT_OT_comment);
WM_operatortype_append(TEXT_OT_unindent);
WM_operatortype_append(TEXT_OT_indent);
WM_operatortype_append(TEXT_OT_clear_all_markers);
WM_operatortype_append(TEXT_OT_next_marker);
WM_operatortype_append(TEXT_OT_previous_marker);
WM_operatortype_append(TEXT_OT_select_line);
WM_operatortype_append(TEXT_OT_select_all);
WM_operatortype_append(TEXT_OT_jump);
WM_operatortype_append(TEXT_OT_move);
WM_operatortype_append(TEXT_OT_move_select);
WM_operatortype_append(TEXT_OT_delete);
WM_operatortype_append(TEXT_OT_toggle_overwrite);
WM_operatortype_append(TEXT_OT_set_cursor);
WM_operatortype_append(TEXT_OT_scroll);
WM_operatortype_append(TEXT_OT_scroll_bar);
WM_operatortype_append(TEXT_OT_line_number);
WM_operatortype_append(TEXT_OT_line_break);
WM_operatortype_append(TEXT_OT_insert);
WM_operatortype_append(TEXT_OT_find_and_replace);
WM_operatortype_append(TEXT_OT_find);
WM_operatortype_append(TEXT_OT_find_set_selected);
WM_operatortype_append(TEXT_OT_replace);
WM_operatortype_append(TEXT_OT_replace_set_selected);
WM_operatortype_append(TEXT_OT_mark_all);
WM_operatortype_append(TEXT_OT_to_3d_object);
WM_operatortype_append(TEXT_OT_resolve_conflict);
}
static void text_keymap(struct wmWindowManager *wm)
{
ListBase *keymap= WM_keymap_listbase(wm, "Text", SPACE_TEXT, 0);
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);
WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_ALT, 0);
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_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 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", JKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find", FKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find_and_replace", FKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find_and_replace", FKEY, 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_replace", HKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0);
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_OSKEY, 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_OSKEY, 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);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE);
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_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);
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", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
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_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", 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_toggle_overwrite", 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_bar", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_set_cursor", LEFTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_set_cursor", 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_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
}
static int text_context(const bContext *C, bContextDataMember member, bContextDataResult *result)
{
SpaceText *st= CTX_wm_space_text(C);
if(member == CTX_DATA_EDIT_TEXT) {
CTX_data_pointer_set(result, st->text);
return 1;
}
return 0;
}
/********************* main region ********************/
/* add handlers, stuff you only do once or on area/region changes */
static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
@ -132,8 +309,8 @@ static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
static void text_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
// SpaceText *stext= (SpaceText*)CTX_wm_space_data(C);
View2D *v2d= &ar->v2d;
SpaceText *st= CTX_wm_space_text(C);
//View2D *v2d= &ar->v2d;
float col[3];
/* clear and setup matrix */
@ -141,31 +318,23 @@ static void text_main_area_draw(const bContext *C, ARegion *ar)
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
UI_view2d_view_ortho(C, v2d);
// UI_view2d_view_ortho(C, v2d);
/* data... */
draw_text_main(st, ar);
/* reset view matrix */
UI_view2d_view_restore(C);
// UI_view2d_view_restore(C);
/* scrollers? */
}
static void text_operatortypes(void)
{
}
static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
{
WM_cursor_set(win, BC_TEXTEDITCURSOR);
}
static void text_keymap(struct wmWindowManager *wm)
{
}
/****************** header region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
@ -195,11 +364,38 @@ static void text_header_area_draw(const bContext *C, ARegion *ar)
UI_view2d_view_restore(C);
}
static void text_main_area_listener(ARegion *ar, wmNotifier *wmn)
/****************** find & replace region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void text_find_area_init(wmWindowManager *wm, ARegion *ar)
{
/* context changes */
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
}
static void text_find_area_draw(const bContext *C, ARegion *ar)
{
float col[3];
/* clear */
if(ED_screen_area_active(C))
UI_GetThemeColor3fv(TH_HEADER, col);
else
UI_GetThemeColor3fv(TH_HEADERDESEL, col);
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
/* set view2d view matrix for scrolling (without scrollers) */
UI_view2d_view_ortho(C, &ar->v2d);
text_find_buttons(C, ar);
/* restore view matrix? */
UI_view2d_view_restore(C);
}
/********************* registration ********************/
/* only called once, from space/spacetypes.c */
void ED_spacetype_text(void)
{
@ -214,14 +410,14 @@ void ED_spacetype_text(void)
st->duplicate= text_duplicate;
st->operatortypes= text_operatortypes;
st->keymap= text_keymap;
st->listener= text_listener;
st->context= text_context;
/* regions: main window */
art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
art->regionid = RGN_TYPE_WINDOW;
art->init= text_main_area_init;
art->draw= text_main_area_draw;
art->listener= text_main_area_listener;
art->keymapflag= ED_KEYMAP_VIEW2D;
art->cursor= text_cursor;
BLI_addhead(&st->regiontypes, art);
@ -237,6 +433,16 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: find & replace */
art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
art->regionid = RGN_TYPE_UI;
art->minsizey= HEADERY;
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
art->init= text_find_area_init;
art->draw= text_find_area_draw;
BLI_addhead(&st->regiontypes, art);
BKE_spacetype_register(st);
}

File diff suppressed because it is too large Load Diff

@ -26,12 +26,26 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.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
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_text_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
@ -39,7 +53,11 @@
#include "BLI_blenlib.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_text.h"
#include "ED_screen.h"
#include "ED_types.h"
@ -53,81 +71,591 @@
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_text.h"
#include "UI_view2d.h"
#include "RNA_access.h"
#ifndef DISABLE_PYTHON
#include "BPY_extern.h"
// XXX #include "BPY_menus.h"
#endif
#include "text_intern.h"
#define HEADER_PATH_MAX 260
/* ************************ header area region *********************** */
static void do_viewmenu(bContext *C, void *arg, int event)
#ifndef DISABLE_PYTHON
static void do_text_template_scriptsmenu(bContext *C, void *arg, int event)
{
// XXX BPY_menu_do_python(PYMENU_SCRIPTTEMPLATE, event);
}
static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
uiBlock *text_template_scriptsmenu(bContext *C, void *args_unused)
{
ScrArea *curarea= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
uiBlock *block;
short yco= 0, menuwidth=120;
// XXX BPyMenu *pym;
// int i= 0;
// short yco = 20, menuwidth = 120;
block= uiBeginBlock(C, ar, "dummy_viewmenu", UI_EMBOSSP, UI_HELV);
uiBlockSetButmFunc(block, do_viewmenu, NULL);
block= uiBeginBlock(C, ar, "text_template_scriptsmenu", UI_EMBOSSP, UI_HELV);
uiBlockSetButmFunc(block, do_text_template_scriptsmenu, NULL);
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20,
menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
/* note that we acount for the N previous entries with i+20: */
/* XXX for (pym = BPyMenuTable[PYMENU_SCRIPTTEMPLATE]; pym; pym = pym->next, i++) {
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
}
else {
uiBlockSetDirection(block, UI_TOP);
uiBlockFlipOrder(block);
}
uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19,
NULL, 0.0, 0.0, 1, i,
pym->tooltip?pym->tooltip:pym->filename);
}*/
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 60);
uiTextBoundsBlock(block, 50);
uiEndBlock(C, block);
uiDrawBlock(C, block);
return block;
}
static void do_text_buttons(bContext *C, void *arg, int event)
static void do_text_plugin_scriptsmenu(bContext *C, void *arg, int event)
{
// XXX BPY_menu_do_python(PYMENU_TEXTPLUGIN, event);
}
uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused)
{
ARegion *ar= CTX_wm_region(C);
uiBlock *block;
// XXX BPyMenu *pym;
// int i= 0;
// short yco = 20, menuwidth = 120;
block= uiBeginBlock(C, ar, "text_plugin_scriptsmenu", UI_EMBOSSP, UI_HELV);
uiBlockSetButmFunc(block, do_text_plugin_scriptsmenu, NULL);
/* note that we acount for the N previous entries with i+20: */
/* XXX for (pym = BPyMenuTable[PYMENU_TEXTPLUGIN]; pym; pym = pym->next, i++) {
uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19,
NULL, 0.0, 0.0, 1, i,
pym->tooltip?pym->tooltip:pym->filename);
}*/
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 60);
uiEndBlock(C, block);
uiDrawBlock(C, block);
return block;
}
#endif
static void text_editmenu_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemEnumO(head, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP);
uiMenuItemEnumO(head, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM);
}
static void text_editmenu_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemO(head, 0, "TEXT_OT_select_all");
uiMenuItemO(head, 0, "TEXT_OT_select_line");
}
static void text_editmenu_markermenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemO(head, 0, "TEXT_OT_clear_all_markers");
uiMenuItemO(head, 0, "TEXT_OT_next_marker");
uiMenuItemO(head, 0, "TEXT_OT_previous_marker");
}
static void text_formatmenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemO(head, 0, "TEXT_OT_indent");
uiMenuItemO(head, 0, "TEXT_OT_unindent");
uiMenuSeparator(head);
uiMenuItemO(head, 0, "TEXT_OT_comment");
uiMenuItemO(head, 0, "TEXT_OT_uncomment");
uiMenuSeparator(head);
uiMenuLevelEnumO(head, "TEXT_OT_convert_whitespace", "type");
}
static void text_editmenu_to3dmenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemBooleanO(head, "One Object", 0, "TEXT_OT_to_3d_object", "split_lines", 0);
uiMenuItemBooleanO(head, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1);
}
static void text_editmenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
uiMenuItemO(head, 0, "ED_OT_undo");
uiMenuItemO(head, 0, "ED_OT_redo");
uiMenuSeparator(head);
uiMenuItemO(head, 0, "TEXT_OT_cut");
uiMenuItemO(head, 0, "TEXT_OT_copy");
uiMenuItemO(head, 0, "TEXT_OT_paste");
uiMenuSeparator(head);
uiMenuLevel(head, "View", text_editmenu_viewmenu);
uiMenuLevel(head, "Select", text_editmenu_selectmenu);
uiMenuLevel(head, "Markers", text_editmenu_markermenu);
uiMenuSeparator(head);
uiMenuItemO(head, 0, "TEXT_OT_jump");
uiMenuItemO(head, 0, "TEXT_OT_find_and_replace");
uiMenuSeparator(head);
uiMenuLevel(head, "Text to 3D Object", text_editmenu_to3dmenu);
}
static void text_filemenu(bContext *C, uiMenuItem *head, void *arg_unused)
{
SpaceText *st= (SpaceText*)CTX_wm_space_data(C);
Text *text= st->text;
uiMenuItemO(head, 0, "TEXT_OT_new");
uiMenuItemO(head, 0, "TEXT_OT_open");
if(text) {
uiMenuItemO(head, 0, "TEXT_OT_reload");
uiMenuSeparator(head);
uiMenuItemO(head, 0, "TEXT_OT_save");
uiMenuItemO(head, 0, "TEXT_OT_save_as");
if(text->name)
uiMenuItemO(head, 0, "TEXT_OT_make_internal");
uiMenuSeparator(head);
uiMenuItemO(head, 0, "TEXT_OT_run_script");
#ifndef DISABLE_PYTHON
if(BPY_is_pyconstraint(text))
uiMenuItemO(head, 0, "TEXT_OT_refresh_pyconstraints");
#endif
}
#ifndef DISABLE_PYTHON
// XXX uiMenuSeparator(head);
// XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
// XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
#endif
}
/*********************** datablock browse *************************/
static void text_unlink(Main *bmain, Text *text)
{
bScreen *scr;
ScrArea *area;
SpaceLink *sl;
/* XXX this ifdef is in fact dangerous, if python is
* disabled it will leave invalid pointers in files! */
#ifndef DISABLE_PYTHON
// XXX BPY_clear_bad_scriptlinks(text);
// XXX BPY_free_pyconstraint_links(text);
// XXX free_text_controllers(text);
/* check if this text was used as script link:
* this check function unsets the pointers and returns how many
* script links used this Text */
if(0) // XXX BPY_text_check_all_scriptlinks (text))
; // XXX notifier: allqueue(REDRAWBUTSSCRIPT, 0);
/* equivalently for pynodes: */
if(0) // XXX nodeDynamicUnlinkText ((ID*)text))
; // XXX notifier: allqueue(REDRAWNODE, 0);
#endif
for(scr= bmain->screen.first; scr; scr= scr->id.next) {
for(area= scr->areabase.first; area; area= area->next) {
for(sl= area->spacedata.first; sl; sl= sl->next) {
if(sl->spacetype==SPACE_TEXT) {
SpaceText *st= (SpaceText*) sl;
if(st->text==text) {
st->text= NULL;
st->top= 0;
if(st==area->spacedata.first)
ED_area_tag_redraw(area);
}
}
}
}
}
free_libblock(&bmain->text, text);
}
static void text_idpoin_handle(bContext *C, ID *id, int event)
{
SpaceText *st= (SpaceText*)CTX_wm_space_data(C);
Text *text;
switch(event) {
case UI_ID_BROWSE:
st->text= (Text*)id;
st->top= 0;
text_update_edited(st->text);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
ED_undo_push(C, "Browse Text");
break;
case UI_ID_DELETE:
text= st->text;
/* make the previous text active, if its not there make the next text active */
if(text->id.prev) {
st->text = text->id.prev;
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
}
else if(text->id.next) {
st->text = text->id.next;
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
}
text_unlink(CTX_data_main(C), text);
WM_event_add_notifier(C, NC_TEXT|NA_REMOVED, text);
ED_undo_push(C, "Delete Text");
break;
case UI_ID_RENAME:
break;
case UI_ID_ADD_NEW:
WM_operator_name_call(C, "TEXT_OT_new", WM_OP_INVOKE_REGION_WIN, NULL);
break;
case UI_ID_OPEN:
WM_operator_name_call(C, "TEXT_OT_open", WM_OP_INVOKE_REGION_WIN, NULL);
break;
}
}
/********************** header buttons ***********************/
void text_header_buttons(const bContext *C, ARegion *ar)
{
bScreen *sc= CTX_wm_screen(C);
SpaceText *st= (SpaceText*)CTX_wm_space_data(C);
PointerRNA spaceptr;
Text *text= st->text;
ScrArea *sa= CTX_wm_area(C);
uiBlock *block;
int xco, yco= 3;
int xco, yco= 3, xmax, oldcol;
RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr);
block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
uiBlockSetHandleFunc(block, do_text_buttons, NULL);
xco= ED_area_header_standardbuttons(C, block, yco);
if((sa->flag & HEADER_NO_PULLDOWN)==0) {
int xmax;
/* pull down menus */
uiBlockSetEmboss(block, UI_EMBOSSP);
xmax= GetButStringLength("View");
uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C),
"View", xco, yco-2, xmax-3, 24, "");
xco+=XIC+xmax;
xmax= GetButStringLength("Text");
uiDefMenuBut(block, text_filemenu, NULL, "Text", xco, yco-2, xmax-3, 24, "");
xco+=xmax;
if(text) {
xmax= GetButStringLength("Edit");
uiDefMenuBut(block, text_editmenu, NULL, "Edit", xco, yco-2, xmax-3, 24, "");
xco+=xmax;
xmax= GetButStringLength("Format");
uiDefMenuBut(block, text_formatmenu, NULL, "Format", xco, yco-2, xmax-3, 24, "");
xco+=xmax;
}
}
uiBlockSetEmboss(block, UI_EMBOSS);
/* always as last */
UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
uiBlockBeginAlign(block);
uiDefIconButR(block, ICONTOG, 0, ICON_LINENUMBERS_OFF, xco, yco,XIC,YIC, &spaceptr, "line_numbers", 0, 0, 0, 0, 0, NULL);
uiDefIconButR(block, ICONTOG, 0, ICON_WORDWRAP_OFF, xco+=XIC, yco,XIC,YIC, &spaceptr, "word_wrap", 0, 0, 0, 0, 0, NULL);
uiDefIconButR(block, ICONTOG, 0, ICON_SYNTAX_OFF, xco+=XIC, yco,XIC,YIC, &spaceptr, "syntax_highlight", 0, 0, 0, 0, 0, NULL);
// uiDefIconButR(block, ICONTOG, 0, ICON_SCRIPTPLUGINS, xco+=XIC, yco,XIC,YIC, &spaceptr, "do_python_plugins", 0, 0, 0, 0, 0, "Enables Python text plugins");
uiBlockEndAlign(block);
/* warning button if text is out of date */
if(text && text_file_modified(text)) {
xco+= XIC;
oldcol= uiBlockGetCol(block);
uiBlockSetCol(block, TH_REDALERT);
uiDefIconButO(block, BUT, "TEXT_OT_resolve_conflict", WM_OP_INVOKE_DEFAULT, ICON_HELP, xco+=XIC,yco,XIC,YIC, "External text is out of sync, click for options to resolve the conflict");
uiBlockSetCol(block, oldcol);
}
/* browse text datablock */
xco+= 2*XIC;
xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)st->text, ID_TXT, NULL, xco, yco,
text_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE);
xco+=XIC;
/*
if(st->text) {
if(st->text->flags & TXT_ISDIRTY && (st->text->flags & TXT_ISEXT || !(st->text->flags & TXT_ISMEM)))
uiDefIconBut(block, BUT,0, ICON_ERROR, xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "The text has been changed");
if(st->text->flags & TXT_ISEXT)
uiDefBut(block, BUT,B_TEXTSTORE, ICON(), xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Stores text in project file");
else
uiDefBut(block, BUT,B_TEXTSTORE, ICON(), xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Disables storing of text in project file");
xco+=10;
}
*/
/* display settings */
if(st->font_id>1) st->font_id= 0;
uiDefButR(block, MENU, 0, NULL, xco,yco,100,YIC, &spaceptr, "font_size", 0, 0, 0, 0, 0, NULL);
xco+=105;
uiDefButR(block, NUM, 0, "Tab:", xco,yco,XIC+50,YIC, &spaceptr, "tab_width", 0, 0, 0, 0, 0, NULL);
xco+= XIC+50;
/* file info */
if(text) {
char fname[HEADER_PATH_MAX], headtxt[HEADER_PATH_MAX+17];
int len;
if(text->name) {
len = strlen(text->name);
if(len > HEADER_PATH_MAX-1)
len = HEADER_PATH_MAX-1;
strncpy(fname, text->name, len);
fname[len]='\0';
if(text->flags & TXT_ISDIRTY)
sprintf(headtxt, "File: *%s (unsaved)", fname);
else
sprintf(headtxt, "File: %s", fname);
}
else
sprintf(headtxt, text->id.lib? "Text: External": "Text: Internal");
UI_ThemeColor(TH_MENU_TEXT);
UI_RasterPos(xco+=XIC, yco+6);
UI_DrawString(G.font, headtxt, 0);
xco += UI_GetStringWidth(G.font, headtxt, 0);
}
uiEndBlock(C, block);
uiDrawBlock(C, block);
/* always as last */
UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
}
/************************* find & replace ***************************/
void text_find_buttons(const bContext *C, ARegion *ar)
{
bScreen *sc= CTX_wm_screen(C);
SpaceText *st= CTX_wm_space_text(C);
PointerRNA spaceptr;
uiBlock *block;
int xco= 5, yco= 3;
RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr);
block= uiBeginBlock(C, ar, "find buttons", UI_EMBOSS, UI_HELV);
/* find */
uiBlockBeginAlign(block);
uiDefButR(block, TEX, 0, "Find: ", xco, yco,220,20, &spaceptr, "find_text", 0, 0, 0, 0, 0, NULL);
xco += 220;
uiDefIconButO(block, BUT, "TEXT_OT_find_set_selected", WM_OP_INVOKE_DEFAULT, ICON_TEXT, xco,yco,20,20, "Copy from selection");
xco += 20+XIC;
uiBlockEndAlign(block);
/* replace */
uiBlockBeginAlign(block);
uiDefButR(block, TEX, 0, "Replace: ", xco, yco,220,20, &spaceptr, "replace_text", 0, 0, 0, 0, 0, NULL);
xco += 220;
uiDefIconButO(block, BUT, "TEXT_OT_replace_set_selected", WM_OP_INVOKE_DEFAULT, ICON_TEXT, xco,yco,20,20, "Copy from selection");
xco += 20+XIC;
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButR(block, TOG, 0, "Wrap", xco, yco,60,20, &spaceptr, "find_wrap", 0, 0, 0, 0, 0, NULL);
xco += 60;
uiDefButR(block, TOG, 0, "All", xco, yco,60,20, &spaceptr, "find_all", 0, 0, 0, 0, 0, NULL);
xco += 50+XIC;
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButO(block, BUT, "TEXT_OT_find", WM_OP_INVOKE_REGION_WIN, "Find", xco,yco,50,20, "Find next.");
xco += 50;
uiDefButO(block, BUT, "TEXT_OT_replace", WM_OP_INVOKE_REGION_WIN, "Replace", xco,yco,70,20, "Replace then find next.");
xco += 70;
uiDefButO(block, BUT, "TEXT_OT_mark_all", WM_OP_INVOKE_REGION_WIN, "Mark All", xco,yco,80,20, "Mark each occurrence to edit all from one");
xco += 80;
uiBlockEndAlign(block);
uiEndBlock(C, block);
uiDrawBlock(C, block);
/* always as last */
UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
}
ARegion *text_has_find_region(ScrArea *sa)
{
ARegion *ar, *arnew;
for(ar= sa->regionbase.first; ar; ar= ar->next)
if(ar->regiontype==RGN_TYPE_UI)
return ar;
/* add subdiv level; after header */
for(ar= sa->regionbase.first; ar; ar= ar->next)
if(ar->regiontype==RGN_TYPE_HEADER)
break;
/* is error! */
if(ar==NULL) return NULL;
arnew= MEM_callocN(sizeof(ARegion), "find and replace region");
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
arnew->regiontype= RGN_TYPE_UI;
arnew->alignment= RGN_ALIGN_BOTTOM;
arnew->flag = RGN_FLAG_HIDDEN;
return arnew;
}
static int find_and_replace_poll(bContext *C)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
return (st && text);
}
static int find_and_replace_exec(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= text_has_find_region(sa);
if(ar) {
ar->flag ^= RGN_FLAG_HIDDEN;
ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
ED_area_tag_redraw(sa);
}
return OPERATOR_FINISHED;
}
void TEXT_OT_find_and_replace(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Find and Replace";
ot->idname= "TEXT_OT_find_and_replace";
/* api callbacks */
ot->exec= find_and_replace_exec;
ot->poll= find_and_replace_poll;
}
/******************** XXX popup menus *******************/
#if 0
{
// RMB
uiMenuItem *head;
if(text) {
head= uiPupMenuBegin("Text", 0);
if(txt_has_sel(text)) {
uiMenuItemO(head, 0, "TEXT_OT_cut");
uiMenuItemO(head, 0, "TEXT_OT_copy");
}
uiMenuItemO(head, 0, "TEXT_OT_paste");
uiMenuItemO(head, 0, "TEXT_OT_new");
uiMenuItemO(head, 0, "TEXT_OT_open");
uiMenuItemO(head, 0, "TEXT_OT_save");
uiMenuItemO(head, 0, "TEXT_OT_save_as");
uiMenuItemO(head, 0, "TEXT_OT_run_script");
uiPupMenuEnd(C, head);
}
else {
head= uiPupMenuBegin("File", 0);
uiMenuItemO(head, 0, "TEXT_OT_new");
uiMenuItemO(head, 0, "TEXT_OT_open");
uiPupMenuEnd(C, head);
}
}
{
// Alt+Shift+E
uiMenuItem *head;
head= uiPupMenuBegin("Edit", 0);
uiMenuItemO(head, 0, "TEXT_OT_cut");
uiMenuItemO(head, 0, "TEXT_OT_copy");
uiMenuItemO(head, 0, "TEXT_OT_paste");
uiPupMenuEnd(C, head);
}
{
// Alt+Shift+F
uiMenuItem *head;
if(text) {
head= uiPupMenuBegin("Text", 0);
uiMenuItemO(head, 0, "TEXT_OT_new");
uiMenuItemO(head, 0, "TEXT_OT_open");
uiMenuItemO(head, 0, "TEXT_OT_save");
uiMenuItemO(head, 0, "TEXT_OT_save_as");
uiMenuItemO(head, 0, "TEXT_OT_run_script");
uiPupMenuEnd(C, head);
}
else {
head= uiPupMenuBegin("File", 0);
uiMenuItemO(head, 0, "TEXT_OT_new");
uiMenuItemO(head, 0, "TEXT_OT_open");
uiPupMenuEnd(C, head);
}
}
{
// Alt+Shift+V
uiMenuItem *head;
head= uiPupMenuBegin("Text", 0);
uiMenuItemEnumO(head, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP);
uiMenuItemEnumO(head, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM);
uiMenuItemEnumO(head, "Page Up", 0, "TEXT_OT_move", "type", PREV_PAGE);
uiMenuItemEnumO(head, "Page Down", 0, "TEXT_OT_move", "type", NEXT_PAGE);
uiPupMenuEnd(C, head);
}
#endif

@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
@ -30,10 +30,128 @@
/* internal exports only */
struct ARegion;
struct bContext;
struct BMF_Font;
struct ReportList;
struct ScrArea;
struct SpaceText;
struct Text;
struct TextLine;
struct wmOperatorType;
struct wmWindowManager;
/* text_header.c */
void text_header_buttons(const bContext *C, ARegion *ar);
void text_header_buttons(const struct bContext *C, struct ARegion *ar);
void text_find_buttons(const struct bContext *C, struct ARegion *ar);
/* text_draw.c */
void draw_text_main(struct SpaceText *st, struct ARegion *ar);
int text_check_bracket(char ch);
int text_check_delim(char ch);
int text_check_digit(char ch);
int text_check_identifier(char ch);
int text_check_whitespace(char ch);
int text_font_width_character(struct SpaceText *st);
int text_font_width(struct SpaceText *st, char *str);
void text_update_line_edited(struct Text *text, struct TextLine *line);
void text_update_edited(struct Text *text);
void text_update_cursor_moved(struct SpaceText *st, struct ARegion *ar);
#define TEXTXLOC 38
#define SUGG_LIST_SIZE 7
#define SUGG_LIST_WIDTH 20
#define DOC_WIDTH 40
#define DOC_HEIGHT 10
#define TOOL_SUGG_LIST 0x01
#define TOOL_DOCUMENT 0x02
#define TMARK_GRP_CUSTOM 0x00010000 /* Lower 2 bytes used for Python groups */
#define TMARK_GRP_FINDALL 0x00020000
typedef struct FlattenString {
char fixedbuf[256];
int fixedaccum[256];
char *buf;
int *accum;
int pos, len;
} FlattenString;
int flatten_string(struct SpaceText *st, FlattenString *fs, char *in);
void flatten_string_free(FlattenString *fs);
void unlink_text(struct Text *text);
int wrap_width(struct SpaceText *st, struct ARegion *ar);
void wrap_offset(struct SpaceText *st, struct ARegion *ar, struct TextLine *linein, int cursin, int *offl, int *offc);
int text_file_modified(struct Text *text);
int text_do_suggest_select(struct SpaceText *st, struct ARegion *ar);
void text_pop_suggest_list();
/* text_ops.c */
enum { LINE_BEGIN, LINE_END, FILE_TOP, FILE_BOTTOM, PREV_CHAR, NEXT_CHAR,
PREV_WORD, NEXT_WORD, PREV_LINE, NEXT_LINE, PREV_PAGE, NEXT_PAGE };
enum { DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_NEXT_WORD, DEL_PREV_WORD };
void TEXT_OT_new(struct wmOperatorType *ot);
void TEXT_OT_open(struct wmOperatorType *ot);
void TEXT_OT_reload(struct wmOperatorType *ot);
void TEXT_OT_save(struct wmOperatorType *ot);
void TEXT_OT_save_as(struct wmOperatorType *ot);
void TEXT_OT_make_internal(struct wmOperatorType *ot);
void TEXT_OT_run_script(struct wmOperatorType *ot);
void TEXT_OT_refresh_pyconstraints(struct wmOperatorType *ot);
void TEXT_OT_paste(struct wmOperatorType *ot);
void TEXT_OT_copy(struct wmOperatorType *ot);
void TEXT_OT_cut(struct wmOperatorType *ot);
void TEXT_OT_convert_whitespace(struct wmOperatorType *ot);
void TEXT_OT_uncomment(struct wmOperatorType *ot);
void TEXT_OT_comment(struct wmOperatorType *ot);
void TEXT_OT_unindent(struct wmOperatorType *ot);
void TEXT_OT_indent(struct wmOperatorType *ot);
void TEXT_OT_line_break(struct wmOperatorType *ot);
void TEXT_OT_insert(struct wmOperatorType *ot);
void TEXT_OT_clear_all_markers(struct wmOperatorType *ot);
void TEXT_OT_next_marker(struct wmOperatorType *ot);
void TEXT_OT_previous_marker(struct wmOperatorType *ot);
void TEXT_OT_select_line(struct wmOperatorType *ot);
void TEXT_OT_select_all(struct wmOperatorType *ot);
void TEXT_OT_jump(struct wmOperatorType *ot);
void TEXT_OT_move(struct wmOperatorType *ot);
void TEXT_OT_move_select(struct wmOperatorType *ot);
void TEXT_OT_delete(struct wmOperatorType *ot);
void TEXT_OT_toggle_overwrite(struct wmOperatorType *ot);
void TEXT_OT_scroll(struct wmOperatorType *ot);
void TEXT_OT_scroll_bar(struct wmOperatorType *ot);
void TEXT_OT_set_cursor(struct wmOperatorType *ot);
void TEXT_OT_line_number(struct wmOperatorType *ot);
void TEXT_OT_find_and_replace(struct wmOperatorType *ot);
void TEXT_OT_find(struct wmOperatorType *ot);
void TEXT_OT_find_set_selected(struct wmOperatorType *ot);
void TEXT_OT_replace(struct wmOperatorType *ot);
void TEXT_OT_replace_set_selected(struct wmOperatorType *ot);
void TEXT_OT_mark_all(struct wmOperatorType *ot);
void TEXT_OT_to_3d_object(struct wmOperatorType *ot);
void TEXT_OT_resolve_conflict(struct wmOperatorType *ot);
#endif /* ED_TEXT_INTERN_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,541 @@
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_text_types.h"
#include "BKE_suggestions.h"
#include "BKE_text.h"
#include "BLI_blenlib.h"
#include "WM_api.h"
#include "WM_types.h"
#include "text_intern.h"
int text_do_suggest_select(SpaceText *st, ARegion *ar)
{
SuggItem *item, *first, *last, *sel;
TextLine *tmp;
int l, x, y, w, h, i;
int tgti, *top;
short mval[2];
if(!st || !st->text) return 0;
if(!texttool_text_is_active(st->text)) return 0;
first = texttool_suggest_first();
last = texttool_suggest_last();
sel = texttool_suggest_selected();
top = texttool_suggest_top();
if(!last || !first)
return 0;
/* Count the visible lines to the cursor */
for(tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
if(l<0) return 0;
if(st->showlinenrs) {
x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET - 4;
}
y = ar->winy - st->lheight*l - 2;
w = SUGG_LIST_WIDTH*text_font_width_character(st) + 20;
h = SUGG_LIST_SIZE*st->lheight + 8;
// XXX getmouseco_areawin(mval);
if(mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
return 0;
/* Work out which of the items is at the top of the visible list */
for(i=0, item=first; i<*top && item->next; i++, item=item->next);
/* Work out the target item index in the visible list */
tgti = (y-mval[1]-4) / st->lheight;
if(tgti<0 || tgti>SUGG_LIST_SIZE)
return 1;
for(i=tgti; i>0 && item->next; i--, item=item->next);
if(item)
texttool_suggest_select(item);
return 1;
}
void text_pop_suggest_list()
{
SuggItem *item, *sel;
int *top, i;
item= texttool_suggest_first();
sel= texttool_suggest_selected();
top= texttool_suggest_top();
i= 0;
while(item && item != sel) {
item= item->next;
i++;
}
if(i > *top+SUGG_LIST_SIZE-1)
*top= i-SUGG_LIST_SIZE+1;
else if(i < *top)
*top= i;
}
static void get_suggest_prefix(Text *text, int offset)
{
int i, len;
char *line, tmp[256];
if(!text) return;
if(!texttool_text_is_active(text)) return;
line= text->curl->line;
for(i=text->curc-1+offset; i>=0; i--)
if(!text_check_identifier(line[i]))
break;
i++;
len= text->curc-i+offset;
if(len > 255) {
printf("Suggestion prefix too long\n");
len = 255;
}
BLI_strncpy(tmp, line+i, len);
tmp[len]= '\0';
texttool_suggest_prefix(tmp);
}
static void confirm_suggestion(Text *text, int skipleft)
{
SuggItem *sel;
int i, over=0;
char *line;
if(!text) return;
if(!texttool_text_is_active(text)) return;
sel = texttool_suggest_selected();
if(!sel) return;
line= text->curl->line;
i=text->curc-skipleft-1;
while(i>=0) {
if(!text_check_identifier(line[i]))
break;
over++;
i--;
}
for(i=0; i<skipleft; i++)
txt_move_left(text, 0);
for(i=0; i<over; i++)
txt_move_left(text, 1);
txt_insert_buf(text, sel->name);
for(i=0; i<skipleft; i++)
txt_move_right(text, 0);
texttool_text_clear();
}
// XXX
#define L_MOUSE 0
#define M_MOUSE 0
#define R_MOUSE 0
#define LR_SHIFTKEY 0
#define LR_ALTKEY 0
#define LR_CTRLKEY 0
#define LR_COMMANDKEY 0
// XXX
static int doc_scroll= 0;
short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short val)
{
ARegion *ar= NULL; // XXX
int qual= 0; // XXX
int draw=0, tools=0, swallow=0, scroll=1;
if(!texttool_text_is_active(st->text)) return 0;
if(!st->text || st->text->id.lib) return 0;
if(st->doplugins && texttool_text_is_active(st->text)) {
if(texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
if(texttool_docs_get()) tools |= TOOL_DOCUMENT;
}
if(ascii) {
if(tools & TOOL_SUGG_LIST) {
if((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text, st->text->curl);
}
else if((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
get_suggest_prefix(st->text, 0);
text_pop_suggest_list();
swallow= 1;
draw= 1;
}
}
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
}
else if(val==1 && evnt) {
switch (evnt) {
case LEFTMOUSE:
if(text_do_suggest_select(st, ar))
swallow= 1;
else {
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
}
draw= 1;
break;
case MIDDLEMOUSE:
if(text_do_suggest_select(st, ar)) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text, st->text->curl);
swallow= 1;
}
else {
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
}
draw= 1;
break;
case ESCKEY:
draw= swallow= 1;
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
else if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
else draw= swallow= 0;
break;
case RETKEY:
if(tools & TOOL_SUGG_LIST) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text, st->text->curl);
swallow= 1;
draw= 1;
}
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
break;
case LEFTARROWKEY:
case BACKSPACEKEY:
if(tools & TOOL_SUGG_LIST) {
if(qual)
texttool_suggest_clear();
else {
/* Work out which char we are about to delete/pass */
if(st->text->curl && st->text->curc > 0) {
char ch= st->text->curl->line[st->text->curc-1];
if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, -1);
text_pop_suggest_list();
}
else
texttool_suggest_clear();
}
else
texttool_suggest_clear();
}
}
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
break;
case RIGHTARROWKEY:
if(tools & TOOL_SUGG_LIST) {
if(qual)
texttool_suggest_clear();
else {
/* Work out which char we are about to pass */
if(st->text->curl && st->text->curc < st->text->curl->len) {
char ch= st->text->curl->line[st->text->curc+1];
if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, 1);
text_pop_suggest_list();
}
else
texttool_suggest_clear();
}
else
texttool_suggest_clear();
}
}
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
break;
case PAGEDOWNKEY:
scroll= SUGG_LIST_SIZE-1;
case WHEELDOWNMOUSE:
case DOWNARROWKEY:
if(tools & TOOL_DOCUMENT) {
doc_scroll++;
swallow= 1;
draw= 1;
break;
}
else if(tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
if(!sel) {
texttool_suggest_select(texttool_suggest_first());
}
else while(sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
texttool_suggest_select(sel->next);
sel= sel->next;
}
text_pop_suggest_list();
swallow= 1;
draw= 1;
break;
}
case PAGEUPKEY:
scroll= SUGG_LIST_SIZE-1;
case WHEELUPMOUSE:
case UPARROWKEY:
if(tools & TOOL_DOCUMENT) {
if(doc_scroll>0) doc_scroll--;
swallow= 1;
draw= 1;
break;
}
else if(tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
while(sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
texttool_suggest_select(sel->prev);
sel= sel->prev;
}
text_pop_suggest_list();
swallow= 1;
draw= 1;
break;
}
case RIGHTSHIFTKEY:
case LEFTSHIFTKEY:
break;
default:
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
}
}
if(draw)
; // XXX redraw_alltext();
return swallow;
}
#if 0
#ifndef DISABLE_PYTHON
/* Run text plugin scripts if enabled */
if(st->doplugins && event && val) {
if(BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
do_draw= 1;
}
}
#endif
if(do_draw)
; // XXX redraw_alltext();
#endif
short do_textmarkers(SpaceText *st, char ascii, unsigned short evnt, short val)
{
Text *text;
TextMarker *marker, *mrk, *nxt;
int c, s, draw=0, swallow=0;
int qual= 0; // XXX
text= st->text;
if(!text || text->id.lib || text->curl != text->sell) return 0;
marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
if(marker && (marker->start > text->curc || marker->end < text->curc))
marker= NULL;
if(!marker) {
/* Find the next temporary marker */
if(evnt==TABKEY) {
int lineno= txt_get_span(text->lines.first, text->curl);
TextMarker *mrk= text->markers.first;
while(mrk) {
if(!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
if((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
marker= mrk;
break;
}
mrk= mrk->next;
}
if(marker) {
txt_move_to(text, marker->lineno, marker->start, 0);
txt_move_to(text, marker->lineno, marker->end, 1);
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
evnt= ascii= val= 0;
draw= 1;
swallow= 1;
}
}
else if(evnt==ESCKEY) {
if(txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
else if(txt_clear_markers(text, 0, 0)) swallow= 1;
else return 0;
evnt= ascii= val= 0;
draw= 1;
}
if(!swallow) return 0;
}
if(ascii) {
if(marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if(s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
while(mrk) {
nxt=txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
if(st->overwrite) {
if(txt_replace_char(text, ascii))
text_update_line_edited(st->text, st->text->curl);
}
else {
if(txt_add_char(text, ascii)) {
text_update_line_edited(st->text, st->text->curl);
}
}
if(mrk==marker || mrk==nxt) break;
mrk=nxt;
}
swallow= 1;
draw= 1;
}
}
else if(val) {
switch(evnt) {
case BACKSPACEKEY:
if(marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if(s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
while(mrk) {
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
txt_backspace_char(text);
text_update_line_edited(st->text, st->text->curl);
if(mrk==marker || mrk==nxt) break;
mrk= nxt;
}
swallow= 1;
draw= 1;
}
break;
case DELKEY:
if(marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if(s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
while(mrk) {
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
txt_delete_char(text);
text_update_line_edited(st->text, st->text->curl);
if(mrk==marker || mrk==nxt) break;
mrk= nxt;
}
swallow= 1;
draw= 1;
}
break;
case TABKEY:
if(qual & LR_SHIFTKEY) {
nxt= marker->prev;
if(!nxt) nxt= text->markers.last;
}
else {
nxt= marker->next;
if(!nxt) nxt= text->markers.first;
}
if(marker->flags & TMARK_TEMP) {
if(nxt==marker) nxt= NULL;
BLI_freelinkN(&text->markers, marker);
}
mrk= nxt;
if(mrk) {
txt_move_to(text, mrk->lineno, mrk->start, 0);
txt_move_to(text, mrk->lineno, mrk->end, 1);
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
}
swallow= 1;
draw= 1;
break;
/* Events that should clear markers */
case UKEY: if(!(qual & LR_ALTKEY)) break;
case ZKEY: if(evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
case RETKEY:
case ESCKEY:
if(marker->flags & (TMARK_EDITALL | TMARK_TEMP))
txt_clear_markers(text, marker->group, 0);
else
BLI_freelinkN(&text->markers, marker);
swallow= 1;
draw= 1;
break;
case RIGHTMOUSE: /* Marker context menu? */
case LEFTMOUSE:
break;
case FKEY: /* Allow find */
if(qual & LR_SHIFTKEY) swallow= 1;
break;
default:
if(qual!=0 && qual!=LR_SHIFTKEY)
swallow= 1; /* Swallow all other shortcut events */
}
}
if(draw)
; // XXX redraw_alltext();
return swallow;
}

@ -47,6 +47,7 @@
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_object.h"
#include "BKE_text.h"
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
@ -62,6 +63,7 @@
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_util.h"
#include "ED_text.h"
#include "WM_api.h"
#include "WM_types.h"
@ -124,7 +126,10 @@ static int ed_undo_step(bContext *C, int step)
Object *obedit= CTX_data_edit_object(C);
ScrArea *sa= CTX_wm_area(C);
if(obedit) {
if(sa && sa->spacetype==SPACE_TEXT) {
ED_text_undo_step(C, step);
}
else if(obedit) {
if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
undo_editmode_step(C, step);
}
@ -133,7 +138,7 @@ static int ed_undo_step(bContext *C, int step)
if(G.f & G_TEXTUREPAINT)
undo_imagepaint_step(step);
else if(sa->spacetype==SPACE_IMAGE) {
else if(sa && sa->spacetype==SPACE_IMAGE) {
SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
if(sima->flag & SI_DRAWTOOL)
undo_imagepaint_step(step);

@ -285,7 +285,7 @@ typedef struct SpaceText {
int showlinenrs;
int tabnumber;
int currtab_set;
int pad;
int showsyntax;
int overwrite;
float pix_per_line;
@ -294,6 +294,8 @@ typedef struct SpaceText {
int wordwrap, doplugins;
char findstr[256]; /* ST_MAX_FIND_STR */
char replacestr[256]; /* ST_MAX_FIND_STR */
} SpaceText;
typedef struct Script {
@ -609,6 +611,12 @@ enum {
#define ST_SCROLL_SELECT 0x0001 // scrollable
#define ST_CLEAR_NAMESPACE 0x0010 // clear namespace after script
// execution (see BPY_main.c)
#define ST_FIND_WRAP 0x0020
#define ST_FIND_ALL 0x0040
/* stext->findstr/replacestr */
#define ST_MAX_FIND_STR 256
/* SpaceOops->type */
#define SO_OOPS 0

@ -78,7 +78,7 @@ typedef struct Text {
/* text flags */
#define TXT_ISDIRTY 0x0001
#define TXT_ISTMP 0x0002
#define TXT_DEPRECATED 0x0004 /* deprecated ISTMP flag */
#define TXT_ISMEM 0x0004
#define TXT_ISEXT 0x0008
#define TXT_ISSCRIPT 0x0010 /* used by space handler scriptlinks */

@ -222,6 +222,7 @@ extern StructRNA RNA_SoundSequence;
extern StructRNA RNA_Space;
extern StructRNA RNA_SpaceImageEditor;
extern StructRNA RNA_SpaceUVEditor;
extern StructRNA RNA_SpaceTextEditor;
extern StructRNA RNA_SpeedControlSequence;
extern StructRNA RNA_SpotLamp;
extern StructRNA RNA_StringProperty;

@ -31,6 +31,8 @@
#include "DNA_space_types.h"
#include "WM_types.h"
#ifdef RNA_RUNTIME
#include "DNA_scene_types.h"
@ -58,12 +60,12 @@ static StructRNA* rna_Space_refine(struct PointerRNA *ptr)
/*case SPACE_INFO:
return &RNA_SpaceUserPreferences;
case SPACE_SEQ:
return &RNA_SpaceSequenceEditor;
return &RNA_SpaceSequenceEditor;*/
case SPACE_TEXT:
return &RNA_SpaceTextEditor;
//case SPACE_IMASEL:
// return &RNA_SpaceImageBrowser;
case SPACE_SOUND:
/*case SPACE_SOUND:
return &RNA_SpaceAudioWindow;
case SPACE_ACTION:
return &RNA_SpaceDopeSheetEditor;
@ -93,6 +95,14 @@ static void rna_SpaceImage_paint_update(bContext *C, PointerRNA *ptr)
brush_check_exists(&scene->toolsettings->imapaint.brush);
}
void rna_SpaceTextEditor_word_wrap_set(PointerRNA *ptr, int value)
{
SpaceText *st= (SpaceText*)(ptr->data);
st->wordwrap= value;
st->left= 0;
}
#else
static void rna_def_space(BlenderRNA *brna)
@ -304,10 +314,80 @@ static void rna_def_space_image(BlenderRNA *brna)
rna_def_space_image_uv(brna);
}
static void rna_def_space_text(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem font_size_items[] = {
{12, "SCREEN_12", "Screen 12", ""},
{15, "SCREEN_15", "Screen 15", ""},
{0, NULL, NULL, NULL}};
srna= RNA_def_struct(brna, "SpaceTextEditor", "Space");
RNA_def_struct_sdna(srna, "SpaceText");
RNA_def_struct_ui_text(srna, "Space Text Editor", "Text editor space data.");
/* text */
prop= RNA_def_property(srna, "text", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "Text", "Text displayed and edited in this space.");
/* display */
prop= RNA_def_property(srna, "syntax_highlight", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "showsyntax", 0);
RNA_def_property_ui_text(prop, "Syntax Highlight", "Syntax highlight for scripting.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
prop= RNA_def_property(srna, "word_wrap", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "wordwrap", 0);
RNA_def_property_boolean_funcs(prop, NULL, "rna_SpaceTextEditor_word_wrap_set");
RNA_def_property_ui_text(prop, "Word Wrap", "Wrap words if there is not enough horizontal space.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
prop= RNA_def_property(srna, "line_numbers", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "showlinenrs", 0);
RNA_def_property_ui_text(prop, "Line Numbers", "Show line numbers next to the text.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
prop= RNA_def_property(srna, "tab_width", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "tabnumber");
RNA_def_property_range(prop, 2, 8);
RNA_def_property_ui_text(prop, "Tab Width", "Number of spaces to display tabs with.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
prop= RNA_def_property(srna, "font_size", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "lheight");
RNA_def_property_enum_items(prop, font_size_items);
RNA_def_property_ui_text(prop, "Font Size", "Font size to use for displaying the text.");
RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
/* find */
prop= RNA_def_property(srna, "find_all", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", ST_FIND_ALL);
RNA_def_property_ui_text(prop, "Find All", "Search in all text datablocks, instead of only the active one.");
prop= RNA_def_property(srna, "find_wrap", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", ST_FIND_WRAP);
RNA_def_property_ui_text(prop, "Find Wrap", "Search again from the start of the file when reaching the end.");
prop= RNA_def_property(srna, "find_text", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "findstr");
RNA_def_property_ui_text(prop, "Find Text", "Text to search for with the find tool.");
prop= RNA_def_property(srna, "replace_text", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "replacestr");
RNA_def_property_ui_text(prop, "Replace Text", "Text to replace selected text with using the replace tool.");
}
void RNA_def_space(BlenderRNA *brna)
{
rna_def_space(brna);
rna_def_space_image(brna);
rna_def_space_text(brna);
}
#endif

@ -206,5 +206,10 @@ void WM_jobs_start(struct wmJob *);
void WM_jobs_stop(struct wmWindowManager *wm, void *owner);
void WM_jobs_stop_all(struct wmWindowManager *wm);
/* clipboard */
char *WM_clipboard_text_get(int selection);
void WM_clipboard_text_set(char *buf, int selection);
#endif /* WM_API_H */

@ -156,6 +156,7 @@ typedef struct wmNotifier {
#define NC_GROUP (9<<24)
#define NC_IMAGE (10<<24)
#define NC_BRUSH (11<<24)
#define NC_TEXT (12<<24)
/* data type, 256 entries is enough, it can overlap */
#define NOTE_DATA 0x00FF0000
@ -205,6 +206,10 @@ typedef struct wmNotifier {
#define ND_LIGHTING_DRAW (45<<16)
#define ND_SKY (46<<16)
/* NC_TEXT Text */
#define ND_CURSOR (50<<16)
#define ND_DISPLAY (51<<16)
/* subtype, 256 entries too */
#define NOTE_SUBTYPE 0x0000FF00

@ -151,12 +151,15 @@ void wm_event_do_notifiers(bContext *C)
}
if(note->window==win) {
if(note->category==NC_SCREEN) {
if(note->data==ND_SCREENBROWSE)
if(note->data==ND_SCREENBROWSE) {
ED_screen_set(C, note->reference); // XXX hrms, think this over!
printf("screen set %p\n", note->reference);
}
}
else if(note->category==NC_SCENE) {
if(note->data==ND_SCENEBROWSE) {
ED_screen_set_scene(C, note->reference); // XXX hrms, think this over!
printf("scene set %p\n", note->reference);
}
else if(note->data==ND_FRAME)
do_anim= 1;

@ -661,6 +661,57 @@ void WM_event_remove_window_timer(wmWindow *win, wmTimer *timer)
}
}
/* ******************* clipboard **************** */
char *WM_clipboard_text_get(int selection)
{
char *p, *p2, *buf, *newbuf;
buf= (char*)GHOST_getClipboard(selection);
if(!buf)
return NULL;
/* always convert from \r\n to \n */
newbuf= MEM_callocN(strlen(buf)+1, "WM_clipboard_text_get");
for(p= buf, p2= newbuf; *p; p++) {
if(*p != '\r')
*(p2++)= *p;
}
*p2= '\0';
free(buf); /* ghost uses regular malloc */
return newbuf;
}
void WM_clipboard_text_set(char *buf, int selection)
{
/* do conversion from \n to \r\n on Windows */
char *p, *p2, *newbuf;
int newlen= 0;
for(p= buf; *p; p++) {
if(*p == '\n')
newlen += 2;
else
newlen++;
}
newbuf= MEM_callocN(newlen+1, "WM_clipboard_text_set");
for(p= buf, p2= newbuf; *p; p++, p2++) {
if(*p == '\n') {
*(p2++)= '\r'; *p2= '\n';
}
else *p2= *p;
}
*p2= '\0';
GHOST_putClipboard((GHOST_TInt8*)newbuf, selection);
MEM_freeN(newbuf);
}
/* ************************************ */
void wm_window_get_position(wmWindow *win, int *posx_r, int *posy_r)