~ubuntu-branches/ubuntu/quantal/nautilus/quantal-updates

« back to all changes in this revision

Viewing changes to .pc/15_use-ubuntu-help.patch/src/nautilus-bookmarks-window.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha, Rico Tzschichholz
  • Date: 2012-08-20 23:59:52 UTC
  • mfrom: (1.17.37)
  • Revision ID: package-import@ubuntu.com-20120820235952-m9fr0w393sd2i6we
Tags: 1:3.5.90-0ubuntu1
* New upstream release.
  - Reorganize application and gear menu, and add a menu for view actions
  - Add a View options selector to the toolbar
  - Add cluebars for Templates and Scripts special directories
  - Add ability to reorder bookmarks
  - Improve strings in the Autorun prompt
  - Improve error message strings
  - Improve the image Properties page
  - Improve the Permissions page in the Properties window
  - Improve the layout of the Bookmarks dialog
  - Use the dropped text paragraph as name when creating new files
    using DnD of text snippets
  - Use double quotes instead of ASCII quotes for filenames
  - Change default action for executable text files to Display
  - Change the view mode and zoom level to be per-window instead of
    per-folder
  - Remove support for Manual layouting in icon views outside of Desktop
  - Remove the Octal permissions list view column
  - Fix segfault when no search results are found
  - Change owner pronoun from "me" to "Me" (LP: #1027216)
* Removed upstream patches:
  - git_no_empty_search_segfault.patch
  - git_fix_missing_desktop_menu.patch
* debian/patches/15_use-ubuntu-help.patch: Refreshed

[ Rico Tzschichholz ]
* Refreshed patches:
  - 03_translations_list_update.patch
  - 12_unity_launcher_support.patch
  - 21_correct_timestamp_use_fix_focus_issue.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
 
3
 
/*
4
 
 * Nautilus
5
 
 *
6
 
 * Copyright (C) 1999, 2000 Eazel, Inc.
7
 
 *
8
 
 * Nautilus is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License as
10
 
 * published by the Free Software Foundation; either version 2 of the
11
 
 * License, or (at your option) any later version.
12
 
 *
13
 
 * Nautilus is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program; if not, write to the Free Software
20
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
 
 *
22
 
 * Authors: John Sullivan <sullivan@eazel.com>
23
 
 */
24
 
 
25
 
/* nautilus-bookmarks-window.c - implementation of bookmark-editing window.
26
 
 */
27
 
 
28
 
#include <config.h>
29
 
#include "nautilus-bookmarks-window.h"
30
 
#include "nautilus-window.h"
31
 
 
32
 
#include <libnautilus-private/nautilus-entry.h>
33
 
#include <libnautilus-private/nautilus-global-preferences.h>
34
 
 
35
 
#include <eel/eel-gtk-extensions.h>
36
 
#include <eel/eel-gnome-extensions.h>
37
 
 
38
 
#include <gtk/gtk.h>
39
 
#include <gdk/gdkkeysyms.h>
40
 
#include <glib/gi18n.h>
41
 
 
42
 
/* Static variables to keep track of window state. If there were
43
 
 * more than one bookmark-editing window, these would be struct or
44
 
 * class fields. 
45
 
 */
46
 
static int                   bookmark_list_changed_signal_id;
47
 
static NautilusBookmarkList *bookmarks = NULL;
48
 
static GtkTreeView          *bookmark_list_widget = NULL; /* awkward name to distinguish from NautilusBookmarkList */
49
 
static GtkListStore         *bookmark_list_store = NULL;
50
 
static GtkListStore         *bookmark_empty_list_store = NULL;
51
 
static GtkTreeSelection     *bookmark_selection = NULL;
52
 
static int                   selection_changed_id = 0;
53
 
static GtkWidget            *name_field = NULL;
54
 
static int                   name_field_changed_signal_id;
55
 
static GtkWidget            *remove_button = NULL;
56
 
static GtkWidget            *jump_button = NULL;
57
 
static gboolean              text_changed = FALSE;
58
 
static gboolean              name_text_changed = FALSE;
59
 
static GtkWidget            *uri_field = NULL;
60
 
static int                   uri_field_changed_signal_id;
61
 
static int                   row_changed_signal_id;
62
 
static int                   row_deleted_signal_id;
63
 
static int                   row_activated_signal_id;
64
 
static int                   button_pressed_signal_id;
65
 
static int                   key_pressed_signal_id;
66
 
 
67
 
/* We store a pointer to the bookmark in a column so when an item is moved
68
 
   with DnD we know which item it is. However we have to be careful to keep
69
 
   this in sync with the actual bookmark. Note that
70
 
   nautilus_bookmark_list_insert_item() makes a copy of the bookmark, so we
71
 
   have to fetch the new copy and update our pointer. */
72
 
#define BOOKMARK_LIST_COLUMN_ICON               0
73
 
#define BOOKMARK_LIST_COLUMN_NAME               1
74
 
#define BOOKMARK_LIST_COLUMN_BOOKMARK           2
75
 
#define BOOKMARK_LIST_COLUMN_STYLE              3
76
 
#define BOOKMARK_LIST_COLUMN_COUNT              4
77
 
 
78
 
/* Larger size initially; user can stretch or shrink (but not shrink below min) */
79
 
#define BOOKMARKS_WINDOW_INITIAL_WIDTH  500
80
 
#define BOOKMARKS_WINDOW_INITIAL_HEIGHT 200
81
 
 
82
 
static gboolean
83
 
get_selection_exists (void)
84
 
{
85
 
        return gtk_tree_selection_get_selected (bookmark_selection, NULL, NULL);
86
 
}
87
 
 
88
 
static guint
89
 
get_selected_row (void)
90
 
{
91
 
        GtkTreeIter       iter;
92
 
        GtkTreePath      *path;
93
 
        GtkTreeModel     *model;
94
 
        gint             *indices, row;
95
 
        
96
 
        g_assert (get_selection_exists());
97
 
        
98
 
        model = GTK_TREE_MODEL (bookmark_list_store);
99
 
        gtk_tree_selection_get_selected (bookmark_selection,
100
 
                                         &model,
101
 
                                         &iter);
102
 
        
103
 
        path = gtk_tree_model_get_path (model, &iter);
104
 
        indices = gtk_tree_path_get_indices (path);
105
 
        row = indices[0];
106
 
        gtk_tree_path_free (path);
107
 
        return row;
108
 
}
109
 
 
110
 
static NautilusBookmark *
111
 
get_selected_bookmark (void)
112
 
{
113
 
        g_return_val_if_fail(NAUTILUS_IS_BOOKMARK_LIST(bookmarks), NULL);
114
 
 
115
 
        if (!get_selection_exists())
116
 
                return NULL;
117
 
 
118
 
        if (nautilus_bookmark_list_length (bookmarks) < 1)
119
 
                return NULL;
120
 
 
121
 
        return nautilus_bookmark_list_item_at(bookmarks, get_selected_row ());
122
 
}
123
 
 
124
 
static void
125
 
nautilus_bookmarks_window_response_cb (GtkDialog *dialog,
126
 
                                       int response_id,
127
 
                                       gpointer callback_data)
128
 
{
129
 
        if (response_id == GTK_RESPONSE_HELP) {
130
 
                GError *error = NULL;
131
 
 
132
 
                gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)),
133
 
                              "help:gnome-help/nautilus-bookmarks-edit",
134
 
                              gtk_get_current_event_time (), &error);
