Skip to content

Commit 79ed900

Browse files
committed
Add treeview to edit properties
1 parent 10d6d64 commit 79ed900

File tree

2 files changed

+96
-27
lines changed

2 files changed

+96
-27
lines changed

com.github.akiraux.libgtkcanvas.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"sources": [
8080
{
8181
"type": "git",
82-
"url": "https://github.com/albfan/libgtkcanvas",
82+
"url": "https://github.com/akiraux/libgtkcanvas",
8383
"branch": "wip/albfan/action-buttons"
8484
}
8585
]

demo/Window.vala

Lines changed: 95 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,46 @@
1919
* Authored by: Felipe Escoto <felescoto95@hotmail.com>
2020
*/
2121

22+
Gtk.TreeStore tree_store;
23+
Gtk.TreeView tree_view;
24+
GSvg.GsDocument svg;
25+
GSvgtk.ActorClutter actorSVG;
26+
27+
void show_attribute(GXml.DomElement element, string attr_name, Gtk.TreeIter? parentIter) {
28+
Gtk.TreeIter childIter;
29+
var value = element.get_attribute(attr_name);
30+
if (value != null) {
31+
//if (element.has_attribute(attr_name)) {
32+
tree_store.append (out childIter, parentIter);
33+
tree_store.set (childIter, 0, attr_name, 1, value, 2, element, -1);
34+
}
35+
}
36+
37+
void list_childs(GXml.DomNode node, Gtk.TreeIter? parentIter) {
38+
39+
foreach (GXml.DomNode child in node.child_nodes) {
40+
Gtk.TreeIter? childIter = parentIter;
41+
if (child is GXml.DomElement) {
42+
tree_store.append (out childIter, parentIter);
43+
tree_store.set (childIter, 0, child.node_name, -1);
44+
45+
var element = child as GXml.DomElement;
46+
Gtk.TreeIter attrIter;
47+
tree_store.append (out attrIter, childIter);
48+
tree_store.set (attrIter, 0, "attributes", -1);
49+
//foreach (var entry in element.attributes.entries()) {
50+
foreach (var param in element.get_class().list_properties()) {
51+
//var key = entry.key;
52+
var key = param.get_nick();
53+
show_attribute(element, key, attrIter);
54+
}
55+
show_attribute(element, "style", attrIter);
56+
show_attribute(element, "id", attrIter);
57+
}
58+
list_childs(child, childIter);
59+
}
60+
}
61+
2262
int main (string argv[]) {
2363
GtkClutter.init (ref argv);
2464

@@ -29,6 +69,8 @@ int main (string argv[]) {
2969

3070
var canvas = new Gcav.Canvas (600, 400);
3171

72+
canvas.set_size_request(600, 400);
73+
3274
canvas.clicked.connect ((modifier) => {
3375
canvas.resizer.visible = false;
3476
});
@@ -102,44 +144,71 @@ int main (string argv[]) {
102144
chooser.close ();
103145

104146
if (chooser.get_file () != null) {
105-
string contents;
106147
var file_choosed = chooser.get_file();
107-
GLib.FileUtils.get_contents(file_choosed.get_path(), out contents, null);
108-
var actor = canvas.add_shape ("svg", "red", 0.0);
109-
(actor as GSvgtk.ActorClutter).set_svg_string(contents);
110-
// Example on how you can add an animation
111-
actor.set_pivot_point (0.5f, 0.5f);
112-
actor.set_scale (0.01f, 0.01f);
113-
actor.opacity = 0;
114-
115-
actor.save_easing_state ();
116-
actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO);
117-
actor.set_easing_duration (200);
118-
actor.set_scale (1.0f, 1.0f);
119-
actor.opacity = 255U;
120-
actor.restore_easing_state ();
148+
try {
149+
svg = new GSvg.GsDocument ();
150+
svg.read_from_file (file_choosed);
151+
list_childs(svg, null);
152+
tree_view.expand_all();
153+
actorSVG = canvas.add_shape ("svg", "red", 0.0) as GSvgtk.ActorClutter;
154+
actorSVG.svg = svg;
155+
// Example on how you can add an animation
156+
actorSVG.set_pivot_point (0.5f, 0.5f);
157+
actorSVG.set_scale (0.01f, 0.01f);
158+
actorSVG.opacity = 0;
159+
160+
actorSVG.save_easing_state ();
161+
actorSVG.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO);
162+
actorSVG.set_easing_duration (200);
163+
actorSVG.set_scale (1.0f, 1.0f);
164+
actorSVG.opacity = 255U;
165+
actorSVG.restore_easing_state ();
166+
} catch( Error e) {
167+
}
121168
}
122-
123169
});
124170
testing_grid.add (canvas_label);
125171
testing_grid.add (width);
126172
testing_grid.add (height);
127173
testing_grid.add (new_shape);
128174
testing_grid.add (new_circle);
129175
testing_grid.add (new_svg);
176+
tree_view = new Gtk.TreeView();
177+
tree_view.expand = true;
178+
tree_store = new Gtk.TreeStore(3, typeof(string), typeof(string), typeof(GXml.DomElement));
179+
tree_view.set_model(tree_store);
180+
tree_view.insert_column_with_attributes(-1, "Type", new Gtk.CellRendererText(), "text", 0, null);
181+
var renderer = new Gtk.CellRendererText();
182+
renderer.editable = true;
183+
renderer.edited.connect ((path, new_text) => {
184+
Gtk.TreeIter iter;
185+
if (tree_store.get_iter_from_string (out iter, path)) {
186+
Value value;
187+
tree_store.get_value(iter, 2, out value);
188+
GXml.DomElement element = value.get_object() as GXml.DomElement;
189+
tree_store.get_value(iter, 0, out value);
190+
var attr_name = value.get_string();
191+
try {
192+
element.set_attribute(attr_name, new_text);
193+
} catch (Error e) {
194+
}
195+
tree_store.set_value(iter, 1, new_text);
196+
197+
actorSVG.svg = svg;
198+
}
199+
});
200+
tree_view.insert_column_with_attributes(-1, "Name", renderer, "text", 1, null);
201+
var scroll = new Gtk.ScrolledWindow (null, null);
202+
scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
203+
scroll.add (tree_view);
204+
testing_grid.add (scroll);
130205

131-
var main_grid = new Gtk.Grid ();
132-
main_grid.margin = 6;
133-
main_grid.column_spacing = 6;
134-
main_grid.orientation = Gtk.Orientation.HORIZONTAL;
135-
136-
var separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
206+
var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
137207

138-
main_grid.add (canvas);
139-
main_grid.add (separator);
140-
main_grid.add (testing_grid);
208+
paned.add1(canvas);
209+
paned.add2(testing_grid);
141210

142-
window.add (main_grid);
211+
window.add (paned);
143212

144213
window.destroy.connect (Gtk.main_quit);
145214
window.show_all ();

0 commit comments

Comments
 (0)