summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@cvs.gnome.org>2006-07-23 18:20:42 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2006-07-23 18:20:42 +0000
commit9287ef60f180ebef2e1b61fe74338e3704243e87 (patch)
tree2e9fbd3753467a2a2e88fe01cf74cd4b8d411bdb
parentce5897676b601a58930b8a35eaf3fe3175f647a4 (diff)
downloadgnome-dictionary-9287ef60f180ebef2e1b61fe74338e3704243e87.tar.gz
A src/gdict-sidebar.h A src/gdict-sidebar.c
2006-07-23 Emmanuele Bassi <ebassi@cvs.gnome.org> A src/gdict-sidebar.h A src/gdict-sidebar.c * src/gdict-sidebar.h: * src/gdict-sidebar.c: Add a side bar widget, similar to Evince and Totem own side bar. * data/gnome-dictionary-ui.xml: Add new actions for the View menu, controlling the visibility of the speller, database chooser (NYI), side bar and status bar. * data/gnome-dictionary.schemas.in: Remove the 'speller-visible' key, and add the 'sidebar-visible' and 'statusbar-visible' keys. * libgdict/gdict-database-chooser.h * libgdict/gdict-database-chooser.c: Implement the database chooser as the speller widget: a box containing a treeview with all the available databases; to be displayed inside the side bar. Not yet finished. * libgdict/gdict-speller.h: * libgdict/gdict-speller.c: Remove the "sidebar" look and make it a bit less specialized widget to be embedded inside the side bar. Do not leak the list store. * src/Makefile.am: Add gdict-sidebar.[ch] to the build. * src/gdict-applet.c (gdict_applet_lookup_end_cb): Cast the window pointer. * src/gdict-pref-dialog.h: Add the macros for the new keys. * src/gdict-window.h: * src/gdict-window.c: Control the status bar using a GConf key and a menu item; add the new GdictSidebar widget and embed the speller widget as a page inside it.
-rw-r--r--ChangeLog39
-rw-r--r--TODO3
-rw-r--r--data/gnome-dictionary-ui.xml4
-rw-r--r--data/gnome-dictionary.schemas.in26
-rw-r--r--libgdict/gdict-database-chooser.c149
-rw-r--r--libgdict/gdict-database-chooser.h16
-rw-r--r--libgdict/gdict-speller.c63
-rw-r--r--libgdict/gdict-speller.h3
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gdict-applet.c2
-rw-r--r--src/gdict-pref-dialog.h3
-rw-r--r--src/gdict-sidebar.c464
-rw-r--r--src/gdict-sidebar.h72
-rw-r--r--src/gdict-window.c205
-rw-r--r--src/gdict-window.h9
15 files changed, 901 insertions, 161 deletions
diff --git a/ChangeLog b/ChangeLog
index 8fef0ed..0a41ea8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2006-07-23 Emmanuele Bassi <ebassi@cvs.gnome.org>
+
+ A src/gdict-sidebar.h
+ A src/gdict-sidebar.c
+
+ * src/gdict-sidebar.h:
+ * src/gdict-sidebar.c: Add a side bar widget, similar to
+ Evince and Totem own side bar.
+
+ * data/gnome-dictionary-ui.xml: Add new actions for the
+ View menu, controlling the visibility of the speller,
+ database chooser (NYI), side bar and status bar.
+
+ * data/gnome-dictionary.schemas.in: Remove the 'speller-visible'
+ key, and add the 'sidebar-visible' and 'statusbar-visible' keys.
+
+ * libgdict/gdict-database-chooser.h
+ * libgdict/gdict-database-chooser.c: Implement the database
+ chooser as the speller widget: a box containing a treeview with
+ all the available databases; to be displayed inside the side
+ bar. Not yet finished.
+
+ * libgdict/gdict-speller.h:
+ * libgdict/gdict-speller.c: Remove the "sidebar" look and make
+ it a bit less specialized widget to be embedded inside the
+ side bar. Do not leak the list store.
+
+ * src/Makefile.am: Add gdict-sidebar.[ch] to the build.
+
+ * src/gdict-applet.c (gdict_applet_lookup_end_cb): Cast the
+ window pointer.
+
+ * src/gdict-pref-dialog.h: Add the macros for the new keys.
+
+ * src/gdict-window.h:
+ * src/gdict-window.c: Control the status bar using a GConf key
+ and a menu item; add the new GdictSidebar widget and embed the
+ speller widget as a page inside it.
+
2006-07-22 Emmanuele Bassi <ebassi@cvs.gnome.org>
* src/gdict-applet.c: Remove an unneeded function; use
diff --git a/TODO b/TODO
index da7f208..f03f3fc 100644
--- a/TODO
+++ b/TODO
@@ -5,7 +5,8 @@
[+] Gdict::Defbox
[ ] common pattern recognition for definition sections
[ ] colors for sections (with theme support)
- [ ] Gdict::Speller
+ [+] Gdict::Speller
+ [ ] visually separate matchs from different dictionaries
* UI additions
[ ] Gdict::DatabaseChooser (combo with all the databases available on
diff --git a/data/gnome-dictionary-ui.xml b/data/gnome-dictionary-ui.xml
index 5eaa984..e96d867 100644
--- a/data/gnome-dictionary-ui.xml
+++ b/data/gnome-dictionary-ui.xml
@@ -20,7 +20,11 @@
<menuitem name="EditPreferencesMenu" action="EditPreferences"/>
</menu>
<menu name="ViewMenu" action="View">
+ <menuitem name="ViewSidebarMenu" action="ViewSidebar"/>
+ <menuitem name="ViewStatusbarMenu" action="ViewStatusbar"/>
+ <separator/>
<menuitem name="ViewSpellerMenu" action="ViewSpeller"/>
+ <menuitem name="ViewDBMenu" action="ViewDB"/>
</menu>
<menu name="GoMenu" action="Go">
<menuitem name="GoPreviousDefMenu" action="GoPreviousDef"/>
diff --git a/data/gnome-dictionary.schemas.in b/data/gnome-dictionary.schemas.in
index 77660e6..32f6fb7 100644
--- a/data/gnome-dictionary.schemas.in
+++ b/data/gnome-dictionary.schemas.in
@@ -140,20 +140,34 @@
</schema>
<schema>
- <key>/schemas/apps/gnome-dictionary/speller-visible</key>
- <applyto>/apps/gnome-dictionary/speller-visible</applyto>
+ <key>/schemas/apps/gnome-dictionary/sidebar-visible</key>
+ <applyto>/apps/gnome-dictionary/sidebar-visible</applyto>
<owner>gnome-dictionary</owner>
<type>bool</type>
<default>FALSE</default>
<locale name="C">
- <short>Whether the speller should be visible</short>
- <long>This key defines whether the speller widget should be visible
- and it's used to remember the state of the speller widgets across
- sessions. Setting it to TRUE will make the speller widget always
+ <short>Whether the sidebar should be visible</short>
+ <long>This key defines whether the sidebar should be visible
+ and it's used to remember the state of the sidebar across
+ sessions. Setting it to TRUE will make the sidebar always
be displayed.</long>
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/gnome-dictionary/statusbar-visible</key>
+ <applyto>/apps/gnome-dictionary/statusbar-visible</applyto>
+ <owner>gnome-dictionary</owner>
+ <type>bool</type>
+ <default>FALSE</default>
+ <locale name="C">
+ <short>Whether the statusbar should be visible</short>
+ <long>This key defines whether the statusbar should be visible
+ and it's used to remember the state of the statusbar across
+ sessions. Setting it to TRUE will make the statusbar always
+ be displayed.</long>
+ </locale>
+ </schema>
</schemalist>
diff --git a/libgdict/gdict-database-chooser.c b/libgdict/gdict-database-chooser.c
index 4bd84c0..75d855b 100644
--- a/libgdict/gdict-database-chooser.c
+++ b/libgdict/gdict-database-chooser.c
@@ -43,14 +43,36 @@
struct _GdictDatabaseChooserPrivate
{
GtkListStore *store;
+
+ GtkWidget *treeview;
GdictContext *context;
- GSList *matches;
+ gint results;
guint start_id;
guint match_id;
guint end_id;
guint error_id;
+
+ GdkCursor *busy_cursor;
+
+ guint is_searching : 1;
+};
+
+enum
+{
+ DATABASE_NAME,
+ DATABASE_DESCRIPTION,
+ DATABASE_ERROR
+} DBType;
+
+enum
+{
+ DB_COLUMN_TYPE,
+ DB_COLUMN_NAME,
+ DB_COLUMN_DESCRIPTION,
+
+ DB_N_COLUMNS
};
enum
@@ -61,10 +83,19 @@ enum
PROP_COUNT
};
+enum
+{
+ DATABASE_ACTIVATED,
+ CLOSED,
+
+ LAST_SIGNAL
+};
+
+static guint db_chooser_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GdictDatabaseChooser,
gdict_database_chooser,
- GTK_TYPE_COMBO_BOX_ENTRY);
+ GTK_TYPE_VBOX);
static void
@@ -122,39 +153,16 @@ set_gdict_context (GdictDatabaseChooser *chooser,
static void
gdict_database_chooser_finalize (GObject *gobject)
{
- GdictDatabaseChooserPrivate *priv;
-
- priv = GDICT_DATABASE_CHOOSER_GET_PRIVATE (gobject);
-
+ GdictDatabaseChooser *chooser = GDICT_DATABASE_CHOOSER (gobject);
+ GdictDatabaseChooserPrivate *priv = chooser->priv;
+
if (priv->context)
- {
- if (priv->start_id)
- {
- _gdict_debug ("Removing old context handlers\n");
-
- g_signal_handler_disconnect (priv->context, priv->start_id);
- g_signal_handler_disconnect (priv->context, priv->match_id);
- g_signal_handler_disconnect (priv->context, priv->end_id);
-
- priv->start_id = 0;
- priv->end_id = 0;
- priv->match_id = 0;
- }
-
- if (priv->error_id)
- {
- g_signal_handler_disconnect (priv->context, priv->error_id);
+ set_gdict_context (speller, NULL);
- priv->error_id = 0;
- }
+ if (priv->busy_cursor)
+ gdk_cursor_unref (priv->busy_cursor);
- _gdict_debug ("Removing old context\n");
-
- g_object_unref (G_OBJECT (priv->context));
- }
-
- if (priv->store)
- g_object_unref (priv->store);
+ g_object_unref (priv->store);
G_OBJECT_CLASS (gdict_database_chooser_parent_class)->finalize (gobject);
}
@@ -169,6 +177,9 @@ gdict_database_chooser_set_property (GObject *gobject,
switch (prop_id)
{
+ case PROP_CONTEXT:
+ set_gdict_context (chooser, g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@@ -185,6 +196,12 @@ gdict_database_chooser_get_property (GObject *gobject,
switch (prop_id)
{
+ case PROP_CONTEXT:
+ g_value_set_object (value, chooser->priv->context);
+ break;
+ case PROP_COUNT:
+ g_value_set_integer (value, chooser->priv->count);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@@ -192,6 +209,74 @@ gdict_database_chooser_get_property (GObject *gobject,
}
static void
+row_activated_cb (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
+{
+ GdictDatabaseChooser *chooser = GDICT_DATABASE_CHOOSER (user_data);
+ GdictDatabaseChooserPrivate *priv = chooser->priv;
+ GtkTreeIter iter;
+ gchar *db_name, *db_desc;
+ gboolean valid;
+
+ valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store),
+ &iter,
+ path);
+ if (!valid)
+ {
+ g_warning ("Invalid iterator found");
+ return;
+ }
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
+ DB_COLUMN_NAME, &db_name,
+ DB_COLUMN_DESCRIPTION, &db_desc,
+ -1);
+ if (db_name && db_desc)
+ {
+ g_signal_emit (chooser, db_chooser_signals[DATABASE_ACTIVATED], 0,
+ db_name, db_desc);
+ }
+ else
+ {
+ gchar *row = gtk_tree_path_to_string (path);
+
+ g_warning ("Row %s activated, but no database attached", row);
+ g_free (row);
+ }
+
+ g_free (db_name);
+ g_free (db_desc);
+}
+
+static GObject *
+gdict_database_chooser_constructor (GType type,
+ guint n_params,
+ GObjectConstructParams *params)
+{
+ GObject *object;
+ GdictDatabaseChooser *chooser;
+ GdictDatabaseChooserPrivate *priv;
+ GtkWidget *sw;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+
+ object = G_OBJECT_CLASS (gdict_database_chooser_parent_class)->constructor (type,
+ n_params,
+ params);
+
+ chooser = GDICT_DATABASE_CHOOSER (object);
+ priv = chooser->priv;
+
+ gtk_widget_push_composite_child ();
+
+ gtk_widget_pop_composite_child ();
+
+ return object;
+}
+
+static void
gdict_database_chooser_class_init (GdictDatabaseChooserClass *klass)
{
diff --git a/libgdict/gdict-database-chooser.h b/libgdict/gdict-database-chooser.h
index 8bc2b4e..da6c933 100644
--- a/libgdict/gdict-database-chooser.h
+++ b/libgdict/gdict-database-chooser.h
@@ -21,7 +21,7 @@
#define __GDICT_DATABASE_CHOOSER_H__
#include <gdict-context.h>
-#include <gtk/gtkcomboxboxentry.h>
+#include <gtk/gtkvbox.h>
G_BEGIN_DECLS
@@ -43,14 +43,18 @@ typedef struct _GdictDatabaseChooserClass GdictDatabaseChooserClass;
struct _GdictDatabaseChooser
{
- GtkComboBoxEntry parent_instance;
+ GtkVBox parent_instance;
GdictDatabaseChooserPrivate *priv;
};
struct _GdictDatabaseChooserClass
{
- GtkComboBoxEntryClass parent_class;
+ GtkVBoxClass parent_class;
+
+ void (*database_activated) (GdictDatabaseChooser *chooser,
+ const gchar *name,
+ const gchar *description);
void (*_gdict_padding1) (void);
void (*_gdict_padding2) (void);
@@ -72,12 +76,10 @@ void gdict_database_chooser_set_context (GdictDatabaseChooser *ch
gchar ** gdict_database_chooser_get_databases (GdictDatabaseChooser *chooser,
gsize length,
GError **error) G_GNUC_MALLOC;
+gint gdict_database_chooser_count_databases (GdictDatabaseChooser *chooser);
gboolean gdict_database_chooser_has_database (GdictDatabaseChooser *chooser,
const gchar *database);
-gboolean gdict_database_chooser_set_database (GdictDatabaseChooser *chooser,
- const gchar *database,
- GError **error);
-gchar * gdict_database_chooser_get_database (GdictDatabaseChooser *chooser) G_GNUC_MALLOC;
+void gdict_database_chooser_clear (GdictDatabaseChooser *chooser);
G_END_DECLS
diff --git a/libgdict/gdict-speller.c b/libgdict/gdict-speller.c
index 87b75db..5efee06 100644
--- a/libgdict/gdict-speller.c
+++ b/libgdict/gdict-speller.c
@@ -49,7 +49,6 @@ struct _GdictSpellerPrivate
gchar *word;
GtkWidget *treeview;
- GtkWidget *close;
GdkCursor *busy_cursor;
@@ -94,7 +93,6 @@ enum
enum
{
WORD_ACTIVATED,
- CLOSED,
LAST_SIGNAL
};
@@ -145,7 +143,7 @@ set_gdict_context (GdictSpeller *speller,
if (!GDICT_IS_CONTEXT (context))
{
- g_warning ("Object of type '%s' instead of a GdictContext\n",
+ g_warning ("Object of type `%s' instead of a GdictContext\n",
g_type_name (G_OBJECT_TYPE (context)));
return;
}
@@ -171,6 +169,8 @@ gdict_speller_finalize (GObject *gobject)
g_free (priv->strategy);
g_free (priv->database);
g_free (priv->word);
+
+ g_object_unref (priv->store);
G_OBJECT_CLASS (gdict_speller_parent_class)->finalize (gobject);
}
@@ -223,6 +223,8 @@ gdict_speller_get_property (GObject *gobject,
case PROP_CONTEXT:
g_value_set_object (value, speller->priv->context);
break;
+ case PROP_COUNT:
+ g_value_set_int (value, speller->priv->results);
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@@ -272,47 +274,24 @@ row_activated_cb (GtkTreeView *treeview,
static GObject *
gdict_speller_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+ guint n_params,
+ GObjectConstructParam *params)
{
GObject *object;
GdictSpeller *speller;
GdictSpellerPrivate *priv;
- GtkWidget *hbox;
- GtkWidget *label;
GtkWidget *sw;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
object = G_OBJECT_CLASS (gdict_speller_parent_class)->constructor (type,
- n_construct_properties,
- construct_params);
+ n_params,
+ params);
speller = GDICT_SPELLER (object);
priv = speller->priv;
gtk_widget_push_composite_child ();
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (speller), hbox, FALSE, FALSE, 0);
- gtk_widget_show (hbox);
-
- label = gtk_label_new (_("Similar words"));
- gtk_widget_set_composite_name (label, "gdict-speller-label");
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_widget_show (label);
-
- priv->close = gtk_button_new ();
- gtk_widget_set_composite_name (priv->close, "gdict-speller-close-button");
- gtk_button_set_image (GTK_BUTTON (priv->close),
- gtk_image_new_from_stock (GTK_STOCK_CLOSE,
- GTK_ICON_SIZE_MENU));
- gtk_button_set_relief (GTK_BUTTON (priv->close), GTK_RELIEF_NONE);
- g_signal_connect_swapped (priv->close, "clicked",
- G_CALLBACK (gdict_speller_closed), speller);
- gtk_box_pack_end (GTK_BOX (hbox), priv->close, FALSE, FALSE, 0);
- gtk_widget_show (priv->close);
-
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_composite_name (sw, "gdict-speller-scrolled-window");
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
@@ -387,14 +366,6 @@ gdict_speller_class_init (GdictSpellerClass *klass)
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_STRING);
- speller_signals[CLOSED] =
- g_signal_new ("closed",
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GdictSpellerClass, closed),
- NULL, NULL,
- gdict_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
g_type_class_add_private (gobject_class, sizeof (GdictSpellerPrivate));
}
@@ -804,19 +775,3 @@ gdict_speller_get_matches (GdictSpeller *speller,
return NULL;
}
-
-/**
- * gdict_speller_closed:
- * @speller: a #GdictSpeller
- *
- * FIXME
- *
- * Since: FIXME
- */
-void
-gdict_speller_closed (GdictSpeller *speller)
-{
- g_return_if_fail (GDICT_IS_SPELLER (speller));
-
- g_signal_emit (speller, speller_signals[CLOSED], 0);
-}
diff --git a/libgdict/gdict-speller.h b/libgdict/gdict-speller.h
index e719490..0249dbc 100644
--- a/libgdict/gdict-speller.h
+++ b/libgdict/gdict-speller.h
@@ -51,7 +51,6 @@ struct _GdictSpellerClass
void (*word_activated) (GdictSpeller *speller,
const gchar *word,
const gchar *database);
- void (*closed) (GdictSpeller *speller);
/* padding for future expansion */
void (*_gdict_speller_1) (void);
@@ -83,8 +82,6 @@ gint gdict_speller_count_matches (GdictSpeller *speller);
gchar ** gdict_speller_get_matches (GdictSpeller *speller,
gsize length);
-void gdict_speller_closed (GdictSpeller *speller);
-
G_END_DECLS
#endif /* __GDICT_SPELLER_H__ */
diff --git a/src/Makefile.am b/src/Makefile.am
index 7d2ec7f..ca56ad4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,6 +25,8 @@ gnome_dictionary_SOURCES = \
gdict-pref-dialog.h \
gdict-print.c \
gdict-print.h \
+ gdict-sidebar.c \
+ gdict-sidebar.h \
gdict-source-dialog.c \
gdict-source-dialog.h \
gdict-window.c \
@@ -64,6 +66,8 @@ gnome_dictionary_applet_SOURCES = \
gdict-pref-dialog.h \
gdict-print.c \
gdict-print.h \
+ gdict-sidebar.c \
+ gdict-sidebar.h \
gdict-source-dialog.c \
gdict-source-dialog.h \
$(NULL)
diff --git a/src/gdict-applet.c b/src/gdict-applet.c
index 77f5ef2..fee1cab 100644
--- a/src/gdict-applet.c
+++ b/src/gdict-applet.c
@@ -675,7 +675,7 @@ gdict_applet_lookup_end_cb (GdictContext *context,
{
gdict_applet_set_menu_items_sensitive (applet, TRUE);
- gtk_window_present (applet->priv->window);
+ gtk_window_present (GTK_WINDOW (applet->priv->window));
set_window_default_size (applet);
}
diff --git a/src/gdict-pref-dialog.h b/src/gdict-pref-dialog.h
index 162cb2d..d7c4335 100644
--- a/src/gdict-pref-dialog.h
+++ b/src/gdict-pref-dialog.h
@@ -44,7 +44,8 @@ G_BEGIN_DECLS
#define GDICT_GCONF_WINDOW_WIDTH_KEY GDICT_GCONF_DIR "/default-window-width"
#define GDICT_GCONF_WINDOW_HEIGHT_KEY GDICT_GCONF_DIR "/default-window-height"
#define GDICT_GCONF_WINDOW_IS_MAXIMIZED_KEY GDICT_GCONF_DIR "/window-is-maximized"
-#define GDICT_GCONF_SPELLER_VISIBLE_KEY GDICT_GCONF_DIR "/speller-visible"
+#define GDICT_GCONF_SIDEBAR_VISIBLE_KEY GDICT_GCONF_DIR "/sidebar-visible"
+#define GDICT_GCONF_STATUSBAR_VISIBLE_KEY GDICT_GCONF_DIR "/statusbar-visible"
#define DOCUMENT_FONT_KEY "/desktop/gnome/interface/document_font_name"
diff --git a/src/gdict-sidebar.c b/src/gdict-sidebar.c
new file mode 100644
index 0000000..4d97ed1
--- /dev/null
+++ b/src/gdict-sidebar.c
@@ -0,0 +1,464 @@
+/* gdict-sidebar.c - sidebar widget
+ *
+ * Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *
+ * Based on the equivalent widget from Evince
+ * by Jonathan Blandford,
+ * Copyright (C) 2004 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+#include <gtk/gtkbindings.h>
+#include <glib/gi18n.h>
+
+#include "gdict-sidebar.h"
+
+typedef struct
+{
+ guint index;
+
+ gchar *id;
+ gchar *name;
+
+ GtkWidget *child;
+} SidebarPage;
+
+#define GDICT_SIDEBAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDICT_TYPE_SIDEBAR, GdictSidebarPrivate))
+
+struct _GdictSidebarPrivate
+{
+ GHashTable *pages_by_id;
+ GSList *pages;
+
+ GtkWidget *hbox;
+ GtkWidget *notebook;
+ GtkWidget *menu;
+ GtkWidget *close_button;
+ GtkWidget *label;
+ GtkWidget *select_button;
+};
+
+enum
+{
+ PAGE_CHANGED,
+ CLOSED,
+
+ LAST_SIGNAL
+};
+
+static guint sidebar_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GdictSidebar, gdict_sidebar, GTK_TYPE_VBOX);
+
+SidebarPage *
+sidebar_page_new (const gchar *id,
+ const gchar *name,
+ GtkWidget *widget)
+{
+ SidebarPage *page;
+
+ page = g_slice_new (SidebarPage);
+
+ page->id = g_strdup (id);
+ page->name = g_strdup (name);
+ page->child = widget;
+ page->index = -1;
+
+ return page;
+}
+
+void
+sidebar_page_free (SidebarPage *page)
+{
+ if (G_LIKELY (page))
+ {
+ g_free (page->name);
+ g_free (page->id);
+
+ g_slice_free (SidebarPage, page);
+ }
+}
+
+static void
+gdict_sidebar_finalize (GObject *object)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (object);
+ GdictSidebarPrivate *priv = sidebar->priv;
+
+ if (priv->pages_by_id)
+ g_hash_table_destroy (priv->pages_by_id);
+
+ if (priv->pages)
+ {
+ g_slist_foreach (priv->pages, (GFunc) sidebar_page_free, NULL);
+ g_slist_free (priv->pages);
+ }
+
+ G_OBJECT_CLASS (gdict_sidebar_parent_class)->finalize (object);
+}
+
+static void
+gdict_sidebar_destroy (GtkObject *object)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (object);
+
+ if (sidebar->priv->menu)
+ {
+ gtk_menu_detach (GTK_MENU (sidebar->priv->menu));
+ sidebar->priv->menu = NULL;
+ }
+
+ GTK_OBJECT_CLASS (gdict_sidebar_parent_class)->destroy (object);
+}
+
+static void
+gdict_sidebar_menu_position_function (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data)
+{
+ GtkWidget *widget;
+
+ g_assert (GTK_IS_BUTTON (user_data));
+
+ widget = GTK_WIDGET (user_data);
+
+ gdk_window_get_origin (widget->window, x, y);
+
+ *x += widget->allocation.x;
+ *y += widget->allocation.y + widget->allocation.height;
+
+ *push_in = FALSE;
+}
+
+static gboolean
+gdict_sidebar_select_button_press_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
+
+ if (event->button == 1)
+ {
+ GtkRequisition req;
+ gint width;
+
+ width = widget->allocation.width;
+ gtk_widget_set_size_request (sidebar->priv->menu, -1, -1);
+ gtk_widget_size_request (sidebar->priv->menu, &req);
+ gtk_widget_set_size_request (sidebar->priv->menu,
+ MAX (width, req.width), -1);
+ gtk_widget_grab_focus (widget);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+ gtk_menu_popup (GTK_MENU (sidebar->priv->menu),
+ NULL, NULL,
+ gdict_sidebar_menu_position_function, widget,
+ event->button, event->time);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+gdict_sidebar_select_key_press_cb (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer user_data)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
+
+ if (event->keyval == GDK_space ||
+ event->keyval == GDK_KP_Space ||
+ event->keyval == GDK_Return ||
+ event->keyval == GDK_KP_Enter)
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+ gtk_menu_popup (GTK_MENU (sidebar->priv->menu),
+ NULL, NULL,
+ gdict_sidebar_menu_position_function, widget,
+ 1, event->time);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+gdict_sidebar_close_clicked_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
+
+ g_signal_emit (sidebar, sidebar_signals[CLOSED], 0);
+}
+
+static void
+gdict_sidebar_menu_deactivate_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
+ GdictSidebarPrivate *priv = sidebar->priv;
+ GtkToggleButton *select_button = GTK_TOGGLE_BUTTON (priv->select_button);
+
+ gtk_toggle_button_set_active (select_button, FALSE);
+}
+
+static void
+gdict_sidebar_menu_detach_cb (GtkWidget *widget,
+ GtkMenu *menu)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (widget);
+
+ sidebar->priv->menu = NULL;
+}
+
+static void
+gdict_sidebar_menu_item_activate (GtkWidget *widget,
+ gpointer user_data)
+{
+ GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
+ GtkWidget *menu_item;
+ gchar *id;
+ SidebarPage *page;
+
+ menu_item = gtk_menu_get_active (GTK_MENU (sidebar->priv->menu));
+ id = g_object_get_data (G_OBJECT (menu_item), "gdict-sidebar-page-id");
+ g_assert (id != NULL);
+
+ page = g_hash_table_lookup (sidebar->priv->pages_by_id, id);
+ g_assert (page != NULL);
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (sidebar->priv->notebook),
+ page->index);
+ gtk_label_set_text (GTK_LABEL (sidebar->priv->label), page->name);
+}
+
+static void
+gdict_sidebar_class_init (GdictSidebarClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = gdict_sidebar_finalize;
+ gtkobject_class->destroy = gdict_sidebar_destroy;
+
+ sidebar_signals[PAGE_CHANGED] =
+ g_signal_new ("page-changed",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdictSidebarClass, page_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ sidebar_signals[CLOSED] =
+ g_signal_new ("closed",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdictSidebarClass, closed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (gobject_class, sizeof (GdictSidebarPrivate));
+}
+
+static void
+gdict_sidebar_init (GdictSidebar *sidebar)
+{
+ GdictSidebarPrivate *priv;
+ GtkWidget *hbox;
+ GtkWidget *select_hbox;
+ GtkWidget *select_button;
+ GtkWidget *close_button;
+ GtkWidget *arrow;
+
+ sidebar->priv = priv = GDICT_SIDEBAR_GET_PRIVATE (sidebar);
+
+ /* we store all the pages inside the list, but we keep
+ * a pointer inside the hash table for faster look up
+ * times; what's inside the table will be destroyed with
+ * the list, so there's no need to supply the destroy
+ * functions for keys and values.
+ */
+ priv->pages = NULL;
+ priv->pages_by_id = g_hash_table_new (g_str_hash, g_str_equal);
+
+ /* top option menu */
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (sidebar), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+ priv->hbox = hbox;
+
+ select_button = gtk_toggle_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (select_button), GTK_RELIEF_NONE);
+ g_signal_connect (select_button, "button-press-event",
+ G_CALLBACK (gdict_sidebar_select_button_press_cb),
+ sidebar);
+ g_signal_connect (select_button, "key-press-event",
+ G_CALLBACK (gdict_sidebar_select_key_press_cb),
+ sidebar);
+ priv->select_button = select_button;
+
+ select_hbox = gtk_hbox_new (FALSE, 0);
+
+ priv->label = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (select_hbox), priv->label, FALSE, FALSE, 0);
+ gtk_widget_show (priv->label);
+
+ arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
+ gtk_box_pack_end (GTK_BOX (select_hbox), arrow, FALSE, FALSE, 0);
+ gtk_widget_show (arrow);
+
+ gtk_container_add (GTK_CONTAINER (select_button), select_hbox);
+ gtk_widget_show (select_hbox);
+
+ gtk_box_pack_start (GTK_BOX (hbox), select_button, TRUE, TRUE, 0);
+ gtk_widget_show (select_button);
+
+ close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ gtk_button_set_image (GTK_BUTTON (close_button),
+ gtk_image_new_from_stock (GTK_STOCK_CLOSE,
+ GTK_ICON_SIZE_SMALL_TOOLBAR));
+ g_signal_connect (close_button, "clicked",
+ G_CALLBACK (gdict_sidebar_close_clicked_cb),
+ sidebar);
+ gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+ gtk_widget_show (close_button);
+ priv->close_button = close_button;
+
+ sidebar->priv->menu = gtk_menu_new ();
+ g_signal_connect (sidebar->priv->menu, "deactivate",
+ G_CALLBACK (gdict_sidebar_menu_deactivate_cb),
+ sidebar);
+ gtk_menu_attach_to_widget (GTK_MENU (sidebar->priv->menu),
+ GTK_WIDGET (sidebar),
+ gdict_sidebar_menu_detach_cb);
+ gtk_widget_show (sidebar->priv->menu);
+
+ sidebar->priv->notebook = gtk_notebook_new ();
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (sidebar->priv->notebook), FALSE);
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (sidebar->priv->notebook), FALSE);
+ gtk_box_pack_start (GTK_BOX (sidebar), sidebar->priv->notebook, TRUE, TRUE, 6);
+ gtk_widget_show (sidebar->priv->notebook);
+}
+
+/*
+ * Public API
+ */
+
+GtkWidget *
+gdict_sidebar_new (void)
+{
+ return g_object_new (GDICT_TYPE_SIDEBAR, NULL);
+}
+
+void
+gdict_sidebar_add_page (GdictSidebar *sidebar,
+ const gchar *page_id,
+ const gchar *page_name,
+ GtkWidget *page_widget)
+{
+ GdictSidebarPrivate *priv;
+ SidebarPage *page;
+ GtkWidget *menu_item;
+
+ g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
+ g_return_if_fail (page_id != NULL);
+ g_return_if_fail (page_name != NULL);
+ g_return_if_fail (GTK_IS_WIDGET (page_widget));
+
+ priv = sidebar->priv;
+
+ if (g_hash_table_lookup (priv->pages_by_id, page_id))
+ {
+ g_warning ("Attempting to add a page to the sidebar with "
+ "id `%s', but there already is a page with the "
+ "same id. Aborting...",
+ page_id);
+ return;
+ }
+
+ /* add the page inside the page list */
+ page = sidebar_page_new (page_id, page_name, page_widget);
+
+ priv->pages = g_slist_append (priv->pages, page);
+ g_hash_table_insert (priv->pages_by_id, page->id, page);
+
+ page->index = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+ page_widget,
+ NULL);
+
+ /* add the menu item for the page */
+ menu_item = gtk_image_menu_item_new_with_label (page_name);
+ g_object_set_data_full (G_OBJECT (menu_item),
+ "gdict-sidebar-page-id",
+ g_strdup (page_id),
+ (GDestroyNotify) g_free);
+ g_signal_connect (menu_item, "activate",
+ G_CALLBACK (gdict_sidebar_menu_item_activate),
+ sidebar);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
+ gtk_widget_show (menu_item);
+
+ gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->menu), menu_item);
+ gtk_label_set_text (GTK_LABEL (priv->label), page_name);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page->index);
+}
+
+void
+gdict_sidebar_remove_page (GdictSidebar *sidebar,
+ const gchar *page_id)
+{
+ g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
+ g_return_if_fail (page_id != NULL);
+
+ g_warning ("FIXME");
+}
+
+void
+gdict_sidebar_view_page (GdictSidebar *sidebar,
+ const gchar *page_id)
+{
+ GdictSidebarPrivate *priv;
+ SidebarPage *page;
+
+ g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
+ g_return_if_fail (page_id != NULL);
+
+ priv = sidebar->priv;
+ page = g_hash_table_lookup (priv->pages_by_id, page_id);
+ if (!page)
+ return;
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ page->index);
+}
diff --git a/src/gdict-sidebar.h b/src/gdict-sidebar.h
new file mode 100644
index 0000000..bd995f7
--- /dev/null
+++ b/src/gdict-sidebar.h
@@ -0,0 +1,72 @@
+/* gdict-sidebar.h - sidebar widget
+ *
+ * Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *
+ * Based on the equivalent widget from Evince
+ * by Jonathan Blandford,
+ * Copyright (C) 2004 Red Hat, Inc.
+ */
+
+#ifndef __GDICT_SIDEBAR_H__
+#define __GDICT_SIDEBAR_H__
+
+#include <gtk/gtkvbox.h>
+
+#define GDICT_TYPE_SIDEBAR (gdict_sidebar_get_type ())
+#define GDICT_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDICT_TYPE_SIDEBAR, GdictSidebar))
+#define GDICT_IS_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDICT_TYPE_SIDEBAR))
+#define GDICT_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDICT_TYPE_SIDEBAR, GdictSidebarClass))
+#define GDICT_IS_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDICT_TYPE_SIDEBAR))
+#define GDICT_SIDEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDICT_TYPE_SIDEBAR, GdictSidebarClass))
+
+typedef struct _GdictSidebar GdictSidebar;
+typedef struct _GdictSidebarPrivate GdictSidebarPrivate;
+typedef struct _GdictSidebarClass GdictSidebarClass;
+
+struct _GdictSidebar
+{
+ GtkVBox parent_instance;
+
+ GdictSidebarPrivate *priv;
+};
+
+struct _GdictSidebarClass
+{
+ GtkVBoxClass parent_class;
+
+ void (*page_changed) (GdictSidebar *sidebar);
+ void (*closed) (GdictSidebar *sidebar);
+
+ void (*_gdict_padding_1) (void);
+ void (*_gdict_padding_2) (void);
+ void (*_gdict_padding_3) (void);
+ void (*_gdict_padding_4) (void);
+};
+
+GType gdict_sidebar_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gdict_sidebar_new (void);
+void gdict_sidebar_add_page (GdictSidebar *sidebar,
+ const gchar *page_id,
+ const gchar *page_name,
+ GtkWidget *page_widget);
+void gdict_sidebar_remove_page (GdictSidebar *sidebar,
+ const gchar *page_id);
+void gdict_sidebar_view_page (GdictSidebar *sidebar,
+ const gchar *page_id);
+
+#endif /* __GDICT_SIDEBAR_H__ */
diff --git a/src/gdict-window.c b/src/gdict-window.c
index 1a07374..925ed57 100644
--- a/src/gdict-window.c
+++ b/src/gdict-window.c
@@ -42,6 +42,7 @@
#include <libgdict/gdict.h>
+#include "gdict-sidebar.h"
#include "gdict-print.h"
#include "gdict-pref-dialog.h"
#include "gdict-about.h"
@@ -135,19 +136,36 @@ gdict_window_finalize (GObject *object)
}
static void
-gdict_window_set_speller_visible (GdictWindow *window,
+gdict_window_set_sidebar_visible (GdictWindow *window,
gboolean is_visible)
{
g_assert (GDICT_IS_WINDOW (window));
- if (is_visible != window->speller_visible)
+ if (is_visible != window->sidebar_visible)
{
if (is_visible)
- gtk_widget_show (window->speller_frame);
+ gtk_widget_show (window->sidebar_frame);
else
- gtk_widget_hide (window->speller_frame);
+ gtk_widget_hide (window->sidebar_frame);
- window->speller_visible = is_visible;
+ window->sidebar_visible = is_visible;
+ }
+}
+
+static void
+gdict_window_set_statusbar_visible (GdictWindow *window,
+ gboolean is_visible)
+{
+ g_assert (GDICT_IS_WINDOW (window));
+
+ if (is_visible != window->statusbar_visible)
+ {
+ if (is_visible)
+ gtk_widget_show (window->status);
+ else
+ gtk_widget_hide (window->status);
+
+ window->statusbar_visible = is_visible;
}
}
@@ -186,8 +204,6 @@ gdict_window_lookup_start_cb (GdictContext *context,
if (!window->busy_cursor)
window->busy_cursor = gdk_cursor_new (GDK_WATCH);
- gdict_window_set_speller_visible (window, FALSE);
-
message = g_strdup_printf (_("Searching for '%s'..."), window->word);
if (window->status)
@@ -253,9 +269,9 @@ gdict_window_error_cb (GdictContext *context,
{
GdictSource *source;
GdictContext *context;
-
- gtk_widget_show (window->speller_frame);
- window->speller_visible = TRUE;
+
+ gdict_window_set_sidebar_visible (window, TRUE);
+ gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), "speller");
/* we clone the context, so that the signals that it
* fires do not get caught by the signal handlers we
@@ -595,8 +611,12 @@ gdict_window_cmd_file_new (GtkAction *action,
window->is_maximized,
NULL);
gconf_client_set_bool (window->gconf_client,
- GDICT_GCONF_SPELLER_VISIBLE_KEY,
- window->speller_visible,
+ GDICT_GCONF_SIDEBAR_VISIBLE_KEY,
+ window->sidebar_visible,
+ NULL);
+ gconf_client_set_bool (window->gconf_client,
+ GDICT_GCONF_STATUSBAR_VISIBLE_KEY,
+ window->statusbar_visible,
NULL);
new_window = gdict_window_new (window->loader, NULL, NULL);
@@ -691,8 +711,12 @@ gdict_window_cmd_file_close_window (GtkAction *action,
window->is_maximized,
NULL);
gconf_client_set_bool (window->gconf_client,
- GDICT_GCONF_SPELLER_VISIBLE_KEY,
- window->speller_visible,
+ GDICT_GCONF_SIDEBAR_VISIBLE_KEY,
+ window->sidebar_visible,
+ NULL);
+ gconf_client_set_bool (window->gconf_client,
+ GDICT_GCONF_STATUSBAR_VISIBLE_KEY,
+ window->statusbar_visible,
NULL);
/* if this was called from the uimanager, destroy the widget;
@@ -761,15 +785,51 @@ gdict_window_cmd_edit_preferences (GtkAction *action,
}
static void
-gdict_window_cmd_view_speller (GtkAction *action,
+gdict_window_cmd_view_sidebar (GtkAction *action,
GdictWindow *window)
{
gboolean is_active;
g_assert (GDICT_IS_WINDOW (window));
- is_active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
- gdict_window_set_speller_visible (window, is_active);
+ if (window->sidebar_visible)
+ gdict_window_set_sidebar_visible (window, FALSE);
+ else
+ gdict_window_set_sidebar_visible (window, TRUE);
+}
+
+static void
+gdict_window_cmd_view_statusbar (GtkAction *action,
+ GdictWindow *window)
+{
+ g_assert (GDICT_IS_WINDOW (window));
+
+ if (window->statusbar_visible)
+ gdict_window_set_statusbar_visible (window, FALSE);
+ else
+ gdict_window_set_statusbar_visible (window, TRUE);
+}
+
+static void
+gdict_window_cmd_view_speller (GtkAction *action,
+ GdictWindow *window)
+{
+ g_assert (GDICT_IS_WINDOW (window));
+
+ gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), "speller");
+ gdict_window_set_sidebar_visible (window, TRUE);
+}
+
+static void
+gdict_window_cmd_view_databases (GtkAction *action,
+ GdictWindow *window)
+{
+ g_assert (GDICT_IS_WINDOW (window));
+
+#if 0
+ gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), "databases");
+#endif
+ gdict_window_set_sidebar_visible (window, TRUE);
}
static void
@@ -877,13 +937,6 @@ gdict_window_cmd_escape (GtkAction *action,
gdict_defbox_set_show_find (GDICT_DEFBOX (window->defbox), FALSE);
}
-static const GtkToggleActionEntry toggle_entries[] =
-{
- { "ViewSpeller", NULL, N_("_Similar Words"), "<control>T",
- N_("Show similar words"),
- G_CALLBACK (gdict_window_cmd_view_speller), FALSE },
-};
-
static const GtkActionEntry entries[] =
{
{ "File", NULL, N_("_File") },
@@ -918,6 +971,14 @@ static const GtkActionEntry entries[] =
G_CALLBACK (gdict_window_cmd_edit_preferences) },
/* View menu */
+ { "ViewSidebar", NULL, N_("_Sidebar"), "F9", NULL,
+ G_CALLBACK (gdict_window_cmd_view_sidebar) },
+ { "ViewStatusbar", NULL, N_("S_tatusbar"), NULL, NULL,
+ G_CALLBACK (gdict_window_cmd_view_statusbar) },
+ { "ViewSpeller", NULL, N_("Similar _Words"), "<control>T", NULL,
+ G_CALLBACK (gdict_window_cmd_view_speller) },
+ { "ViewDb", NULL, N_("Available_Databases"), "<control>B", NULL,
+ G_CALLBACK (gdict_window_cmd_view_databases) },
/* Go menu */
{ "GoPreviousDef", GTK_STOCK_GO_BACK, N_("_Previous Definition"), "<control>Page_Up",
@@ -1004,12 +1065,21 @@ gdict_window_gconf_notify_cb (GConfClient *client,
else
gdict_window_set_defbox_font (window, GDICT_DEFAULT_DEFBOX_FONT);
}
- else if (strcmp (entry->key, GDICT_GCONF_SPELLER_VISIBLE_KEY) == 0)
+ else if (strcmp (entry->key, GDICT_GCONF_SIDEBAR_VISIBLE_KEY) == 0)
{
if (entry->value && (entry->value->type == GCONF_VALUE_BOOL))
- gdict_window_set_speller_visible (window, gconf_value_get_bool (entry->value));
+ gdict_window_set_sidebar_visible (window,
+ gconf_value_get_bool (entry->value));
else
- gdict_window_set_speller_visible (window, FALSE);
+ gdict_window_set_sidebar_visible (window, FALSE);
+ }
+ else if (strcmp (entry->key, GDICT_GCONF_STATUSBAR_VISIBLE_KEY) == 0)
+ {
+ if (entry->value && (entry->value->type == GCONF_VALUE_BOOL))
+ gdict_window_set_statusbar_visible (window,
+ gconf_value_get_bool (entry->value));
+ else
+ gdict_window_set_statusbar_visible (window, FALSE);
}
}
@@ -1032,6 +1102,17 @@ entry_activate_cb (GtkWidget *widget,
gdict_window_set_word (window, word, NULL);
}
+#if 0
+static void
+database_activated_cb (GdictDatabaseChooser *chooser,
+ const gchar *db_name,
+ const gchar *db_desc,
+ GdictWindow *window)
+{
+ gdict_window_set_database (window, db_name);
+}
+#endif
+
static void
speller_word_activated_cb (GdictSpeller *speller,
const gchar *word,
@@ -1044,11 +1125,11 @@ speller_word_activated_cb (GdictSpeller *speller,
}
static void
-speller_closed_cb (GdictSpeller *speller,
+sidebar_closed_cb (GdictSidebar *sidebar,
GdictWindow *window)
{
- gtk_widget_hide (window->speller_frame);
- window->speller_visible = FALSE;
+ gtk_widget_hide (window->sidebar_frame);
+ window->sidebar_visible = FALSE;
}
static void
@@ -1200,7 +1281,8 @@ gdict_window_constructor (GType type,
PangoFontDescription *font_desc;
gchar *font_name;
GError *error;
- gboolean speller_visible;
+ gboolean sidebar_visible;
+ gboolean statusbar_visible;
object = G_OBJECT_CLASS (gdict_window_parent_class)->constructor (type,
n_construct_properties,
@@ -1220,9 +1302,6 @@ gdict_window_constructor (GType type,
gtk_action_group_add_actions (action_group, entries,
G_N_ELEMENTS (entries),
window);
- gtk_action_group_add_toggle_actions (action_group, toggle_entries,
- G_N_ELEMENTS (toggle_entries),
- window);
window->ui_manager = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (window->ui_manager, action_group, 0);
@@ -1293,31 +1372,58 @@ gdict_window_constructor (GType type,
gtk_container_add (GTK_CONTAINER (frame1), window->defbox);
gtk_widget_show (window->defbox);
+ window->sidebar = gdict_sidebar_new ();
+ g_signal_connect (window->sidebar, "closed",
+ G_CALLBACK (sidebar_closed_cb),
+ window);
+
window->speller = gdict_speller_new ();
if (window->context)
- gdict_speller_set_context (GDICT_SPELLER (window->speller), window->context);
-
+ gdict_speller_set_context (GDICT_SPELLER (window->speller),
+ window->context);
g_signal_connect (window->speller, "word-activated",
G_CALLBACK (speller_word_activated_cb),
window);
- g_signal_connect (window->speller, "closed",
- G_CALLBACK (speller_closed_cb),
- window);
- gtk_container_add (GTK_CONTAINER (frame2), window->speller);
+
+ gdict_sidebar_add_page (GDICT_SIDEBAR (window->sidebar),
+ "speller",
+ _("Similar words"),
+ window->speller);
gtk_widget_show (window->speller);
+#if 0
+ window->db_chooser = gdict_database_chooser_new ();
+ if (window->context)
+ gdict_database_chooser_set_contect (GDICT_DATABASE_CHOOSER (window->db_chooser,
+ window->context);
+ g_signal_connect (window->db_chooser, "database-activated",
+ G_CALLBACK (database_activated_cb),
+ window);
+ gdict_sidebar_add_page (GDICT_SIDEBAR (window->sidebar),
+ "db-chooser",
+ _("Available dictionaries"),
+ window->db_chooser);
+ gtk_widget_show (window->db_chooser);
+#endif
+
+ gtk_container_add (GTK_CONTAINER (frame2), window->sidebar);
+ gtk_widget_show (window->sidebar);
+
gtk_paned_pack1 (GTK_PANED (handle), frame1, TRUE, FALSE);
gtk_paned_pack2 (GTK_PANED (handle), frame2, FALSE, TRUE);
window->defbox_frame = frame1;
- window->speller_frame = frame2;
+ window->sidebar_frame = frame2;
gtk_widget_show (window->defbox_frame);
window->status = gtk_statusbar_new ();
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (window->status), TRUE);
gtk_box_pack_end (GTK_BOX (window->main_box), window->status, FALSE, FALSE, 0);
- gtk_widget_show (window->status);
+ statusbar_visible = gconf_client_get_bool (window->gconf_client,
+ GDICT_GCONF_STATUSBAR_VISIBLE_KEY,
+ NULL);
+ gdict_window_set_statusbar_visible (window, statusbar_visible);
window->progress = gtk_progress_bar_new ();
gtk_box_pack_end (GTK_BOX (window->status), window->progress, FALSE, FALSE, 0);
@@ -1332,18 +1438,11 @@ gdict_window_constructor (GType type,
gdict_window_set_defbox_font (window, font_name);
font_desc = pango_font_description_from_string (font_name);
- speller_visible = gconf_client_get_bool (window->gconf_client,
- GDICT_GCONF_SPELLER_VISIBLE_KEY,
+ sidebar_visible = gconf_client_get_bool (window->gconf_client,
+ GDICT_GCONF_SIDEBAR_VISIBLE_KEY,
NULL);
- action = gtk_action_group_get_action (action_group, "ViewSpeller");
- if (action)
- {
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- speller_visible);
- gtk_toggle_action_toggled (GTK_TOGGLE_ACTION (action));
- }
- window->speller_visible = speller_visible;
-
+ gdict_window_set_sidebar_visible (window, sidebar_visible);
+
/* retrieve the window state from gconf */
is_maximized = gconf_client_get_bool (window->gconf_client,
GDICT_GCONF_WINDOW_IS_MAXIMIZED_KEY,
diff --git a/src/gdict-window.h b/src/gdict-window.h
index a178d66..ad9edc8 100644
--- a/src/gdict-window.h
+++ b/src/gdict-window.h
@@ -46,7 +46,9 @@ struct _GdictWindow
GtkWidget *menubar;
GtkWidget *entry;
GtkWidget *speller;
- GtkWidget *speller_frame;
+ GtkWidget *db_chooser;
+ GtkWidget *sidebar;
+ GtkWidget *sidebar_frame;
GtkWidget *defbox;
GtkWidget *defbox_frame;
GtkWidget *status;
@@ -84,8 +86,9 @@ struct _GdictWindow
gint default_width;
gint default_height;
- guint is_maximized : 1;
- guint speller_visible : 1;
+ guint is_maximized : 1;
+ guint sidebar_visible : 1;
+ guint statusbar_visible : 1;
gulong window_id;
};