/* project-dialog.vala * * Copyright (C) 2008 Nicolas Joseph * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Author: * Nicolas Joseph */ using Gtk; private enum Valide.ColumnType { ICON, NAME, DESCRIPTION, NB_COLUMNS } public class Valide.ProjectDialog : Gtk.Dialog { private Gtk.ListStore list_store; private Gtk.IconView icon_view; private Gtk.Label desc_label; private Gtk.Entry name_entry; private Gtk.Entry dir_entry; private Gtk.Entry path_entry; private string project_type_; public string project_name { get { return this.name_entry.text; } } public string project_path { get { return this.path_entry.text; } } public string project_dir { get { return this.dir_entry.text; } } public string project_type { get { return this.project_type_; } } public string project_desc { set { this.desc_label.set_text ("Description: " + value); } } construct { this.list_store = new Gtk.ListStore (3, typeof (Gdk.Pixbuf), typeof (string), typeof (string)); this.icon_view = new Gtk.IconView (); this.icon_view.set_selection_mode (Gtk.SelectionMode.SINGLE); this.icon_view.set_pixbuf_column (0); this.icon_view.set_text_column (1); this.icon_view.set_model (this.list_store); this.populate_icon_view (); weak Gtk.Box main_box = (Gtk.Box)this.vbox; main_box.pack_start (icon_view, true, true, 0); this.desc_label = new Gtk.Label (""); main_box.pack_start (this.desc_label, false, true, 5); var hbox = new Gtk.HBox (false, 20); Gtk.VBox vbox = new Gtk.VBox (true, 0); hbox.pack_start (vbox, false, true, 0); vbox.add (new Gtk.Label ("Project name : ")); vbox.add (new Gtk.Label ("Project directory : ")); vbox.add (new Gtk.Label ("Project path : ")); vbox = new Gtk.VBox (true, 0); hbox.pack_start (vbox, true, true, 0); this.name_entry = new Gtk.Entry (); this.name_entry.changed += this.project_path_change; vbox.add (this.name_entry); Gtk.HBox hbox2 = new Gtk.HBox (false, 0); vbox.add (hbox2); this.dir_entry = new Gtk.Entry (); this.dir_entry.changed += this.project_path_change; hbox2.pack_start (this.dir_entry, true, true, 0); Gtk.Button button = new Gtk.Button.with_label ("..."); button.clicked += this.btn_clicked; hbox2.pack_start (button, false, true, 0); this.path_entry = new Gtk.Entry (); vbox.add (this.path_entry); main_box.pack_start (hbox, false, true, 0); this.add_button (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL); this.add_button (Gtk.STOCK_OK, Gtk.ResponseType.OK); this.set_modal (true); this.icon_view.selection_changed += this.selection_changed; this.icon_view.select_path (new Gtk.TreePath.from_string ("0")); main_box.show_all (); this.name_entry.grab_focus (); } public ProjectDialog () { this.title = "Create new project"; this.default_height = 600; this.default_width = 800; } protected void populate_icon_view () { try { GLib.List files = Template.get_list (); foreach (string filename in files) { try { Gtk.TreeIter iter; Template template = new Template (filename); this.list_store.append (out iter); this.list_store.set (iter, ColumnType.ICON, template.icon, ColumnType.NAME, template.name, ColumnType.DESCRIPTION, template.desc, -1); } catch (GLib.Error e) { GLib.critical (e.message); } } } catch (GLib.Error e) { GLib.critical (e.message); } } [Callback] protected void selection_changed (Gtk.IconView icon_view) { Gtk.TreeIter iter; weak GLib.List item = this.icon_view.get_selected_items (); if (item != null) { Gtk.TreePath* path = item.data; Gtk.TreePath path2 = new Gtk.TreePath.from_string (path->to_string ()); this.list_store.get_iter (out iter, path2); string desc; this.list_store.get (iter, ColumnType.DESCRIPTION, out desc); this.project_desc = desc; } } [Callback] private void btn_clicked () { Gtk.FileChooserDialog dialog = new FileChooserDialog ("Select projects directory", null, Gtk.FileChooserAction.SELECT_FOLDER, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT, null); if (dialog.run () == Gtk.ResponseType.ACCEPT) { this.dir_entry.set_text (dialog.get_filename ()); } dialog.destroy (); } [Callback] private void project_path_change () { this.path_entry.text = GLib.Path.build_filename (this.dir_entry.text, this.project_name, null) + "/"; } }