135
 
 
136
 
                if (error) {
137
 
                        GtkWidget *err_dialog;
138
 
                        err_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
139
 
                                                             GTK_DIALOG_DESTROY_WITH_PARENT,
140
 
                                                             GTK_MESSAGE_ERROR,
141
 
                                                             GTK_BUTTONS_OK,
142
 
                                                             _("There was an error displaying help: \n%s"),
143
 
                                                             error->message);
144
 
 
145
 
                        g_signal_connect (G_OBJECT (err_dialog),
146
 
                                          "response", G_CALLBACK (gtk_widget_destroy),
147
 
                                          NULL);
148
 
                        gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE);
149
 
                        gtk_widget_show (err_dialog);
150
 
                        g_error_free (error);
151
 
                }
152
 
        } else if (response_id == GTK_RESPONSE_CLOSE) {
153
 
                gtk_widget_destroy (GTK_WIDGET (dialog));
154
 
        }
155
 
}
156
 
 
157
 
static int
158
 
nautilus_bookmarks_window_key_press_event_cb (GtkWindow *window, 
159
 
                                              GdkEventKey *event, 
160
 
                                              gpointer user_data)
161
 
{
162
 
        if (event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_w) {
163
 
                gtk_widget_destroy (GTK_WIDGET (window));
164
 
                return TRUE;
165
 
        }
166
 
 
167
 
        return FALSE;
168
 
}
169
 
 
170
 
static GtkListStore *
171
 
create_bookmark_store (void)
172
 
{
173
 
        return gtk_list_store_new (BOOKMARK_LIST_COLUMN_COUNT,
174
 
                                   G_TYPE_ICON,
175
 
                                   G_TYPE_STRING,
176
 
                                   G_TYPE_OBJECT,
177
 
                                   PANGO_TYPE_STYLE);
178
 
}
179
 
 
180
 
static void
181
 
setup_empty_list (void)
182
 
