[Github-comments] [geany] If more tags are found during tag definition/declaration goto, let user select which one to use (#406)

Colomban Wendling notifications at xxxxx
Sat Feb 13 21:54:41 UTC 2016


Hum, I don't really like the popup, esp. because it can popup far from the pointer or whatever the trigger was (and it be something else?).  Also, the popup sizing is incorrect (at least with my theme, so it's incorrect in general, yet maybe happen to be good in your case).  This is fixable correctly (not like in Scintilla), but not really trivial.

Anyway, I wanted to check if it was easy to implement using AUTOCLISTs, and realized Scintilla had USERLISTs, which sounded quite nice :)
Here is a sample of how it might look like (yet it has 2 unresolved issues, one hard and one simple):
```c
static void on_goto_popup_sci_notify(GtkWidget *sci, gint scn, SCNotification *nt, gpointer data)
{
	switch (nt->nmhdr.code)
	{
		case SCN_USERLISTSELECTION:
			if (nt->listType == 42)
			{
				gchar *name = g_strdup(nt->text);
				gchar *line = strrchr(name, ':');
				GeanyDocument *old_doc = document_get_current();
				GeanyDocument *new_doc;

				if (line)
				{
					*line = 0;
					line++;
				}

				new_doc = document_find_by_real_path(name);
				if (!new_doc)
					new_doc = document_open_file(name, FALSE, NULL, NULL);

				if (new_doc)
					navqueue_goto_line(old_doc, new_doc, line ? atoi(line) : 0);

				g_free(name);
			}
			/* fallthrough */
		case SCN_AUTOCCANCELLED:
			g_signal_handlers_disconnect_by_func(sci, on_goto_popup_sci_notify, data);
			break;
	}
}


static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_best)
{
	TMTag *tmtag;
	guint i;
	GString *words;

	if (tags->len < 1)
		return;

	words = g_string_new(NULL);

	foreach_ptr_array(tmtag, i, tags)
	{
		if (words->len > 0)
			g_string_append_c(words, '\n');

		/* FIXME: how to show something and get associated data? */
		g_string_append_printf(words, "%s:%lu", tmtag->file->file_name, tmtag->line);

		/* FIXME: better images */
		if (!EMPTY(tmtag->arglist))
			g_string_append(words, "?2");
		else
			g_string_append(words, "?1");
	}

	g_signal_connect(doc->editor->sci, "sci-notify", G_CALLBACK(on_goto_popup_sci_notify), NULL);
	scintilla_send_message(doc->editor->sci, SCI_AUTOCCANCEL, 0, 0);
	scintilla_send_message(doc->editor->sci, SCI_USERLISTSHOW, 42, (sptr_t) words->str);
	g_string_free(words, TRUE);
}
```
It's quick'n dirty, and we might rather want to register that in the editor handler or somewhere -- although this doesn't feel *so* bad in the end, as it's contained and temporary.  The real question here is the first *FIXME in the code, e.g. whether it's possible to store some additional data with the displayed entry.  Otherwise, we either need something like I did, or a table mapping the name to the actual tag… meh.

---

Apart that, I don't know, the theory is probably fine, but to really have an opinion I'd need to use it for some time and see in the "long" run.
And there's an issue when merging this in current master, conflicting signature for `tm_workspace_find()`.  And an int should be unsigned :)
```diff
diff --git a/src/symbols.c b/src/symbols.c
index ed71004..7e429ec 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -1990,7 +1990,7 @@ static void show_goto_popup(GPtrArray *tags, gboolean have_best)
     GtkTreeModel *model;
     GtkTreeIter iter;
     TMTag *tmtag;
-    gint i;
+    guint i;
 
     if (!tag_goto_popup)
         create_goto_popup();
@@ -2094,7 +2094,7 @@ static gboolean goto_tag(const gchar *name, gboolean definition)
 
     /* goto tag definition: all except prototypes / forward declarations / externs */
     type = (definition) ? tm_tag_max_t - forward_types : forward_types;
-    all_tags = tm_workspace_find(name, type, NULL, FALSE, old_doc->file_type->lang);
+    all_tags = tm_workspace_find(name, NULL, type, NULL, old_doc->file_type->lang);
 
     /* get rid of global tags */
     workspace_tags = g_ptr_array_new();
```
(the `tm_workspace_find()` might not be correctly fixed, I did that quickly and I'm not yet familiar with the new API)

---
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/406#issuecomment-183763414
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20160213/a5f99d9a/attachment.html>


More information about the Github-comments mailing list