/* window.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; public class Valide.Window : Gtk.Window { private static Window instance = null; protected UIManager ui_manager; protected DocumentFactory documents; protected ProjectFactory projects; construct { this.maximize (); this.delete_event += on_delete_event; this.destroy += Gtk.main_quit; this.title = "Val(a)IDE"; this.documents = DocumentFactory.get_instance (); this.projects = ProjectFactory.get_instance (); this.setup_ui_manager (); this.populate_window (); try { GLib.List list; /// @todo Change URI list.append (new Gdk.Pixbuf.from_file ("./pixmaps/icone-16.xpm")); list.append (new Gdk.Pixbuf.from_file ("./pixmaps/icone-32.xpm")); list.append (new Gdk.Pixbuf.from_file ("./pixmaps/icone-48.xpm")); list.append (new Gdk.Pixbuf.from_file ("./pixmaps/icone-64.xpm")); Gtk.Window.set_default_icon_list (list); } catch (GLib.Error e) { GLib.critical (e.message); } } protected static bool on_delete_event () { Window self = Window.get_instance (); return !self.documents.close_all (); } private Window () { } protected void setup_ui_manager () { this.ui_manager = new UIManager (); ui_manager.post_activate += on_action_activated; try { /// @todo Change URI this.ui_manager.add_ui_from_file ("./data/valide-ui.xml"); } catch (GLib.Error e) { GLib.critical (e.message); } this.add_accel_group (this.ui_manager.get_accel_group ()); } protected virtual void populate_window () { var main_box = new Gtk.VBox (false, 0); this.add (main_box); main_box.pack_start (this.ui_manager.get_widget ("/menubar"), false, true, 0); main_box.pack_start (this.ui_manager.get_widget ("/toolbar"), false, true, 0); var paned = new HPaned (); main_box.pack_start (paned, true, true, 0); paned.add1 (this.projects); paned.add2 (this.documents); } /** * @todo replace with switch statement once it works with strings */ private void on_action_activated (GLib.Object o, Action action) { /* File menu */ if (action.name == "file-new") { this.documents.create (); } else if (action.name == "file-open") { this.documents.open (); } else if (action.name == "file-save") { this.documents.current.save (); } else if (action.name == "file-save-as") { this.documents.current.save_as (); } else if (action.name == "file-close") { this.documents.current.close (); } else if (action.name == "file-close-all") { this.documents.close_all (); } else if (action.name == "quit") { if (!this.on_delete_event ()) { this.destroy (); } } /* Project menu */ if (action.name == "project-new") { this.projects.create (); } else if (action.name == "project-open") { this.projects.open (); } else if (action.name == "project-save") { this.projects.current.save (); } else if (action.name == "project-save-as") { this.projects.current.save_as (); } else if (action.name == "project-close") { this.projects.current.close (); } else if (action.name == "project-close-all") { this.projects.close_all (); } /* Help menu */ else if (action.name == "help-about") { var dialog = new AboutDialog (); dialog.run (); dialog.destroy (); } } public static Window get_instance () { if (Window.instance == null) { Window.instance = new Window (); } return Window.instance; } public void run () { this.show_all (); } }