mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #394 from ailin-nemui/reset-history
option to clear the history
This commit is contained in:
commit
bd2c549064
@ -94,13 +94,13 @@ HISTORY_REC *command_history_current(WINDOW_REC *window)
|
||||
if (window == NULL)
|
||||
return global_history;
|
||||
|
||||
if (window_history)
|
||||
return window->history;
|
||||
|
||||
rec = command_history_find_name(window->history_name);
|
||||
if (rec != NULL)
|
||||
return rec;
|
||||
|
||||
if (window_history)
|
||||
return window->history;
|
||||
|
||||
return global_history;
|
||||
}
|
||||
|
||||
@ -178,6 +178,17 @@ HISTORY_REC *command_history_create(const char *name)
|
||||
return rec;
|
||||
}
|
||||
|
||||
void command_history_clear(HISTORY_REC *history)
|
||||
{
|
||||
g_return_if_fail(history != NULL);
|
||||
|
||||
command_history_clear_pos_func(history, NULL);
|
||||
g_list_foreach(history->list, (GFunc) g_free, NULL);
|
||||
g_list_free(history->list);
|
||||
history->list = NULL;
|
||||
history->lines = 0;
|
||||
}
|
||||
|
||||
void command_history_destroy(HISTORY_REC *history)
|
||||
{
|
||||
g_return_if_fail(history != NULL);
|
||||
@ -186,9 +197,7 @@ void command_history_destroy(HISTORY_REC *history)
|
||||
g_return_if_fail(history->refcount == 0);
|
||||
|
||||
histories = g_slist_remove(histories, history);
|
||||
|
||||
g_list_foreach(history->list, (GFunc) g_free, NULL);
|
||||
g_list_free(history->list);
|
||||
command_history_clear(history);
|
||||
|
||||
g_free_not_null(history->name);
|
||||
g_free(history);
|
||||
@ -229,6 +238,18 @@ static void sig_window_destroyed(WINDOW_REC *window)
|
||||
g_free_not_null(window->history_name);
|
||||
}
|
||||
|
||||
static void sig_window_history_cleared(WINDOW_REC *window, const char *name) {
|
||||
HISTORY_REC *history;
|
||||
|
||||
if (name == NULL || *name == '\0') {
|
||||
history = command_history_current(window);
|
||||
} else {
|
||||
history = command_history_find_name(name);
|
||||
}
|
||||
|
||||
command_history_clear(history);
|
||||
}
|
||||
|
||||
static void sig_window_history_changed(WINDOW_REC *window, const char *oldname)
|
||||
{
|
||||
command_history_link(window->history_name);
|
||||
@ -279,6 +300,7 @@ void command_history_init(void)
|
||||
signal_add("window created", (SIGNAL_FUNC) sig_window_created);
|
||||
signal_add("window destroyed", (SIGNAL_FUNC) sig_window_destroyed);
|
||||
signal_add("window history changed", (SIGNAL_FUNC) sig_window_history_changed);
|
||||
signal_add_last("window history cleared", (SIGNAL_FUNC) sig_window_history_cleared);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
}
|
||||
|
||||
@ -287,6 +309,7 @@ void command_history_deinit(void)
|
||||
signal_remove("window created", (SIGNAL_FUNC) sig_window_created);
|
||||
signal_remove("window destroyed", (SIGNAL_FUNC) sig_window_destroyed);
|
||||
signal_remove("window history changed", (SIGNAL_FUNC) sig_window_history_changed);
|
||||
signal_remove("window history cleared", (SIGNAL_FUNC) sig_window_history_cleared);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_history_destroy(global_history);
|
||||
|
@ -28,6 +28,7 @@ const char *command_history_next(WINDOW_REC *window, const char *text);
|
||||
void command_history_clear_pos(WINDOW_REC *window);
|
||||
|
||||
HISTORY_REC *command_history_create(const char *name);
|
||||
void command_history_clear(HISTORY_REC *history);
|
||||
void command_history_destroy(HISTORY_REC *history);
|
||||
void command_history_link(const char *name);
|
||||
void command_history_unlink(const char *name);
|
||||
|
@ -229,11 +229,16 @@ void window_set_history(WINDOW_REC *window, const char *name)
|
||||
else
|
||||
window->history_name = g_strdup(name);
|
||||
|
||||
signal_emit("window history changed", 1, window, oldname);
|
||||
signal_emit("window history changed", 2, window, oldname);
|
||||
|
||||
g_free_not_null(oldname);
|
||||
}
|
||||
|
||||
void window_clear_history(WINDOW_REC *window, const char *name)
|
||||
{
|
||||
signal_emit("window history cleared", 2, window, name);
|
||||
}
|
||||
|
||||
void window_set_level(WINDOW_REC *window, int level)
|
||||
{
|
||||
g_return_if_fail(window != NULL);
|
||||
|
@ -66,6 +66,7 @@ void window_change_server(WINDOW_REC *window, void *server);
|
||||
void window_set_refnum(WINDOW_REC *window, int refnum);
|
||||
void window_set_name(WINDOW_REC *window, const char *name);
|
||||
void window_set_history(WINDOW_REC *window, const char *name);
|
||||
void window_clear_history(WINDOW_REC *window, const char *name);
|
||||
void window_set_level(WINDOW_REC *window, int level);
|
||||
void window_set_immortal(WINDOW_REC *window, int immortal);
|
||||
|
||||
|
@ -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,25 @@ 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 | PARAM_FLAG_STRIP_TRAILING_WS,
|
||||
"window history", &optlist, &name))
|
||||
return;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "clear") != NULL) {
|
||||
signal_continue(1, data);
|
||||
window_clear_history(active_win, name);
|
||||
} else {
|
||||
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 +899,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)
|
||||
|
@ -456,22 +456,21 @@ static void key_send_line(void)
|
||||
add_history = *str != '\0';
|
||||
history = command_history_current(active_win);
|
||||
|
||||
if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
|
||||
add_history = 0;
|
||||
|
||||
if (add_history && history != NULL) {
|
||||
command_history_add(history, str);
|
||||
}
|
||||
|
||||
if (redir == NULL) {
|
||||
signal_emit("send command", 3, str,
|
||||
active_win->active_server,
|
||||
active_win->active);
|
||||
} else {
|
||||
if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
|
||||
add_history = 0;
|
||||
handle_entry_redirect(str);
|
||||
}
|
||||
|
||||
if (add_history) {
|
||||
history = command_history_find(history);
|
||||
if (history != NULL)
|
||||
command_history_add(history, str);
|
||||
}
|
||||
|
||||
if (active_entry != NULL)
|
||||
gui_entry_set_text(active_entry, "");
|
||||
command_history_clear_pos(active_win);
|
||||
|
Loading…
Reference in New Issue
Block a user