From 3d597ed46074cfc3000708b0b259302915d345b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Sun, 3 Sep 2017 11:47:35 -0300 Subject: [PATCH] Initial multipane support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/files.c | 14 +++++++++++++- src/global.c | 9 +++++++++ src/nano.c | 39 ++++++++++++++++++++++++++++++++++++--- src/nano.h | 2 ++ src/proto.h | 5 +++++ src/winio.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/files.c b/src/files.c index 6a6bb1ca..399c501e 100644 --- a/src/files.c +++ b/src/files.c @@ -656,6 +656,7 @@ void switch_to_next_buffer(void) * open buffers. */ bool close_buffer(void) { + const openfilestruct *removedfile = openfile; /* If only one file buffer is open, get out. */ if (openfile == openfile->next) return FALSE; @@ -673,8 +674,19 @@ bool close_buffer(void) unlink_opennode(openfile->prev); /* If now just one buffer remains open, show "Exit" in the help lines. */ - if (openfile == openfile->next) + if (openfile == openfile->next) { exitfunc->desc = exit_tag; + alternatefile = NULL; + UNSET(MULTIPANE); + UNSET(SECONDPANE); + total_refresh(); + } else { + if (removedfile == alternatefile) { + alternatefile = openfile->next; + if (ISSET(MULTIPANE)) + refresh_both_panes(); + } + } return TRUE; } diff --git a/src/global.c b/src/global.c index e2017115..40fbbecb 100644 --- a/src/global.c +++ b/src/global.c @@ -120,6 +120,9 @@ partition *filepart = NULL; openfilestruct *openfile = NULL; /* The list of all open file buffers. */ +openfilestruct *alternatefile = NULL; + /* A pointer to an alternate file buffer. */ + #ifndef NANO_TINY char *matchbrackets = NULL; /* The opening and closing brackets that can be found by bracket @@ -1217,6 +1220,8 @@ void shortcut_init(void) #ifdef ENABLE_LINENUMBERS add_to_sclist(MMAIN, "M-#", 0, do_toggle_void, LINE_NUMBERS); #endif + add_to_sclist(MMAIN, "M-1", 0, do_toggle_void, MULTIPANE); + add_to_sclist(MMAIN, "M-2", 0, do_toggle_void, SECONDPANE); add_to_sclist(MMAIN, "M-P", 0, do_toggle_void, WHITESPACE_DISPLAY); #ifndef DISABLE_COLOR add_to_sclist(MMAIN, "M-Y", 0, do_toggle_void, NO_COLOR_SYNTAX); @@ -1415,6 +1420,10 @@ const char *flagtostr(int flag) return N_("Suspension"); case LINE_NUMBERS: return N_("Line numbering"); + case MULTIPANE: + return N_("Multipane"); + case SECONDPANE: + return N_("Secondpane"); default: return "?????"; } diff --git a/src/nano.c b/src/nano.c index f29cea90..7c163a88 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1325,7 +1325,7 @@ void regenerate_screen(void) COLS = win.ws_col; LINES = win.ws_row; #endif - editwincols = COLS - margin; + editwincols = (ISSET(MULTIPANE) ? COLS / 2 : COLS) - margin; /* Ensure that firstcolumn is the starting column of its chunk. */ ensure_firstcolumn_is_aligned(); @@ -1376,6 +1376,39 @@ void do_toggle(int flag) TOGGLE(flag); switch (flag) { + case SECONDPANE: + if (!ISSET(MULTIPANE)) { + UNSET(SECONDPANE); + statusline(HUSH, _("Can't swtich pane in single pane mode.")); + return; + } + + if (alternatefile == NULL) + alternatefile = openfile->next; + else { + openfilestruct *aux = openfile; + openfile = alternatefile; + alternatefile = aux; + } + total_refresh(); + break; + case MULTIPANE: + if (openfile->next == openfile) { + UNSET(MULTIPANE); + statusline(HUSH, _("Can't enable multipane with only one\ +buffer.")); + return; + } + + if (!ISSET(MULTIPANE)){ + total_refresh(); + } else { + if (alternatefile == NULL) + alternatefile = openfile->next; + + refresh_both_panes(); + } + break; #ifdef ENABLE_MOUSE case USE_MOUSE: mouse_init(); @@ -2487,7 +2520,7 @@ int main(int argc, char **argv) /* Create the three subwindows, based on the current screen dimensions. */ window_init(); - editwincols = COLS; + editwincols = ISSET(MULTIPANE) ? COLS / 2 : COLS; /* Set up the signal handlers. */ signal_init(); @@ -2614,7 +2647,7 @@ int main(int argc, char **argv) if (needed_margin != margin) { margin = needed_margin; - editwincols = COLS - margin; + editwincols = (ISSET(MULTIPANE) ? COLS / 2 : COLS) - margin; #ifndef NANO_TINY /* Ensure that firstcolumn is the starting column of its chunk. */ diff --git a/src/nano.h b/src/nano.h index 1a77097a..dbbc75ac 100644 --- a/src/nano.h +++ b/src/nano.h @@ -519,6 +519,8 @@ enum JUSTIFY_TRIM, SHOW_CURSOR, LINE_NUMBERS, + MULTIPANE, + SECONDPANE, NO_PAUSES, AT_BLANKS }; diff --git a/src/proto.h b/src/proto.h index 8ee4eb0e..249fced1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -100,6 +100,7 @@ extern filestruct *cutbuffer; extern filestruct *cutbottom; extern partition *filepart; extern openfilestruct *openfile; +extern openfilestruct *alternatefile; #ifndef NANO_TINY extern char *matchbrackets; @@ -437,6 +438,10 @@ int do_mouse(void); #endif void do_output(char *output, size_t output_len, bool allow_cntrls); +void switch_open_alternate(); +void select_pane(int pane); +void refresh_both_panes(); + /* Most functions in prompt.c. */ #ifdef ENABLE_MOUSE int do_statusbar_mouse(void); diff --git a/src/winio.c b/src/winio.c index 0a27f8d6..ff64afe4 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3305,6 +3305,37 @@ void total_redraw(void) #endif } +void select_pane(int pane) +{ + if(pane) { + wresize(edit, getmaxy(edit), COLS/2); + mvwin(edit, getbegy(edit), COLS/2); + editwincols = COLS/2 - margin; + } else { + wresize(edit, getmaxy(edit), COLS/2); + mvwin(edit, getbegy(edit), 0); + editwincols = COLS/2 - margin; + } +} + +void switch_open_alternate() +{ + openfilestruct *aux = openfile; + openfile = alternatefile; + alternatefile = aux; +} + +void refresh_both_panes() +{ + select_pane(!ISSET(SECONDPANE)); + switch_open_alternate(); + edit_refresh(); + switch_open_alternate(); + + select_pane(ISSET(SECONDPANE)); + edit_refresh(); +} + /* Redraw the entire screen, then refresh the title bar and the content of * the edit window (when not in the file browser), and the bottom bars. */ void total_refresh(void) @@ -3317,8 +3348,17 @@ void total_refresh(void) wrap_the_help_text(TRUE); else #endif - if (currmenu != MBROWSER && currmenu != MWHEREISFILE && currmenu != MGOTODIR) - edit_refresh(); + if (currmenu != MBROWSER && currmenu != MWHEREISFILE && currmenu != MGOTODIR) { + if (ISSET(MULTIPANE)) { + refresh_both_panes(); + } else { + wresize(edit, getmaxy(edit), COLS); + mvwin(edit, getbegy(edit), 0); + editwincols = COLS - margin; + edit_refresh(); + } + + } bottombars(currmenu); } -- 2.11.0