This commit is contained in:
Jari Matilainen 2016-01-09 19:55:26 +00:00
commit a459e7b18a
3 changed files with 36 additions and 6 deletions

View file

@ -104,6 +104,18 @@ HISTORY_REC *command_history_current(WINDOW_REC *window)
return global_history;
}
void command_history_clear(WINDOW_REC *window)
{
if (window_history) {
if (command_history_destroy(window->history))
window->history = command_history_create(NULL);
}
else {
if (command_history_destroy(global_history))
global_history = command_history_create(NULL);
}
}
const char *command_history_prev(WINDOW_REC *window, const char *text)
{
HISTORY_REC *history;
@ -178,12 +190,12 @@ HISTORY_REC *command_history_create(const char *name)
return rec;
}
void command_history_destroy(HISTORY_REC *history)
int command_history_destroy(HISTORY_REC *history)
{
g_return_if_fail(history != NULL);
g_return_val_if_fail(history != NULL, FALSE);
/* history->refcount should be 0 here, or somthing is wrong... */
g_return_if_fail(history->refcount == 0);
g_return_val_if_fail(history->refcount == 0, FALSE);
histories = g_slist_remove(histories, history);
@ -192,6 +204,8 @@ void command_history_destroy(HISTORY_REC *history)
g_free_not_null(history->name);
g_free(history);
return TRUE;
}
void command_history_link(const char *name)

View file

@ -26,9 +26,10 @@ const char *command_history_prev(WINDOW_REC *window, const char *text);
const char *command_history_next(WINDOW_REC *window, const char *text);
void command_history_clear_pos(WINDOW_REC *window);
void command_history_clear(WINDOW_REC *window);
HISTORY_REC *command_history_create(const char *name);
void command_history_destroy(HISTORY_REC *history);
int command_history_destroy(HISTORY_REC *history);
void command_history_link(const char *name);
void command_history_unlink(const char *name);

View file

@ -33,6 +33,7 @@
#include "window-items.h"
#include "windows-layout.h"
#include "printtext.h"
#include "command-history.h"
static void window_print_binds(WINDOW_REC *win)
{
@ -615,10 +616,23 @@ static void cmd_window_name(const char *data)
}
}
/* SYNTAX: WINDOW HISTORY <name> */
/* SYNTAX: WINDOW HISTORY [-clear] <name> */
void cmd_window_history(const char *data)
{
window_set_history(active_win, data);
GHashTable *optlist;
char *name;
void *free_arg;
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
"window history", &optlist, &name))
return;
if (*name == '\0' && g_hash_table_lookup(optlist, "clear") != NULL)
command_history_clear(active_win);
else if (*name != '\0')
window_set_history(active_win, name);
cmd_params_free(free_arg);
}
/* we're moving the first window to last - move the first contiguous block
@ -883,6 +897,7 @@ void window_commands_init(void)
command_set_options("window number", "sticky");
command_set_options("window server", "sticky unsticky");
command_set_options("window theme", "delete");
command_set_options("window history", "clear");
}
void window_commands_deinit(void)