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:
parent
eddb0b30df
commit
e2795eff54
1 changed files with 96 additions and 119 deletions
|
@ -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
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -59,6 +59,9 @@ midori_extensions_get_property (GObject* object,
|
||||||
GValue* value,
|
GValue* value,
|
||||||
GParamSpec* pspec);
|
GParamSpec* pspec);
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_extensions_finalize (GObject* object);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_extensions_class_init (MidoriExtensionsClass* class)
|
midori_extensions_class_init (MidoriExtensionsClass* class)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +71,7 @@ midori_extensions_class_init (MidoriExtensionsClass* class)
|
||||||
gobject_class = G_OBJECT_CLASS (class);
|
gobject_class = G_OBJECT_CLASS (class);
|
||||||
gobject_class->set_property = midori_extensions_set_property;
|
gobject_class->set_property = midori_extensions_set_property;
|
||||||
gobject_class->get_property = midori_extensions_get_property;
|
gobject_class->get_property = midori_extensions_get_property;
|
||||||
|
gobject_class->finalize = midori_extensions_finalize;
|
||||||
|
|
||||||
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
||||||
|
|
||||||
|
@ -93,37 +97,6 @@ midori_extensions_get_stock_id (MidoriViewable* viewable)
|
||||||
return STOCK_EXTENSIONS;
|
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*
|
static GtkWidget*
|
||||||
midori_extensions_get_toolbar (MidoriViewable* extensions)
|
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_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
||||||
gtk_widget_show (GTK_WIDGET (toolitem));
|
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;
|
MIDORI_EXTENSIONS (extensions)->toolbar = toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +126,21 @@ midori_extensions_viewable_iface_init (MidoriViewableIface* iface)
|
||||||
iface->get_toolbar = midori_extensions_get_toolbar;
|
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
|
static void
|
||||||
midori_extensions_add_item_cb (KatzeArray* array,
|
midori_extensions_add_item_cb (KatzeArray* array,
|
||||||
MidoriExtension* extension,
|
MidoriExtension* extension,
|
||||||
|
@ -184,6 +152,10 @@ midori_extensions_add_item_cb (KatzeArray* array,
|
||||||
model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview));
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview));
|
||||||
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, extension, -1);
|
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
|
static void
|
||||||
|
@ -239,13 +211,19 @@ midori_extensions_get_property (GObject* object,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_extensions_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
midori_extensions_treeview_render_tick_cb (GtkTreeViewColumn* column,
|
||||||
GtkCellRenderer* renderer,
|
GtkCellRenderer* renderer,
|
||||||
GtkTreeModel* model,
|
GtkTreeModel* model,
|
||||||
GtkTreeIter* iter,
|
GtkTreeIter* iter,
|
||||||
GtkWidget* treeview)
|
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
|
static void
|
||||||
|
@ -271,9 +249,7 @@ midori_extensions_treeview_render_text_cb (GtkTreeViewColumn* column,
|
||||||
g_free (version);
|
g_free (version);
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
|
|
||||||
g_object_set (renderer, "markup", text,
|
g_object_set (renderer, "markup", text, NULL);
|
||||||
"sensitive", midori_extension_is_active (extension),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
g_free (text);
|
g_free (text);
|
||||||
g_object_unref (extension);
|
g_object_unref (extension);
|
||||||
|
@ -285,16 +261,10 @@ midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
|
||||||
GtkTreeViewColumn* column,
|
GtkTreeViewColumn* column,
|
||||||
MidoriExtensions* extensions)
|
MidoriExtensions* extensions)
|
||||||
{
|
{
|
||||||
GtkToolItem* button_enable;
|
|
||||||
GtkToolItem* button_disable;
|
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
model = gtk_tree_view_get_model (treeview);
|
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))
|
if (gtk_tree_model_get_iter (model, &iter, path))
|
||||||
{
|
{
|
||||||
MidoriExtension* extension;
|
MidoriExtension* extension;
|
||||||
|
@ -304,47 +274,11 @@ midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
|
||||||
midori_extension_deactivate (extension);
|
midori_extension_deactivate (extension);
|
||||||
else
|
else
|
||||||
g_signal_emit_by_name (extension, "activate", extensions->app);
|
g_signal_emit_by_name (extension, "activate", extensions->app);
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
|
|
||||||
!midori_extension_is_active (extension));
|
g_object_unref (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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void
|
||||||
midori_extensions_preferences_activate_cb (GtkWidget* menuitem,
|
midori_extensions_preferences_activate_cb (GtkWidget* menuitem,
|
||||||
MidoriExtensions* extensions)
|
MidoriExtensions* extensions)
|
||||||
|
@ -471,7 +405,7 @@ midori_extensions_button_press_event_cb (GtkWidget* widget,
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
if (event->button != 2 && event->button != 3)
|
if (event->button != 3)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
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;
|
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
|
static void
|
||||||
midori_extensions_init (MidoriExtensions* extensions)
|
midori_extensions_init (MidoriExtensions* extensions)
|
||||||
|
@ -494,16 +450,20 @@ midori_extensions_init (MidoriExtensions* extensions)
|
||||||
/* Create the treeview */
|
/* Create the treeview */
|
||||||
GtkTreeViewColumn* column;
|
GtkTreeViewColumn* column;
|
||||||
GtkCellRenderer* renderer_text;
|
GtkCellRenderer* renderer_text;
|
||||||
GtkCellRenderer* renderer_pixbuf;
|
GtkCellRenderer* renderer_toggle;
|
||||||
GtkListStore* liststore = gtk_list_store_new (1, G_TYPE_OBJECT);
|
GtkListStore* liststore = gtk_list_store_new (1, G_TYPE_OBJECT);
|
||||||
extensions->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
|
extensions->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
|
||||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (extensions->treeview), FALSE);
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (extensions->treeview), FALSE);
|
||||||
column = gtk_tree_view_column_new ();
|
column = gtk_tree_view_column_new ();
|
||||||
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
|
renderer_toggle = gtk_cell_renderer_toggle_new ();
|
||||||
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
|
gtk_tree_view_column_pack_start (column, renderer_toggle, FALSE);
|
||||||
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
|
gtk_tree_view_column_set_cell_data_func (column, renderer_toggle,
|
||||||
(GtkTreeCellDataFunc)midori_extensions_treeview_render_icon_cb,
|
(GtkTreeCellDataFunc)midori_extensions_treeview_render_tick_cb,
|
||||||
extensions->treeview, NULL);
|
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 ();
|
renderer_text = gtk_cell_renderer_text_new ();
|
||||||
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
|
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
|
||||||
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
|
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
|
||||||
|
@ -511,22 +471,39 @@ midori_extensions_init (MidoriExtensions* extensions)
|
||||||
extensions->treeview, NULL);
|
extensions->treeview, NULL);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column);
|
||||||
g_object_unref (liststore);
|
g_object_unref (liststore);
|
||||||
g_signal_connect (extensions->treeview, "row-activated",
|
g_object_connect (extensions->treeview,
|
||||||
G_CALLBACK (midori_extensions_treeview_row_activated_cb),
|
"signal::row-activated",
|
||||||
extensions);
|
midori_extensions_treeview_row_activated_cb, extensions,
|
||||||
g_signal_connect (extensions->treeview, "cursor-changed",
|
"signal::button-press-event",
|
||||||
G_CALLBACK (midori_extensions_treeview_cursor_changed_cb),
|
midori_extensions_button_press_event_cb, extensions,
|
||||||
extensions);
|
"signal::popup-menu",
|
||||||
g_signal_connect (extensions->treeview, "button-press-event",
|
midori_extensions_popup_menu_cb, extensions,
|
||||||
G_CALLBACK (midori_extensions_button_press_event_cb),
|
NULL);
|
||||||
extensions);
|
|
||||||
g_signal_connect (extensions->treeview, "popup-menu",
|
|
||||||
G_CALLBACK (midori_extensions_popup_menu_cb),
|
|
||||||
extensions);
|
|
||||||
gtk_widget_show (extensions->treeview);
|
gtk_widget_show (extensions->treeview);
|
||||||
gtk_box_pack_start (GTK_BOX (extensions), extensions->treeview, TRUE, TRUE, 0);
|
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:
|
* midori_extensions_new:
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue