[anjuta] Fixes for vala wizard in class-gen
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] Fixes for vala wizard in class-gen
- Date: Mon, 27 Dec 2010 21:34:00 +0000 (UTC)
commit ab4bba039c872239d6399739c3915760b2567277
Author: Kenny Meyer <knny myer gmail com>
Date: Mon Dec 27 17:16:56 2010 -0300
Fixes for vala wizard in class-gen
* Remove checkbox for deriving from GLib.Object, instead use Base
class entry for that.
* Scope for properties now for getter/setter
* Automatic properties
* Add 'internal' scope
* Add implicit scope if no scope defined. Defaults to 'public'
* Prefill Vala signals return value with void, because not implemented
yet in Vala.
plugins/class-gen/anjuta-class-gen-plugin.ui | 166 ++++++++++++--------------
plugins/class-gen/templates/vala-source.tpl | 42 ++++---
plugins/class-gen/window.c | 91 +++++++--------
3 files changed, 142 insertions(+), 157 deletions(-)
---
diff --git a/plugins/class-gen/anjuta-class-gen-plugin.ui b/plugins/class-gen/anjuta-class-gen-plugin.ui
index db11095..d1da275 100644
--- a/plugins/class-gen/anjuta-class-gen-plugin.ui
+++ b/plugins/class-gen/anjuta-class-gen-plugin.ui
@@ -2,6 +2,54 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkListStore" id="model1">
+ <columns>
+ <!-- column-name gchararray -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0">public</col>
+ </row>
+ <row>
+ <col id="0">protected</col>
+ </row>
+ <row>
+ <col id="0">private</col>
+ </row>
+ </data>
+ </object>
+ <object class="GtkListStore" id="model2">
+ <columns>
+ <!-- column-name gchararray -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">General Public License (GPL)</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Lesser General Public License (LGPL)</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">No License</col>
+ </row>
+ </data>
+ </object>
+ <object class="GtkListStore" id="model3">
+ <columns>
+ <!-- column-name gchararray -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0">public</col>
+ </row>
+ <row>
+ <col id="0">internal</col>
+ </row>
+ </data>
+ </object>
<object class="GtkDialog" id="classgen_main">
<property name="title" translatable="yes">Class Generator</property>
<property name="default_height">582</property>
@@ -1561,8 +1609,8 @@
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
- <property name="n_rows">5</property>
- <property name="n_columns">3</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">4</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
@@ -1582,33 +1630,26 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label17">
+ <object class="GtkLabel" id="lbl_vala_base">
<property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Source/Header Headings:</property>
+ <property name="label" translatable="yes">Base Class:</property>
</object>
<packing>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="vala_headings">
- <property name="label" translatable="yes">Author/Date/Time</property>
+ <object class="GtkEntry" id="vala_base">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="text" translatable="yes">GLib.Object</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
<child>
@@ -1617,14 +1658,14 @@
<property name="label" translatable="yes">Class Scope:</property>
</object>
<packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="vala_class_scope">
<property name="visible">True</property>
- <property name="model">model1</property>
+ <property name="model">model3</property>
<child>
<object class="GtkCellRendererText" id="renderer2"/>
<attributes>
@@ -1633,51 +1674,38 @@
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="lbl_vala_base">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="label" translatable="yes">Base Class:</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="left_attach">3</property>
+ <property name="right_attach">4</property>
</packing>
</child>
<child>
- <object class="GtkEntry" id="vala_base">
+ <object class="GtkLabel" id="label17">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Source/Header Headings:</property>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="vala_derive_from_glib">
- <property name="label" translatable="yes">Derive from GLib.Object</property>
+ <object class="GtkCheckButton" id="vala_headings">
+ <property name="label" translatable="yes">Author/Date/Time</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@@ -1692,12 +1720,6 @@
<child>
<placeholder/>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
</child>
</object>
@@ -2277,38 +2299,4 @@
<action-widget response="-3">create_button</action-widget>
</action-widgets>
</object>
- <object class="GtkListStore" id="model2">
- <columns>
- <!-- column-name gchararray -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">General Public License (GPL)</col>
- </row>
- <row>
- <col id="0" translatable="yes">Lesser General Public License (LGPL)</col>
- </row>
- <row>
- <col id="0" translatable="yes">No License</col>
- </row>
- </data>
- </object>
- <object class="GtkListStore" id="model1">
- <columns>
- <!-- column-name gchararray -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0">public</col>
- </row>
- <row>
- <col id="0">protected</col>
- </row>
- <row>
- <col id="0">private</col>
- </row>
- </data>
- </object>
</interface>
diff --git a/plugins/class-gen/templates/vala-source.tpl b/plugins/class-gen/templates/vala-source.tpl
index 7acdfc7..9b98d14 100644
--- a/plugins/class-gen/templates/vala-source.tpl
+++ b/plugins/class-gen/templates/vala-source.tpl
@@ -28,38 +28,40 @@
[+ == "GPL" +][+(gpl (get "ProjectName") " * ")+]
[+ESAC+] */
-[+ClassScope+] class [+ClassName+][+
-IF (=(get "DeriveFromGlib") "1") +] : GLib.Object[+
-ELIF (not (=(get "BaseClass") "")) +] : [+BaseClass+][+
-ENDIF+] {[+
-FOR Properties+]
- [+Scope+] [+Type+] _[+Name+] = [+Value+];[+
+[+ClassScope+] class [+ClassName+] : [+BaseClass+] {[+
+FOR Properties+][+
+ IF (=(get "Automatic") "Yes") +]
+ [+Scope+] [+Type+] [+Name+] { get; set; }[+
+ ELSE+]
+ private [+Type+] _[+Name+] = [+Value+];[+
+ ENDIF+][+
IF (last-for?) +]
[+
ENDIF+][+
ENDFOR+][+
+FOR Properties+][+
+ IF (=(get "Automatic") "No") +]
+ [+Scope+] [+Type+] [+Name+] {[+
+ IF (=(get "Getter") "YES")+]
+ get { return _[+Name+] }[+
+ ENDIF+][+
+ IF (=(get "Setter") "YES")+]
+ set { _[+Name+] = value }[+
+ ENDIF+]
+ }[+
+ ENDIF+][+
+ENDFOR+][+
FOR Signals+][+
IF (first-for?) +]
/* Signal definitions */[+ENDIF+]
- [+Scope+] signal [+Type+] [+Name+] [+Arguments+];[+
- IF (last-for?) +]
-
-[+
- ENDIF+][+
+ [+Scope+] signal void [+Name+] [+Arguments+];[+
ENDFOR+]
+
// Constructor
public [+ClassName+] () {
+
}
[+
-FOR Properties+]
- public int [+Name+] {
- get { return _[+Name+] }[+
- IF (not (=(get "Setter") "")) +]
- set { _[+Name+] = value }[+
- ENDIF+]
- }[+
-ENDFOR+]
-[+
FOR Methods+][+
IF (first-for?) +]
/* Method definitions */[+ENDIF+]
diff --git a/plugins/class-gen/window.c b/plugins/class-gen/window.c
index 6f6a536..b8f89b5 100644
--- a/plugins/class-gen/window.c
+++ b/plugins/class-gen/window.c
@@ -150,12 +150,20 @@ static const gchar *VALA_BOOLEAN_LIST[] =
NULL
};
-static const gchar *VALA_SCOPE_LIST[] =
+static const gchar *VALA_METHSIG_SCOPE_LIST[] =
{
"public",
"private",
"protected",
NULL
+}
+;
+static const gchar *VALA_PROP_SCOPE_LIST[] =
+{
+ "public",
+ "protected",
+ "internal",
+ NULL
};
#if 0
@@ -639,36 +647,6 @@ cg_window_vala_name_changed_cb (GtkEntry *entry,
cg_window_dynamic_name_changed_cb (entry, user_data, ".vala");
}
-static void
-cg_window_vala_derive_from_glib (GtkEntry *entry,
- gpointer user_data)
-{
- CgWindow *window;
- CgWindowPrivate *priv;
-
- GtkWidget *derive_from_glib;
- GtkWidget *entry_base_class;
- GtkWidget *label_base_class;
-
- window = CG_WINDOW (user_data);
- priv = CG_WINDOW_PRIVATE (window);
-
- derive_from_glib = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "vala_derive_from_glib"));
- entry_base_class = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "vala_base"));
- label_base_class = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "lbl_vala_base"));
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (derive_from_glib)) == FALSE)
- {
- gtk_editable_set_editable (GTK_EDITABLE (entry_base_class), TRUE);
- gtk_widget_set_sensitive (label_base_class, TRUE);
- }
- else
- {
- gtk_editable_set_editable (GTK_EDITABLE (entry_base_class), FALSE);
- gtk_widget_set_sensitive (label_base_class, FALSE);
- }
-}
-
#if 0
static void
cg_window_associate_browse_button (GladeXML *xml,
@@ -798,7 +776,7 @@ cg_window_set_builder (CgWindow *window,
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_methods_add")),
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_methods_remove")),
4,
- _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_SCOPE_LIST,
+ _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_METHSIG_SCOPE_LIST,
_("Type"), CG_ELEMENT_EDITOR_COLUMN_STRING,
_("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING,
_("Arguments"), CG_ELEMENT_EDITOR_COLUMN_ARGUMENTS);
@@ -807,20 +785,21 @@ cg_window_set_builder (CgWindow *window,
GTK_TREE_VIEW (gtk_builder_get_object (priv->bxml, "vala_properties")),
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_properties_add")),
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_properties_remove")),
- 5,
- _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_SCOPE_LIST,
+ 7,
+ _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_PROP_SCOPE_LIST,
_("Type"), CG_ELEMENT_EDITOR_COLUMN_STRING,
_("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING,
- _("Value"), CG_ELEMENT_EDITOR_COLUMN_STRING,
- _("Setter"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_BOOLEAN_LIST);
+ _("Automatic"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_BOOLEAN_LIST,
+ _("Getter"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_BOOLEAN_LIST,
+ _("Setter"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_BOOLEAN_LIST,
+ _("Value"), CG_ELEMENT_EDITOR_COLUMN_STRING);
priv->editor_vala_signals = cg_element_editor_new (
GTK_TREE_VIEW (gtk_builder_get_object (priv->bxml, "vala_signals")),
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_signals_add")),
GTK_BUTTON (gtk_builder_get_object (priv->bxml, "vala_signals_remove")),
- 4,
- _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_SCOPE_LIST,
- _("Type"), CG_ELEMENT_EDITOR_COLUMN_STRING,
+ 3,
+ _("Scope"), CG_ELEMENT_EDITOR_COLUMN_LIST, VALA_METHSIG_SCOPE_LIST,
_("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING,
_("Arguments"), CG_ELEMENT_EDITOR_COLUMN_ARGUMENTS);
@@ -840,9 +819,6 @@ cg_window_set_builder (CgWindow *window,
G_OBJECT (gtk_builder_get_object (priv->bxml, "vala_name")), "changed",
G_CALLBACK (cg_window_vala_name_changed_cb), window);
- g_signal_connect (
- G_OBJECT (gtk_builder_get_object (priv->bxml, "vala_derive_from_glib")), "toggled",
- G_CALLBACK (cg_window_vala_derive_from_glib), window);
gtk_combo_box_set_active (
GTK_COMBO_BOX (gtk_builder_get_object (priv->bxml, "vala_class_scope")),
0);
@@ -1015,19 +991,37 @@ cg_window_js_imports_transform_func (GHashTable *table,
}
static void
+vala_transform_scope_func (GHashTable *table,
+ G_GNUC_UNUSED gpointer user_data)
+{
+ gchar *scope;
+
+ scope = g_hash_table_lookup (table, "Scope");
+ if (scope == NULL)
+ {
+ g_hash_table_insert (table, "Scope",
+ g_strdup_printf("public"));
+ }
+}
+
+static void
cg_window_vala_methods_transform_func (GHashTable *table,
G_GNUC_UNUSED gpointer user_data)
{
cg_transform_string (table, "Name");
cg_transform_arguments (table, "Arguments", FALSE);
+
+ vala_transform_scope_func (table, user_data);
}
static void
cg_window_vala_signals_transform_func (GHashTable *table,
- G_GNUC_UNUSED gpointer user_data)
+ G_GNUC_UNUSED gpointer user_data)
{
cg_transform_string (table, "Name");
cg_transform_arguments (table, "Arguments", FALSE);
+
+ vala_transform_scope_func (table, user_data);
}
static void
@@ -1035,6 +1029,9 @@ cg_window_vala_properties_transform_func (GHashTable *table,
G_GNUC_UNUSED gpointer user_data)
{
cg_transform_string (table, "Name");
+ cg_transform_string (table, "Value");
+
+ vala_transform_scope_func (table, user_data);
}
#if 0
@@ -1433,18 +1430,16 @@ cg_window_create_value_heap (CgWindow *window)
"ClassScope", "vala_class_scope");
cg_window_set_heap_value (window, values, G_TYPE_BOOLEAN,
"Headings", "vala_headings");
- cg_window_set_heap_value (window, values, G_TYPE_BOOLEAN,
- "DeriveFromGlib", "vala_derive_from_glib");
cg_element_editor_set_values (priv->editor_vala_methods, "Methods", values,
cg_window_vala_methods_transform_func,
window, "Scope", "Type", "Name", "Arguments");
cg_element_editor_set_values (priv->editor_vala_properties, "Properties", values,
cg_window_vala_properties_transform_func,
- window, "Scope", "Type", "Name", "Value",
- "Setter");
+ window, "Scope", "Type", "Name", "Automatic",
+ "Getter", "Setter", "Value");
cg_element_editor_set_values (priv->editor_vala_signals, "Signals", values,
cg_window_vala_signals_transform_func,
- window, "Scope", "Type", "Name", "Arguments");
+ window, "Scope", "Name", "Arguments");
break;
default:
g_assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]