From 98adfc2c3ebefa874f3fe95da0d2124f1d690b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 30 Jan 2023 00:23:16 +0100 Subject: [PATCH] Add kind to info bar message to keep notification message longer The notification message should not be cleared when the record is changed but only when a new notification is computed. Closes #12050 --- sao/src/screen.js | 4 ++-- sao/src/window.js | 19 +++++++++++++++---- tryton/tryton/gui/window/infobar.py | 13 +++++++++---- .../gui/window/view_form/screen/screen.py | 4 ++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/sao/src/screen.js b/sao/src/screen.js index aaca6d4c18..5b5a7b2977 100644 --- a/sao/src/screen.js +++ b/sao/src/screen.js @@ -1237,11 +1237,11 @@ record_notify: function(notifications) { for (const window_ of this.windows) { if (window_.info_bar) { - window_.info_bar.refresh(); + window_.info_bar.refresh('notification'); for (const notification of notifications) { const type = notification[0]; const message = notification[1]; - window_.info_bar.add(message, type); + window_.info_bar.add(message, type, 'notification'); } } } diff --git a/sao/src/window.js b/sao/src/window.js index f63347e774..d63482f4de 100644 --- a/sao/src/window.js +++ b/sao/src/window.js @@ -59,7 +59,8 @@ }); this.__messages = new Set(); }, - add: function(message, type) { + add: function(message, type, kind) { + kind = kind || null; if (!message) { return; } @@ -84,16 +85,26 @@ .on('close.bs.alert', null, key, this.__response.bind(this)); this.el.append(infobar); + infobar.data('kind', kind); } }, __response: function(evt) { this.__messages.add(evt.data); }, - refresh: function() { - this.el.empty(); + refresh: function(kind) { + kind = kind || null; + this.el.children().each((i, el) => { + el = jQuery(el); + if (el.data('kind') === kind) { + el.remove(); + } + }); }, clear: function() { - this.refresh(); + var kinds = this.el.children().each((i, el) => el.data('kind')); + new Set(kinds).forEach(kind => { + this.refresh(kind); + }); this.__messages.clear(); }, }); diff --git a/tryton/tryton/gui/window/infobar.py b/tryton/tryton/gui/window/infobar.py index 4293d70787..65355228c2 100644 --- a/tryton/tryton/gui/window/infobar.py +++ b/tryton/tryton/gui/window/infobar.py @@ -12,9 +12,10 @@ class InfoBar(object): self.__box = Gtk.VBox() self.__box.show() self.__messages = set() + self.__kinds = {} return self.__box - def info_bar_add(self, message, type_=Gtk.MessageType.ERROR): + def info_bar_add(self, message, type_=Gtk.MessageType.ERROR, kind=None): if not message: return key = (message, type_) @@ -27,15 +28,19 @@ class InfoBar(object): info_bar.connect('response', self.__response, key) info_bar.set_message_type(type_) info_bar.show_all() + self.__kinds[info_bar] = kind def __response(self, widget, response, key): self.__messages.add(key) self.__box.remove(widget) - def info_bar_refresh(self): + def info_bar_refresh(self, kind=None): for child in self.__box.get_children(): - self.__box.remove(child) + if self.__kinds[child] == kind: + self.__box.remove(child) + del self.__kinds[child] def info_bar_clear(self): - self.info_bar_refresh() + for kind in set(self.__kinds.values()): + self.info_bar_refresh(kind=kind) self.__messages.clear() diff --git a/tryton/tryton/gui/window/view_form/screen/screen.py b/tryton/tryton/gui/window/view_form/screen/screen.py index 6ca14d7ba4..ea8dffaa76 100644 --- a/tryton/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/tryton/gui/window/view_form/screen/screen.py @@ -449,14 +449,14 @@ class Screen: def record_notify(self, notifications): for window in self.windows: if isinstance(window, InfoBar): - window.info_bar_refresh() + window.info_bar_refresh('notification') for type_, message in notifications: type_ = { 'info': Gtk.MessageType.INFO, 'warning': Gtk.MessageType.WARNING, 'error': Gtk.MessageType.ERROR, }.get(type_, Gtk.MessageType.WARNING) - window.info_bar_add(message, type_) + window.info_bar_add(message, type_, 'notification') def record_message(self, position, size, max_size, record_id): for window in self.windows: