/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/app.js

  • Committer: Gustav Hartvigsson
  • Date: 2014-12-02 21:00:08 UTC
  • mfrom: (52.1.12 GPump_test)
  • Revision ID: gustav.hartvigsson@gmail.com-20141202210008-v9ma32lgz57i0ikb
* Made the window behave when it is shown

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * in the file lgpl-3.0.txt in the root of this project.
6
6
 */
7
7
 
8
 
const cairo = imports.gi.cairo;
 
8
 
 
9
const Gettext = imports.gettext;
9
10
const Gio = imports.gi.Gio;
10
11
const GLib = imports.gi.GLib;
11
12
const GObject = imports.gi.GObject;
12
13
const Gtk = imports.gi.Gtk;
 
14
const _ = imports.gettext.gettext;
13
15
const Lang = imports.lang;
14
 
const _ = imports.gettext.gettext;
15
 
const Gettext = imports.gettext;
16
16
 
17
17
const SettingsData = imports.settings_data;
18
18
/* const Style = imports.style; */
19
19
const PreferencesUI = imports.preferences_ui;
 
20
const UserMenu = imports.user_menu;
 
21
const UserButton = imports.user_button;
20
22
 
 
23
/** @class
 
24
 * This class is the main application class, it creates the main wiev
 
25
 * and basically is what runs the program.
 
26
 */
