mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 09:13:14 +02:00
api: allow creation of structure with hdata_update (allowed for hdata "history")
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+94
-34
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +217,62 @@ gui_history_buffer_free (struct t_gui_buffer *buffer)
|
||||
buffer->num_history = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+5
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+3
-3
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user