Implement togglable ticks in the extensions panel

Whether an extension is active or not is now reflected by a tick
mark that can be toggled with a mouse. Double clicking and
pressing space do the same. The buttons are thusly removed.
While we are at it, we also listen for status changes that might be
coming from a different window.
Sensitivity does no longer relate to activation status.
This commit is contained in:
Christian Dywan 2009-06-07 16:59:51 +02:00
parent eddb0b30df
commit e2795eff54

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -59,6 +59,9 @@ midori_extensions_get_property (GObject* object,
GValue* value,
GParamSpec* pspec);
static void
midori_extensions_finalize (GObject* object);
static void
midori_extensions_class_init (MidoriExtensionsClass* class)
{
@ -68,6 +71,7 @@ midori_extensions_class_init (MidoriExtensionsClass* class)
gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = midori_extensions_set_property;
gobject_class->get_property = midori_extensions_get_property;
gobject_class->finalize = midori_extensions_finalize;
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
@ -93,37 +97,6 @@ midori_extensions_get_stock_id (MidoriViewable* viewable)
return STOCK_EXTENSIONS;
}
static void
midori_extensions_button_status_clicked_cb (GtkToolItem* toolitem,
MidoriExtensions* extensions)
{
GtkTreeView* treeview;
GtkTreeModel* model;
GtkTreeIter iter;
MidoriExtension* extension;
treeview = GTK_TREE_VIEW (extensions->treeview);
if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
{
GtkToolItem* button_enable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 1);
GtkToolItem* button_disable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 2);
gtk_tree_model_get (model, &iter, 0, &extension, -1);
if (toolitem == button_enable)
g_signal_emit_by_name (extension, "activate", extensions->app);
else if (toolitem == button_disable)
midori_extension_deactivate (extension);
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
!midori_extension_is_active (extension));
gtk_widget_set_sensitive (GTK_WIDGET (button_disable),
midori_extension_is_active (extension));
}
}
static GtkWidget*
midori_extensions_get_toolbar (MidoriViewable* extensions)
{
@ -139,26 +112,6 @@ midori_extensions_get_toolbar (MidoriViewable* extensions)
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
gtk_widget_show (GTK_WIDGET (toolitem));
/* enable button */
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_YES);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("_Enable"));
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), _("Enable"));
g_signal_connect (toolitem, "clicked",
G_CALLBACK (midori_extensions_button_status_clicked_cb), extensions);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
gtk_widget_set_sensitive (GTK_WIDGET (toolitem), FALSE);
gtk_widget_show (GTK_WIDGET (toolitem));
/* disable button */
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_NO);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("_Disable"));
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), _("Disable"));
g_signal_connect (toolitem, "clicked",
G_CALLBACK (midori_extensions_button_status_clicked_cb), extensions);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
gtk_widget_set_sensitive (GTK_WIDGET (toolitem), FALSE);
gtk_widget_show (GTK_WIDGET (toolitem));
MIDORI_EXTENSIONS (extensions)->toolbar = toolbar;
}
@ -173,6 +126,21 @@ midori_extensions_viewable_iface_init (MidoriViewableIface* iface)
iface->get_toolbar = midori_extensions_get_toolbar;
}
static void
midori_extensions_extension_activate_cb (MidoriExtension* extension,
MidoriApp* app,
MidoriExtensions* extensions)
{
gtk_widget_queue_draw (GTK_WIDGET (extensions->treeview));
}
static void
midori_extensions_extension_deactivate_cb (MidoriExtension* extension,
MidoriExtensions* extensions)
{
gtk_widget_queue_draw (GTK_WIDGET (extensions->treeview));
}
static void
midori_extensions_add_item_cb (KatzeArray* array,
MidoriExtension* extension,
@ -184,6 +152,10 @@ midori_extensions_add_item_cb (KatzeArray* array,
model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview));
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, extension, -1);
g_signal_connect (extension, "activate",
G_CALLBACK (midori_extensions_extension_activate_cb), extensions);
g_signal_connect (extension, "deactivate",
G_CALLBACK (midori_extensions_extension_deactivate_cb), extensions);
}
static void
@ -239,13 +211,19 @@ midori_extensions_get_property (GObject* object,
}
static void
midori_extensions_treeview_render_icon_cb (GtkTreeViewColumn* column,
midori_extensions_treeview_render_tick_cb (GtkTreeViewColumn* column,
GtkCellRenderer* renderer,
GtkTreeModel* model,
GtkTreeIter* iter,
GtkWidget* treeview)
{
g_object_set (renderer, "stock-id", GTK_STOCK_EXECUTE, NULL);
MidoriExtension* extension;
gtk_tree_model_get (model, iter, 0, &extension, -1);
g_object_set (renderer, "active", midori_extension_is_active (extension), NULL);
g_object_unref (extension);
}
static void
@ -271,9 +249,7 @@ midori_extensions_treeview_render_text_cb (GtkTreeViewColumn* column,
g_free (version);
g_free (desc);
g_object_set (renderer, "markup", text,
"sensitive", midori_extension_is_active (extension),
NULL);
g_object_set (renderer, "markup", text, NULL);
g_free (text);
g_object_unref (extension);
@ -285,16 +261,10 @@ midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
GtkTreeViewColumn* column,
MidoriExtensions* extensions)
{
GtkToolItem* button_enable;
GtkToolItem* button_disable;
GtkTreeModel* model;
GtkTreeIter iter;
model = gtk_tree_view_get_model (treeview);
button_enable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 1);
button_disable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 2);
if (gtk_tree_model_get_iter (model, &iter, path))
{
MidoriExtension* extension;
@ -304,47 +274,11 @@ midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
midori_extension_deactivate (extension);
else
g_signal_emit_by_name (extension, "activate", extensions->app);
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
!midori_extension_is_active (extension));
gtk_widget_set_sensitive (GTK_WIDGET (button_disable),
midori_extension_is_active (extension));
/* FIXME: Update only the appropriate row */
gtk_widget_queue_draw (GTK_WIDGET (treeview));
g_object_unref (extension);
}
}
static void
midori_extensions_treeview_cursor_changed_cb (GtkTreeView* treeview,
MidoriExtensions* extensions)
{
GtkTreeModel* model;
GtkTreePath* path;
GtkTreeIter iter;
GtkToolItem* button_enable;
GtkToolItem* button_disable;
gtk_tree_view_get_cursor (treeview, &path, NULL);
model = gtk_tree_view_get_model (treeview);
button_enable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 1);
button_disable = gtk_toolbar_get_nth_item (
GTK_TOOLBAR (extensions->toolbar), 2);
if (gtk_tree_model_get_iter (model, &iter, path))
{
MidoriExtension* extension;
if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
{
gtk_tree_model_get (model, &iter, 0, &extension, -1);
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
!midori_extension_is_active (extension));
gtk_widget_set_sensitive (GTK_WIDGET (button_disable),
midori_extension_is_active (extension));
}
}
return;
}
static void
midori_extensions_preferences_activate_cb (GtkWidget* menuitem,
MidoriExtensions* extensions)
@ -471,7 +405,7 @@ midori_extensions_button_press_event_cb (GtkWidget* widget,
GtkTreeModel* model;
GtkTreeIter iter;
if (event->button != 2 && event->button != 3)
if (event->button != 3)
return FALSE;
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
@ -487,6 +421,28 @@ midori_extensions_button_press_event_cb (GtkWidget* widget,
return FALSE;
}
static void
midori_extensions_cell_renderer_toggled_cb (GtkCellRendererToggle* renderer,
const gchar* path,
MidoriExtensions* extensions)
{
GtkTreeModel* model;
GtkTreeIter iter;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview));
if (gtk_tree_model_get_iter_from_string (model, &iter, path))
{
MidoriExtension *extension;
gtk_tree_model_get (model, &iter, 0, &extension, -1);
if (midori_extension_is_active (extension))
midori_extension_deactivate (extension);
else
g_signal_emit_by_name (extension, "activate", extensions->app);
g_object_unref (extension);
}
}
static void
midori_extensions_init (MidoriExtensions* extensions)
@ -494,16 +450,20 @@ midori_extensions_init (MidoriExtensions* extensions)
/* Create the treeview */
GtkTreeViewColumn* column;
GtkCellRenderer* renderer_text;
GtkCellRenderer* renderer_pixbuf;
GtkCellRenderer* renderer_toggle;
GtkListStore* liststore = gtk_list_store_new (1, G_TYPE_OBJECT);
extensions->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (extensions->treeview), FALSE);
column = gtk_tree_view_column_new ();
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
(GtkTreeCellDataFunc)midori_extensions_treeview_render_icon_cb,
renderer_toggle = gtk_cell_renderer_toggle_new ();
gtk_tree_view_column_pack_start (column, renderer_toggle, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_toggle,
(GtkTreeCellDataFunc)midori_extensions_treeview_render_tick_cb,
extensions->treeview, NULL);
g_signal_connect (renderer_toggle, "toggled",
G_CALLBACK (midori_extensions_cell_renderer_toggled_cb), extensions);
gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column);
column = gtk_tree_view_column_new ();
renderer_text = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
@ -511,22 +471,39 @@ midori_extensions_init (MidoriExtensions* extensions)
extensions->treeview, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column);
g_object_unref (liststore);
g_signal_connect (extensions->treeview, "row-activated",
G_CALLBACK (midori_extensions_treeview_row_activated_cb),
extensions);
g_signal_connect (extensions->treeview, "cursor-changed",
G_CALLBACK (midori_extensions_treeview_cursor_changed_cb),
extensions);
g_signal_connect (extensions->treeview, "button-press-event",
G_CALLBACK (midori_extensions_button_press_event_cb),
extensions);
g_signal_connect (extensions->treeview, "popup-menu",
G_CALLBACK (midori_extensions_popup_menu_cb),
extensions);
g_object_connect (extensions->treeview,
"signal::row-activated",
midori_extensions_treeview_row_activated_cb, extensions,
"signal::button-press-event",
midori_extensions_button_press_event_cb, extensions,
"signal::popup-menu",
midori_extensions_popup_menu_cb, extensions,
NULL);
gtk_widget_show (extensions->treeview);
gtk_box_pack_start (GTK_BOX (extensions), extensions->treeview, TRUE, TRUE, 0);
}
static void
midori_extensions_finalize (GObject* object)
{
MidoriExtensions* extensions = MIDORI_EXTENSIONS (object);
KatzeArray* array = katze_object_get_object (extensions->app, "extensions");
guint i = 0;
MidoriExtension* extension;
while ((extension = katze_array_get_nth_item (array, i++)))
{
g_signal_handlers_disconnect_by_func (extension,
midori_extensions_extension_activate_cb, extensions);
g_signal_handlers_disconnect_by_func (extension,
midori_extensions_extension_deactivate_cb, extensions);
}
g_signal_handlers_disconnect_by_func (array,
midori_extensions_add_item_cb, extensions);
g_object_unref (array);
}
/**
* midori_extensions_new:
*