Commit 6b58acd3 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

More mouse integration, esp with the shortcut lists

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@593 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 214 additions and 136 deletions
+214 -136
Cvs code -
- General
- New global variables currshortcut and currslen to support using
the mouse with the shortcuts. FIXME - Does not support the
do_yesno function yet as that will have to be done by hand.
nano 1.1 tree forked here 04/07/2001
......
......@@ -258,6 +258,8 @@ int do_insertfile(void)
char *realname = NULL;
wrap_reset();
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
_("File to insert [from ./] "));
if (i != -1) {
......@@ -276,6 +278,8 @@ int do_insertfile(void)
if (i == NANO_TOFILES_KEY) {
char *tmp = do_browse_from(realname);
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
#ifdef DISABLE_TABCOMP
realname = NULL;
......@@ -503,6 +507,8 @@ int do_writeout(char *path, int exiting)
static int did_cred = 0;
#endif
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
answer = mallocstrcpy(answer, path);
if ((exiting) && (ISSET(TEMP_OPT))) {
......@@ -529,6 +535,8 @@ int do_writeout(char *path, int exiting)
if (i == NANO_TOFILES_KEY) {
char *tmp = do_browse_from(answer);
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
if (tmp != NULL)
answer = mallocstrcpy(answer, tmp);
......@@ -1131,6 +1139,8 @@ char *do_browser(char *inpath)
int lineno = 0, kb;
char **filelist = (char **) NULL;
currshortcut = browser_list;
currslen = BROWSER_LIST_LEN;
/* If path isn't the same as inpath, we are being passed a new
dir as an arg. We free it here so it will be copied from
inpath below */
......@@ -1172,6 +1182,14 @@ char *do_browser(char *inpath)
lineno = selected / width;
switch (kbinput) {
#ifndef NANO_SMALL
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE:
do_mouse();
break;
#endif
#endif
case KEY_UP:
case 'u':
if (selected - width >= 0)
......
......@@ -82,6 +82,9 @@ shortcut spell_list[SPELL_LIST_LEN];
shortcut browser_list[BROWSER_LIST_LEN];
#endif
shortcut *currshortcut = main_list; /* Current shortcut list we're using */
int currslen = MAIN_VISIBLE; /* Length of current shortcut list */
#ifndef NANO_SMALL
toggle toggles[TOGGLE_LEN];
#endif
......
......@@ -425,7 +425,8 @@ void usage(void)
#endif
#endif
printf(_(" -p Emulate Pico as closely as possible\n"));
printf(_(" -r [#cols] Set fill cols to (wrap lines at) #cols\n"));
printf(_
(" -r [#cols] Set fill cols to (wrap lines at) #cols\n"));
#ifndef DISABLE_SPELLER
printf(_(" -s [prog] Enable alternate speller\n"));
#endif
......@@ -456,21 +457,21 @@ void version(void)
#ifdef NANO_SMALL
printf(" --enable-tiny");
#else
#ifdef DISABLE_BROWSER
#ifdef DISABLE_BROWSER
printf(" --disable-browser");
#endif
#ifdef DISABLE_TABCOMP
#endif
#ifdef DISABLE_TABCOMP
printf(" --disable-tabcomp");
#endif
#ifdef DISABLE_JUSTIFY
#endif
#ifdef DISABLE_JUSTIFY
printf(" --disable-justify");
#endif
#ifdef DISABLE_SPELLER
#endif
#ifdef DISABLE_SPELLER
printf(" --disable-speller");
#endif
#ifdef DISABLE_HELP
#endif
#ifdef DISABLE_HELP
printf(" --disable-help");
#endif
#endif
#endif
#ifdef DISABLE_WRAPPING
......@@ -500,7 +501,8 @@ filestruct *make_new_node(filestruct * prevnode)
}
/* Splice a node into an existing filestruct */
void splice_node(filestruct * begin, filestruct * newnode, filestruct * end)
void splice_node(filestruct * begin, filestruct * newnode,
filestruct * end)
{
newnode->next = end;
newnode->prev = begin;
......@@ -922,7 +924,8 @@ void do_wrap(filestruct * inptr, char input_char)
int old_x = current_x, old_y = current_y;
/* Plus one for the space which concatenates the two lines together plus 1 for \0. */
char *p = nmalloc((strlen(temp->data) + strlen(inptr->next->data) + 2)
char *p =
nmalloc((strlen(temp->data) + strlen(inptr->next->data) + 2)
* sizeof(char));
if (ISSET(AUTOINDENT)) {
......@@ -1221,8 +1224,7 @@ int do_int_spell_fix(char *word)
edit_update(fileage, TOP);
/* make sure word is still mis-spelt (i.e. when multi-errors) */
if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL)
{
if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL) {
do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */
......@@ -1274,7 +1276,7 @@ int do_int_speller(char *tempfile_name)
/* A new process to run spell in */
if ( (pid_spell = fork()) == 0) {
if ((pid_spell = fork()) == 0) {
/* Child continues, (i.e. future spell process) */
......@@ -1282,7 +1284,7 @@ int do_int_speller(char *tempfile_name)
/* replace the standard in with the tempfile */
if ( (tempfile_fd = open(tempfile_name, O_RDONLY)) == -1) {
if ((tempfile_fd = open(tempfile_name, O_RDONLY)) == -1) {
close(in_fd[1]);
exit(1);
......@@ -1328,17 +1330,17 @@ int do_int_speller(char *tempfile_name)
/* Get system pipe buffer size */
if ( (pipe_buff_size = fpathconf(in_fd[0], _PC_PIPE_BUF)) < 1) {
if ((pipe_buff_size = fpathconf(in_fd[0], _PC_PIPE_BUF)) < 1) {
close(in_fd[0]);
return FALSE;
}
read_buff = nmalloc( pipe_buff_size + 1 );
read_buff = nmalloc(pipe_buff_size + 1);
/* Process the returned spelling errors */
while ( (bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) {
while ((bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) {
read_buff[bytesread] = (char) NULL;
read_buff_word = read_buff_ptr = read_buff;
......@@ -1377,8 +1379,7 @@ int do_int_speller(char *tempfile_name)
if (WIFEXITED(spell_status)) {
if (WEXITSTATUS(spell_status) != 0)
return FALSE;
}
else
} else
return FALSE;
return TRUE;
......@@ -1410,7 +1411,7 @@ int do_alt_speller(char *file_name)
spellargs[arglen - 2] = file_name;
/* Start a new process for the alternate speller */
if ( (pid_spell = fork()) == 0) {
if ((pid_spell = fork()) == 0) {
/* Start alternate spell program, we are using the PATH here!?!? */
execvp(spellargs[0], spellargs);
......@@ -1431,8 +1432,7 @@ int do_alt_speller(char *file_name)
if (WIFEXITED(alt_spell_status)) {
if (WEXITSTATUS(alt_spell_status) != 0)
return FALSE;
}
else
} else
return FALSE;
refresh();
......@@ -1495,8 +1495,7 @@ int do_exit(void)
if (ISSET(TEMP_OPT)) {
i = 1;
} else {
i =
do_yesno(0, 0,
i = do_yesno(0, 0,
_
("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "));
}
......@@ -1527,8 +1526,12 @@ void do_mouse(void)
if (getmouse(&mevent) == ERR)
return;
/* If mouse not in edit window, return (add help selection later). */
if (!wenclose(edit, mevent.y, mevent.x))
/* If mouse not in edit or bottom window, return */
if (wenclose(edit, mevent.y, mevent.x)) {
/* Don't let people screw with the marker when they're in a
subfunction */
if (currshortcut != main_list)
return;
/* Subtract out size of topwin. Perhaps we need a constant somewhere? */
......@@ -1586,7 +1589,24 @@ void do_mouse(void)
update_cursor();
edit_refresh();
} else if (wenclose(bottomwin, mevent.y, mevent.x) && !ISSET(NO_HELP)) {
int k = COLS / 6, val = 0;
/* Determine what shortcut list was clicked */
mevent.y -= (editwinrows + 3);
if (mevent.y < 0) /* They clicked on the statusbar */
return;
/* Don't select stuff beyond list length */
if (mevent.x / k >= currslen)
return;
val = currshortcut[(mevent.x / k) * 2 + mevent.y].val;
/* And ungetch that value */
ungetch(val);
}
}
#endif
#endif
......@@ -1750,6 +1770,7 @@ void mouse_init(void)
#ifdef NCURSES_MOUSE_VERSION
if (ISSET(USE_MOUSE)) {
keypad_on(edit, 1);
keypad_on(bottomwin, 1);
mousemask(BUTTON1_RELEASED, NULL);
mouseinterval(50);
......@@ -2141,7 +2162,8 @@ void print_numlock_warning(void)
{
static int didmsg = 0;
if (!didmsg) {
statusbar(_("NumLock glitch detected. Keypad will malfunction with NumLock off"));
statusbar(_
("NumLock glitch detected. Keypad will malfunction with NumLock off"));
didmsg = 1;
}
}
......@@ -2151,16 +2173,15 @@ void print_numlock_warning(void)
Esc-O-[A-D] or Esc-[-[A-D]. */
int ABCD(int input)
{
switch(input)
{
switch (input) {
case 'A':
return(KEY_UP);
return (KEY_UP);
case 'B':
return(KEY_DOWN);
return (KEY_DOWN);
case 'C':
return(KEY_RIGHT);
return (KEY_RIGHT);
case 'D':
return(KEY_LEFT);
return (KEY_LEFT);
default:
return 0;
}
......@@ -2223,7 +2244,8 @@ int main(int argc, char *argv[])
while ((optchr = getopt_long(argc, argv, "?T:RVbcefhiklmpr:s:tvwxz",
long_options, &option_index)) != EOF) {
#else
while ((optchr = getopt(argc, argv, "h?T:RVbcefiklmpr:s:tvwxz")) != EOF) {
while ((optchr =
getopt(argc, argv, "h?T:RVbcefiklmpr:s:tvwxz")) != EOF) {
#endif
switch (optchr) {
......@@ -2394,7 +2416,7 @@ int main(int argc, char *argv[])
edit_update(fileage, CENTER);
/* return here after a sigwinch */
sigsetjmp(jmpbuf,1);
sigsetjmp(jmpbuf, 1);
/* Fix clobber-age */
kbinput = 0;
......@@ -2406,6 +2428,9 @@ int main(int argc, char *argv[])
while (1) {
currshortcut = main_list;
currslen = MAIN_VISIBLE;
#ifndef _POSIX_VDISABLE
/* We're going to have to do it the old way, i.e. on cygwin */
raw();
......
......@@ -36,6 +36,7 @@ extern int mark_beginx, samelinewrap;
extern int totsize, temp_opt;
extern int fill, flags,tabsize;
extern int search_last_line;
extern int currslen;
extern WINDOW *edit, *topwin, *bottomwin;
extern char *filename;
......@@ -54,6 +55,7 @@ extern shortcut spell_list[SPELL_LIST_LEN], replace_list_2[REPLACE_LIST_LEN];
#ifndef DISABLE_BROWSER
extern shortcut browser_list[BROWSER_LIST_LEN];
#endif
extern shortcut *currshortcut;
#ifdef HAVE_REGEX_H
extern int use_regexp, regexp_compiled;
......@@ -140,6 +142,7 @@ void add_to_cutbuffer(filestruct * inptr);
void do_replace_highlight(int highlight_flag, char *word);
void nano_disabled_msg(void);
void window_init(void);
void do_mouse(void);
#ifdef NANO_EXTRA
void do_credits(void);
#endif
......
......@@ -262,6 +262,8 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
x_left = strlen(buf);
x = strlen(def) + x_left;
currshortcut = s;
currslen = slen;
/* Get the input! */
if (strlen(def) > 0)
strcpy(inputbuf, def);
......@@ -273,6 +275,10 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
while ((kbinput = wgetch(bottomwin)) != 13) {
for (j = 0; j <= slen - 1; j++) {
#ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif
if (kbinput == s[j].val) {
/* We shouldn't discard the answer it gave, just because
......@@ -288,6 +294,7 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
tabbed = 0;
switch (kbinput) {
/* Stuff we want to equate with <enter>, ASCII 13 */
case 343:
ungetch(13); /* Enter on iris-ansi $TERM, sometimes */
......@@ -299,8 +306,15 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
case 543: /* Right ctrl again */
case 544:
case 545: /* Right alt again */
break;
#endif
#ifndef NANO_SMALL
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE:
do_mouse();
break;
#endif
#endif
case KEY_HOME:
x = x_left;
nanoget_repaint(buf, inputbuf, x);
......@@ -1217,14 +1231,17 @@ int do_help(void)
{
#ifndef DISABLE_HELP
char *ptr = help_text, *end;
int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp;
int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
int no_help_flag = 0;
blank_edit();
curs_set(0);
blank_statusbar();
currshortcut = help_list;
currslen = HELP_LIST_LEN;
kp = keypad_on(edit, 1);
kp2 = keypad_on(bottomwin, 1);
if (ISSET(NO_HELP)) {
......@@ -1241,6 +1258,13 @@ int do_help(void)
do {
ptr = help_text;
switch (kbinput) {
#ifndef NANO_SMALL
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE:
do_mouse();
break;
#endif
#endif
case NANO_NEXTPAGE_KEY:
case NANO_NEXTPAGE_FKEY:
case KEY_NPAGE:
......@@ -1320,6 +1344,7 @@ int do_help(void)
curs_set(1);
edit_refresh();
kp = keypad_on(edit, kp);
kp2 = keypad_on(bottomwin, kp2);
#elif defined(DISABLE_HELP)
nano_disabled_msg();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment