(mc_config_history_get_recent_item): new API.

* (edit_search_cmd): use mc_config_history_get_recent_item().
  * (mcview_continue_search_cmd): likewise.

mc_config_history_get_recent_item() is not implemented optimally yet.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-10-29 15:10:48 +03:00
parent 018687b12f
commit a74d638155
4 changed files with 40 additions and 19 deletions

View File

@ -105,6 +105,8 @@ vfs_path_t *mc_config_get_full_vpath (const char *config_name);
/* read history to the mc_config, but don't save config to file */
GList *mc_config_history_get (const char *name);
/* read recent item from the history */
char *mc_config_history_get_recent_item (const char *name);
/* load history from the mc_config */
GList *mc_config_history_load (mc_config_t * cfg, const char *name);
/* save history to the mc_config, but don't save config to file */

View File

@ -94,6 +94,33 @@ mc_config_history_get (const char *name)
/* --------------------------------------------------------------------------------------------- */
/**
* Get the recent item of a history from the ${XDG_DATA_HOME}/mc/history file.
*
* TODO: get rid of load the entire history to get the only top item.
*/
char *
mc_config_history_get_recent_item (const char *name)
{
GList *history;
char *item = NULL;
history = mc_config_history_get (name);
if (history != NULL)
{
/* FIXME: can history->data be NULL? */
item = (char *) history->data;
history->data = NULL;
history = g_list_first (history);
g_list_free_full (history, g_free);
}
return item;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load history from the mc_config
*/

View File

@ -29,7 +29,7 @@
#include "lib/global.h"
#include "lib/search.h"
#include "lib/mcconfig.h" /* mc_config_history_get */
#include "lib/mcconfig.h" /* mc_config_history_get_recent_item() */
#ifdef HAVE_CHARSET
#include "lib/charsets.h" /* cp_source */
#endif
@ -780,16 +780,12 @@ edit_search_cmd (WEdit * edit, gboolean again)
else
{
/* find last search string in history */
GList *history;
char *s;
history = mc_config_history_get (MC_HISTORY_SHARED_SEARCH);
if (history != NULL)
s = mc_config_history_get_recent_item (MC_HISTORY_SHARED_SEARCH);
if (s != NULL)
{
/* FIXME: is it possible that history->data == NULL? */
edit->last_search_string = (char *) history->data;
history->data = NULL;
history = g_list_first (history);
g_list_free_full (history, g_free);
edit->last_search_string = s;
if (edit_search_init (edit, edit->last_search_string))
{

View File

@ -57,13 +57,13 @@
#include "lib/charsets.h"
#endif
#include "lib/event.h" /* mc_event_raise() */
#include "lib/mcconfig.h" /* mc_config_history_get() */
#include "lib/mcconfig.h" /* mc_config_history_get_recent_item() */
#include "src/filemanager/layout.h"
#include "src/filemanager/filemanager.h" /* current_panel */
#include "src/filemanager/ext.h" /* regex_command_for() */
#include "src/history.h"
#include "src/history.h" /* MC_HISTORY_SHARED_SEARCH */
#include "src/file_history.h" /* show_file_history() */
#include "src/execute.h"
#include "src/keymap.h"
@ -139,16 +139,12 @@ mcview_continue_search_cmd (WView * view)
else
{
/* find last search string in history */
GList *history;
char *s;
history = mc_config_history_get (MC_HISTORY_SHARED_SEARCH);
if (history != NULL)
s = mc_config_history_get_recent_item (MC_HISTORY_SHARED_SEARCH);
if (s != NULL)
{
/* FIXME: is it possible that history->data == NULL? */
view->last_search_string = (gchar *) history->data;
history->data = NULL;
history = g_list_first (history);
g_list_free_full (history, g_free);
view->last_search_string = s;
if (mcview_search_init (view))
{