[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 1/2] new thing: a tools menu that groups together so
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 1/2] new thing: a tools menu that groups together some larger functions |
Date: |
Thu, 9 May 2019 12:05:15 +0200 |
This menu draws a prompt bar but centers the text so that it is clear
that this is not actually a prompt. It also leaves the cursor in the
edit window, so the user can see where cut-till-end-of-file will start
its cut.
---
src/global.c | 37 +++++++++++++++++++++----------------
src/help.c | 8 ++++++++
src/nano.h | 1 +
src/prompt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/proto.h | 1 +
5 files changed, 79 insertions(+), 16 deletions(-)
diff --git a/src/global.c b/src/global.c
index 9bde6a91..216e6b7e 100644
--- a/src/global.c
+++ b/src/global.c
@@ -536,6 +536,7 @@ void shortcut_init(void)
const char *uncut_gist =
N_("Paste the contents of cutbuffer at current cursor
position");
const char *cursorpos_gist = N_("Display the position of the cursor");
+ const char *tools_gist = N_("Show a menu with several tools");
#ifdef ENABLE_SPELLER
const char *spell_gist = N_("Invoke the spell checker, if available");
#endif
@@ -673,12 +674,12 @@ void shortcut_init(void)
/* Start populating the different menus with functions. */
- add_to_funcs(do_help_void, (MMOST | MBROWSER) & ~MFINDINHELP,
+ add_to_funcs(do_help_void, (MMOST | MBROWSER | MTOOLS) & ~MFINDINHELP,
/* TRANSLATORS: Try to keep the next ninety strings or so at
most 10
* characters. Some strings may be longer -- run nano and see.
*/
N_("Get Help"), WITHORSANS(help_gist), TOGETHER, VIEW);
- add_to_funcs(do_cancel, ((MMOST & ~MMAIN) | MYESNO),
+ add_to_funcs(do_cancel, ((MMOST & ~MMAIN) | MYESNO | MTOOLS),
N_("Cancel"), WITHORSANS(cancel_gist), BLANKAFTER, VIEW);
add_to_funcs(do_exit, MMAIN,
@@ -743,11 +744,18 @@ void shortcut_init(void)
N_("Justify"), WITHORSANS(justify_gist),
TOGETHER, NOVIEW);
#endif
#ifdef ENABLE_SPELLER
- add_to_funcs(do_spell, MMAIN,
+ add_to_funcs(do_spell, MTOOLS,
N_("To Spell"), WITHORSANS(spell_gist),
BLANKAFTER, NOVIEW);
+#endif
+#ifdef ENABLE_COLOR
+ add_to_funcs(do_linter, MTOOLS,
+ N_("To Linter"), WITHORSANS(lint_gist),
BLANKAFTER, NOVIEW);
#endif
}
+ add_to_funcs(offer_tools, MMAIN,
+ N_("Tools"), WITHORSANS(tools_gist), TOGETHER, NOVIEW);
+
add_to_funcs(do_cursorpos_void, MMAIN,
N_("Cur Pos"), WITHORSANS(cursorpos_gist), TOGETHER, VIEW);
@@ -794,11 +802,6 @@ void shortcut_init(void)
add_to_funcs(flip_goto, MWHEREIS,
N_("Go To Line"), WITHORSANS(gotoline_gist), TOGETHER, VIEW);
-#ifdef ENABLE_JUSTIFY
- add_to_funcs(do_full_justify, MWHEREIS,
- N_("FullJstify"), WITHORSANS(fulljustify_gist), BLANKAFTER,
NOVIEW);
-#endif
-
#ifndef NANO_TINY
add_to_funcs(do_find_bracket, MMAIN,
N_("To Bracket"), WITHORSANS(bracket_gist), BLANKAFTER, VIEW);
@@ -922,12 +925,12 @@ void shortcut_init(void)
N_("Chop Left"), WITHORSANS(chopwordleft_gist), TOGETHER,
NOVIEW);
add_to_funcs(chop_next_word, MMAIN,
N_("Chop Right"), WITHORSANS(chopwordright_gist), TOGETHER,
NOVIEW);
- add_to_funcs(cut_till_eof, MMAIN,
+ add_to_funcs(cut_till_eof, MMAIN|MTOOLS,
N_("CutTillEnd"), WITHORSANS(cuttilleof_gist), BLANKAFTER,
NOVIEW);
#endif
#ifdef ENABLE_JUSTIFY
- add_to_funcs(do_full_justify, MMAIN,
+ add_to_funcs(do_full_justify, MMAIN|MTOOLS,
N_("FullJstify"), WITHORSANS(fulljustify_gist), TOGETHER,
NOVIEW);
#endif
@@ -1072,7 +1075,7 @@ void shortcut_init(void)
add_to_sclist(MMOST, "Del", 0, do_delete, 0);
add_to_sclist(MMOST, "^I", 0, do_tab, 0);
add_to_sclist(MMOST, "Tab", TAB_CODE, do_tab, 0);
- add_to_sclist((MMOST|MBROWSER) & ~MFINDINHELP, "^G", 0, do_help_void,
0);
+ add_to_sclist((MMOST|MBROWSER|MTOOLS) & ~MFINDINHELP, "^G", 0,
do_help_void, 0);
add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", 0, do_exit, 0);
if (!ISSET(PRESERVE))
add_to_sclist(MMAIN, "^S", 0, do_savefile, 0);
@@ -1090,7 +1093,7 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "^J", 0, do_justify_void, 0);
#endif
#ifdef ENABLE_SPELLER
- add_to_sclist(MMAIN, "^T", 0, do_spell, 0);
+ add_to_sclist(MMAIN, "^T", 0, offer_tools, 0);
#endif
#ifdef ENABLE_COLOR
add_to_sclist(MMAIN, "M-B", 0, do_linter, 0);
@@ -1257,7 +1260,7 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "M-Z", 0, do_toggle_void, SUSPEND);
#endif /* !NANO_TINY */
- add_to_sclist(((MMOST & ~MMAIN) | MYESNO), "^C", 0, do_cancel, 0);
+ add_to_sclist(((MMOST & ~MMAIN) | MYESNO | MTOOLS), "^C", 0, do_cancel,
0);
add_to_sclist(MWHEREIS|MREPLACE, "M-C", 0, case_sens_void, 0);
add_to_sclist(MWHEREIS|MREPLACE, "M-R", 0, regexp_void, 0);
@@ -1340,9 +1343,11 @@ void shortcut_init(void)
add_to_sclist(MHELP, "Home", KEY_HOME, to_first_line, 0);
add_to_sclist(MHELP, "End", KEY_END, to_last_line, 0);
#endif
-#ifdef ENABLE_COLOR
- add_to_sclist(MLINTER, "^X", 0, do_cancel, 0);
-#endif
+ add_to_sclist(MTOOLS|MLINTER, "^X", 0, do_cancel, 0);
+ add_to_sclist(MTOOLS, "^T", 0, do_spell, 0);
+ add_to_sclist(MTOOLS, "^L", 0, do_linter, 0);
+ add_to_sclist(MTOOLS, "^K", 0, cut_till_eof, 0);
+ add_to_sclist(MTOOLS, "^J", 0, do_full_justify, 0);
add_to_sclist(MMOST & ~MFINDINHELP, "F1", 0, do_help_void, 0);
add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", 0, do_exit, 0);
add_to_sclist(MMAIN, "F3", 0, do_writeout_void, 0);
diff --git a/src/help.c b/src/help.c
index bf13bbd8..43e01f21 100644
--- a/src/help.c
+++ b/src/help.c
@@ -422,6 +422,14 @@ void help_init(void)
htx[1] = N_(" The following function keys are "
"available in Linter mode:\n\n");
htx[2] = NULL;
+ } else if (currmenu == MTOOLS) {
+ htx[0] = N_("=== Tools menu ===\n\n "
+ "Here you can pick one of a handful of
functions. "
+ "These functions affect the whole buffer or the
"
+ "marked region.\n\n");
+ htx[1] = N_(" The following shortcuts are "
+ "available in the Tools menu:\n\n");
+ htx[2] = NULL;
}
#endif /* !NANO_TINY */
else {
diff --git a/src/nano.h b/src/nano.h
index 5b89e33b..49a464ab 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -564,6 +564,7 @@ enum
#define MYESNO (1<<13)
#define MLINTER (1<<14)
#define MFINDINHELP (1<<15)
+#define MTOOLS (1<<16)
/* This is an abbreviation for all menus except Help and Browser and YesNo. */
#define MMOST
(MMAIN|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MWRITEFILE|MINSERTFILE|\
MEXTCMD|MWHEREISFILE|MGOTODIR|MFINDINHELP|MSPELL|MLINTER)
diff --git a/src/prompt.c b/src/prompt.c
index 953330a9..f11320d2 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -760,3 +760,51 @@ int do_yesno_prompt(bool all, const char *msg)
return choice;
}
+
+/* Offer a choice of tools and execute the chosen one, if any. */
+void offer_tools(void)
+{
+ const char *motto = _("Choose a tool");
+ size_t width = breadth(motto);
+
+ while (TRUE) {
+ functionptrtype func;
+ size_t offset = 0;
+ int input;
+
+ if (width < COLS)
+ offset = (COLS - width) / 2;
+
+ /* Color the status bar over its full width and show the
"prompt". */
+ wattron(bottomwin, interface_color_pair[TITLE_BAR]);
+ blank_statusbar();
+ mvwaddnstr(bottomwin, 0, offset, motto, actual_x(motto, COLS -
offset));
+ wattroff(bottomwin, interface_color_pair[TITLE_BAR]);
+ wnoutrefresh(bottomwin);
+
+ bottombars(MTOOLS);
+ place_the_cursor();
+ wnoutrefresh(edit);
+
+ input = get_kbinput(bottomwin, VISIBLE);
+ func = func_from_key(&input);
+
+ if (input == KEY_WINCH)
+ continue;
+
+ if (func == do_spell || func == do_linter || func ==
do_full_justify) {
+ func();
+ return;
+ } else if (func == cut_till_eof) {
+ cut_till_eof();
+ wipe_statusbar();
+ return;
+ } else if (func == do_cancel) {
+ wipe_statusbar();
+ return;
+ } else if (func == do_help_void)
+ do_help_void();
+ else
+ beep();
+ }
+}
diff --git a/src/proto.h b/src/proto.h
index ee2fcec9..6762f012 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -464,6 +464,7 @@ int do_prompt(bool allow_tabs, bool allow_files,
int menu, const char *curranswer, linestruct **history_list,
void (*refresh_func)(void), const char *msg, ...);
int do_yesno_prompt(bool all, const char *msg);
+void offer_tools(void);
/* Most functions in rcfile.c. */
#ifdef ENABLE_NANORC
--
2.20.1
- [Nano-devel] [PATCH 1/2] new thing: a tools menu that groups together some larger functions,
Benno Schulenberg <=