[polari] roomStack: Split out a generic MessageInfoBar



commit 14a97215043fdd28ab7aa2f712a8c34c93f18935
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Apr 19 11:11:30 2019 +0200

    roomStack: Split out a generic MessageInfoBar
    
    The save-password confirmation bar is currently the only InfoBar we
    use, but as we have designs for other bars that will follow the same
    title/subtitle structure, it makes sense to split out a generic base
    class to share the common bits.
    
    https://gitlab.gnome.org/GNOME/polari/merge_requests/115

 src/appNotifications.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/roomStack.js        | 51 ++++++++----------------------
 2 files changed, 95 insertions(+), 39 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index aca9e23..da0c5fd 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -1,5 +1,5 @@
 /* exported MessageNotification UndoNotification NotificationQueue
-            SimpleOutput GridOutput CommandOutputQueue */
+            SimpleOutput GridOutput CommandOutputQueue MessageInfoBar */
 
 const { GLib, GObject, Gtk, Pango } = imports.gi;
 
@@ -200,3 +200,84 @@ class CommandOutputQueue extends NotificationQueue {
         this.get_style_context().add_class('irc-feedback');
     }
 });
+
+var MessageInfoBar = GObject.registerClass({
+    Properties: {
+        'title': GObject.ParamSpec.string(
+            'title', 'title', 'title',
+            GObject.ParamFlags.READWRITE,
+            ''),
+        'subtitle': GObject.ParamSpec.string(
+            'subtitle', 'subtitle', 'subtitle',
+            GObject.ParamFlags.READWRITE,
+            '')
+    }
+}, class MessageInfoBar extends Gtk.InfoBar {
+    _init(params) {
+        this._title = '';
+        this._subtitle = '';
+
+        let defaultParams = {
+            show_close_button: true,
+            revealed: false,
+            valign: Gtk.Align.START
+        };
+        super._init(Object.assign(defaultParams, params));
+
+        let box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
+        this.get_content_area().add(box);
+
+        this._titleLabel = new Gtk.Label({
+            halign: Gtk.Align.START,
+            valign: Gtk.Align.CENTER,
+            label: `<b>${this._title}</b>`,
+            use_markup: true,
+            wrap: true
+        });
+        box.add(this._titleLabel);
+
+        this._subtitleLabel = new Gtk.Label({
+            halign: Gtk.Align.START,
+            valign: Gtk.Align.CENTER,
+            label: this._subtitle,
+            ellipsize: Pango.EllipsizeMode.END
+        });
+        box.add(this._subtitleLabel);
+
+        box.show_all();
+    }
+
+    get title() {
+        return this._title;
+    }
+
+    set title(title) {
+        if (this._title == title)
+            return;
+
+        this._title = title;
+        this.notify('title');
+
+        if (this._titleLabel)
+            this._titleLabel.label = `<b>${title}</b>`;
+    }
+
+    get subtitle() {
+        return this._subtitle;
+    }
+
+    set subtitle(subtitle) {
+        if (this._subtitle == subtitle)
+            return;
+
+        this._subtitle = subtitle;
+        this.notify('subtitle');
+
+        if (this._subtitleLabel)
+            this._subtitleLabel.label = subtitle;
+    }
+
+    vfunc_response() {
+        this.revealed = false;
+    }
+});
diff --git a/src/roomStack.js b/src/roomStack.js
index 84b26c1..a9b180b 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -1,10 +1,11 @@
 /* exported RoomStack */
 
-const { Gio, GLib, GObject, Gtk, Pango, TelepathyGLib: Tp } = imports.gi;
+const { Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
 
 const { AccountsMonitor } = imports.accountsMonitor;
 const { ChatView } = imports.chatView;
 const { EntryArea } = imports.entryArea;
+const { MessageInfoBar } = imports.appNotifications;
 const { RoomManager } = imports.roomManager;
 
 var RoomStack = GObject.registerClass({
@@ -90,19 +91,22 @@ var RoomStack = GObject.registerClass({
 });
 
 const SavePasswordConfirmationBar = GObject.registerClass(
-class SavePasswordConfirmationBar extends Gtk.InfoBar {
+class SavePasswordConfirmationBar extends MessageInfoBar {
     _init(room) {
         this._room = room;
 
-        super._init({
-            show_close_button: true,
-            revealed: false,
-            valign: Gtk.Align.START
-        });
+        let title = _('Should the password be saved?');
+        let subtitle = _(
+            'Identification will happen automatically the next time you connect to %s'
+        ).format(this._room.account.display_name);
+        super._init({ title, subtitle });
 
         this.connect('destroy', this._onDestroy.bind(this));
 
-        this._createWidget();
+        this.add_button(_('_Save Password'), Gtk.ResponseType.ACCEPT).set({
+            action_name: 'app.save-identify-password',
+            action_target: new GLib.Variant('o', this._room.account.object_path)
+        });
 
         this._identifySentId = this._room.connect('identify-sent', () => {
             this.revealed = true;
@@ -110,7 +114,7 @@ class SavePasswordConfirmationBar extends Gtk.InfoBar {
     }
 
     vfunc_response(response) {
-        this.revealed = false;
+        super.vfunc_response(response);
 
         if (response == Gtk.ResponseType.ACCEPT)
             return;
@@ -120,35 +124,6 @@ class SavePasswordConfirmationBar extends Gtk.InfoBar {
         app.lookup_action('discard-identify-password').activate(target);
     }
 
-    _createWidget() {
-        this.add_button(_('_Save Password'), Gtk.ResponseType.ACCEPT).set({
-            action_name: 'app.save-identify-password',
-            action_target: new GLib.Variant('o', this._room.account.object_path)
-        });
-
-        let box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
-        this.get_content_area().add(box);
-
-        let title = _('Should the password be saved?');
-        this._titleLabel = new Gtk.Label({
-            halign: Gtk.Align.START,
-            valign: Gtk.Align.CENTER,
-            wrap: true
-        });
-        this._titleLabel.set_markup(`<b>${title}<${'/'}b>`);
-        box.add(this._titleLabel);
-
-        let accountName = this._room.account.display_name;
-        let text = _('Identification will happen automatically the next time you connect to 
%s').format(accountName);
-        this._subtitleLabel = new Gtk.Label({
-            label: text,
-            ellipsize: Pango.EllipsizeMode.END
-        });
-        box.add(this._subtitleLabel);
-
-        box.show_all();
-    }
-
     _onDestroy() {
         if (this._identifySentId)
             this._room.disconnect(this._identifySentId);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]