The R Project SVN R

Rev

Rev 44575 | Rev 46774 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44575 Rev 45070
Line 84... Line 84...
84
    EditorData p = getdata(t);
84
    EditorData p = getdata(t);
85
    strncpy(wtitle, title, EDITORMAXTITLE);
85
    strncpy(wtitle, title, EDITORMAXTITLE);
86
    wtitle[EDITORMAXTITLE] = '\0';
86
    wtitle[EDITORMAXTITLE] = '\0';
87
    strcpy(p->title, wtitle);
87
    strcpy(p->title, wtitle);
88
    if (strlen(wtitle) + strlen(G_("R Editor")) + 3 < EDITORMAXTITLE) {
88
    if (strlen(wtitle) + strlen(G_("R Editor")) + 3 < EDITORMAXTITLE) {
89
    	strcat(wtitle, " - ");
89
	strcat(wtitle, " - ");
90
    	strcat(wtitle, G_("R Editor"));
90
	strcat(wtitle, G_("R Editor"));
91
    }
91
    }
92
    settext(c, wtitle);
92
    settext(c, wtitle);
93
}
93
}
94
 
94
 
95
/*** FILE MANAGEMENT FUNCTIONS ***/
95
/*** FILE MANAGEMENT FUNCTIONS ***/
Line 114... Line 114...
114
	if (num >= 0) {
114
	if (num >= 0) {
115
	    bufsize += num;
115
	    bufsize += num;
116
	    buffer[bufsize] = '\0';
116
	    buffer[bufsize] = '\0';
117
	}
117
	}
118
	else {
118
	else {
119
	    snprintf(tmp, MAX_PATH+50, G_("Could not read from file '%s'"), 
119
	    snprintf(tmp, MAX_PATH+50, G_("Could not read from file '%s'"),
120
		     name);
120
		     name);
121
	    askok(tmp);
121
	    askok(tmp);
122
	}
122
	}
123
    }
123
    }
124
    setlimittext(t, 2 * strlen(buffer));
124
    setlimittext(t, 2 * strlen(buffer));
Line 145... Line 145...
145
	fprintf(f, "%s", gettext(t));
145
	fprintf(f, "%s", gettext(t));
146
	fclose(f);
146
	fclose(f);
147
    }
147
    }
148
}
148
}
149
 
149
 
150
static void editorsaveas(editor c) {
150
static void editorsaveas(editor c)
-
 
151
{
151
    textbox t = getdata(c);
152
    textbox t = getdata(c);
152
    EditorData p = getdata(t);
153
    EditorData p = getdata(t);
153
    char *current_name = (p->file ? p->filename : "");
154
    char *current_name = (p->file ? p->filename : "");
154
    char *name;
155
    char *name;
155
    setuserfilter("R files (*.R)\0*.R\0S files (*.q, *.ssc, *.S)\0*.q;*.ssc;*.S\0All files (*.*)\0*.*\0\0");
156
    setuserfilter("R files (*.R)\0*.R\0S files (*.q, *.ssc, *.S)\0*.q;*.ssc;*.S\0All files (*.*)\0*.*\0\0");
Line 222... Line 223...
222
    i = 0;
223
    i = 0;
223
    while (i < strlen(contents)) {
224
    while (i < strlen(contents)) {
224
	if ( linep + fh >= rr ) { /* new page */
225
	if ( linep + fh >= rr ) { /* new page */
225
	    if (page > 1) nextpage(lpr);
226
	    if (page > 1) nextpage(lpr);
226
	    sprintf(msg, "Page %d", page++);
227
	    sprintf(msg, "Page %d", page++);
227
  	    gdrawstr(lpr, f, Black, pt(cc - gstrwidth(lpr, f, msg) - 1, top),
228
	    gdrawstr(lpr, f, Black, pt(cc - gstrwidth(lpr, f, msg) - 1, top),
228
		     msg);
229
		     msg);
229
	    linep = top + 2*fh;
230
	    linep = top + 2*fh;
230
	}
231
	}
231
	j = 0;
232
	j = 0;
232
	istartline = i;
233
	istartline = i;
Line 234... Line 235...
234
	    ++i; ++j;
235
	    ++i; ++j;
235
	}
236
	}
236
	linebuf = realloc(linebuf, (j+1)*sizeof(char));
237
	linebuf = realloc(linebuf, (j+1)*sizeof(char));
237
	strncpy(linebuf, &contents[istartline], j);
238
	strncpy(linebuf, &contents[istartline], j);
238
	linebuf[j] = '\0';
239
	linebuf[j] = '\0';
239
  	gdrawstr(lpr, f, Black, pt(left, linep), linebuf);
240
	gdrawstr(lpr, f, Black, pt(left, linep), linebuf);
240
	linep += fh;
241
	linep += fh;
241
	++i;
242
	++i;
242
    }
243
    }
