aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks
diff options
context:
space:
mode:
authorXan Lopez <xan@src.gnome.org>2003-05-11 01:28:07 +0800
committerXan Lopez <xan@src.gnome.org>2003-05-11 01:28:07 +0800
commit62bd43f7d8a97b9a8b84f71cfefdb69f303638aa (patch)
tree68f6080b530f4489fe904e2a454263c116ee3f07 /src/bookmarks
parent477a3fa1f329ab95464c9078f6f33c06774e18c1 (diff)
downloadgsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar.gz
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar.bz2
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar.lz
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar.xz
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.tar.zst
gsoc2013-epiphany-62bd43f7d8a97b9a8b84f71cfefdb69f303638aa.zip
Alphabetical sort of bookmarks menu elements, fixes #111315. Also create
Alphabetical sort of bookmarks menu elements, fixes #111315. Also create ephy-node-common.h with some general enums.
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c13
-rw-r--r--src/bookmarks/ephy-bookmarks.c10
-rw-r--r--src/bookmarks/ephy-topic-action.c116
3 files changed, 120 insertions, 19 deletions
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 7427b3075..964fd301c 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -32,6 +32,7 @@
#include "ephy-bookmarks-editor.h"
#include "ephy-bookmark-properties.h"
+#include "ephy-node-common.h"
#include "ephy-node-view.h"
#include "ephy-window.h"
#include "ephy-dnd.h"
@@ -390,7 +391,7 @@ cmd_delete (EggAction *action,
}
else if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->key_view)))
{
- EphyNodeViewPriority priority;
+ EphyNodePriority priority;
GList *selected;
EphyNode *node;
@@ -398,9 +399,9 @@ cmd_delete (EggAction *action,
node = EPHY_NODE (selected->data);
priority = ephy_node_get_property_int (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- if (priority == -1) priority = EPHY_NODE_VIEW_NORMAL_PRIORITY;
+ if (priority == -1) priority = EPHY_NODE_NORMAL_PRIORITY;
- if (priority == EPHY_NODE_VIEW_NORMAL_PRIORITY)
+ if (priority == EPHY_NODE_NORMAL_PRIORITY)
{
ephy_node_view_remove (EPHY_NODE_VIEW (editor->priv->key_view));
}
@@ -703,7 +704,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
if (key_focus && selected)
{
EphyNode *node = EPHY_NODE (selected->data);
- EphyNodeViewPriority priority;
+ EphyNodePriority priority;
gulong id;
id = ephy_node_get_id (node);
@@ -712,8 +713,8 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
priority = ephy_node_get_property_int
(node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- if (priority == -1) priority = EPHY_NODE_VIEW_NORMAL_PRIORITY;
- key_normal = (priority == EPHY_NODE_VIEW_NORMAL_PRIORITY);
+ if (priority == -1) priority = EPHY_NODE_NORMAL_PRIORITY;
+ key_normal = (priority == EPHY_NODE_NORMAL_PRIORITY);
g_list_free (selected);
}
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index f8eb28469..084d8a343 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -22,7 +22,7 @@
#include "ephy-history.h"
#include "ephy-debug.h"
#include "ephy-tree-model-node.h"
-#include "ephy-node-view.h"
+#include "ephy-node-common.h"
#include "ephy-toolbars-model.h"
#include <string.h>
@@ -597,7 +597,7 @@ ephy_bookmarks_init (EphyBookmarks *eb)
eb->priv->keywords = ephy_node_new_with_id (KEYWORDS_NODE_ID);
ephy_node_ref (eb->priv->keywords);
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, EPHY_NODE_VIEW_ALL_PRIORITY);
+ g_value_set_int (&value, EPHY_NODE_ALL_PRIORITY);
ephy_node_set_property (eb->priv->bookmarks,
EPHY_NODE_KEYWORD_PROP_PRIORITY,
&value);
@@ -621,7 +621,7 @@ ephy_bookmarks_init (EphyBookmarks *eb)
&value);
g_value_unset (&value);
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, EPHY_NODE_VIEW_SPECIAL_PRIORITY);
+ g_value_set_int (&value, EPHY_NODE_SPECIAL_PRIORITY);
ephy_node_set_property (eb->priv->favorites,
EPHY_NODE_KEYWORD_PROP_PRIORITY,
&value);
@@ -638,7 +638,7 @@ ephy_bookmarks_init (EphyBookmarks *eb)
&value);
g_value_unset (&value);
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, EPHY_NODE_VIEW_SPECIAL_PRIORITY);
+ g_value_set_int (&value, EPHY_NODE_SPECIAL_PRIORITY);
ephy_node_set_property (eb->priv->notcategorized,
EPHY_NODE_KEYWORD_PROP_PRIORITY,
&value);
@@ -946,7 +946,7 @@ ephy_bookmarks_add_keyword (EphyBookmarks *eb,
g_value_unset (&value);
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, EPHY_NODE_VIEW_NORMAL_PRIORITY);
+ g_value_set_int (&value, EPHY_NODE_NORMAL_PRIORITY);
ephy_node_set_property (key, EPHY_NODE_KEYWORD_PROP_PRIORITY,
&value);
g_value_unset (&value);
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index 7e3408336..791c98072 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include "ephy-node-common.h"
#include "ephy-topic-action.h"
#include "ephy-bookmarks.h"
#include "ephy-shell.h"
@@ -143,6 +144,29 @@ ephy_topic_action_sync_label (EggAction *action, GParamSpec *pspec, GtkWidget *p
gtk_label_set_label (label, action->label);
}
+static int
+sort_bookmarks (gconstpointer a, gconstpointer b)
+{
+ EphyNode *node_a = (EphyNode *)a;
+ EphyNode *node_b = (EphyNode *)b;
+ char *str_a = NULL;
+ char *str_b = NULL;
+ int retval;
+
+ g_return_val_if_fail (EPHY_IS_NODE (node_a), 1);
+ g_return_val_if_fail (EPHY_IS_NODE (node_b), -1);
+
+ str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE),
+ -1);
+ str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE),
+ -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+
+ return retval;
+}
+
static GtkWidget *
build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
{
@@ -150,6 +174,7 @@ build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
GPtrArray *children;
int i;
EphyFaviconCache *cache;
+ GList *node_list = NULL, *l = NULL;
menu = gtk_menu_new ();
@@ -158,7 +183,15 @@ build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
children = ephy_node_get_children (node);
- // Show an insensitive "Empty" sub-menu if the topic has no children
+ for (i = 0; i < children->len; ++i)
+ {
+ node_list = g_list_append (node_list,
+ g_ptr_array_index (children, i));
+ }
+
+ g_list_sort (node_list, (GCompareFunc)sort_bookmarks);
+
+ /* Show an insensitive "Empty" sub-menu if the topic has no children */
if (children->len < 1)
{
@@ -166,16 +199,15 @@ build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
gtk_widget_set_sensitive (item, FALSE);
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
}
- for (i = 0; i < children->len; i++)
+ for (l = g_list_first (node_list); l != NULL; l = g_list_next (l))
{
EphyNode *kid;
const char *icon_location;
const char *title;
- kid = g_ptr_array_index (children, i);
+ kid = (EphyNode*)l->data;
icon_location = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_ICON);
@@ -208,18 +240,60 @@ build_bookmarks_menu (EphyTopicAction *action, EphyNode *node)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
ephy_node_thaw (node);
+ g_list_free (node_list);
return menu;
}
+static int
+sort_topics (gconstpointer a, gconstpointer b)
+{
+ EphyNode *node_a = (EphyNode *)a;
+ EphyNode *node_b = (EphyNode *)b;
+ EphyNodePriority priority_a, priority_b;
+ char *str_a = NULL;
+ char *str_b = NULL;
+ int retval;
+
+ g_return_val_if_fail (EPHY_IS_NODE (node_a), 1);
+ g_return_val_if_fail (EPHY_IS_NODE (node_b), -1);
+
+ priority_a = ephy_node_get_property_int (node_a, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+ priority_b = ephy_node_get_property_int (node_b, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+
+ if (priority_a < priority_b)
+ {
+ retval = -1;
+ }
+ else if (priority_a > priority_b)
+ {
+ retval = 1;
+ }
+ else
+ {
+ str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME),
+ -1);
+ str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME),
+ -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+ }
+
+ return retval;
+}
+
static GtkWidget *
build_topics_menu (EphyTopicAction *action, EphyNode *node)
{
- GtkWidget *menu, *item;
+ GtkWidget *menu, *item, *label;
GPtrArray *children;
int i;
EphyBookmarks *bookmarks;
EphyNode *all;
+ EphyNodePriority priority;
+ char *markup_title = NULL;
+ GList *node_list = NULL, *l = NULL;
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
all = ephy_bookmarks_get_bookmarks (bookmarks);
@@ -227,20 +301,45 @@ build_topics_menu (EphyTopicAction *action, EphyNode *node)
menu = gtk_menu_new ();
children = ephy_node_get_children (node);
- for (i = 0; i < children->len; i++)
+
+ for (i = 0; i < children->len; ++i)
+ {
+ node_list = g_list_append (node_list,
+ g_ptr_array_index (children, i));
+ }
+
+ g_list_sort (node_list, (GCompareFunc)sort_topics);
+
+ for (l = g_list_first (node_list); l != NULL; l = g_list_next (l))
{
EphyNode *kid;
const char *title;
GtkWidget *bmk_menu;
- kid = g_ptr_array_index (children, i);
+ kid = (EphyNode*)l->data;
if (kid == all) continue;
title = ephy_node_get_property_string
(kid, EPHY_NODE_KEYWORD_PROP_NAME);
+ priority = ephy_node_get_property_int
+ (kid, EPHY_NODE_KEYWORD_PROP_PRIORITY);
LOG ("Create menu for topic %s", title);
- item = gtk_image_menu_item_new_with_label (title);
+ if (priority == EPHY_NODE_ALL_PRIORITY ||
+ priority == EPHY_NODE_SPECIAL_PRIORITY)
+ {
+ markup_title = g_strconcat ("<b>", title, "</b>", NULL);
+ }
+ else
+ {
+ markup_title = g_strdup (title);
+ }
+ item = gtk_image_menu_item_new_with_label (markup_title);
+ g_free (markup_title);
+
+ label = gtk_bin_get_child (GTK_BIN (item));
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
@@ -249,6 +348,7 @@ build_topics_menu (EphyTopicAction *action, EphyNode *node)
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), bmk_menu);
}
ephy_node_thaw (node);
+ g_list_free (node_list);
return menu;
}