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

gEDA-cvs: pcb.git: branch: master updated (f010e6bfec24967534ca82bc047f82b6ed0b9f16)



The branch, master has been updated
       via  f010e6bfec24967534ca82bc047f82b6ed0b9f16 (commit)
       via  1f264644a8e39505b028159459d78b2020c3fb60 (commit)
       via  b23b65887e9874270677189765c960e2fcc8985b (commit)
       via  347f55ffb64a16d90c3753d9f398a31a86ec7310 (commit)
       via  1cc1a36b2d9348a820be0306f4232be1d79e9c9b (commit)
       via  758950bce677f9bda6cc069ea68c9ca1d06725ad (commit)
       via  31f3ad1fe78cacbb210044cfa2bdb27d8ad2524a (commit)
       via  53a53695310aa9b7af7278ac93f5026d2bf59067 (commit)
      from  29c65d98352be5be38b2746ebfd9cc650a0ee04c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 src/hid/gtk/ghid-layer-selector.c |  338 +++++++++++++++++++++++++------------
 src/hid/gtk/ghid-layer-selector.h |    3 +-
 src/hid/gtk/gui-config.c          |   24 ++-
 src/hid/gtk/gui-top-window.c      |   48 +++++-
 src/hid/gtk/gui-utils.c           |   31 ----
 src/hid/gtk/gui.h                 |    1 -
 6 files changed, 292 insertions(+), 153 deletions(-)


=================
 Commit Messages
=================

commit f010e6bfec24967534ca82bc047f82b6ed0b9f16
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Extend layer selector to allow editing layer names in situ

:100644 100644 43b0fa3... 1afd211... M	src/hid/gtk/ghid-layer-selector.c
:100644 100644 ff67800... 1ed5e01... M	src/hid/gtk/ghid-layer-selector.h
:100644 100644 98bfcfe... 4f25e72... M	src/hid/gtk/gui-top-window.c

commit 1f264644a8e39505b028159459d78b2020c3fb60
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Layer selector - Rename "activatable" to "selectable"
    
    GTK has a special meaning for the word "activatable", meaning that the item
    can be double-clicked, or "activated" by hitting enter on it. We use it to
    mean selectable - so change the code to make this clear.

:100644 100644 ca5abe9... 43b0fa3... M	src/hid/gtk/ghid-layer-selector.c
:100644 100644 09fa182... ff67800... M	src/hid/gtk/ghid-layer-selector.h

commit b23b65887e9874270677189765c960e2fcc8985b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Layer selector - remove unused variable

:100644 100644 7648261... ca5abe9... M	src/hid/gtk/ghid-layer-selector.c

commit 347f55ffb64a16d90c3753d9f398a31a86ec7310
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Refactor to remove some duplicated code in the layer selector

:100644 100644 72ec44d... 7648261... M	src/hid/gtk/ghid-layer-selector.c

commit 1cc1a36b2d9348a820be0306f4232be1d79e9c9b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Better encapsulate some of the layer selector initialisation
    
    The work we do within ghid_layer_selector_new() is better placed in the
    appropriate class initialiser functions, otherwise we needn't go to the
    trouble of subclassing a widget in the first place.

:100644 100644 840cd98... 72ec44d... M	src/hid/gtk/ghid-layer-selector.c

commit 758950bce677f9bda6cc069ea68c9ca1d06725ad
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Don't refleak the accel group created by the layer selector
    
    When the accel group is created, we have a reference to it - we don't need
    another.

:100644 100644 639e2be... 840cd98... M	src/hid/gtk/ghid-layer-selector.c

commit 31f3ad1fe78cacbb210044cfa2bdb27d8ad2524a
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Remove the unused function utf8_dup_string

:100644 100644 7136fbb... 0fcb5d2... M	src/hid/gtk/gui-utils.c
:100644 100644 5ba5aeb... ea49bee... M	src/hid/gtk/gui.h

commit 53a53695310aa9b7af7278ac93f5026d2bf59067
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Don't use dup_string where doing so would mix g_free() and free()
    
    The core uses malloc(), strdup(), free() etc..
    The GTK HID primarily uses g_malloc(), g_strdup(), g_free() etc..
    
    Mixing them can lead to bad behaviour and hard to debug crashes. This
    commit is not aimed at fixing any known bugs, but is "by inspection", as
    I spotted some of these when working on a layer selector patch.

:100644 100644 dba0635... 7b2751a... M	src/hid/gtk/gui-config.c

=========
 Changes
=========

commit f010e6bfec24967534ca82bc047f82b6ed0b9f16
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Extend layer selector to allow editing layer names in situ

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index 43b0fa3..1afd211 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -29,6 +29,7 @@ static void menu_pick_cb (GtkRadioAction *action, struct _layer *ldata);
 enum {
   SELECT_LAYER_SIGNAL,
   TOGGLE_LAYER_SIGNAL,
+  RENAME_LAYER_SIGNAL,
   LAST_SIGNAL
 };
 
@@ -40,6 +41,7 @@ enum {
   COLOR_COL,
   TEXT_COL,
   FONT_COL,
+  EDITABLE_COL,
   SELECTABLE_COL,
   SEPARATOR_COL,
   N_COLS
@@ -73,6 +75,7 @@ struct _GHidLayerSelectorClass
 
   void (* select_layer) (GHidLayerSelector *, gint);
   void (* toggle_layer) (GHidLayerSelector *, gint);
+  void (* rename_layer) (GHidLayerSelector *, gint, gchar *);
 };
 
 struct _layer
@@ -85,6 +88,42 @@ struct _layer
   GtkTreeRowReference *rref;
 };
 
+static void
+g_cclosure_user_marshal_VOID__INT_STRING (GClosure     *closure,
+                                          GValue       *return_value G_GNUC_UNUSED,
+                                          guint         n_param_values,
+                                          const GValue *param_values,
+                                          gpointer      invocation_hint G_GNUC_UNUSED,
+                                          gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__INT_STRING) (gpointer     data1,
+                                                 gint         arg_1,
+                                                 gpointer     arg_2,
+                                                 gpointer     data2);
+  register GMarshalFunc_VOID__INT_STRING callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__INT_STRING) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_value_get_int (param_values + 1),
+            (char *)g_value_get_string (param_values + 2),
+            data2);
+}
+
 /*! \brief Deletes the action and accelerator from a layer */
 static void
 free_ldata (GHidLayerSelector *ls, struct _layer *ldata)
@@ -243,6 +282,70 @@ selection_changed_cb (GtkTreeSelection *selection, GHidLayerSelector *ls)
     }
 }
 
+/*! \brief Callback for when a layer name has been edited  */
+static void
+layer_name_editing_started_cb (GtkCellRenderer *renderer,
+                               GtkCellEditable *editable,
+                               gchar           *path,
+                               gpointer         user_data)
+{
+  /* When editing begins, we need to detach PCB's accelerators
+   * so they don't steal all the user's keystrokes.
+   *
+   * XXX: We should not have to do this within a simple widget,
+   *
+   *      and this quick hack workaround breaks the widget's
+   *      abstraction from the rest of the application :(
+   */
+  ghid_remove_accel_groups (GTK_WINDOW (gport->top_window), ghidgui);
+}
+
+/*! \brief Callback for when layer name editing has been canceled */
+static void
+layer_name_editing_canceled_cb (GtkCellRenderer *renderer,
+                                 gpointer         user_data)
+{
+  /* Put PCB's accelerators back.
+   *
+   * XXX: We should not have to do this within a simple widget,
+   *      and this quick hack workaround breaks the widget's
+   *      abstraction from the rest of the application :(
+   */
+  ghid_install_accel_groups (GTK_WINDOW (gport->top_window), ghidgui);
+}
+
+/*! \brief Callback for when a layer name has been edited  */
+static void
+layer_name_edited_cb (GtkCellRendererText *renderer,
+                      gchar               *path,
+                      gchar               *new_text,
+                      gpointer             user_data)
+{
+  GHidLayerSelector *ls = user_data;
+  GtkTreeIter iter;
+  int user_id;
+
+  /* Put PCB's accelerators back.
+   *
+   * XXX: We should not have to do this within a simple widget,
+   *      and this quick hack workaround breaks the widget's
+   *      abstraction from the rest of the application :(
+   */
+  ghid_install_accel_groups (GTK_WINDOW (gport->top_window), ghidgui);
+
+  if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ls->list_store), &iter, path))
+    return;
+
+  gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
+                      &iter,
+                      USER_ID_COL, &user_id,
+                      -1);
+
+  g_signal_emit (ls, ghid_layer_selector_signals[RENAME_LAYER_SIGNAL],
+                 0, user_id, new_text);
+}
+
+
 /*! \brief Callback for menu actions: sync layer selection list, emit signal */
 static void
 menu_view_cb (GtkToggleAction *action, struct _layer *ldata)
@@ -300,20 +403,37 @@ ghid_layer_selector_init (GHidLayerSelector *ls)
 
   renderer1 = ghid_cell_renderer_visibility_new ();
   renderer2 = gtk_cell_renderer_text_new ();
