summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2015-12-15 01:52:44 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2016-01-08 15:19:13 +0100
commit4659cea65a663b11f3cc16e1d03c9955a4135238 (patch)
treed3966d97a49c08b8bbc9c98759e25819824a0db0 /src
parentbe6d7629e3e58102e5c7599943974cc39c9b172c (diff)
downloadirssi-4659cea65a663b11f3cc16e1d03c9955a4135238.zip
option to clear the history
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/command-history.c45
-rw-r--r--src/fe-common/core/command-history.h1
-rw-r--r--src/fe-common/core/fe-windows.c7
-rw-r--r--src/fe-common/core/fe-windows.h1
-rw-r--r--src/fe-common/core/window-commands.c21
5 files changed, 66 insertions, 9 deletions
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index f9c3884c..9f46ee99 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -33,6 +33,7 @@
static HISTORY_REC *global_history;
static int window_history;
static GSList *histories;
+static HISTORY_REC *last_cleared_history;
void command_history_add(HISTORY_REC *history, const char *text)
{
@@ -41,6 +42,13 @@ void command_history_add(HISTORY_REC *history, const char *text)
g_return_if_fail(history != NULL);
g_return_if_fail(text != NULL);
+ if (last_cleared_history == history) {
+ last_cleared_history = NULL;
+ return; /* ignore this history addition, we just
+ cleared it */
+ }
+ last_cleared_history = NULL;
+
link = g_list_last(history->list);
if (link != NULL && g_strcmp0(link->data, text) == 0)
return; /* same as previous entry */
@@ -94,13 +102,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 +186,18 @@ 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;
+ last_cleared_history = history;
+}
+
void command_history_destroy(HISTORY_REC *history)
{
g_return_if_fail(history != NULL);
@@ -186,9 +206,8 @@ 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);
+ last_cleared_history = NULL; /* was destroyed */
g_free_not_null(history->name);
g_free(history);
@@ -229,6 +248,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 +310,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 +319,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);
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index 7b76246b..a572216b 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -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);
diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c
index 1049137f..46c1593b 100644
--- a/src/fe-common/core/fe-windows.c
+++ b/src/fe-common/core/fe-windows.c
@@ -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);
diff --git a/src/fe-common/core/fe-windows.h b/src/fe-common/core/fe-windows.h
index 613f15f8..32d6cfcd 100644
--- a/src/fe-common/core/fe-windows.h
+++ b/src/fe-common/core/fe-windows.h
@@ -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);
diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c
index c6ab68c0..e5005144 100644
--- a/src/fe-common/core/window-commands.c
+++ b/src/fe-common/core/window-commands.c
@@ -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,
+ "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)