Move Popover button creation to buttons.js

This commit is contained in:
Rafostar
2020-09-12 21:10:44 +02:00
parent 71c5454547
commit 043fe9f75e
3 changed files with 95 additions and 51 deletions

View File

@@ -3,15 +3,30 @@ const { GObject, Gtk } = imports.gi;
var BoxedIconButton = GObject.registerClass(
class BoxedIconButton extends Gtk.Button
{
_init(icon, size)
_init(icon, size, isFullscreen)
{
super._init();
super._init({
margin_top: 4,
margin_bottom: 4,
can_focus: false,
can_default: false,
});
this.isFullscreen = isFullscreen || false;
size = size || Gtk.IconSize.SMALL_TOOLBAR;
let image = Gtk.Image.new_from_icon_name(icon, size);
if(image)
this.set_image(image);
this.image.defaultSize = size;
this.image.fullscreenSize = (size === Gtk.IconSize.SMALL_TOOLBAR)
? Gtk.IconSize.LARGE_TOOLBAR
: Gtk.IconSize.DND;
this.get_style_context().add_class('flat');
this.box = new Gtk.Box();
this.box.pack_start(this, false, false, 0);
@@ -23,6 +38,18 @@ class BoxedIconButton extends Gtk.Button
return this.box.visible;
}
setFullscreenMode(isFullscreen)
{
if(this.isFullscreen === isFullscreen)
return;
this.image.icon_size = (isFullscreen)
? this.image.fullscreenSize
: this.image.defaultSize;
this.isFullscreen = isFullscreen;
}
show_all()
{
this.box.show_all();
@@ -38,3 +65,40 @@ class BoxedIconButton extends Gtk.Button
this.box.hide();
}
});
var BoxedPopoverButton = GObject.registerClass(
class BoxedPopoverButton extends BoxedIconButton
{
_init(icon, size, isFullscreen)
{
super._init(icon, size, isFullscreen);
this.popover = new Gtk.Popover({
relative_to: this.box
});
this.popoverBox = new Gtk.VBox();
this.popover.add(this.popoverBox);
this.popoverBox.show();
this.connect(
'clicked', this._onPopoverButtonClicked.bind(this)
);
if(this.isFullscreen)
this.popover.get_style_context().add_class('osd');
}
setFullscreenMode(isEnabled)
{
if(this.isFullscreen === isEnabled)
return;
let action = (isEnabled) ? 'add_class' : 'remove_class';
this.popover.get_style_context()[action]('osd');
super.setFullscreenMode(isEnabled);
}
_onPopoverButtonClicked()
{
this.popover.popup();
}
});