{
183
 
        GtkTreeIter iter;
184
 
 
185
 
        bookmark_empty_list_store = create_bookmark_store ();
186
 
        gtk_list_store_append (bookmark_empty_list_store, &iter);
187
 
 
188
 
        gtk_list_store_set (bookmark_empty_list_store, &iter,
189
 
                            BOOKMARK_LIST_COLUMN_NAME, _("No bookmarks defined"),
190
 
                            BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_ITALIC,
191
 
                            -1);
192
 
}
193
 
 
194
 
static void
195
 
on_selection_changed (GtkTreeSelection *treeselection,
196
 
                      gpointer user_data)
197
 
{
198
 
        NautilusBookmark *selected;
199
 
        const char *name = NULL;
200
 
        char *entry_text = NULL;
201
 
        GFile *location;
202
 
 
203
 
        g_assert (GTK_IS_ENTRY (name_field));
204
 
        g_assert (GTK_IS_ENTRY (uri_field));
205
 
 
206
 
        selected = get_selected_bookmark ();
207
 
 
208
 
        if (selected) {
209
 
                name = nautilus_bookmark_get_name (selected);
210
 
                location = nautilus_bookmark_get_location (selected);
211
 
                entry_text = g_file_get_parse_name (location);
212
 
 
213
 
                g_object_unref (location);
214
 
        }
215
 
        
216
 
        /* Set the sensitivity of widgets that require a selection */
217
 
        gtk_widget_set_sensitive (remove_button, selected != NULL);
218
 
        gtk_widget_set_sensitive (jump_button, selected != NULL);
219
 
        gtk_widget_set_sensitive (name_field, selected != NULL);
220
 
        gtk_widget_set_sensitive (uri_field, selected != NULL);
221
 
 
222
 
        g_signal_handler_block (name_field, name_field_changed_signal_id);
223
 
        nautilus_entry_set_text (NAUTILUS_ENTRY (name_field),
224
 
                                 name ? name : "");
225
 
        g_signal_handler_unblock (name_field, name_field_changed_signal_id);
226
 
 
227
 
        g_signal_handler_block (uri_field, uri_field_changed_signal_id);
228
 
        nautilus_entry_set_text (NAUTILUS_ENTRY (uri_field),
229
 
                                 entry_text ? entry_text : "");
230
 
        g_signal_handler_unblock (uri_field, uri_field_changed_signal_id);
231
 
 
232
 
        text_changed = FALSE;
233
 
        name_text_changed = FALSE;
234
 
 
235
 
        g_free (entry_text);
236
 
}
237
 
 
238
 
static void
239
 
bookmarks_set_empty (gboolean empty)
240
 
{
241
 
        GtkTreeIter iter;
242
 
 
243
 
        if (empty) {
244
 
                gtk_tree_view_set_model (bookmark_list_widget,
245
 
                                         GTK_TREE_MODEL (bookmark_empty_list_store));
246
 
                gtk_widget_set_sensitive (GTK_WIDGET (bookmark_list_widget), FALSE);
247
 
        } else {
248
 
                gtk_tree_view_set_model (bookmark_list_widget,
249
 
                                         GTK_TREE_MODEL (bookmark_list_store));
250
 
                gtk_widget_set_sensitive (GTK_WIDGET (bookmark_list_widget), TRUE);
251
 
 
252
 
                if (nautilus_bookmark_list_length (bookmarks) > 0 &&
253
 
                    !get_selection_exists ()) {
254
 
                        gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (bookmark_list_store),
255
 
                                                       &iter, NULL, 0);
256
 
                        gtk_tree_selection_select_iter (bookmark_selection, &iter);
257
 
                }
258
 
        }
259
 
 
260
 
        on_selection_changed (bookmark_selection, NULL);
261
 
}
262
 
 
263
 
static void
264
 
repopulate (void)
265
 
{
266
 
        NautilusBookmark *selected;
267
 
        GtkListStore *store;
268
 
        GtkTreePath *path;
269
 
        GtkTreeRowReference *reference;
270
 
        guint index;
271
 
 
272
 
        g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget));
