Ticket #4184: WindowCascadeTiled___-w_-T_opts___menus___man_doc.patch

File WindowCascadeTiled___-w_-T_opts___menus___man_doc.patch, 9.5 KB (added by psprint, 8 months ago)
  • doc/man/mcedit.1.in

    From 9ec735f2a3ed7f091dda2c48331403b8898d58bc Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Sat, 23 Jan 2021 21:26:07 -0600
    Subject: WindowCascade
    
    WindowTile
    
    Add -w/-T options and menu entries.
    ---
     doc/man/mcedit.1.in     |   6 ++
     lib/keybind.c           |   2 +
     lib/keybind.h           |   2 +
     misc/mc.default.keymap  |   2 +
     src/args.c              |  20 +++++++
     src/args.h              |   2 +
     src/editor/editmenu.c   |   2 +
     src/editor/editwidget.c | 128 ++++++++++++++++++++++++++++++++++++++++
     src/keybind-defaults.c  |   2 +
     9 files changed, 166 insertions(+)
    
    diff --git a/doc/man/mcedit.1.in b/doc/man/mcedit.1.in
    index 33e5f34b7..df1680b63 100644
    a b Display the version of the program. 
    5454.I "\-x" 
    5555Force xterm mode.  Used when running on xterm\-capable terminals (two 
    5656screen modes, and able to send mouse escape sequences). 
     57.TP 
     58.I "\-w/\-\-cascade" 
     59Start with file windows arranged in cascade (not fullscreen). 
     60.TP 
     61.I "\-T/\-\-tile" 
     62Start with file windows tiled (not fullscreen). 
    5763.SH FEATURES 
    5864The internal file editor is a full\-featured windowed editor.  It can 
    5965edit several files at the same time. Maximum size of each file is 64 
  • lib/keybind.c

    diff --git a/lib/keybind.c b/lib/keybind.c
    index abd44d3e2..4d735ed43 100644
    a b static name_keymap_t command_names[] = { 
    341341    ADD_KEYMAP_NAME (WindowList), 
    342342    ADD_KEYMAP_NAME (WindowNext), 
    343343    ADD_KEYMAP_NAME (WindowPrev), 
     344    ADD_KEYMAP_NAME (WindowCascade), 
     345    ADD_KEYMAP_NAME (WindowTile), 
    344346#endif /* USE_INTERNAL_EDIT */ 
    345347 
    346348    /* viewer */ 
  • lib/keybind.h

    diff --git a/lib/keybind.h b/lib/keybind.h
    index af019df09..a3828e68d 100644
    a b enum 
    300300    CK_WindowList, 
    301301    CK_WindowNext, 
    302302    CK_WindowPrev, 
     303    CK_WindowCascade, 
     304    CK_WindowTile, 
    303305    /* misc commands */ 
    304306    CK_SpellCheck, 
    305307    CK_SpellCheckCurrentWord, 
  • misc/mc.default.keymap

    diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
    index 2931ddd0a..1cd6ab5b3 100644
    a b SpellCheckCurrentWord = ctrl-p 
    386386# WindowList = 
    387387# WindowNext = 
    388388# WindowPrev = 
     389WindowCascade = ctrl-alt-c 
     390WindowTile = ctrl-alt-t 
    389391# ExtendedKeyMap = 
    390392 
    391393[viewer] 
  • src/args.c

    diff --git a/src/args.c b/src/args.c
    index 3f6a8b2a4..c52afa8b2 100644
    a b  
    4646 
    4747/*** global variables ****************************************************************************/ 
    4848 
     49gboolean mc_args__cascade = FALSE; 
     50gboolean mc_args__tile = FALSE; 
     51 
    4952/* If true, assume we are running on an xterm terminal */ 
    5053gboolean mc_args__force_xterm = FALSE; 
    5154 
    static const GOptionEntry argument_main_table[] = { 
    178181    }, 
    179182#endif /* ENABLE_VFS_SMB */ 
    180183 
     184#ifdef USE_INTERNAL_EDIT 
     185    /* options for non-fullscreen mcedit startup */ 
     186    { 
     187     "cascade", 'w', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, 
     188     &mc_args__cascade, 
     189     N_("Start editor with windows arranged in cascade"), 
     190     NULL 
     191    }, 
     192 
     193    { 
     194     "tile", 'T', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, 
     195     &mc_args__tile, 
     196     N_("Start editor with windows tiled"), 
     197     NULL 
     198    }, 
     199#endif 
     200 
    181201    { 
    182202     /* handle arguments manually */ 
    183203     "view", 'v', G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, 
  • src/args.h

    diff --git a/src/args.h b/src/args.h
    index 616864d00..69b25ec16 100644
    a b extern gboolean mc_args__force_xterm; 
    2222extern gboolean mc_args__nomouse; 
    2323extern gboolean mc_args__force_colors; 
    2424extern gboolean mc_args__nokeymap; 
     25extern gboolean mc_args__cascade; 
     26extern gboolean mc_args__tile; 
    2527extern char *mc_args__last_wd_file; 
    2628extern char *mc_args__netfs_logfile; 
    2729extern char *mc_args__keymap_file; 
  • src/editor/editmenu.c

    diff --git a/src/editor/editmenu.c b/src/editor/editmenu.c
    index 489893849..c20e9fb7e 100644
    a b create_window_menu (void) 
    232232    entries = g_list_prepend (entries, menu_entry_create (_("&Resize"), CK_WindowResize)); 
    233233    entries = 
    234234        g_list_prepend (entries, menu_entry_create (_("&Toggle fullscreen"), CK_WindowFullscreen)); 
     235    entries = g_list_prepend (entries, menu_entry_create (_("&Cascade"), CK_WindowCascade)); 
     236    entries = g_list_prepend (entries, menu_entry_create (_("T&iled"), CK_WindowTile)); 
    235237    entries = g_list_prepend (entries, menu_separator_create ()); 
    236238    entries = g_list_prepend (entries, menu_entry_create (_("&Next"), CK_WindowNext)); 
    237239    entries = g_list_prepend (entries, menu_entry_create (_("&Previous"), CK_WindowPrev)); 
  • src/editor/editwidget.c

    diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c
    index 3eafff2b8..d1a41de45 100644
    a b get_hotkey (int n) 
    292292 
    293293/* --------------------------------------------------------------------------------------------- */ 
    294294 
     295static gboolean 
     296edit_window_leave_fullscreen_resize (Widget * w, int y, int x, int lines, int cols) 
     297{ 
     298    WRect resize_rect; 
     299    gboolean ret = FALSE; 
     300 
     301    if (edit_widget_is_editor (w)) 
     302    { 
     303        WEdit *e = (WEdit *) w; 
     304        if (e->fullscreen) 
     305            edit_toggle_fullscreen (e); 
     306        rect_init (&resize_rect, y, x, lines, cols); 
     307        e->force |= REDRAW_COMPLETELY; 
     308        send_message (WIDGET (e), NULL, MSG_RESIZE, 0, &resize_rect); 
     309        ret = TRUE; 
     310    } 
     311    return ret; 
     312} 
     313 
     314/* --------------------------------------------------------------------------------------------- */ 
     315 
     316static void 
     317edit_window_cascade (const WDialog * h) 
     318{ 
     319    const WGroup *g = CONST_GROUP (h); 
     320    const Widget *wid = CONST_WIDGET (h); 
     321    int diff = 5; 
     322    int cur_y, cur_x, lines, cols; 
     323    GList *w; 
     324 
     325    cur_x = 0; 
     326    cur_y = 1; 
     327    lines = wid->lines - 2; 
     328    cols = wid->cols; 
     329 
     330    for (w = g->widgets; w != NULL; w = g_list_next (w)) 
     331    { 
     332        if (w == g->current) 
     333            continue; 
     334        if (edit_window_leave_fullscreen_resize (WIDGET (w->data), cur_y, cur_x, lines, cols)) 
     335        { 
     336            cur_y += diff; 
     337            cur_x += diff; 
     338            lines -= diff; 
     339            cols -= diff; 
     340            /* Underflow – cycle back to the first size and position. */ 
     341            if (lines < 7 || cols < 30) 
     342            { 
     343                /* Second and following series are more dense. */ 
     344                diff -= diff > 1 ? 1 : 0; 
     345                /* Use a little degrading shift for the next series of windows. */ 
     346                cur_x = 0 + diff - 1; 
     347                cur_y = 1 + diff - 1; 
     348                lines = wid->lines - diff - 1; 
     349                cols = wid->cols - diff + 1; 
     350            } 
     351        } 
     352    } 
     353    w = g->current; 
     354    edit_window_leave_fullscreen_resize (WIDGET (w->data), cur_y, cur_x, lines, cols); 
     355    repaint_screen (); 
     356} 
     357 
     358/* --------------------------------------------------------------------------------------------- */ 
     359 
     360static void 
     361edit_window_tile (const WDialog * h) 
     362{ 
     363    const WGroup *g = CONST_GROUP (h); 
     364    const Widget *wid = CONST_WIDGET (h); 
     365    const size_t offset = 3;    /* skip menu and buttonbar */ 
     366    int cur_y, orig_lines, lines, dlg_num; 
     367    GList *w; 
     368 
     369    dlg_num = g_list_length (g->widgets) - offset; 
     370 
     371    cur_y = 1; 
     372    lines = wid->lines / dlg_num; 
     373    if (lines < 5) 
     374        lines = 5; 
     375    orig_lines = lines; 
     376 
     377    for (w = g->widgets; w != NULL; w = g_list_next (w)) 
     378    { 
     379        if (w == g->current) 
     380            continue; 
     381        /* Detect overflow and use space for final window (in series). */ 
     382        if (cur_y + 2 * orig_lines - 1 > wid->lines) 
     383            lines = wid->lines - cur_y - 1; 
     384 
     385        /* Resize and unfullscreen window. */ 
     386        if (edit_window_leave_fullscreen_resize (WIDGET (w->data), cur_y, 0, lines, wid->cols)) 
     387        { 
     388            cur_y += orig_lines; 
     389            /* Overflow - cycle back to the first size and position. */ 
     390            if (cur_y + orig_lines - 1 > wid->lines) 
     391            { 
     392                cur_y = 1; 
     393                lines = orig_lines; 
     394            } 
     395        } 
     396    } 
     397 
     398    /* Ensure that the currently edited file is positioned last. */ 
     399    w = g->current; 
     400    if (cur_y + orig_lines > wid->lines - 1) 
     401        lines = wid->lines - cur_y - 1; 
     402    edit_window_leave_fullscreen_resize (WIDGET (w->data), cur_y, 0, lines, wid->cols); 
     403    repaint_screen (); 
     404} 
     405 
     406/* --------------------------------------------------------------------------------------------- */ 
     407 
    295408static void 
    296409edit_window_list (const WDialog * h) 
    297410{ 
    edit_dialog_command_execute (WDialog * h, long command) 
    459572    case CK_WindowList: 
    460573        edit_window_list (h); 
    461574        break; 
     575    case CK_WindowCascade: 
     576        edit_window_cascade (h); 
     577        break; 
     578    case CK_WindowTile: 
     579        edit_window_tile (h); 
     580        break; 
    462581    case CK_WindowNext: 
    463582        group_select_next_widget (g); 
    464583        break; 
    edit_files (const GList * files) 
    12681387        ok = ok || f_ok; 
    12691388    } 
    12701389 
     1390    if (mc_args__cascade) 
     1391    { 
     1392        edit_window_cascade (edit_dlg); 
     1393    } 
     1394    else if (mc_args__tile) 
     1395    { 
     1396        edit_window_tile (edit_dlg); 
     1397    } 
     1398 
    12711399    if (ok) 
    12721400        dlg_run (edit_dlg); 
    12731401 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 7b87c2f5a..dbed20014 100644
    a b static const global_keymap_ini_t default_editor_keymap[] = { 
    471471    {"Sort", "alt-t"}, 
    472472    {"Mail", "alt-m"}, 
    473473    {"ExternalCommand", "alt-u"}, 
     474    {"WindowTile", "alt-shift-t"}, 
     475    {"WindowCascade", "alt-shift-c"}, 
    474476#ifdef HAVE_ASPELL 
    475477    {"SpellCheckCurrentWord", "ctrl-p"}, 
    476478#endif