summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-08-31 22:32:38 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-08-31 22:32:38 +0200
commit12be3b8c332c75a398f77478fd8d62304c632a1e (patch)
treea8c49b9277d308372d02cb17d6583d1a27d54c41 /src/gui
parent5b5626a82ba5bf1418817f94c386cf436f71e008 (diff)
downloadweechat-12be3b8c332c75a398f77478fd8d62304c632a1e.zip
core: add options in command /input and new keys to remove/restore buffers in hotlist
New options in command /input: - hotlist_remove_buffer - hotlist_restore_buffer - hotlist_restore_all New keys: - alt+h, alt+c: clear the whole hotlist (former key: alt+h) - alt+h, alt+m: mark the current buffer as read by removing it from the hotlist - alt+h, alt+r: restore latest hotlist removed in the current buffer - alt+h, alt+shift+R: restore latest hotlist removed in all buffers
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-key.c5
-rw-r--r--src/gui/gui-buffer.c4
-rw-r--r--src/gui/gui-buffer.h1
-rw-r--r--src/gui/gui-hotlist.c86
-rw-r--r--src/gui/gui-hotlist.h1
-rw-r--r--src/gui/gui-input.c56
-rw-r--r--src/gui/gui-input.h3
7 files changed, 121 insertions, 35 deletions
diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c
index 16ebdf91b..3ee703080 100644
--- a/src/gui/curses/gui-curses-key.c
+++ b/src/gui/curses/gui-curses-key.c
@@ -137,7 +137,10 @@ gui_key_default_bindings (int context)
BIND(/* m-j,m-l */ "meta-jmeta-l", "/buffer +");
BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw");
BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump");
- BIND(/* m-h */ "meta-h", "/input hotlist_clear");
+ BIND(/* m-h,m-c */ "meta-hmeta-c", "/input hotlist_clear");
+ BIND(/* m-h,m-m */ "meta-hmeta-m", "/input hotlist_remove_buffer");
+ BIND(/* m-h,m-r */ "meta-hmeta-r", "/input hotlist_restore_buffer");
+ BIND(/* m-h,m-R */ "meta-hmeta-R", "/input hotlist_restore_all");
BIND(/* m-k */ "meta-k", "/input grab_key_command");
BIND(/* m-s */ "meta-s", "/mute spell toggle");
BIND(/* m-u */ "meta-u", "/window scroll_unread");
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 87493bcc4..411d48f4d 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -790,6 +790,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
/* hotlist */
new_buffer->hotlist = NULL;
+ new_buffer->hotlist_removed = NULL;
new_buffer->hotlist_max_level_nicks = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
@@ -2900,6 +2901,8 @@ gui_buffer_close (struct t_gui_buffer *buffer)
}
gui_hotlist_remove_buffer (buffer, 1);
+ if (buffer->hotlist_removed)
+ free (buffer->hotlist_removed);
if (gui_hotlist_initial_buffer == buffer)
gui_hotlist_initial_buffer = NULL;
@@ -4798,6 +4801,7 @@ gui_buffer_print_log ()
log_printf (" highlight_tags_count. . : %d", ptr_buffer->highlight_tags_count);
log_printf (" highlight_tags_array. . : 0x%lx", ptr_buffer->highlight_tags_array);
log_printf (" hotlist . . . . . . . . : 0x%lx", ptr_buffer->hotlist);
+ log_printf (" hotlist_removed . . . . : 0x%lx", ptr_buffer->hotlist_removed);
log_printf (" keys. . . . . . . . . . : 0x%lx", ptr_buffer->keys);
log_printf (" last_key. . . . . . . . : 0x%lx", ptr_buffer->last_key);
log_printf (" keys_count. . . . . . . : %d", ptr_buffer->keys_count);
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 8da63d62a..bcc8d4137 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -206,6 +206,7 @@ struct t_gui_buffer
/* hotlist */
struct t_gui_hotlist *hotlist; /* hotlist entry for buffer */
+ struct t_gui_hotlist *hotlist_removed; /* hotlist that can be restored */
struct t_hashtable *hotlist_max_level_nicks; /* max hotlist level for */
/* some nicks */
diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c
index 87eb46cd1..2de62215c 100644
--- a/src/gui/gui-hotlist.c
+++ b/src/gui/gui-hotlist.c
@@ -86,19 +86,55 @@ gui_hotlist_search (struct t_gui_hotlist *hotlist, struct t_gui_buffer *buffer)
}
/*
+ * Duplicates a hotlist element.
+ *
+ * Returns pointer to new hotlist, NULL if error.
+ */
+
+struct t_gui_hotlist *
+gui_hotlist_dup (struct t_gui_hotlist *hotlist)
+{
+ struct t_gui_hotlist *new_hotlist;
+
+ new_hotlist = malloc (sizeof (*new_hotlist));
+ if (!new_hotlist)
+ return NULL;
+
+ new_hotlist->priority = hotlist->priority;
+ memcpy (&(new_hotlist->creation_time), &(hotlist->creation_time),
+ sizeof (new_hotlist->creation_time));
+ new_hotlist->buffer = hotlist->buffer;
+ memcpy (new_hotlist->count, hotlist->count, sizeof (hotlist->count));
+ new_hotlist->prev_hotlist = NULL;
+ new_hotlist->next_hotlist = NULL;
+
+ return new_hotlist;
+}
+
+/*
* Frees a hotlist and removes it from hotlist queue.
*/
void
gui_hotlist_free (struct t_gui_hotlist **hotlist,
struct t_gui_hotlist **last_hotlist,
- struct t_gui_hotlist *ptr_hotlist)
+ struct t_gui_hotlist *ptr_hotlist,
+ int save_removed_hotlist)
{
struct t_gui_hotlist *new_hotlist;
if (!ptr_hotlist)
return;
+ if (save_removed_hotlist)
+ {
+ if (ptr_hotlist->buffer->hotlist_removed)
+ free (ptr_hotlist->buffer->hotlist_removed);
+ ptr_hotlist->buffer->hotlist_removed = gui_hotlist_dup (ptr_hotlist);
+ ptr_hotlist->buffer->hotlist_removed->prev_hotlist = NULL;
+ ptr_hotlist->buffer->hotlist_removed->next_hotlist = NULL;
+ }
+
ptr_hotlist->buffer->hotlist = NULL;
/* remove hotlist from queue */
@@ -130,7 +166,7 @@ gui_hotlist_free_all (struct t_gui_hotlist **hotlist,
/* remove all hotlists */
while (*hotlist)
{
- gui_hotlist_free (hotlist, last_hotlist, *hotlist);
+ gui_hotlist_free (hotlist, last_hotlist, *hotlist, 1);
}
}
@@ -391,7 +427,7 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
* and go on
*/
memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count));
- gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
+ gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist, 1);
}
new_hotlist = malloc (sizeof (*new_hotlist));
@@ -421,29 +457,31 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
}
/*
- * Duplicates a hotlist element.
- *
- * Returns pointer to new hotlist, NULL if error.
+ * Restores a hotlist that was removed from a buffer.
*/
-struct t_gui_hotlist *
-gui_hotlist_dup (struct t_gui_hotlist *hotlist)
+void
+gui_hotlist_restore_buffer (struct t_gui_buffer *buffer)
{
- struct t_gui_hotlist *new_hotlist;
+ struct t_gui_hotlist *ptr_hotlist;
- new_hotlist = malloc (sizeof (*new_hotlist));
- if (new_hotlist)
- {
- new_hotlist->priority = hotlist->priority;
- memcpy (&(new_hotlist->creation_time), &(hotlist->creation_time),
- sizeof (new_hotlist->creation_time));
- new_hotlist->buffer = hotlist->buffer;
- memcpy (new_hotlist->count, hotlist->count, sizeof (hotlist->count));
- new_hotlist->prev_hotlist = NULL;
- new_hotlist->next_hotlist = NULL;
- return new_hotlist;
- }
- return NULL;
+ if (!buffer->hotlist_removed)
+ return;
+
+ /* remove hotlist with buffer from list (if found) */
+ ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer);
+ if (ptr_hotlist)
+ gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist, 0);
+
+ /* restore the removed hotlist */
+ buffer->hotlist_removed->buffer = buffer;
+ ptr_hotlist = gui_hotlist_dup (buffer->hotlist_removed);
+ gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
+
+ free (buffer->hotlist_removed);
+ buffer->hotlist_removed = NULL;
+
+ gui_hotlist_changed_signal (buffer);
}
/*
@@ -503,7 +541,7 @@ gui_hotlist_clear (int level_mask)
ptr_next_hotlist = ptr_hotlist->next_hotlist;
if (level_mask & (1 << ptr_hotlist->priority))
{
- gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
+ gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist, 1);
hotlist_changed = 1;
}
ptr_hotlist = ptr_next_hotlist;
@@ -554,7 +592,7 @@ gui_hotlist_remove_buffer (struct t_gui_buffer *buffer,
if (buffer_to_remove)
{
- gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
+ gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist, 1);
hotlist_changed = 1;
}
diff --git a/src/gui/gui-hotlist.h b/src/gui/gui-hotlist.h
index 5904f149d..06dad0802 100644
--- a/src/gui/gui-hotlist.h
+++ b/src/gui/gui-hotlist.h
@@ -61,6 +61,7 @@ extern int gui_add_hotlist;
extern struct t_gui_hotlist *gui_hotlist_add (struct t_gui_buffer *buffer,
enum t_gui_hotlist_priority priority,
struct timeval *creation_time);
+extern void gui_hotlist_restore_buffer (struct t_gui_buffer *buffer);
extern void gui_hotlist_resort ();
extern void gui_hotlist_clear (int level_mask);
extern void gui_hotlist_remove_buffer (struct t_gui_buffer *buffer,
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index 97456275e..537d37487 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -642,7 +642,7 @@ gui_input_search_compile_regex (struct t_gui_buffer *buffer)
}
/*
- * Switches case for search in buffer (default key: meta-c during search).
+ * Switches case for search in buffer (default key: alt-c during search).
*/
void
@@ -894,7 +894,7 @@ gui_input_delete_previous_word (struct t_gui_buffer *buffer)
}
/*
- * Deletes next word (default key: meta-d).
+ * Deletes next word (default key: alt-d).
*/
void
@@ -1006,7 +1006,7 @@ gui_input_delete_end_of_line (struct t_gui_buffer *buffer)
}
/*
- * Deletes entire line (default key: meta-r).
+ * Deletes entire line (default key: alt-r).
*/
void
@@ -1121,7 +1121,7 @@ gui_input_move_next_char (struct t_gui_buffer *buffer)
}
/*
- * Moves cursor to beginning of previous word (default key: meta-b or
+ * Moves cursor to beginning of previous word (default key: alt-b or
* ctrl-left).
*/
@@ -1160,7 +1160,7 @@ gui_input_move_previous_word (struct t_gui_buffer *buffer)
}
/*
- * Moves cursor to the beginning of next word (default key: meta-f or
+ * Moves cursor to the beginning of next word (default key: alt-f or
* ctrl-right).
*/
@@ -1469,7 +1469,7 @@ gui_input_jump_smart (struct t_gui_buffer *buffer)
/*
* Jumps to last buffer displayed (before last jump to a buffer) (default key:
- * meta-/).
+ * alt-/).
*/
void
@@ -1489,7 +1489,7 @@ gui_input_jump_last_buffer_displayed (struct t_gui_buffer *buffer)
/*
* Jumps to previously visited buffer (buffer displayed before current one)
- * (default key: meta-<).
+ * (default key: alt-<).
*/
void
@@ -1523,7 +1523,7 @@ gui_input_jump_previously_visited_buffer (struct t_gui_buffer *buffer)
/*
* Jumps to next visited buffer (buffer displayed after current one) (default
- * key: meta->).
+ * key: alt->).
*/
void
@@ -1555,7 +1555,7 @@ gui_input_jump_next_visited_buffer (struct t_gui_buffer *buffer)
}
/*
- * Clears hotlist (default key: meta-h).
+ * Clears hotlist (default key: alt-h, alt-c).
*/
void
@@ -1621,8 +1621,44 @@ gui_input_hotlist_clear (struct t_gui_buffer *buffer,
}
/*
+ * Removes buffer from hotlist (default key: alt-h, alt-m).
+ */
+
+void
+gui_input_hotlist_remove_buffer (struct t_gui_buffer *buffer)
+{
+ gui_hotlist_remove_buffer (buffer, 1);
+}
+
+/*
+ * Restores latest hotlist removed in a buffer (default key: alt-h, alt-r).
+ */
+
+void
+gui_input_hotlist_restore_buffer (struct t_gui_buffer *buffer)
+{
+ gui_hotlist_restore_buffer (buffer);
+}
+
+/*
+ * Restores latest hotlist removed in all buffers (default key: alt-h, alt-R).
+ */
+
+void
+gui_input_hotlist_restore_all ()
+{
+ struct t_gui_buffer *ptr_buffer;
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ gui_hotlist_restore_buffer (ptr_buffer);
+ }
+}
+
+/*
* Initializes "grab key mode" (next key will be inserted into input buffer)
- * (default key: meta-k).
+ * (default key: alt-k).
*/
void
diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h
index 070bb98cc..4fe8eba4c 100644
--- a/src/gui/gui-input.h
+++ b/src/gui/gui-input.h
@@ -77,6 +77,9 @@ extern void gui_input_jump_previously_visited_buffer (struct t_gui_buffer *buffe
extern void gui_input_jump_next_visited_buffer (struct t_gui_buffer *buffer);
extern void gui_input_hotlist_clear (struct t_gui_buffer *buffer,
const char *level_mask);
+extern void gui_input_hotlist_remove_buffer (struct t_gui_buffer *buffer);
+extern void gui_input_hotlist_restore_buffer (struct t_gui_buffer *buffer);
+extern void gui_input_hotlist_restore_all ();
extern void gui_input_grab_key (struct t_gui_buffer *buffer, int command,
const char *delay);
extern void gui_input_grab_mouse (struct t_gui_buffer *buffer, int area);