diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 5501ba46a..8651ebca8 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -42,6 +42,7 @@ #include "lib/strutil.h" #include "lib/fileloc.h" /* MC_HISTORY_FILE */ #include "lib/event.h" /* mc_event_raise() */ +#include "lib/util.h" /* MC_PTR_FREE */ #include "lib/widget.h" #include "lib/widget/mouse.h" @@ -653,6 +654,7 @@ dlg_default_repaint (WDialog * h) if (h->title != NULL) { + /* TODO: truncate long title */ tty_setcolor (h->color[DLG_COLOR_TITLE]); widget_move (h, space, (wh->cols - str_term_width1 (h->title)) / 2); tty_print_string (h->title); @@ -783,16 +785,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag new_d->mouse_status = MOU_UNHANDLED; - /* Strip existing spaces, add one space before and after the title */ - if (title != NULL && *title != '\0') - { - char *t; - - t = g_strstrip (g_strdup (title)); - if (*t != '\0') - new_d->title = g_strdup_printf (" %s ", t); - g_free (t); - } + dlg_set_title (new_d, title); /* unique name of event group for this dialog */ new_d->event_group = g_strdup_printf ("%s_%p", MCEVENT_GROUP_DIALOG, (void *) new_d); @@ -1257,6 +1250,25 @@ dlg_save_history (WDialog * h) /* --------------------------------------------------------------------------------------------- */ +void +dlg_set_title (WDialog * h, const char *title) +{ + MC_PTR_FREE (h->title); + + /* Strip existing spaces, add one space before and after the title */ + if (title != NULL && title[0] != '\0') + { + char *t; + + t = g_strstrip (g_strdup (title)); + if (t[0] != '\0') + h->title = g_strdup_printf (" %s ", t); + g_free (t); + } +} + +/* --------------------------------------------------------------------------------------------- */ + char * dlg_get_title (const WDialog * h, size_t len) { diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h index 1185ccac9..f4bc154fa 100644 --- a/lib/widget/dialog.h +++ b/lib/widget/dialog.h @@ -131,6 +131,7 @@ void dlg_run_done (WDialog * h); void dlg_save_history (WDialog * h); void dlg_process_event (WDialog * h, int key, Gpm_Event * event); +void dlg_set_title (WDialog * h, const char *title); char *dlg_get_title (const WDialog * h, size_t len); void dlg_redraw (WDialog * h);