21
27
const Application = new Lang.Class ({
22
28
  Name: "Application",
23
29
  Extends: Gtk.Application,
43
49
    let w_list = this.get_windows ();
44
50
    if (w_list.length) {
45
51
      w_list[0].present ();
 
52
      if (!(this._is_shown ())) {
 
53
        if (!(this.settings.get_setting ("ui.x").data < 0 &&
 
54
            this.settings.get_setting ("ui.y").data < 0)){
 
55
          this.window.move (this.settings.get_setting ("ui.x").data,
 
56
                                           this.settings.get_setting ("ui.y").data);
 
57
        }
 
58
      }
46
59
      return;
47
60
    }
48
61
    
60
73
   * the headerbar to it.
61
74
   */
62
75
  _prepare_window: function () {
 
76
    
63
77
    this.window = new Gtk.ApplicationWindow ({
64
78
      application: this,
65
79
      type: Gtk.WindowType.TOPLEVEL,
66
80
      title: GLib.get_application_name (),
67
 
      default_height: this.settings.get_setting ("ui.h").data,
68
 
      default_width: this.settings.get_setting ("ui.w").data,
 
81
      default_height: 500,
 
82
      default_width: 500,
69
83
      height_request: 500,
70
84
      width_request: 500,
71
85
      window_position: Gtk.WindowPosition.CENTER
92
106
    
93
107
    print ("derp!\n");
94
108
    
95
 
    this.window.add (( this.scroll_view = new Gtk.ScrolledWindow () ));
96
 
    this.scroll_view.add ((this.list_box = new Gtk.ListBox ()));
97
 
    
 
109
    
 
110
    
 
111
    this.window.add ((this.layout = new Gtk.Box ({
 
112
      orientation: Gtk.Orientation.VERTICAL
 
113
    })));
 
114
    
 
115
    /* * Building the stack switched views */
 
116
    /* switcher */
 
117
    /* Hack to centre the damn switcher */
 
118
    this.layout.pack_start ((this.switcher_box = new Gtk.Box ({
 
119
      orientation: Gtk.Orientation.HORIZONTAL
 
120
    })), false, false, 0);
 
121
    
 
122
    this.switcher_box.set_center_widget (
 
123
      (this.stack_switcher = new Gtk.StackSwitcher ())
 
124
    );
 
125
    
 
126
    /* the stack */
 
127
    this.layout.pack_end ((this.stack = new Gtk.Stack ({
 
128
      homogeneous: true,
 
129
      transition_duration: 250,
 
130
      transition_type: Gtk.StackTransitionType.CROSSFADE
 
131
    })), true, true, 0);
 
132
    
 
133
    /* main view */
 
134
    this.stack.add_titled ((new Gtk.ScrolledWindow ({
 
135
      child: (this.main_list_box = new Gtk.ListBox()),
 
136
      margin: 1
 
137
    })), "main", _("Main"));
 
138
    
 
139
    
 
140
    /* 'mean while' view */
 
141
    this.stack.add_titled ((new Gtk.ScrolledWindow ({
 
142
      child: (this.mw_list_box = new Gtk.ListBox()),
 
143
      margin: 1
 
144
    })), "meanwhile", _("Meanwhile"));
 
145
    
 
146
    /* * Hook up the stack and the stack switcher */
 
147
    this.stack_switcher.set_stack (this.stack);
 
148
    
 
149
    /* * Hide the window so, so we can show it later */
98
150
    this.window.connect ('delete_event',
99
 
                         Lang.bind (this.window,
100
 
                                    this.window.hide_on_delete));
 
151
                         Lang.bind (this, function () {
 
152
      this._save_settings ();
 
153
      this.window.hide_on_delete ();
 
154
    }));
101
155
    
102
156
    this.add_window (this.window);
103
157
  },
140
194
    
141
195
    let quit_action = new Gio.SimpleAction ({name: "quit"});
142
196
    quit_action.connect ('activate', Lang.bind (this, function () {
143
 
      let allocation = this.window.get_allocation ();
144
 
      this.settings.set_setting ("ui.h", allocation.height);
145
 
      this.settings.set_setting ("ui.w", allocation.width);
146
 
      
147
 
      let win_pos = this.window.get_position ();
148
 
      this.settings.set_setting ("ui.x", win_pos[0]);
149
 
      this.settings.set_setting ("ui.y", win_pos[1]);
150
 
      this.settings.commit_to_file ();
 
197
      this._save_settings ();
151
198
      this.quit ();
152
199
    }));
153
200
    this.add_action (quit_action);
166
213
   * assigning callback functions to them.
167
214
   */
168
215
  _prepare_header_bar: function () {
169
 
    this.headerbar.pack_start ((this.new_post_btn = new Gtk.Button ({
 
216
    
 
217
    let button_container = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL});
 
218
    
 
219
    button_container.pack_start ((this.new_post_btn = new Gtk.Button ({
170
220
      image: (new Gtk.Image ({icon_name: 'text-editor-symbolic'})),
171
 
      tooltip_text: _("Create new post")
172
 
    })));
 
221
      tooltip_text: _("Create new post"),
 
222
    })), false, false, null);
173
223
    
174
 
    this.headerbar.pack_start ((this.refresh_btn = new Gtk.Button({
 
224
    button_container.pack_start ((this.refresh_btn = new Gtk.Button({
175
225
      image: (new Gtk.Image ({icon_name: 'emblem-synchronizing-symbolic'})),
176
 
      tooltip_text: _("Refresh the stream")
177
 
    })));
178
 
    
179
 
    this.headerbar.pack_end ((this.user_menu_btn = new Gtk.Button ({
180
 
      image: (new Gtk.Image ({icon_name: 'emblem-system-symbolic'})),
181
 
      tooltip_text: _("Switch and manage users")
182
 
    })));
 
226
      tooltip_text: _("Refresh the stream"),
 
227
    })), false, false, null);
 
228
    
 
229
    let special_btn_container_style_ctx = button_container.get_style_context ();
 
230
    special_btn_container_style_ctx.add_class ("linked");
 
231
    
 
232
    this.headerbar.pack_start (button_container);
 
233
    
 
234
    this.headerbar.pack_end ((this.user_menu_btn = new UserButton.UserButton ({
 
235
      image: (new Gtk.Image ({icon_name: 'mail-send-symbolic'})),
 
236
      tooltip_text: _("Switch and manage users"),
 
237
      popover: (this.user_menu = new UserMenu.UserMenu ()),
 
238
    })));
 
239
    
 
240
  },
 
241
  
 
242
  _save_settings: function () {
 
243
    let allocation = this.window.get_allocation ();
 
244
    this.settings.set_setting ("ui.h", allocation.height);
 
245
    this.settings.set_setting ("ui.w", allocation.width);
 
246
    
 
247
    let win_pos = this.window.get_position ();
 
248
    this.settings.set_setting ("ui.x", win_pos[0]);
 
249
    this.settings.set_setting ("ui.y", win_pos[1]);
 
250
    this.settings.commit_to_file ();
 
251
  },
 
252
  
 
253
  _is_shown: function () {
 
254
    let win_pos = this.window.get_position ();
 
255
    if (win_pos[0] == undefined || win_pos[1] == undefined) {
 
256
      return false;
 
257
    } else {
 
258
      return true;
 
259
    }
183
260
  }
184
261
  
185
262
});