Add record changed callback
Only when the current record has changed that those objects needs to be
refreshed/cleared:
- the info bar
- the resources
- the attachment preview
- the chat
Closes #15012
(grafted from dc3a3e20006329b742e6f989a0fd01d485ec80b1)
--HG--
branch : 8.0
This commit is contained in:
+17
-9
@@ -1362,6 +1362,7 @@
|
||||
return this.__current_record;
|
||||
},
|
||||
set current_record(record) {
|
||||
let changed = this.__current_record !== record;
|
||||
this.__current_record = record;
|
||||
var pos = null;
|
||||
var record_id = null;
|
||||
@@ -1377,15 +1378,22 @@
|
||||
this.record_message(
|
||||
pos || 0, this.group.length + this.offset, this.search_count,
|
||||
record_id);
|
||||
if (this.switch_callback) {
|
||||
this.switch_callback();
|
||||
}
|
||||
if (this.has_update_resources()) {
|
||||
if (record) {
|
||||
record.get_resources().always(
|
||||
this.update_resources.bind(this));
|
||||
} else {
|
||||
this.update_resources();
|
||||
if (changed) {
|
||||
for (let window_ of this.windows) {
|
||||
if (window_.record_changed) {
|
||||
window_.record_changed();
|
||||
}
|
||||
}
|
||||
if (this.switch_callback) {
|
||||
this.switch_callback();
|
||||
}
|
||||
if (this.has_update_resources()) {
|
||||
if (record) {
|
||||
record.get_resources().always(
|
||||
this.update_resources.bind(this));
|
||||
} else {
|
||||
this.update_resources();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+11
-9
@@ -1611,8 +1611,18 @@
|
||||
msg = name + '/' + Sao.common.humanize(size);
|
||||
}
|
||||
this.status_label.text(msg).attr('title', msg);
|
||||
this.info_bar.clear();
|
||||
this.set_buttons_sensitive();
|
||||
},
|
||||
record_modified: function() {
|
||||
this.set_buttons_sensitive();
|
||||
this.info_bar.refresh();
|
||||
},
|
||||
record_saved: function() {
|
||||
this.set_buttons_sensitive();
|
||||
this.refresh_resources();
|
||||
},
|
||||
record_changed: function() {
|
||||
this.info_bar.clear();
|
||||
this.refresh_attachment_preview();
|
||||
|
||||
if (this._chat) {
|
||||
@@ -1627,14 +1637,6 @@
|
||||
this.update_sidebar();
|
||||
}
|
||||
},
|
||||
record_modified: function() {
|
||||
this.set_buttons_sensitive();
|
||||
this.info_bar.refresh();
|
||||
},
|
||||
record_saved: function() {
|
||||
this.set_buttons_sensitive();
|
||||
this.refresh_resources();
|
||||
},
|
||||
action: function() {
|
||||
window.setTimeout(() => {
|
||||
this.buttons.action.click();
|
||||
|
||||
@@ -652,19 +652,7 @@ class Form(TabContent):
|
||||
else:
|
||||
msg = "%s/%s" % (name, common.humanize(size))
|
||||
self.status_label.set_text(msg)
|
||||
self.info_bar_clear()
|
||||
self.set_buttons_sensitive()
|
||||
self.refresh_attachment_preview()
|
||||
if self._chat:
|
||||
self._chat.unregister()
|
||||
self.chat.remove(self._chat.widget)
|
||||
if self.screen.current_reference:
|
||||
self._chat = Chat(self.screen.current_reference)
|
||||
self.chat.add(self._chat.widget)
|
||||
self.chat.show_all()
|
||||
self._chat.refresh()
|
||||
else:
|
||||
self.buttons['chat'].set_active(False)
|
||||
|
||||
def record_modified(self):
|
||||
def _record_modified():
|
||||
@@ -679,6 +667,20 @@ class Form(TabContent):
|
||||
self.set_buttons_sensitive()
|
||||
self.refresh_resources()
|
||||
|
||||
def record_changed(self):
|
||||
self.info_bar_clear()
|
||||
self.refresh_attachment_preview()
|
||||
if self._chat:
|
||||
self._chat.unregister()
|
||||
self.chat.remove(self._chat.widget)
|
||||
if self.screen.current_reference:
|
||||
self._chat = Chat(self.screen.current_reference)
|
||||
self.chat.add(self._chat.widget)
|
||||
self.chat.show_all()
|
||||
self._chat.refresh()
|
||||
else:
|
||||
self.buttons['chat'].set_active(False)
|
||||
|
||||
def modified_save(self):
|
||||
self.screen.save_tree_state()
|
||||
self.screen.current_view.set_value()
|
||||
|
||||
@@ -502,6 +502,7 @@ class Screen:
|
||||
return self.__current_record
|
||||
|
||||
def __set_current_record(self, record):
|
||||
changed = self.__current_record != record
|
||||
self.__current_record = record
|
||||
if record:
|
||||
try:
|
||||
@@ -514,9 +515,13 @@ class Screen:
|
||||
self.record_message(
|
||||
pos, len(self.group) + self.offset,
|
||||
self.search_count, record and record.id)
|
||||
self.update_resources(record.resources if record else None)
|
||||
# update resources after 1 second
|
||||
GLib.timeout_add(1000, self._update_resources, record)
|
||||
if changed:
|
||||
for window in self.windows:
|
||||
if hasattr(window, 'record_changed'):
|
||||
window.record_changed()
|
||||
self.update_resources(record.resources if record else None)
|
||||
# update resources after 1 second
|
||||
GLib.timeout_add(1000, self._update_resources, record)
|
||||
|
||||
current_record = property(__get_current_record, __set_current_record)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user