Commit 6650c307 authored by Mattias Bengtsson's avatar Mattias Bengtsson Committed by Jonas Danielsson

MainWindow: Use Templates

Since we need to inherit from a GObject to be templated this patch also
makes MainWindow extend Gtk.ApplicationWindow.

https://bugzilla.gnome.org/show_bug.cgi?id=740647
parent 16da0c7d
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkApplicationWindow" id="app-window">
<template class="Gjs_MainWindow" parent="GtkApplicationWindow">
<property name="width-request">600</property>
<property name="height-request">500</property>
<property name="window-position">center</property>
<property name="title" translatable="yes">Maps</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header-bar">
<object class="GtkHeaderBar" id="headerBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="show-close-button">True</property>
......@@ -15,7 +15,7 @@
<class name="titlebar"/>
</style>
<child>
<object class="GtkButton" id="goto-user-location-button">
<object class="GtkButton" id="gotoUserLocationButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
......@@ -37,7 +37,7 @@
</packing>
</child>
<child>
<object class="GtkMenuButton" id="layers-button">
<object class="GtkMenuButton" id="layersButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
......@@ -55,7 +55,7 @@
</object>
</child>
<child>
<object class="GtkToggleButton" id="toggle-sidebar-button">
<object class="GtkToggleButton" id="toggleSidebarButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
......@@ -77,7 +77,7 @@
</packing>
</child>
<child>
<object class="GtkMenuButton" id="favorites-button">
<object class="GtkMenuButton" id="favoritesButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
......@@ -104,7 +104,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkStack" id="main-stack">
<object class="GtkStack" id="mainStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition-type">crossfade</property>
......@@ -115,7 +115,7 @@
</object>
</child>
<child>
<object class="GtkGrid" id="no-network-view">
<object class="GtkGrid" id="noNetworkView">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
......@@ -168,5 +168,5 @@
</child>
</object>
</child>
</object>
</template>
</interface>
......@@ -108,7 +108,7 @@ const Application = new Lang.Class({
_onShowContactActivate: function(action, parameter) {
this._createWindow();
this._checkNetwork();
this._mainWindow.window.present();
this._mainWindow.present();
let id = parameter.deep_unpack();
......@@ -123,7 +123,7 @@ const Application = new Lang.Class({
},
_onQuitActivate: function() {
this._mainWindow.window.destroy();
this._mainWindow.destroy();
},
_addContacts: function() {
......@@ -213,7 +213,7 @@ const Application = new Lang.Class({
let overlay = new Gtk.Overlay({ visible: true, can_focus: false });
notificationManager = new NotificationManager.NotificationManager(overlay);
this._mainWindow = new MainWindow.MainWindow(this, overlay);
this._mainWindow.window.connect('destroy', this._onWindowDestroy.bind(this));
this._mainWindow.connect('destroy', this._onWindowDestroy.bind(this));
},
vfunc_dbus_register: function(connection, path) {
......@@ -228,7 +228,7 @@ const Application = new Lang.Class({
vfunc_activate: function() {
this._createWindow();
this._checkNetwork();
this._mainWindow.window.present();
this._mainWindow.present();
},
_onWindowDestroy: function(window) {
......
......@@ -47,20 +47,23 @@ const _WINDOW_MIN_HEIGHT = 500;
const MainWindow = new Lang.Class({
Name: 'MainWindow',
Extends: Gtk.ApplicationWindow,
Template: 'resource:///org/gnome/Maps/ui/main-window.ui',
InternalChildren: [ 'headerBar',
'grid',
'mainStack',
'noNetworkView',
'gotoUserLocationButton',
'toggleSidebarButton',
'layersButton',
'favoritesButton' ],
_init: function(app, overlay) {
this.parent();
this._configureId = 0;
let ui = Utils.getUIObject('main-window', [ 'app-window',
'header-bar',
'grid',
'main-stack',
'no-network-view',
'goto-user-location-button',
'toggle-sidebar-button',
'layers-button',
'favorites-button' ]);
this.window = ui.appWindow;
this.window.application = app;
this.application = app;
this._overlay = overlay;
this.mapView = new MapView.MapView();
......@@ -72,18 +75,11 @@ const MainWindow = new Lang.Class({
this._contextMenu = new ContextMenu.ContextMenu(this.mapView);
ui.layersButton.popover = new LayersPopover.LayersPopover();
ui.favoritesButton.popover = new FavoritesPopover.FavoritesPopover({ mapView: this.mapView });
this._layersButton.popover = new LayersPopover.LayersPopover();
this._favoritesButton.popover = new FavoritesPopover.FavoritesPopover({ mapView: this.mapView });
this._overlay.add_overlay(new ZoomControl.ZoomControl(this.mapView));
this._mainStack = ui.mainStack;
this._mainStack.add(this._overlay);
this._noNetworkView = ui.noNetworkView;
this._headerBar = ui.headerBar;
this._gotoUserLocationButton = ui.gotoUserLocationButton;
this._toggleSidebarButton = ui.toggleSidebarButton;
this._layersButton = ui.layersButton;
this._favoritesButton = ui.favoritesButton;
this._busy = new BusyMarker.BusyMarker();
this._overlay.add_overlay(this._busy);
......@@ -94,9 +90,9 @@ const MainWindow = new Lang.Class({
this._busySignalId = 0;
ui.grid.attach(this._sidebar, 1, 0, 1, 1);
this._grid.attach(this._sidebar, 1, 0, 1, 1);
ui.grid.show_all();
this._grid.show_all();
},
_createPlaceEntry: function() {
......@@ -128,16 +124,16 @@ const MainWindow = new Lang.Class({
sidebar.bind_property('reveal-child',
this.mapView, 'routeVisible',
GObject.BindingFlags.BIDIRECTIONAL);
this.window.application.bind_property('connected',
sidebar, 'visible',
GObject.BindingFlags.DEFAULT);
this.application.bind_property('connected',
sidebar, 'visible',
GObject.BindingFlags.DEFAULT);
return sidebar;
},
_initActions: function() {
Utils.addActions(this.window, {
Utils.addActions(this, {
'close': {
onActivate: this.window.close.bind(this.window)
onActivate: this.close.bind(this)
},
'about': {
onActivate: this._onAboutActivate.bind(this)
......@@ -175,11 +171,11 @@ const MainWindow = new Lang.Class({
},
_initSignals: function() {
this.window.connect('delete-event', this._quit.bind(this));
this.window.connect('configure-event',
this._onConfigureEvent.bind(this));
this.window.connect('window-state-event',
this._onWindowStateEvent.bind(this));
this.connect('delete-event', this._quit.bind(this));
this.connect('configure-event',
this._onConfigureEvent.bind(this));
this.connect('window-state-event',
this._onWindowStateEvent.bind(this));
this.mapView.view.connect('button-press-event', (function() {
// Can not call something that will generate clutter events
// from a clutter event-handler. So use an idle.
......@@ -188,8 +184,8 @@ const MainWindow = new Lang.Class({
}).bind(this));
}).bind(this));
this.window.application.connect('notify::connected', (function() {
if(this.window.application.connected)
this.application.connect('notify::connected', (function() {
if (this.application.connected)
this._mainStack.visible_child = this._overlay;
else
this._mainStack.visible_child = this._noNetworkView;
......@@ -198,7 +194,7 @@ const MainWindow = new Lang.Class({
_updateLocationSensitivity: function() {
let sensitive = (Application.geoclue.state !== Geoclue.State.INITIAL &&
this.window.application.connected);
this.application.connected);
this._gotoUserLocationButton.sensitive = sensitive;
},
......@@ -216,8 +212,8 @@ const MainWindow = new Lang.Class({
Application.geoclue.connect('notify::state',
this._updateLocationSensitivity.bind(this));
this.window.application.connect('notify::connected', (function() {
let app = this.window.application;
this.application.connect('notify::connected', (function() {
let app = this.application;
this._updateLocationSensitivity();
this._layersButton.sensitive = app.connected;
......@@ -229,17 +225,17 @@ const MainWindow = new Lang.Class({
},
_saveWindowGeometry: function() {
let window = this.window.get_window();
let window = this.get_window();
let state = window.get_state();
if (state & Gdk.WindowState.MAXIMIZED)
return;
// GLib.Variant.new() can handle arrays just fine
let size = this.window.get_size();
let size = this.get_size();
Application.settings.set('window-size', size);
let position = this.window.get_position();
let position = this.get_position();
Application.settings.set('window-position', position);
},
......@@ -247,18 +243,18 @@ const MainWindow = new Lang.Class({
let size = Application.settings.get('window-size');
if (size.length === 2) {
let [width, height] = size;
this.window.set_default_size(width, height);
this.set_default_size(width, height);
}
let position = Application.settings.get('window-position');
if (position.length === 2) {
let [x, y] = position;
this.window.move(x, y);
this.move(x, y);
}
if (Application.settings.get('window-maximized'))
this.window.maximize();
this.maximize();
},
_onConfigureEvent: function(widget, event) {
......@@ -350,7 +346,7 @@ const MainWindow = new Lang.Class({
},
_setRevealSidebar: function(value) {
let action = this.window.lookup_action('toggle-sidebar');
let action = this.lookup_action('toggle-sidebar');
action.change_state(GLib.Variant.new_boolean(value));
},
......@@ -375,7 +371,7 @@ const MainWindow = new Lang.Class({
wrap_license: true,
modal: true,
transient_for: this.window
transient_for: this
});
aboutDialog.show();
aboutDialog.connect('response',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment