好的,我来回答我自己的问题。
据我所知,在gnomeshell扩展中使用GTK对话框是不可能的。如果需要“关于对话框”,请使用modaldialog.js启动自己的对话框。
const St = imports.gi.St;
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const ModalDialog = imports.ui.modalDialog;
const Clutter = imports.gi.Clutter;
const ExtensionUtils = imports.misc.extensionUtils;
const MySelf = ExtensionUtils.getCurrentExtension();
const MyAboutDialog = new Lang.Class({
Name: 'MyAboutDialog',
Extends: ModalDialog.ModalDialog,
_init: function() {
this.parent({ styleClass: 'extension-dialog' });
this.setButtons([{ label: "OK",
action: Lang.bind(this, this._onClose),
key: Clutter.Escape
}]);
let box = new St.BoxLayout({ vertical: true});
this.contentLayout.add(box);
let gicon = new Gio.FileIcon({ file: Gio.file_new_for_path(MySelf.path + "/icons/icon.png") });
let icon = new St.Icon({ gicon: gicon });
box.add(icon);
box.add(new St.Label({ text: "AboutDialogTest Version " + MySelf.metadata.version, x_align: Clutter.ActorAlign.CENTER, style_class: "title-label" }));
box.add(new St.Label({ text: "GNOME Shell extension to display an About Dialog.", x_align: Clutter.ActorAlign.CENTER }));
box.add(new St.Label({ text: "This program comes with absolutely no warranty.", x_align: Clutter.ActorAlign.CENTER, style_class: "warn-label" }));
box.add(new St.Label({ text: "Copyright © 2017-2018 BlahBlahBlah", x_align: Clutter.ActorAlign.CENTER, style_class: "copyright-label" }));
},
_onClose: function(button, event) {
this.close(global.get_current_time());
},
});
并这样称呼它:
_showAbout2: function() {
let dialog = new MyAboutDialog();
dialog.open(global.get_current_time());
},