-
-  opacity_col = gtk_tree_view_column_new_with_attributes ("", renderer1,
+  g_object_set (renderer2, "editable-set", TRUE, NULL);
+  g_signal_connect (renderer2, "editing-started",
+                    G_CALLBACK (layer_name_editing_started_cb), ls);
+  g_signal_connect (renderer2, "editing-canceled",
+                    G_CALLBACK (layer_name_editing_canceled_cb), ls);
+  g_signal_connect (renderer2, "edited",
+                    G_CALLBACK (layer_name_edited_cb), ls);
+
+  opacity_col = gtk_tree_view_column_new_with_attributes ("",
+                                                          renderer1,
                                                           "active", VISIBLE_COL,
-                                                          "color", COLOR_COL, NULL);
-  name_col = gtk_tree_view_column_new_with_attributes ("", renderer2,
+                                                          "color",  COLOR_COL,
+                                                          NULL);
+  name_col = gtk_tree_view_column_new_with_attributes ("",
+                                                       renderer2,
                                                        "text", TEXT_COL,
                                                        "font", FONT_COL,
+                                                       "editable", EDITABLE_COL,
                                                        NULL);
 
-  /* action index, active, color, text, font, is_separator */
-  ls->list_store = gtk_list_store_new (N_COLS, G_TYPE_POINTER, G_TYPE_INT,
-                                       G_TYPE_BOOLEAN, G_TYPE_STRING,
-                                       G_TYPE_STRING, G_TYPE_STRING,
-                                       G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+  ls->list_store = gtk_list_store_new (N_COLS,
+                 /* STRUCT_COL      */ G_TYPE_POINTER,
+                 /* USER_ID_COL     */ G_TYPE_INT,
+                 /* VISIBLE_COL     */ G_TYPE_BOOLEAN,
+                 /* COLOR_COL       */ G_TYPE_STRING,
+                 /* TEXT_COL        */ G_TYPE_STRING,
+                 /* FONT_COL        */ G_TYPE_STRING,
+                 /* EDITABLE_COL    */ G_TYPE_BOOLEAN,
+                 /* ACTIVATABLE_COL */ G_TYPE_BOOLEAN,
+                 /* SEPARATOR_COL   */ G_TYPE_BOOLEAN);
+
   gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), opacity_col, -1);
   gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), name_col, -1);
   gtk_tree_view_set_model (GTK_TREE_VIEW (ls), GTK_TREE_MODEL (ls->list_store));
@@ -364,6 +484,14 @@ ghid_layer_selector_class_init (GHidLayerSelectorClass *klass)
                   NULL, NULL,
                   g_cclosure_marshal_VOID__INT, G_TYPE_NONE,
                   1, G_TYPE_INT);
+  ghid_layer_selector_signals[RENAME_LAYER_SIGNAL] =
+    g_signal_new ("rename-layer",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (GHidLayerSelectorClass, rename_layer),
+                  NULL, NULL,
+                  g_cclosure_user_marshal_VOID__INT_STRING, G_TYPE_NONE,
+                  2, G_TYPE_INT, G_TYPE_STRING);
 
   object_class->finalize = ghid_layer_selector_finalize;
 }
@@ -455,7 +583,8 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                                const gchar *name,
                                const gchar *color_string,
                                gboolean visible,
-                               gboolean selectable)
+                               gboolean selectable,
+                               gboolean builtin)
 {
   struct _layer *new_layer = NULL;
   gchar *pname, *vname;
@@ -523,6 +652,7 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                       COLOR_COL,       color_string,
                       TEXT_COL,        name,
                       FONT_COL,        selectable ? NULL : "Italic",
+                      EDITABLE_COL,    !builtin,
                       SELECTABLE_COL,  selectable,
                       SEPARATOR_COL,   FALSE,
                       -1);
diff --git a/src/hid/gtk/ghid-layer-selector.h b/src/hid/gtk/ghid-layer-selector.h
index ff67800..1ed5e01 100644
--- a/src/hid/gtk/ghid-layer-selector.h
+++ b/src/hid/gtk/ghid-layer-selector.h
@@ -24,7 +24,8 @@ void ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                                     const gchar *name,
                                     const gchar *color_string,
                                     gboolean visible,
-                                    gboolean selectable);
+                                    gboolean selectable,
+                                    gboolean builtin);
 
 gint ghid_layer_selector_install_pick_items (GHidLayerSelector *ls,
                                              GtkMenuShell *shell, gint pos);
diff --git a/src/hid/gtk/gui-top-window.c b/src/hid/gtk/gui-top-window.c
index 98bfcfe..4f25e72 100644
--- a/src/hid/gtk/gui-top-window.c
+++ b/src/hid/gtk/gui-top-window.c
@@ -553,6 +553,33 @@ layer_selector_select_callback (GHidLayerSelector *ls, int layer, gpointer d)
   ghid_invalidate_all ();
 }
 
+/*! \brief Callback for GHidLayerSelector layer renaming */
+static void
+layer_selector_rename_callback (GHidLayerSelector *ls,
+                                int layer_id,
+                                char *new_name,
+                                void *userdata)
+{
+  LayerType *layer = LAYER_PTR (layer_id);
+
+  /* Check for a legal layer name - for now, allow anything non-empty */
+  if (new_name[0] == '\0')
+    return;
+
+  /* Don't bother if the name is identical to the current one */
+  if (strcmp (layer->Name, new_name) == 0)
+    return;
+
+  free (layer->Name);
+  layer->Name = strdup (new_name);
+  ghid_layer_buttons_update ();
+  if (!PCB->Changed)
+    {
+      SetChangedFlag (true);
+      ghid_window_set_name_label (PCB->Name);
+    }
+}
+
 /*! \brief Callback for GHidLayerSelector layer toggling */
 static void
 layer_selector_toggle_callback (GHidLayerSelector *ls, int layer, gpointer d)
@@ -772,22 +799,22 @@ make_virtual_layer_buttons (GtkWidget *layer_selector)
  
   layer_process (&color_string, &text, &active, LAYER_BUTTON_SILK);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_SILK,
