aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamon Chaplin <damon@helixcode.com>2000-07-17 14:22:18 +0800
committerDamon Chaplin <damon@src.gnome.org>2000-07-17 14:22:18 +0800
commit4c3eaff412bf29bf8eb5e5dda2f11a9b24a46abb (patch)
tree0c5573bb616e7dd351bb3ed7f5d441daddfdf381
parent237f2dc92b27da3e11c2ea4fcea7b45f7196f583 (diff)
downloadgsoc2013-evolution-4c3eaff412bf29bf8eb5e5dda2f11a9b24a46abb.tar.gz
gsoc2013-evolution-4c3eaff412bf29bf8eb5e5dda2f11a9b24a46abb.tar.zst
gsoc2013-evolution-4c3eaff412bf29bf8eb5e5dda2f11a9b24a46abb.zip
new files implementing a simple model for the shortcuts, so we can have
2000-07-16 Damon Chaplin <damon@helixcode.com> * e-shortcut-model.[hc]: new files implementing a simple model for the shortcuts, so we can have multiple views. * Makefile.am (libshortcut_bar_a_SOURCES): added e-shortcut-model.[hc] * e-shortcut-bar.[hc]: updated to use the model. * e-icon-bar.c (e_icon_bar_item_pressed): set mouse_over_item_num as well as pressed_item_num to fix bug. svn path=/trunk/; revision=4186
-rw-r--r--widgets/shortcut-bar/ChangeLog12
-rw-r--r--widgets/shortcut-bar/Makefile.am2
-rw-r--r--widgets/shortcut-bar/e-group-bar.c3
-rw-r--r--widgets/shortcut-bar/e-icon-bar-bg-item.c1
-rw-r--r--widgets/shortcut-bar/e-icon-bar.c6
-rw-r--r--widgets/shortcut-bar/e-shortcut-bar.c402
-rw-r--r--widgets/shortcut-bar/e-shortcut-bar.h32
-rw-r--r--widgets/shortcut-bar/e-vscrolled-bar.c2
-rw-r--r--widgets/shortcut-bar/test-shortcut-bar.c67
9 files changed, 298 insertions, 229 deletions
diff --git a/widgets/shortcut-bar/ChangeLog b/widgets/shortcut-bar/ChangeLog
index 2b32884bb3..5019955680 100644
--- a/widgets/shortcut-bar/ChangeLog
+++ b/widgets/shortcut-bar/ChangeLog
@@ -1,3 +1,15 @@
+2000-07-16 Damon Chaplin <damon@helixcode.com>
+
+ * e-shortcut-model.[hc]: new files implementing a simple model for
+ the shortcuts, so we can have multiple views.
+
+ * Makefile.am (libshortcut_bar_a_SOURCES): added e-shortcut-model.[hc]
+
+ * e-shortcut-bar.h: updated to use the model.
+
+ * e-icon-bar.c (e_icon_bar_item_pressed): set mouse_over_item_num as
+ well as pressed_item_num to fix bug.
+
2000-07-10 Ettore Perazzoli <ettore@helixcode.com>
* e-group-bar.c (e_group_bar_add): Set `group_bar'.
diff --git a/widgets/shortcut-bar/Makefile.am b/widgets/shortcut-bar/Makefile.am
index 71b8446363..9f17d684b6 100644
--- a/widgets/shortcut-bar/Makefile.am
+++ b/widgets/shortcut-bar/Makefile.am
@@ -18,6 +18,8 @@ libshortcut_bar_a_SOURCES = \
e-icon-bar.h \
e-shortcut-bar.c \
e-shortcut-bar.h \
+ e-shortcut-model.c \
+ e-shortcut-model.h \
e-vscrolled-bar.c \
e-vscrolled-bar.h
diff --git a/widgets/shortcut-bar/e-group-bar.c b/widgets/shortcut-bar/e-group-bar.c
index bd96898765..dd78fe6243 100644
--- a/widgets/shortcut-bar/e-group-bar.c
+++ b/widgets/shortcut-bar/e-group-bar.c
@@ -34,10 +34,9 @@
* GtkNotebook tab labels.
*/
+#include <config.h>
#include <math.h>
-
#include <gnome.h>
-
#include "e-group-bar.h"
#define E_GROUP_BAR_SCROLL_TIMEOUT 10
diff --git a/widgets/shortcut-bar/e-icon-bar-bg-item.c b/widgets/shortcut-bar/e-icon-bar-bg-item.c
index 025bd6f467..5154a38267 100644
--- a/widgets/shortcut-bar/e-icon-bar-bg-item.c
+++ b/widgets/shortcut-bar/e-icon-bar-bg-item.c
@@ -28,6 +28,7 @@
* the lines between items when dragging.
*/
+#include <config.h>
#include "e-icon-bar-bg-item.h"
#include "e-icon-bar.h"
diff --git a/widgets/shortcut-bar/e-icon-bar.c b/widgets/shortcut-bar/e-icon-bar.c
index 73346b8535..832506201d 100644
--- a/widgets/shortcut-bar/e-icon-bar.c
+++ b/widgets/shortcut-bar/e-icon-bar.c
@@ -27,6 +27,7 @@
* icons and descriptions. It provides 2 views - large icons and small icons.
*/
+#include <config.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <gdk-pixbuf/gnome-canvas-pixbuf.h>
@@ -296,8 +297,6 @@ e_icon_bar_destroy (GtkObject *object)
icon_bar = E_ICON_BAR (object);
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
-
for (item_num = 0; item_num < icon_bar->items->len; item_num++) {
item = &g_array_index (icon_bar->items,
EIconBarItem, item_num);
@@ -311,6 +310,8 @@ e_icon_bar_destroy (GtkObject *object)
gtk_timeout_remove (icon_bar->auto_scroll_timeout_id);
icon_bar->auto_scroll_timeout_id = 0;
}
+
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
@@ -1037,6 +1038,7 @@ e_icon_bar_item_pressed (EIconBar *icon_bar,
button = event->button.button;
if (button == 1 && item_num != -1) {
+ icon_bar->mouse_over_item_num = item_num;
icon_bar->pressed_item_num = item_num;
icon_bar->pressed_x = event->button.x;
icon_bar->pressed_y = event->button.y;
diff --git a/widgets/shortcut-bar/e-shortcut-bar.c b/widgets/shortcut-bar/e-shortcut-bar.c
index f3af57d659..20e0336fcb 100644
--- a/widgets/shortcut-bar/e-shortcut-bar.c
+++ b/widgets/shortcut-bar/e-shortcut-bar.c
@@ -23,14 +23,19 @@
*/
/*
- * ShortcutBar displays a vertical bar with a number of Groups, each of which
+ * EShortcutBar displays a vertical bar with a number of Groups, each of which
* contains any number of icons. It is used on the left of the main application
* window so users can easily access items such as folders and files.
+ *
+ * The architecture is a bit complicated. EShortcutBar is a sublass of
+ * EGroupBar (which supports a number of groups with buttons to slide them
+ * into view). EShortcutBar places an EIconBar widget in each group page,
+ * which displays an icon and name for each shortcut.
*/
+#include <config.h>
#include <string.h>
-#include <gnome.h>
-
+#include <e-util/e-util.h>
#include "e-shortcut-bar.h"
#include "e-clipped-label.h"
#include "e-vscrolled-bar.h"
@@ -44,57 +49,91 @@ static GtkTargetEntry target_table[] = {
};
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
-gboolean e_shortcut_bar_default_icon_loaded = FALSE;
-GdkPixbuf *e_shortcut_bar_default_icon = NULL;
-gchar *e_shortcut_bar_default_icon_filename = "gnome-folder.png";
-
-static void e_shortcut_bar_class_init (EShortcutBarClass *class);
-static void e_shortcut_bar_init (EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_destroy (GtkObject *object);
-static void e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar,
- GtkWidget *canvas);
-static void e_shortcut_bar_item_selected (EIconBar *icon_bar,
- GdkEvent *event,
- gint item_num,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_item_dragged (EIconBar *icon_bar,
- GdkEvent *event,
- gint item_num,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_on_drag_data_get (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_on_drag_data_received (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *data,
- guint info,
- guint time,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_on_drag_data_delete (GtkWidget *widget,
- GdkDragContext *context,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_on_drag_end (GtkWidget *widget,
- GdkDragContext *context,
- EShortcutBar *shortcut_bar);
-static void e_shortcut_bar_stop_editing (GtkWidget *button,
- EShortcutBar *shortcut_bar);
+gboolean e_shortcut_bar_default_icon_loaded = FALSE;
+GdkPixbuf *e_shortcut_bar_default_icon = NULL;
+gchar *e_shortcut_bar_default_icon_filename = "gnome-folder.png";
+
+static void e_shortcut_bar_class_init (EShortcutBarClass *class);
+static void e_shortcut_bar_init (EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_destroy (GtkObject *object);
+
+static void e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar);
+
+static void e_shortcut_bar_on_model_destroyed (EShortcutModel *model,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_group_added (EShortcutModel *model,
+ gint group_num,
+ gchar *group_name,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_group_removed (EShortcutModel *model,
+ gint group_num,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_item_added (EShortcutModel *model,
+ gint group_num,
+ gint item_num,
+ gchar *item_url,
+ gchar *item_name,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_item_removed (EShortcutModel *model,
+ gint group_num,
+ gint item_num,
+ EShortcutBar *shortcut_bar);
+
+static gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar,
+ gint position,
+ const gchar *group_name);
+static void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
+ gint group_num);
+static gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar,
+ gint group_num,
+ gint position,
+ const gchar *item_url,
+ const gchar *item_name);
+static void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
+ gint group_num,
+ gint item_num);
+
+
+static void e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar,
+ GtkWidget *canvas);
+static void e_shortcut_bar_item_selected (EIconBar *icon_bar,
+ GdkEvent *event,
+ gint item_num,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_item_dragged (EIconBar *icon_bar,
+ GdkEvent *event,
+ gint item_num,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_drag_data_received(GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *data,
+ guint info,
+ guint time,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_drag_data_delete (GtkWidget *widget,
+ GdkDragContext *context,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_on_drag_end (GtkWidget *widget,
+ GdkDragContext *context,
+ EShortcutBar *shortcut_bar);
+static void e_shortcut_bar_stop_editing (GtkWidget *button,
+ EShortcutBar *shortcut_bar);
static GdkPixbuf* e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
const gchar *item_url);
-static GdkPixbuf* e_shortcut_bar_load_image (const gchar *filename);
+static GdkPixbuf* e_shortcut_bar_load_image (const gchar *filename);
enum
{
ITEM_SELECTED,
- ITEM_ADDED,
- ITEM_REMOVED,
- GROUP_ADDED,
- GROUP_REMOVED,
LAST_SIGNAL
};
@@ -103,30 +142,9 @@ static guint e_shortcut_bar_signals[LAST_SIGNAL] = {0};
static EGroupBarClass *parent_class;
-GtkType
-e_shortcut_bar_get_type (void)
-{
- static GtkType e_shortcut_bar_type = 0;
-
- if (!e_shortcut_bar_type){
- GtkTypeInfo e_shortcut_bar_info = {
- "EShortcutBar",
- sizeof (EShortcutBar),
- sizeof (EShortcutBarClass),
- (GtkClassInitFunc) e_shortcut_bar_class_init,
- (GtkObjectInitFunc) e_shortcut_bar_init,
- NULL, /* reserved 1 */
- NULL, /* reserved 2 */
- (GtkClassInitFunc) NULL
- };
-
- parent_class = gtk_type_class (e_group_bar_get_type ());
- e_shortcut_bar_type = gtk_type_unique (e_group_bar_get_type (),
- &e_shortcut_bar_info);
- }
-
- return e_shortcut_bar_type;
-}
+E_MAKE_TYPE(e_shortcut_bar, "EShortcutBar", EShortcutBar,
+ e_shortcut_bar_class_init, e_shortcut_bar_init,
+ e_group_bar_get_type())
static void
@@ -135,6 +153,8 @@ e_shortcut_bar_class_init (EShortcutBarClass *class)
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
+ parent_class = gtk_type_class (e_group_bar_get_type ());
+
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
@@ -148,44 +168,6 @@ e_shortcut_bar_class_init (EShortcutBarClass *class)
GTK_TYPE_NONE, 3, GTK_TYPE_GDK_EVENT,
GTK_TYPE_INT, GTK_TYPE_INT);
- e_shortcut_bar_signals[ITEM_ADDED] =
- gtk_signal_new ("item_added",
- GTK_RUN_LAST | GTK_RUN_ACTION,
- object_class->type,
- GTK_SIGNAL_OFFSET (EShortcutBarClass,
- added_item),
- gtk_marshal_NONE__INT_INT,
- GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
-
- /* This is emitted just before the item is actually removed. */
- e_shortcut_bar_signals[ITEM_REMOVED] =
- gtk_signal_new ("item_removed",
- GTK_RUN_LAST | GTK_RUN_ACTION,
- object_class->type,
- GTK_SIGNAL_OFFSET (EShortcutBarClass,
- removed_item),
- gtk_marshal_NONE__INT_INT,
- GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
-
- e_shortcut_bar_signals[GROUP_ADDED] =
- gtk_signal_new ("group_added",
- GTK_RUN_LAST | GTK_RUN_ACTION,
- object_class->type,
- GTK_SIGNAL_OFFSET (EShortcutBarClass,
- added_group),
- gtk_marshal_NONE__INT,
- GTK_TYPE_NONE, 1, GTK_TYPE_INT);
-
- /* This is emitted just before the group is actually removed. */
- e_shortcut_bar_signals[GROUP_REMOVED] =
- gtk_signal_new ("group_removed",
- GTK_RUN_LAST | GTK_RUN_ACTION,
- object_class->type,
- GTK_SIGNAL_OFFSET (EShortcutBarClass,
- removed_group),
- gtk_marshal_NONE__INT,
- GTK_TYPE_NONE, 1, GTK_TYPE_INT);
-
gtk_object_class_add_signals (object_class, e_shortcut_bar_signals,
LAST_SIGNAL);
@@ -223,14 +205,139 @@ e_shortcut_bar_destroy (GtkObject *object)
shortcut_bar = E_SHORTCUT_BAR (object);
+ g_array_free (shortcut_bar->groups, TRUE);
+
+ g_free (shortcut_bar->dragged_url);
+ g_free (shortcut_bar->dragged_name);
+
GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
- g_array_free (shortcut_bar->groups, TRUE);
+
+void
+e_shortcut_bar_set_model (EShortcutBar *shortcut_bar,
+ EShortcutModel *model)
+{
+ gint num_groups, group_num, num_items, item_num;
+ gchar *group_name, *item_url, *item_name;
+
+ /* Disconnect any existing model. */
+ e_shortcut_bar_disconnect_model (shortcut_bar);
+
+ shortcut_bar->model = model;
+
+ if (!model)
+ return;
+
+ gtk_signal_connect (GTK_OBJECT (model), "destroy",
+ GTK_SIGNAL_FUNC (e_shortcut_bar_on_model_destroyed),
+ shortcut_bar);
+ gtk_signal_connect (GTK_OBJECT (model), "group_added",
+ GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_added),
+ shortcut_bar);
+ gtk_signal_connect (GTK_OBJECT (model), "group_removed",
+ GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_removed),
+ shortcut_bar);
+ gtk_signal_connect (GTK_OBJECT (model), "item_added",
+ GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_added),
+ shortcut_bar);
+ gtk_signal_connect (GTK_OBJECT (model), "item_removed",
+ GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_removed),
+ shortcut_bar);
+
+ /* Add any items already in the model. */
+ num_groups = e_shortcut_model_get_num_groups (model);
+ for (group_num = 0; group_num < num_groups; group_num++) {
+ group_name = e_shortcut_model_get_group_name (model,
+ group_num);
+ e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
+ g_free (group_name);
+
+ num_items = e_shortcut_model_get_num_items (model, group_num);
+ for (item_num = 0; item_num < num_items; item_num++) {
+ e_shortcut_model_get_item_info (model, group_num,
+ item_num, &item_url,
+ &item_name);
+ e_shortcut_bar_add_item (shortcut_bar, group_num,
+ item_num, item_url,
+ item_name);
+ g_free (item_url);
+ g_free (item_name);
+ }
+ }
+}
+
+
+static void
+e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar)
+{
+ /* Remove all the current groups. */
+ while (shortcut_bar->groups->len)
+ e_shortcut_bar_remove_group (shortcut_bar, 0);
+
+ if (shortcut_bar->model) {
+ /* Disconnect all the signals in one go. */
+ gtk_signal_disconnect_by_data (GTK_OBJECT (shortcut_bar->model), shortcut_bar);
+ shortcut_bar->model = NULL;
+ }
+}
+
+
+static void
+e_shortcut_bar_on_model_destroyed (EShortcutModel *model,
+ EShortcutBar *shortcut_bar)
+{
+ e_shortcut_bar_disconnect_model (shortcut_bar);
+}
+
+
+static void
+e_shortcut_bar_on_group_added (EShortcutModel *model,
+ gint group_num,
+ gchar *group_name,
+ EShortcutBar *shortcut_bar)
+{
+ e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
+}
+
+
+static void
+e_shortcut_bar_on_group_removed (EShortcutModel *model,
+ gint group_num,
+ EShortcutBar *shortcut_bar)
+{
+ e_shortcut_bar_remove_group (shortcut_bar, group_num);
+}
+
+
+static void
+e_shortcut_bar_on_item_added (EShortcutModel *model,
+ gint group_num,
+ gint item_num,
+ gchar *item_url,
+ gchar *item_name,
+ EShortcutBar *shortcut_bar)
+{
+ e_shortcut_bar_add_item (shortcut_bar, group_num, item_num,
+ item_url, item_name);
}
-gint
-e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, const gchar *group_name)
+static void
+e_shortcut_bar_on_item_removed (EShortcutModel *model,
+ gint group_num,
+ gint item_num,
+ EShortcutBar *shortcut_bar)
+{
+ e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num);
+}
+
+
+
+static gint
+e_shortcut_bar_add_group (EShortcutBar *shortcut_bar,
+ gint position,
+ const gchar *group_name)
{
EShortcutBarGroup *group, tmp_group;
gint group_num;
@@ -242,8 +349,8 @@ e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, const gchar *group_name)
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
gtk_widget_push_visual (gdk_rgb_get_visual ());
- group_num = shortcut_bar->groups->len;
- g_array_append_val (shortcut_bar->groups, tmp_group);
+ group_num = position;
+ g_array_insert_val (shortcut_bar->groups, group_num, tmp_group);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
@@ -307,30 +414,25 @@ e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, const gchar *group_name)
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
- gtk_signal_emit (GTK_OBJECT (shortcut_bar),
- e_shortcut_bar_signals[GROUP_ADDED],
- group_num);
-
return group_num;
}
-void
-e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
- gint group_num)
+static void
+e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
+ gint group_num)
{
- gtk_signal_emit (GTK_OBJECT (shortcut_bar),
- e_shortcut_bar_signals[GROUP_REMOVED],
- group_num);
-
e_group_bar_remove_group (E_GROUP_BAR (shortcut_bar), group_num);
g_array_remove_index (shortcut_bar->groups, group_num);
}
-gint
-e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, gint group_num,
- const gchar *item_url, const gchar *item_name)
+static gint
+e_shortcut_bar_add_item (EShortcutBar *shortcut_bar,
+ gint group_num,
+ gint position,
+ const gchar *item_url,
+ const gchar *item_name)
{
EShortcutBarGroup *group;
GdkPixbuf *image;
@@ -347,23 +449,19 @@ e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, gint group_num,
EShortcutBarGroup, group_num);
item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar),
- image, item_name, -1);
+ image, item_name, position);
gdk_pixbuf_unref (image);
e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), item_num,
g_strdup (item_url), g_free);
- gtk_signal_emit (GTK_OBJECT (shortcut_bar),
- e_shortcut_bar_signals[ITEM_ADDED],
- group_num, item_num);
-
return item_num;
}
-void
-e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
- gint group_num,
- gint item_num)
+static void
+e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
+ gint group_num,
+ gint item_num)
{
EShortcutBarGroup *group;
@@ -374,10 +472,6 @@ e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
- gtk_signal_emit (GTK_OBJECT (shortcut_bar),
- e_shortcut_bar_signals[ITEM_REMOVED],
- group_num, item_num);
-
e_icon_bar_remove_item (E_ICON_BAR (group->icon_bar), item_num);
}
@@ -512,35 +606,23 @@ e_shortcut_bar_on_drag_data_received (GtkWidget *widget,
guint time,
EShortcutBar *shortcut_bar)
{
- EShortcutBarGroup *group;
gchar *item_name, *item_url;
EIconBar *icon_bar;
- GdkPixbuf *image;
- gint group_num, item_num;
+ gint position, group_num;
icon_bar = E_ICON_BAR (widget);
+ position = icon_bar->dragging_before_item_num;
if ((data->length >= 0) && (data->format == 8)
- && icon_bar->dragging_before_item_num != -1) {
+ && position != -1) {
item_name = data->data;
item_url = item_name + strlen (item_name) + 1;
- image = e_shortcut_bar_get_image_from_url (shortcut_bar,
- item_url);
-
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
GTK_WIDGET (icon_bar)->parent);
- group = &g_array_index (shortcut_bar->groups,
- EShortcutBarGroup, group_num);
-
- item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar), image, item_name, icon_bar->dragging_before_item_num);
- e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar),
- item_num, g_strdup (item_url),
- g_free);
- gtk_signal_emit (GTK_OBJECT (shortcut_bar),
- e_shortcut_bar_signals[ITEM_ADDED],
- group_num, item_num);
+ e_shortcut_model_add_item (shortcut_bar->model, group_num,
+ position, item_url, item_name);
gtk_drag_finish (context, TRUE, TRUE, time);
return;
@@ -563,8 +645,8 @@ e_shortcut_bar_on_drag_data_delete (GtkWidget *widget,
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
widget->parent);
- e_shortcut_bar_remove_item (shortcut_bar, group_num,
- icon_bar->dragged_item_num);
+ e_shortcut_model_remove_item (shortcut_bar->model, group_num,
+ icon_bar->dragged_item_num);
}
diff --git a/widgets/shortcut-bar/e-shortcut-bar.h b/widgets/shortcut-bar/e-shortcut-bar.h
index 8d151b0a4e..573303d290 100644
--- a/widgets/shortcut-bar/e-shortcut-bar.h
+++ b/widgets/shortcut-bar/e-shortcut-bar.h
@@ -26,6 +26,7 @@
#include "e-group-bar.h"
#include "e-icon-bar.h"
+#include "e-shortcut-model.h"
#ifdef __cplusplus
extern "C" {
@@ -58,7 +59,6 @@ struct _EShortcutBarGroup
#define E_TYPE_SHORTCUT_BAR (e_shortcut_bar_get_type ())
-#define SHORTCUT_BAR(obj) GTK_CHECK_CAST (obj, e_shortcut_bar_get_type (), EShortcutBar)
#define E_SHORTCUT_BAR(obj) GTK_CHECK_CAST (obj, e_shortcut_bar_get_type (), EShortcutBar)
#define E_SHORTCUT_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_bar_get_type (), EShortcutBarClass)
#define E_IS_SHORTCUT_BAR(obj) GTK_CHECK_TYPE (obj, e_shortcut_bar_get_type ())
@@ -68,6 +68,9 @@ struct _EShortcutBar
{
EGroupBar group_bar;
+ /* This is the underlying model. */
+ EShortcutModel *model;
+
/* This is an array of EShortcutBarGroup elements. */
GArray *groups;
@@ -90,27 +93,15 @@ struct _EShortcutBarClass
GdkEvent *event,
gint group_num,
gint item_num);
- void (*added_item) (EShortcutBar *shortcut_bar,
- gint group_num,
- gint item_num);
- void (*removed_item) (EShortcutBar *shortcut_bar,
- gint group_num,
- gint item_num);
- void (*added_group) (EShortcutBar *shortcut_bar,
- gint group_num);
- void (*removed_group) (EShortcutBar *shortcut_bar,
- gint group_num);
};
GtkType e_shortcut_bar_get_type (void);
GtkWidget* e_shortcut_bar_new (void);
-/* Adds a new group, returning the index. */
-gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar,
- const gchar *group_name);
-void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
- gint group_num);
+/* Sets the underlying model. */
+void e_shortcut_bar_set_model (EShortcutBar *shortcut_bar,
+ EShortcutModel *shortcut_model);
/* Sets/gets the view type for the group. */
void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar,
@@ -119,18 +110,9 @@ void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar
EIconBarViewType e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar,
gint group_num);
-/* Adds a new item to a group, returning the index within the group. */
-gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar,
- gint group_num,
- const gchar *item_url,
- const gchar *item_name);
-
void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
-void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
- gint group_num,
- gint item_num);
/* Sets the callback which is called to return the icon to use for a particular
URL. This callback must be set before any items are added. If the callback
diff --git a/widgets/shortcut-bar/e-vscrolled-bar.c b/widgets/shortcut-bar/e-vscrolled-bar.c
index edd60f29fb..decfffc3e4 100644
--- a/widgets/shortcut-bar/e-vscrolled-bar.c
+++ b/widgets/shortcut-bar/e-vscrolled-bar.c
@@ -27,10 +27,10 @@
* vertically. It is intended for scrolling narrow vertical bars.
*/
+#include <config.h>
#include <gtk/gtkarrow.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtksignal.h>
-
#include "e-vscrolled-bar.h"
/* These are the offsets of the up & down buttons from the right and top/bottom
diff --git a/widgets/shortcut-bar/test-shortcut-bar.c b/widgets/shortcut-bar/test-shortcut-bar.c
index 3d3503c745..9197fdf16e 100644
--- a/widgets/shortcut-bar/test-shortcut-bar.c
+++ b/widgets/shortcut-bar/test-shortcut-bar.c
@@ -80,27 +80,26 @@ static void rename_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void remove_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
-static void on_move_button_clicked (GtkWidget *button,
- EShortcutBar *shortcut_bar);
static void on_set_group_button_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar);
static void on_set_group_button_no_animation_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar);
-static void on_item_added (EShortcutBar *shortcut_bar,
+static void on_item_added (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
-static void on_item_removed (EShortcutBar *shortcut_bar,
+static void on_item_removed (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
-static void on_group_added (EShortcutBar *shortcut_bar,
+static void on_group_added (EShortcutModel *shortcut_model,
gint group_num);
-static void on_group_removed (EShortcutBar *shortcut_bar,
+static void on_group_removed (EShortcutModel *shortcut_model,
gint group_num);
int
main (int argc, char *argv[])
{
GtkWidget *window, *hpaned, *shortcut_bar, *vbox, *button;
+ EShortcutModel *shortcut_model;
gchar *pathname;
gint i;
@@ -120,20 +119,24 @@ main (int argc, char *argv[])
gnome_app_set_contents (GNOME_APP (window), hpaned);
gtk_widget_show (hpaned);
+ shortcut_model = e_shortcut_model_new ();
+
shortcut_bar = e_shortcut_bar_new ();
+ e_shortcut_bar_set_model (E_SHORTCUT_BAR (shortcut_bar),
+ shortcut_model);
e_paned_pack1 (E_PANED (hpaned), shortcut_bar, FALSE, TRUE);
gtk_widget_show (shortcut_bar);
e_shortcut_bar_set_icon_callback (E_SHORTCUT_BAR (shortcut_bar),
icon_callback,
NULL);
- gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_added",
+ gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_added",
GTK_SIGNAL_FUNC (on_item_added), NULL);
- gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_removed",
+ gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_removed",
GTK_SIGNAL_FUNC (on_item_removed), NULL);
- gtk_signal_connect (GTK_OBJECT (shortcut_bar), "group_added",
+ gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_added",
GTK_SIGNAL_FUNC (on_group_added), NULL);
- gtk_signal_connect (GTK_OBJECT (shortcut_bar), "group_removed",
+ gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_removed",
GTK_SIGNAL_FUNC (on_group_removed), NULL);
#if 0
@@ -155,13 +158,6 @@ main (int argc, char *argv[])
GTK_SIGNAL_FUNC (on_main_label_size_allocate),
NULL);
- button = gtk_button_new_with_label ("Move 1st group to 4th");
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
- gtk_signal_connect (GTK_OBJECT (button), "clicked",
- GTK_SIGNAL_FUNC (on_move_button_clicked),
- shortcut_bar);
-
button = gtk_button_new_with_label ("Set current group to 3rd");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
@@ -253,12 +249,11 @@ add_test_group (EShortcutBar *shortcut_bar, gint i, gchar *group_name)
gchar buffer[128];
gint shortcut_type, j;
- group_num = e_shortcut_bar_add_group (E_SHORTCUT_BAR (shortcut_bar),
- group_name);
+ group_num = e_shortcut_model_add_group (shortcut_bar->model, -1,
+ group_name);
if (group_num % 2)
- e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (shortcut_bar),
- group_num,
+ e_shortcut_bar_set_view_type (shortcut_bar, group_num,
E_ICON_BAR_SMALL_ICONS);
num_items = get_random_int (5) + 3;
@@ -271,7 +266,10 @@ add_test_group (EShortcutBar *shortcut_bar, gint i, gchar *group_name)
sprintf (buffer, "Item %i:%i\n", i, j);
shortcut_type = get_random_int (NUM_SHORTCUT_TYPES);
- item_num = e_shortcut_bar_add_item (E_SHORTCUT_BAR (shortcut_bar), group_num, shortcut_types[shortcut_type], buffer);
+ item_num = e_shortcut_model_add_item (shortcut_bar->model,
+ group_num, -1,
+ shortcut_types[shortcut_type],
+ buffer);
}
}
@@ -435,7 +433,7 @@ remove_group (GtkWidget *menuitem,
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
- e_shortcut_bar_remove_group (shortcut_bar, group_num);
+ e_shortcut_model_remove_group (shortcut_bar->model, group_num);
}
@@ -547,7 +545,8 @@ remove_item (GtkWidget *menuitem,
item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"item_num"));
- e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num);
+ e_shortcut_model_remove_item (shortcut_bar->model, group_num,
+ item_num);
}
@@ -558,7 +557,7 @@ on_set_group_button_clicked (GtkWidget *button,
g_print ("In on_set_group_button_clicked\n");
e_group_bar_set_current_group_num (E_GROUP_BAR (shortcut_bar),
- 2, FALSE);
+ 2, TRUE);
}
@@ -574,17 +573,7 @@ on_set_group_button_no_animation_clicked (GtkWidget *button,
static void
-on_move_button_clicked (GtkWidget *button,
- EShortcutBar *shortcut_bar)
-{
- g_print ("In on_move_button_clicked\n");
-
- e_group_bar_reorder_group (E_GROUP_BAR (shortcut_bar), 0, 3);
-}
-
-
-static void
-on_item_added (EShortcutBar *shortcut_bar,
+on_item_added (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
@@ -593,7 +582,7 @@ on_item_added (EShortcutBar *shortcut_bar,
static void
-on_item_removed (EShortcutBar *shortcut_bar,
+on_item_removed (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
@@ -602,7 +591,7 @@ on_item_removed (EShortcutBar *shortcut_bar,
static void
-on_group_added (EShortcutBar *shortcut_bar,
+on_group_added (EShortcutModel *shortcut_model,
gint group_num)
{
g_print ("In on_group_added Group:%i\n", group_num);
@@ -610,7 +599,7 @@ on_group_added (EShortcutBar *shortcut_bar,
static void
-on_group_removed (EShortcutBar *shortcut_bar,
+on_group_removed (EShortcutModel *shortcut_model,
gint group_num)
{
g_print ("In on_group_removed Group:%i\n", group_num);