[Xfce4-commits] <design:master> Further work on the tree view mockup implementation in Vala.
Jannis Pohlmann
noreply at xfce.org
Sun May 29 15:58:01 CEST 2011
Updating branch refs/heads/master
to d97b5a3e27b4a3f124a8a8c1ac97727d8b2e012b (commit)
from 8eb8e697f57b5bbb8b96c3f29c3eb8d156f9e4cb (commit)
commit d97b5a3e27b4a3f124a8a8c1ac97727d8b2e012b
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Sun May 29 15:56:10 2011 +0200
Further work on the tree view mockup implementation in Vala.
.../treeview-mockup/vala/mockup.vala | 398 +++++++++++++++++++-
1 files changed, 397 insertions(+), 1 deletions(-)
diff --git a/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala b/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
index b8e9022..6c38346 100644
--- a/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
+++ b/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
@@ -20,15 +20,411 @@
using Gtk;
+
+
+public class Shortcut : GLib.Object {
+ public string name { get; set; }
+ public Icon icon { get; set; }
+}
+
+
+
+public class DeviceShortcut : Shortcut {
+ public bool mounted { get; set; }
+
+ public DeviceShortcut (string name, string icon_name, bool mounted) {
+ this.name = name;
+ this.icon = new ThemedIcon (icon_name);
+ this.mounted = mounted;
+ }
+}
+
+
+
+public class SystemShortcut : Shortcut {
+ public SystemShortcut (string name, string icon_name) {
+ this.name = name;
+ this.icon = new ThemedIcon (icon_name);
+ }
+}
+
+
+
+public class RemoteShortcut : Shortcut {
+ public bool connected { get; set; }
+
+ public RemoteShortcut (string name, string icon_name, bool connected) {
+ this.name = name;
+ this.icon = new ThemedIcon (icon_name);
+ this.connected = connected;
+ }
+}
+
+
+
+public class Category : GLib.Object {
+ public string name { get; set; }
+
+ private GenericArray<Shortcut> _items = new GenericArray<Shortcut> ();
+
+ public GenericArray<Shortcut> items {
+ get { return _items; }
+ }
+
+ public Category (string name) {
+ this.name = name;
+ }
+}
+
+
+
+public class ShortcutsModel : GLib.Object, TreeModel {
+ public static enum Column { ICON, NAME, ACTION_WIDGET }
+ private static Type[] ColumnTypes = { typeof (Icon), typeof (string), typeof (Button) };
+
+ private GenericArray<Category> categories = new GenericArray<Category> ();
+ private int stamp = (int) Random.next_int ();
+
+ public ShortcutsModel () {
+ var devices = new Category ("Devices");
+ categories.add (devices);
+
+ var disk = new DeviceShortcut ("File System", "harddrive", true);
+ devices.items.add (disk);
+
+ var ipod = new DeviceShortcut ("iPod", "multimedia-player", true);
+ devices.items.add (ipod);
+
+ var dvd = new DeviceShortcut ("Blank DVD+RW Disc", "media-optical-dvd", false);
+ devices.items.add (dvd);
+
+ var places = new Category ("Places");
+ categories.add (places);
+
+ var home = new SystemShortcut ("ochosi", "user-home");
+ places.items.add(home);
+
+ var desktop = new SystemShortcut ("desktop", "user-desktop");
+ places.items.add (desktop);
+
+ var network = new Category ("Network");
+ categories.add (network);
+
+ var sshxfce = new RemoteShortcut ("ssh at xfce.org", "folder-remote", true);
+ network.items.add(sshxfce);
+
+ var ftpgezeiten = new RemoteShortcut ("ftp at gezeiten.org", "folder-remote", false);
+ network.items.add(ftpgezeiten);
+ }
+
+ public TreeModelFlags get_flags () {
+ return TreeModelFlags.ITERS_PERSIST;
+ }
+
+ public int get_n_columns () {
+ return 3;
+ }
+
+ public Type get_column_type (int index) {
+ return ColumnTypes[index];
+ }
+
+ public bool get_iter (out TreeIter iter, TreePath path) {
+ int category_index = path.get_indices ()[0];
+ int item_index = path.get_indices ()[1];
+
+ if (path.get_depth () == 1) {
+ if (category_index >= 0 && category_index < categories.length) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = category_index.to_pointer (),
+ user_data2 = (-1).to_pointer ()
+ };
+
+ return true;
+ }
+ } else {
+ if (category_index >= 0 && category_index < categories.length) {
+ Category category = categories.get (category_index);
+
+ if (category != null && item_index >= 0 && item_index < category.items.length) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = category_index.to_pointer (),
+ user_data2 = item_index.to_pointer ()
+ };
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public TreePath get_path (TreeIter iter) {
+ /* TODO implement me */
+ assert (false);
+ return new TreePath ();
+ }
+
+ public void get_value (TreeIter iter, int column, out Value value) {
+ int category_index = (int) iter.user_data;
+ assert (category_index < categories.length);
+
+ Category category = categories.get (category_index);
+ assert (category != null);
+
+ int item_index = (int) iter.user_data2;
+ assert (item_index < category.items.length);
+
+ if (item_index < 0) {
+ if (column == Column.NAME)
+ value = "<b>" + category.name + "</b>";
+ else
+ value = Value (ColumnTypes[column]);
+ } else {
+ var item = category.items.get (item_index);
+ assert (item != null);
+
+ if (column == Column.NAME)
+ value = item.name;
+ else if (column == Column.ICON) {
+ value = item.icon;
+ } else
+ value = Value (ColumnTypes[column]);
+ }
+ }
+
+ public bool iter_next (ref TreeIter iter) {
+ int category_index = (int) iter.user_data;
+ int item_index = (int) iter.user_data2;
+
+ assert (category_index < categories.length || categories.length == 0);
+
+ Category category = categories.get (category_index);
+ assert (category != null);
+
+ assert (item_index < category.items.length || category.items.length == 0);
+
+ if (item_index < 0) {
+ int next_category = category_index + 1;
+ iter.user_data = next_category.to_pointer ();
+ return next_category < categories.length;
+ } else {
+ int next_item_index = item_index + 1;
+ iter.user_data2 = next_item_index.to_pointer ();
+ return next_item_index < category.items.length;
+ }
+ }
+
+ public bool iter_children (out TreeIter iter, TreeIter? parent) {
+ if (parent == null) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = 0.to_pointer (),
+ user_data2 = (-1).to_pointer ()
+ };
+
+ return true;
+ } else {
+ int item_index = (int) parent.user_data2;
+ if (item_index < 0) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = parent.user_data,
+ user_data2 = 0.to_pointer ()
+ };
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public bool iter_has_child (TreeIter iter) {
+ int category_index = (int) iter.user_data;
+ int item_index = (int) iter.user_data2;
+
+ if (category_index < 0 || category_index >= categories.length)
+ return false;
+
+ Category category = categories.get (category_index);
+ assert (category != null);
+
+ return item_index < 0 && category.items.length > 0;
+ }
+
+ public int iter_n_children (TreeIter? iter) {
+ if (iter == null) {
+ return (int) categories.length;
+ } else {
+ int item_index = (int) iter.user_data2;
+ if (item_index < 0) {
+ int category_index = (int) iter.user_data;
+ assert (category_index < categories.length);
+
+ Category category = categories.get (category_index);
+ assert (category != null);
+
+ return category.items.length;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ public bool iter_nth_child (out TreeIter iter, TreeIter? parent, int n) {
+ if (parent == null) {
+ if (n < categories.length) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = n.to_pointer (),
+ user_data2 = (-1).to_pointer ()
+ };
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ int item_index = (int) parent.user_data2;
+ if (item_index < 0) {
+ int category_index = (int) parent.user_data;
+ assert (category_index < categories.length);
+
+ Category category = categories.get (category_index);
+ assert (category != null);
+
+ assert (n < category.items.length);
+
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = category_index.to_pointer (),
+ user_data2 = n.to_pointer ()
+ };
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public bool iter_parent (out TreeIter iter, TreeIter child) {
+ int category_index = (int) child.user_data;
+ int item_index = (int) child.user_data2;
+
+ if (item_index >= 0) {
+ iter = TreeIter () {
+ stamp = stamp,
+ user_data = category_index.to_pointer (),
+ user_data2 = (-1).to_pointer ()
+ };
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public void ref_node (TreeIter iter) {
+ }
+
+ public void unref_node (TreeIter iter) {
+ }
+}
+
+
+
+public class CellRendererFlexibleIcon : CellRendererPixbuf {
+
+ public override void get_size (Widget widget, Gdk.Rectangle? cell_area,
+ out int x_offset, out int y_offset,
+ out int width, out int height)
+ {
+ if (gicon != null) {
+ x_offset = 0;
+ y_offset = 0;
+ width = 16;
+ height = 16;
+ } else {
+ x_offset = 0;
+ y_offset = 0;
+ width = 0;
+ height = 0;
+ }
+ }
+
+}
+
+
+
+public class ShortcutsView : Frame {
+ private ShortcutsModel model;
+ private TreeView view;
+
+ public ShortcutsView () {
+ set_shadow_type (ShadowType.NONE);
+
+ var scrollwin = new ScrolledWindow (null, null);
+ scrollwin.set_shadow_type (ShadowType.ETCHED_IN);
+ scrollwin.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+ add (scrollwin);
+ scrollwin.show ();
+
+ model = new ShortcutsModel ();
+
+ view = new TreeView ();
+ view.set_model (model);
+ view.set_headers_visible (true);
+ view.set_level_indentation (-16);
+ scrollwin.add (view);
+ view.show ();
+
+ var icon_renderer = new CellRendererFlexibleIcon ();
+
+ var name_renderer = new CellRendererText ();
+
+ var column = new TreeViewColumn ();
+ column.set_title ("Name");
+ column.pack_start (icon_renderer, false);
+ column.set_attributes (icon_renderer, "gicon", ShortcutsModel.Column.ICON);
+ column.pack_start (name_renderer, true);
+ column.set_attributes (name_renderer, "markup", ShortcutsModel.Column.NAME);
+ view.append_column(column);
+ }
+}
+
+
+
+public class ShortcutsPane : Frame {
+ private ShortcutsView view;
+
+ public ShortcutsPane () {
+ set_border_width (24);
+ set_shadow_type (ShadowType.NONE);
+
+ view = new ShortcutsView ();
+ add (view);
+ view.show ();
+ }
+}
+
+
+
int main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
window.title = "Shortcuts Pane Mockup (Tree View)";
- window.set_default_size (250, 600);
+ window.set_default_size (300, 600);
window.position = WindowPosition.CENTER;
window.destroy.connect (Gtk.main_quit);
+ var shortcuts_pane = new ShortcutsPane ();
+ window.add (shortcuts_pane);
+ shortcuts_pane.show ();
+
window.show ();
Gtk.main ();
More information about the Xfce4-commits
mailing list