From 083445a830cef0a7385230c1ce171481dd75486f Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:22:35 +0100 Subject: [PATCH] Split header bar source file into two This allows creating another headerbar with different functionality from the same source code. --- clapper_src/headerbar.js | 108 ++--------------------------- clapper_src/headerbarBase.js | 129 +++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 103 deletions(-) create mode 100644 clapper_src/headerbarBase.js diff --git a/clapper_src/headerbar.js b/clapper_src/headerbar.js index 9060b80b..c300b9ba 100644 --- a/clapper_src/headerbar.js +++ b/clapper_src/headerbar.js @@ -1,94 +1,17 @@ -const { GObject, Gtk, Pango } = imports.gi; +const { GObject } = imports.gi; +const { HeaderBarBase } = imports.clapper_src.headerbarBase; var HeaderBar = GObject.registerClass( -class ClapperHeaderBar extends Gtk.HeaderBar +class ClapperHeaderBar extends HeaderBarBase { - _init(window, models) + _init(window) { - super._init({ - can_focus: false, - }); - this.add_css_class('noborder'); + super._init(window); - this.set_title_widget(this._createWidgetForWindow(window)); let clapperWidget = window.get_child(); - - let addMediaButton = new Gtk.MenuButton({ - icon_name: 'list-add-symbolic', - }); - let addMediaPopover = new HeaderBarPopover(models.addMediaMenu); - addMediaButton.set_popover(addMediaPopover); - this.pack_start(addMediaButton); - - let openMenuButton = new Gtk.MenuButton({ - icon_name: 'open-menu-symbolic', - }); - let settingsPopover = new HeaderBarPopover(models.settingsMenu); - openMenuButton.set_popover(settingsPopover); - this.pack_end(openMenuButton); - - let buttonsBox = new Gtk.Box({ - orientation: Gtk.Orientation.HORIZONTAL, - }); - buttonsBox.add_css_class('linked'); - - let floatButton = new Gtk.Button({ - icon_name: 'preferences-desktop-remote-desktop-symbolic', - }); - floatButton.connect('clicked', this._onFloatButtonClicked.bind(this)); clapperWidget.controls.unfloatButton.bind_property('visible', this, 'visible', GObject.BindingFlags.INVERT_BOOLEAN ); - buttonsBox.append(floatButton); - - let fullscreenButton = new Gtk.Button({ - icon_name: 'view-fullscreen-symbolic', - }); - fullscreenButton.connect('clicked', this._onFullscreenButtonClicked.bind(this)); - - buttonsBox.append(fullscreenButton); - this.pack_end(buttonsBox); - } - - updateHeaderBar(title, subtitle) - { - this.titleLabel.label = title; - this.subtitleLabel.visible = (subtitle !== null); - - if(subtitle) - this.subtitleLabel.label = subtitle; - } - - _createWidgetForWindow(window) - { - let box = new Gtk.Box ({ - orientation: Gtk.Orientation.VERTICAL, - valign: Gtk.Align.CENTER, - }); - - this.titleLabel = new Gtk.Label({ - halign: Gtk.Align.CENTER, - single_line_mode: true, - ellipsize: Pango.EllipsizeMode.END, - width_chars: 5, - }); - this.titleLabel.add_css_class('title'); - this.titleLabel.set_parent(box); - - window.bind_property('title', this.titleLabel, 'label', - GObject.BindingFlags.SYNC_CREATE - ); - - this.subtitleLabel = new Gtk.Label({ - halign: Gtk.Align.CENTER, - single_line_mode: true, - ellipsize: Pango.EllipsizeMode.END, - }); - this.subtitleLabel.add_css_class('subtitle'); - this.subtitleLabel.set_parent(box); - this.subtitleLabel.visible = false; - - return box; } _onFloatButtonClicked() @@ -103,24 +26,3 @@ class ClapperHeaderBar extends Gtk.HeaderBar window.fullscreen(); } }); - -var HeaderBarPopover = GObject.registerClass( -class ClapperHeaderBarPopover extends Gtk.PopoverMenu -{ - _init(model) - { - super._init({ - menu_model: model, - }); - - this.connect('closed', this._onClosed.bind(this)); - } - - _onClosed() - { - let root = this.get_root(); - let clapperWidget = root.get_child(); - - clapperWidget.player.widget.grab_focus(); - } -}); diff --git a/clapper_src/headerbarBase.js b/clapper_src/headerbarBase.js new file mode 100644 index 00000000..09d32b40 --- /dev/null +++ b/clapper_src/headerbarBase.js @@ -0,0 +1,129 @@ +const { GObject, Gtk, Pango } = imports.gi; +const Misc = imports.clapper_src.misc; + +var HeaderBarBase = GObject.registerClass( +class ClapperHeaderBarBase extends Gtk.HeaderBar +{ + _init(window) + { + super._init({ + can_focus: false, + }); + + let clapperPath = Misc.getClapperPath(); + let uiBuilder = Gtk.Builder.new_from_file( + `${clapperPath}/ui/clapper.ui` + ); + let models = { + addMediaMenu: uiBuilder.get_object('addMediaMenu'), + settingsMenu: uiBuilder.get_object('settingsMenu'), + }; + + this.add_css_class('noborder'); + this.set_title_widget(this._createWidgetForWindow(window)); + + let addMediaButton = new Gtk.MenuButton({ + icon_name: 'list-add-symbolic', + }); + let addMediaPopover = new HeaderBarPopover(models.addMediaMenu); + addMediaButton.set_popover(addMediaPopover); + this.pack_start(addMediaButton); + + let openMenuButton = new Gtk.MenuButton({ + icon_name: 'open-menu-symbolic', + }); + let settingsPopover = new HeaderBarPopover(models.settingsMenu); + openMenuButton.set_popover(settingsPopover); + this.pack_end(openMenuButton); + + let buttonsBox = new Gtk.Box({ + orientation: Gtk.Orientation.HORIZONTAL, + }); + buttonsBox.add_css_class('linked'); + + let floatButton = new Gtk.Button({ + icon_name: 'preferences-desktop-remote-desktop-symbolic', + }); + floatButton.connect('clicked', this._onFloatButtonClicked.bind(this)); + buttonsBox.append(floatButton); + + let fullscreenButton = new Gtk.Button({ + icon_name: 'view-fullscreen-symbolic', + }); + fullscreenButton.connect('clicked', this._onFullscreenButtonClicked.bind(this)); + + buttonsBox.append(fullscreenButton); + this.pack_end(buttonsBox); + } + + updateHeaderBar(title, subtitle) + { + this.titleLabel.label = title; + this.subtitleLabel.visible = (subtitle !== null); + + if(subtitle) + this.subtitleLabel.label = subtitle; + } + + _createWidgetForWindow(window) + { + let box = new Gtk.Box({ + orientation: Gtk.Orientation.VERTICAL, + valign: Gtk.Align.CENTER, + }); + + this.titleLabel = new Gtk.Label({ + halign: Gtk.Align.CENTER, + single_line_mode: true, + ellipsize: Pango.EllipsizeMode.END, + width_chars: 5, + }); + this.titleLabel.add_css_class('title'); + this.titleLabel.set_parent(box); + + window.bind_property('title', this.titleLabel, 'label', + GObject.BindingFlags.SYNC_CREATE + ); + + this.subtitleLabel = new Gtk.Label({ + halign: Gtk.Align.CENTER, + single_line_mode: true, + ellipsize: Pango.EllipsizeMode.END, + }); + this.subtitleLabel.add_css_class('subtitle'); + this.subtitleLabel.set_parent(box); + this.subtitleLabel.visible = false; + + return box; + } + + _onFloatButtonClicked() + { + } + + _onFullscreenButtonClicked() + { + } +}); + +var HeaderBarPopover = GObject.registerClass( +class ClapperHeaderBarPopover extends Gtk.PopoverMenu +{ + _init(model) + { + super._init({ + menu_model: model, + }); + + this.connect('closed', this._onClosed.bind(this)); + } + + _onClosed() + { + let root = this.get_root(); + let clapperWidget = root.get_child(); + + if(clapperWidget && clapperWidget.player) + clapperWidget.player.widget.grab_focus(); + } +});