Skip to content

Commit fab4f6b

Browse files
committed
Merge branch '4783_input_line_history_save'
* 4783_input_line_history_save: (panel_save_history): save history in any case. (mc_config_history_save): remove old history from config if new history is empty. (query_default_callback): clarify position of query dialog. Ticket #4783: input line: save modified history in any case.
2 parents 4c5f858 + 48ef840 commit fab4f6b

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

lib/mcconfig/history.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ mc_config_history_load (mc_config_t *cfg, const char *name)
186186

187187
/**
188188
* Save history to the mc_config, but don't save config to file
189+
*
190+
* @param cfg mc_config_t object where history is stored in
191+
* @param name history name
192+
* @param h history. If NULL, then the @name group will be removed from @cfg
189193
*/
190194
void
191195
mc_config_history_save (mc_config_t *cfg, const char *name, GList *h)
@@ -194,7 +198,12 @@ mc_config_history_save (mc_config_t *cfg, const char *name, GList *h)
194198
GString *buffer;
195199
int i;
196200

197-
if (name == NULL || *name == '\0' || h == NULL)
201+
if (name == NULL || *name == '\0')
202+
return;
203+
204+
mc_config_del_group (cfg, name);
205+
206+
if (h == NULL)
198207
return;
199208

200209
// go to end of list
@@ -204,8 +213,6 @@ mc_config_history_save (mc_config_t *cfg, const char *name, GList *h)
204213
for (i = 0; (i < num_history_items_recorded - 1) && (h->prev != NULL); i++)
205214
h = g_list_previous (h);
206215

207-
mc_config_del_group (cfg, name);
208-
209216
/* create charset conversion handler to convert strings
210217
from system codepage to UTF-8 */
211218
if (!mc_global.utf8_display)

lib/widget/input.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,18 @@ input_save_history (const gchar *event_group_name, const gchar *event_name, gpoi
842842
(void) event_name;
843843

844844
if (!in->is_password && (DIALOG (WIDGET (in)->owner)->ret_value != B_CANCEL))
845+
input_push_history (in);
846+
847+
// save modified history regardless of ret_value
848+
if (in->history.changed)
845849
{
846-
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
850+
const ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
847851

848-
input_push_history (in);
849-
if (in->history.changed)
850-
mc_config_history_save (ev->cfg, in->history.name, in->history.list);
851-
in->history.changed = FALSE;
852+
mc_config_history_save (ev->cfg, in->history.name, in->history.list);
852853
}
853854

855+
in->history.changed = FALSE;
856+
854857
return TRUE;
855858
}
856859

lib/widget/wtools.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ query_default_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, v
7575
if ((w->pos_flags & WPOS_CENTER) == 0)
7676
{
7777
WDialog *prev_dlg = NULL;
78-
int ypos, xpos;
79-
WRect r;
78+
int ypos;
79+
WRect r = { 0, 0, w->rect.lines, w->rect.cols };
8080

8181
// get dialog under h
8282
if (top_dlg != NULL)
@@ -101,14 +101,13 @@ query_default_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, v
101101
else
102102
ypos = WIDGET (prev_dlg)->rect.y + 2;
103103

104-
// if dialog is too high, place it centered
105-
if (ypos + w->rect.lines < LINES / 2)
106-
w->pos_flags |= WPOS_CENTER;
107-
108-
xpos = COLS / 2 - w->rect.cols / 2;
104+
// if dialog is too high or too low, place it centered
105+
if (ypos + w->rect.lines < LINES / 2 || ypos > LINES / 2)
106+
w->pos_flags |= WPOS_CENTER_VERT;
107+
else
108+
r.y = ypos;
109109

110-
// set position
111-
rect_init (&r, ypos, xpos, w->rect.lines, w->rect.cols);
110+
w->pos_flags |= WPOS_CENTER_HORZ;
112111

113112
return dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
114113
}

src/filemanager/panel.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,16 +1377,12 @@ panel_save_history (const gchar *event_group_name, const gchar *event_name, gpoi
13771377
gpointer data)
13781378
{
13791379
WPanel *p = PANEL (init_data);
1380+
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
13801381

13811382
(void) event_group_name;
13821383
(void) event_name;
13831384

1384-
if (p->dir_history.list != NULL)
1385-
{
1386-
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
1387-
1388-
mc_config_history_save (ev->cfg, p->dir_history.name, p->dir_history.list);
1389-
}
1385+
mc_config_history_save (ev->cfg, p->dir_history.name, p->dir_history.list);
13901386

13911387
return TRUE;
13921388
}

0 commit comments

Comments
 (0)