Skip to content

Commit

Permalink
msgwin: factor out MessageWindow
Browse files Browse the repository at this point in the history
 * msgwin: factor out MessageWindow
 * msgwin: let the MessageWindow paint itself
 * msgwin: add helper functions
 * msgwin: use msgwin_set_height()
 * msgwin: use msgwin_get_width()
 * msgwin: use msgwin_clear_text()
 * msgwin: use msgwin_set_text()
 * msgwin: ask for a MessageWindow pointer
 * msgwin: convert the Progress Bar to use msgwin_get_window()
 * msgwin: hide the details of the MessageWindow
 * window: add window_is_focused()
  • Loading branch information
flatcap committed Jun 4, 2021
2 parents b61cd26 + 96dde18 commit d632573
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 171 deletions.
6 changes: 3 additions & 3 deletions Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ $(PWD)/email:
###############################################################################
# libgui
LIBGUI= libgui.a
LIBGUIOBJS= gui/color.o gui/curs_lib.o gui/dialog.o gui/mutt_curses.o \
gui/mutt_window.o gui/reflow.o gui/sbar.o gui/simple.o \
gui/terminal.o
LIBGUIOBJS= gui/color.o gui/curs_lib.o gui/dialog.o gui/msgwin.o \
gui/mutt_curses.o gui/mutt_window.o gui/reflow.o gui/sbar.o \
gui/simple.o gui/terminal.o
CLEANFILES+= $(LIBGUI) $(LIBGUIOBJS)
ALLOBJS+= $(LIBGUIOBJS)

Expand Down
11 changes: 6 additions & 5 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,10 @@ void ci_bounce_message(struct Mailbox *m, struct EmailList *el)
snprintf(scratch, sizeof(scratch),
ngettext("Bounce message to %s?", "Bounce messages to %s?", msg_count), buf);

if (mutt_strwidth(scratch) > (MessageWindow->state.cols - EXTRA_SPACE))
const size_t width = msgwin_get_width();
if (mutt_strwidth(scratch) > (width - EXTRA_SPACE))
{
mutt_simple_format(prompt, sizeof(prompt), 0, MessageWindow->state.cols - EXTRA_SPACE,
mutt_simple_format(prompt, sizeof(prompt), 0, width - EXTRA_SPACE,
JUSTIFY_LEFT, 0, scratch, sizeof(scratch), false);
mutt_str_cat(prompt, sizeof(prompt), "...?");
}
Expand All @@ -500,12 +501,12 @@ void ci_bounce_message(struct Mailbox *m, struct EmailList *el)
if (query_quadoption(c_bounce, prompt) != MUTT_YES)
{
mutt_addrlist_clear(&al);
mutt_window_clearline(MessageWindow, 0);
msgwin_clear_text();
mutt_message(ngettext("Message not bounced", "Messages not bounced", msg_count));
return;
}

mutt_window_clearline(MessageWindow, 0);
msgwin_clear_text();

struct Message *msg = NULL;
STAILQ_FOREACH(en, el, entries)
Expand Down Expand Up @@ -924,7 +925,7 @@ bool mutt_shell_escape(void)
return false;
}

mutt_window_clearline(MessageWindow, 0);
msgwin_clear_text();
mutt_endwin();
fflush(stdout);
int rc = mutt_system(buf);
Expand Down
14 changes: 9 additions & 5 deletions enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags fl
bool multiple, struct Mailbox *m, char ***files,
int *numfiles, struct EnterState *state)
{
int width = MessageWindow->state.cols - col - 1;
struct MuttWindow *win = msgwin_get_window();
if (!win)
return -1;

int width = win->state.cols - col - 1;
enum EnterRedrawFlags redraw = ENTER_REDRAW_NONE;
bool pass = (flags & MUTT_PASS);
bool first = true;
Expand Down Expand Up @@ -211,17 +215,17 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags fl
state->wbuf, state->lastchar,
mutt_mb_wcswidth(state->wbuf, state->curpos) - (width / 2));
}
mutt_window_move(MessageWindow, col, 0);
mutt_window_move(win, col, 0);
int w = 0;
for (size_t i = state->begin; i < state->lastchar; i++)
{
w += mutt_mb_wcwidth(state->wbuf[i]);
if (w > width)
break;
my_addwch(MessageWindow, state->wbuf[i]);
my_addwch(win, state->wbuf[i]);
}
mutt_window_clrtoeol(MessageWindow);
mutt_window_move(MessageWindow,
mutt_window_clrtoeol(win);
mutt_window_move(win,
col + mutt_mb_wcswidth(state->wbuf + state->begin,
state->curpos - state->begin),
0);
Expand Down
13 changes: 8 additions & 5 deletions flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,28 @@ int mutt_thread_set_flag(struct Mailbox *m, struct Email *e,
*/
int mutt_change_flag(struct Mailbox *m, struct EmailList *el, bool bf)
{
struct MuttWindow *win = msgwin_get_window();
if (!win)
return -1;

if (!m || !el || STAILQ_EMPTY(el))
return -1;

enum MessageType flag = MUTT_NONE;
struct KeyEvent event;

struct MuttWindow *old_focus = window_set_focus(MessageWindow);
struct MuttWindow *old_focus = window_set_focus(win);

mutt_window_mvprintw(MessageWindow, 0, 0,
"%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
mutt_window_clrtoeol(MessageWindow);
mutt_window_mvprintw(win, 0, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
mutt_window_clrtoeol(win);
window_redraw(RootWindow);

do
{
event = mutt_getch();
} while (event.ch == -2); // Timeout

mutt_window_clearline(MessageWindow, 0);
msgwin_clear_text();
window_set_focus(old_focus);

if (event.ch < 0) // SIGINT, Abort key (Ctrl-G)
Expand Down
Loading

0 comments on commit d632573

Please sign in to comment.