After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 346574 - "open file at cursor" feature
"open file at cursor" feature
Status: RESOLVED OBSOLETE
Product: anjuta
Classification: Applications
Component: plugins: document-manager
2.1.3
Other All
: Normal enhancement
: ---
Assigned To: Anjuta maintainers
Anjuta maintainers
: 690631 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-07-04 18:10 UTC by hariseldon78
Modified: 2020-11-07 12:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
open at cursor feature (4.47 KB, patch)
2011-07-14 23:21 UTC, Tamara Atanasoska
needs-work Details | Review
Feature in progress (7.39 KB, patch)
2011-07-25 17:08 UTC, Tamara Atanasoska
needs-work Details | Review
Feature in progress (12.50 KB, patch)
2011-08-22 02:23 UTC, Tamara Atanasoska
needs-work Details | Review

Description hariseldon78 2006-07-04 18:10:18 UTC
i would like to have the possibility to open a file from the editor context menu, clicking on its name. for example if i have
#include "abc.h"

i would like to click on abc.h in some way and go to edit that file directly.
Comment 1 Naba Kumar 2007-06-23 22:43:26 UTC
Corrected version.
Comment 2 Johannes Schmid 2007-09-24 09:15:38 UTC
The problem is in which paths to search for abc.h. I could be in /usr/include/* or somewhere in the project diretories (probably multiple times).
Comment 3 hariseldon78 2008-01-11 18:32:39 UTC
well, a minimal but still useful implementation could be to search just in the project directories and just open the first match found..
Comment 4 Adam Dingle 2009-01-13 15:25:33 UTC
I'd also like to see this feature.  I agree that finding the right paths might be a little tricky.
Comment 5 Tamara Atanasoska 2011-07-14 23:21:24 UTC
Created attachment 192009 [details] [review]
open at cursor feature

Opening only local header files by adding a new menu item in the PopupDocumentManager menu.
Comment 6 Johannes Schmid 2011-07-15 13:50:57 UTC
Review of attachment 192009 [details] [review]:

::: plugins/language-support-cpp-java/plugin.c
@@ +998,3 @@
+	file = ianjuta_file_get_file (IANJUTA_FILE (lang_plugin->current_editor),
+								  NULL);
+    IAnjutaIterable *position;

Indentation...

@@ +1009,3 @@
+	begin = ianjuta_editor_get_line_begin_position (IANJUTA_EDITOR(lang_plugin->current_editor), line_number, NULL);
+	end = ianjuta_editor_get_line_end_position (IANJUTA_EDITOR(lang_plugin->current_editor), line_number, NULL);
+    text = ianjuta_editor_get_text (IANJUTA_EDITOR(lang_plugin->current_editor), begin, end, NULL);

Indentation...

@@ +1016,3 @@
+	GMatchInfo *match_info;
+	GFile *header_file;
+	regex = g_regex_new ("^#\\s*include\\s+\"(.+)\"", 0, 0, NULL);

What about #include <file.h>?

Also sometimes you have things like #include <gtk/gtk.h> where there is a directory present in the include line. We also need to take care of that.

@@ +1020,3 @@
+	{
+      gchar *match_word = g_match_info_fetch (match_info, 1);
+      header_file = g_file_get_child (parent_file, match_word);

also indentation

@@ +1022,3 @@
+      header_file = g_file_get_child (parent_file, match_word);
+		
+	if (g_file_query_exists (header_file, NULL))

We need some more magic here, possible points are:
-> Check if the file exists in the same directory -> open it
-> If not, check if the file exists in the project, probably provide a list of files if there are multiple files with the same name. Ideally we would check the include path in the Makefile.am but that might be tricky.
-> If we didn't find the file yet, check if it exists in one of the directories specified by the included pkg-config libraries, if we can find them. That the last step though and might be done as a seperate patch.

::: plugins/language-support-cpp-java/plugin.h
@@ +85,3 @@
 
+void
+open_include_file_func(GtkAction* action, gpointer data);

I don't think we need this. The callback should be "static" in plugin.c
Comment 7 Tamara Atanasoska 2011-07-25 17:08:21 UTC
Created attachment 192623 [details] [review]
Feature in progress

Now <> files can be opened too.
At the moment working on a better way to search for files, so this patch is just to post my progress.
Comment 8 Johannes Schmid 2011-07-25 17:36:20 UTC
Review of attachment 192623 [details] [review]:

::: plugins/language-support-cpp-java/plugin.c
@@ +1029,3 @@
+	position = ianjuta_editor_get_position(IANJUTA_EDITOR(lang_plugin->current_editor), NULL);
+	line_number = ianjuta_editor_get_line_from_position (IANJUTA_EDITOR(lang_plugin->current_editor), position, NULL);
+	begin = ianjuta_editor_get_line_begin_position (IANJUTA_EDITOR(lang_plugin->current_editor), line_number, NULL);

You need to unref (g_object_unref()) position, begin, end and g_free text!

@@ +1031,3 @@
+	begin = ianjuta_editor_get_line_begin_position (IANJUTA_EDITOR(lang_plugin->current_editor), line_number, NULL);
+	end = ianjuta_editor_get_line_end_position (IANJUTA_EDITOR(lang_plugin->current_editor), line_number, NULL);
+    text = ianjuta_editor_get_text (IANJUTA_EDITOR(lang_plugin->current_editor), begin, end, NULL);

The indentation is still wrong here - be sure to use tabs. If in doubt, mark all the lines and press Ctrl-I

@@ +1035,3 @@
+	parent_file = g_file_get_parent(file);
+	
+    lang_plugin->regex = g_regex_new (INCLUDE_REGEX, 0, 0, NULL);

dito

@@ +1036,3 @@
+	
+    lang_plugin->regex = g_regex_new (INCLUDE_REGEX, 0, 0, NULL);
+	lang_plugin->regex_1 = g_regex_new (INCLUDE_REGEX_2, 0, 0, NULL);

You need to create the regex objects somewhere in _init() if you want to cache them.

@@ +1038,3 @@
+	lang_plugin->regex_1 = g_regex_new (INCLUDE_REGEX_2, 0, 0, NULL);
+
+	if (g_regex_match (lang_plugin->regex, text, 0, &match_info) || (g_regex_match (lang_plugin->regex_1, text, 0, &match_info)))

Could you split that into an if/else if block? Thanks!

@@ +1057,3 @@
+			g_string_append  ( str, root_uri );
+			g_string_append  ( str, "/" );
+			g_string_append  ( str, match_word );

It would be better to use g_build_filename (see http://developer.gnome.org/glib/2.28/glib-Miscellaneous-Utility-Functions.html#g-build-filename)

@@ +1069,3 @@
+		g_match_info_free (match_info);
+	 }
+	    g_regex_unref (lang_plugin->regex);

If you want to cache the regex elements, do the unref in deactivate() or so.

::: plugins/language-support-cpp-java/plugin.h
@@ +53,3 @@
+
+	gchar *project_root_directory;
+	GRegex *regex,*regex_1;

Style: Use two lines.
Comment 9 Tamara Atanasoska 2011-08-22 02:23:43 UTC
Created attachment 194341 [details] [review]
Feature in progress

After the Desktop Summit I've been involved with this.
Got some help from seb for anjuta api and also from aruiz with gtk.

But I got stuck again. This is my first time doing this with GTK so I've spent the week spinning in circles mostly, but I finally got somewhere. If jhs is not available to help I would really appreciate if someone does.

То point out at the beginning I haven't taken care of the memory still and some haven't really aligned the code, but I plan to do that at the end.

At the moment we have a part of the function opening "" include files, another part opening <> files immediately if there is no other with the same name/path in the project, and a part that if there are more of the files named the same in the project, displays a list of the files in a dialog so the user can choose which file to open.

So I kind of got stuck with getting the selection. I've tried a few approaches, trying to get the selection trough gtk_tree_model_get , then with gtk_dialog_run and doing it afterwards when the button is clicked, also some other successful stuff. 

My other patch for feature: https://bugzilla.gnome.org/show_bug.cgi?id=591688; also depends on this, so if I finish this I finish both :)

Thanks for all the help in advance.
Comment 10 Johannes Schmid 2011-08-22 03:59:20 UTC
Review of attachment 194341 [details] [review]:

Overall it should be better if you add two columns to the tree model, one column for the GFile* and one column showing the display name of the file (it is available through GFile API). The GFile column isn't shown and is just used internal to open the file later.

::: plugins/language-support-cpp-java/plugin.c
@@ +89,3 @@
 static gpointer parent_class;
+const gchar *root_uri;
+gint broj=0;

???

@@ +1014,3 @@
+					  gpointer user_data)
+{
+}

Free'ing root_uri and setting it to NULL should be done here.

@@ +1100,3 @@
+			gfile = g_list_nth_data (list_children, i);
+
+			if ((local_filename = g_file_get_path (gfile)) == NULL)

Maybe just operate of GFile as long as possible so you don't have to care if the file is local or not. Just save the GFile in the tree model instead of a string.
Comment 11 Sébastien Granjoux 2012-12-22 10:15:04 UTC
*** Bug 690631 has been marked as a duplicate of this bug. ***
Comment 12 André Klapper 2020-11-07 12:13:06 UTC
bugzilla.gnome.org is being replaced by gitlab.gnome.org. We are closing all
old feature requests in Bugzilla which have not seen updates for many years.

If you are still requesting this feature in a currently supported version of GNOME (currently that would be 3.38), then please feel free to report it at https://gitlab.gnome.org/GNOME/anjuta/-/issues/

Thank you for reporting this issue and we are sorry it could not be implemented.