SHOW:
|
|
- or go back to the newest paste.
| 1 | /* Title: Elementary Sequal | |
| 2 | * | |
| 3 | * | |
| 4 | * Based Upon the code-example by Tom Beckmann: https://plus.google.com/111734729718206650167/posts/jGGQrQrqxdg | |
| 5 | * Toms' Code is Based upon the design by Harvey Cabaguio: https://plus.google.com/110079731285191638950/posts/F8LZJuHxojD | |
| 6 | * | |
| 7 | */ | |
| 8 | ||
| 9 | ||
| 10 | ||
| 11 | using Gtk; | |
| 12 | using Granite; | |
| 13 | ||
| 14 | namespace eSQL {
| |
| 15 | ||
| 16 | class MainWindow : Gtk.Window {
| |
| 17 | ||
| 18 | /* APPLICATION INFORMATION */ | |
| 19 | const string program_name = ""; | |
| 20 | const string exec_name = ""; | |
| 21 | ||
| 22 | const string app_years = ""; | |
| 23 | const string app_version = ""; | |
| 24 | const string application_id = ""; | |
| 25 | const string app_icon = ""; | |
| 26 | const string app_launcher = ".desktop"; | |
| 27 | const string app_website = ""; | |
| 28 | const string app_website_lbl = ""; | |
| 29 | ||
| 30 | const string[] app_authors = {""};
| |
| 31 | const string[] app_documenters = {""};
| |
| 32 | const string[] app_translators = {"Chris Timberlake <[email protected]>"};
| |
| 33 | const string[] app_artists = {""};
| |
| 34 | ||
| 35 | const string app_license_name = "Unknown License"; | |
| 36 | - | const Gtk.License app_license = License.Unknown; |
| 36 | + | const Gtk.License app_license = License.MIT_X11; |
| 37 | ||
| 38 | const string app_comments = ""; | |
| 39 | ||
| 40 | ||
| 41 | //Define variables. | |
| 42 | Gtk.Box main_container; | |
| 43 | Gtk.Toolbar main_toolbar; | |
| 44 | Gtk.ToolItem main_title; | |
| 45 | ||
| 46 | ||
| 47 | const int icon_size = Gtk.IconSize.LARGE_TOOLBAR; | |
| 48 | const int icon_height = 48; | |
| 49 | ||
| 50 | const string main_toolbar_css = """ | |
| 51 | .title {
| |
| 52 | color: #666; | |
| 53 | text-shadow: 0px 1px 0px white; | |
| 54 | } | |
| 55 | .toolbar {
| |
| 56 | padding: 0px; | |
| 57 | box-shadow: inset 0px 1px 0px rgba(255,255,255,0.3); | |
| 58 | } | |
| 59 | """; | |
| 60 | Gtk.CssProvider css; | |
| 61 | ||
| 62 | /* CUSTOM WIDGETS */ | |
| 63 | ||
| 64 | // It's just good coding practice in any language to define everything before it's used. | |
| 65 | // Even if that specific language doesn't care. | |
| 66 | public Gtk.ToolItem toolbar_seperator() {
| |
| 67 | ||
| 68 | //Create the Seperator Referance | |
| 69 | var sep = new Gtk.ToolItem (); | |
| 70 | //Set Height/Width | |
| 71 | sep.height_request = icon_height; | |
| 72 | sep.width_request = 1; | |
| 73 | ||
| 74 | //Design the look! | |
| 75 | sep.draw.connect ((cr) => {
| |
| 76 | cr.move_to (0, 0); | |
| 77 | cr.line_to (0, 60); | |
| 78 | cr.set_line_width (1); | |
| 79 | var grad = new Cairo.Pattern.linear (0, 0, 0, icon_height); | |
| 80 | grad.add_color_stop_rgba (0, 0.3, 0.3, 0.3, 0.4); | |
| 81 | grad.add_color_stop_rgba (0.8, 0, 0, 0, 0); | |
| 82 | cr.set_source (grad); | |
| 83 | cr.stroke (); | |
| 84 | return true; | |
| 85 | }); | |
| 86 | //Add CSS Class Contexts | |
| 87 | sep.get_style_context ().add_class ("sep");
| |
| 88 | sep.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); | |
| 89 | ||
| 90 | return sep; | |
| 91 | } | |
| 92 | ||
| 93 | //Main window's title | |
| 94 | Gtk.Label mw_title; | |
| 95 | public new string title {
| |
| 96 | get {
| |
| 97 | return mw_title.label; | |
| 98 | } | |
| 99 | set {
| |
| 100 | mw_title.label = value; | |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | public MainWindow(){
| |
| 105 | ||
| 106 | /* CREATE THE BASE! */ | |
| 107 | ||
| 108 | //Build Main Toolbar | |
| 109 | main_toolbar = new Gtk.Toolbar(); | |
| 110 | //Setup the Toolbar's Look | |
| 111 | main_toolbar.icon_size = icon_size; | |
| 112 | //The CSS | |
| 113 | main_toolbar.get_style_context().add_class ("primary-toolbar");
| |
| 114 | main_toolbar.get_style_context().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); | |
| 115 | ||
| 116 | //Build the Box Container! | |
| 117 | main_container = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); | |
| 118 | main_container.pack_start (main_toolbar, false); | |
| 119 | //main_container.window-state-event.connect (() => { this.toggle_maximize(); });
| |
| 120 | ||
| 121 | /* TOOLBAR ITEMS! */ | |
| 122 | // Close Button | |
| 123 | var tb_close = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/close.svg"), "Close");
| |
| 124 | // Clicked Action | |
| 125 | tb_close.clicked.connect (() => destroy ()); | |
| 126 | // Set the proper dimension so it doesn't look ugly! | |
| 127 | tb_close.height_request = icon_height; | |
| 128 | tb_close.width_request = icon_height; | |
| 129 | ||
| 130 | // Maximize Button | |
| 131 | var tb_maximize = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/maximize.svg"), "Close");
| |
| 132 | // Clicked Action => TOGGLE MAXIMIZE! | |
| 133 | tb_maximize.clicked.connect (() => { this.toggle_maximize(); });
| |
| 134 | // Set the proper dimension so it doesn't look ugly! | |
| 135 | tb_maximize.height_request = icon_height; | |
| 136 | tb_maximize.width_request = icon_height; | |
| 137 | ||
| 138 | // Prepare the Main Window Title. | |
| 139 | mw_title = new Gtk.Label("Elementary Studio (Sequal)");
| |
| 140 | // Make it look right. | |
| 141 | mw_title.override_font(Pango.FontDescription.from_string("bold"));
| |
| 142 | // Create the ToolBar Item | |
| 143 | main_title = new Gtk.ToolItem(); | |
| 144 | // Add the Main Window Title. | |
| 145 | main_title.add(mw_title); | |
| 146 | // Expand it! | |
| 147 | main_title.set_expand(true); | |
| 148 | ||
| 149 | // Settings Menu! | |
| 150 | var settings_menu = new Gtk.Menu(); | |
| 151 | //Make a spot for an about dlg | |
| 152 | Gtk.MenuItem item_about = new Gtk.MenuItem.with_label ("About");
| |
| 153 | Gtk.MenuItem item_tf = new Gtk.MenuItem.with_label ("tf");
| |
| 154 | item_about.activate.connect (() => {
| |
| 155 | ||
| 156 | Granite.Widgets.show_about_dialog (base, | |
| 157 | "program_name", program_name, | |
| 158 | // "version", build_version, | |
| 159 | "logo_icon_name", app_icon, | |
| 160 | ||
| 161 | "comments", app_comments, | |
| 162 | "copyright", "%s %s Developers".printf (app_years, program_name), | |
| 163 | "website", app_website, | |
| 164 | "website_label", "Website", | |
| 165 | ||
| 166 | "authors", app_authors, | |
| 167 | "documenters", app_documenters, | |
| 168 | "artists", app_artists, | |
| 169 | "translator_credits", app_translators, | |
| 170 | "license", app_license_name, | |
| 171 | "license_type", app_license, | |
| 172 | ||
| 173 | "help", app_website, | |
| 174 | "translate", app_website, | |
| 175 | "bug", app_website); | |
| 176 | }); | |
| 177 | ||
| 178 | ||
| 179 | // Compile the menu! | |
| 180 | settings_menu.add(item_about); | |
| 181 | settings_menu.add(item_tf); | |
| 182 | ||
| 183 | // Settings Button! | |
| 184 | //new Granite.Widgets.ToolButtonWithMenu (new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", new Gtk.Menu ()), true
| |
| 185 | var tb_menu = new Granite.Widgets.ToolButtonWithMenu(new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", settings_menu);
| |
| 186 | ||
| 187 | // Insert the toolbar items in order! | |
| 188 | main_toolbar.insert (tb_close, -1); | |
| 189 | main_toolbar.insert (toolbar_seperator (), -1); | |
| 190 | main_toolbar.insert (main_title, -1); | |
| 191 | main_toolbar.insert (toolbar_seperator (), -1); | |
| 192 | main_toolbar.insert (tb_menu, -1); | |
| 193 | main_toolbar.insert (toolbar_seperator (), -1); | |
| 194 | main_toolbar.insert (tb_maximize, -1); | |
| 195 | ||
| 196 | ||
| 197 | /*CONTENT */ | |
| 198 | ||
| 199 | //main_container.pack_start(/*CONTENT WIDGET HERE*/, true, true, 0); | |
| 200 | ||
| 201 | ||
| 202 | ||
| 203 | //Add the Container to the Base GTK | |
| 204 | base.add(main_container); | |
| 205 | //set the default size | |
| 206 | base.set_default_size(800, 600); | |
| 207 | //Push it to the center! | |
| 208 | base.window_position = WindowPosition.CENTER; | |
| 209 | } | |
| 210 | ||
| 211 | // This is to check and see if it's maximized. If so, Minimize. | |
| 212 | void toggle_maximize(){
| |
| 213 | get_window ().maximize (); | |
| 214 | } | |
| 215 | ||
| 216 | // We need to hijack the show function of the GTK Window. | |
| 217 | public override void show(){
| |
| 218 | //Show the GTK Window | |
| 219 | base.show(); | |
| 220 | //Change the window style. Border-Only. | |
| 221 | get_window ().set_decorations (Gdk.WMDecoration.BORDER); | |
| 222 | } | |
| 223 | ||
| 224 | ||
| 225 | public override void add (Gtk.Widget widget){
| |
| 226 | main_container.pack_start(widget, true, true, 0); | |
| 227 | main_container.show_all(); | |
| 228 | } | |
| 229 | ||
| 230 | ||
| 231 | public override void remove (Gtk.Widget widget){
| |
| 232 | main_container.remove(widget); | |
| 233 | } | |
| 234 | } | |
| 235 | } | |
| 236 | ||
| 237 | ||
| 238 | //Main Loop! | |
| 239 | public static int main (string[] args){
| |
| 240 | ||
| 241 | //Init GTK! | |
| 242 | Gtk.init(ref args); | |
| 243 | ||
| 244 | //Assign window | |
| 245 | var main_window = new eSQL.MainWindow(); | |
| 246 | // When our app is closed, Cancel the process. | |
| 247 | main_window.destroy.connect (Gtk.main_quit); | |
| 248 | ||
| 249 | //Show the main window. | |
| 250 | main_window.show_all(); | |
| 251 | ||
| 252 | //GTK Main Loop. | |
| 253 | Gtk.main(); | |
| 254 | return 0; | |
| 255 | } |