anjuta r4643 - in trunk: . plugins/document-manager
- From: sgranjoux svn gnome org
- To: svn-commits-list gnome org
- Subject: anjuta r4643 - in trunk: . plugins/document-manager
- Date: Tue, 27 Jan 2009 20:35:38 +0000 (UTC)
Author: sgranjoux
Date: Tue Jan 27 20:35:37 2009
New Revision: 4643
URL: http://svn.gnome.org/viewvc/anjuta?rev=4643&view=rev
Log:
* plugins/document-manager/file_history.c,
plugins/document-manager/file_history.h,
plugins/document-manager/anjuta-docman.c:
Fix #357820 â Goto / Previous history should return to previous cursor
position
Modified:
trunk/ChangeLog
trunk/plugins/document-manager/anjuta-docman.c
trunk/plugins/document-manager/file_history.c
trunk/plugins/document-manager/file_history.h
Modified: trunk/plugins/document-manager/anjuta-docman.c
==============================================================================
--- trunk/plugins/document-manager/anjuta-docman.c (original)
+++ trunk/plugins/document-manager/anjuta-docman.c Tue Jan 27 20:35:37 2009
@@ -1269,6 +1269,7 @@
{
IAnjutaDocument *doc;
IAnjutaEditor *te;
+ AnjutaDocmanPage *page;
g_return_val_if_fail (file != NULL, NULL);
@@ -1276,6 +1277,25 @@
{
return NULL;
}
+
+ /* Save current uri and line in document history list */
+ page = anjuta_docman_get_current_page (docman);
+ if (page && page->doc && IANJUTA_IS_FILE (page->doc))
+ {
+ GFile* file = ianjuta_file_get_file (IANJUTA_FILE (page->doc), NULL);
+
+ if (file)
+ {
+ gint line = 0;
+
+ if (IANJUTA_IS_EDITOR (page->doc))
+ {
+ line = ianjuta_editor_get_lineno (IANJUTA_EDITOR (page->doc), NULL);
+ }
+
+ an_file_history_push (file, line);
+ }
+ }
/* if possible, use a document that's already open */
doc = anjuta_docman_get_document_for_file (docman, file);
@@ -1296,11 +1316,6 @@
if (te != NULL)
{
- GFile *te_file = ianjuta_file_get_file (IANJUTA_FILE (te), NULL);
- gchar* te_uri = g_file_get_uri (te_file);
- an_file_history_push (te_uri, line);
- g_free (te_uri);
-
if (line >= 0)
{
ianjuta_editor_goto_line (te, line, NULL);
Modified: trunk/plugins/document-manager/file_history.c
==============================================================================
--- trunk/plugins/document-manager/file_history.c (original)
+++ trunk/plugins/document-manager/file_history.c Tue Jan 27 20:35:37 2009
@@ -29,6 +29,7 @@
{
GList *items;
GList *current;
+ gboolean history_move;
} AnFileHistory;
static AnFileHistory *s_history = NULL;
@@ -38,15 +39,17 @@
s_history = g_new(AnFileHistory, 1);
s_history->items = NULL;
s_history->current = NULL;
+ s_history->history_move = FALSE;
}
-AnHistFile *an_hist_file_new (const gchar *uri, gint line)
+AnHistFile *an_hist_file_new (GFile *file, gint line)
{
AnHistFile *h_file;
- g_return_val_if_fail(uri, NULL);
+ g_return_val_if_fail(file, NULL);
+
h_file= g_new(AnHistFile, 1);
- h_file->uri = g_strdup(uri);
+ h_file->file = g_object_ref (file);
h_file->line = line;
return h_file;
}
@@ -54,7 +57,7 @@
void an_hist_file_free(AnHistFile *h_file)
{
g_return_if_fail(h_file);
- g_free(h_file->uri);
+ g_object_unref (h_file->file);
g_free(h_file);
}
@@ -77,33 +80,38 @@
s_history->current = NULL;
}
-void an_file_history_push (const gchar *uri, gint line)
+void an_file_history_push (GFile *file, gint line)
{
AnHistFile *h_file;
- g_return_if_fail (uri);
+ g_return_if_fail (file);
+
if (!s_history)
an_file_history_init();
+
if (s_history->current)
{
- AnHistFile *current = (AnHistFile *) s_history->current->data;
- if (strcmp(uri, current->uri) == 0 &&
- (current->line < 1 || line == current->line))
+ GList *next;
+
+ /* Only update line number when called by forward/backward */
+ if (s_history->history_move)
{
- current->line = line;
- return;
- }
- if (s_history->current != s_history->items)
- {
- GList *tmp = s_history->current->prev;
- if (tmp)
+ AnHistFile *h_file = (AnHistFile *) s_history->current->data;
+
+ if (g_file_equal (file,h_file->file))
{
- tmp->next = NULL;
- an_hist_items_free(s_history->items);
+ h_file->line = line;
}
- s_history->items = s_history->current;
- s_history->current->prev = NULL;
+ return;
}
+
+ next = s_history->current->next;
+ s_history->current->next = NULL;
+ an_hist_items_free(s_history->items);
+
+ s_history->items = next;
+ if (next) next->prev = NULL;
+ s_history->current = NULL;
if (g_list_length(s_history->items) > MAX_ENTRIES)
{
GList *tmp = g_list_nth(s_history->items, OPT_ENTRIES);
@@ -111,41 +119,47 @@
tmp->next = NULL;
}
}
- h_file = an_hist_file_new(uri, line);
+ h_file = an_hist_file_new(file, line);
s_history->items = g_list_prepend(s_history->items, h_file);
- s_history->current = s_history->items;
+ s_history->current = NULL;
}
void an_file_history_back(AnjutaDocman *docman)
{
AnHistFile *h_file;
- GFile* file;
+ GList *current;
- if (!(s_history && s_history->current && s_history->current->next))
+ if (!(s_history && (!s_history->current || s_history->current->next)))
return;
- s_history->current = s_history->current->next;
- h_file = (AnHistFile *) s_history->current->data;
- file = g_file_new_for_uri (h_file->uri);
- anjuta_docman_goto_file_line_mark (docman, file,
+ current = s_history->current ? s_history->current->next : s_history->items;
+ h_file = (AnHistFile *) current->data;
+
+ s_history->history_move = TRUE;
+ anjuta_docman_goto_file_line_mark (docman, h_file->file,
h_file->line, FALSE);
- g_object_unref (file);
+ s_history->history_move = FALSE;
+
+ s_history->current = current;
}
void an_file_history_forward(AnjutaDocman *docman)
{
AnHistFile *h_file;
- GFile* file;
+ GList *current;
if (!(s_history && s_history->current && s_history->current->prev))
return;
- s_history->current = s_history->current->prev;
- h_file = (AnHistFile *) s_history->current->data;
- file = g_file_new_for_uri (h_file->uri);
- anjuta_docman_goto_file_line_mark(docman, file,
+ current = s_history->current->prev;
+ h_file = (AnHistFile *) current->data;
+
+ s_history->history_move = TRUE;
+ anjuta_docman_goto_file_line_mark(docman, h_file->file,
h_file->line, FALSE);
- g_object_unref (file);
+ s_history->history_move = FALSE;
+
+ s_history->current = current;
}
void an_file_history_dump(void)
@@ -157,8 +171,11 @@
fprintf(stderr, "--------------------------\n");
for (tmp = s_history->items; tmp; tmp = g_list_next(tmp))
{
+ gchar *uri;
h_file = (AnHistFile *) tmp->data;
- fprintf(stderr, "%s:%d", h_file->uri, h_file->line);
+ uri = g_file_get_uri (h_file->file);
+ fprintf(stderr, "%s:%d", uri, h_file->line);
+ g_free (uri);
if (tmp == s_history->current)
fprintf(stderr, " (*)");
fprintf(stderr, "\n");
Modified: trunk/plugins/document-manager/file_history.h
==============================================================================
--- trunk/plugins/document-manager/file_history.h (original)
+++ trunk/plugins/document-manager/file_history.h Tue Jan 27 20:35:37 2009
@@ -14,11 +14,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
#ifndef _FILE_HISTORY_H
#define _FILE_HISTORY_H
#include <glib.h>
+#include <gio/gio.h>
#include "anjuta-docman.h"
@@ -26,15 +26,15 @@
struct _AnHistFile
{
- gchar *uri;
+ GFile *file;
gint line;
};
-AnHistFile *an_hist_file_new (const gchar *uri, gint line);
+AnHistFile *an_hist_file_new (GFile *file, gint line);
void an_hist_file_free(AnHistFile *h_file);
void an_file_history_reset(void);
-void an_file_history_push (const gchar *uri, gint line);
+void an_file_history_push (GFile *file, gint line);
void an_file_history_back(AnjutaDocman *docman);
void an_file_history_forward(AnjutaDocman *docman);
void an_file_history_dump(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]