From 7b62337edffc2a59659c18043f24a0bf5a317a45 Mon Sep 17 00:00:00 2001 From: sgranjoux Date: Fri, 25 Jan 2008 21:03:45 +0000 Subject: [PATCH] * plugins/document-manager/plugin.c, plugins/document-manager/file_history.c, plugins/document-manager/file_history.h, plugins/document-manager/anjuta-docman.c, plugins/document-manager/anjuta-docman.h: Rename filename argument to uri when an uri is expected anjuta_docman_get_document_for_uri will remove symlinks git-svn-id: http://svn.gnome.org/svn/anjuta/trunk@3520 1dbfb86a-d425-0410-a06b-cb591aac69f6 --- ChangeLog | 12 ++ plugins/document-manager/anjuta-docman.c | 281 ++++++++++++++++++------------- plugins/document-manager/anjuta-docman.h | 12 +- plugins/document-manager/file_history.c | 24 +-- plugins/document-manager/file_history.h | 6 +- plugins/document-manager/plugin.c | 8 +- 6 files changed, 204 insertions(+), 139 deletions(-) diff --git a/ChangeLog b/ChangeLog index 421b24a8..335277c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-01-25 Tom + + reviewed by: Sébastien Granjoux + + * plugins/document-manager/plugin.c, + plugins/document-manager/file_history.c, + plugins/document-manager/file_history.h, + plugins/document-manager/anjuta-docman.c, + plugins/document-manager/anjuta-docman.h: + Rename filename argument to uri when an uri is expected + anjuta_docman_get_document_for_uri will remove symlinks + 2008-01-25 Naba Kumar * plugins/terminal/terminal.c: (terminal_execute), diff --git a/plugins/document-manager/anjuta-docman.c b/plugins/document-manager/anjuta-docman.c index fccfb0b9..51d9d532 100644 --- a/plugins/document-manager/anjuta-docman.c +++ b/plugins/document-manager/anjuta-docman.c @@ -1092,125 +1092,123 @@ anjuta_docman_set_current_document (AnjutaDocman *docman, IAnjutaDocument *doc) } IAnjutaEditor * -anjuta_docman_goto_file_line (AnjutaDocman *docman, const gchar *fname, gint lineno) +anjuta_docman_goto_file_line (AnjutaDocman *docman, const gchar *uri, gint lineno) { - return anjuta_docman_goto_file_line_mark (docman, fname, lineno, FALSE); + return anjuta_docman_goto_file_line_mark (docman, uri, lineno, FALSE); } +/* file_uri must be an escaped URI string such as returned by + gnome_vfs_get_uri_from_local_path() */ IAnjutaEditor * -anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, const gchar *fname, +anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, const gchar *file_uri, gint line, gboolean mark) { - gchar *uri, *te_uri; GnomeVFSURI* vfs_uri; - GList *node; - const gchar *linenum; + gchar *uri; + const gchar *fragment; gint lineno; - gchar *normalized_path = NULL; - gchar *local_path; IAnjutaDocument *doc; IAnjutaEditor *te; - g_return_val_if_fail (fname, NULL); + g_return_val_if_fail (file_uri != NULL, NULL); - vfs_uri = gnome_vfs_uri_new (fname); + vfs_uri = gnome_vfs_uri_new (file_uri); + g_return_val_if_fail (vfs_uri != NULL, NULL); - /* Extract linenum which comes as fragment identifier */ - linenum = gnome_vfs_uri_get_fragment_identifier (vfs_uri); - if (linenum) - lineno = atoi (linenum); + /* Extract linenum which sometimes comes as an appended uri fragment + e.g. when loading a file at session start or later */ + fragment = gnome_vfs_uri_get_fragment_identifier (vfs_uri); + if (fragment) + { + const gchar *numstart; + gchar *numend; + gulong converted; + + DEBUG_PRINT ("uri fragment provided for %s line %d", file_uri, line); + /* the real uri may have fragment(s) for vfs as well as for line-number */ + numstart = strrchr (fragment, '#'); + if (numstart == NULL) + numstart = fragment; + else + numstart++; + converted = strtoul (numstart, &numend, 10); + if (*numstart == '\0' || numend == numstart || *numend != '\0') + { + lineno = line; + uri = g_strdup (file_uri); + } + else /* the number is valid */ + { + lineno = (gint) converted; + + /* Restore URI without fragment identifier (linenum) */ + uri = gnome_vfs_uri_to_string (vfs_uri, + GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER); + if (uri != NULL && numstart != fragment) + { + gchar *freeme, *freeme2; + freeme = uri; + freeme2 = g_strndup (fragment, numstart-fragment); + uri = g_strconcat (uri, "#", freeme2, NULL); + g_free (freeme); + g_free (freeme2); + } + } + } else + { lineno = line; + uri = g_strdup (file_uri); + } - /* Restore URI without fragment identifier (linenum) */ - uri = gnome_vfs_uri_to_string (vfs_uri, - GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER); gnome_vfs_uri_unref (vfs_uri); g_return_val_if_fail (uri != NULL, NULL); - - /* Get the normalized file path for comparision */ - local_path = gnome_vfs_get_local_path_from_uri (uri); - normalized_path = anjuta_util_get_real_path (local_path); - g_free (local_path); - if (normalized_path == NULL) - normalized_path = g_strdup (uri); - - /* first, try to use a document that's already open */ - for (node = docman->priv->pages; node != NULL; node = g_list_next (node)) - { - AnjutaDocmanPage *page; - - page = (AnjutaDocmanPage *) node->data; - doc = IANJUTA_DOCUMENT (page->widget); - if (!IANJUTA_IS_EDITOR (doc)) - continue; - te_uri = ianjuta_file_get_uri (IANJUTA_FILE (doc), NULL); - if (te_uri) - { - gchar *te_normalized_path; - - /* Get the normalized file path for comparision */ - local_path = gnome_vfs_get_local_path_from_uri (te_uri); - te_normalized_path = anjuta_util_get_real_path (local_path); - g_free (local_path); - if (te_normalized_path == NULL) - te_normalized_path = g_strdup (te_uri); - - if (normalized_path && te_normalized_path) - { - if (strcmp (normalized_path, te_normalized_path) == 0) - { - if (lineno >= 0) - { - ianjuta_editor_goto_line (IANJUTA_EDITOR (doc), lineno, NULL); - if (mark) - { - ianjuta_markable_delete_all_markers (IANJUTA_MARKABLE (doc), - IANJUTA_MARKABLE_LINEMARKER, - NULL); - ianjuta_markable_mark (IANJUTA_MARKABLE (doc), lineno, - IANJUTA_MARKABLE_LINEMARKER, NULL); - } - } - anjuta_docman_present_notebook_page (docman, doc); - an_file_history_push (te_uri, lineno); - g_free (te_uri); - g_free (te_normalized_path); - g_free (uri); - g_free (normalized_path); - return IANJUTA_EDITOR (doc); - } - } - else - { - DEBUG_PRINT ("Unexpected NULL path"); - } - g_free (te_uri); - g_free (te_normalized_path); - } + DEBUG_PRINT("get document %s", uri); + /* if possible, use a document that's already open */ + doc = anjuta_docman_get_document_for_uri (docman, uri); + if (doc == NULL) + { + DEBUG_PRINT("open new"); + /* no deal, open a new document */ + te = anjuta_docman_add_editor (docman, uri, NULL); /* CHECKME NULL if not IANJUTA_IS_EDITOR () ? */ + doc = IANJUTA_DOCUMENT (te); } - /* no deal, open a new document */ - te = anjuta_docman_add_editor (docman, uri, NULL); - if (te) + else if (IANJUTA_IS_EDITOR (doc)) + { + DEBUG_PRINT("get te"); + te = IANJUTA_EDITOR (doc); + } + else + { + doc = NULL; + te = NULL; + } + g_free (uri); + + if (te != NULL) { - te_uri = ianjuta_file_get_uri (IANJUTA_FILE (te), NULL); + gchar *te_uri = ianjuta_file_get_uri (IANJUTA_FILE (te), NULL); an_file_history_push (te_uri, lineno); g_free (te_uri); - if (lineno >= 0) + + if (lineno >= 0) { - ianjuta_editor_goto_line(te, lineno, NULL); - if (mark) - { - ianjuta_markable_mark(IANJUTA_MARKABLE(te), lineno, - IANJUTA_MARKABLE_LINEMARKER, NULL); + ianjuta_editor_goto_line (te, lineno, NULL); + if (mark && IANJUTA_IS_MARKABLE (doc)) + { + ianjuta_markable_delete_all_markers (IANJUTA_MARKABLE (doc), + IANJUTA_MARKABLE_LINEMARKER, + NULL); + ianjuta_markable_mark (IANJUTA_MARKABLE (doc), lineno, + IANJUTA_MARKABLE_LINEMARKER, NULL); } } + anjuta_docman_present_notebook_page (docman, doc); } - g_free (uri); - g_free (normalized_path); - return te ; + + return te; } gchar * @@ -1397,14 +1395,15 @@ anjuta_docman_delete_all_indicators (AnjutaDocman *docman) } /* Saves a file to keep it synchronized with external programs */ +/* CHECKME unused */ void -anjuta_docman_save_file_if_modified (AnjutaDocman *docman, const gchar *szFullPath) +anjuta_docman_save_file_if_modified (AnjutaDocman *docman, const gchar *uri) { IAnjutaDocument *doc; - g_return_if_fail (szFullPath != NULL); + g_return_if_fail (uri != NULL); - doc = anjuta_docman_get_document_for_path (docman, szFullPath); + doc = anjuta_docman_get_document_for_uri (docman, uri); if (doc) { if(ianjuta_file_savable_is_dirty (IANJUTA_FILE_SAVABLE (doc), NULL)) @@ -1415,20 +1414,21 @@ anjuta_docman_save_file_if_modified (AnjutaDocman *docman, const gchar *szFullPa } /* If an external program changed the file, we must reload it */ +/* CHECKME unused */ void -anjuta_docman_reload_file (AnjutaDocman *docman, const gchar *szFullPath) +anjuta_docman_reload_file (AnjutaDocman *docman, const gchar *uri) { IAnjutaDocument *doc; - g_return_if_fail (szFullPath != NULL); + g_return_if_fail (uri != NULL); - doc = anjuta_docman_get_document_for_path (docman, szFullPath); + doc = anjuta_docman_get_document_for_uri (docman, uri); if (doc && IANJUTA_IS_EDITOR (doc)) { IAnjutaEditor *te; te = IANJUTA_EDITOR (doc); glong nNowPos = ianjuta_editor_get_lineno (te, NULL); - ianjuta_file_open (IANJUTA_FILE (doc), szFullPath, NULL); + ianjuta_file_open (IANJUTA_FILE (doc), uri, NULL); ianjuta_editor_goto_line (te, nNowPos, NULL); } } @@ -1518,32 +1518,85 @@ anjuta_docman_set_editor_properties (AnjutaDocman *docman) } IAnjutaDocument * -anjuta_docman_get_document_for_path (AnjutaDocman *docman, const gchar *file_path) +anjuta_docman_get_document_for_uri (AnjutaDocman *docman, const gchar *file_uri) { + gchar *local_path; + gchar *normalized_path; GList *node; - g_return_val_if_fail (file_path != NULL, NULL); - - for (node = docman->priv->pages; node != NULL; node = g_list_next (node)) + g_return_val_if_fail (file_uri != NULL, NULL); + + local_path = gnome_vfs_get_local_path_from_uri (file_uri); + /* grab a normalized file path for effective comparision */ + normalized_path = anjuta_util_get_real_path (local_path); + g_free (local_path); + + if (normalized_path != NULL) { - AnjutaDocmanPage *page; - page = (AnjutaDocmanPage *) node->data; + for (node = docman->priv->pages; node != NULL; node = g_list_next (node)) + { + AnjutaDocmanPage *page; + page = (AnjutaDocmanPage *) node->data; + + if (page && page->widget && IANJUTA_IS_DOCUMENT (page->widget)) + { + IAnjutaDocument *doc; + gchar *te_uri; + + doc = IANJUTA_DOCUMENT (page->widget); + te_uri = ianjuta_file_get_uri (IANJUTA_FILE (doc), NULL); + if (te_uri) + { + gchar *te_path; - if (page && page->widget && IANJUTA_IS_DOCUMENT (page->widget)) + te_path = gnome_vfs_get_local_path_from_uri (te_uri); + if (te_path) + { + /* editor uri is local too */ + gchar *normalized_te_path; + + normalized_te_path = anjuta_util_get_real_path (te_path); + g_free (te_path); + if ((normalized_te_path != NULL) && + strcmp (normalized_te_path, normalized_path) == 0) + { + g_free (normalized_path); + g_free (te_uri); + g_free (normalized_te_path); + return doc; + } + g_free (normalized_te_path); + } + g_free (te_uri); + } + } + } + g_free (normalized_path); + } + else + { + /* not a local uri, too bad about any links etc */ + for (node = docman->priv->pages; node != NULL; node = g_list_next (node)) { - IAnjutaDocument *doc; - gchar *uri; + AnjutaDocmanPage *page; + page = (AnjutaDocmanPage *) node->data; - doc = IANJUTA_DOCUMENT (page->widget); - uri = ianjuta_file_get_uri (IANJUTA_FILE (doc), NULL); - if (uri) + if (page && page->widget && IANJUTA_IS_DOCUMENT (page->widget)) { - if (0 == strcmp (file_path, uri)) + IAnjutaDocument *doc; + gchar *te_uri; + + doc = IANJUTA_DOCUMENT (page->widget); + te_uri = ianjuta_file_get_uri (IANJUTA_FILE (doc), NULL); + if (te_uri) { - g_free (uri); - return doc; + if (strcmp (te_uri, file_uri) == 0) + { + g_free (te_uri); + return doc; + } + g_free (te_uri); } - g_free (uri); } } } diff --git a/plugins/document-manager/anjuta-docman.h b/plugins/document-manager/anjuta-docman.h index 8e9d19ac..58454276 100644 --- a/plugins/document-manager/anjuta-docman.h +++ b/plugins/document-manager/anjuta-docman.h @@ -66,8 +66,8 @@ void anjuta_docman_add_document (AnjutaDocman *docman, IAnjutaDocument *doc, void anjuta_docman_remove_document (AnjutaDocman *docman, IAnjutaDocument *doc); IAnjutaDocument *anjuta_docman_get_current_document (AnjutaDocman *docman); -IAnjutaDocument *anjuta_docman_get_document_for_path (AnjutaDocman *docman, - const gchar *full_path); +IAnjutaDocument *anjuta_docman_get_document_for_uri (AnjutaDocman *docman, + const gchar *file_uri); GtkWidget *anjuta_docman_get_current_focus_widget (AnjutaDocman *docman); @@ -76,10 +76,10 @@ GtkWidget *anjuta_docman_get_current_popup (AnjutaDocman *docman); void anjuta_docman_set_current_document (AnjutaDocman *docman, IAnjutaDocument *doc); IAnjutaEditor *anjuta_docman_goto_file_line (AnjutaDocman *docman, - const gchar *fname, + const gchar *uri, gint lineno); IAnjutaEditor *anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, - const gchar *fname, + const gchar *uri, gint lineno, gboolean mark); void anjuta_docman_present_notebook_page (AnjutaDocman *docman, IAnjutaDocument *doc); @@ -88,8 +88,8 @@ void anjuta_docman_delete_all_markers (AnjutaDocman *docman, gint marker); void anjuta_docman_delete_all_indicators (AnjutaDocman *docman); void anjuta_docman_save_file_if_modified (AnjutaDocman *docman, - const gchar *szFullPath); -void anjuta_docman_reload_file (AnjutaDocman *docman, const gchar *szFullPath); + const gchar *uri); +void anjuta_docman_reload_file (AnjutaDocman *docman, const gchar *uri); gboolean anjuta_docman_set_editor_properties (AnjutaDocman *docman); diff --git a/plugins/document-manager/file_history.c b/plugins/document-manager/file_history.c index 5ee141c5..cde8dea2 100644 --- a/plugins/document-manager/file_history.c +++ b/plugins/document-manager/file_history.c @@ -40,13 +40,13 @@ static void an_file_history_init() s_history->current = NULL; } -AnHistFile *an_hist_file_new (const gchar *name, gint line) +AnHistFile *an_hist_file_new (const gchar *uri, gint line) { AnHistFile *h_file; - g_return_val_if_fail(name, NULL); + g_return_val_if_fail(uri, NULL); h_file= g_new(AnHistFile, 1); - h_file->file = g_strdup(name); + h_file->uri = g_strdup(uri); h_file->line = line; return h_file; } @@ -54,7 +54,7 @@ AnHistFile *an_hist_file_new (const gchar *name, gint line) void an_hist_file_free(AnHistFile *h_file) { g_return_if_fail(h_file); - g_free(h_file->file); + g_free(h_file->uri); g_free(h_file); } @@ -77,18 +77,18 @@ void an_file_history_reset(void) s_history->current = NULL; } -void an_file_history_push (const gchar *filename, gint line) +void an_file_history_push (const gchar *uri, gint line) { AnHistFile *h_file; - g_return_if_fail(filename); + g_return_if_fail (uri); if (!s_history) an_file_history_init(); if (s_history->current) { AnHistFile *current = (AnHistFile *) s_history->current->data; - if ((0 == strcmp(filename, current->file)) && - ((current->line < 1) || (line == current->line))) + if (strcmp(uri, current->uri) == 0 && + (current->line < 1 || line == current->line)) { current->line = line; return; @@ -111,7 +111,7 @@ void an_file_history_push (const gchar *filename, gint line) tmp->next = NULL; } } - h_file = an_hist_file_new(filename, line); + h_file = an_hist_file_new(uri, line); s_history->items = g_list_prepend(s_history->items, h_file); s_history->current = s_history->items; } @@ -125,7 +125,7 @@ void an_file_history_back(AnjutaDocman *docman) s_history->current = s_history->current->next; h_file = (AnHistFile *) s_history->current->data; - anjuta_docman_goto_file_line_mark (docman, h_file->file, + anjuta_docman_goto_file_line_mark (docman, h_file->uri, h_file->line, FALSE); } @@ -138,7 +138,7 @@ void an_file_history_forward(AnjutaDocman *docman) s_history->current = s_history->current->prev; h_file = (AnHistFile *) s_history->current->data; - anjuta_docman_goto_file_line_mark(docman, h_file->file, + anjuta_docman_goto_file_line_mark(docman, h_file->uri, h_file->line, FALSE); } @@ -152,7 +152,7 @@ void an_file_history_dump(void) for (tmp = s_history->items; tmp; tmp = g_list_next(tmp)) { h_file = (AnHistFile *) tmp->data; - fprintf(stderr, "%s:%d", h_file->file, h_file->line); + fprintf(stderr, "%s:%d", h_file->uri, h_file->line); if (tmp == s_history->current) fprintf(stderr, " (*)"); fprintf(stderr, "\n"); diff --git a/plugins/document-manager/file_history.h b/plugins/document-manager/file_history.h index a3bada85..c0711ea4 100644 --- a/plugins/document-manager/file_history.h +++ b/plugins/document-manager/file_history.h @@ -26,15 +26,15 @@ typedef struct _AnHistFile AnHistFile; struct _AnHistFile { - gchar *file; + gchar *uri; gint line; }; -AnHistFile *an_hist_file_new (const gchar *name, gint line); +AnHistFile *an_hist_file_new (const gchar *uri, gint line); void an_hist_file_free(AnHistFile *h_file); void an_file_history_reset(void); -void an_file_history_push (const gchar *filename, gint line); +void an_file_history_push (const gchar *uri, gint line); void an_file_history_back(AnjutaDocman *docman); void an_file_history_forward(AnjutaDocman *docman); void an_file_history_dump(void); diff --git a/plugins/document-manager/plugin.c b/plugins/document-manager/plugin.c index a381cdb7..da8468c4 100644 --- a/plugins/document-manager/plugin.c +++ b/plugins/document-manager/plugin.c @@ -1838,12 +1838,12 @@ ianjuta_docman_get_full_filename (IAnjutaDocumentManager *plugin, } static IAnjutaDocument* -ianjuta_docman_get_document_with_path (IAnjutaDocumentManager *plugin, - const gchar *file_path, GError **e) +ianjuta_docman_get_document_for_uri (IAnjutaDocumentManager *plugin, + const gchar *file_uri, GError **e) { AnjutaDocman *docman; docman = ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin)->docman)); - return anjuta_docman_get_document_for_path (docman, file_path); + return anjuta_docman_get_document_for_uri (docman, file_uri); } static IAnjutaDocument* @@ -1957,7 +1957,7 @@ ianjuta_document_manager_iface_init (IAnjutaDocumentManagerIface *iface) { iface->add_buffer = ianjuta_docman_add_buffer; iface->add_document = ianjuta_docman_add_document; - iface->find_document_with_path = ianjuta_docman_get_document_with_path; + iface->find_document_with_path = ianjuta_docman_get_document_for_uri; iface->get_current_document = ianjuta_docman_get_current_document; iface->get_doc_widgets = ianjuta_docman_get_doc_widgets; iface->get_full_filename = ianjuta_docman_get_full_filename; -- 2.11.4.GIT