add the ability to move to the first and last file in the file browser

via Meta-\ (Meta-|) and Meta-/ (Meta-?)


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3479 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2006-05-06 15:07:26 +00:00
parent 5bb7727740
commit 0ec909cb98
4 changed files with 139 additions and 109 deletions

View File

@ -66,9 +66,14 @@ CVS code -
do_unindent_marked_void(); changes to shortcut_init(). (Chris
and DLR)
- Add the ability to move to the first and last line of the help
text via Meta-\ (Meta-|) and Meta-/ (Meta-?). Changes to
shortcut_init() and do_help(). (DLR)
text and the first and last file in the file browser via
Meta-\ (Meta-|) and Meta-/ (Meta-?). Changes to do_browser(),
shortcut_init(), and do_help(). (DLR)
- browser.c:
do_browser()
- Reference NANO_GOTODIR_(ALT|F)?KEY instead of
NANO_GOTOLINE_(ALT|F)?KEY for the "Go to Directory" shortcut.
(DLR)
parse_browser_input()
- Remove redundant key checks. (DLR)
- files.c:
@ -113,6 +118,10 @@ CVS code -
- Tweak the descriptions of some shortcut keys to make them more
uniform. (Benno Schulenberg, minor tweaks by DLR)
- Change the shortcut to find the matching bracket to ^]. (DLR)
- Shorten the "Where is Next" shortcut name to fit on the screen
after adding Meta-\ (Meta-|) and Meta-/ (Meta-?). (DLR)
- Lengthen the "UnCut Txt" shortcut name to "UnCut Text", as
there's enough room to display it unabbreviated. (DLR)
toggle_init()
- In the global toggle list, move the "Constant cursor position
display" toggle up to after the "Use more space for editing"

View File

@ -39,7 +39,8 @@ static int width = 0;
static int longest = 0;
/* The number of columns in the longest filename in the list. */
static size_t selected = 0;
/* The currently selected filename in the list. */
/* The currently selected filename in the list. This variable
* is zero-based. */
static bool search_last_file = FALSE;
/* Have we gone past the last file while searching? */
@ -149,26 +150,27 @@ char *do_browser(char *path, DIR *dir)
}
break;
#endif /* !DISABLE_MOUSE */
case NANO_HELP_KEY:
#ifndef DISABLE_HELP
do_browser_help();
curs_set(0);
#else
nano_disabled_msg();
#endif
case NANO_PREVLINE_KEY:
if (selected >= width)
selected -= width;
break;
case NANO_BACK_KEY:
if (selected > 0)
selected--;
/* Search for a filename. */
case NANO_WHEREIS_KEY:
curs_set(1);
do_filesearch();
curs_set(0);
break;
case NANO_NEXTLINE_KEY:
if (selected + width <= filelist_len - 1)
selected += width;
break;
case NANO_FORWARD_KEY:
if (selected < filelist_len - 1)
selected++;
/* Search for another filename. */
case NANO_WHEREIS_NEXT_KEY:
do_fileresearch();
break;
case NANO_PREVPAGE_KEY:
@ -187,86 +189,18 @@ char *do_browser(char *path, DIR *dir)
selected = filelist_len - 1;
break;
case NANO_HELP_KEY:
#ifndef DISABLE_HELP
do_browser_help();
curs_set(0);
#else
nano_disabled_msg();
#endif
case NANO_FIRSTFILE_ALTKEY:
if (meta_key)
selected = 0;
break;
case NANO_ENTER_KEY:
/* You can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) {
statusbar(_("Can't move up a directory"));
beep();
break;
}
#ifndef DISABLE_OPERATINGDIR
/* Note: the selected file can be outside the operating
* directory if it's ".." or if it's a symlink to a
* directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
statusbar(
_("Can't go outside of %s in restricted mode"),
operating_dir);
beep();
break;
}
#endif
if (stat(filelist[selected], &st) == -1) {
/* We can't open this file for some reason.
* Complain. */
statusbar(_("Error reading %s: %s"),
filelist[selected], strerror(errno));
beep();
break;
}
if (!S_ISDIR(st.st_mode)) {
retval = mallocstrcpy(retval, filelist[selected]);
abort = TRUE;
break;
}
dir = opendir(filelist[selected]);
if (dir == NULL) {
/* We can't open this dir for some reason.
* Complain. */
statusbar(_("Error reading %s: %s"),
filelist[selected], strerror(errno));
beep();
break;
}
path = mallocstrcpy(path, filelist[selected]);
/* Start over again with the new path value. */
free_chararray(filelist, filelist_len);
goto change_browser_directory;
/* Redraw the screen. */
case NANO_REFRESH_KEY:
total_redraw();
break;
/* Search for a filename. */
case NANO_WHEREIS_KEY:
curs_set(1);
do_filesearch();
curs_set(0);
break;
/* Search for another filename. */
case NANO_WHEREIS_NEXT_KEY:
do_fileresearch();
case NANO_LASTFILE_ALTKEY:
if (meta_key)
selected = filelist_len - 1;
break;
/* Go to a specific directory. */
case NANO_GOTOLINE_KEY:
case NANO_GOTODIR_KEY:
curs_set(1);
i = do_prompt(TRUE,
@ -340,6 +274,83 @@ char *do_browser(char *path, DIR *dir)
free_chararray(filelist, filelist_len);
goto change_browser_directory;
case NANO_PREVLINE_KEY:
if (selected >= width)
selected -= width;
break;
case NANO_BACK_KEY:
if (selected > 0)
selected--;
break;
case NANO_NEXTLINE_KEY:
if (selected + width <= filelist_len - 1)
selected += width;
break;
case NANO_FORWARD_KEY:
if (selected < filelist_len - 1)
selected++;
break;
case NANO_ENTER_KEY:
/* You can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) {
statusbar(_("Can't move up a directory"));
beep();
break;
}
#ifndef DISABLE_OPERATINGDIR
/* Note: the selected file can be outside the operating
* directory if it's ".." or if it's a symlink to a
* directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
statusbar(
_("Can't go outside of %s in restricted mode"),
operating_dir);
beep();
break;
}
#endif
if (stat(filelist[selected], &st) == -1) {
/* We can't open this file for some reason.
* Complain. */
statusbar(_("Error reading %s: %s"),
filelist[selected], strerror(errno));
beep();
break;
}
if (!S_ISDIR(st.st_mode)) {
retval = mallocstrcpy(retval, filelist[selected]);
abort = TRUE;
break;
}
dir = opendir(filelist[selected]);
if (dir == NULL) {
/* We can't open this dir for some reason.
* Complain. */
statusbar(_("Error reading %s: %s"),
filelist[selected], strerror(errno));
beep();
break;
}
path = mallocstrcpy(path, filelist[selected]);
/* Start over again with the new path value. */
free_chararray(filelist, filelist_len);
goto change_browser_directory;
/* Redraw the screen. */
case NANO_REFRESH_KEY:
total_redraw();
break;
/* Abort the browser. */
case NANO_EXIT_KEY:
abort = TRUE;
@ -512,7 +523,7 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
break;
case 'G':
case 'g':
*kbinput = NANO_GOTOLINE_KEY;
*kbinput = NANO_GOTODIR_KEY;
break;
case 'S':
case 's':

