2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-10-20 20:46:38 -04:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gdk = imports.gi.Gdk;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Pango = imports.gi.Pango;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
2012-03-09 20:27:19 -05:00
|
|
|
const Atk = imports.gi.Atk;
|
2010-10-20 20:46:38 -04:00
|
|
|
|
|
|
|
const Params = imports.misc.params;
|
|
|
|
|
2017-01-19 13:49:52 -05:00
|
|
|
const Dialog = imports.ui.dialog;
|
2012-08-16 15:37:27 -04:00
|
|
|
const Layout = imports.ui.layout;
|
2010-10-20 20:46:38 -04:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var OPEN_AND_CLOSE_TIME = 0.1;
|
|
|
|
var FADE_OUT_DIALOG_TIME = 1.0;
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var State = {
|
2010-10-20 20:46:38 -04:00
|
|
|
OPENED: 0,
|
|
|
|
CLOSED: 1,
|
|
|
|
OPENING: 2,
|
|
|
|
CLOSING: 3,
|
|
|
|
FADED_OUT: 4
|
|
|
|
};
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var ModalDialog = new Lang.Class({
|
2011-11-20 10:32:59 -05:00
|
|
|
Name: 'ModalDialog',
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(params) {
|
2011-08-27 23:04:56 -04:00
|
|
|
params = Params.parse(params, { shellReactive: false,
|
2012-05-24 16:47:48 -04:00
|
|
|
styleClass: null,
|
2014-12-11 09:35:40 -05:00
|
|
|
actionMode: Shell.ActionMode.SYSTEM_MODAL,
|
2013-04-06 10:53:11 -04:00
|
|
|
shouldFadeIn: true,
|
2014-05-08 18:56:23 -04:00
|
|
|
shouldFadeOut: true,
|
2013-04-06 10:53:11 -04:00
|
|
|
destroyOnClose: true });
|
2010-10-20 20:46:38 -04:00
|
|
|
|
|
|
|
this.state = State.CLOSED;
|
2011-03-18 11:28:18 -04:00
|
|
|
this._hasModal = false;
|
2014-12-11 09:35:40 -05:00
|
|
|
this._actionMode = params.actionMode;
|
2011-08-27 23:04:56 -04:00
|
|
|
this._shellReactive = params.shellReactive;
|
2012-08-22 03:27:32 -04:00
|
|
|
this._shouldFadeIn = params.shouldFadeIn;
|
2014-05-08 18:56:23 -04:00
|
|
|
this._shouldFadeOut = params.shouldFadeOut;
|
2013-04-06 10:53:11 -04:00
|
|
|
this._destroyOnClose = params.destroyOnClose;
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2012-02-14 11:33:26 -05:00
|
|
|
this._group = new St.Widget({ visible: false,
|
|
|
|
x: 0,
|
2012-03-09 20:27:19 -05:00
|
|
|
y: 0,
|
|
|
|
accessible_role: Atk.Role.DIALOG });
|
2014-03-18 09:44:44 -04:00
|
|
|
Main.layoutManager.modalDialogGroup.add_actor(this._group);
|
2011-03-16 18:57:05 -04:00
|
|
|
|
|
|
|
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
2012-02-15 11:58:56 -05:00
|
|
|
coordinate: Clutter.BindCoordinate.ALL });
|
2011-03-16 18:57:05 -04:00
|
|
|
this._group.add_constraint(constraint);
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._group.connect('destroy', this._onGroupDestroy.bind(this));
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2013-05-07 16:11:42 -04:00
|
|
|
this.backgroundStack = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
2013-03-22 19:39:05 -04:00
|
|
|
this._backgroundBin = new St.Bin({ child: this.backgroundStack,
|
|
|
|
x_fill: true, y_fill: true });
|
2012-08-16 15:37:27 -04:00
|
|
|
this._monitorConstraint = new Layout.MonitorConstraint();
|
|
|
|
this._backgroundBin.add_constraint(this._monitorConstraint);
|
2010-10-20 20:46:38 -04:00
|
|
|
this._group.add_actor(this._backgroundBin);
|
2011-03-18 11:28:18 -04:00
|
|
|
|
2017-01-19 13:49:52 -05:00
|
|
|
this.dialogLayout = new Dialog.Dialog(this.backgroundStack, params.styleClass);
|
|
|
|
this.contentLayout = this.dialogLayout.contentLayout;
|
|
|
|
this.buttonLayout = this.dialogLayout.buttonLayout;
|
2011-08-27 23:04:56 -04:00
|
|
|
|
|
|
|
if (!this._shellReactive) {
|
|
|
|
this._lightbox = new Lightbox.Lightbox(this._group,
|
2012-12-14 20:41:03 -05:00
|
|
|
{ inhibitEvents: true,
|
|
|
|
radialEffect: true });
|
2011-08-27 23:04:56 -04:00
|
|
|
this._lightbox.highlight(this._backgroundBin);
|
|
|
|
|
2013-02-22 06:23:56 -05:00
|
|
|
this._eventBlocker = new Clutter.Actor({ reactive: true });
|
2013-03-22 19:39:05 -04:00
|
|
|
this.backgroundStack.add_actor(this._eventBlocker);
|
2011-08-27 23:04:56 -04:00
|
|
|
}
|
2011-04-06 12:54:47 -04:00
|
|
|
|
2012-08-07 14:33:46 -04:00
|
|
|
global.focus_manager.add_group(this.dialogLayout);
|
2017-09-28 06:38:33 -04:00
|
|
|
this._initialKeyFocus = null;
|
2012-02-12 13:55:59 -05:00
|
|
|
this._initialKeyFocusDestroyId = 0;
|
2011-04-06 12:54:47 -04:00
|
|
|
this._savedKeyFocus = null;
|
2010-10-20 20:46:38 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2011-08-19 14:29:39 -04:00
|
|
|
this._group.destroy();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
clearButtons() {
|
2017-01-19 13:49:52 -05:00
|
|
|
this.dialogLayout.clearButtons();
|
2012-11-01 12:07:48 -04:00
|
|
|
},
|
2011-01-30 18:15:19 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setButtons(buttons) {
|
2012-11-01 12:07:48 -04:00
|
|
|
this.clearButtons();
|
2012-02-28 10:53:46 -05:00
|
|
|
|
2011-10-20 16:40:22 -04:00
|
|
|
for (let i = 0; i < buttons.length; i++) {
|
2011-09-18 20:40:21 -04:00
|
|
|
let buttonInfo = buttons[i];
|
2010-10-20 20:46:38 -04:00
|
|
|
|
|
|
|
let x_alignment;
|
|
|
|
if (buttons.length == 1)
|
|
|
|
x_alignment = St.Align.END;
|
|
|
|
else if (i == 0)
|
|
|
|
x_alignment = St.Align.START;
|
|
|
|
else if (i == buttons.length - 1)
|
|
|
|
x_alignment = St.Align.END;
|
|
|
|
else
|
|
|
|
x_alignment = St.Align.MIDDLE;
|
|
|
|
|
2015-07-29 07:45:11 -04:00
|
|
|
this.addButton(buttonInfo);
|
2012-11-01 12:07:48 -04:00
|
|
|
}
|
|
|
|
},
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addButton(buttonInfo) {
|
2017-01-19 13:49:52 -05:00
|
|
|
return this.dialogLayout.addButton(buttonInfo);
|
2010-10-20 20:46:38 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onGroupDestroy() {
|
2010-10-20 20:46:38 -04:00
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_fadeOpen(onPrimary) {
|
2012-10-14 12:34:22 -04:00
|
|
|
if (onPrimary)
|
|
|
|
this._monitorConstraint.primary = true;
|
|
|
|
else
|
|
|
|
this._monitorConstraint.index = global.screen.get_current_monitor();
|
2010-10-20 20:46:38 -04:00
|
|
|
|
|
|
|
this.state = State.OPENING;
|
|
|
|
|
2012-08-07 14:33:46 -04:00
|
|
|
this.dialogLayout.opacity = 255;
|
2011-08-27 23:04:56 -04:00
|
|
|
if (this._lightbox)
|
|
|
|
this._lightbox.show();
|
2010-10-20 20:46:38 -04:00
|
|
|
this._group.opacity = 0;
|
|
|
|
this._group.show();
|
|
|
|
Tweener.addTween(this._group,
|
|
|
|
{ opacity: 255,
|
2012-08-22 03:27:32 -04:00
|
|
|
time: this._shouldFadeIn ? OPEN_AND_CLOSE_TIME : 0,
|
2010-10-20 20:46:38 -04:00
|
|
|
transition: 'easeOutQuad',
|
2017-10-30 20:38:18 -04:00
|
|
|
onComplete: () => {
|
|
|
|
this.state = State.OPENED;
|
|
|
|
this.emit('opened');
|
|
|
|
}
|
2010-10-20 20:46:38 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setInitialKeyFocus(actor) {
|
2012-02-12 13:55:59 -05:00
|
|
|
if (this._initialKeyFocusDestroyId)
|
|
|
|
this._initialKeyFocus.disconnect(this._initialKeyFocusDestroyId);
|
|
|
|
|
2011-03-15 16:05:40 -04:00
|
|
|
this._initialKeyFocus = actor;
|
2012-02-12 13:55:59 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._initialKeyFocusDestroyId = actor.connect('destroy', () => {
|
2017-09-28 06:38:33 -04:00
|
|
|
this._initialKeyFocus = null;
|
2012-02-12 13:55:59 -05:00
|
|
|
this._initialKeyFocusDestroyId = 0;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-03-15 16:05:40 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
open(timestamp, onPrimary) {
|
2010-10-20 20:46:38 -04:00
|
|
|
if (this.state == State.OPENED || this.state == State.OPENING)
|
|
|
|
return true;
|
|
|
|
|
2014-01-21 21:39:52 -05:00
|
|
|
if (!this.pushModal(timestamp))
|
2010-10-20 20:46:38 -04:00
|
|
|
return false;
|
|
|
|
|
2012-10-14 12:34:22 -04:00
|
|
|
this._fadeOpen(onPrimary);
|
2010-10-20 20:46:38 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_closeComplete() {
|
2014-05-08 18:56:23 -04:00
|
|
|
this.state = State.CLOSED;
|
|
|
|
this._group.hide();
|
|
|
|
this.emit('closed');
|
|
|
|
|
|
|
|
if (this._destroyOnClose)
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
close(timestamp) {
|
2010-10-20 20:46:38 -04:00
|
|
|
if (this.state == State.CLOSED || this.state == State.CLOSING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.state = State.CLOSING;
|
2011-03-18 11:28:18 -04:00
|
|
|
this.popModal(timestamp);
|
2011-04-06 12:54:47 -04:00
|
|
|
this._savedKeyFocus = null;
|
2010-10-20 20:46:38 -04:00
|
|
|
|
2014-05-08 18:56:23 -04:00
|
|
|
if (this._shouldFadeOut)
|
|
|
|
Tweener.addTween(this._group,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: OPEN_AND_CLOSE_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
2017-12-01 19:27:35 -05:00
|
|
|
onComplete: this._closeComplete.bind(this)
|
2014-05-08 18:56:23 -04:00
|
|
|
})
|
|
|
|
else
|
|
|
|
this._closeComplete();
|
2010-10-20 20:46:38 -04:00
|
|
|
},
|
|
|
|
|
2011-03-18 11:28:18 -04:00
|
|
|
// Drop modal status without closing the dialog; this makes the
|
|
|
|
// dialog insensitive as well, so it needs to be followed shortly
|
|
|
|
// by either a close() or a pushModal()
|
2017-10-30 20:03:21 -04:00
|
|
|
popModal(timestamp) {
|
2011-03-18 11:28:18 -04:00
|
|
|
if (!this._hasModal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
if (focus && this._group.contains(focus))
|
|
|
|
this._savedKeyFocus = focus;
|
|
|
|
else
|
|
|
|
this._savedKeyFocus = null;
|
|
|
|
Main.popModal(this._group, timestamp);
|
2017-12-14 11:22:59 -05:00
|
|
|
Gdk.Display.get_default().sync();
|
2011-03-18 11:28:18 -04:00
|
|
|
this._hasModal = false;
|
|
|
|
|
2011-08-27 23:04:56 -04:00
|
|
|
if (!this._shellReactive)
|
|
|
|
this._eventBlocker.raise_top();
|
2011-03-18 11:28:18 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
pushModal(timestamp) {
|
2011-03-18 11:28:18 -04:00
|
|
|
if (this._hasModal)
|
|
|
|
return true;
|
2014-01-21 21:39:52 -05:00
|
|
|
|
|
|
|
let params = { actionMode: this._actionMode };
|
|
|
|
if (timestamp)
|
|
|
|
params['timestamp'] = timestamp;
|
|
|
|
if (!Main.pushModal(this._group, params))
|
2011-03-18 11:28:18 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this._hasModal = true;
|
|
|
|
if (this._savedKeyFocus) {
|
|
|
|
this._savedKeyFocus.grab_key_focus();
|
|
|
|
this._savedKeyFocus = null;
|
2013-07-03 11:26:01 -04:00
|
|
|
} else {
|
2017-09-28 06:38:33 -04:00
|
|
|
let focus = this._initialKeyFocus || this.dialogLayout.initialKeyFocus;
|
|
|
|
focus.grab_key_focus();
|
2013-07-03 11:26:01 -04:00
|
|
|
}
|
2011-03-18 11:28:18 -04:00
|
|
|
|
2011-08-27 23:04:56 -04:00
|
|
|
if (!this._shellReactive)
|
|
|
|
this._eventBlocker.lower_bottom();
|
2011-03-18 11:28:18 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-10-20 20:46:38 -04:00
|
|
|
// This method is like close, but fades the dialog out much slower,
|
|
|
|
// and leaves the lightbox in place. Once in the faded out state,
|
|
|
|
// the dialog can be brought back by an open call, or the lightbox
|
|
|
|
// can be dismissed by a close call.
|
|
|
|
//
|
|
|
|
// The main point of this method is to give some indication to the user
|
|
|
|
// that the dialog reponse has been acknowledged but will take a few
|
|
|
|
// moments before being processed.
|
|
|
|
// e.g., if a user clicked "Log Out" then the dialog should go away
|
|
|
|
// imediately, but the lightbox should remain until the logout is
|
|
|
|
// complete.
|
2017-10-30 20:03:21 -04:00
|
|
|
_fadeOutDialog(timestamp) {
|
2010-10-20 20:46:38 -04:00
|
|
|
if (this.state == State.CLOSED || this.state == State.CLOSING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this.state == State.FADED_OUT)
|
|
|
|
return;
|
|
|
|
|
2011-03-18 11:28:18 -04:00
|
|
|
this.popModal(timestamp);
|
2012-08-07 14:33:46 -04:00
|
|
|
Tweener.addTween(this.dialogLayout,
|
2010-10-20 20:46:38 -04:00
|
|
|
{ opacity: 0,
|
|
|
|
time: FADE_OUT_DIALOG_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
2017-10-30 20:38:18 -04:00
|
|
|
onComplete: () => {
|
|
|
|
this.state = State.FADED_OUT;
|
|
|
|
}
|
2010-10-20 20:46:38 -04:00
|
|
|
});
|
|
|
|
}
|
2011-11-20 10:32:59 -05:00
|
|
|
});
|
2010-10-20 20:46:38 -04:00
|
|
|
Signals.addSignalMethods(ModalDialog.prototype);
|