summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2005-01-13 20:25:41 +0000
committerShaun McCance <shaunm@src.gnome.org>2005-01-13 20:25:41 +0000
commit6f1b19791506e0026ee45b2756b17d845a86e115 (patch)
tree5c98666f465e1a02c4d010d5d2cb272124484f59
parent89bbe60be107d758fc52e37f8a895c69deeb97fd (diff)
downloadyelp-6f1b19791506e0026ee45b2756b17d845a86e115.tar.gz
- Bookmarks improvements
* data/ui/yelp.glade: * src/yelp-bookmarks.c: - Bookmarks improvements
-rw-r--r--ChangeLog6
-rw-r--r--data/ui/yelp.glade117
-rw-r--r--src/yelp-bookmarks.c500
3 files changed, 382 insertions, 241 deletions
diff --git a/ChangeLog b/ChangeLog
index 4970b4dd..7d332d39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-01-13 Shaun McCance <shaunm@gnome.org>
+
+ * data/ui/yelp.glade:
+ * src/yelp-bookmarks.c:
+ - Bookmarks improvements
+
2005-01-10 Shaun McCance <shaunm@gnome.org>
* data/toc.xml.in:
diff --git a/data/ui/yelp.glade b/data/ui/yelp.glade
index c7fcb9fe..9915b2a7 100644
--- a/data/ui/yelp.glade
+++ b/data/ui/yelp.glade
@@ -815,24 +815,118 @@
</child>
<child>
- <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <widget class="GtkTable" id="table1">
<property name="border_width">6</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="shadow_type">GTK_SHADOW_IN</property>
- <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <property name="homogeneous">False</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">6</property>
+
+ <child>
+ <widget class="GtkLabel" id="label1231">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">&lt;b&gt;_Bookmarks:&lt;/b&gt;</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="mnemonic_widget">bookmarks_view</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
<child>
- <widget class="GtkTreeView" id="bookmarks_view">
+ <widget class="GtkVButtonBox" id="vbuttonbox1">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_START</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkButton" id="open_button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-open</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="rename_button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Re_name</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="remove_button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-remove</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">fill</property>
+ <property name="y_options">fill</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="headers_visible">False</property>
- <property name="rules_hint">False</property>
- <property name="reorderable">False</property>
- <property name="enable_search">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTreeView" id="bookmarks_view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ <property name="rules_hint">False</property>
+ <property name="reorderable">False</property>
+ <property name="enable_search">True</property>
+ </widget>
+ </child>
</widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
</child>
</widget>
<packing>
@@ -939,6 +1033,7 @@
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
+ <property name="mnemonic_widget">bookmark_title_entry</property>
</widget>
<packing>
<property name="padding">0</property>
diff --git a/src/yelp-bookmarks.c b/src/yelp-bookmarks.c
index 3f39b81a..2c37addf 100644
--- a/src/yelp-bookmarks.c
+++ b/src/yelp-bookmarks.c
@@ -46,19 +46,23 @@
#define d(x)
#endif
-#define COL_NAME 0
-#define COL_LABEL 1
-#define COL_SEP 2
+#define COL_NAME 0
+#define COL_LABEL 1
+#define COL_EDIT 2
+#define COL_HEADER 3
#define TOC_PATH "ui/menubar/BookmarksMenu/BookmarksTOC"
#define DOC_PATH "ui/menubar/BookmarksMenu/BookmarksDOC"
static GSList *windows;
-static GtkListStore *actions_store;
+static GtkTreeStore *actions_store;
static gchar *dup_title;
-static gboolean have_tocs = FALSE;
-static gboolean have_docs = FALSE;
-static GtkTreeIter *seperator_iter = NULL;
+static GtkWidget *bookmarks_dialog = NULL;
+
+static gboolean have_toc = FALSE;
+static gboolean have_doc = FALSE;
+static GtkTreeIter toc_iter;
+static GtkTreeIter doc_iter;
typedef struct _YelpWindowData YelpWindowData;
struct _YelpWindowData {
@@ -86,40 +90,42 @@ static gboolean bookmarks_unregister (YelpWindow *window,
static void action_activated_cb (GtkActionGroup *group,
GtkAction *action,
YelpWindowData *data);
-static gboolean row_is_separator (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data);
-void bookmarks_rebuild_menus (void);
-void bookmarks_edit_name_cb (GtkTreeView *treeview,
- GtkTreePath *path,
- GtkTreeViewColumn *col,
- gpointer user_data);
-void bookmarks_edit_response_cb (GtkDialog *dialog,
- gint response,
- gpointer user_data);
-void bookmarks_key_event_cb (GtkWidget *widget,
+static void bookmarks_rebuild_menus (void);
+static void bookmarks_key_event_cb (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data);
+static void bookmarks_open_button_cb (GtkWidget *widget,
+ GtkTreeView *view);
+static void bookmarks_rename_button_cb (GtkWidget *widget,
+ GtkTreeView *view);
+static void bookmarks_remove_button_cb (GtkWidget *widget,
+ GtkTreeView *view);
static gboolean bookmarks_read (void);
-static void bookmarks_add_seperator (void);
-
static gboolean bookmarks_dup_finder (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
+static void bookmarks_open_cb (GtkTreeView *view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *col,
+ gpointer user_data);
+static void bookmarks_cell_edited_cb (GtkCellRendererText *cell,
+ const gchar *path_string,
+ const gchar *new_title,
+ gpointer user_data);
void
yelp_bookmarks_init (void)
{
- GtkTreeIter iter;
gboolean read;
-
+
windows = NULL;
- actions_store = gtk_list_store_new (3,
+ actions_store = gtk_tree_store_new (4,
G_TYPE_STRING,
G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
read = bookmarks_read ();
@@ -130,8 +136,8 @@ yelp_bookmarks_register (YelpWindow *window)
{
GtkUIManager *ui_manager;
YelpWindowData *data;
- GtkTreeIter iter;
- gboolean valid;
+ GtkTreeIter top_iter, sub_iter;
+ gboolean top_valid, sub_valid;
ui_manager = yelp_window_get_ui_manager (window);
@@ -156,47 +162,34 @@ yelp_bookmarks_register (YelpWindow *window)
G_CALLBACK (action_activated_cb),
data);
- valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store), &iter);
- while (valid) {
- gchar *label, *name;
- gboolean sep;
-
- gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &iter,
- COL_NAME, &name,
- COL_LABEL, &label,
- COL_SEP, &sep,
- -1);
- if (!sep)
- window_add_bookmark (data, name, label);
-
- g_free (name);
- g_free (label);
-
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store), &iter);
+ top_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store),
+ &top_iter);
+ while (top_valid) {
+ if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (actions_store),
+ &top_iter)) {
+ sub_valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (actions_store),
+ &sub_iter, &top_iter);
+ while (sub_valid) {
+ gchar *label, *name;
+ gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &sub_iter,
+ COL_NAME, &name,
+ COL_LABEL, &label,
+ -1);
+ window_add_bookmark (data, name, label);
+ g_free (name);
+ g_free (label);
+
+ sub_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &sub_iter);
+ }
+ }
+ top_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &top_iter);
}
windows = g_slist_append (windows, data);
}
-static void
-bookmarks_add_seperator (void)
-{
- GtkTreeIter iter;
-
- if (seperator_iter == NULL) {
- if (have_tocs)
- gtk_list_store_append (actions_store, &iter);
- else
- gtk_list_store_prepend (actions_store, &iter);
- gtk_list_store_set (actions_store, &iter,
- COL_NAME, NULL,
- COL_LABEL, NULL,
- COL_SEP, TRUE,
- -1);
- seperator_iter = gtk_tree_iter_copy (&iter);
- }
-}
-
static gboolean
bookmarks_dup_finder (GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data)
@@ -283,10 +276,11 @@ static void
bookmark_add_response_cb (GtkDialog *dialog, gint id, gchar *uri)
{
GtkEntry *entry;
+ gchar *title;
if (id == GTK_RESPONSE_OK) {
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (dialog), "title_entry"));
- const gchar *title = gtk_entry_get_text (entry);
+ title = (gchar *) gtk_entry_get_text (entry);
bookmarks_add_bookmark (uri, title, TRUE);
}
@@ -308,7 +302,7 @@ bookmarks_add_bookmark (const gchar *uri,
g_free (dup_title);
dup_title = NULL;
gtk_tree_model_foreach (GTK_TREE_MODEL (actions_store),
- bookmarks_dup_finder, uri);
+ bookmarks_dup_finder, (gpointer) uri);
if (dup_title) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new_with_markup
@@ -327,31 +321,43 @@ bookmarks_add_bookmark (const gchar *uri,
tocQ = g_str_has_prefix (uri, "x-yelp-toc:");
if (tocQ) {
- if (seperator_iter == NULL) {
- if (have_docs) {
- bookmarks_add_seperator ();
- gtk_list_store_prepend (actions_store, &iter);
- } else {
- gtk_list_store_append (actions_store, &iter);
- }
- } else {
- gtk_list_store_insert_before (actions_store,
- &iter, seperator_iter);
+ if (!have_toc) {
+ gchar *label = g_markup_printf_escaped ("<b>%s</b>",
+ _("Help Topics"));
+ gtk_tree_store_prepend (actions_store, &toc_iter, NULL);
+ gtk_tree_store_set (actions_store, &toc_iter,
+ COL_NAME, "",
+ COL_LABEL, label,
+ COL_EDIT, FALSE,
+ COL_HEADER, TRUE,
+ -1);
+ have_toc = TRUE;
+ g_free (label);
}
- have_tocs = TRUE;
+ gtk_tree_store_append (actions_store, &iter, &toc_iter);
} else {
- if (seperator_iter == NULL && have_tocs)
- bookmarks_add_seperator ();
- gtk_list_store_append (actions_store, &iter);
- have_docs = TRUE;
+ if (!have_doc) {
+ gchar *label = g_markup_printf_escaped ("<b>%s</b>",
+ _("Document Sections"));
+ gtk_tree_store_append (actions_store, &doc_iter, NULL);
+ gtk_tree_store_set (actions_store, &doc_iter,
+ COL_NAME, "",
+ COL_LABEL, label,
+ COL_EDIT, FALSE,
+ COL_HEADER, TRUE,
+ -1);
+ have_doc = TRUE;
+ g_free (label);
+ }
+ gtk_tree_store_append (actions_store, &iter, &doc_iter);
}
- gtk_list_store_set (actions_store, &iter,
- COL_NAME, uri,
- COL_LABEL, title,
- COL_SEP, FALSE,
+ gtk_tree_store_set (actions_store, &iter,
+ COL_NAME, uri,
+ COL_LABEL, title,
+ COL_EDIT, TRUE,
+ COL_HEADER, FALSE,
-1);
-
if (save) {
for (cur = windows; cur != NULL; cur = cur->next) {
window_add_bookmark ((YelpWindowData *) cur->data, uri, title);
@@ -360,28 +366,7 @@ bookmarks_add_bookmark (const gchar *uri,
}
}
-void
-bookmarks_edit_response_cb (GtkDialog *dialog, gint response,
- gpointer user_data)
-{
- gtk_widget_hide (GTK_WIDGET (dialog));
- if ( response == GTK_RESPONSE_ACCEPT){
- GList *children =
- gtk_container_get_children (GTK_CONTAINER (dialog->vbox));
- GtkEntry *entry = children->data;
- gchar *new_title = (gchar *) gtk_entry_get_text (entry);
- GtkTreePath *path = (GtkTreePath *) user_data;
- GtkTreeIter it;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (actions_store), &it, path);
- gtk_list_store_set (actions_store, &it,
- COL_LABEL, new_title,
- -1);
- bookmarks_rebuild_menus ();
- }
-}
-
-void
+static void
window_remove_bookmark_menu (YelpWindowData *data)
{
GtkUIManager *ui_manager;
@@ -395,7 +380,7 @@ window_remove_bookmark_menu (YelpWindowData *data)
gtk_ui_manager_ensure_update (ui_manager);
}
-void
+static void
window_remove_action (YelpWindowData *data, gchar *name)
{
GtkAction *action = gtk_action_group_get_action (data->toc_actions, name);
@@ -410,46 +395,52 @@ window_remove_action (YelpWindowData *data, gchar *name)
}
}
-void
+static void
bookmarks_rebuild_menus (void)
{
GSList *cur;
- gboolean ret;
- GtkTreeIter iter;
+ GtkTreeIter top_iter, sub_iter;
+ gboolean top_valid, sub_valid;
for (cur = windows; cur != NULL; cur = cur->next) {
window_remove_bookmark_menu ((YelpWindowData *) cur->data);
}
- ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store),
- &iter);
- while (ret) {
- gchar *name, *label;
- gboolean sep;
-
- gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &iter,
- COL_NAME, &name,
- COL_LABEL, &label,
- COL_SEP, &sep,
- -1);
- if (!sep) {
- for (cur = windows; cur != NULL; cur = cur->next) {
- window_remove_action (cur->data, name);
- window_add_bookmark (cur->data, name, label);
+ top_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store),
+ &top_iter);
+ while (top_valid) {
+ if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (actions_store),
+ &top_iter)) {
+ sub_valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (actions_store),
+ &sub_iter, &top_iter);
+ while (sub_valid) {
+ gchar *name, *label;
+ gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &sub_iter,
+ COL_NAME, &name,
+ COL_LABEL, &label,
+ -1);
+ for (cur = windows; cur != NULL; cur = cur->next) {
+ window_remove_action (cur->data, name);
+ window_add_bookmark (cur->data, name, label);
+ }
+ g_free (name);
+ g_free (label);
+
+ sub_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &sub_iter);
}
}
- g_free (name);
- g_free (label);
-
- ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
- &iter);
-
+ top_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &top_iter);
}
+
yelp_bookmarks_write ();
}
-void bookmarks_key_event_cb (GtkWidget *widget, GdkEventKey *event,
- gpointer user_data)
+static void
+bookmarks_key_event_cb (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer user_data)
{
GtkTreeView *view = GTK_TREE_VIEW (widget);
GtkTreePath *path;
@@ -466,12 +457,12 @@ void bookmarks_key_event_cb (GtkWidget *widget, GdkEventKey *event,
switch (event->keyval) {
case GDK_BackSpace:
case GDK_Delete:
- gtk_list_store_remove (actions_store, &iter);
+ gtk_tree_store_remove (actions_store, &iter);
bookmarks_rebuild_menus ();
break;
case GDK_Return:
case GDK_KP_Enter:
- bookmarks_edit_name_cb (view, path, NULL, NULL);
+ bookmarks_open_cb (view, path, NULL, NULL);
break;
case GDK_Up:
gtk_tree_path_prev (path);
@@ -487,91 +478,148 @@ void bookmarks_key_event_cb (GtkWidget *widget, GdkEventKey *event,
}
-
-void
-bookmarks_edit_name_cb (GtkTreeView *treeview, GtkTreePath *path,
- GtkTreeViewColumn *col,
- gpointer user_data)
+static void
+bookmarks_open_cb (GtkTreeView *view, GtkTreePath *path,
+ GtkTreeViewColumn *col, gpointer user_data)
{
GtkTreeIter iter;
gchar *name;
gchar *title;
- GtkDialog *edit;
- GtkWidget *entry;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (actions_store), &iter, path);
+ GSList *cur;
+ YelpWindowData *data;
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (actions_store), &iter, path);
gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &iter,
COL_NAME, &name,
- COL_LABEL, &title,
- -1);
+ COL_LABEL, &title, -1);
- edit = gtk_dialog_new_with_buttons ("Edit bookmark name",
- NULL,
- GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- NULL);
- entry = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (entry), title);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG(edit)->vbox),
- entry);
- g_signal_connect (edit, "response",
- G_CALLBACK (bookmarks_edit_response_cb),
- gtk_tree_path_copy(path));
- gtk_widget_show_all (GTK_WIDGET (edit));
+ cur = windows;
+ data = cur->data;
+
+ g_signal_emit_by_name (data->window, "new_window_requested", name, NULL);
+
+}
+
+
+static void
+bookmarks_cell_edited_cb (GtkCellRendererText *cell, const gchar *path_string,
+ const gchar *new_title, gpointer user_data)
+{
+ GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
+ GtkTreeView *view = GTK_TREE_VIEW (user_data);
+ GtkTreeIter it;
+
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (actions_store), &it, path);
+
+ gtk_tree_store_set (actions_store, &it,
+ COL_LABEL, new_title, -1);
+ bookmarks_rebuild_menus ();
- return;
}
void
yelp_bookmarks_edit (void)
{
GladeXML *glade;
- GtkWidget *dialog;
GtkTreeView *view;
GtkTreeSelection *select;
+ GtkCellRenderer *renderer;
+ GtkWidget *button;
+
+ if (!bookmarks_dialog) {
+ glade = glade_xml_new (DATADIR "/yelp/ui/yelp.glade",
+ "bookmarks_dialog",
+ NULL);
+ if (!glade) {
+ g_warning ("Could not find necessary glade file "
+ DATADIR "/yelp/ui/yelp.glade");
+ return;
+ }
- glade = glade_xml_new (DATADIR "/yelp/ui/yelp.glade",
- "bookmarks_dialog",
- NULL);
- if (!glade) {
- g_warning ("Could not find necessary glade file "
- DATADIR "/yelp/ui/yelp.glade");
- return;
+ bookmarks_dialog = glade_xml_get_widget (glade, "bookmarks_dialog");
+ view = GTK_TREE_VIEW (glade_xml_get_widget (glade, "bookmarks_view"));
+
+ g_signal_connect (G_OBJECT (bookmarks_dialog), "response",
+ G_CALLBACK (gtk_widget_hide), NULL);
+ renderer = gtk_cell_renderer_text_new ();
+
+ gtk_tree_view_insert_column_with_attributes
+ (view, -1,
+ NULL, renderer,
+ "markup", COL_LABEL,
+ "editable", COL_EDIT,
+ NULL);
+ gtk_tree_view_set_model (view, GTK_TREE_MODEL (actions_store));
+
+ select = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+
+ gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
+
+ g_signal_connect (G_OBJECT (view), "row-activated",
+ G_CALLBACK (bookmarks_open_cb),
+ NULL);
+ g_signal_connect (G_OBJECT (view), "key-press-event",
+ G_CALLBACK (bookmarks_key_event_cb),
+ NULL);
+ g_signal_connect (G_OBJECT (renderer), "edited",
+ G_CALLBACK (bookmarks_cell_edited_cb), NULL);
+
+ button = glade_xml_get_widget (glade, "open_button");
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (bookmarks_open_button_cb),
+ view);
+ button = glade_xml_get_widget (glade, "rename_button");
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (bookmarks_rename_button_cb),
+ view);
+ button = glade_xml_get_widget (glade, "remove_button");
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (bookmarks_remove_button_cb),
+ view);
+
+ g_object_unref (glade);
}
- dialog = glade_xml_get_widget (glade, "bookmarks_dialog");
- view = GTK_TREE_VIEW (glade_xml_get_widget (glade, "bookmarks_view"));
+ gtk_window_present (GTK_WINDOW (bookmarks_dialog));
+}
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
+static void
+bookmarks_open_button_cb (GtkWidget *widget, GtkTreeView *view)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeModel *model;
+ GtkTreeSelection *select;
- gtk_tree_view_insert_column_with_attributes
- (view, -1,
- NULL, gtk_cell_renderer_text_new (),
- "text", COL_LABEL,
- NULL);
- gtk_tree_view_set_row_separator_func (view, row_is_separator, NULL, NULL);
+ model = gtk_tree_view_get_model (view);
- gtk_tree_view_set_model (view, GTK_TREE_MODEL (actions_store));
+ select = gtk_tree_view_get_selection (view);
+ gtk_tree_selection_get_selected (select, NULL, &iter);
- select = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ path = gtk_tree_model_get_path (model, &iter);
- gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+ bookmarks_open_cb (view, path, NULL, NULL);
- g_signal_connect (G_OBJECT (view), "row-activated",
- G_CALLBACK (bookmarks_edit_name_cb),
- NULL);
- g_signal_connect (G_OBJECT (view), "key-press-event",
- G_CALLBACK (bookmarks_key_event_cb),
- NULL);
+ gtk_tree_path_free (path);
+}
- g_object_unref (glade);
+static void
+bookmarks_rename_button_cb (GtkWidget *widget, GtkTreeView *view)
+{
+}
- gtk_window_present (GTK_WINDOW (dialog));
+static void
+bookmarks_remove_button_cb (GtkWidget *widget, GtkTreeView *view)
+{
+ GtkTreeIter iter;
+ GtkTreeSelection *select;
+
+ select = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ gtk_tree_selection_get_selected (select, NULL, &iter);
+
+ gtk_tree_store_remove (actions_store, &iter);
+ bookmarks_rebuild_menus ();
}
void
@@ -579,8 +627,8 @@ yelp_bookmarks_write (void)
{
xmlTextWriterPtr file;
gint rc;
- GtkTreeIter iter;
- gboolean res;
+ GtkTreeIter top_iter, sub_iter;
+ gboolean top_valid, sub_valid;
gchar *filename;
filename = g_build_filename (g_get_home_dir (), ".gnome2",
@@ -605,23 +653,23 @@ yelp_bookmarks_write (void)
xmlTextWriterEndElement (file);
xmlTextWriterEndElement (file);
- res = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store),
- &iter);
-
- while (res)
- {
- gchar *name;
- gchar *label;
- gboolean sep;
- gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &iter,
- COL_NAME, &name,
- COL_LABEL, &label,
- COL_SEP, &sep, -1);
-
- xmlTextWriterStartElement (file, BAD_CAST "bookmark");
-
- if (!sep) {
- xmlTextWriterWriteAttribute (file, "href", name);
+ top_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (actions_store),
+ &top_iter);
+
+ while (top_valid) {
+ if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (actions_store),
+ &top_iter)) {
+ sub_valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (actions_store),
+ &sub_iter, &top_iter);
+ while (sub_valid) {
+ gchar *name;
+ gchar *label;
+ gtk_tree_model_get (GTK_TREE_MODEL (actions_store), &sub_iter,
+ COL_NAME, &name,
+ COL_LABEL, &label,
+ -1);
+ xmlTextWriterStartElement (file, BAD_CAST "bookmark");
+ xmlTextWriterWriteAttribute (file, "href", name);
rc = xmlTextWriterWriteElement (file,
BAD_CAST "title",
@@ -632,16 +680,20 @@ yelp_bookmarks_write (void)
rc = xmlTextWriterWriteAttribute
(file, BAD_CAST "owner",
BAD_CAST "http://live.gnome.org/Yelp");
- xmlTextWriterEndElement (file);
- xmlTextWriterEndElement (file);
- }
+ xmlTextWriterEndElement (file); /* metadata */
+ xmlTextWriterEndElement (file); /* info */
+ xmlTextWriterEndElement (file); /* bookmark */
- xmlTextWriterEndElement (file);
+ g_free (name);
+ g_free (label);
- res = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store), &iter);
- g_free (name);
- g_free (label);
+ sub_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &sub_iter);
+ }
}
+ top_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (actions_store),
+ &top_iter);
+ }
rc = xmlTextWriterEndDocument(file);
xmlFreeTextWriter(file);
@@ -766,15 +818,3 @@ action_activated_cb (GtkActionGroup *group,
g_free (uri);
}
-
-static gboolean
-row_is_separator (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- gboolean sep;
-
- gtk_tree_model_get (model, iter, COL_SEP, &sep, -1);
-
- return sep;
-}