~elementary-apps/pantheon-terminal/new-saved-state

« back to all changes in this revision

Viewing changes to src/PantheonTerminalWindow.vala

  • Committer: Raphael Isemann
  • Date: 2014-08-25 14:27:57 UTC
  • Revision ID: teemperor@googlemail.com-20140825142757-efxtp4svnm3mggpn
Removed the SavedState functionality in this codebase and use the one from Granite

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        private bool is_fullscreen = false;
41
41
        private string[] saved_tabs;
42
42
 
 
43
        Granite.Services.SavedState new_saved_state;
 
44
 
43
45
        const string ui_string = """
44
46
            <ui>
45
47
            <popup name="MenuItemTool">
80
82
        public PantheonTerminalWindow.with_coords (PantheonTerminalApp app, int x, int y,
81
83
                                                   bool should_recreate_tabs = true) {
82
84
            move (x, y);
83
 
            init (app, should_recreate_tabs, false);
 
85
            init (app, should_recreate_tabs);
84
86
        }
85
87
 
86
88
        public PantheonTerminalWindow.with_working_directory (PantheonTerminalApp app, string location,
97
99
            new_tab (location);
98
100
        }
99
101
 
100
 
        private void init (PantheonTerminalApp app, bool recreate_tabs = true, bool restore_pos = true) {
 
102
        private void init (PantheonTerminalApp app, bool recreate_tabs = true) {
101
103
            icon_name = "utilities-terminal";
102
104
            set_application (app);
103
105
 
105
107
            set_visual (Gdk.Screen.get_default ().get_rgba_visual ());
106
108
 
107
109
            title = _("Terminal");
108
 
            restore_saved_state (restore_pos);
 
110
            restore_saved_state ();
109
111
 
110
112
            /* Actions and UIManager */
111
113
            main_actions = new Gtk.ActionGroup ("MainActionGroup");
125
127
            }
126
128
 
127
129
            Notify.init ("pantheon-terminal");
128
 
            //new Notify.Notification ("Bye Process", "p finished","utilities-terminal").show ();
129
130
 
130
131
            Gtk.AccelGroup accel_group = ui.get_accel_group ();
131
132
            add_accel_group (accel_group);
134
135
            ui.ensure_update ();
135
136
 
136
137
            setup_ui ();
 
138
            new_saved_state = new Granite.Services.SavedState (this, "org.pantheon.terminal.settings");
137
139
            show_all ();
138
140
 
 
141
            if ((get_window ().get_state () & Gdk.WindowState.FULLSCREEN) != 0)
 
142
                is_fullscreen = true;
 
143
 
139
144
            term_font = Pango.FontDescription.from_string (get_term_font ());
140
145
 
141
146
            if (recreate_tabs)
142
147
                open_tabs ();
143
148
 
144
 
            set_size_request (app.minimum_width, app.minimum_height);
145
 
 
146
149
            destroy.connect (on_destroy);
147
150
            restorable_terminals = new HashTable<string, TerminalWidget> (str_hash, str_equal);
148
151
        }
244
247
            });
245
248
        }
246
249
 
247
 
        private void restore_saved_state (bool restore_pos = true) {
 
250
        private void restore_saved_state () {
248
251
            saved_tabs = saved_state.tabs;
249
 
            default_width = PantheonTerminal.saved_state.window_width;
250
 
            default_height = PantheonTerminal.saved_state.window_height;
251
 
 
252
 
            if (restore_pos) {
253
 
                int x = saved_state.opening_x;
254
 
                int y = saved_state.opening_y;
255
 
 
256
 
                if (x != -1 && y != -1) {
257
 
                    move (x, y);
258
 
                } else {
259
 
                    x = (Gdk.Screen.width ()  - default_width)  / 2;
260
 
                    y = (Gdk.Screen.height () - default_height) / 2;
261
 
                    move (x, y);
262
 
                }
263
 
            }
264
 
 
265
 
            if (PantheonTerminal.saved_state.window_state == PantheonTerminalWindowState.MAXIMIZED) {
266
 
                maximize ();
267
 
            } else if (PantheonTerminal.saved_state.window_state == PantheonTerminalWindowState.FULLSCREEN) {
268
 
                fullscreen ();
269
 
            }
270
252
        }
271
253
 
272
254
        private void on_tab_added (Granite.Widgets.Tab tab) {
307
289
            }
308
290
 
309
291
            if (notebook.n_tabs - 1 == 0) {
310
 
                update_saved_window_state ();
311
292
                reset_saved_tabs ();
312
293
            }
313
294
 
364
345
            main_actions.get_action ("Paste").set_sensitive (can_paste);
365
346
        }
366
347
 
367
 
        private void update_saved_window_state () {
368
 
            /* Save window state */
369
 
            if ((get_window ().get_state () & Gdk.WindowState.MAXIMIZED) != 0) {
370
 
                PantheonTerminal.saved_state.window_state = PantheonTerminalWindowState.MAXIMIZED;
371
 
            } else if ((get_window ().get_state () & Gdk.WindowState.FULLSCREEN) != 0) {
372
 
                PantheonTerminal.saved_state.window_state = PantheonTerminalWindowState.FULLSCREEN;
373
 
            } else {
374
 
                PantheonTerminal.saved_state.window_state = PantheonTerminalWindowState.NORMAL;
375
 
            }
376
 
 
377
 
            /* Save window size */
378
 
            if (PantheonTerminal.saved_state.window_state == PantheonTerminalWindowState.NORMAL) {
379
 
                int width, height;
380
 
                get_size (out width, out height);
381
 
                PantheonTerminal.saved_state.window_width = width;
382
 
                PantheonTerminal.saved_state.window_height = height;
383
 
            }
384
 
 
385
 
            /* Save window position */
386
 
            int root_x, root_y;
387
 
            get_position (out root_x, out root_y);
388
 
            saved_state.opening_x = root_x;
389
 
            saved_state.opening_y = root_y;
390
 
        }
391
 
 
392
348
        private void reset_saved_tabs () {
393
349
            saved_state.tabs = {};
394
350
        }
515
471
        }
516
472
 
517
473
        protected override bool delete_event (Gdk.EventAny event) {
518
 
            update_saved_window_state ();
519
474
            action_quit ();
520
475
            string[] tabs = {};
521
476
            var tabs_to_terminate = new GLib.List <TerminalWidget> ();