mirror of git://git.sv.gnu.org/nano.git
convert ints to bools in the low-level input routines, and consolidate
the high-level input routines for the edit window git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1910 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
19420aac9d
commit
a0b5ba2f7f
18
ChangeLog
18
ChangeLog
|
@ -1,9 +1,27 @@
|
|||
CVS code -
|
||||
- General:
|
||||
- Convert more ints that hold only TRUE and FALSE values to
|
||||
bools. (DLR)
|
||||
- Consolidate the code for finding a shortcut in a shortcut
|
||||
list, the code for finding a toogle in a toggle list, and
|
||||
the code for doing both of those and interpreting mouse clicks
|
||||
in the edit window. Also move the code for do_mouse() to
|
||||
get_edit_mouse() and tweak it to properly handle cases where a
|
||||
shortcut isn't clicked. New functions get_shortcut(),
|
||||
get_toggle(), get_edit_input(), and get_edit_mouse(); changes
|
||||
to do_browser(), do_justify(), do_help(), and main(). (DLR)
|
||||
- rcfile.c:
|
||||
parse_rcfile()
|
||||
- Add missing brackets around an if statement block so that
|
||||
parsing the numeric argument after "tabsize" works properly
|
||||
again. (DLR, found by Mike Frysinger)
|
||||
- winio.c:
|
||||
get_mouseinput()
|
||||
- Consolidate two if statements to increase efficiency. (DLR)
|
||||
do_yesno()
|
||||
- Don't bother assigning the value of get_mouseinput() to
|
||||
anything. Since allow_shortcuts is FALSE, its return value
|
||||
will always be FALSE. (DLR)
|
||||
|
||||
GNU nano 1.3.4 - 2004.08.17
|
||||
- General:
|
||||
|
|
15
src/files.c
15
src/files.c
|
@ -2534,9 +2534,10 @@ char *do_browser(const char *inpath)
|
|||
struct stat st;
|
||||
char *foo, *retval = NULL;
|
||||
static char *path = NULL;
|
||||
int numents = 0, i = 0, j = 0, kbinput = ERR, meta_key, longest = 0;
|
||||
int abort = 0, col = 0, selected = 0, editline = 0, width = 0;
|
||||
int filecols = 0, lineno = 0;
|
||||
int numents = 0, i = 0, j = 0, longest = 0, abort = 0, col = 0;
|
||||
int selected = 0, editline = 0, width = 0, filecols = 0, lineno = 0;
|
||||
int kbinput = ERR;
|
||||
bool meta_key;
|
||||
char **filelist = (char **)NULL;
|
||||
#ifndef DISABLE_MOUSE
|
||||
MEVENT mevent;
|
||||
|
@ -2619,8 +2620,10 @@ char *do_browser(const char *inpath)
|
|||
selected = numents - 1;
|
||||
else if (selectedbackup == selected)
|
||||
ungetch('s'); /* Unget the 'select' key */
|
||||
} else /* Must be clicking a shortcut */
|
||||
do_mouse();
|
||||
} else { /* Must be clicking a shortcut */
|
||||
int mouse_x, mouse_y;
|
||||
get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
@ -2856,7 +2859,7 @@ char *do_browser(const char *inpath)
|
|||
width = filecols;
|
||||
}
|
||||
}
|
||||
wrefresh(edit);
|
||||
wrefresh(edit);
|
||||
} while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
|
||||
curs_set(1);
|
||||
blank_edit();
|
||||
|
|
209
src/nano.c
209
src/nano.c
|
@ -876,59 +876,6 @@ bool open_pipe(const char *command)
|
|||
}
|
||||
#endif /* !NANO_SMALL */
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
void do_mouse(void)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
if (!get_mouseinput(&mouse_x, &mouse_y, TRUE)) {
|
||||
/* Click in the edit window to move the cursor, but only when
|
||||
we're not in a subfunction. */
|
||||
if (wenclose(edit, mouse_y, mouse_x) && currshortcut == main_list) {
|
||||
bool sameline;
|
||||
/* Did they click on the line with the cursor? If they
|
||||
clicked on the cursor, we set the mark. */
|
||||
size_t xcur;
|
||||
/* The character they clicked on. */
|
||||
|
||||
/* Subtract out size of topwin. Perhaps we need a constant
|
||||
somewhere? */
|
||||
mouse_y -= 2;
|
||||
|
||||
sameline = (mouse_y == current_y);
|
||||
|
||||
/* Move to where the click occurred. */
|
||||
for (; current_y < mouse_y && current->next != NULL; current_y++)
|
||||
current = current->next;
|
||||
for (; current_y > mouse_y && current->prev != NULL; current_y--)
|
||||
current = current->prev;
|
||||
|
||||
xcur = actual_x(current->data, get_page_start(xplustabs()) +
|
||||
mouse_x);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Selecting where the cursor is toggles the mark, as does
|
||||
selecting beyond the line length with the cursor at the
|
||||
end of the line. */
|
||||
if (sameline && xcur == current_x) {
|
||||
if (ISSET(VIEW_MODE)) {
|
||||
print_view_warning();
|
||||
return;
|
||||
}
|
||||
do_mark();
|
||||
}
|
||||
#endif
|
||||
|
||||
current_x = xcur;
|
||||
placewewant = xplustabs();
|
||||
edit_refresh();
|
||||
}
|
||||
}
|
||||
/* FIXME: If we clicked on a location in the statusbar, the cursor
|
||||
should move to the location we clicked on. */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The user typed a character; add it to the edit buffer. */
|
||||
void do_char(char ch)
|
||||
{
|
||||
|
@ -2360,7 +2307,7 @@ void do_justify(bool full_justify)
|
|||
int mark_beginx_save = mark_beginx;
|
||||
#endif
|
||||
int kbinput;
|
||||
int meta_key;
|
||||
bool meta_key;
|
||||
|
||||
/* If we're justifying the entire file, start at the beginning. */
|
||||
if (full_justify)
|
||||
|
@ -2620,26 +2567,10 @@ void do_justify(bool full_justify)
|
|||
|
||||
/* Now get a keystroke and see if it's unjustify; if not, unget the
|
||||
* keystroke and return. */
|
||||
kbinput = get_kbinput(edit, &meta_key);
|
||||
kbinput = get_edit_input(&meta_key, FALSE);
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
/* If it was a mouse click, parse it with do_mouse() and it might
|
||||
* become the unjustify key. Else give it back to the input
|
||||
* stream. */
|
||||
if (kbinput == KEY_MOUSE) {
|
||||
do_mouse();
|
||||
kbinput = get_kbinput(edit, &meta_key);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (meta_key || (kbinput != NANO_UNJUSTIFY_KEY &&
|
||||
kbinput != NANO_UNJUSTIFY_FKEY)) {
|
||||
ungetch(kbinput);
|
||||
if (meta_key)
|
||||
ungetch(NANO_CONTROL_3);
|
||||
placewewant = 0;
|
||||
} else {
|
||||
/* Else restore the justify we just did (ungrateful user!). */
|
||||
if (!meta_key && kbinput == NANO_UNJUSTIFY_KEY) {
|
||||
/* Restore the justify we just did (ungrateful user!). */
|
||||
filestruct *cutbottom = get_cutbottom();
|
||||
|
||||
current = current_save;
|
||||
|
@ -2676,6 +2607,11 @@ void do_justify(bool full_justify)
|
|||
if (!ISSET(MODIFIED))
|
||||
titlebar(NULL);
|
||||
edit_refresh();
|
||||
} else {
|
||||
placewewant = 0;
|
||||
ungetch(kbinput);
|
||||
if (meta_key)
|
||||
ungetch(NANO_CONTROL_3);
|
||||
}
|
||||
|
||||
cutbuffer = cutbuffer_save;
|
||||
|
@ -3007,14 +2943,8 @@ int main(int argc, char **argv)
|
|||
#ifndef DISABLE_WRAPJUSTIFY
|
||||
bool fill_flag_used = FALSE; /* Was the fill option used? */
|
||||
#endif
|
||||
const shortcut *s;
|
||||
bool keyhandled = FALSE; /* Have we handled the keystroke yet? */
|
||||
int kbinput; /* Input from keyboard */
|
||||
int meta_key;
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
const toggle *t;
|
||||
#endif
|
||||
bool meta_key;
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
const struct option long_options[] = {
|
||||
{"help", 0, 0, 'h'},
|
||||
|
@ -3510,8 +3440,6 @@ int main(int argc, char **argv)
|
|||
edit_refresh();
|
||||
|
||||
while (TRUE) {
|
||||
keyhandled = FALSE;
|
||||
|
||||
reset_cursor();
|
||||
if (ISSET(CONSTUPDATE))
|
||||
do_cursorpos(TRUE);
|
||||
|
@ -3520,115 +3448,16 @@ int main(int argc, char **argv)
|
|||
currshortcut = main_list;
|
||||
#endif
|
||||
|
||||
kbinput = get_kbinput(edit, &meta_key);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput);
|
||||
#endif
|
||||
if (meta_key) {
|
||||
/* Check for the metaval and miscval defs... */
|
||||
for (s =
|
||||
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
||||
currshortcut
|
||||
#else
|
||||
main_list
|
||||
#endif
|
||||
; s != NULL && !keyhandled; s = s->next) {
|
||||
if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) ||
|
||||
(s->miscval != NANO_NO_KEY && kbinput == s->miscval)) {
|
||||
if (ISSET(VIEW_MODE) && !s->viewok)
|
||||
print_view_warning();
|
||||
else {
|
||||
if (s->func != do_cut_text)
|
||||
cutbuffer_reset();
|
||||
s->func();
|
||||
}
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
#ifndef NANO_SMALL
|
||||
if (!keyhandled) {
|
||||
/* And for toggle switches */
|
||||
for (t = toggles; t != NULL; t = t->next) {
|
||||
if (kbinput == t->val) {
|
||||
cutbuffer_reset();
|
||||
do_toggle(t);
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "I got Alt-%c! (%d)\n", kbinput, kbinput);
|
||||
#endif
|
||||
}
|
||||
kbinput = get_edit_input(&meta_key, TRUE);
|
||||
|
||||
/* Look through the main shortcut list to see if we've hit a
|
||||
shortcut key or function key */
|
||||
|
||||
if (!keyhandled) {
|
||||
for (s =
|
||||
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
||||
currshortcut
|
||||
#else
|
||||
main_list
|
||||
#endif
|
||||
; s != NULL && !keyhandled; s = s->next) {
|
||||
if ((s->ctrlval != NANO_NO_KEY && kbinput == s->ctrlval) ||
|
||||
(s->funcval != NANO_NO_KEY && kbinput == s->funcval)) {
|
||||
if (ISSET(VIEW_MODE) && !s->viewok)
|
||||
print_view_warning();
|
||||
else {
|
||||
if (s->func != do_cut_text)
|
||||
cutbuffer_reset();
|
||||
s->func();
|
||||
}
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!keyhandled)
|
||||
cutbuffer_reset();
|
||||
|
||||
/* Don't even think about changing this string */
|
||||
if (kbinput == NANO_XON_KEY)
|
||||
statusbar(_("XON ignored, mumble mumble."));
|
||||
if (kbinput == NANO_XOFF_KEY)
|
||||
statusbar(_("XOFF ignored, mumble mumble."));
|
||||
if (kbinput == NANO_XON_KEY || kbinput == NANO_XOFF_KEY)
|
||||
keyhandled = TRUE;
|
||||
|
||||
/* Catch ^Z by hand when triggered also */
|
||||
if (kbinput == NANO_SUSPEND_KEY) {
|
||||
if (ISSET(SUSPEND))
|
||||
do_suspend(0);
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
|
||||
/* Last gasp, stuff that's not in the main lists */
|
||||
if (!keyhandled) {
|
||||
switch (kbinput) {
|
||||
#ifndef DISABLE_MOUSE
|
||||
case KEY_MOUSE:
|
||||
do_mouse();
|
||||
break;
|
||||
#endif
|
||||
case NANO_CONTROL_3: /* Ctrl-[ (Esc), which should
|
||||
* have been handled before we
|
||||
* got here */
|
||||
case NANO_CONTROL_5: /* Ctrl-] */
|
||||
break;
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "I got %c (%d)!\n", kbinput, kbinput);
|
||||
#endif
|
||||
/* We no longer stop unhandled sequences so that
|
||||
people with odd character sets can type... */
|
||||
if (ISSET(VIEW_MODE))
|
||||
print_view_warning();
|
||||
else
|
||||
do_char((char)kbinput);
|
||||
}
|
||||
/* Last gasp, stuff that's not in the main lists. */
|
||||
if (kbinput != ERR && !is_cntrl_char(kbinput)) {
|
||||
/* Don't stop unhandled sequences, so that people with odd
|
||||
* character sets can type. */
|
||||
if (ISSET(VIEW_MODE))
|
||||
print_view_warning();
|
||||
else
|
||||
do_char(kbinput);
|
||||
}
|
||||
}
|
||||
assert(FALSE);
|
||||
|
|
32
src/proto.h
32
src/proto.h
|
@ -303,9 +303,6 @@ void nano_disabled_msg(void);
|
|||
RETSIGTYPE cancel_fork(int signal);
|
||||
bool open_pipe(const char *command);
|
||||
#endif
|
||||
#ifndef DISABLE_MOUSE
|
||||
void do_mouse(void);
|
||||
#endif
|
||||
void do_char(char ch);
|
||||
void do_verbatim_input(void);
|
||||
void do_backspace(void);
|
||||
|
@ -494,31 +491,40 @@ int check_wildcard_match(const char *text, const char *pattern);
|
|||
#ifndef NANO_SMALL
|
||||
void reset_kbinput(void);
|
||||
#endif
|
||||
int get_kbinput(WINDOW *win, int *meta_key);
|
||||
int get_translated_kbinput(int kbinput, int *es
|
||||
int get_kbinput(WINDOW *win, bool *meta_key);
|
||||
int get_translated_kbinput(int kbinput, bool *es
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
);
|
||||
int get_ascii_kbinput(int kbinput, size_t ascii_digits
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
);
|
||||
int get_control_kbinput(int kbinput);
|
||||
int get_escape_seq_kbinput(int *escape_seq, size_t es_len, int
|
||||
int get_escape_seq_kbinput(int *escape_seq, size_t es_len, bool
|
||||
*ignore_seq);
|
||||
int get_escape_seq_abcd(int kbinput);
|
||||
int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
|
||||
int allow_ascii);
|
||||
int get_untranslated_kbinput(int kbinput, size_t position, int
|
||||
bool allow_ascii);
|
||||
int get_untranslated_kbinput(int kbinput, size_t position, bool
|
||||
allow_ascii
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
);
|
||||
#ifndef DISABLE_MOUSE
|
||||
int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts);
|
||||
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
||||
#endif
|
||||
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||
*meta_key);
|
||||
#ifndef NANO_SMALL
|
||||
const toggle *get_toggle(int kbinput, bool meta_key);
|
||||
#endif
|
||||
int get_edit_input(bool *meta_key, bool allow_funcs);
|
||||
#ifndef DISABLE_MOUSE
|
||||
bool get_edit_mouse(void);
|
||||
#endif
|
||||
size_t xplustabs(void);
|
||||
size_t actual_x(const char *str, size_t xplus);
|
||||
|
@ -567,7 +573,7 @@ int statusq(int allowtabs, const shortcut *s, const char *def,
|
|||
int do_yesno(int all, const char *msg);
|
||||
void total_refresh(void);
|
||||
void display_main_list(void);
|
||||
void do_cursorpos(int constant);
|
||||
void do_cursorpos(bool constant);
|
||||
void do_cursorpos_void(void);
|
||||
#ifndef DISABLE_HELP
|
||||
int help_line_len(const char *ptr);
|
||||
|
|
275
src/winio.c
275
src/winio.c
|
@ -107,9 +107,10 @@ void reset_kbinput(void)
|
|||
* editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), the
|
||||
* function keypad (F1-F14), and the numeric keypad with NumLock off.
|
||||
* Assume nodelay(win) is FALSE. */
|
||||
int get_kbinput(WINDOW *win, int *meta_key)
|
||||
int get_kbinput(WINDOW *win, bool *meta_key)
|
||||
{
|
||||
int kbinput, es, retval = ERR;
|
||||
int kbinput, retval = ERR;
|
||||
bool es;
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
allow_pending_sigwinch(TRUE);
|
||||
|
@ -155,7 +156,7 @@ int get_kbinput(WINDOW *win, int *meta_key)
|
|||
* sequence into the corresponding key value, and save
|
||||
* that as the result. */
|
||||
if (es_len > 1) {
|
||||
int ignore_seq;
|
||||
bool ignore_seq;
|
||||
|
||||
*meta_key = FALSE;
|
||||
retval = get_escape_seq_kbinput(escape_seq, es_len,
|
||||
|
@ -174,7 +175,7 @@ int get_kbinput(WINDOW *win, int *meta_key)
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, *meta_key);
|
||||
fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, (int)*meta_key);
|
||||
#endif
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
|
@ -187,9 +188,9 @@ int get_kbinput(WINDOW *win, int *meta_key)
|
|||
/* Translate acceptable ASCII, extended keypad values, and escape
|
||||
* sequences into their corresponding key values. Set es to TRUE when
|
||||
* we get an escape sequence. Assume nodelay(win) is FALSE. */
|
||||
int get_translated_kbinput(int kbinput, int *es
|
||||
int get_translated_kbinput(int kbinput, bool *es
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
@ -416,7 +417,7 @@ int get_translated_kbinput(int kbinput, int *es
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, *es, escapes, (unsigned long)ascii_digits, retval);
|
||||
fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, (int)*es, escapes, (unsigned long)ascii_digits, retval);
|
||||
#endif
|
||||
|
||||
/* Return the result. */
|
||||
|
@ -427,7 +428,7 @@ int get_translated_kbinput(int kbinput, int *es
|
|||
* ASCII code from 000-255 into its corresponding ASCII character. */
|
||||
int get_ascii_kbinput(int kbinput, size_t ascii_digits
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
@ -564,7 +565,7 @@ int get_control_kbinput(int kbinput)
|
|||
* ERR and set ignore_seq to TRUE; if it's unrecognized, return ERR and
|
||||
* set ignore_seq to FALSE. Assume that Escape has already been read
|
||||
* in. */
|
||||
int get_escape_seq_kbinput(int *escape_seq, size_t es_len, int
|
||||
int get_escape_seq_kbinput(int *escape_seq, size_t es_len, bool
|
||||
*ignore_seq)
|
||||
{
|
||||
int retval = ERR;
|
||||
|
@ -1042,7 +1043,7 @@ int get_escape_seq_kbinput(int *escape_seq, size_t es_len, int
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "get_escape_seq_kbinput(): retval = %d, ignore_seq = %d\n", retval, *ignore_seq);
|
||||
fprintf(stderr, "get_escape_seq_kbinput(): retval = %d, ignore_seq = %d\n", retval, (int)*ignore_seq);
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
|
@ -1071,7 +1072,7 @@ int get_escape_seq_abcd(int kbinput)
|
|||
* verbatim. Store the string in v_kbinput and return the length
|
||||
* of the string in v_len. Assume nodelay(win) is FALSE. */
|
||||
int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
|
||||
int allow_ascii)
|
||||
bool allow_ascii)
|
||||
{
|
||||
int kbinput;
|
||||
size_t i = 0, v_newlen = 0;
|
||||
|
@ -1178,10 +1179,10 @@ int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
|
|||
return v_kbinput;
|
||||
}
|
||||
|
||||
int get_untranslated_kbinput(int kbinput, size_t position, int
|
||||
int get_untranslated_kbinput(int kbinput, size_t position, bool
|
||||
allow_ascii
|
||||
#ifndef NANO_SMALL
|
||||
, int reset
|
||||
, bool reset
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
@ -1246,7 +1247,7 @@ int get_untranslated_kbinput(int kbinput, size_t position, int
|
|||
* equivalent keystroke(s). Return FALSE if no keystrokes were
|
||||
* ungetch()ed, or TRUE if at least one was. Assume that KEY_MOUSE has
|
||||
* already been read in. */
|
||||
int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts)
|
||||
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
{
|
||||
MEVENT mevent;
|
||||
|
||||
|
@ -1261,15 +1262,12 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts)
|
|||
*mouse_x = mevent.x;
|
||||
*mouse_y = mevent.y;
|
||||
|
||||
/* If we're not allowing shortcuts' we're done now. */
|
||||
if (!allow_shortcuts)
|
||||
return FALSE;
|
||||
|
||||
/* Otherwise, if the current shortcut list is being displayed on the
|
||||
* last two lines of the screen and the mouse event took place
|
||||
* inside it, we need to figure out which shortcut was clicked and
|
||||
* ungetch() the equivalent keystroke(s) for it. */
|
||||
if (!ISSET(NO_HELP) && wenclose(bottomwin, *mouse_y, *mouse_x)) {
|
||||
/* If we're allowing shortcuts, the current shortcut list is being
|
||||
* displayed on the last two lines of the screen, and the mouse
|
||||
* event took place inside it, we need to figure out which shortcut
|
||||
* was clicked and ungetch() the equivalent keystroke(s) for it. */
|
||||
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
|
||||
*mouse_y, *mouse_x)) {
|
||||
int i, j;
|
||||
size_t currslen;
|
||||
/* The number of shortcuts in the current shortcut list. */
|
||||
|
@ -1298,10 +1296,10 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts)
|
|||
* list, or beyond the end of a shortcut on the right side of
|
||||
* the screen, don't do anything. */
|
||||
if (j < 0 || (*mouse_x / i) >= currslen)
|
||||
return 0;
|
||||
return FALSE;
|
||||
j = (*mouse_x / i) * 2 + j;
|
||||
if (j >= currslen)
|
||||
return 0;
|
||||
return FALSE;
|
||||
|
||||
/* Go through the shortcut list to determine which shortcut was
|
||||
* clicked. */
|
||||
|
@ -1323,8 +1321,207 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts)
|
|||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
|
||||
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||
*meta_key)
|
||||
{
|
||||
const shortcut *s = s_list;
|
||||
size_t slen = length_of_list(s_list);
|
||||
|
||||
/* Check for shortcuts. */
|
||||
for (; slen > 0; slen--) {
|
||||
/* We've found a shortcut if:
|
||||
*
|
||||
* 1. The key exists.
|
||||
* 2. The key is a control key in the shortcut list.
|
||||
* 3. The key is a function key in the shortcut list.
|
||||
* 4. meta_key is TRUE and the key is a meta sequence.
|
||||
* 5. meta_key is TRUE and the key is the other meta sequence in
|
||||
* the shortcut list. */
|
||||
if (kbinput != NANO_NO_KEY && ((*meta_key == FALSE &&
|
||||
((kbinput == s->ctrlval || kbinput == s->funcval))) ||
|
||||
(*meta_key == TRUE && (kbinput == s->metaval ||
|
||||
kbinput == s->miscval)))) {
|
||||
break;
|
||||
}
|
||||
|
||||
s = s->next;
|
||||
}
|
||||
|
||||
/* Translate the shortcut to either its control key or its meta key
|
||||
* equivalent. Assume that the shortcut has an equivalent control
|
||||
* key, meta key, or both. */
|
||||
if (slen > 0) {
|
||||
if (s->ctrlval != NANO_NO_KEY) {
|
||||
*meta_key = FALSE;
|
||||
kbinput = s->ctrlval;
|
||||
} else if (s->metaval != NANO_NO_KEY) {
|
||||
*meta_key = TRUE;
|
||||
kbinput = s->metaval;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
const toggle *get_toggle(int kbinput, bool meta_key)
|
||||
{
|
||||
const toggle *t = toggles;
|
||||
|
||||
/* Check for toggles. */
|
||||
for (; t != NULL; t = t->next) {
|
||||
/* We've found a toggle if meta_key is TRUE and the key is in
|
||||
* the meta toggle list. */
|
||||
if (meta_key && kbinput == t->val)
|
||||
break;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
#endif /* !NANO_SMALL */
|
||||
|
||||
int get_edit_input(bool *meta_key, bool allow_funcs)
|
||||
{
|
||||
bool keyhandled = FALSE;
|
||||
int kbinput, retval;
|
||||
const shortcut *s;
|
||||
#ifndef NANO_SMALL
|
||||
const toggle *t;
|
||||
#endif
|
||||
|
||||
kbinput = get_kbinput(edit, meta_key);
|
||||
|
||||
/* Universal shortcuts. These aren't in any shortcut lists, but we
|
||||
* should handle them anyway. */
|
||||
switch (kbinput) {
|
||||
case NANO_XON_KEY:
|
||||
statusbar(_("XON ignored, mumble mumble."));
|
||||
return ERR;
|
||||
case NANO_XOFF_KEY:
|
||||
statusbar(_("XOFF ignored, mumble mumble."));
|
||||
return ERR;
|
||||
#ifndef NANO_SMALL
|
||||
case NANO_SUSPEND_KEY:
|
||||
if (ISSET(SUSPEND))
|
||||
do_suspend(0);
|
||||
return ERR;
|
||||
#endif
|
||||
#ifndef DISABLE_MOUSE
|
||||
case KEY_MOUSE:
|
||||
if (get_edit_mouse()) {
|
||||
kbinput = get_kbinput(edit, meta_key);
|
||||
break;
|
||||
} else
|
||||
return ERR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Check for a shortcut in the main list. */
|
||||
s = get_shortcut(main_list, kbinput, meta_key);
|
||||
|
||||
if (s != NULL) {
|
||||
/* We got a shortcut. Run the shortcut's corresponding function
|
||||
* if it has one. */
|
||||
if (s->func != do_cut_text)
|
||||
cutbuffer_reset();
|
||||
if (s->func != NULL) {
|
||||
if (allow_funcs)
|
||||
s->func();
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
else {
|
||||
/* If we didn't get a shortcut, check for a toggle. */
|
||||
t = get_toggle(kbinput, *meta_key);
|
||||
|
||||
/* We got a toggle. Switch the value of the toggle's
|
||||
* corresponding flag. */
|
||||
if (t != NULL) {
|
||||
cutbuffer_reset();
|
||||
if (allow_funcs)
|
||||
do_toggle(t);
|
||||
keyhandled = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we got a shortcut with a corresponding function or a toggle,
|
||||
* reset meta_key and retval. If we didn't, keep the value of
|
||||
* meta_key and return the key we got in retval. */
|
||||
if (allow_funcs && keyhandled) {
|
||||
*meta_key = FALSE;
|
||||
retval = ERR;
|
||||
} else {
|
||||
cutbuffer_reset();
|
||||
retval = kbinput;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
bool get_edit_mouse(void)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
bool retval;
|
||||
|
||||
retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
|
||||
if (!retval) {
|
||||
/* We can click in the edit window to move the cursor. */
|
||||
if (wenclose(edit, mouse_y, mouse_x)) {
|
||||
bool sameline;
|
||||
/* Did they click on the line with the cursor? If they
|
||||
* clicked on the cursor, we set the mark. */
|
||||
size_t xcur;
|
||||
/* The character they clicked on. */
|
||||
|
||||
/* Subtract out the size of topwin. Perhaps we need a
|
||||
* constant somewhere? */
|
||||
mouse_y -= 2;
|
||||
|
||||
sameline = (mouse_y == current_y);
|
||||
|
||||
/* Move to where the click occurred. */
|
||||
for (; current_y < mouse_y && current->next != NULL; current_y++)
|
||||
current = current->next;
|
||||
for (; current_y > mouse_y && current->prev != NULL; current_y--)
|
||||
current = current->prev;
|
||||
|
||||
xcur = actual_x(current->data, get_page_start(xplustabs()) +
|
||||
mouse_x);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Clicking where the cursor is toggles the mark, as does
|
||||
* clicking beyond the line length with the cursor at the
|
||||
* end of the line. */
|
||||
if (sameline && xcur == current_x) {
|
||||
if (ISSET(VIEW_MODE)) {
|
||||
print_view_warning();
|
||||
return retval;
|
||||
}
|
||||
do_mark();
|
||||
}
|
||||
#endif
|
||||
|
||||
current_x = xcur;
|
||||
placewewant = xplustabs();
|
||||
edit_refresh();
|
||||
}
|
||||
}
|
||||
/* FIXME: If we clicked on a location in the statusbar, the cursor
|
||||
* should move to the location we clicked on. This functionality
|
||||
* should be in get_statusbar_mouse() when it's written. */
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
|
||||
/* Return the placewewant associated with current_x. That is, xplustabs
|
||||
* is the zero-based column position of the cursor. Value is no smaller
|
||||
* than current_x. */
|
||||
|
@ -1541,7 +1738,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
|||
)
|
||||
{
|
||||
int kbinput;
|
||||
int meta_key;
|
||||
bool meta_key;
|
||||
static int x = -1;
|
||||
/* the cursor position in 'answer' */
|
||||
int xend;
|
||||
|
@ -1635,7 +1832,10 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
|||
switch (kbinput) {
|
||||
#ifndef DISABLE_MOUSE
|
||||
case KEY_MOUSE:
|
||||
do_mouse();
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case NANO_HOME_KEY:
|
||||
|
@ -2872,7 +3072,7 @@ int do_yesno(int all, const char *msg)
|
|||
|
||||
do {
|
||||
int kbinput;
|
||||
int meta_key;
|
||||
bool meta_key;
|
||||
#ifndef DISABLE_MOUSE
|
||||
int mouse_x, mouse_y;
|
||||
#endif
|
||||
|
@ -2883,14 +3083,13 @@ int do_yesno(int all, const char *msg)
|
|||
ok = -1;
|
||||
#ifndef DISABLE_MOUSE
|
||||
/* Look ma! We get to duplicate lots of code from
|
||||
* do_mouse()!! */
|
||||
* get_edit_mouse()!! */
|
||||
else if (kbinput == KEY_MOUSE) {
|
||||
kbinput = get_mouseinput(&mouse_x, &mouse_y, FALSE);
|
||||
get_mouseinput(&mouse_x, &mouse_y, FALSE);
|
||||
|
||||
if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) &&
|
||||
wenclose(bottomwin, mouse_y, mouse_x) && mouse_x <
|
||||
(width * 2) && mouse_y >= editwinrows + 3) {
|
||||
|
||||
int x = mouse_x / width;
|
||||
/* Did we click in the first column of shortcuts, or
|
||||
* the second? */
|
||||
|
@ -2949,7 +3148,7 @@ void display_main_list(void)
|
|||
* If constant is TRUE and DISABLE_CURPOS is set, we unset it and update
|
||||
* old_i and old_totsize. That way, we leave the current statusbar
|
||||
* alone, but next time we will display. */
|
||||
void do_cursorpos(int constant)
|
||||
void do_cursorpos(bool constant)
|
||||
{
|
||||
const filestruct *fileptr;
|
||||
unsigned long i = 0;
|
||||
|
@ -3038,12 +3237,13 @@ void do_help(void)
|
|||
int line = 0;
|
||||
/* The line number in help_text of the first displayed help line.
|
||||
* This variable is zero-based. */
|
||||
int no_more = 0;
|
||||
bool no_more = FALSE;
|
||||
/* no_more means the end of the help text is shown, so don't go
|
||||
* down any more. */
|
||||
int kbinput = ERR, meta_key;
|
||||
int kbinput = ERR;
|
||||
bool meta_key;
|
||||
|
||||
int old_no_help = ISSET(NO_HELP);
|
||||
bool old_no_help = ISSET(NO_HELP);
|
||||
#ifndef DISABLE_MOUSE
|
||||
const shortcut *oldshortcut = currshortcut;
|
||||
/* We will set currshortcut to allow clicking on the help
|
||||
|
@ -3082,7 +3282,10 @@ void do_help(void)
|
|||
switch (kbinput) {
|
||||
#ifndef DISABLE_MOUSE
|
||||
case KEY_MOUSE:
|
||||
do_mouse();
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case NANO_NEXTPAGE_KEY:
|
||||
|
|
Loading…
Reference in New Issue