diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-24 16:37:12 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-24 16:37:12 +0200 |
| commit | 41debbfd7649a347f5c49489ed4de536f9d62c78 (patch) | |
| tree | 752cd7a1bb90e142c2b928a2d16d6f7956c1a417 | |
| parent | 3a24e6a5562e4b1ea456fbe36607bd8a9c92744d (diff) | |
| download | vis-41debbfd7649a347f5c49489ed4de536f9d62c78.tar.gz vis-41debbfd7649a347f5c49489ed4de536f9d62c78.tar.xz | |
Change split/vsplit API
| -rw-r--r-- | editor.c | 38 | ||||
| -rw-r--r-- | editor.h | 9 | ||||
| -rw-r--r-- | vis.c | 9 |
3 files changed, 27 insertions, 29 deletions
@@ -21,11 +21,10 @@ static EditorWin *editor_window_new_text(Editor *ed, Text *text); static void editor_window_free(Editor *ed, EditorWin *win); -static bool editor_window_split_internal(EditorWin *original); static void editor_windows_invalidate(Editor *ed, size_t start, size_t end); static void editor_window_draw(EditorWin *win); -static void editor_windows_arrange_horizontal(Editor *ed); -static void editor_windows_arrange_vertical(Editor *ed); +static void windows_arrange_horizontal(Editor *ed); +static void windows_arrange_vertical(Editor *ed); static Prompt *editor_prompt_new(); static void editor_prompt_free(Prompt *prompt); @@ -69,7 +68,7 @@ void editor_statusbar_set(Editor *ed, void (*statusbar)(EditorWin*)) { ed->statusbar = statusbar; } -static void editor_windows_arrange_horizontal(Editor *ed) { +static void windows_arrange_horizontal(Editor *ed) { int n = 0, x = 0, y = 0; for (EditorWin *win = ed->windows; win; win = win->next) n++; @@ -81,7 +80,7 @@ static void editor_windows_arrange_horizontal(Editor *ed) { } } -static void editor_windows_arrange_vertical(Editor *ed) { +static void windows_arrange_vertical(Editor *ed) { int n = 0, x = 0, y = 0; for (EditorWin *win = ed->windows; win; win = win->next) n++; @@ -118,28 +117,23 @@ bool editor_window_reload(EditorWin *win) { return true; } -static bool editor_window_split_internal(EditorWin *original) { +void editor_windows_arrange_vertical(Editor *ed) { + ed->windows_arrange = windows_arrange_vertical; + editor_draw(ed); +} + +void editor_windows_arrange_horizontal(Editor *ed) { + ed->windows_arrange = windows_arrange_horizontal; + editor_draw(ed); +} + +bool editor_window_split(EditorWin *original) { EditorWin *win = editor_window_new_text(original->editor, original->text); if (!win) return false; win->text = original->text; window_syntax_set(win->win, window_syntax_get(original->win)); window_cursor_to(win->win, window_cursor_get(original->win)); - return true; -} - -bool editor_window_split(EditorWin *win) { - if (!editor_window_split_internal(win)) - return false; - win->editor->windows_arrange = editor_windows_arrange_horizontal; - editor_draw(win->editor); - return true; -} - -bool editor_window_vsplit(EditorWin *win) { - if (!editor_window_split_internal(win)) - return false; - win->editor->windows_arrange = editor_windows_arrange_vertical; editor_draw(win->editor); return true; } @@ -401,7 +395,7 @@ Editor *editor_new(int width, int height) { ed->height = height; ed->tabwidth = 8; ed->expandtab = false; - ed->windows_arrange = editor_windows_arrange_horizontal; + ed->windows_arrange = windows_arrange_horizontal; return ed; err: editor_free(ed); @@ -140,14 +140,15 @@ bool editor_window_new(Editor*, const char *filename); /* reload the file currently displayed in the window from disk */ bool editor_window_reload(EditorWin*); void editor_window_close(EditorWin*); -/* split the given window either horizontally or vertically, changes to - * the displayed text will be reflected in both windows */ +/* split the given window. changes to the displayed text will be reflected + * in both windows */ bool editor_window_split(EditorWin*); -bool editor_window_vsplit(EditorWin*); /* focus the next / previous window */ void editor_window_next(Editor*); void editor_window_prev(Editor*); - +/* rearrange all windows either vertically or horizontally */ +void editor_windows_arrange_vertical(Editor*); +void editor_windows_arrange_horizontal(Editor*); /* display a user prompt with a certain title */ void editor_prompt_show(Editor*, const char *title); /* hide the user prompt if it is currently shown */ @@ -870,10 +870,11 @@ static void winclose(const Arg *arg) { } static void winsplit(const Arg *arg) { + editor_window_split(vis->win); if (arg->b) - editor_window_vsplit(vis->win); + editor_windows_arrange_vertical(vis); else - editor_window_split(vis->win); + editor_windows_arrange_horizontal(vis); } static int argi2lines(const Arg *arg) { @@ -1240,14 +1241,16 @@ static bool openfiles(const char **files) { } static bool cmd_split(const char *argv[]) { + editor_windows_arrange_horizontal(vis); if (!argv[1]) return editor_window_split(vis->win); return openfiles(&argv[1]); } static bool cmd_vsplit(const char *argv[]) { + editor_windows_arrange_vertical(vis); if (!argv[1]) - return editor_window_vsplit(vis->win); + return editor_window_split(vis->win); return openfiles(&argv[1]); } |
