From 9ad2d3231196d37138009907fa1db3f6f0a5365e Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Sun, 4 Oct 2015 16:56:50 +0200 Subject: [PATCH 1/3] work in progress --- src/fe-common/core/command-history.c | 20 +++++++++++++++++--- src/fe-common/core/window-commands.c | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c index f9c3884c..c246a5db 100644 --- a/src/fe-common/core/command-history.c +++ b/src/fe-common/core/command-history.c @@ -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) +bool 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) diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index c6ab68c0..5254c580 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -883,6 +883,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) From 9db14f100e8036f7489fd5a11c485a1ad872de85 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Thu, 8 Oct 2015 12:37:02 +0200 Subject: [PATCH 2/3] Add /window history -clear to wipe out command history for window or the global history --- src/fe-common/core/command-history.c | 2 +- src/fe-common/core/command-history.h | 3 ++- src/fe-common/core/window-commands.c | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c index c246a5db..aeafa6c8 100644 --- a/src/fe-common/core/command-history.c +++ b/src/fe-common/core/command-history.c @@ -190,7 +190,7 @@ HISTORY_REC *command_history_create(const char *name) return rec; } -bool command_history_destroy(HISTORY_REC *history) +int command_history_destroy(HISTORY_REC *history) { g_return_val_if_fail(history != NULL, FALSE); diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h index 7b76246b..97152fe5 100644 --- a/src/fe-common/core/command-history.h +++ b/src/fe-common/core/command-history.h @@ -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); diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index 5254c580..201bf394 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,23 @@ static void cmd_window_name(const char *data) } } -/* SYNTAX: WINDOW HISTORY */ +/* SYNTAX: WINDOW HISTORY [-clear] */ 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 From 76c97caba21bb2b8d633c91639b6944f9c909489 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Sun, 25 Oct 2015 17:10:32 +0100 Subject: [PATCH 3/3] Changed tab to spaces in a couple of places --- src/fe-common/core/command-history.c | 16 ++++++++-------- src/fe-common/core/window-commands.c | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c index aeafa6c8..c1e1bcdc 100644 --- a/src/fe-common/core/command-history.c +++ b/src/fe-common/core/command-history.c @@ -106,14 +106,14 @@ HISTORY_REC *command_history_current(WINDOW_REC *window) 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); - } + 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) diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index 201bf394..8b31a507 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -628,11 +628,11 @@ void cmd_window_history(const char *data) 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); + command_history_clear(active_win); + else if (*name != '\0') + window_set_history(active_win, name); - cmd_params_free(free_arg); + cmd_params_free(free_arg); } /* we're moving the first window to last - move the first contiguous block