-                                 text, color_string, active, TRUE);
+                                 text, color_string, active, TRUE, TRUE);
   layer_process (&color_string, &text, &active, LAYER_BUTTON_RATS);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_RATS,
-                                 text, color_string, active, TRUE);
+                                 text, color_string, active, TRUE, TRUE);
   layer_process (&color_string, &text, &active, LAYER_BUTTON_PINS);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_PINS,
-                                 text, color_string, active, FALSE);
+                                 text, color_string, active, FALSE, TRUE);
   layer_process (&color_string, &text, &active, LAYER_BUTTON_VIAS);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_VIAS,
-                                 text, color_string, active, FALSE);
+                                 text, color_string, active, FALSE, TRUE);
   layer_process (&color_string, &text, &active, LAYER_BUTTON_FARSIDE);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_FARSIDE,
-                                 text, color_string, active, FALSE);
+                                 text, color_string, active, FALSE, TRUE);
   layer_process (&color_string, &text, &active, LAYER_BUTTON_MASK);
   ghid_layer_selector_add_layer (layersel, LAYER_BUTTON_MASK,
-                                 text, color_string, active, FALSE);
+                                 text, color_string, active, FALSE, TRUE);
 }
 
 /*! \brief callback for ghid_layer_selector_update_colors */
@@ -821,7 +848,7 @@ make_layer_buttons (GtkWidget *layersel)
     {
       layer_process (&color_string, &text, &active, i);
       ghid_layer_selector_add_layer (GHID_LAYER_SELECTOR (layersel), i,
-                                     text, color_string, active, TRUE);
+                                     text, color_string, active, TRUE, FALSE);
     }
 }
 
@@ -1248,12 +1275,15 @@ ghid_build_pcb_top_window (void)
   ghidgui->layer_selector = ghid_layer_selector_new ();
   make_layer_buttons (ghidgui->layer_selector);
   make_virtual_layer_buttons (ghidgui->layer_selector);
-  g_signal_connect (G_OBJECT (ghidgui->layer_selector), "select_layer",
+  g_signal_connect (G_OBJECT (ghidgui->layer_selector), "select-layer",
                     G_CALLBACK (layer_selector_select_callback),
                     NULL);
-  g_signal_connect (G_OBJECT (ghidgui->layer_selector), "toggle_layer",
+  g_signal_connect (G_OBJECT (ghidgui->layer_selector), "toggle-layer",
                     G_CALLBACK (layer_selector_toggle_callback),
                     NULL);
+  g_signal_connect (G_OBJECT (ghidgui->layer_selector), "rename-layer",
+                    G_CALLBACK (layer_selector_rename_callback),
+                    NULL);
   /* Build main menu */
   ghidgui->menu_bar = ghid_load_menus ();
   gtk_box_pack_start (GTK_BOX (ghidgui->menubar_toolbar_vbox),

commit 1f264644a8e39505b028159459d78b2020c3fb60
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Layer selector - Rename "activatable" to "selectable"
    
    GTK has a special meaning for the word "activatable", meaning that the item
    can be double-clicked, or "activated" by hitting enter on it. We use it to
    mean selectable - so change the code to make this clear.

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index ca5abe9..43b0fa3 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -40,7 +40,7 @@ enum {
   COLOR_COL,
   TEXT_COL,
   FONT_COL,
-  ACTIVATABLE_COL,
+  SELECTABLE_COL,
   SEPARATOR_COL,
   N_COLS
 };
@@ -173,9 +173,9 @@ tree_selection_func (GtkTreeSelection *selection, GtkTreeModel *model,
 
   if (gtk_tree_model_get_iter (model, &iter, path))
     {
-      gboolean activatable;
-      gtk_tree_model_get (model, &iter, ACTIVATABLE_COL, &activatable, -1);
-      return activatable;
+      gboolean selectable;
+      gtk_tree_model_get (model, &iter, SELECTABLE_COL, &selectable, -1);
+      return selectable;
     }
 
   return FALSE;
@@ -203,14 +203,15 @@ button_press_cb (GHidLayerSelector *ls, GdkEventButton *event)
                                      &path, &column, NULL, NULL))
     {
       GtkTreeIter iter;
-      gboolean activatable, separator;
+      gboolean selectable;
+      gboolean separator;
       gtk_tree_model_get_iter (GTK_TREE_MODEL (ls->list_store), &iter, path);
       gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store), &iter,
-                          ACTIVATABLE_COL, &activatable,
+                          SELECTABLE_COL, &selectable,
                           SEPARATOR_COL, &separator, -1);
-      /* Toggle visibility for non-activatable layers no matter
+      /* Toggle visibility for non-selectable layers no matter
        *  where you click. */
-      if (!separator && (column == ls->visibility_column || !activatable))
+      if (!separator && (column == ls->visibility_column || !selectable))
         {
           toggle_visibility (ls, &iter, TRUE);
           return TRUE; 
@@ -446,7 +447,7 @@ ghid_layer_selector_new (void)
  *  \param [in] name          The name of the layer; will be used on selector and menus
  *  \param [in] color_string  The color of the layer on selector
  *  \param [in] visibile      Whether the layer is visible
- *  \param [in] activatable   Whether the layer appears in menus and can be selected
+ *  \param [in] selectable    Whether the layer appears in menus and can be selected
  */
 void
 ghid_layer_selector_add_layer (GHidLayerSelector *ls,
@@ -454,12 +455,12 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                                const gchar *name,
                                const gchar *color_string,
                                gboolean visible,
-                               gboolean activatable)
+                               gboolean selectable)
 {
   struct _layer *new_layer = NULL;
   gchar *pname, *vname;
   gboolean new_iter = TRUE;
-  gboolean last_activatable = TRUE;
+  gboolean last_selectable = TRUE;
   GtkTreePath *path;
   GtkTreeIter iter;
   int i;
@@ -468,17 +469,19 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
   if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls->list_store), &iter))
     do
       {
-        gboolean is_sep, active;
+        gboolean is_sep;
+        gboolean this_selectable;
         gint read_id;
+
         gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
                             &iter, USER_ID_COL, &read_id,
                             SEPARATOR_COL, &is_sep,
-                            ACTIVATABLE_COL, &active, -1);
+                            SELECTABLE_COL, &this_selectable, -1);
 
         if (is_sep)
           continue;
 