273
 
        g_assert (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
274
 
        
275
 
        store = GTK_LIST_STORE (bookmark_list_store);
276
 
 
277
 
        selected = get_selected_bookmark ();
278
 
 
279
 
        g_signal_handler_block (bookmark_selection,
280
 
                                selection_changed_id);
281
 
        g_signal_handler_block (bookmark_list_store,
282
 
                                row_deleted_signal_id);
283
 
        g_signal_handler_block (bookmark_list_widget,
284
 
                                row_activated_signal_id);
285
 
        g_signal_handler_block (bookmark_list_widget,
286
 
                                key_pressed_signal_id);
287
 
        g_signal_handler_block (bookmark_list_widget,
288
 
                                button_pressed_signal_id);
289
 
 
290
 
        gtk_list_store_clear (store);
291
 
        
292
 
        g_signal_handler_unblock (bookmark_list_widget,
293
 
                                  row_activated_signal_id);
294
 
        g_signal_handler_unblock (bookmark_list_widget,
295
 
                                  key_pressed_signal_id);
296
 
        g_signal_handler_unblock (bookmark_list_widget,
297
 
                                  button_pressed_signal_id);
298
 
        g_signal_handler_unblock (bookmark_list_store,
299
 
                                  row_deleted_signal_id);
300
 
        g_signal_handler_unblock (bookmark_selection,
301
 
                                  selection_changed_id);
302
 
        
303
 
        /* Fill the list in with the bookmark names. */
304
 
        g_signal_handler_block (store, row_changed_signal_id);
305
 
 
306
 
        reference = NULL;
307
 
 
308
 
        for (index = 0; index < nautilus_bookmark_list_length (bookmarks); ++index) {
309
 
                NautilusBookmark *bookmark;
310
 
                const char       *bookmark_name;
311
 
                GIcon            *bookmark_icon;
312
 
                GtkTreeIter       iter;
313
 
 
314
 
                bookmark = nautilus_bookmark_list_item_at (bookmarks, index);
315
 
                bookmark_name = nautilus_bookmark_get_name (bookmark);
316
 
                bookmark_icon = nautilus_bookmark_get_icon (bookmark);
317
 
 
318
 
                gtk_list_store_append (store, &iter);
319
 
                gtk_list_store_set (store, &iter, 
320
 
                                    BOOKMARK_LIST_COLUMN_ICON, bookmark_icon,
321
 
                                    BOOKMARK_LIST_COLUMN_NAME, bookmark_name,
322
 
                                    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark,
323
 
                                    BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_NORMAL,
324
 
                                    -1);
325
 
 
326
 
                if (bookmark == selected) {
327
 
                        /* save old selection */
328
 
                        GtkTreePath *path;
329
 
 
330
 
                        path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
331
 
                        reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
332
 
                        gtk_tree_path_free (path);
333
 
                }
334
 
 
335
 
                g_object_unref (bookmark_icon);
336
 
        }
337
 
 
338
 
        g_signal_handler_unblock (store, row_changed_signal_id);
339
 
 
340
 
        if (reference != NULL) {
341
 
                /* restore old selection */
342
 
 
343
 
                /* bookmarks_set_empty() will call the selection change handler,
344
 
                 * so we block it here in case of selection change.
345
 
                 */
346
 
                g_signal_handler_block (bookmark_selection, selection_changed_id);
347
 
 
348
 
                g_assert (index != 0);
349
 
                g_assert (gtk_tree_row_reference_valid (reference));
350
 
 
351
 
                path = gtk_tree_row_reference_get_path (reference);
352
 
                gtk_tree_selection_select_path (bookmark_selection, path);
353
 
                gtk_tree_row_reference_free (reference);
354
 
                gtk_tree_path_free (path);
355
 
 
356
 
                g_signal_handler_unblock (bookmark_selection, selection_changed_id);
357
 
        }
358
 
 
359
 
        bookmarks_set_empty (index == 0);         
360
 
}
361
 
 
362
 
static void
363
 
on_bookmark_list_changed (NautilusBookmarkList *bookmarks, gpointer data)
364
 
{
365
 
        g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
366
 
 
367
 
        /* maybe add logic here or in repopulate to save/restore selection */
368
 
        repopulate ();
369
 
}
370
 
 
371
 
static void
372
 
on_name_field_changed (GtkEditable *editable,
373
 
                       gpointer     user_data)
374
 
{
375
 
        GtkTreeIter   iter;
376
 
        g_return_if_fail(GTK_IS_TREE_VIEW(bookmark_list_widget));
377
 
        g_return_if_fail(GTK_IS_ENTRY(name_field));
378
 
 
379
 
        if (!get_selection_exists())
380
 
                return;
381
 
 
382
 
        /* Update text displayed in list instantly. Also remember that 
383
 
         * user has changed text so we update real bookmark later. 
384
 
         */
385
 
        gtk_tree_selection_get_selected (bookmark_selection,
386
 
                                         NULL,
387
 
                                         &iter);
388
 
        
389
 
        gtk_list_store_set (bookmark_list_store, 
390
 
                            &iter, BOOKMARK_LIST_COLUMN_NAME, 
391
 
                            gtk_entry_get_text (GTK_ENTRY (name_field)),
392
 
                            -1);
393
 
        text_changed = TRUE;
394
 
        name_text_changed = TRUE;
395
 
}
396
 
 
397
 
static void
398
 
open_selected_bookmark (NautilusWindow *window)
399
 
