summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-12-08 23:54:07 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-12-08 23:54:07 +0100
commit641de51bdbd449196c0d54102d17641cd4b5d3d7 (patch)
tree820e555781f6cb2d55bd06b5b71ee9ef083436d9 /src/gui
parent3f2155e548c0ebe86a694f69630f41d7503f679c (diff)
downloadweechat-641de51bdbd449196c0d54102d17641cd4b5d3d7.zip
api: allow creation of structure with hdata_update (allowed for hdata "history")
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-bar-item.c2
-rw-r--r--src/gui/gui-bar-window.c2
-rw-r--r--src/gui/gui-bar.c2
-rw-r--r--src/gui/gui-buffer.c6
-rw-r--r--src/gui/gui-completion.c4
-rw-r--r--src/gui/gui-filter.c2
-rw-r--r--src/gui/gui-history.c128
-rw-r--r--src/gui/gui-history.h6
-rw-r--r--src/gui/gui-hotlist.c2
-rw-r--r--src/gui/gui-input.c10
-rw-r--r--src/gui/gui-key.c2
-rw-r--r--src/gui/gui-line.c6
-rw-r--r--src/gui/gui-nicklist.c4
-rw-r--r--src/gui/gui-window.c6
14 files changed, 121 insertions, 61 deletions
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index f4efc03b0..25a584344 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -1900,7 +1900,7 @@ gui_bar_item_hdata_bar_item_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_item", "next_item",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_bar_item, plugin, POINTER, 0, NULL, "plugin");
diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c
index 66ac6f6e5..29406b49f 100644
--- a/src/gui/gui-bar-window.c
+++ b/src/gui/gui-bar-window.c
@@ -1405,7 +1405,7 @@ gui_bar_window_hdata_bar_window_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_bar_window", "next_bar_window",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_bar_window, bar, POINTER, 0, NULL, "bar");
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index 66c839416..32fb6f33a 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -2253,7 +2253,7 @@ gui_bar_hdata_bar_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_bar", "next_bar",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_bar, name, STRING, 0, NULL, NULL);
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 05cb8aa77..db9879506 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -3151,7 +3151,7 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_buffer", "next_buffer",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_buffer, plugin, POINTER, 0, NULL, "plugin");
@@ -3240,7 +3240,7 @@ gui_buffer_hdata_input_undo_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_undo", "next_undo",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_input_undo, data, STRING, 0, NULL, NULL);
@@ -3264,7 +3264,7 @@ gui_buffer_hdata_buffer_visited_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_buffer", "next_buffer",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_buffer_visited, buffer, POINTER, 0, NULL, "buffer");
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 74581da13..e83c00f3b 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -1215,7 +1215,7 @@ gui_completion_hdata_completion_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, NULL, NULL,
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_completion, buffer, POINTER, 0, NULL, "buffer");
@@ -1255,7 +1255,7 @@ gui_completion_hdata_completion_partial_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_item", "next_item",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_completion_partial, word, STRING, 0, NULL, NULL);
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index 8df37a261..01a45c833 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -450,7 +450,7 @@ gui_filter_hdata_filter_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_filter", "next_filter",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_filter, enabled, INTEGER, 0, NULL, NULL);
diff --git a/src/gui/gui-history.c b/src/gui/gui-history.c
index c9071ccee..01d82284a 100644
--- a/src/gui/gui-history.c
+++ b/src/gui/gui-history.c
@@ -27,11 +27,13 @@
#endif
#include <stdlib.h>
+#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "../core/weechat.h"
#include "../core/wee-config.h"
+#include "../core/wee-hashtable.h"
#include "../core/wee-hdata.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
@@ -41,10 +43,10 @@
#include "gui-buffer.h"
-struct t_gui_history *history_global = NULL;
-struct t_gui_history *last_history_global = NULL;
-struct t_gui_history *history_global_ptr = NULL;
-int num_history_global = 0;
+struct t_gui_history *gui_history = NULL;
+struct t_gui_history *last_gui_history = NULL;
+struct t_gui_history *gui_history_ptr = NULL;
+int num_gui_history = 0;
/*
@@ -106,36 +108,36 @@ gui_history_global_add (const char *string)
if (!string)
return;
- if (!history_global
- || (history_global
- && (strcmp (history_global->text, string) != 0)))
+ if (!gui_history
+ || (gui_history
+ && (strcmp (gui_history->text, string) != 0)))
{
new_history = malloc (sizeof (*new_history));
if (new_history)
{
new_history->text = strdup (string);
- if (history_global)
- history_global->prev_history = new_history;
+ if (gui_history)
+ gui_history->prev_history = new_history;
else
- last_history_global = new_history;
- new_history->next_history = history_global;
+ last_gui_history = new_history;
+ new_history->next_history = gui_history;
new_history->prev_history = NULL;
- history_global = new_history;
- num_history_global++;
+ gui_history = new_history;
+ num_gui_history++;
/* remove one command if necessary */
if ((CONFIG_INTEGER(config_history_max_commands) > 0)
- && (num_history_global > CONFIG_INTEGER(config_history_max_commands)))
+ && (num_gui_history > CONFIG_INTEGER(config_history_max_commands)))
{
- ptr_history = last_history_global->prev_history;
- if (history_global_ptr == last_history_global)
- history_global_ptr = ptr_history;
- (last_history_global->prev_history)->next_history = NULL;
- if (last_history_global->text)
- free (last_history_global->text);
- free (last_history_global);
- last_history_global = ptr_history;
- num_history_global--;
+ ptr_history = last_gui_history->prev_history;
+ if (gui_history_ptr == last_gui_history)
+ gui_history_ptr = ptr_history;
+ (last_gui_history->prev_history)->next_history = NULL;
+ if (last_gui_history->text)
+ free (last_gui_history->text);
+ free (last_gui_history);
+ last_gui_history = ptr_history;
+ num_gui_history--;
}
}
}
@@ -177,18 +179,18 @@ gui_history_global_free ()
{
struct t_gui_history *ptr_history;
- while (history_global)
+ while (gui_history)
{
- ptr_history = history_global->next_history;
- if (history_global->text)
- free (history_global->text);
- free (history_global);
- history_global = ptr_history;
+ ptr_history = gui_history->next_history;
+ if (gui_history->text)
+ free (gui_history->text);
+ free (gui_history);
+ gui_history = ptr_history;
}
- history_global = NULL;
- last_history_global = NULL;
- history_global_ptr = NULL;
- num_history_global = 0;
+ gui_history = NULL;
+ last_gui_history = NULL;
+ gui_history_ptr = NULL;
+ num_gui_history = 0;
}
@@ -216,6 +218,62 @@ gui_history_buffer_free (struct t_gui_buffer *buffer)
}
/*
+ * gui_history_hdata_history_update_cb: callback for updating history
+ */
+
+int
+gui_history_hdata_history_update_cb (void *data,
+ struct t_hdata *hdata,
+ void *pointer,
+ struct t_hashtable *hashtable)
+{
+ struct t_gui_history *ptr_history;
+ struct t_gui_buffer *ptr_buffer;
+ const char *text, *buffer;
+ long unsigned int value;
+ int rc;
+
+ /* make C compiler happy */
+ (void) data;
+
+ rc = 0;
+
+ text = hashtable_get (hashtable, "text");
+ if (!text)
+ return rc;
+
+ if (pointer)
+ {
+ /* update history */
+ ptr_history = (struct t_gui_history *)pointer;
+ if (ptr_history->text)
+ free (ptr_history->text);
+ ptr_history->text = strdup (text);
+ }
+ else
+ {
+ /* create new entry in history */
+ ptr_buffer = NULL;
+ if (hashtable_has_key (hashtable, "buffer"))
+ {
+ buffer = hashtable_get (hashtable, "buffer");
+ if (buffer)
+ {
+ rc = sscanf (buffer, "%lx", &value);
+ if ((rc != EOF) && (rc != 0))
+ ptr_buffer = (struct t_gui_buffer *)value;
+ }
+ }
+ if (ptr_buffer)
+ gui_history_add (ptr_buffer, text);
+ else
+ gui_history_global_add (text);
+ }
+
+ return rc;
+}
+
+/*
* gui_history_hdata_history_cb: return hdata for history
*/
@@ -228,12 +286,14 @@ gui_history_hdata_history_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_history", "next_history",
- 0, NULL, NULL);
+ 1, 1, &gui_history_hdata_history_update_cb, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_history, text, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_history, prev_history, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_history, next_history, POINTER, 0, NULL, hdata_name);
+ HDATA_LIST(gui_history);
+ HDATA_LIST(last_gui_history);
}
return hdata;
}
diff --git a/src/gui/gui-history.h b/src/gui/gui-history.h
index 79bce5230..7a4447cec 100644
--- a/src/gui/gui-history.h
+++ b/src/gui/gui-history.h
@@ -29,9 +29,9 @@ struct t_gui_history
struct t_gui_history *prev_history;/* link to previous text/command */
};
-extern struct t_gui_history *history_global;
-extern struct t_gui_history *last_history_global;
-extern struct t_gui_history *history_global_ptr;
+extern struct t_gui_history *gui_history;
+extern struct t_gui_history *last_gui_history;
+extern struct t_gui_history *gui_history_ptr;
extern void gui_history_buffer_add (struct t_gui_buffer *buffer,
const char *string);
diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c
index 7ebc9750e..1837897ea 100644
--- a/src/gui/gui-hotlist.c
+++ b/src/gui/gui-hotlist.c
@@ -475,7 +475,7 @@ gui_hotlist_hdata_hotlist_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_hotlist", "next_hotlist",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_hotlist, priority, INTEGER, 0, NULL, NULL);
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index a4dc2ef69..735d335bb 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -391,7 +391,7 @@ gui_input_return (struct t_gui_buffer *buffer)
gui_completion_stop (window->buffer->completion, 1);
gui_buffer_undo_free_all (window->buffer);
window->buffer->ptr_history = NULL;
- history_global_ptr = NULL;
+ gui_history_ptr = NULL;
gui_input_optimize_size (window->buffer);
gui_input_text_changed_modifier_and_signal (window->buffer, 0);
input_data (window->buffer, command);
@@ -1215,8 +1215,8 @@ gui_input_history_global_previous (struct t_gui_buffer *buffer)
if (window)
{
gui_input_history_previous (window,
- history_global,
- &history_global_ptr);
+ gui_history,
+ &gui_history_ptr);
}
}
@@ -1234,8 +1234,8 @@ gui_input_history_global_next (struct t_gui_buffer *buffer)
if (window)
{
gui_input_history_next (window,
- history_global,
- &history_global_ptr);
+ gui_history,
+ &gui_history_ptr);
}
}
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index 16e87677a..4a415b5ea 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -1751,7 +1751,7 @@ gui_key_hdata_key_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_key", "next_key",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_key, key, STRING, 0, NULL, NULL);
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index c9a32a532..19fed22ac 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -1351,7 +1351,7 @@ gui_line_hdata_lines_cb (void *data, const char *hdata_name)
/* make C compiler happy */
(void) data;
- hdata = hdata_new (NULL, hdata_name, NULL, NULL, 0, NULL, NULL);
+ hdata = hdata_new (NULL, hdata_name, NULL, NULL, 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_lines, first_line, POINTER, 0, NULL, "line");
@@ -1379,7 +1379,7 @@ gui_line_hdata_line_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_line", "next_line",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_line, data, POINTER, 0, NULL, "line_data");
@@ -1486,7 +1486,7 @@ gui_line_hdata_line_data_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, NULL, NULL,
- 0, &gui_line_hdata_line_data_update_cb, NULL);
+ 0, 0, &gui_line_hdata_line_data_update_cb, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_line_data, buffer, POINTER, 0, NULL, "buffer");
diff --git a/src/gui/gui-nicklist.c b/src/gui/gui-nicklist.c
index d160aae02..ba6e32c0c 100644
--- a/src/gui/gui-nicklist.c
+++ b/src/gui/gui-nicklist.c
@@ -972,7 +972,7 @@ gui_nicklist_hdata_nick_group_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_group", "next_group",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_nick_group, name, STRING, 0, NULL, NULL);
@@ -1003,7 +1003,7 @@ gui_nicklist_hdata_nick_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_nick", "next_nick",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_nick, group, POINTER, 0, NULL, "nick_group");
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index d763ce6e2..31ee5cc9a 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -1610,7 +1610,7 @@ gui_window_hdata_window_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_window", "next_window",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_window, number, INTEGER, 0, NULL, NULL);
@@ -1657,7 +1657,7 @@ gui_window_hdata_window_scroll_cb (void *data, const char *hdata_name)
(void) data;
hdata = hdata_new (NULL, hdata_name, "prev_scroll", "next_scroll",
- 0, NULL, NULL);
+ 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_window_scroll, buffer, POINTER, 0, NULL, "buffer");
@@ -1686,7 +1686,7 @@ gui_window_hdata_window_tree_cb (void *data, const char *hdata_name)
/* make C compiler happy */
(void) data;
- hdata = hdata_new (NULL, hdata_name, NULL, NULL, 0, NULL, NULL);
+ hdata = hdata_new (NULL, hdata_name, NULL, NULL, 0, 0, NULL, NULL);
if (hdata)
{
HDATA_VAR(struct t_gui_window_tree, parent_node, POINTER, 0, NULL, hdata_name);