Simplified some of the completions to avoid duplicate code.
gboolean bookmark_fill_tag_completion(GtkListStore *store, const char *input)
{
- gboolean found = false;
+ gboolean found;
unsigned int len, i;
- GtkTreeIter iter;
- GList *src = NULL, *tags = NULL, *l;
+ GList *src = NULL, *tags = NULL;
Bookmark *bm;
/* get all distinct tags from bookmark file */
}
/* generate the completion with the found tags */
- if (!input || !*input) {
- for (l = tags; l; l = l->next) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- } else {
- for (l = tags; l; l = l->next) {
- if (g_str_has_prefix(l->data, input)) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- }
- }
+ found = util_fill_completion(store, input, tags);
g_list_free_full(src, (GDestroyNotify)free_bookmark);
/* we don't need to free the values, because they where already removed by
* freeing the src list - we never allocated new momory for them */
found = bookmark_fill_tag_completion(store, token);
break;
+ case EX_SCR:
+ sort = true;
+ found = shortcut_fill_completion(store, token);
+ break;
+
case EX_HANDREM:
sort = true;
found = handler_fill_completion(store, token);
#include "main.h"
#include "handlers.h"
-#include "completion.h"
#include "util.h"
extern VbCore vb;
gboolean handler_fill_completion(GtkListStore *store, const char *input)
{
- gboolean found = false;
- GtkTreeIter iter;
GList *src = g_hash_table_get_keys(handlers);
-
- if (!input || !*input) {
- for (GList *l = src; l; l = l->next) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- } else {
- for (GList *l = src; l; l = l->next) {
- char *value = (char*)l->data;
- if (g_str_has_prefix(value, input)) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- }
- }
+ gboolean found = util_fill_completion(store, input, src);
g_list_free(src);
return found;
gboolean setting_fill_completion(GtkListStore *store, const char *input)
{
- gboolean found = false;
- GtkTreeIter iter;
GList *src = g_hash_table_get_keys(settings);
-
- if (!input || !*input) {
- for (GList *l = src; l; l = l->next) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- } else {
- for (GList *l = src; l; l = l->next) {
- char *value = (char*)l->data;
- if (g_str_has_prefix(value, input)) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
- found = true;
- }
- }
- }
+ gboolean found = util_fill_completion(store, input, src);
g_list_free(src);
return found;
return uri;
}
+gboolean shortcut_fill_completion(GtkListStore *store, const char *input)
+{
+ GList *src = g_hash_table_get_keys(shortcuts);
+ gboolean found = util_fill_completion(store, input, src);
+ g_list_free(src);
+
+ return found;
+}
+
/**
* Retrieves th highest placesholder number used in given string.
* If no placeholder is found -1 is returned.
gboolean shortcut_remove(const char *key);
gboolean shortcut_set_default(const char *key);
char *shortcut_get_uri(const char *key);
+gboolean shortcut_fill_completion(GtkListStore *store, const char *input);
#endif /* end of include guard: _SHORTCUT_H */
#include "main.h"
#include "util.h"
#include "ascii.h"
+#include "completion.h"
char *util_get_config_dir(void)
{
return result;
}
+
+/**
+ * Fills the given list store by matching data of also given src list.
+ */
+gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src)
+{
+ gboolean found = false;
+ GtkTreeIter iter;
+
+ if (!input || !*input) {
+ for (GList *l = src; l; l = l->next) {
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
+ found = true;
+ }
+ } else {
+ for (GList *l = src; l; l = l->next) {
+ char *value = (char*)l->data;
+ if (g_str_has_prefix(value, input)) {
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
+ found = true;
+ }
+ }
+ }
+
+ return found;
+}
gboolean util_create_tmp_file(const char *content, char **file);
char *util_build_path(const char *path, const char *dir);
char *util_expand(const char *src);
+gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src);
#endif /* end of include guard: _UTIL_H */