{
400
 
        NautilusBookmark *selected;
401
 
        GFile *location;
402
 
        
403
 
        selected = get_selected_bookmark ();
404
 
 
405
 
        if (!selected) {
406
 
                return;
407
 
        }
408
 
 
409
 
        location = nautilus_bookmark_get_location (selected);
410
 
        if (location == NULL) { 
411
 
                return;
412
 
        }
413
 
 
414
 
        nautilus_window_go_to (window, location);
415
 
 
416
 
        g_object_unref (location);
417
 
}
418
 
 
419
 
static void
420
 
on_jump_button_clicked (GtkButton *button,
421
 
                        gpointer   user_data)
422
 
{
423
 
        open_selected_bookmark (user_data);
424
 
}
425
 
 
426
 
static void
427
 
bookmarks_delete_bookmark (void)
428
 
{
429
 
        GtkTreeIter iter;
430
 
        GtkTreePath *path;
431
 
        gint *indices, row, rows;
432
 
 
433
 
        g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget));
434
 
        
435
 
        if (!gtk_tree_selection_get_selected (bookmark_selection, NULL, &iter))
436
 
                return;
437
 
 
438
 
        /* Remove the selected item from the list store. on_row_deleted() will
439
 
           remove it from the bookmark list. */
440
 
        path = gtk_tree_model_get_path (GTK_TREE_MODEL (bookmark_list_store),
441
 
                                        &iter);
442
 
        indices = gtk_tree_path_get_indices (path);
443
 
        row = indices[0];
444
 
        gtk_tree_path_free (path);
445
 
 
446
 
        gtk_list_store_remove (bookmark_list_store, &iter);
447
 
 
448
 
        /* Try to select the same row, or the last one in the list. */
449
 
        rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (bookmark_list_store), NULL);
450
 
        if (row >= rows)
451
 
                row = rows - 1;
452
 
 
453
 
        if (row < 0) {
454
 
                bookmarks_set_empty (TRUE);
455
 
        } else {
456
 
                gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (bookmark_list_store),
457
 
                                               &iter, NULL, row);
458
 
                gtk_tree_selection_select_iter (bookmark_selection, &iter);
459
 
        }
460
 
}
461
 
 
462
 
static void
463
 
on_remove_button_clicked (GtkButton *button,
464
 
                          gpointer   user_data)
465
 
{
466
 
        bookmarks_delete_bookmark ();
467
 
}
468
 
 
469
 
 
470
 
/* This is a bit of a kludge to get DnD to work. We check if the row in the
471
 
   GtkListStore matches the one in the bookmark list. If it doesn't, we assume
472
 
   the bookmark has just been dragged here and we insert it into the bookmark
473
 
   list. */
474
 
static void
475
 
on_row_changed (GtkListStore *store,
476
 
                GtkTreePath *path,
477
 
                GtkTreeIter *iter,
478
 
                gpointer user_data)
479
 
{
480
 
        NautilusBookmark *bookmark = NULL, *bookmark_in_list;
481
 
        gint *indices, row;
482
 
        gboolean insert_bookmark = TRUE;
483
 
 
484
 
        store = bookmark_list_store;
485
 
 
486
 
        indices = gtk_tree_path_get_indices (path);
487
 
        row = indices[0];
488
 
        gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
489
 
                            BOOKMARK_LIST_COLUMN_BOOKMARK, &bookmark,
490
 
                            -1);
491
 
 
492
 
        /* If the bookmark in the list doesn't match the changed one, it must
493
 
           have been dragged here, so we insert it into the list. */
494
 
        if (row < (gint) nautilus_bookmark_list_length (bookmarks)) {
495
 
                bookmark_in_list = nautilus_bookmark_list_item_at (bookmarks,
496
 
                                                                   row);
497
 
                if (bookmark_in_list == bookmark)
498
 
                        insert_bookmark = FALSE;
499
 
        }
500
 
 
501
 
        if (insert_bookmark) {
502
 
                g_signal_handler_block (bookmarks,
503
 
                                        bookmark_list_changed_signal_id);
504
 
                nautilus_bookmark_list_insert_item (bookmarks, bookmark, row);
505
 
                g_signal_handler_unblock (bookmarks,
506
 
                                          bookmark_list_changed_signal_id);
507
 
 
508
 
                /* The bookmark will be copied when inserted into the list, so
509
 
                   we have to update the pointer in the list store. */
510
 
                bookmark = nautilus_bookmark_list_item_at (bookmarks, row);
511
 
                g_signal_handler_block (store, row_changed_signal_id);
512
 
                gtk_list_store_set (store, iter,
513
 
                                    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark,
514
 
                                    -1);
515
 
                g_signal_handler_unblock (store, row_changed_signal_id);
516
 
        }
517
 
}
518
 
 
519
 
