summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/gui-buffer.c20
-rw-r--r--src/gui/gui-buffer.h1
-rw-r--r--tests/unit/gui/test-gui-buffer.cpp23
3 files changed, 44 insertions, 0 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index bfade9dc9..5d3fa475c 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -2861,6 +2861,26 @@ gui_buffer_search_main ()
}
/*
+ * Searches for a buffer by id (unique identifier).
+ */
+
+struct t_gui_buffer *
+gui_buffer_search_by_id (long long id)
+{
+ struct t_gui_buffer *ptr_buffer;
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if (ptr_buffer->id == id)
+ return ptr_buffer;
+ }
+
+ /* buffer not found */
+ return NULL;
+}
+
+/*
* Searches for a buffer by full name (example: "irc.libera.#weechat").
*
* If full_name starts with "(?i)", the search starts after this string
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 3f540d442..643f5ec85 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -391,6 +391,7 @@ extern void gui_buffer_add_value_num_displayed (struct t_gui_buffer *buffer,
int value);
extern int gui_buffer_is_main (const char *plugin_name, const char *name);
extern struct t_gui_buffer *gui_buffer_search_main ();
+extern struct t_gui_buffer *gui_buffer_search_by_id (long long id);
extern struct t_gui_buffer *gui_buffer_search_by_full_name (const char *full_name);
extern struct t_gui_buffer *gui_buffer_search (const char *plugin, const char *name);
extern struct t_gui_buffer *gui_buffer_search_by_partial_name (const char *plugin,
diff --git a/tests/unit/gui/test-gui-buffer.cpp b/tests/unit/gui/test-gui-buffer.cpp
index 5093a14b3..1c4e1131b 100644
--- a/tests/unit/gui/test-gui-buffer.cpp
+++ b/tests/unit/gui/test-gui-buffer.cpp
@@ -1315,6 +1315,29 @@ TEST(GuiBuffer, SearchMain)
/*
* Tests functions:
+ * gui_buffer_search_by_id
+ */
+
+TEST(GuiBuffer, SearchById)
+{
+ struct t_gui_buffer *buffer;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ POINTERS_EQUAL(NULL, gui_buffer_search_by_id (-1));
+ POINTERS_EQUAL(NULL, gui_buffer_search_by_id (0));
+
+ POINTERS_EQUAL(gui_buffers, gui_buffer_search_by_id (gui_buffers->id));
+ POINTERS_EQUAL(buffer, gui_buffer_search_by_id (buffer->id));
+
+ gui_buffer_close (buffer);
+}
+
+/*
+ * Tests functions:
* gui_buffer_search_by_full_name
*/