-        last_activatable = active;
+        last_selectable = this_selectable;
         if (read_id == user_id)
           {
             new_iter = FALSE;
@@ -490,9 +493,9 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
   /* Handle separator addition */
   if (new_iter)
     {
-      if (activatable != last_activatable)
+      if (selectable != last_selectable)
         {
-          /* Add separator between activatable/non-activatable boundaries */
+          /* Add separator between selectable / non-selectable boundaries */
           gtk_list_store_append (ls->list_store, &iter);
           gtk_list_store_set (ls->list_store, &iter,
                               STRUCT_COL, NULL,
@@ -519,8 +522,8 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                       VISIBLE_COL,     visible,
                       COLOR_COL,       color_string,
                       TEXT_COL,        name,
-                      FONT_COL,        activatable ? NULL : "Italic",
-                      ACTIVATABLE_COL, activatable,
+                      FONT_COL,        selectable ? NULL : "Italic",
+                      SELECTABLE_COL,  selectable,
                       SEPARATOR_COL,   FALSE,
                       -1);
 
@@ -535,7 +538,7 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
   gtk_tree_path_free (path);
 
   /* Create selection action */
-  if (activatable)
+  if (selectable)
     {
       new_layer->pick_action
         = gtk_radio_action_new (pname, name, NULL, NULL, user_id);
@@ -563,7 +566,7 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                                        i < 10 ? "" : "<Alt>",
                                        (i + 1) % 10);
 
-      if (activatable)
+      if (selectable)
         {
           GtkAction *action = GTK_ACTION (new_layer->pick_action);
           gtk_action_set_accel_group (action, ls->accel_group);
@@ -772,11 +775,13 @@ ghid_layer_selector_select_next_visible (GHidLayerSelector *ls)
       /* Scan forward, looking for selectable iter */
       do
         {
-          gboolean visible, activatable;
+          gboolean visible;
+          gboolean selectable;
+
           gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
                               &iter, VISIBLE_COL, &visible,
-                              ACTIVATABLE_COL, &activatable, -1);
-          if (visible && activatable)
+                              SELECTABLE_COL, &selectable, -1);
+          if (visible && selectable)
             {
               gtk_tree_selection_select_iter (ls->selection, &iter);
               return TRUE;
@@ -787,11 +792,13 @@ ghid_layer_selector_select_next_visible (GHidLayerSelector *ls)
       gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls->list_store), &iter);
       do
         {
-          gboolean visible, activatable;
+          gboolean visible;
+          gboolean selectable;
+
           gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
                               &iter, VISIBLE_COL, &visible,
-                              ACTIVATABLE_COL, &activatable, -1);
-          if (visible && activatable)
+                              SELECTABLE_COL, &selectable, -1);
+          if (visible && selectable)
             {
               gtk_tree_selection_select_iter (ls->selection, &iter);
               return TRUE;
diff --git a/src/hid/gtk/ghid-layer-selector.h b/src/hid/gtk/ghid-layer-selector.h
index 09fa182..ff67800 100644
--- a/src/hid/gtk/ghid-layer-selector.h
+++ b/src/hid/gtk/ghid-layer-selector.h
@@ -24,7 +24,7 @@ void ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                                     const gchar *name,
                                     const gchar *color_string,
                                     gboolean visible,
-                                    gboolean activatable);
+                                    gboolean selectable);
 
 gint ghid_layer_selector_install_pick_items (GHidLayerSelector *ls,
                                              GtkMenuShell *shell, gint pos);

commit b23b65887e9874270677189765c960e2fcc8985b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Layer selector - remove unused variable

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index 7648261..ca5abe9 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -64,8 +64,6 @@ struct _GHidLayerSelector
 
   gboolean accel_available[20];
 
