Fix being able to open editor during sorting

This commit is contained in:
Oliver Hamlet
2016-11-11 17:45:26 +00:00
parent 836ede30ac
commit 89b5524879
8 changed files with 43 additions and 15 deletions
+2 -1
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+5 -1
View File
@@ -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);
}
};
}));
+7 -9
View File
@@ -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) {
+8
View File
@@ -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;
}
}));
@@ -10,7 +10,7 @@
<link rel="import" href="../../../../gui/html/elements/loot-plugin-item.html">
</head>
<body data-editors="1">
<body>
<loot-plugin-item priority="10"
is-global-priority
is-editor-open
+5
View File
@@ -4,6 +4,7 @@ window.loot = window.loot || {};
loot.DOM = {
elementShownStates: new Map(),
elementEnabledStates: new Map(),
state: undefined,
show(elementId, showElement = true) {
this.elementShownStates.set(elementId, showElement);
@@ -12,4 +13,8 @@ loot.DOM = {
enable(elementId, enableElement = true) {
this.elementEnabledStates.set(elementId, enableElement);
},
setUIState(state) {
this.state = state;
},
};
+12
View File
@@ -8,6 +8,10 @@ function getEnabled(elementId) {
return loot.DOM.elementEnabledStates.get(elementId);
}
function getDomState() {
return loot.DOM.state;
}
beforeEach(() => {
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', () => {