Re: Tab grouping extension.
- From: Justin Wake <jwake iinet net au>
- To: Adam Hooper <adamh densi com>
- Cc: epiphany-list gnome org
- Subject: Re: Tab grouping extension.
- Date: Thu, 26 Aug 2004 23:25:38 +0800
On Thu, 2004-08-26 at 21:56 +0800, Justin Wake wrote:
> Assuming I don't code myself into a small buggy corner, I should have a
> new version of the extension ready and tested in an hour or two.
>
Okay, this should do the trick. Seems to unload (and reload, and unload,
and reload, and so on) happily enough with the expected behaviour, and I
changed the code to be a little bit more efficient and slightly less
redundant.
I've attached all the files (including the ones that haven't changed)
for completeness; this set of attachments is the extension (plus
epiphany patch) self-contained in its entirety.
--
Justin Wake
Index: src/ephy-notebook.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-notebook.c,v
retrieving revision 1.37
diff -u -r1.37 ephy-notebook.c
--- src/ephy-notebook.c 19 Jun 2004 23:32:07 -0000 1.37
+++ src/ephy-notebook.c 25 Aug 2004 14:06:23 -0000
@@ -1004,6 +1004,9 @@
if (jump_to)
{
+ /* The signal handler may have reordered the tabs */
+ position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET(tab));
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (nb),
position);
g_object_set_data (G_OBJECT (tab), "jump_to",
Index: configure.ac
===================================================================
RCS file: /cvs/gnome/epiphany-extensions/configure.ac,v
retrieving revision 1.68
diff -u -r1.68 configure.ac
--- configure.ac 16 Aug 2004 10:59:18 -0000 1.68
+++ configure.ac 25 Aug 2004 14:09:55 -0000
@@ -135,8 +135,8 @@
AC_MSG_CHECKING([extensions to build])
-all_extensions="certificates,dashboard,error-viewer,gestures,sample,sample-mozilla,tabsmenu"
-all_useful_extensions="certificates,dashboard,error-viewer,gestures,tabsmenu"
+all_extensions="certificates,dashboard,error-viewer,gestures,sample,sample-mozilla,tabsmenu,tab-groups"
+all_useful_extensions="certificates,dashboard,error-viewer,gestures,tabsmenu,tab-groups"
default_extensions="certificates,error-viewer,gestures,tabsmenu"
mozilla_dependent_extensions="certificates,error-viewer,sample-mozilla"
@@ -147,7 +147,7 @@
AC_ARG_WITH([extensions],
[ --with-extensions=extension1,extension2,...
build the specified extensions. Available:
- gestures, sample, tabsmenu, all])
+ gestures, sample, tabsmenu, tab-groups, all])
dnl If no extensions specified, build the default set
if test "x$with_extensions" = xyes; then
@@ -187,6 +187,7 @@
AM_CONDITIONAL(ENABLE_SAMPLE_EXTENSION, echo "$extensions" | egrep '(^|,)sample($|,)' > /dev/null)
AM_CONDITIONAL(ENABLE_SAMPLE_MOZILLA_EXTENSION, echo "$extensions" | egrep '(^|,)sample-mozilla($|,)' > /dev/null)
AM_CONDITIONAL(ENABLE_TABSMENU_EXTENSION, echo "$extensions" | egrep '(^|,)tabsmenu($|,)' > /dev/null)
+AM_CONDITIONAL(ENABLE_TAB_GROUPS_EXTENSION, echo "$extensions" | egrep '(^|,)tab-groups($|,)' > /dev/null)
dnl AM_CONDITIONAL(ENABLE_TOOLBAR_EXTRAS_EXTENSION, echo "$extensions" | egrep '(^|,)toolbar-extras($|,)' > /dev/null)
dnl *******************************************
@@ -380,6 +381,7 @@
extensions/sample-mozilla/Makefile
extensions/sample-mozilla/mozilla/Makefile
extensions/tabsmenu/Makefile
+extensions/tab-groups/Makefile
po/Makefile.in
])
Index: extensions/Makefile.am
===================================================================
RCS file: /cvs/gnome/epiphany-extensions/extensions/Makefile.am,v
retrieving revision 1.13
diff -u -r1.13 Makefile.am
--- extensions/Makefile.am 6 Jul 2004 15:06:51 -0000 1.13
+++ extensions/Makefile.am 25 Aug 2004 14:10:13 -0000
@@ -28,10 +28,14 @@
SUBDIRS += tabsmenu
endif
+if ENABLE_TAB_GROUPS_EXTENSION
+SUBDIRS += tab-groups
+endif
+
#if ENABLE_TOOLBAR_EXTRAS_EXTENSION
#SUBDIRS += toolbar-extras
#endif
-DIST_SUBDIRS = certificates dashboard error-viewer gestures sample sample-mozilla tabsmenu
+DIST_SUBDIRS = certificates dashboard error-viewer gestures sample sample-mozilla tabsmenu tab-groups
EXTRA_DIST =
extensiondir = $(libdir)/epiphany/extensions
INCLUDES = \
-I$(top_srcdir)/include \
$(EPIPHANY_DEPENDENCY_CFLAGS) \
-DSHARE_DIR=\"$(pkgdatadir)\" \
-DEPHY_PLUGINS_LOCALEDIR=\"$(datadir)/locale\" \
-DG_DISABLE_DEPRECATED \
-DGDK_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
-DGDK_PIXBUF_DISABLE_DEPRECATED \
-DGNOME_DISABLE_DEPRECATED
extension_LTLIBRARIES = libtabgroupsextension.la
libtabgroupsextension_la_SOURCES = \
ephy-tab-groups-extension.c \
ephy-tab-groups-extension.h \
ephy-tab-grouper.c \
ephy-tab-grouper.h \
tab-groups.c
/*
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
* Copyright (C) 2004 Justin Wake
*
* 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, 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 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, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ephy-tab-grouper.h"
#include "ephy-debug.h"
#include <epiphany/ephy-session.h>
#include <epiphany/ephy-shell.h>
#include <gmodule.h>
#define EPHY_TAB_GROUPER_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB_GROUPER, EphyTabGrouperPrivate))
struct _EphyTabGrouperPrivate
{
GtkWidget *nb;
EphyTab *last_opened_tab;
};
static void ephy_tab_grouper_class_init (EphyTabGrouperClass *klass);
static void ephy_tab_grouper_init (EphyTabGrouper *grouper);
enum
{
PROP_0,
PROP_NOTEBOOK
};
GObjectClass *tab_grouper_parent_class = NULL;
GType tab_grouper_type = 0;
GType
ephy_tab_grouper_get_type (void)
{
return tab_grouper_type;
}
GType
ephy_tab_grouper_register_type (GTypeModule *module)
{
static const GTypeInfo our_info =
{
sizeof (EphyTabGrouperClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) ephy_tab_grouper_class_init,
NULL,
NULL, /* class_data */
sizeof (EphyTabGrouper),
0, /* n_preallocs */
(GInstanceInitFunc) ephy_tab_grouper_init
};
tab_grouper_type =
g_type_module_register_type (module,
G_TYPE_OBJECT,
"EphyTabGrouper",
&our_info, 0);
return tab_grouper_type;
}
/**
* Clear the recently opened tab spot.
*/
static void
reset_last_tab (EphyTabGrouper *grouper)
{
g_return_if_fail (EPHY_IS_TAB_GROUPER (grouper));
if (grouper->priv->last_opened_tab != NULL)
{
g_object_unref (grouper->priv->last_opened_tab);
grouper->priv->last_opened_tab = NULL;
}
}
static void
tab_added_cb (GtkWidget *notebook,
EphyTab *tab,
EphyTabGrouper *grouper)
{
GtkWidget *cur_tab;
guint position = -1;
g_return_if_fail (EPHY_IS_TAB (tab));
/* Calculate the appropriate position for the tab */
if (grouper->priv->last_opened_tab != NULL)
{
position = gtk_notebook_page_num
(GTK_NOTEBOOK (notebook), GTK_WIDGET (grouper->priv->last_opened_tab)) + 1;
}
else
{
position = gtk_notebook_get_current_page
(GTK_NOTEBOOK (notebook)) + 1;
}
gtk_notebook_reorder_child
(GTK_NOTEBOOK (notebook), GTK_WIDGET (tab), position);
/* Clear the last tab so we can set it to the new tab */
reset_last_tab (grouper);
grouper->priv->last_opened_tab = g_object_ref (tab);
}
/**
* Doing just about anything related to tabs will clear
* the recently opened tabs list.
*/
static void
reset_tabs_cb (GtkWidget *dummy,
EphyTab *tab,
EphyTabGrouper *grouper)
{
reset_last_tab (grouper);
}
static void
switch_page_cb (GtkNotebook *nb,
GtkNotebookPage *page,
guint new_page,
EphyTabGrouper *grouper)
{
reset_last_tab (grouper);
}
static void
tab_deleted_cb (EphyTab *tab,
gboolean *inhibited,
EphyTabGrouper *grouper)
{
reset_last_tab (grouper);
}
static void
tabs_reordered_cb (GtkWidget *notebook,
EphyTabGrouper *grouper)
{
reset_last_tab (grouper);
}
static void
ephy_tab_grouper_set_nb (EphyTabGrouper *grouper,
GtkWidget *nb)
{
g_return_if_fail (EPHY_IS_TAB_GROUPER (grouper));
g_return_if_fail (GTK_IS_NOTEBOOK (nb));
grouper->priv->nb = g_object_ref (nb);
/* Hook up the signals */
g_signal_connect (grouper->priv->nb, "tab_added",
G_CALLBACK (tab_added_cb), grouper);
g_signal_connect (grouper->priv->nb, "tab_removed",
G_CALLBACK (reset_tabs_cb), grouper);
g_signal_connect (grouper->priv->nb, "tab_detached",
G_CALLBACK (reset_tabs_cb), grouper);
g_signal_connect (grouper->priv->nb, "switch_page",
G_CALLBACK (switch_page_cb), grouper);
g_signal_connect (grouper->priv->nb, "tabs_reordered",
G_CALLBACK (tabs_reordered_cb), grouper);
g_signal_connect (grouper->priv->nb, "tab_delete",
G_CALLBACK (tab_deleted_cb), grouper);
}
static void
ephy_tab_grouper_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
switch (prop_id)
{
case PROP_NOTEBOOK:
ephy_tab_grouper_set_nb (grouper, g_value_get_object (value));
break;
}
}
static void
ephy_tab_grouper_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
switch (prop_id)
{
case PROP_NOTEBOOK:
g_value_set_object (value, grouper->priv->nb);
break;
}
}
static void
ephy_tab_grouper_finalize (GObject *object)
{
EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
g_return_if_fail (EPHY_IS_TAB_GROUPER (grouper));
reset_last_tab (grouper);
if (grouper->priv->nb != NULL)
{
/* Disconnect the signal handlers */
g_signal_handlers_disconnect_matched
(grouper->priv->nb, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, grouper);
g_object_unref (grouper->priv->nb);
}
LOG ("EphyTabGrouper finalised")
G_OBJECT_CLASS (tab_grouper_parent_class)->finalize (object);
}
static void
ephy_tab_grouper_init (EphyTabGrouper *grouper)
{
grouper->priv = EPHY_TAB_GROUPER_GET_PRIVATE (grouper);
grouper->priv->nb = NULL;
grouper->priv->last_opened_tab = NULL;
LOG ("EphyTabGrouper initialised");
}
static void
ephy_tab_grouper_class_init (EphyTabGrouperClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
tab_grouper_parent_class = g_type_class_peek_parent (klass);
object_class->finalize = ephy_tab_grouper_finalize;
object_class->set_property = ephy_tab_grouper_set_property;
object_class->get_property = ephy_tab_grouper_get_property;
g_object_class_install_property (object_class,
PROP_NOTEBOOK,
g_param_spec_object ("nb",
"Notebook",
"Parent notebook",
GTK_TYPE_NOTEBOOK,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (EphyTabGrouperPrivate));
}
EphyTabGrouper *
ephy_tab_grouper_new (GtkWidget *nb)
{
return g_object_new (EPHY_TYPE_TAB_GROUPER,
"nb", nb,
NULL);
}
/*
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
* Copyright (C) 2004 Justin Wake
*
* 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, 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 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, Boston, MA 02111-1307, USA.
*
*/
#ifndef EPHY_TAB_GROUPER_H
#define EPHY_TAB_GROUPER_H
#include <glib-object.h>
#include <epiphany/ephy-window.h>
#include <gmodule.h>
G_BEGIN_DECLS
#define EPHY_TYPE_TAB_GROUPER (ephy_tab_grouper_get_type())
#define EPHY_TAB_GROUPER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_TAB_GROUPER, EphyTabGrouper))
#define EPHY_TAB_GROUPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_TAB_GROUPER, EphyTabGrouperClass))
#define EPHY_IS_TAB_GROUPER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_TAB_GROUPER))
#define EPHY_IS_TAB_GROUPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_TAB_GROUPER))
#define EPHY_TAB_GROUPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_TAB_GROUPER, EphyTabGrouperClass))
typedef struct _EphyTabGrouper EphyTabGrouper;
typedef struct _EphyTabGrouperClass EphyTabGrouperClass;
typedef struct _EphyTabGrouperPrivate EphyTabGrouperPrivate;
struct _EphyTabGrouperClass
{
GObjectClass parent_class;
};
struct _EphyTabGrouper
{
GObject parent_object;
/* Private */
EphyTabGrouperPrivate *priv;
};
GType ephy_tab_grouper_get_type (void);
GType ephy_tab_grouper_register_type (GTypeModule *module);
EphyTabGrouper *ephy_tab_grouper_new (GtkWidget *nb);
G_END_DECLS
#endif
/*
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
* Copyright (C) 2004 Justin Wake
*
* 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, 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 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, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ephy-tab-groups-extension.h"
#include "ephy-tab-grouper.h"
#include "ephy-debug.h"
#include <epiphany/ephy-extension.h>
static void ephy_tab_groups_extension_class_init (EphyTabGroupsExtensionClass *class);
static void ephy_tab_groups_extension_iface_init (EphyExtensionIface *iface);
static void ephy_tab_groups_extension_init (EphyTabGroupsExtension *ext);
GObjectClass *tab_groups_extension_parent_class = NULL;
GType tab_groups_extension_type = 0;
GType
ephy_tab_groups_extension_get_type (void)
{
return tab_groups_extension_type;
}
GType
ephy_tab_groups_extension_register_type (GTypeModule *module)
{
static const GTypeInfo our_info =
{
sizeof (EphyTabGroupsExtensionClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) ephy_tab_groups_extension_init,
NULL,
NULL, /* class_data */
sizeof (EphyTab),
0, /* n_preallocs */
(GInstanceInitFunc) ephy_tab_groups_extension_init
};
static const GInterfaceInfo extension_info =
{
(GInterfaceInitFunc) ephy_tab_groups_extension_iface_init,
NULL,
NULL
};
tab_groups_extension_type =
g_type_module_register_type (module,
G_TYPE_OBJECT,
"EphyTabGroupsExtension",
&our_info, 0);
g_type_module_add_interface (module,
tab_groups_extension_type,
EPHY_TYPE_EXTENSION,
&extension_info);
return tab_groups_extension_type;
}
static void
impl_attach_window (EphyExtension *extension,
EphyWindow *window)
{
EphyTabGrouper *grouper;
grouper = ephy_tab_grouper_new (ephy_window_get_notebook (window));
g_object_set_data_full (G_OBJECT (window), "ephy-tab-grouper", grouper,
(GDestroyNotify) g_object_unref);
}
static void
impl_detach_window (EphyExtension *ext,
EphyWindow *window)
{
/* Kill the tab grouper for this window */
g_object_set_data (G_OBJECT (window), "ephy-tab-grouper", NULL);
}
static void
ephy_tab_groups_extension_init (EphyTabGroupsExtension *extension)
{
LOG ("EphyTabGroupsExtension initialising")
}
static void
ephy_tab_groups_extension_finalize (GObject *object)
{
EphyTabGroupsExtension *extension = EPHY_TAB_GROUPS_EXTENSION (object);
LOG ("EphyTabGroupsExtension finalising")
G_OBJECT_CLASS (tab_groups_extension_parent_class)->finalize (object);
}
static void
ephy_tab_groups_extension_iface_init (EphyExtensionIface *iface)
{
iface->attach_window = impl_attach_window;
iface->detach_window = impl_detach_window;
}
static void
ephy_tab_groups_extension_class_init (EphyTabGroupsExtensionClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
tab_groups_extension_parent_class = (GObjectClass *) g_type_class_peek_parent (class);
object_class->finalize = ephy_tab_groups_extension_finalize;
}
/*
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
* Copyright (C) 2004 Justin Wake
*
* 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, 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 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, Boston, MA 02111-1307, USA.
*
*/
#ifndef EPHY_TAB_GROUPS_EXTENSION_H
#define EPHY_TAB_GROUPS_EXTENSION_H
#include <glib-object.h>
#include <gmodule.h>
G_BEGIN_DECLS
#define EPHY_TYPE_TAB_GROUPS_EXTENSION (ephy_tab_groups_extension_get_type())
#define EPHY_TAB_GROUPS_EXTENSION(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_TAB_GROUPS_EXTENSION, EphyTabGroupsExtension))
#define EPHY_TAB_GROUPS_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_TAB_GROUPS_EXTENSION, EphyTabGroupsExtensionClass))
#define EPHY_IS_TAB_GROUPS_EXTENSION(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_TAB_GROUPS_EXTENSION))
#define EPHY_IS_TAB_GROUPS_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_TAB_GROUPS_EXTENSION))
#define EPHY_TAB_GROUPS_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_TAB_GROUPS_EXTENSION, EphyTabGroupsExtensionClass))
typedef struct _EphyTabGroupsExtension EphyTabGroupsExtension;
typedef struct _EphyTabGroupsExtensionClass EphyTabGroupsExtensionClass;
typedef struct _EphyTabGroupsExtensionPrivate EphyTabGroupsExtensionPrivate;
struct _EphyTabGroupsExtensionClass
{
GObjectClass parent_class;
};
struct _EphyTabGroupsExtension
{
GObject parent_object;
};
GType ephy_tab_groups_extension_get_type (void);
GType ephy_tab_groups_extension_register_type (GTypeModule *module);
G_END_DECLS
#endif
/*
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
* Copyright (C) 2004 Justin Wake
*
* 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, 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 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, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ephy-tab-groups-extension.h"
#include "ephy-tab-grouper.h"
#include <gmodule.h>
G_MODULE_EXPORT GType
register_module (GTypeModule *module)
{
GType extension_type;
ephy_tab_grouper_register_type (module);
extension_type = ephy_tab_groups_extension_register_type (module);
return extension_type;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]