-  gboolean last_activatable;
-
   gulong selection_changed_sig_id;
 };
 
@@ -320,7 +318,6 @@ ghid_layer_selector_init (GHidLayerSelector *ls)
   gtk_tree_view_set_model (GTK_TREE_VIEW (ls), GTK_TREE_MODEL (ls->list_store));
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ls), FALSE);
 
-  ls->last_activatable = TRUE;
   ls->visibility_column = opacity_col;
   ls->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ls));
   ls->accel_group = gtk_accel_group_new ();

commit 347f55ffb64a16d90c3753d9f398a31a86ec7310
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Refactor to remove some duplicated code in the layer selector

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index 72ec44d..7648261 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -477,14 +477,15 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                             &iter, USER_ID_COL, &read_id,
                             SEPARATOR_COL, &is_sep,
                             ACTIVATABLE_COL, &active, -1);
-        if (!is_sep)
+
+        if (is_sep)
+          continue;
+
+        last_activatable = active;
+        if (read_id == user_id)
           {
-            last_activatable = active;
-            if(read_id == user_id)
-              {
-                new_iter = FALSE;
-                break;
-              }
+            new_iter = FALSE;
+            break;
           }
       }
     while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ls->list_store), &iter));
@@ -501,18 +502,7 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
                               SEPARATOR_COL, TRUE, -1);
         }
       /* Create new layer */
-      new_layer = malloc (sizeof (*new_layer));
       gtk_list_store_append (ls->list_store, &iter);
-      gtk_list_store_set (ls->list_store, &iter,
-                          STRUCT_COL, new_layer,
-                          USER_ID_COL, user_id,
-                          VISIBLE_COL, visible,
-                          COLOR_COL, color_string,
-                          TEXT_COL, name,
-                          FONT_COL, activatable ? NULL : "Italic",
-                          ACTIVATABLE_COL, activatable,
-                          SEPARATOR_COL, FALSE,
-                          -1);
     }
   else
     {
@@ -521,18 +511,22 @@ ghid_layer_selector_add_layer (GHidLayerSelector *ls,
       gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store), &iter,
                           STRUCT_COL, &new_layer, -1);
       free_ldata (ls, new_layer);
-      new_layer = malloc (sizeof (*new_layer));
-
-      gtk_list_store_set (ls->list_store, &iter,
-                          STRUCT_COL, new_layer,
-                          VISIBLE_COL, visible,
-                          COLOR_COL, color_string,
-                          TEXT_COL, name,
-                          FONT_COL, activatable ? NULL : "Italic",
-                          ACTIVATABLE_COL, activatable,
-                          -1);
     }
 
+  new_layer = malloc (sizeof (*new_layer));
+
+  gtk_list_store_set (ls->list_store,
+                      &iter,
+                      STRUCT_COL,      new_layer,
+                      USER_ID_COL,     user_id,
+                      VISIBLE_COL,     visible,
+                      COLOR_COL,       color_string,
+                      TEXT_COL,        name,
+                      FONT_COL,        activatable ? NULL : "Italic",
+                      ACTIVATABLE_COL, activatable,
+                      SEPARATOR_COL,   FALSE,
+                      -1);
+
   /* -- Setup new actions -- */
   vname = g_strdup_printf ("LayerView%d", ls->n_actions);
   pname = g_strdup_printf ("LayerPick%d", ls->n_actions);

commit 1cc1a36b2d9348a820be0306f4232be1d79e9c9b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Better encapsulate some of the layer selector initialisation
    
    The work we do within ghid_layer_selector_new() is better placed in the
    appropriate class initialiser functions, otherwise we needn't go to the
    trouble of subclassing a widget in the first place.

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index 840cd98..72ec44d 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -290,11 +290,59 @@ menu_pick_cb (GtkRadioAction *action, struct _layer *ldata)
     }
 }
 
-/* CONSTRUCTOR */
 static void
 ghid_layer_selector_init (GHidLayerSelector *ls)
 {
-  /* Hookup signal handlers */
+  int i;
+  GtkCellRenderer *renderer1;
+  GtkCellRenderer *renderer2;
+  GtkTreeViewColumn *opacity_col;
+  GtkTreeViewColumn *name_col;
+
+  renderer1 = ghid_cell_renderer_visibility_new ();
+  renderer2 = gtk_cell_renderer_text_new ();
+
+  opacity_col = gtk_tree_view_column_new_with_attributes ("", renderer1,
+                                                          "active", VISIBLE_COL,
+                                                          "color", COLOR_COL, NULL);
+  name_col = gtk_tree_view_column_new_with_attributes ("", renderer2,
+                                                       "text", TEXT_COL,
+                                                       "font", FONT_COL,
+                                                       NULL);
+
+  /* action index, active, color, text, font, is_separator */
+  ls->list_store = gtk_list_store_new (N_COLS, G_TYPE_POINTER, G_TYPE_INT,
+                                       G_TYPE_BOOLEAN, G_TYPE_STRING,
+                                       G_TYPE_STRING, G_TYPE_STRING,
+                                       G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+  gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), opacity_col, -1);
+  gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), name_col, -1);
+  gtk_tree_view_set_model (GTK_TREE_VIEW (ls), GTK_TREE_MODEL (ls->list_store));
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ls), FALSE);
+
+  ls->last_activatable = TRUE;
+  ls->visibility_column = opacity_col;
+  ls->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ls));
+  ls->accel_group = gtk_accel_group_new ();
+  ls->action_group = gtk_action_group_new ("LayerSelector");
+  ls->n_actions = 0;
+
+  for (i = 0; i < 20; ++i)
+    ls->accel_available[i] = TRUE;
+
+  gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (ls),
+                                        tree_view_separator_func,
+                                        NULL, NULL);
+  gtk_tree_selection_set_select_function (ls->selection, tree_selection_func,
+                                          NULL, NULL);
+  gtk_tree_selection_set_mode (ls->selection, GTK_SELECTION_BROWSE);
+
+  g_object_set_data (G_OBJECT (ls->list_store), "layer-selector", ls);
+  g_signal_connect (ls, "button_press_event",
+                    G_CALLBACK (button_press_cb), NULL);
+  ls->selection_changed_sig_id =
+    g_signal_connect (ls->selection, "changed",
+                      G_CALLBACK (selection_changed_cb), ls);
 }
 
 static void