static void
520
 
update_bookmark_from_text (void)
521
 
{
522
 
        NautilusBookmark *bookmark, *bookmark_in_list;
523
 
        const char *name;
524
 
        GIcon *icon;
525
 
        guint selected_row;
526
 
        GtkTreeIter iter;
527
 
        GFile *location;
528
 
 
529
 
        g_assert (GTK_IS_ENTRY (name_field));
530
 
        g_assert (GTK_IS_ENTRY (uri_field));
531
 
 
532
 
        if (!text_changed ||
533
 
            gtk_entry_get_text_length (GTK_ENTRY (uri_field)) == 0) {
534
 
                return;
535
 
        }
536
 
 
537
 
        location = g_file_parse_name 
538
 
                (gtk_entry_get_text (GTK_ENTRY (uri_field)));
539
 
                
540
 
        bookmark = nautilus_bookmark_new (location,
541
 
                                          name_text_changed ? gtk_entry_get_text (GTK_ENTRY (name_field)) : NULL,
542
 
                                          NULL);
543
 
                
544
 
        g_object_unref (location);
545
 
 
546
 
        selected_row = get_selected_row ();
547
 
 
548
 
        /* turn off list updating 'cuz otherwise the list-reordering code runs
549
 
         * after repopulate(), thus reordering the correctly-ordered list.
550
 
         */
551
 
        g_signal_handler_block (bookmarks, 
552
 
                                bookmark_list_changed_signal_id);
553
 
        nautilus_bookmark_list_delete_item_at (bookmarks, selected_row);
554
 
        nautilus_bookmark_list_insert_item (bookmarks, bookmark, selected_row);
555
 
        g_signal_handler_unblock (bookmarks, 
556
 
                                  bookmark_list_changed_signal_id);
557
 
        g_object_unref (bookmark);
558
 
 
559
 
        /* We also have to update the bookmark pointer in the list
560
 
           store. */
561
 
        gtk_tree_selection_get_selected (bookmark_selection,
562
 
                                         NULL, &iter);
563
 
        g_signal_handler_block (bookmark_list_store,
564
 
                                row_changed_signal_id);
565
 
 
566
 
        bookmark_in_list = nautilus_bookmark_list_item_at (bookmarks,
567
 
                                                           selected_row);
568
 
 
569
 
        name = nautilus_bookmark_get_name (bookmark_in_list);
570
 
        icon = nautilus_bookmark_get_icon (bookmark_in_list);
571
 
 
572
 
        gtk_list_store_set (bookmark_list_store, &iter,
573
 
                            BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list,
574
 
                            BOOKMARK_LIST_COLUMN_NAME, name,
575
 
                            BOOKMARK_LIST_COLUMN_ICON, icon,
576
 
                            -1);
577
 
        g_signal_handler_unblock (bookmark_list_store,
578
 
                                  row_changed_signal_id);
579
 
 
580
 
        g_object_unref (icon);
581
 
}
582
 
 
583
 
/* The update_bookmark_from_text() calls in the
584
 
 * on_button_pressed() and on_key_pressed() handlers
585
 
 * of the tree view are a hack.
586
 
 *
587
 
 * The purpose is to track selection changes to the view
588
 
 * and write the text fields back before the selection
589
 
 * actually changed.
590
 
 *
591
 
 * Note that the focus-out event of the text entries is emitted
592
 
 * after the selection changed, else this would not not be neccessary.
593
 
 */
594
 
 
595
 
static gboolean
596
 
on_button_pressed (GtkTreeView *view,
597
 
                   GdkEventButton *event,
598
 
                   gpointer user_data)
599
 
{
600
 
        update_bookmark_from_text ();
601
 
 
602
 
        return FALSE;
603
 
}
604
 
 
605
 
static gboolean
606
 
on_key_pressed (GtkTreeView *view,
607
 
                GdkEventKey *event,
608
 
                gpointer user_data)
609
 
{
610
 
        if (event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_KP_Delete) {
611
 
                bookmarks_delete_bookmark ();
612
 
                return TRUE;
613
 
        }
614
 
 
615
 
        update_bookmark_from_text ();
616
 
 
617
 
        return FALSE;
618
 
}
619
 
 
620
 
static void
621
 
on_row_activated (GtkTreeView       *view,
622
 
                  GtkTreePath       *path,
623
 
                  GtkTreeViewColumn *column,
624
 
                  gpointer           user_data)
625
 
{
626
 
        open_selected_bookmark (user_data);
627
 
}
628
 
 
629
 
static void
630
 
on_row_deleted (GtkListStore *store,
631
 
                GtkTreePath *path,
632
 
                gpointer user_data)
633
 
