Code

Add action to maximize the current view; bound to M by default
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index ece56281d8bd07d0cf4ab0ab42f6122966f79620..413bd04b61a2766f7c1c6decde15fdfb578220fd 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -331,6 +331,7 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src)
        REQ_(PREVIOUS,          "Move to previous"), \
        REQ_(VIEW_NEXT,         "Move focus to next view"), \
        REQ_(REFRESH,           "Reload and refresh"), \
+       REQ_(MAXIMIZE,          "Maximize the current view"), \
        REQ_(VIEW_CLOSE,        "Close the current view"), \
        REQ_(QUIT,              "Close all views and quit"), \
        \
@@ -730,6 +731,7 @@ static struct keybinding default_keybindings[] = {
        { KEY_UP,       REQ_PREVIOUS },
        { KEY_DOWN,     REQ_NEXT },
        { 'R',          REQ_REFRESH },
+       { 'M',          REQ_MAXIMIZE },
 
        /* Cursor navigation */
        { 'k',          REQ_MOVE_UP },
@@ -1357,6 +1359,7 @@ struct view {
        struct view_ops *ops;   /* View operations */
 
        enum keymap keymap;     /* What keymap does this view have */
+       bool git_dir;           /* Whether the view requires a git directory. */
 
        char cmd[SIZEOF_STR];   /* Command buffer */
        char ref[SIZEOF_REF];   /* Hovered commit reference */
@@ -1416,27 +1419,28 @@ static struct view_ops help_ops;
 static struct view_ops status_ops;
 static struct view_ops stage_ops;
 
-#define VIEW_STR(name, cmd, env, ref, ops, map) \
-       { name, cmd, #env, ref, ops, map}
+#define VIEW_STR(name, cmd, env, ref, ops, map, git) \
+       { name, cmd, #env, ref, ops, map, git }
 
-#define VIEW_(id, name, ops, ref) \
-       VIEW_STR(name, TIG_##id##_CMD,  TIG_##id##_CMD, ref, ops, KEYMAP_##id)
+#define VIEW_(id, name, ops, git, ref) \
+       VIEW_STR(name, TIG_##id##_CMD,  TIG_##id##_CMD, ref, ops, KEYMAP_##id, git)
 
 
 static struct view views[] = {
-       VIEW_(MAIN,   "main",   &main_ops,   ref_head),
-       VIEW_(DIFF,   "diff",   &pager_ops,  ref_commit),
-       VIEW_(LOG,    "log",    &pager_ops,  ref_head),
-       VIEW_(TREE,   "tree",   &tree_ops,   ref_commit),
-       VIEW_(BLOB,   "blob",   &blob_ops,   ref_blob),
-       VIEW_(BLAME,  "blame",  &blame_ops,  ref_commit),
-       VIEW_(HELP,   "help",   &help_ops,   ""),
-       VIEW_(PAGER,  "pager",  &pager_ops,  "stdin"),
-       VIEW_(STATUS, "status", &status_ops, ""),
-       VIEW_(STAGE,  "stage",  &stage_ops,  ""),
+       VIEW_(MAIN,   "main",   &main_ops,   TRUE,  ref_head),
+       VIEW_(DIFF,   "diff",   &pager_ops,  TRUE,  ref_commit),
+       VIEW_(LOG,    "log",    &pager_ops,  TRUE,  ref_head),
+       VIEW_(TREE,   "tree",   &tree_ops,   TRUE,  ref_commit),
+       VIEW_(BLOB,   "blob",   &blob_ops,   TRUE,  ref_blob),
+       VIEW_(BLAME,  "blame",  &blame_ops,  TRUE,  ref_commit),
+       VIEW_(HELP,   "help",   &help_ops,   FALSE, ""),
+       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, "stdin"),
+       VIEW_(STATUS, "status", &status_ops, TRUE,  ""),
+       VIEW_(STAGE,  "stage",  &stage_ops,  TRUE,  ""),
 };
 
-#define VIEW(req) (&views[(req) - REQ_OFFSET - 1])
+#define VIEW(req)      (&views[(req) - REQ_OFFSET - 1])
+#define VIEW_REQ(view) ((view) - views + REQ_OFFSET + 1)
 
 #define foreach_view(view, i) \
        for (i = 0; i < ARRAY_SIZE(views) && (view = &views[i]); i++)
@@ -2278,6 +2282,11 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
                return;
        }
 
+       if (view->git_dir && !opt_git_dir[0]) {
+               report("The %s view is disabled in pager view", view->name);
+               return;
+       }
+
        if (split) {
                display[1] = view;
                if (!backgrounded)
@@ -2581,6 +2590,11 @@ view_driver(struct view *view, enum request request)
                report("Refreshing is not yet supported for the %s view", view->name);
                break;
 
+       case REQ_MAXIMIZE:
+               if (displayed_views() == 2)
+                       open_view(view, VIEW_REQ(view), OPEN_DEFAULT);
+               break;
+
        case REQ_TOGGLE_LINENO:
                opt_line_number = !opt_line_number;
                redraw_display();