~versable/estudio/estudio

« back to all changes in this revision

Viewing changes to src/UI/WelcomeScreen.vala

  • Committer: Chris Timberlake
  • Date: 2013-09-13 08:15:44 UTC
  • Revision ID: git-v1:a81e8a287bd7e509bb70f1845e2d7dd56a57a660
Moved Repo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *    Copyright (c) 2013 Christopher Timberlake 
3
 
 *    <Chris@TimberlakeTechnologies.com> -or- <www.ChristopherTimberlake.com>
4
 
 *
5
 
 *    Permission is hereby granted, free of charge, to any person obtaining a copy
6
 
 *    of this software and associated documentation files (the "Software"), to deal
7
 
 *    in the Software without restriction, including without limitation the rights
8
 
 *    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 
 *    copies of the Software, and to permit persons to whom the Software is
10
 
 *    furnished to do so, subject to the following conditions:
11
 
 
12
 
 *    The above copyright notice and this permission notice shall be included in
13
 
 *    all copies or substantial portions of the Software.
14
 
 
15
 
 *    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 
 *    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 
 *    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 
 *    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 
 *    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 
 *    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 
 *    THE SOFTWARE.
22
 
 */
23
 
 
24
 
using Gtk;
25
 
namespace eStudio {
26
 
    class WelcomeScreen : Gtk.Box {
27
 
 
28
 
        private static const string TEXT = "Hello World!";
29
 
        public MainWindow main_window;
30
 
 
31
 
        public Granite.Widgets.WidgetWelcome lbl;
32
 
 
33
 
        construct {
34
 
 
35
 
        }
36
 
 
37
 
        enum Recent {
38
 
                    Name,
39
 
                    Type,
40
 
                    Path
41
 
            }
42
 
 
43
 
        public WelcomeScreen(MainWindow window){
44
 
 
45
 
            main_window = window;
46
 
            //Build the welcome screen!
47
 
            lbl = new Granite.Widgets.WidgetWelcome("eStudio (Baseline)", "Beating the code into you.. One line at a time!");
48
 
 
49
 
            lbl.append("document-new", "Create A Project", "A Whole New Project!");
50
 
            lbl.append("document-open", "Open A Project", "Finish Some Old Work!");
51
 
            
52
 
            //Lets connect the welcome menu to a function!
53
 
            lbl.activated.connect (on_activated);     
54
 
 
55
 
            var view_contents = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3);
56
 
 
57
 
            var view = new TreeView ();
58
 
            var listmodel = new ListStore (4, typeof (string), typeof (string),
59
 
                                              typeof (string), typeof (string));
60
 
            
61
 
            
62
 
            //view.insert_column_with_attributes (0, "Icon", new CellRendererText (), "text", 0);
63
 
            view.insert_column_with_attributes (0, "Name", new CellRendererText (), "text", Recent.Name);
64
 
            view.insert_column_with_attributes (1, "Type", new CellRendererText (), "text", Recent.Type);
65
 
            view.insert_column_with_attributes (2, "Directory", new CellRendererText (), "text", Recent.Path);
66
 
 
67
 
            TreeIter iter;
68
 
            for (var i=0;i<FileManager.rp_name.length; i++) {
69
 
                        listmodel.append (out iter);
70
 
                listmodel.set (iter, 0, FileManager.rp_name[i], 1, FileManager.rp_type[i], 2, FileManager.rp_path[i]); 
71
 
            }
72
 
            
73
 
 
74
 
            view.set_model (listmodel);
75
 
            view.headers_visible = false;
76
 
            view.set_size_request(550, 150);
77
 
            
78
 
            var selection = view.get_selection ();
79
 
                    selection.changed.connect (this.on_changed);
80
 
           
81
 
            view_contents.pack_start(new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0);
82
 
            view_contents.pack_start(view, false, false, 0);
83
 
            view_contents.pack_start(new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0);
84
 
 
85
 
            lbl.set_content(view_contents);
86
 
 
87
 
            base.pack_start(lbl);
88
 
            
89
 
            //return lbl;
90
 
        }
91
 
        public void on_changed (Gtk.TreeSelection selection){
92
 
            Gtk.TreeModel model;
93
 
            Gtk.TreeIter iter;
94
 
            string path;
95
 
            
96
 
            if (selection.get_selected (out model, out iter)) {
97
 
                model.get (iter, Recent.Path, out path);
98
 
                FileManager.OpenProject(path, this.main_window);
99
 
            }
100
 
        }
101
 
        private void on_activated(int index) {
102
 
 
103
 
            switch (index) {
104
 
                case 0: // New Project
105
 
                    var newproj = new CreateProject_Dialog(main_window);
106
 
                    newproj.show_all();
107
 
                    newproj.window_position = Gtk.WindowPosition.CENTER;
108
 
                break;
109
 
 
110
 
                case 1: // Existing Project
111
 
                    var file_chooser = new FileChooserDialog ("Open Project", main_window,
112
 
                                            FileChooserAction.SELECT_FOLDER,
113
 
                                            Stock.CANCEL, ResponseType.CANCEL,
114
 
                                            Stock.OPEN, ResponseType.ACCEPT);
115
 
                    if (file_chooser.run () == ResponseType.ACCEPT) {
116
 
                        FileManager.OpenProject(file_chooser.get_filename (), main_window);
117
 
                    }
118
 
                    file_chooser.destroy ();
119
 
                break;
120
 
            }
121
 
        }
122
 
    }
123
 
}