From 89b552487990a3909e34ce29f80f4e12dc2a2794 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 11 Nov 2016 17:45:26 +0000 Subject: [PATCH] Fix being able to open editor during sorting --- src/gui/html/elements/loot-plugin-card.html | 3 ++- src/gui/html/elements/loot-plugin-item.html | 6 +++--- src/gui/html/js/dom.js | 6 +++++- src/gui/html/js/events.js | 16 +++++++--------- src/gui/html/js/state.js | 8 ++++++++ .../gui/html/elements/test_loot-plugin-item.html | 2 +- src/tests/gui/html/js/mock_dom.js | 5 +++++ src/tests/gui/html/js/test_state.js | 12 ++++++++++++ 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/gui/html/elements/loot-plugin-card.html b/src/gui/html/elements/loot-plugin-card.html index bcee22c8..3ab1470a 100644 --- a/src/gui/html/elements/loot-plugin-card.html +++ b/src/gui/html/elements/loot-plugin-card.html @@ -82,7 +82,8 @@ overflow: hidden; white-space: nowrap; } - :host-context(body[data-editors]) #editMetadata { + :host-context(body[data-state=editing]) #editMetadata, + :host-context(body[data-state=sorting]) #editMetadata { color: #9b9b9b; pointer-events: none; } diff --git a/src/gui/html/elements/loot-plugin-item.html b/src/gui/html/elements/loot-plugin-item.html index 4f31eef7..4d484881 100644 --- a/src/gui/html/elements/loot-plugin-item.html +++ b/src/gui/html/elements/loot-plugin-item.html @@ -53,7 +53,7 @@ min-height: 32px; height: 32px; } - :host-context(body[data-editors]) paper-item-body[two-line] { + :host-context(body[data-state=editing]) paper-item-body[two-line] { min-height: 40px; } div[item-icon] { @@ -72,7 +72,7 @@ #secondary iron-icon { transition: height var(--state-transition-time); } - :host-context(body[data-editors]) #primary { + :host-context(body[data-state=editing]) #primary { line-height: normal; } #secondary > span { @@ -89,7 +89,7 @@ color: var(--secondary-text-color); } /* When not in edit mode, hide secondary text. */ - :host-context(body:not([data-editors])) #secondary { + :host-context(body:not([data-state=editing])) #secondary { height: 0; overflow: hidden; } diff --git a/src/gui/html/js/dom.js b/src/gui/html/js/dom.js index ef458408..70cf19bd 100644 --- a/src/gui/html/js/dom.js +++ b/src/gui/html/js/dom.js @@ -220,7 +220,7 @@ case that has happened. */ window.getSelection().removeAllRanges(); - if (!document.body.hasAttribute('data-editors')) { + if (document.body.getAttribute('data-state') !== 'editing') { document.getElementById(evt.target.getAttribute('data-id')).onShowEditor(); } } @@ -254,5 +254,9 @@ static initialiseAutocompleteBashTags(tags) { getElementInTableRowTemplate('tagRow', 'name').setAttribute('source', JSON.stringify(tags)); } + + static setUIState(state) { + document.body.setAttribute('data-state', state); + } }; })); diff --git a/src/gui/html/js/events.js b/src/gui/html/js/events.js index 0bf5f3b1..23520cb6 100644 --- a/src/gui/html/js/events.js +++ b/src/gui/html/js/events.js @@ -275,9 +275,9 @@ function handleUnappliedChangesClose(change) { }); } function onQuit() { - if (!document.getElementById('applySortButton').hidden) { + if (loot.state.isInSortingState()) { handleUnappliedChangesClose(loot.l10n.translate('sorted load order')); - } else if (document.body.hasAttribute('data-editors')) { + } else if (loot.state.isInEditingState()) { handleUnappliedChangesClose(loot.l10n.translate('metadata edits')); } else { window.close(); @@ -329,8 +329,9 @@ function onEditorOpen(evt) { /* Set the editor data. */ document.getElementById('editor').setEditorData(evt.target.data); - /* Set body attribute so that sidebar items are styled correctly. */ - document.body.setAttribute('data-editors', true); + loot.state.enterEditingState(); + + /* Sidebar items have been resized. */ document.getElementById('cardsNav').notifyResize(); /* Update the plugin's editor state tracker */ @@ -343,8 +344,6 @@ function onEditorOpen(evt) { elements[i].addEventListener('dragstart', elements[i].onDragStart); } - loot.state.enterEditingState(); - return loot.query('editorOpened').catch(loot.handlePromiseError); } function onEditorClose(evt) { @@ -378,8 +377,8 @@ function onEditorClose(evt) { promise = loot.query('editorClosed', 'null'); } promise.catch(loot.handlePromiseError).then(() => { - /* Remove body attribute so that sidebar items are styled correctly. */ - document.body.removeAttribute('data-editors'); + loot.state.exitEditingState(); + /* Sidebar items have been resized. */ document.getElementById('cardsNav').notifyResize(); /* Remove drag 'n' drop event handlers. */ @@ -389,7 +388,6 @@ function onEditorClose(evt) { elements[i].removeEventListener('dragstart', elements[i].onDragStart); } - loot.state.exitEditingState(); }).catch(loot.handlePromiseError); } function onCopyMetadata(evt) { diff --git a/src/gui/html/js/state.js b/src/gui/html/js/state.js index 017b8b65..c39e4028 100644 --- a/src/gui/html/js/state.js +++ b/src/gui/html/js/state.js @@ -57,6 +57,8 @@ dom.enable('gameMenu', false); dom.enable('refreshContentButton', false); + dom.setUIState('sorting'); + this.currentState = State.SORTING_STATE; } @@ -79,6 +81,8 @@ dom.enable('gameMenu'); dom.enable('refreshContentButton'); + dom.setUIState('default'); + this.currentState = State.DEFAULT_STATE; } @@ -99,6 +103,8 @@ dom.enable('updateMasterlistButton', false); dom.enable('sortButton', false); + dom.setUIState('editing'); + this.currentState = State.EDITING_STATE; } @@ -119,6 +125,8 @@ dom.enable('updateMasterlistButton'); dom.enable('sortButton'); + dom.setUIState('default'); + this.currentState = State.DEFAULT_STATE; } })); diff --git a/src/tests/gui/html/elements/test_loot-plugin-item.html b/src/tests/gui/html/elements/test_loot-plugin-item.html index 62cef1b6..6e28adaf 100644 --- a/src/tests/gui/html/elements/test_loot-plugin-item.html +++ b/src/tests/gui/html/elements/test_loot-plugin-item.html @@ -10,7 +10,7 @@ - + { loot.DOM.elementShownStates.clear(); loot.DOM.elementEnabledStates.clear(); @@ -116,6 +120,8 @@ describe('State', () => { getShown('cancelSortButton').should.be.true(); getEnabled('gameMenu').should.be.false(); getEnabled('refreshContentButton').should.be.false(); + + getDomState().should.equal('sorting'); }); it('should throw an error if called in the editing state', () => { @@ -155,6 +161,8 @@ describe('State', () => { getShown('cancelSortButton').should.be.false(); getEnabled('gameMenu').should.be.true(); getEnabled('refreshContentButton').should.be.true(); + + getDomState().should.equal('default'); }); it('should throw an error if called in the editing state', () => { @@ -193,6 +201,8 @@ describe('State', () => { getEnabled('gameMenu').should.be.false(); getEnabled('updateMasterlistButton').should.be.false(); getEnabled('sortButton').should.be.false(); + + getDomState().should.equal('editing'); }); it('should throw an error if called in the sorting state', () => { @@ -234,6 +244,8 @@ describe('State', () => { getEnabled('gameMenu').should.be.true(); getEnabled('updateMasterlistButton').should.be.true(); getEnabled('sortButton').should.be.true(); + + getDomState().should.equal('default'); }); it('should throw an error if called in the sorting state', () => {