summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2016-01-11 21:04:48 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2016-01-11 21:04:48 +0100
commitbd2c549064314cbff8ff0a52842d410d59f74ae6 (patch)
tree50680fa7e687fb60536fdd1d570e303f267cd23a /src
parent8f370959691185127a38f70a7de002e64a65310e (diff)
parentad842ea8a60f107d68df4298a8914e66edf95c3b (diff)
downloadirssi-bd2c549064314cbff8ff0a52842d410d59f74ae6.zip
Merge pull request #394 from ailin-nemui/reset-history
option to clear the history
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/command-history.c35
-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
-rw-r--r--src/fe-text/gui-readline.c15
6 files changed, 63 insertions, 17 deletions
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index f9c3884c..1060744e 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -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);
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..9e4aab3a 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 | 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)
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index fcf152e8..5acfaf60 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -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);