Modyfing egg toolbar classes



Hello,

I'm just trying to write down some of the changes that I've made to the
egg toolbar code to see what people thing of it. I've attached my
current egg-toolbars-model.h as it provides a useful programming insight
into the major changes, which are:

EggToolbarsModel:
      * Replaced the get_item_ signals with a list of structures
        containing callback functions. Each structure represents a
        portable data type which can be handled by the EggToolbarsModel
        (for reading/writing it's XML file).
      * Removed the stored type information for individulal toolbar
        items. Now each item is just a name - if you want to get the
        associated data of a certain type, you use the list of
        structures mentioned above. A helper function is provided (ie.
        give it the name of the item, and the data type you want, and it
        will do it's best).
      * Added functions to record numbers of each item (identified by
        name) which are available for addition to the toolbar.
      * Changed the way that the toolbar description is stored (in a
        backward/forward-compatible manner!). This allows for multiple
        portable data types to be stored per tool item if necessary. It
        also allows us to provide a 'fallback' mechanism whereby if the
        item cannot be reconstructed from the portable data type we try
        just to use the name of the item. See example below.

EggToolbarEditor
      * Use the new 'availability' information in EggToolbarsModel to
        work out what to add to the toolbar without using a static XML
        file. This also allows plugins to add their own toolbar items
        easily at runtime.
      * Changed UI slightly to distinguish between 'factory' type items
        (which are copied) and 'normal' items (which are moved) when
        doing d-n-d from the editor to the toolbar. See
        http://www.dsl.uow.edu.au/~harvey/quicktopics.png

EggEditableToolbar
      * Changed EggEditableToolbar to accept for d-n-d any data type
        that is supported by it's EggToolbarsModel. Using the different
        callback functions now available we can solve bug 137056 (which
        was damned annoying) very nicely.
      * Changed EggEditableToolbar so that every item on the toolbar is
        now treated as application/x-toolbar-item when dragging from the
        toolbar in edit mode. This means you can d-n-d any item on to
        the EggToolbarEditor to remove it from the toolbar.

Let me know what you think!

Regards,
Peter.


EXAMPLE OF OLD FORMAT
=====================

<?xml version="1.0"?>
<toolbars version="1.0">
  <toolbar name="UserCreated">
    <toolitem type="application/x-toolbar-item" name="NavigationBack"/>
    <toolitem type="application/x-toolbar-item" name="NavigationForward"/>
    <toolitem type="application/x-toolbar-item" name="NavigationUp"/>
    <separator/>
    <toolitem type="application/x-toolbar-item" name="ViewStop"/>
    <toolitem type="application/x-toolbar-item" name="Location"/>
    <toolitem type="application/x-toolbar-item" name="ViewReload"/>
    <separator/>
    <toolitem type="_NETSCAPE_URL" name="file:///usr/share/doc/libgtk2.0-doc/gtk/index.html"/>
    <toolitem type="_NETSCAPE_URL" name="http://www.gnome.org/projects/epiphany/"/>
  </toolbar>
</toolbars>

EXAMPLE OF NEW FORMAT
=====================

<?xml version="1.0"?>
<toolbars version="1.0">
  <toolbar name="UserCreated">
    <toolitem name="NavigationBack"/>
    <toolitem name="NavigationForward"/>
    <toolitem name="NavigationUp"/>
    <separator/>
    <toolitem name="ViewStop"/>
    <toolitem name="Location"/>
    <toolitem name="ViewReload"/>
    <separator/>
    <toolitem name="OpenBmk183">
      <data type="_NETSCAPE_URL">file:///usr/share/doc/libgtk2.0-doc/gtk/index.html</data>
    </toolitem>
    <toolitem name="OpenBmk136">
      <data type="_NETSCAPE_URL">http://www.gnome.org/projects/epiphany/</data>
    </toolitem>
  </toolbar>
</toolbars>

/*
 *  Copyright (C) 2003-2004 Marco Pesenti Gritti
 *
 *  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 EGG_TOOLBARS_MODEL_H
#define EGG_TOOLBARS_MODEL_H

#include <glib.h>
#include <glib-object.h>
#include <gdk/gdktypes.h>

G_BEGIN_DECLS


#define EGG_TYPE_TOOLBARS_MODEL             (egg_toolbars_model_get_type ())
#define EGG_TOOLBARS_MODEL(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModel))
#define EGG_TOOLBARS_MODEL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelClass))
#define EGG_IS_TOOLBARS_MODEL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TOOLBARS_MODEL))
#define EGG_IS_TOOLBARS_MODEL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TOOLBARS_MODEL))
#define EGG_TOOLBARS_MODEL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelClass))

typedef struct EggToolbarsModel		EggToolbarsModel;
typedef struct EggToolbarsModelPrivate	EggToolbarsModelPrivate;
typedef struct EggToolbarsModelClass	EggToolbarsModelClass;

#define EGG_TOOLBAR_ITEM_TYPE "application/x-toolbar-item"

typedef enum
{
  EGG_TB_MODEL_NOT_REMOVABLE	 = 1 << 0,
  EGG_TB_MODEL_ICONS_ONLY	 = 1 << 1,
  EGG_TB_MODEL_TEXT_ONLY	 = 1 << 2,
  EGG_TB_MODEL_ICONS_TEXT	 = 1 << 3,
  EGG_TB_MODEL_ICONS_TEXT_HORIZ	 = 1 << 4,
  EGG_TB_MODEL_ACCEPT_ITEMS_ONLY = 1 << 5
} EggTbModelFlags;

struct EggToolbarsModel
{
  GObject parent_object;

  /*< private >*/
  EggToolbarsModelPrivate *priv;
};

struct EggToolbarsModelClass
{
  GObjectClass parent_class;

  /* Signals */
  void (* item_added)      (EggToolbarsModel *model,
			    int toolbar_position,
			    int position);
  void (* item_removed)    (EggToolbarsModel *model,
			    int toolbar_position,
			    int position);
  void (* toolbar_added)   (EggToolbarsModel *model,
			    int position);
  void (* toolbar_changed) (EggToolbarsModel *model,
			    int position);
  void (* toolbar_removed) (EggToolbarsModel *model,
			    int position);

  /* Virtual Table */
  gboolean (* add_item)    (EggToolbarsModel *t,
			    int	              toolbar_position,
			    int               position,
			    const char       *name);
};

typedef struct EggToolbarsItemType EggToolbarsItemType;

struct EggToolbarsItemType
{
  GdkAtom type;
        
  gboolean (* has_data) (EggToolbarsItemType *type,
                         const char          *name);
  char *   (* get_data) (EggToolbarsItemType *type,
                         const char          *name);
  
  char *   (* new_name) (EggToolbarsItemType *type,
                         const char          *data);
  char *   (* get_name) (EggToolbarsItemType *type,
                         const char          *data);
};

struct EggToolbarsItemAvailable
{
  const char * name;
  guint        available;
};

GType		  egg_toolbars_model_get_type       (void);
EggToolbarsModel *egg_toolbars_model_new	    (void);
gboolean          egg_toolbars_model_load           (EggToolbarsModel *model,
						     const char *xml_file);
void              egg_toolbars_model_save           (EggToolbarsModel *model,
						     const char *xml_file,
						     const char *version);

/* Functions for manipulating the types of portable data this toolbar understands. */
GList *           egg_toolbars_model_get_types      (EggToolbarsModel *model);
void              egg_toolbars_model_set_types      (EggToolbarsModel *model,
                                                     GList            *types);

/* Functions for converting between name and portable data. */
char *            egg_toolbars_model_get_name       (EggToolbarsModel *model,
                                                     GdkAtom           type,
                                                     const char       *data,
                                                     gboolean          create);
char *            egg_toolbars_model_get_data       (EggToolbarsModel *model,
                                                     GdkAtom           type,
                                                     const char       *name);

/* Functions for retrieving what items are available for adding to the toolbars. */
GPtrArray *       egg_toolbars_model_get_avail      (EggToolbarsModel *model);
gint              egg_toolbars_model_get_n_avail    (EggToolbarsModel *model,
                                                     const char       *name);
void              egg_toolbars_model_set_n_avail    (EggToolbarsModel *model,
                                                     const char       *name,
                                                     gint              count);

/* Functions for manipulating flags on individual toolbars. */
EggTbModelFlags   egg_toolbars_model_get_flags      (EggToolbarsModel *model,
						     int               toolbar_position);
void              egg_toolbars_model_set_flags      (EggToolbarsModel *model,
						     int	       toolbar_position,
						     EggTbModelFlags   flags);

/* Functions for adding and removing toolbars. */
int               egg_toolbars_model_add_toolbar    (EggToolbarsModel *model,
						     int               position,
						     const char       *name);
void		  egg_toolbars_model_remove_toolbar (EggToolbarsModel *model,
						     int               position);

/* Functions for adding, removing and moving items. */
gboolean	  egg_toolbars_model_add_item       (EggToolbarsModel *model,
						     int	       toolbar_position,
				                     int               position,
						     const char       *name);
void		  egg_toolbars_model_remove_item    (EggToolbarsModel *model,
						     int               toolbar_position,
						     int               position);
void		  egg_toolbars_model_move_item      (EggToolbarsModel *model,
						     int               toolbar_position,
						     int               position,
						     int	       new_toolbar_position,
						     int               new_position);

/* Functions for accessing the names of items. */
int		  egg_toolbars_model_n_items	    (EggToolbarsModel *model,
						     int               toolbar_position);
const char *      egg_toolbars_model_item_nth	    (EggToolbarsModel *model,
						     int	       toolbar_position,
						     int               position);

/* Functions for accessing the names of toolbars. */
int		  egg_toolbars_model_n_toolbars	    (EggToolbarsModel *model);
const char	 *egg_toolbars_model_toolbar_nth    (EggToolbarsModel *model,
						     int               position);

G_END_DECLS

#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]