~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/navqueue.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2009-01-01 18:40:50 UTC
  • mfrom: (1.1.8 upstream) (3.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20090101184050-u635kualu7amyt4a
Tags: 0.15-1ubuntu1
* Merge from debian experimental, remaining change:
  - patches/20_add_debdiff_as_diff_type.dpatch: Also recognize .dpatch files
    as diff's
  - debian/geany.xpm: Replace icon with a .xpm of the new one

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *      along with this program; if not, write to the Free Software
20
20
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
21
 *
22
 
 * $Id: navqueue.c 2505 2008-04-19 08:14:00Z eht16 $
 
22
 * $Id: navqueue.c 2779 2008-07-15 14:29:41Z ntrel $
23
23
 */
24
24
 
25
25
/*
28
28
 
29
29
#include "geany.h"
30
30
 
31
 
#include "navqueue.h"
32
31
#include "sciwrappers.h"
33
32
#include "document.h"
34
33
#include "utils.h"
35
34
#include "support.h"
 
35
#include "ui_utils.h"
 
36
#include "editor.h"
 
37
#include "navqueue.h"
36
38
 
37
39
 
38
40
/* for the navigation history queue */
39
41
typedef struct
40
42
{
41
 
        gchar *file;    /* This is the document's filename, in UTF-8 */
 
43
        const gchar *file;      /* This is the document's filename, in UTF-8 */
42
44
        gint pos;
43
45
} filepos;
44
46
 
54
56
        navigation_queue = g_queue_new();
55
57
        nav_queue_pos = 0;
56
58
 
57
 
        navigation_buttons[0] = lookup_widget(app->window, "toolbutton_back");
58
 
        navigation_buttons[1] = lookup_widget(app->window, "toolbutton_forward");
 
59
        navigation_buttons[0] = lookup_widget(main_widgets.window, "toolbutton_back");
 
60
        navigation_buttons[1] = lookup_widget(main_widgets.window, "toolbutton_forward");
59
61
}
60
62
 
61
63
 
106
108
}
107
109
 
108
110
 
109
 
static void add_new_position(gchar *utf8_filename, gint pos)
 
111
static void add_new_position(const gchar *utf8_filename, gint pos)
110
112
{
111
113
        filepos *npos;
112
114
        guint i;
135
137
/**
136
138
 *  Add old file position and new file position to the navqueue, then goes to the new position.
137
139
 *
138
 
 *  @param old_idx the %document index of the previous position, if set as invalid (-1) then no old
 
140
 *  @param old_doc The document of the previous position, if set as invalid (@c NULL) then no old
139
141
 *         position is set
140
 
 *  @param new_idx the %document index of the new position, must be valid.
 
142
 *  @param new_doc The document of the new position, must be valid.
141
143
 *  @param line the line number of the new position. It is counted with 1 as the first line, not 0.
142
144
 *
143
145
 *  @return @a TRUE if the cursor has changed the position to @a line or @a FALSE otherwise.
144
146
 **/
145
 
gboolean navqueue_goto_line(gint old_idx, gint new_idx, gint line)
 
147
gboolean navqueue_goto_line(GeanyDocument *old_doc, GeanyDocument *new_doc, gint line)
146
148
{
147
149
        gint pos;
148
150
 
149
 
        g_return_val_if_fail(DOC_IDX_VALID(new_idx), FALSE);
 
151
        g_return_val_if_fail(new_doc != NULL, FALSE);
150
152
        g_return_val_if_fail(line >= 1, FALSE);
151
153
 
152
 
        pos = sci_get_position_from_line(doc_list[new_idx].sci, line - 1);
 
154
        pos = sci_get_position_from_line(new_doc->editor->sci, line - 1);
153
155
 
154
156
        /* first add old file position */
155
 
        if (DOC_IDX_VALID(old_idx) && doc_list[old_idx].file_name)
 
157
        if (old_doc != NULL && old_doc->file_name)
156
158
        {
157
 
                gint cur_pos = sci_get_current_position(doc_list[old_idx].sci);
 
159
                gint cur_pos = sci_get_current_position(old_doc->editor->sci);
158
160
 
159
 
                add_new_position(doc_list[old_idx].file_name, cur_pos);
 
161
                add_new_position(old_doc->file_name, cur_pos);
160
162
        }
161
163
 
162
164
        /* now add new file position */
163
 
        if (doc_list[new_idx].file_name)
 
165
        if (new_doc->file_name)
164
166
        {
165
 
                add_new_position(doc_list[new_idx].file_name, pos);
 
167
                add_new_position(new_doc->file_name, pos);
166
168
        }
167
169
 
168
 
        return utils_goto_pos(new_idx, pos);
 
170
        return editor_goto_pos(new_doc->editor, pos, TRUE);
 
171
}
 
172
 
 
173
 
 
174
static gboolean goto_file_pos(const gchar *file, gint pos)
 
175
{
 
176
        GeanyDocument *doc = document_find_by_filename(file);
 
177
 
 
178
        if (doc == NULL)
 
179
                return FALSE;
 
180
 
 
181
        return editor_goto_pos(doc->editor, pos, TRUE);
169
182
}
170
183
 
171
184
 
180
193
 
181
194
        /* jump back */
182
195
        fprev = g_queue_peek_nth(navigation_queue, nav_queue_pos + 1);
183
 
        if (utils_goto_file_pos(fprev->file, FALSE, fprev->pos))
 
196
        if (goto_file_pos(fprev->file, fprev->pos))
184
197
        {
185
198
                nav_queue_pos++;
186
199
        }
203
216
 
204
217
        /* jump forward */
205
218
        fnext = g_queue_peek_nth(navigation_queue, nav_queue_pos - 1);
206
 
        if (utils_goto_file_pos(fnext->file, FALSE, fnext->pos))
 
219
        if (goto_file_pos(fnext->file, fnext->pos))
207
220
        {
208
221
                nav_queue_pos--;
209
222
        }