index fd40b8e98027c3aeac5a9c55a130d902c98e102f..7ad7fe741ce2b80ac74c58503b9529ed76ecb886 100644 (file)
--- a/tig.c
+++ b/tig.c
}
static void
-maximize_view(struct view *view)
+maximize_view(struct view *view, bool redraw)
{
memset(display, 0, sizeof(display));
current_view = 0;
display[current_view] = view;
resize_display();
- redraw_display(FALSE);
- report("");
+ if (redraw) {
+ redraw_display(FALSE);
+ report("");
+ }
}
}
static bool
-format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool first)
+format_argv(const char ***dst_argv, const char *src_argv[], bool first)
{
char buf[SIZEOF_STR];
int argc;
@@ -2426,7 +2428,7 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool f
int len = next - arg;
const char *value;
- if (!next || !replace) {
+ if (!next) {
len = strlen(arg);
value = "";
@@ -2441,7 +2443,7 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool f
if (!string_format_from(buf, &bufpos, "%.*s%s", len, arg, value))
return FALSE;
- arg = next && replace ? strchr(next, ')') + 1 : NULL;
+ arg = next ? strchr(next, ')') + 1 : NULL;
}
if (!argv_append(dst_argv, buf))
}
static bool
-prepare_io(struct view *view, const char *dir, const char *argv[], bool replace)
+prepare_update(struct view *view, const char *dir, const char *argv[])
{
+ if (view->pipe)
+ io_done(view->pipe);
view->dir = dir;
- return format_argv(&view->argv, argv, replace, !view->prev);
+ return argv_copy(&view->argv, argv);
}
static bool
start_update(struct view *view, const char **argv, const char *dir)
{
- if (view->pipe)
- io_done(view->pipe);
- return prepare_io(view, dir, argv, FALSE) &&
+ return prepare_update(view, dir, argv) &&
io_run(&view->io, IO_RD, dir, view->argv);
}
@@ -2526,7 +2528,8 @@ begin_update(struct view *view, const char *dir, const char **argv, enum open_fl
end_update(view, TRUE);
if (!refresh) {
- if (!prepare_io(view, dir, argv, TRUE))
+ view->dir = dir;
+ if (!format_argv(&view->argv, argv, !view->prev))
return FALSE;
/* Put the current ref_* value to the view title ref
#define refresh_view(view) load_view(view, OPEN_REFRESH)
+static void
+split_view(struct view *prev, struct view *view)
+{
+ display[1] = view;
+ current_view = 1;
+ view->parent = prev;
+ resize_display();
+
+ if (prev->lineno - prev->offset >= prev->height) {
+ /* Take the title line into account. */
+ int lines = prev->lineno - prev->offset - prev->height + 1;
+
+ /* Scroll the view that was split if the current line is
+ * outside the new limited view. */
+ do_scroll_view(prev, lines);
+ }
+
+ if (view != prev && view_is_displayed(prev)) {
+ /* "Blur" the previous view. */
+ update_view_title(prev);
+ }
+}
+
static void
open_view(struct view *prev, enum request request, enum open_flags flags)
{
bool reload = !!(flags & (OPEN_RELOAD | OPEN_PREPARED));
struct view *view = VIEW(request);
int nviews = displayed_views();
- struct view *base_view = display[0];
assert(flags ^ OPEN_REFRESH);
}
if (split) {
- display[1] = view;
- current_view = 1;
- view->parent = prev;
+ split_view(prev, view);
} else {
- /* Maximize the current view. */
- memset(display, 0, sizeof(display));
- current_view = 0;
- display[current_view] = view;
+ maximize_view(view, FALSE);
}
/* No prev signals that this is the first loaded view. */
view->prev = prev;
}
- /* Resize the view when switching between split- and full-screen,
- * or when switching between two different full-screen views. */
- if (nviews != displayed_views() ||
- (nviews == 1 && base_view != display[0]))
- resize_display();
-
- if (split && prev->lineno - prev->offset >= prev->height) {
- /* Take the title line into account. */
- int lines = prev->lineno - prev->offset - prev->height + 1;
-
- /* Scroll the view that was split if the current line is
- * outside the new limited view. */
- do_scroll_view(prev, lines);
- }
-
- if (prev && view != prev && split && view_is_displayed(prev)) {
- /* "Blur" the previous view. */
- update_view_title(prev);
- }
-
load_view(view, flags);
}
@@ -2780,9 +2780,7 @@ open_argv(struct view *prev, struct view *view, const char *argv[], const char *
{
enum request request = view - views + REQ_OFFSET + 1;
- if (view->pipe)
- end_update(view, TRUE);
- if (!prepare_io(view, dir, argv, FALSE)) {
+ if (!prepare_update(view, dir, argv)) {
report("Failed to open %s view: %s", view->name, io_strerror(&view->io));
} else {
open_view(prev, request, flags | OPEN_PREPARED);
return;
}
- if (format_argv(&argv, req->argv, TRUE, FALSE))
+ if (format_argv(&argv, req->argv, FALSE))
open_external_viewer(argv, NULL);
if (argv)
argv_free(argv);
case REQ_MAXIMIZE:
if (displayed_views() == 2)
- maximize_view(view);
+ maximize_view(view, TRUE);
break;
case REQ_OPTIONS:
* view itself. Parents to closed view should never be
* followed. */
if (view->prev && view->prev != view) {
- maximize_view(view->prev);
+ maximize_view(view->prev, TRUE);
view->prev = view;
break;
}
switch (request) {
case REQ_ENTER:
if (view_is_displayed(view) && display[0] != view)
- maximize_view(view);
+ maximize_view(view, TRUE);
open_view(view, REQ_VIEW_DIFF, flags);
break;
case REQ_REFRESH: