"Goto Directory" added and minor fixes in the browser

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@597 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Rocco Corsi 2001-04-14 06:50:24 +00:00
parent ea066c8413
commit 12f294c651
6 changed files with 80 additions and 12 deletions

View File

@ -7,9 +7,23 @@ Cvs code -
to its own flag, --disable mouse. The --tiny option defines
this automatically, but now just mouse support can be disabled
if desired.
- File Browser supports the "Goto Directory"
- configure.in:
- New option, --enable-nanorc which currently does nothing but
sets a define. Will do more later...
- files.c:
do_browser()
- Minor fixes to the processing of SELECT function (Rocco)
- Added the "Goto Directory" code (Rocco)
- global.c:
- Updated some of the lists for the "Goto Directory" code (Rocco)
- nano.c:
main()
- Code to silently process "-g" and "-j" (Rocco)
- nano.h:
- Updated the BROWSER_LIST_LEN for the "Goto Directory" code (Rocco)
- proto.h:
- New shortcut list added: gotodir_list (Rocco).
nano 1.1 tree forked here 04/07/2001

56
files.c
View File

@ -1170,8 +1170,10 @@ char *do_browser(char *inpath)
/* Loop invariant: Microsoft sucks. */
do {
blank_edit();
blank_statusbar();
DIR *test_dir;
blank_statusbar_refresh();
editline = 0;
col = 0;
@ -1250,20 +1252,23 @@ char *do_browser(char *inpath)
case 'S':
/* You can't cd up from / */
if (!strcmp(filelist[selected], "/..") && !strcmp(path, "/"))
if (!strcmp(filelist[selected], "/..") && !strcmp(path, "/")) {
statusbar(_("Can't move up a directory"));
else
path = mallocstrcpy(path, filelist[selected]);
break;
}
path = mallocstrcpy(path, filelist[selected]);
st = filestat(path);
if (S_ISDIR(st.st_mode)) {
if (opendir(path) == NULL) {
if ((test_dir = opendir(path)) == NULL) {
/* We can't open this dir for some reason. Complain */
statusbar(_("Can't open \"%s\": %s"), path, strerror(errno));
striponedir(path);
striponedir(path);
align(&path);
break;
}
closedir(test_dir);
if (!strcmp("..", tail(path))) {
/* They want to go up a level, so strip off .. and the
@ -1280,6 +1285,41 @@ char *do_browser(char *inpath)
abort = 1;
}
break;
/* Goto a specific directory */
case 'g': /* Pico compatibility */
case 'G':
case NANO_GOTO_KEY:
curs_set(1);
j = statusq(0, gotodir_list, GOTODIR_LIST_LEN, "", _("Goto Directory"));
bottombars(browser_list, BROWSER_LIST_LEN);
curs_set(0);
if (j < 0) {
statusbar(_("Goto Cancelled"));
break;
}
if (answer[0] != '/') {
char *saveanswer = NULL;
saveanswer = mallocstrcpy(saveanswer, answer);
answer = realloc(answer, strlen(path) + strlen(saveanswer) + 2);
sprintf(answer, "%s/%s", path, saveanswer);
free(saveanswer);
}
if ((test_dir = opendir(answer)) == NULL) {
/* We can't open this dir for some reason. Complain */
statusbar(_("Can't open \"%s\": %s"), answer, strerror(errno));
break;
}
closedir(test_dir);
/* Start over again with the new path value */
path = mallocstrcpy(path, answer);
return do_browser(path);
/* Stuff we want to abort the browser */
case 'q':
case 'Q':
@ -1292,6 +1332,8 @@ char *do_browser(char *inpath)
if (abort)
break;
blank_edit();
if (width)
i = width * editwinrows * ((selected / width) / editwinrows);
else

View File

@ -75,6 +75,7 @@ shortcut whereis_list[WHEREIS_LIST_LEN];
shortcut replace_list[REPLACE_LIST_LEN];
shortcut replace_list_2[REPLACE_LIST_LEN]; /* 2nd half of replace dialog */
shortcut goto_list[GOTO_LIST_LEN];
shortcut gotodir_list[GOTODIR_LIST_LEN];
shortcut writefile_list[WRITEFILE_LIST_LEN];
shortcut help_list[HELP_LIST_LEN];
shortcut spell_list[SPELL_LIST_LEN];
@ -184,6 +185,7 @@ void shortcut_init(int unjustify)
#ifndef NANO_SMALL
char *nano_tofiles_msg = "";
char *nano_gotodir_msg = "";
nano_help_msg = _("Invoke the help menu");
nano_writeout_msg = _("Write the current file to disk");
@ -218,6 +220,7 @@ void shortcut_init(int unjustify)
nano_case_msg =
_("Make the current search or replace case (in)sensitive");
nano_tofiles_msg = _("Go to file browser");
nano_gotodir_msg = _("Goto Directory");
nano_cancel_msg = _("Cancel the current function");
#endif
@ -429,9 +432,15 @@ void shortcut_init(int unjustify)
nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, 0);
sc_init_one(&browser_list[2], NANO_EXIT_KEY, _("Exit"),
sc_init_one(&browser_list[2], NANO_GOTO_KEY, _("Goto"),
nano_gotodir_msg, 0, NANO_GOTO_FKEY, 0, VIEW, 0);
sc_init_one(&browser_list[3], NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, 0);
sc_init_one(&gotodir_list[0], NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#endif

6
nano.c
View File

@ -2244,11 +2244,11 @@ int main(int argc, char *argv[])
#endif
#ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "?T:RVbcefhiklmpr:s:tvwxz",
while ((optchr = getopt_long(argc, argv, "?T:RVbcefghijklmpr:s:tvwxz",
long_options, &option_index)) != EOF) {
#else
while ((optchr =
getopt(argc, argv, "h?T:RVbcefiklmpr:s:tvwxz")) != EOF) {
getopt(argc, argv, "h?T:RVbcefgijklmpr:s:tvwxz")) != EOF) {
#endif
switch (optchr) {
@ -2270,6 +2270,8 @@ int main(int argc, char *argv[])
case 'b':
case 'e':
case 'f':
case 'g':
case 'j':
/* Pico compatibility flags */
break;
case 'c':

3
nano.h
View File

@ -244,12 +244,13 @@ know what you're doing */
#define REPLACE_LIST_LEN 6
#define REPLACE_LIST_2_LEN 3
#define GOTO_LIST_LEN 3
#define GOTODIR_LIST_LEN 1
#define HELP_LIST_LEN 3
#define SPELL_LIST_LEN 1
#ifndef DISABLE_BROWSER
#define WRITEFILE_LIST_LEN 2
#define BROWSER_LIST_LEN 3
#define BROWSER_LIST_LEN 4
#else
#define WRITEFILE_LIST_LEN 1
#endif

View File

@ -53,7 +53,7 @@ extern shortcut replace_list[REPLACE_LIST_LEN], goto_list[GOTO_LIST_LEN];
extern shortcut writefile_list[WRITEFILE_LIST_LEN], help_list[HELP_LIST_LEN];
extern shortcut spell_list[SPELL_LIST_LEN], replace_list_2[REPLACE_LIST_LEN];
#ifndef DISABLE_BROWSER
extern shortcut browser_list[BROWSER_LIST_LEN];
extern shortcut browser_list[BROWSER_LIST_LEN], gotodir_list[GOTODIR_LIST_LEN];
#endif
extern shortcut *currshortcut;