bzr branch
http://gegoxaren.bato24.eu/bzr/gpump/trunk
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
1 |
/* This file is part of GPump, a Pump.io client.
|
2 |
*
|
|
3 |
* GPump (THE SOFTWARE) is made available under the terms and conditions of the
|
|
4 |
* GNU Lesser General Public Licence 3.0. A copy of the licence can be read
|
|
5 |
* in the file lgpl-3.0.txt in the root of this project.
|
|
6 |
*/
|
|
7 |
||
8 |
const Gio = imports.gi.Gio; |
|
9 |
const GLib = imports.gi.GLib; |
|
10 |
const Gtk = imports.gi.Gtk; |
|
11 |
const Lang = imports.lang; |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
12 |
const _ = imports.gettext.gettext; |
13 |
||
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
14 |
|
15 |
const SettingsData = imports.settings_data; |
|
16 |
||
17 |
const Application = new Lang.Class ({ |
|
18 |
Name: "Application", |
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
19 |
Extends: Gtk.Application, |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
20 |
|
21 |
_init: function () { |
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
22 |
this.parent ({ |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
23 |
application_id: "org.gego.gpump", |
24 |
flags: Gio.ApplicationFlags.FLAGS_NONE, |
|
25 |
register_session: true |
|
26 |
}); |
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
27 |
GLib.set_application_name (_("GPump")); |
|
37
by Gustav Hartvigsson
* finnihed the construction of the settings file. |
28 |
|
29 |
this.settings = SettingsData.get_settings (); |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
30 |
}, |
31 |
|
|
|
36
by Gustav Hartvigsson
* changed from this.connect(...) to vfunc_ . |
32 |
vfunc_activate: function () { |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
33 |
/* Guarantee that only one window is present at any time. */ |
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
34 |
let w_list = this.get_windows (); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
35 |
if (w_list.length) { |
36 |
w_list[0].present (); |
|
37 |
return; |
|
38 |
} |
|
39 |
|
|
40 |
this._prepareWindow (); |
|
41 |
this._prepareAppMenu (); |
|
42 |
this._prepareHeaderBar (); |
|
43 |
|
|
44 |
this.window.show_all (); |
|
45 |
}, |
|
46 |
|
|
47 |
/** |
|
48 |
* This function is used to prepare the window, it also initializes and adds
|
|
49 |
* the headerbar to it.
|
|
50 |
*/
|
|
51 |
_prepareWindow: function () { |
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
52 |
this.window = new Gtk.ApplicationWindow ({ |
53 |
application: this, |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
54 |
type: Gtk.WindowType.TOPLEVEL, |
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
55 |
title: GLib.get_application_name (), |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
56 |
default_height: 500, |
57 |
default_width: 500, |
|
58 |
height_request: 500, |
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
59 |
width_request: 500, |
60 |
window_position: Gtk.WindowPosition.CENTER |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
61 |
}); |
62 |
|
|
63 |
this.window.set_titlebar ((this.headerbar = new Gtk.HeaderBar({ |
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
64 |
title: GLib.get_application_name (), |
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
65 |
subtitle: _('A Pump.io client'), |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
66 |
show_close_button: true |
67 |
}))); |
|
68 |
|
|
|
38
by Gustav Hartvigsson
* Can now load settings from file. |
69 |
print ("derp!\n"); |
70 |
|
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
71 |
this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () )); |
72 |
this.scroll_view.add ((this.list_box = new Gtk.ListBox ())); |
|
73 |
|
|
74 |
this.window.connect ('delete_event', |
|
75 |
Lang.bind (this.window, |
|
76 |
this.window.hide_on_delete)); |
|
77 |
|
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
78 |
this.add_window (this.window); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
79 |
}, |
80 |
|
|
81 |
/** |
|
82 |
* This function is used to create the application menu.
|
|
83 |
*/
|
|
84 |
_prepareAppMenu: function () { |
|
85 |
let menu = new Gio.Menu (); |
|
86 |
let section = new Gio.Menu (); |
|
87 |
|
|
88 |
section.append ("Preferences", "app.preferences"); |
|
89 |
menu.append_section (null, section); |
|
90 |
|
|
91 |
section = new Gio.Menu (); |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
92 |
section.append (_("About"), "app.about"); |
93 |
section.append (_("Quit"), "app.quit"); |
|
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
94 |
menu.append_section (null, section); |
95 |
|
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
96 |
this.set_app_menu (menu); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
97 |
|
98 |
let quit_action = new Gio.SimpleAction ({name: "quit"}); |
|
99 |
quit_action.connect ('activate', Lang.bind (this, function () { |
|
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
100 |
this.quit (); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
101 |
})); |
|
35
by Gustav Hartvigsson
* Changed to extending Gtk.Application instead.... |
102 |
this.add_action (quit_action); |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
103 |
|
104 |
}, |
|
105 |
|
|
106 |
/** |
|
107 |
* This function is used to prepare the hearderbar by adding buttons and
|
|
108 |
* assigning callback functions to them.
|
|
109 |
*/
|
|
110 |
_prepareHeaderBar: function () { |
|
111 |
this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({ |
|
112 |
image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
113 |
tooltip_text: _('Create new post') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
114 |
}))); |
115 |
|
|
116 |
this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({ |
|
117 |
image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
118 |
tooltip_text: _('Refresh the stream') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
119 |
}))); |
120 |
|
|
121 |
this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({ |
|
122 |
image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})), |
|
|
34
by Gustav Hartvigsson
* added GetText stuffs... |
123 |
tooltip_text: _('Switch and manage users') |
|
33
by Gustav Hartvigsson
* Main window no on par with the C version |
124 |
}))); |
125 |
} |
|
126 |
|
|
127 |
});
|