@@ -383,55 +431,7 @@ ghid_layer_selector_get_type (void)
 GtkWidget *
 ghid_layer_selector_new (void)
 {
-  int i;
-  GtkCellRenderer *renderer1 = ghid_cell_renderer_visibility_new ();
-  GtkCellRenderer *renderer2 = gtk_cell_renderer_text_new ();
-  GtkTreeViewColumn *opacity_col =
-      gtk_tree_view_column_new_with_attributes ("", renderer1,
-                                                "active", VISIBLE_COL,
-                                                "color", COLOR_COL, NULL);
-  GtkTreeViewColumn *name_col =
-      gtk_tree_view_column_new_with_attributes ("", renderer2,
-                                                "text", TEXT_COL,
-                                                "font", FONT_COL,
-                                                NULL);
-
-  GHidLayerSelector *ls = g_object_new (GHID_LAYER_SELECTOR_TYPE, NULL);
-
-  /* action index, active, color, text, font, is_separator */
-  ls->list_store = gtk_list_store_new (N_COLS, G_TYPE_POINTER, G_TYPE_INT,
-                                       G_TYPE_BOOLEAN, G_TYPE_STRING,
-                                       G_TYPE_STRING, G_TYPE_STRING,
-                                       G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
-  gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), opacity_col, -1);
-  gtk_tree_view_insert_column (GTK_TREE_VIEW (ls), name_col, -1);
-  gtk_tree_view_set_model (GTK_TREE_VIEW (ls), GTK_TREE_MODEL (ls->list_store));
-  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ls), FALSE);
-
-  ls->last_activatable = TRUE;
-  ls->visibility_column = opacity_col;
-  ls->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ls));
-  ls->accel_group = gtk_accel_group_new ();
-  ls->action_group = gtk_action_group_new ("LayerSelector");
-  ls->n_actions = 0;
-  for (i = 0; i < 20; ++i)
-    ls->accel_available[i] = TRUE;
-
-  gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (ls),
-                                        tree_view_separator_func,
-                                        NULL, NULL);
-  gtk_tree_selection_set_select_function (ls->selection, tree_selection_func,
-                                          NULL, NULL);
-  gtk_tree_selection_set_mode (ls->selection, GTK_SELECTION_BROWSE);
-
-  g_object_set_data (G_OBJECT (ls->list_store), "layer-selector", ls);
-  g_signal_connect (ls, "button_press_event",
-                    G_CALLBACK (button_press_cb), NULL);
-  ls->selection_changed_sig_id =
-    g_signal_connect (ls->selection, "changed",
-                      G_CALLBACK (selection_changed_cb), ls);
-
-  return GTK_WIDGET (ls);
+  return GTK_WIDGET (g_object_new (GHID_LAYER_SELECTOR_TYPE, NULL));
 }
 
 /*! \brief Add a layer to a GHidLayerSelector.

commit 758950bce677f9bda6cc069ea68c9ca1d06725ad
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Don't refleak the accel group created by the layer selector
    
    When the accel group is created, we have a reference to it - we don't need
    another.

diff --git a/src/hid/gtk/ghid-layer-selector.c b/src/hid/gtk/ghid-layer-selector.c
index 639e2be..840cd98 100644
--- a/src/hid/gtk/ghid-layer-selector.c
+++ b/src/hid/gtk/ghid-layer-selector.c
@@ -431,8 +431,6 @@ ghid_layer_selector_new (void)
     g_signal_connect (ls->selection, "changed",
                       G_CALLBACK (selection_changed_cb), ls);
 
-  g_object_ref (ls->accel_group);
-
   return GTK_WIDGET (ls);
 }
 

commit 31f3ad1fe78cacbb210044cfa2bdb27d8ad2524a
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Remove the unused function utf8_dup_string

diff --git a/src/hid/gtk/gui-utils.c b/src/hid/gtk/gui-utils.c
index 7136fbb..0fcb5d2 100644
--- a/src/hid/gtk/gui-utils.c
+++ b/src/hid/gtk/gui-utils.c
@@ -838,34 +838,3 @@ ghid_scrolled_text_view (GtkWidget * box,
     *scr = scrolled;
   return view;
 }
-
-
-/* If src is not utf8, *dst is converted to utf8.
- */
-gboolean
-utf8_dup_string (gchar ** dst_utf8, const gchar * src)
-{
-  if (!dst_utf8 || (!*dst_utf8 && !src))
-    return FALSE;
-  if (*dst_utf8)
-    {
-      if (src && !strcmp (*dst_utf8, src))
-	return FALSE;
-      g_free (*dst_utf8);
-    }
-  if (src)
-    {
-      if (g_utf8_validate (src, -1, NULL))
-	*dst_utf8 = g_strdup (src);
-      else
-	{
-	  *dst_utf8 = g_locale_to_utf8 (src, -1, NULL, NULL, NULL);
-	  if (!*dst_utf8)
-	    *dst_utf8 = g_strdup (src);
-	}
-    }
-  else
-    *dst_utf8 = NULL;
-
-  return TRUE;
-}
diff --git a/src/hid/gtk/gui.h b/src/hid/gtk/gui.h
index 5ba5aeb..ea49bee 100644
--- a/src/hid/gtk/gui.h
+++ b/src/hid/gtk/gui.h
@@ -347,7 +347,6 @@ void make_route_style_buttons (GHidRouteStyleSelector *rss);
 /* gui-utils.c
 */
 gboolean dup_string (gchar ** dst, const gchar * src);