{
634
 
        gint *indices, row;
635
 
 
636
 
        indices = gtk_tree_path_get_indices (path);
637
 
        row = indices[0];
638
 
 
639
 
        g_signal_handler_block (bookmarks, bookmark_list_changed_signal_id);
640
 
        nautilus_bookmark_list_delete_item_at (bookmarks, row);
641
 
        g_signal_handler_unblock (bookmarks, bookmark_list_changed_signal_id);
642
 
}
643
 
 
644
 
static gboolean
645
 
on_text_field_focus_out_event (GtkWidget *widget,
646
 
                               GdkEventFocus *event,
647
 
                               gpointer user_data)
648
 
{
649
 
        g_assert (NAUTILUS_IS_ENTRY (widget));
650
 
 
651
 
        update_bookmark_from_text ();
652
 
        return FALSE;
653
 
}
654
 
 
655
 
static void
656
 
name_or_uri_field_activate (NautilusEntry *entry)
657
 
{
658
 
        g_assert (NAUTILUS_IS_ENTRY (entry));
659
 
 
660
 
        update_bookmark_from_text ();
661
 
        nautilus_entry_select_all_at_idle (entry);
662
 
}
663
 
 
664
 
static void
665
 
on_uri_field_changed (GtkEditable *editable,
666
 
                      gpointer user_data)
667
 
{
668
 
        /* Remember that user has changed text so we 
669
 
         * update real bookmark later. 
670
 
         */
671
 
        text_changed = TRUE;
672
 
}
673
 
 
674
 
/**
675
 
 * nautilus_bookmarks_window_new:
676
 
 * 
677
 
 * Create a new bookmark-editing window. 
678
 
 * @list: The NautilusBookmarkList that this window will edit.
679
 
 *
680
 
 * Return value: A pointer to the new window.
681
 
 **/
682
 
GtkWindow *
683
 
nautilus_bookmarks_window_new (NautilusWindow *parent_window,
684
 
                               NautilusBookmarkList *list)
685
 
{
686
 
        GtkWindow         *window;
687
 
        GtkTreeViewColumn *col;
688
 
        GtkCellRenderer   *rend;
689
 
        GtkBuilder        *builder;
690
 
 
691
 
        bookmarks = list;
692
 
 
693
 
        builder = gtk_builder_new ();
694
 
        if (!gtk_builder_add_from_resource (builder,
695
 
                                            "/org/gnome/nautilus/nautilus-bookmarks-window.ui",
696
 
                                            NULL)) {
697
 
                return NULL;
698
 
        }
699
 
 
700
 
        window = GTK_WINDOW (gtk_builder_get_object (builder, "bookmarks_dialog"));
701
 
 
702
 
        gtk_window_set_wmclass (window, "bookmarks", "Nautilus");
703
 
        gtk_window_set_default_size (window, 
704
 
                                     BOOKMARKS_WINDOW_INITIAL_WIDTH, 
705
 
                                     BOOKMARKS_WINDOW_INITIAL_HEIGHT);
706
 
        gtk_window_set_application (window,
707
 
                                    gtk_window_get_application (GTK_WINDOW (parent_window)));
708
 
        gtk_window_set_destroy_with_parent (window, TRUE);
709
 
 
710
 
        g_signal_connect (window, "key-press-event",
711
 
                          G_CALLBACK (nautilus_bookmarks_window_key_press_event_cb), NULL);
712
 
        g_signal_connect (window, "response",
713
 
                          G_CALLBACK (nautilus_bookmarks_window_response_cb), NULL);
714
 
 
715
 
        bookmark_list_widget = GTK_TREE_VIEW (gtk_builder_get_object (builder, "bookmark_tree_view"));
716
 
        remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_delete_button"));
717
 
        jump_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_jump_button"));
718
 
 
719
 
        rend = gtk_cell_renderer_pixbuf_new ();
720
 
        g_object_set (rend,
721
 
                      "follow-state", TRUE,
722
 
                      NULL);
723
 
        col = gtk_tree_view_column_new_with_attributes ("Icon", 
724
 
                                                        rend,
725
 
                                                        "gicon", 
726
 
                                                        BOOKMARK_LIST_COLUMN_ICON,
727
 
                                                        NULL);
728
 
        gtk_tree_view_append_column (bookmark_list_widget,
729
 
                                     GTK_TREE_VIEW_COLUMN (col));
730
 
        gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (col),
731
 
                                              NAUTILUS_ICON_SIZE_SMALLER);
732
 
 
733
 
        rend = gtk_cell_renderer_text_new ();
734
 
        g_object_set (rend,
735
 
                      "ellipsize", PANGO_ELLIPSIZE_END,
736
 
                      "ellipsize-set", TRUE,
737
 
                      NULL);
