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
This commit is contained in:
+2
-2
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-4
@@ -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();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user