The R Project SVN R

Rev

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

Rev 4394 Rev 4606
Line 116... Line 116...
116
 
116
 
117
static char cod[MAX_PATH]=""; /*current open directory*/
117
static char cod[MAX_PATH]=""; /*current open directory*/
118
 
118
 
119
void askchangedir()
119
void askchangedir()
120
{
120
{
121
  char *s;
-
 
122
  char msg[MAX_PATH+40]=" Change working directory to:";
121
    char *s, msg[MAX_PATH + 40];
-
 
122
 
123
/* if cod never used, set it to current directory */
123
/* if cod has never been used, set it to current directory */
124
  if (!cod[0]) GetCurrentDirectory(MAX_PATH,cod);
124
    if (!cod[0]) GetCurrentDirectory(MAX_PATH, cod);
125
  s = askstring(msg,cod);
125
    s = askcdstring(" Change working directory to:", cod);
126
  if (s && (SetCurrentDirectory(s)==FALSE)) {
126
    if (s && (SetCurrentDirectory(s) == FALSE)) {
127
     sprintf(msg,"Impossible to set '%s' as working directory",s);
127
	sprintf(msg, "Unable to set '%s' as working directory", s);
128
     askok(msg);
128
	askok(msg);
129
  }
129
    }
130
  /* in every case reset cod (to new directory if all went ok
130
    /* in every case reset cod (to new directory if all went ok
131
     or to old since user can have edited it */
131
       or to old since user may have edited it */
132
  GetCurrentDirectory(MAX_PATH,cod);
132
    GetCurrentDirectory(MAX_PATH, cod);
133
}
133
}
134
 
134
 
135
 
135
 