738
 
 
739
 
        col = gtk_tree_view_column_new_with_attributes ("Icon", 
740
 
                                                        rend,
741
 
                                                        "text", 
742
 
                                                        BOOKMARK_LIST_COLUMN_NAME,
743
 
                                                        "style",
744
 
                                                        BOOKMARK_LIST_COLUMN_STYLE,
745
 
                                                        NULL);
746
 
        gtk_tree_view_append_column (bookmark_list_widget,
747
 
                                     GTK_TREE_VIEW_COLUMN (col));
748
 
        
749
 
        bookmark_list_store = create_bookmark_store ();
750
 
        setup_empty_list ();
751
 
        gtk_tree_view_set_model (bookmark_list_widget,
752
 
                                 GTK_TREE_MODEL (bookmark_empty_list_store));
753
 
        
754
 
        bookmark_selection =
755
 
                GTK_TREE_SELECTION (gtk_tree_view_get_selection (bookmark_list_widget));
756
 
 
757
 
        name_field = nautilus_entry_new ();
758
 
        
759
 
        gtk_widget_show (name_field);
760
 
        gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_name_placeholder")),
761
 
                            name_field, TRUE, TRUE, 0);
762
 
        
763
 
        gtk_label_set_mnemonic_widget (
764
 
                GTK_LABEL (gtk_builder_get_object (builder, "bookmark_name_label")),
765
 
                name_field);
766
 
 
767
 
        uri_field = nautilus_entry_new ();
768
 
        gtk_widget_show (uri_field);
769
 
        gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_location_placeholder")),
770
 
                            uri_field, TRUE, TRUE, 0);
771
 
 
772
 
        gtk_label_set_mnemonic_widget (
773
 
                GTK_LABEL (gtk_builder_get_object (builder, "bookmark_location_label")),
774
 
                uri_field);
775
 
 
776
 
        bookmark_list_changed_signal_id =
777
 
                g_signal_connect (bookmarks, "changed",
778
 
                                  G_CALLBACK (on_bookmark_list_changed), NULL);
779
 
        row_changed_signal_id =
780
 
                g_signal_connect (bookmark_list_store, "row_changed",
781
 
                                  G_CALLBACK (on_row_changed), NULL);
782
 
        row_deleted_signal_id =
783
 
                g_signal_connect (bookmark_list_store, "row_deleted",
784
 
                                  G_CALLBACK (on_row_deleted), NULL);
785
 
        row_activated_signal_id =
786
 
                g_signal_connect (bookmark_list_widget, "row_activated",
787
 
                                  G_CALLBACK (on_row_activated), parent_window);
788
 
        button_pressed_signal_id =
789
 
                g_signal_connect (bookmark_list_widget, "button_press_event",
790
 
                                  G_CALLBACK (on_button_pressed), NULL);
791
 
        key_pressed_signal_id =
792
 
                g_signal_connect (bookmark_list_widget, "key_press_event",
793
 
                                  G_CALLBACK (on_key_pressed), NULL);
794
 
        selection_changed_id =
795
 
                g_signal_connect (bookmark_selection, "changed",
796
 
                                  G_CALLBACK (on_selection_changed), NULL);     
797
 
 
798
 
        name_field_changed_signal_id =
799
 
                g_signal_connect (name_field, "changed",
800
 
                                  G_CALLBACK (on_name_field_changed), NULL);
801
 
                                    
802
 
        g_signal_connect (name_field, "focus_out_event",
803
 
                          G_CALLBACK (on_text_field_focus_out_event), NULL);                            
804
 
        g_signal_connect (name_field, "activate",
805
 
                          G_CALLBACK (name_or_uri_field_activate), NULL);
806
 
 
807
 
        uri_field_changed_signal_id = 
808
 
                g_signal_connect (uri_field, "changed",
809
 
                                  G_CALLBACK (on_uri_field_changed), NULL);
810
 
                                    
811
 
        g_signal_connect (uri_field, "focus_out_event",
812
 
                          G_CALLBACK (on_text_field_focus_out_event), NULL);
813
 
        g_signal_connect (uri_field, "activate",
814
 
                          G_CALLBACK (name_or_uri_field_activate), NULL);
815
 
        g_signal_connect (remove_button, "clicked",
816
 
                          G_CALLBACK (on_remove_button_clicked), NULL);
817
 
        g_signal_connect (jump_button, "clicked",
818
 
                          G_CALLBACK (on_jump_button_clicked), parent_window);
819
 
 
820
 
        gtk_tree_selection_set_mode (bookmark_selection, GTK_SELECTION_BROWSE);
821
 
        
822
 
        /* Fill in list widget with bookmarks, must be after signals are wired up. */
823
 
        repopulate();
824
 
 
825
 
        g_object_unref (builder);
826
 
        
827
 
        return GTK_WINDOW (window);
828
 
}