From e6276c621259b407bada1ca8e6a59f32e81e9a57 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 22 Dec 2016 10:03:38 +0100 Subject: [PATCH] feat(ui/views/App/MainWindow/MainWindow): - add a lock feature of views - display a confirm dialog when lock is enabled and if the user try to change the view - `ContactEdit` use a lock on edition --- tests/assets/languages/en.ts | 8 +++ tests/assets/languages/fr.ts | 8 +++ tests/ui/scripts/Utils/utils.js | 6 +-- tests/ui/views/App/MainWindow/ContactEdit.qml | 7 +++ tests/ui/views/App/MainWindow/MainWindow.qml | 50 +++++++++++++++++-- 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/tests/assets/languages/en.ts b/tests/assets/languages/en.ts index 099982015..ee6911bc2 100644 --- a/tests/assets/languages/en.ts +++ b/tests/assets/languages/en.ts @@ -190,6 +190,14 @@ locality + + abortEditionTitle + + + + abortEditionDescriptionText + + Contacts diff --git a/tests/assets/languages/fr.ts b/tests/assets/languages/fr.ts index 45fee9df7..712f8928b 100644 --- a/tests/assets/languages/fr.ts +++ b/tests/assets/languages/fr.ts @@ -178,6 +178,14 @@ locality + + abortEditionTitle + + + + abortEditionDescriptionText + + Contacts diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 3513688fb..68cd5925f 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -105,11 +105,11 @@ function getTopParent (object, useFakeParent) { function openConfirmDialog (parent, options) { return openWindow( 'import QtQuick 2.7;' + - 'import Common 1.0;' + - 'ConfirmDialog {' + + 'import Common 1.0;' + + 'ConfirmDialog {' + 'descriptionText: \'' + escapeQuotes(options.descriptionText) + '\';' + 'title: \'' + escapeQuotes(options.title) + '\'' + - '}', + '}', parent, { isString: true, exitHandler: options.exitHandler diff --git a/tests/ui/views/App/MainWindow/ContactEdit.qml b/tests/ui/views/App/MainWindow/ContactEdit.qml index 3b63cb3fa..ee491e9df 100644 --- a/tests/ui/views/App/MainWindow/ContactEdit.qml +++ b/tests/ui/views/App/MainWindow/ContactEdit.qml @@ -25,11 +25,17 @@ ColumnLayout { function _editContact () { _contact.startEdit() _edition = true + + window.lockView({ + title: qsTr('abortEditionTitle'), + descriptionText: qsTr('abortEditionDescriptionText') + }) } function _save () { if (_contact) { _contact.endEdit() + window.unlockView() } else { _contact = ContactsListModel.addContact(_vcard) } @@ -41,6 +47,7 @@ ColumnLayout { if (_contact) { _contact.abortEdit() _edition = false + window.unlockView() } else { window.setView('Contacts') } diff --git a/tests/ui/views/App/MainWindow/MainWindow.qml b/tests/ui/views/App/MainWindow/MainWindow.qml index 023a963ac..a57001e47 100644 --- a/tests/ui/views/App/MainWindow/MainWindow.qml +++ b/tests/ui/views/App/MainWindow/MainWindow.qml @@ -13,20 +13,62 @@ import App.Styles 1.0 ApplicationWindow { id: window + property string _currentView: '' + property var _lockedInfo + + // --------------------------------------------------------------------------- + + function lockView (info) { + _lockedInfo = info + } + + function unlockView () { + _lockedInfo = undefined + } + function setView (view, props) { + if (!_lockedInfo) { + _setView(view, props) + return + } + + Utils.openConfirmDialog(window, { + descriptionText: _lockedInfo.descriptionText, + exitHandler: function (status) { + if (status) { + unlockView() + _setView(view, props) + } else { + _updateSelectedEntry(_currentView, props) + } + }, + title: _lockedInfo.title + }) + } + + function ensureCollapsed () { + collapse.setCollapsed(true) + } + + // --------------------------------------------------------------------------- + + function _updateSelectedEntry (view, props) { if (view === 'Home' || view === 'Contacts') { menu.setSelectedEntry(view === 'Home' ? 0 : 1) timeline.resetSelectedEntry() } else if (view === 'Conversation') { menu.resetSelectedEntry() timeline.setSelectedEntry(props.sipAddress) + } else if (view === 'ContactEdit') { + menu.resetSelectedEntry() + timeline.resetSelectedEntry() } - - contentLoader.setSource(view + '.qml', props || {}) } - function ensureCollapsed () { - collapse.setCollapsed(true) + function _setView (view, props) { + _updateSelectedEntry(view, props) + _currentView = view + contentLoader.setSource(view + '.qml', props || {}) } // ---------------------------------------------------------------------------