From d1291774fd493b6a559636d8955a368e2c8de51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 25 Apr 2022 23:20:57 +0200 Subject: [PATCH] Compute next/previous record to set button state The position is not enough to determine if the button will change the current record. Also the position can be a list for the tree. issue11413 review405241002 --- src/screen.js | 38 ++++++++++++++++++++++++++++---------- src/tab.js | 4 ++-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/screen.js b/src/screen.js index ea87cdfc71..8255c24787 100644 --- a/src/screen.js +++ b/src/screen.js @@ -1355,10 +1355,8 @@ } })); }, - display_next: function() { + _get_next_record: function() { var view = this.current_view; - view.set_value(); - this.set_cursor(false, false); if (~['tree', 'form', 'list-form'].indexOf(view.view_type) && this.current_record && this.current_record.group) { var group = this.current_record.group; @@ -1377,17 +1375,26 @@ break; } } - this.current_record = record; + return record; } else { - this.current_record = this.group[0]; + return this.group[0]; } - this.set_cursor(false, false); - return view.display(); }, - display_previous: function() { + has_next: function() { + var next_record = this._get_next_record(); + return next_record && + (next_record !== this.current_record); + }, + display_next: function() { var view = this.current_view; view.set_value(); this.set_cursor(false, false); + this.current_record = this._get_next_record(); + this.set_cursor(false, false); + return view.display(); + }, + _get_previous_record: function() { + var view = this.current_view; if (~['tree', 'form', 'list-form'].indexOf(view.view_type) && this.current_record && this.current_record.group) { var group = this.current_record.group; @@ -1406,10 +1413,21 @@ break; } } - this.current_record = record; + return record; } else { - this.current_record = this.group[0]; + return this.group[0]; } + }, + has_previous: function() { + var previous_record = this._get_previous_record(); + return previous_record && + (previous_record !== this.current_record); + }, + display_previous: function() { + var view = this.current_view; + view.set_value(); + this.set_cursor(false, false); + this.current_record = this._get_previous_record(); this.set_cursor(false, false); return view.display(); }, diff --git a/src/tab.js b/src/tab.js index f9186bc9c0..ff92de14f8 100644 --- a/src/tab.js +++ b/src/tab.js @@ -1487,8 +1487,8 @@ } set_sensitive('switch_', this.screen.number_of_views > 1); set_sensitive('delete_', this.screen.deletable); - set_sensitive('previous', position > (this.screen.offset + 1)); - set_sensitive('next', position < size); + set_sensitive('previous', this.screen.has_previous()); + set_sensitive('next', this.screen.has_next()); var msg; if (size < max_size) {