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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/src/header_text.c')
-rw-r--r--source/blender/src/header_text.c215
1 files changed, 193 insertions, 22 deletions
diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c
index cf6d21ff264..eeea43ec57a 100644
--- a/source/blender/src/header_text.c
+++ b/source/blender/src/header_text.c
@@ -42,6 +42,7 @@
#include "BMF_Api.h"
#include "BIF_language.h"
+#include "MEM_guardedalloc.h"
#include "BSE_headerbuttons.h"
@@ -52,6 +53,7 @@
#include "DNA_constraint_types.h"
#include "DNA_action_types.h"
+#include "BIF_gl.h" /* for glRasterPos2i */
#include "BIF_drawtext.h"
#include "BIF_interface.h"
#include "BIF_resources.h"
@@ -128,7 +130,7 @@ void do_text_buttons(unsigned short event)
st->top= 0;
pop_space_text(st);
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
allqueue(REDRAWTEXT, 0);
allqueue(REDRAWHEADERS, 0);
}
@@ -194,14 +196,20 @@ void do_text_buttons(unsigned short event)
break;
case B_TAB_NUMBERS:
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
allqueue(REDRAWTEXT, 0);
allqueue(REDRAWHEADERS, 0);
break;
case B_SYNTAX:
- if (st->showsyntax) {
- get_format_string(st);
- }
+ if (st->showsyntax) txt_format_text(st);
+ allqueue(REDRAWTEXT, 0);
+ allqueue(REDRAWHEADERS, 0);
+ break;
+ case B_TEXTPLUGINS:
+ allqueue(REDRAWHEADERS, 0);
+ break;
+ case B_WORDWRAP:
+ st->left= 0;
allqueue(REDRAWTEXT, 0);
allqueue(REDRAWHEADERS, 0);
break;
@@ -239,6 +247,37 @@ static uiBlock *text_template_scriptsmenu (void *args_unused)
return block;
}
+static void do_text_plugin_scriptsmenu(void *arg, int event)
+{
+ BPY_menu_do_python(PYMENU_TEXTPLUGIN, event);
+
+ allqueue(REDRAWIMAGE, 0);
+}
+
+static uiBlock *text_plugin_scriptsmenu (void *args_unused)
+{
+ uiBlock *block;
+ BPyMenu *pym;
+ int i= 0;
+ short yco = 20, menuwidth = 120;
+
+ block= uiNewBlock(&curarea->uiblocks, "text_plugin_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
+ uiBlockSetButmFunc(block, do_text_plugin_scriptsmenu, NULL);
+
+ /* note that we acount for the N previous entries with i+20: */
+ 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);
+
+ return block;
+}
+
/* action executed after clicking in File menu */
static void do_text_filemenu(void *arg, int event)
{
@@ -268,7 +307,7 @@ static void do_text_filemenu(void *arg, int event)
if (!reopen_text(text)) {
error("Could not reopen file");
}
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
}
break;
case 5:
@@ -277,9 +316,14 @@ static void do_text_filemenu(void *arg, int event)
txt_write_file(text);
break;
case 6:
- run_python_script(st);
+ text->flags |= TXT_ISMEM | TXT_ISDIRTY | TXT_ISTMP;
+ MEM_freeN(text->name);
+ text->name= NULL;
break;
case 7:
+ run_python_script(st);
+ break;
+ case 8:
{
Object *ob;
bConstraint *con;
@@ -340,11 +384,17 @@ static void do_text_editmenu(void *arg, int event)
switch(event) {
case 1:
txt_do_undo(text);
+ pop_space_text(st);
break;
case 2:
txt_do_redo(text);
+ pop_space_text(st);
break;
case 3:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
txt_copy_clipboard(text);
txt_cut_sel(text);
pop_space_text(st);
@@ -354,8 +404,12 @@ static void do_text_editmenu(void *arg, int event)
txt_copy_clipboard(text);
break;
case 5:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
txt_paste_clipboard(text);
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
break;
case 6:
txt_print_cutbuffer();
@@ -364,10 +418,11 @@ static void do_text_editmenu(void *arg, int event)
jumptoline_interactive(st);
break;
case 8:
- txt_find_panel(st,1);
- break;
case 9:
- txt_find_panel(st,0);
+ find_and_replace(st, 0);
+ break;
+ case 10:
+ find_and_replace(st, 1);
break;
default:
break;
@@ -443,6 +498,57 @@ static void do_text_editmenu_selectmenu(void *arg, int event)
}
}
+/* action executed after clicking in Markers menu */
+static void do_text_editmenu_markermenu(void *arg, int event)
+{
+ SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
+ Text *text;
+ TextMarker *mrk;
+ ScrArea *sa;
+ int lineno;
+
+ if (st==NULL || st->spacetype != SPACE_TEXT) return;
+
+ text = st->text;
+
+ switch(event) {
+ case 1:
+ txt_clear_markers(text, 0, 0);
+ break;
+ case 2:
+ lineno= txt_get_span(text->lines.first, text->curl);
+ mrk= text->markers.first;
+ while (mrk && (mrk->lineno<lineno || (mrk->lineno==lineno && mrk->start <= text->curc)))
+ mrk= mrk->next;
+ if (!mrk) mrk= text->markers.first;
+ if (mrk) {
+ txt_move_to(text, mrk->lineno, mrk->start, 0);
+ txt_move_to(text, mrk->lineno, mrk->end, 1);
+ }
+ break;
+ case 3:
+ lineno= txt_get_span(text->lines.first, text->curl);
+ mrk= text->markers.last;
+ while (mrk && (mrk->lineno>lineno || (mrk->lineno==lineno && mrk->end > text->curc)))
+ mrk= mrk->prev;
+ if (!mrk) mrk= text->markers.last;
+ if (mrk) {
+ txt_move_to(text, mrk->lineno, mrk->start, 0);
+ txt_move_to(text, mrk->lineno, mrk->end, 1);
+ }
+ break;
+ default:
+ break;
+ }
+
+ for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
+ SpaceText *st= sa->spacedata.first;
+ if (st && st->spacetype==SPACE_TEXT) {
+ scrarea_queue_redraw(sa);
+ }
+ }
+}
+
/* action executed after clicking in Format menu */
static void do_text_formatmenu(void *arg, int event)
{
@@ -456,6 +562,10 @@ static void do_text_formatmenu(void *arg, int event)
switch(event) {
case 3:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
if (txt_has_sel(text)) {
txt_order_cursors(text);
indent(text);
@@ -466,6 +576,10 @@ static void do_text_formatmenu(void *arg, int event)
break;
}
case 4:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
if ( txt_has_sel(text)) {
txt_order_cursors(text);
unindent(text);
@@ -473,18 +587,26 @@ static void do_text_formatmenu(void *arg, int event)
}
break;
case 5:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
if ( txt_has_sel(text)) {
txt_order_cursors(text);
comment(text);
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
break;
}
break;
case 6:
+ if (text && text->id.lib) {
+ error_libdata();
+ break;
+ }
if ( txt_has_sel(text)) {
txt_order_cursors(text);
uncomment(text);
- if (st->showsyntax) get_format_string(st);
+ if (st->showsyntax) txt_format_text(st);
break;
}
break;
@@ -536,6 +658,25 @@ static uiBlock *text_editmenu_selectmenu(void *arg_unused)
return block;
}
+/* Select menu */
+static uiBlock *text_editmenu_markermenu(void *arg_unused)
+{
+ uiBlock *block;
+ short yco = 20, menuwidth = 120;
+
+ block= uiNewBlock(&curarea->uiblocks, "text_editmenu_markermenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
+ uiBlockSetButmFunc(block, do_text_editmenu_markermenu, NULL);
+
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear All", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Marker", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Marker", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
+
+ uiBlockSetDirection(block, UI_RIGHT);
+ uiTextBoundsBlock(block, 60);
+
+ return block;
+}
+
void do_text_formatmenu_convert(void *arg, int event)
{
SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
@@ -649,10 +790,12 @@ static uiBlock *text_editmenu(void *arg_unused)
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBlockBut(block, text_editmenu_viewmenu, NULL, ICON_RIGHTARROW_THIN, "View|Alt Shift V ", 0, yco-=20, 120, 19, "");
uiDefIconTextBlockBut(block, text_editmenu_selectmenu, NULL, ICON_RIGHTARROW_THIN, "Select|Alt Shift S ", 0, yco-=20, 120, 19, "");
+ uiDefIconTextBlockBut(block, text_editmenu_markermenu, NULL, ICON_RIGHTARROW_THIN, "Markers", 0, yco-=20, 120, 19, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump...|Alt J", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find...|Alt Ctrl F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Again|Alt F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find And Replace...|Alt F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Next|Alt F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBlockBut(block, text_editmenu_to3dmenu, NULL, ICON_RIGHTARROW_THIN, "Text to 3d Object", 0, yco-=20, 120, 19, "");
@@ -690,17 +833,21 @@ static uiBlock *text_filemenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
+ if (text->name)
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make Internal", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
+
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Run Python Script|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Run Python Script|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
if (BPY_is_pyconstraint(text))
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Refresh All PyConstraints", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Refresh All PyConstraints", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
}
uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
+ uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
@@ -715,13 +862,15 @@ static uiBlock *text_filemenu(void *arg_unused)
}
/* header */
+#define HEADER_PATH_MAX 260
void text_buttons(void)
{
uiBlock *block;
SpaceText *st= curarea->spacedata.first;
Text *text;
short xco, xmax;
- char naam[256];
+ char naam[256], fname[HEADER_PATH_MAX], headtxt[HEADER_PATH_MAX+17];
+ int len;
if (st==NULL || st->spacetype != SPACE_TEXT) return;
@@ -779,8 +928,9 @@ void text_buttons(void)
else uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN, xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
uiDefIconButI(block, ICONTOG, B_TEXTLINENUM, ICON_LONGDISPLAY, xco+=XIC,0,XIC,YIC, &st->showlinenrs, 0, 0, 0, 0, "Displays line numbers");
-
- uiDefIconButI(block, ICONTOG, B_SYNTAX, ICON_SYNTAX, xco+=XIC,0,XIC,YIC, &st->showsyntax, 0, 0, 0, 0, "Enables Syntax Highlighting");
+ uiDefIconButI(block, ICONTOG, B_WORDWRAP, ICON_WORDWRAP, xco+=XIC,0,XIC,YIC, &st->wordwrap, 0, 0, 0, 0, "Enables word wrap");
+ uiDefIconButI(block, ICONTOG, B_SYNTAX, ICON_SYNTAX, xco+=XIC,0,XIC,YIC, &st->showsyntax, 0, 0, 0, 0, "Enables syntax highlighting");
+ uiDefIconButI(block, ICONTOG, B_TEXTPLUGINS, ICON_PYTHON, xco+=XIC,0,XIC,YIC, &st->doplugins, 0, 0, 0, 0, "Enables Python text plugins");
uiBlockEndAlign(block);
/* STD TEXT BUTTONS */
@@ -804,9 +954,30 @@ void text_buttons(void)
uiDefButI(block, MENU, B_TEXTFONT, "Screen 12 %x0|Screen 15%x1", xco,0,100,YIC, &st->font_id, 0, 0, 0, 0, "Displays available fonts");
xco+=110;
- uiDefButI(block, NUM, B_TAB_NUMBERS, "Tab:", xco, 0, XIC+50, YIC, &st->tabnumber, 2, 8, 0, 0, "Set spacing of Tab");
+ uiDefButI(block, NUM, B_TAB_NUMBERS, "Tab:", xco, 0, XIC+50, YIC, &st->tabnumber, 2, 8, 0, 0, "Set spacing of Tab");
xco+= XIC+50;
-
+
+ /* File info */
+ if (text) {
+ 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");
+ }
+ BIF_ThemeColor(TH_MENU_TEXT);
+ glRasterPos2i(xco+=XIC, 5);
+ BMF_DrawString(G.font, headtxt);
+ xco += BMF_GetStringWidth(G.font, headtxt);
+ }
+
/* always as last */
curarea->headbutlen= xco+2*XIC;