1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +01:00

Add history to some dialog boxes

This patch adds history to some dialog boxes. To use it replace %a with
%A in menu file (like in "Run..." menu item). You can specify third
parameter to %A to use different histories for differen dialogs.

All history files is kept in ~/GNUstep/.AppInfo/WindowMaker/ and the number of
history lines controlled by DialogHistoryLines parameter (one for
all dialogs) defaults to 500 lines.

It also adds Tab completion.

Origin: ALT/Sisyphus Linux, Alexey Voinov <voins@altlinux.ru>
This commit is contained in:
Alexey Voinov
2007-08-14 15:15:37 +04:00
committed by Carlos R. Mafra
parent f8dd3dc49e
commit 05720d9707
7 changed files with 366 additions and 83 deletions

View File

@@ -32,6 +32,7 @@
#include <pwd.h>
#include <math.h>
#include <time.h>
#include <libintl.h>
#include <WINGs/WUtil.h>
#include <wraster.h>
@@ -563,93 +564,59 @@ static char *getselection(WScreen * scr)
return tmp;
}
static char *getuserinput(WScreen * scr, char *line, int *ptr)
static char*
parseuserinputpart(char *line, int *ptr, char *endchars)
{
char *ret;
char *title;
char *prompt;
int j, state;
int begin = 0;
#define BUFSIZE 512
char tbuffer[BUFSIZE], pbuffer[BUFSIZE];
int depth = 0, begin;
char *value = NULL;
begin = ++*ptr;
title = _("Program Arguments");
prompt = _("Enter command arguments:");
ret = NULL;
#define _STARTING 0
#define _TITLE 1
#define _PROMPT 2
#define _DONE 3
state = _STARTING;
j = 0;
for (; line[*ptr] != 0 && state != _DONE; (*ptr)++) {
switch (state) {
case _STARTING:
if (line[*ptr] == '(') {
state = _TITLE;
begin = *ptr + 1;
} else {
state = _DONE;
}
break;
case _TITLE:
if (j <= 0 && line[*ptr] == ',') {
j = 0;
if (*ptr > begin) {
strncpy(tbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE));
tbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0;
title = (char *)tbuffer;
}
begin = *ptr + 1;
state = _PROMPT;
} else if (j <= 0 && line[*ptr] == ')') {
if (*ptr > begin) {
strncpy(tbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE));
tbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0;
title = (char *)tbuffer;
}
state = _DONE;
} else if (line[*ptr] == '(') {
j++;
} else if (line[*ptr] == ')') {
j--;
}
break;
case _PROMPT:
if (line[*ptr] == ')' && j == 0) {
if (*ptr - begin > 1) {
strncpy(pbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE));
pbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0;
prompt = (char *)pbuffer;
}
state = _DONE;
} else if (line[*ptr] == '(')
j++;
else if (line[*ptr] == ')')
j--;
while(line[*ptr] != '\0') {
if(line[*ptr] == '(') {
++depth;
} else if(depth > 0 && line[*ptr] == ')') {
--depth;
} else if(depth == 0 && strchr(endchars, line[*ptr]) != NULL) {
value = wmalloc(*ptr - begin + 1);
strncpy(value, line + begin, *ptr - begin);
value[*ptr - begin] = '\0';
break;
}
++*ptr;
}
(*ptr)--;
#undef _STARTING
#undef _TITLE
#undef _PROMPT
#undef _DONE
if (!wInputDialog(scr, title, prompt, &ret))
return NULL;
else
return ret;
return value;
}
static char*
getuserinput(WScreen *scr, char *line, int *ptr, Bool advanced)
{
char *ret = NULL, *title = NULL, *prompt = NULL, *name = NULL;
int rv;
if(line[*ptr] == '(')
title = parseuserinputpart(line, ptr, ",)");
if(title != NULL && line[*ptr] == ',')
prompt = parseuserinputpart(line, ptr, ",)");
if(prompt != NULL && line[*ptr] == ',')
name = parseuserinputpart(line, ptr, ")");
if(advanced)
rv = wAdvancedInputDialog(scr,
title ? gettext(title):_("Program Arguments"),
prompt ? gettext(prompt):_("Enter command arguments:"),
name, &ret);
else
rv = wInputDialog(scr,
title ? gettext(title):_("Program Arguments"),
prompt ? gettext(prompt):_("Enter command arguments:"),
&ret);
if(title) wfree(title);
if(prompt) wfree(prompt);
if(name) wfree(name);
return rv ? ret : NULL;
}
#define S_NORMAL 0
@@ -765,8 +732,9 @@ char *ExpandOptions(WScreen * scr, char *cmdline)
break;
case 'a':
case 'A':
ptr++;
user_input = getuserinput(scr, cmdline, &ptr);
user_input = getuserinput(scr, cmdline, &ptr, cmdline[ptr-1] == 'A');
if (user_input) {
slen = strlen(user_input);
olen += slen;