136
char *askfilename(char *title, char *default_name)
136
char *askfilename(char *title, char *default_name)
137
{
137
{
Line 244... Line 244...
244
	#define data(w) ((dialog_data *) (getdata(w)))
244
	#define data(w) ((dialog_data *) (getdata(w)))
245
 
245
 
246
/*
246
/*
247
 *  Some strings to use:
247
 *  Some strings to use:
248
 */
248
 */
249
	static char * OKAY_STRING	= "Okay";
249
	static char * OKAY_STRING	= "OK";
250
	static char * CANCEL_STRING	= "Cancel";
250
	static char * CANCEL_STRING	= "Cancel";
-
 
251
	static char * BROWSE_STRING	= "Browse";
251
 
252
 
252
	static char * QUESTION_TITLE	= "Question";
253
	static char * QUESTION_TITLE	= "Question";
253
	static char * PASSWORD_TITLE	= "Password Entry";
254
	static char * PASSWORD_TITLE	= "Password Entry";
-
 
255
	static char * FINDDIR_TITLE	= "Change directory";
254
 
256
 
255
static void add_data(window w)
257
static void add_data(window w)
256
{
258
{
257
	dialog_data *d;
259
	dialog_data *d;
258
 
260
 
Line 285... Line 287...
285
 
287
 
286
	d->hit = value;
288
	d->hit = value;
287
	hide(w);
289
	hide(w);
288
}
290
}
289
 
291
 
-
 
292
static void browse_button(control c)
-
 
293
{
-
 
294
    window w = parentwindow(c);
-
 
295
    dialog_data *d = data(w);
-
 
296
 
-
 
297
    OPENFILENAME ofn;
-
 
298
    char strbuf[256]="anything", *p;
-
 
299
 
-
 
300
    ofn.lStructSize     = sizeof(OPENFILENAME);
-
 
301
    ofn.hwndOwner       = 0;
-
 
302
    ofn.hInstance       = 0;
-
 
303
    ofn.lpstrFilter     = "All files (*.*)\0*.*\0\0";
-
 
304
    ofn.lpstrCustomFilter = NULL;
-
 
305
    ofn.nMaxCustFilter  = 0;
-
 
306
    ofn.nFilterIndex    = 0;
-
 
307
    ofn.lpstrFile       = strbuf;
-
 
308
    ofn.nMaxFile        = _MAX_PATH;
-
 
309
    ofn.lpstrFileTitle  = NULL;
-
 
310
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
-
 
311
    ofn.lpstrInitialDir = gettext(d->text);
-
 
312
    ofn.lpstrTitle      = "Select working directory";
-
 
313
    ofn.Flags           = OFN_HIDEREADONLY;
-
 
314
    ofn.nFileOffset     = 0;
-
 
315
    ofn.nFileExtension  = 0;
-
 
316
    ofn.lpstrDefExt     = "";
-
 
317
    ofn.lCustData       = 0L;
-
 
318
    ofn.lpfnHook        = NULL;
-
 
319
    ofn.lpTemplateName  = NULL;
-
 
320
 
-
 
321
    if(GetSaveFileName(&ofn) && strlen(strbuf)) {
-
 
322
	 p = strrchr(strbuf,'\\'); if(p) *p ='\0';
-
 
323
	 settext(d->text, strbuf);
-
 
324
    }
-
 
325
}
-
 
326
 
290
static void hit_key(window w, int key)
327
static void hit_key(window w, int key)
291
{
328
{
292
	button btn;
329
	button btn;
293
	char *name = NULL;
330
	char *name = NULL;
294
 
331
 
Line 372... Line 409...
372
        setbackground(win,LightGray);
409
        setbackground(win,LightGray);
373
	add_data(win);
410
	add_data(win);
374
	d = data(win);
411
	d = data(win);
375
	d->question = newlabel(question, rect(10,h,tw+4,h*2+2),
412
	d->question = newlabel(question, rect(10,h,tw+4,h*2+2),
376
			AlignLeft);
413
			AlignLeft);
-
 
414
	if (title == FINDDIR_TITLE) {
-
 
415
	    bw = strwidth(SystemFont, BROWSE_STRING) * 3/2;
-
 
416
	    d->text = newfield(default_str, rect(10,h*4,tw+4-bw,h*3/2));
-
 
417
	    newbutton(BROWSE_STRING, rect(20+tw-bw, h*4-2, bw, h+10), 
-
 
418
		      browse_button);
-
 
419
	}
377
	if (title == PASSWORD_TITLE)
420
	else if (title == PASSWORD_TITLE)
378
		d->text = newpassword(default_str, rect(10,h*4,tw+4,h*3/2));
421
		d->text = newpassword(default_str, rect(10,h*4,tw+4,h*3/2));
379
	else
422
	else
380
		d->text = newfield(default_str, rect(10,h*4,tw+4,h*3/2));
423
		d->text = newfield(default_str, rect(10,h*4,tw+4,h*3/2));
381
 
424
 
382
	middle = (tw+30)/2;
425
	middle = (tw+30)/2;
383
	bw = strwidth(SystemFont, CANCEL_STRING) * 3/2;
426
	bw = strwidth(SystemFont, CANCEL_STRING) * 3/2;
384
 
427
 
385
	d->yes = newbutton(OKAY_STRING,
428
	d->yes = newbutton(OKAY_STRING,
386
			rect(middle-bw-10,h*7,bw,h+6), hit_button);
429
			rect(middle-bw-10, h*7, bw, h+10), hit_button);
387
	setvalue(d->yes, YES);
430
	setvalue(d->yes, YES);
388
 
431
 
389
	d->cancel = newbutton(CANCEL_STRING,
432
	d->cancel = newbutton(CANCEL_STRING,
390
			rect(middle+10,h*7,bw,h+6), hit_button);
433
			rect(middle+10, h*7, bw, h+10), hit_button);
391
	setvalue(d->cancel, CANCEL);
434
	setvalue(d->cancel, CANCEL);
392
 
435
 
393
	setkeydown(win, hit_key);
436
	setkeydown(win, hit_key);
394
 
437
 
395
	return win;
438
	return win;
Line 405... Line 448...
405
	else {
448
	else {
406
		settext(data(win)->question, question);
449
		settext(data(win)->question, question);
407
		settext(data(win)->text, default_str);
450
		settext(data(win)->text, default_str);
408
	}
451
	}
409
	handle_message_dialog(win);
452
	handle_message_dialog(win);
-
 
453
	current_window = prev;
-
 
454
	return get_dialog_string(win);
-
 
455
}
-
 
456
 
-
 
457
char *askcdstring(char *question, char *default_str)
-
 
458
{
-
 
459
	static window win = NULL;
-
 
460
	window prev = current_window;
-
 
461
 
-
 
462
	if (! win)
-
 
463
		win = init_askstr_dialog(FINDDIR_TITLE, question, default_str);
-
 
464
	else {
-
 
465
		settext(data(win)->question, question);
-
 
466
		settext(data(win)->text, default_str);
-
 
467
	}
-
 
468
	handle_message_dialog(win);
410
	current_window = prev;
469
	current_window = prev;
411
	return get_dialog_string(win);
470
	return get_dialog_string(win);
412
}
471
}
413
 
472
 
414
char *askpassword(char *question, char *default_str)
473
char *askpassword(char *question, char *default_str)