243
    free(linebuf);
244
    free(linebuf);
244
    if (f != FixedFont) del(f);
245
    if (f != FixedFont) del(f);
Line 357... Line 358...
357
 
358
 
358
void menueditoropen(control m)
359
void menueditoropen(control m)
359
{
360
{
360
    editor c = getdata(m);
361
    editor c = getdata(m);
361
    char *default_name = "";
362
    char *default_name = "";
362
    /* It really is not clear what is meant here: seems to assume an 
363
    /* It really is not clear what is meant here: seems to assume an
363
       editor window but is called from elsewhere, hopefully with NULL 
364
       editor window but is called from elsewhere, hopefully with NULL
364
       (since 2.1.1 patched). */
365
       (since 2.1.1 patched). */
365
    if (c) {
366
    if (c) {
366
	textbox t = getdata(c);
367
	textbox t = getdata(c);
367
	EditorData p = getdata(t);
368
	EditorData p = getdata(t);
368
	if (p->file) default_name = p->filename;  /* name of currently-open file, if there is one */
369
	if (p->file) default_name = p->filename;  /* name of currently-open file, if there is one */
Line 457... Line 458...
457
static Rboolean busy_running = FALSE;
458
static Rboolean busy_running = FALSE;
458
 
459
 
459
static void editorrun(textbox t)
460
static void editorrun(textbox t)
460
{
461
{
461
    if (!busy_running) {
462
    if (!busy_running) {
462
        long start=0, end=0;
463
	long start=0, end=0;
463
    	if (CharacterMode != RGui) {
464
	if (CharacterMode != RGui) {
464
    	    R_ShowMessage(G_("No RGui console to paste to"));
465
	    R_ShowMessage(G_("No RGui console to paste to"));
465
    	    return;
466
	    return;
466
    	}
467
	}
467
    	busy_running = TRUE;
468
	busy_running = TRUE;
468
    	textselectionex(t, &start, &end);
469
	textselectionex(t, &start, &end);
469
    	if (start >= end)
470
	if (start >= end)
470
	    editorrunline(t);
471
	    editorrunline(t);
471
    	else {
472
	else {
472
	    editorrunselection(t, start, end);
473
	    editorrunselection(t, start, end);
473
	    selecttextex(t, end, end); /* move insertion point to end of selection after running */
474
	    selecttextex(t, end, end); /* move insertion point to end of selection after running */
474
    	}
475
	}
475
    	busy_running = FALSE;
476
	busy_running = FALSE;
476
    }
477
    }
477
}
478
}
478
 
479
 
479
static void menueditorrun(control m)
480
static void menueditorrun(control m)
480
{
481
{
Line 499... Line 500...
499
    long start, end;
500
    long start, end;
500
    textbox t = getdata(m);
501
    textbox t = getdata(m);
501
    EditorData p = getdata(t);
502
    EditorData p = getdata(t);
502
    textselectionex(t, &start, &end);
503
    textselectionex(t, &start, &end);
503
    if (start < end) {
504
    if (start < end) {
504
        enable(p->mcut);
505
	enable(p->mcut);
505
        enable(p->mcopy);
506
	enable(p->mcopy);
506
        enable(p->mdelete);
507
	enable(p->mdelete);
507
        enable(p->mpopcut);
508
	enable(p->mpopcut);
508
        enable(p->mpopcopy);
509
	enable(p->mpopcopy);
509
        enable(p->mpopdelete);
510
	enable(p->mpopdelete);
510
    }
511
    }
511
    else {
512
    else {
512
	disable(p->mcut);
513
	disable(p->mcut);
513
	disable(p->mcopy);
514
	disable(p->mcopy);
514
	disable(p->mdelete);
515
	disable(p->mdelete);
Line 544... Line 545...
544
}
545
}
545
 
546
 
546
static void editorasciikeydown(textbox t, int key)
547
static void editorasciikeydown(textbox t, int key)
547
{
548
{
548
    /* check whether the text limit is about to be exceeded and
549
    /* check whether the text limit is about to be exceeded and
549
     increase it if necessary.  Ugh - this callback is called after
550
       increase it if necessary.  Ugh - this callback is called after
550
     the text is inserted, so we make space for two characters */
551
       the text is inserted, so we make space for two characters */
551
    checklimittext(t, 2);
552
    checklimittext(t, 2);
552
}
553
}
553
 
554
 
554
/* Set keyboard focus to the text editing area when the editor window receives focus */
555
/* Set keyboard focus to the text editing area when the editor window receives focus */
555
 
556
 
Line 702... Line 703...
702
    setdata(m, t);
703
    setdata(m, t);
703
    MCHECK(m = newmenuitem("-", 0, NULL));
704
    MCHECK(m = newmenuitem("-", 0, NULL));
704
    MCHECK(m = newmenuitem(G_("Close script"), 0, menueditorclose));
705
    MCHECK(m = newmenuitem(G_("Close script"), 0, menueditorclose));
705
    setdata(m, c);
706
    setdata(m, c);
706
    /* MCHECK(m = newmenuitem("-", 0, NULL));
707
    /* MCHECK(m = newmenuitem("-", 0, NULL));
707
    MCHECK(m = newmenuitem(G_("Exit"), 0, closeconsole));
708
       MCHECK(m = newmenuitem(G_("Exit"), 0, closeconsole));
708
    setdata(m, c); */
709
       setdata(m, c); */
709
    MCHECK(newmenu(G_("Edit")));
710
    MCHECK(newmenu(G_("Edit")));
710
    MCHECK(m = newmenuitem(G_("Undo"), 'Z', editorundo));
711
    MCHECK(m = newmenuitem(G_("Undo"), 'Z', editorundo));
711
    setdata(m, t);
712
    setdata(m, t);
712
    MCHECK(m = newmenuitem("-", 0, NULL));
713
    MCHECK(m = newmenuitem("-", 0, NULL));
713
    MCHECK(p->mcut = newmenuitem(G_("Cut"), 'X', editorcut));
714
    MCHECK(p->mcut = newmenuitem(G_("Cut"), 'X', editorcut));
Line 769... Line 770...
769
{
770
{
770
    int i, ismod;
771
    int i, ismod;
771
    textbox t;
772
    textbox t;
772
    for (i = 0; i < neditors; i++) {
773
    for (i = 0; i < neditors; i++) {
773
	t = getdata(REditors[i]);
774
	t = getdata(REditors[i]);
774
 	ismod = ggetmodified(t);
775
	ismod = ggetmodified(t);
775
	/* Don't change the modification flag when changing font  */
776
	/* Don't change the modification flag when changing font  */
776
	settextfont(t, f);
777
	settextfont(t, f);
777
	gsetmodified(t, ismod);
778
	gsetmodified(t, ismod);
778
	show(t);
779
	show(t);
779
    }
780
    }
Line 819... Line 820...
819
    }
820
    }
820
    else {
821
    else {
821
	editor_set_title(c, G_("Untitled"));
822
	editor_set_title(c, G_("Untitled"));
822
    }
823
    }
823
    show(c);
824
    show(c);
824
    
825
 
825
    p = getdata(getdata(c));
826
    p = getdata(getdata(c));
826
    p->stealconsole = modal;
827
    p->stealconsole = modal;
827
    if (modal) {
828
    if (modal) {
828
    	fix_editor_up = TRUE;
829
	fix_editor_up = TRUE;
829
    	eventloop(c);
830
	eventloop(c);
830
    }
831
    }
831
    return 0;
832
    return 0;
832
}
833
}