-gboolean utf8_dup_string (gchar ** dst_utf8, const gchar * src);
 void free_glist_and_data (GList ** list_head);
 
 ModifierKeysState ghid_modifier_keys_state (GdkModifierType * state);

commit 53a53695310aa9b7af7278ac93f5026d2bf59067
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    hid/gtk: Don't use dup_string where doing so would mix g_free() and free()
    
    The core uses malloc(), strdup(), free() etc..
    The GTK HID primarily uses g_malloc(), g_strdup(), g_free() etc..
    
    Mixing them can lead to bad behaviour and hard to debug crashes. This
    commit is not aimed at fixing any known bugs, but is "by inspection", as
    I spotted some of these when working on a layer selector patch.

diff --git a/src/hid/gtk/gui-config.c b/src/hid/gtk/gui-config.c
index dba0635..7b2751a 100644
--- a/src/hid/gtk/gui-config.c
+++ b/src/hid/gtk/gui-config.c
@@ -169,6 +169,20 @@ static ConfigAttribute config_attributes[] = {
   {"layer-name-8", CONFIG_Unused, NULL},
 };
 
+static gboolean
+dup_core_string (gchar ** dst, const gchar * src)
+{
+  if (dst == NULL || (*dst == NULL && src == NULL))
+    return FALSE;
+
+  if (*dst != NULL && src != NULL && strcmp (*dst, src) == 0)
+    return FALSE;
+
+  free (*dst);
+  *dst = (src == NULL) ? NULL : strdup (src);
+
+  return TRUE;
+}
 
 static FILE *
 config_file_open (gchar * mode)
@@ -1362,10 +1376,10 @@ config_layers_apply (void)
     {
       layer = &PCB->Data->Layer[i];
       s = ghid_entry_get_text (layer_entry[i]);
-      if (dup_string (&layer->Name, s))
+      if (dup_core_string (&layer->Name, s))
 	layers_modified = TRUE;
 /* FIXME */
-      if (use_as_default && dup_string (&Settings.DefaultLayerName[i], s))
+      if (use_as_default && dup_core_string (&Settings.DefaultLayerName[i], s))
 	ghidgui->config_modified = TRUE;
 
     }
@@ -1421,7 +1435,7 @@ config_layers_apply (void)
   if (use_as_default)
     {
       s = make_layer_group_string (&PCB->LayerGroups);
-      if (dup_string (&Settings.Groups, s))
+      if (dup_core_string (&Settings.Groups, s))
 	{
 	  ParseGroupString (Settings.Groups, &Settings.LayerGroups, max_copper_layer);
 	  ghidgui->config_modified = TRUE;
@@ -1460,7 +1474,7 @@ layer_name_entry_cb(GtkWidget *entry, gpointer data)
 
 	layer = &PCB->Data->Layer[i];
 	name = ghid_entry_get_text(entry);
-	if (dup_string (&layer->Name, name))
+	if (dup_core_string (&layer->Name, name))
 		ghid_layer_buttons_update();
 }
 
@@ -1712,7 +1726,7 @@ config_color_defaults_cb (gpointer data)
     {
       cc = (ConfigColor *) list->data;
       ha = cc->attributes;
-      dup_string ((char **) ha->value, ha->default_val.str_value);
+      dup_core_string ((char **) ha->value, ha->default_val.str_value);
       cc->color_is_mapped = FALSE;
       ghid_set_special_colors (ha);
     }




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs