diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-10-12 13:47:36 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-10-14 10:33:26 +0200 |
| commit | 277c6b4897e11a5449fc1cfab3ab6e83307a7989 (patch) | |
| tree | a8b34ab47c11dfd9995ef03d9fae1613dde2be67 | |
| parent | 9e391f5e3b2baaee0bf73e5273daf84be8a76ce2 (diff) | |
| download | vis-277c6b4897e11a5449fc1cfab3ab6e83307a7989.tar.gz vis-277c6b4897e11a5449fc1cfab3ab6e83307a7989.tar.xz | |
view: cleanup option handling
| -rw-r--r-- | editor.c | 6 | ||||
| -rw-r--r-- | editor.h | 1 | ||||
| -rw-r--r-- | ui-curses.c | 22 | ||||
| -rw-r--r-- | ui.h | 3 | ||||
| -rw-r--r-- | view.c | 8 | ||||
| -rw-r--r-- | view.h | 3 | ||||
| -rw-r--r-- | vis.c | 26 |
7 files changed, 46 insertions, 23 deletions
@@ -64,6 +64,7 @@ bool editor_window_split(Win *original) { win->file = original->file; win->file->refcount++; view_syntax_set(win->view, view_syntax_get(original->view)); + view_options_set(win->view, view_options_get(original->view)); view_cursor_to(win->view, view_cursor_get(original->view)); editor_draw(win->editor); return true; @@ -506,8 +507,3 @@ void editor_info_show(Editor *ed, const char *msg, ...) { void editor_info_hide(Editor *ed) { ed->ui->info_hide(ed->ui); } - -void editor_window_options(Win *win, enum UiOption options) { - win->ui->options(win->ui, options); -} - @@ -325,7 +325,6 @@ void editor_prompt_set(Editor*, const char *line); /* display a message to the user */ void editor_info_show(Editor*, const char *msg, ...); void editor_info_hide(Editor*); -void editor_window_options(Win*, enum UiOption options); /* look up a curses color pair for the given combination of fore and * background color */ diff --git a/ui-curses.c b/ui-curses.c index 7e74919..cd26508 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -798,26 +798,27 @@ static void ui_window_focus(UiWin *w) { ui_window_draw(w); } -static void ui_window_options(UiWin *w, enum UiOption options) { +static void ui_window_options_set(UiWin *w, enum UiOption options) { UiCursesWin *win = (UiCursesWin*)w; win->options = options; - switch (options) { - case UI_OPTION_LINE_NUMBERS_NONE: + if (options & (UI_OPTION_LINE_NUMBERS_ABSOLUTE|UI_OPTION_LINE_NUMBERS_RELATIVE)) { + if (!win->winside) + win->winside = newwin(1, 1, 1, 1); + } else { if (win->winside) { delwin(win->winside); win->winside = NULL; win->sidebar_width = 0; } - break; - case UI_OPTION_LINE_NUMBERS_ABSOLUTE: - case UI_OPTION_LINE_NUMBERS_RELATIVE: - if (!win->winside) - win->winside = newwin(1, 1, 1, 1); - break; } ui_window_draw(w); } +static enum UiOption ui_window_options_get(UiWin *w) { + UiCursesWin *win = (UiCursesWin*)w; + return win->options; +} + static UiWin *ui_window_new(Ui *ui, View *view, File *file) { UiCurses *uic = (UiCurses*)ui; UiCursesWin *win = calloc(1, sizeof(UiCursesWin)); @@ -828,7 +829,8 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file) { .draw = ui_window_draw, .draw_status = ui_window_draw_status, .draw_text = ui_window_draw_text, - .options = ui_window_options, + .options_set = ui_window_options_set, + .options_get = ui_window_options_get, .reload = ui_window_reload, .syntax_style = ui_window_syntax_style, }; @@ -55,7 +55,8 @@ struct UiWin { void (*draw_text)(UiWin*, const Line*); void (*draw_status)(UiWin*); void (*reload)(UiWin*, File*); - void (*options)(UiWin*, enum UiOption); + void (*options_set)(UiWin*, enum UiOption); + enum UiOption (*options_get)(UiWin*); bool (*syntax_style)(UiWin*, int id, const char *style); }; @@ -873,6 +873,14 @@ int view_symbols_get(View *view) { return flags; } +void view_options_set(View *view, enum UiOption options) { + view->ui->options_set(view->ui, options); +} + +enum UiOption view_options_get(View *view) { + return view->ui->options_get(view->ui); +} + size_t view_screenline_goto(View *view, int n) { size_t pos = view->start; for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next) @@ -97,6 +97,9 @@ Syntax *view_syntax_get(View*); void view_symbols_set(View*, int flags); int view_symbols_get(View*); +void view_options_set(View*, enum UiOption options); +enum UiOption view_options_get(View*); + /* A view can manage multiple cursors, one of which (the main cursor) is always * placed within the visible viewport. All functions named view_cursor_* operate * on this cursor. Additional cursor can be created and manipulated using the @@ -1783,15 +1783,29 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { } view_symbols_set(vis->win->view, flags); break; - case OPTION_NUMBER: - editor_window_options(vis->win, arg.b ? UI_OPTION_LINE_NUMBERS_ABSOLUTE : - UI_OPTION_LINE_NUMBERS_NONE); + case OPTION_NUMBER: { + enum UiOption opt = view_options_get(vis->win->view); + if (arg.b) { + opt &= ~UI_OPTION_LINE_NUMBERS_RELATIVE; + opt |= UI_OPTION_LINE_NUMBERS_ABSOLUTE; + } else { + opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; + } + view_options_set(vis->win->view, opt); break; - case OPTION_NUMBER_RELATIVE: - editor_window_options(vis->win, arg.b ? UI_OPTION_LINE_NUMBERS_RELATIVE : - UI_OPTION_LINE_NUMBERS_NONE); + } + case OPTION_NUMBER_RELATIVE: { + enum UiOption opt = view_options_get(vis->win->view); + if (arg.b) { + opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; + opt |= UI_OPTION_LINE_NUMBERS_RELATIVE; + } else { + opt &= ~UI_OPTION_LINE_NUMBERS_RELATIVE; + } + view_options_set(vis->win->view, opt); break; } + } return true; } |
