aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--src/bookmarks/ephy-new-bookmark.c15
-rw-r--r--src/bookmarks/ephy-topics-selector.c73
-rw-r--r--src/bookmarks/ephy-topics-selector.h2
4 files changed, 101 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 463518fed..bba1dd45b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-06-21 Marco Pesenti Gritti <marco@gnome.org>
+
+ * src/bookmarks/ephy-new-bookmark.c: (response_cb),
+ (ephy_new_bookmark_construct):
+ * src/bookmarks/ephy-topics-selector.c: (renderer_edited_cb),
+ (renderer_editing_canceled_cb), (ephy_topics_build_ui),
+ (ephy_topics_selector_new), (ephy_topics_selector_new_topic):
+ * src/bookmarks/ephy-topics-selector.h:
+
+ Add a New topic button to the new bookmark dialog.
+
2004-06-21 Christian Persch <chpe@cvs.gnome.org>
* lib/egg/egg-toolbars-model.c: (egg_toolbars_model_get_flags),
diff --git a/src/bookmarks/ephy-new-bookmark.c b/src/bookmarks/ephy-new-bookmark.c
index e90bae9f5..341fdd2c5 100644
--- a/src/bookmarks/ephy-new-bookmark.c
+++ b/src/bookmarks/ephy-new-bookmark.c
@@ -54,6 +54,11 @@ static void ephy_new_bookmark_get_property (GObject *object,
#define EPHY_NEW_BOOKMARK_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_NEW_BOOKMARK, EphyNewBookmarkPrivate))
+enum
+{
+ RESPONSE_NEW_TOPIC
+};
+
struct EphyNewBookmarkPrivate
{
EphyBookmarks *bookmarks;
@@ -176,6 +181,10 @@ response_cb (EphyNewBookmark *new_bookmark,
int response_id,
gpointer user_data)
{
+ EphyTopicsSelector *selector;
+
+ selector = EPHY_TOPICS_SELECTOR (new_bookmark->priv->topics_selector);
+
switch (response_id)
{
case GTK_RESPONSE_HELP:
@@ -183,6 +192,9 @@ response_cb (EphyNewBookmark *new_bookmark,
"epiphany",
"to-create-new-bookmark");
break;
+ case RESPONSE_NEW_TOPIC:
+ ephy_topics_selector_new_topic (selector);
+ break;
/* For both OK and Cancel we want to destroy the dialog */
case GTK_RESPONSE_OK:
ephy_new_bookmark_add (new_bookmark);
@@ -283,6 +295,9 @@ ephy_new_bookmark_construct (EphyNewBookmark *editor)
GTK_STOCK_HELP,
GTK_RESPONSE_HELP);
gtk_dialog_add_button (GTK_DIALOG (editor),
+ _("_New Topic"),
+ RESPONSE_NEW_TOPIC);
+ gtk_dialog_add_button (GTK_DIALOG (editor),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (editor),
diff --git a/src/bookmarks/ephy-topics-selector.c b/src/bookmarks/ephy-topics-selector.c
index 7983ca6f9..8d15a59b2 100644
--- a/src/bookmarks/ephy-topics-selector.c
+++ b/src/bookmarks/ephy-topics-selector.c
@@ -26,6 +26,7 @@
#include "ephy-debug.h"
#include "ephy-node-view.h"
+#include <glib/gi18n.h>
#include <gtk/gtkliststore.h>
#include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellrenderertext.h>
@@ -52,6 +53,10 @@ struct EphyTopicsSelectorPrivate
EphyBookmarks *bookmarks;
GtkTreeModel *model;
EphyNode *bookmark;
+
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+ GtkTreePath *edited_path;
};
enum
@@ -346,6 +351,45 @@ topic_key_pressed (GtkTreeView *tree_view,
}
static void
+renderer_edited_cb (GtkCellRendererText *cell,
+ const char *path_str,
+ const char *new_text,
+ EphyTopicsSelector *selector)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ EphyNode *topic;
+
+ path = gtk_tree_path_new_from_string (path_str);
+ gtk_tree_model_get_iter (selector->priv->model, &iter, path);
+
+ topic = ephy_bookmarks_add_keyword (selector->priv->bookmarks, new_text);
+ gtk_list_store_set (GTK_LIST_STORE (selector->priv->model), &iter,
+ COL_HAS_TOPIC, TRUE,
+ COL_TOPIC, new_text,
+ COL_NODE, topic,
+ -1);
+ gtk_tree_path_free (path);
+
+ g_object_set (G_OBJECT (cell), "editable", FALSE, NULL);
+ gtk_tree_path_free (selector->priv->edited_path);
+}
+
+static void
+renderer_editing_canceled_cb (GtkCellRendererText *cell,
+ EphyTopicsSelector *selector)
+{
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter (selector->priv->model, &iter,
+ selector->priv->edited_path);
+ gtk_list_store_remove (GTK_LIST_STORE (selector->priv->model), &iter);
+
+ g_object_set (G_OBJECT (cell), "editable", FALSE, NULL);
+ gtk_tree_path_free (selector->priv->edited_path);
+}
+
+static void
ephy_topics_build_ui (EphyTopicsSelector *editor)
{
GtkListStore *model;
@@ -369,9 +413,15 @@ ephy_topics_build_ui (EphyTopicsSelector *editor)
gtk_tree_view_append_column (GTK_TREE_VIEW (editor), column);
renderer = gtk_cell_renderer_text_new ();
+ editor->priv->renderer = renderer;
column = gtk_tree_view_column_new_with_attributes
("Description", renderer, "text", COL_TOPIC, NULL);
+ editor->priv->column = column;
gtk_tree_view_append_column (GTK_TREE_VIEW (editor), column);
+ g_signal_connect (renderer, "edited",
+ G_CALLBACK (renderer_edited_cb), editor);
+ g_signal_connect (renderer, "editing-canceled",
+ G_CALLBACK (renderer_editing_canceled_cb), editor);
g_signal_connect (G_OBJECT (editor), "key_press_event",
G_CALLBACK (topic_key_pressed), editor);
@@ -406,3 +456,26 @@ ephy_topics_selector_new (EphyBookmarks *bookmarks,
return GTK_WIDGET (editor);
}
+
+void
+ephy_topics_selector_new_topic (EphyTopicsSelector *selector)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ g_object_set (G_OBJECT (selector->priv->renderer),
+ "editable", TRUE, NULL);
+
+ gtk_list_store_append (GTK_LIST_STORE (selector->priv->model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (selector->priv->model), &iter,
+ COL_HAS_TOPIC, FALSE,
+ COL_TOPIC, _("Type a topic"),
+ COL_NODE, NULL,
+ -1);
+
+ path = gtk_tree_model_get_path (selector->priv->model, &iter);
+ gtk_widget_grab_focus (GTK_WIDGET (selector));
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (selector), path,
+ selector->priv->column, TRUE);
+ selector->priv->edited_path = path;
+}
diff --git a/src/bookmarks/ephy-topics-selector.h b/src/bookmarks/ephy-topics-selector.h
index c013b04e6..ce4a4ac35 100644
--- a/src/bookmarks/ephy-topics-selector.h
+++ b/src/bookmarks/ephy-topics-selector.h
@@ -57,6 +57,8 @@ GtkWidget *ephy_topics_selector_new (EphyBookmarks *bookmarks,
void ephy_topics_selector_set_bookmark (EphyTopicsSelector *selector,
EphyNode *bookmark);
+void ephy_topics_selector_new_topic (EphyTopicsSelector *selector);
+
void ephy_topics_selector_apply (EphyTopicsSelector *selector);