View File

@ -267,7 +267,7 @@ void shortcut_init(bool unjustify)
/* TRANSLATORS: Try to keep this and previous strings at most 10 characters. */
const char *replace_msg = N_("Replace");
#ifndef NANO_TINY
/* TRANSLATORS: Try to keep this at most 16 characters. */
/* TRANSLATORS: Try to keep this at most 12 characters. */
const char *whereis_next_msg = N_("WhereIs Next");
#endif
/* TRANSLATORS: Try to keep this and following strings at most 10 characters. */
@ -525,7 +525,7 @@ void shortcut_init(bool unjustify)
NANO_NO_KEY, NOVIEW, NULL);
else
/* TRANSLATORS: Try to keep this at most 10 characters. */
sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Txt"),
sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Text"),
IFHELP(nano_uncut_msg, FALSE), NANO_NO_KEY,
NANO_UNCUT_FKEY, NANO_NO_KEY, NOVIEW, do_uncut_text);
@ -556,7 +556,6 @@ void shortcut_init(bool unjustify)
NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace);
#ifndef NANO_TINY
/* TRANSLATORS: Try to keep this at most 16 characters. */
sc_init_one(&main_list, NANO_MARK_KEY, N_("Mark Text"),
IFHELP(nano_mark_msg, FALSE), NANO_MARK_ALTKEY, NANO_MARK_FKEY,
NANO_NO_KEY, VIEW, do_mark);
@ -1106,14 +1105,6 @@ void shortcut_init(bool unjustify)
IFHELP(nano_exitbrowser_msg, FALSE), NANO_NO_KEY,
NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
IFHELP(nano_prevpage_msg, FALSE), NANO_NO_KEY,
NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
IFHELP(nano_nextpage_msg, FALSE), NANO_NO_KEY,
NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_WHEREIS_KEY, whereis_msg,
IFHELP(nano_whereis_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
NANO_NO_KEY, VIEW, NULL);
@ -1122,10 +1113,26 @@ void shortcut_init(bool unjustify)
IFHELP(nano_whereis_next_msg, FALSE), NANO_WHEREIS_NEXT_KEY,
NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
IFHELP(nano_prevpage_msg, FALSE), NANO_NO_KEY,
NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
IFHELP(nano_nextpage_msg, FALSE), NANO_NO_KEY,
NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_NO_KEY, first_file_msg,
IFHELP(nano_firstfile_msg, FALSE), NANO_FIRSTFILE_ALTKEY,
NANO_NO_KEY, NANO_FIRSTFILE_ALTKEY2, VIEW, NULL);
sc_init_one(&browser_list, NANO_NO_KEY, last_file_msg,
IFHELP(nano_lastfile_msg, FALSE), NANO_LASTFILE_ALTKEY,
NANO_NO_KEY, NANO_LASTFILE_ALTKEY2, VIEW, NULL);
/* TRANSLATORS: Try to keep this at most 22 characters. */
sc_init_one(&browser_list, NANO_GOTOLINE_KEY, N_("Go To Dir"),
IFHELP(nano_gotodir_msg, FALSE), NANO_GOTOLINE_ALTKEY,
NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
sc_init_one(&browser_list, NANO_GOTODIR_KEY, N_("Go To Dir"),
IFHELP(nano_gotodir_msg, FALSE), NANO_GOTODIR_ALTKEY,
NANO_GOTODIR_FKEY, NANO_NO_KEY, VIEW, NULL);
free_shortcutage(&whereis_file_list);

View File

@ -482,6 +482,9 @@ typedef struct rcoption {
#define NANO_GOTOLINE_KEY NANO_CONTROL_7
#define NANO_GOTOLINE_FKEY KEY_F(13)
#define NANO_GOTOLINE_ALTKEY NANO_ALT_G
#define NANO_GOTODIR_KEY NANO_CONTROL_7
#define NANO_GOTODIR_FKEY KEY_F(13)
#define NANO_GOTODIR_ALTKEY NANO_ALT_G
#define NANO_TOGOTOLINE_KEY NANO_CONTROL_T
#define NANO_HELP_KEY NANO_CONTROL_G
#define NANO_HELP_FKEY KEY_F(1)