Conflicts filter can now be overridden.

Closes #248. Also fixed a few JS bugs:
* Plugin menu appearing at bottom of UI for an instant before being
moved.
* Undefined (old) filter function.
* Error on window refocus with plugin menu open.
This commit is contained in:
WrinklyNinja
2014-08-25 17:03:20 +01:00
parent 016269ef0f
commit 78818a2146
2 changed files with 40 additions and 46 deletions
+17 -24
View File
@@ -45,13 +45,18 @@ var pluginMenuProto = Object.create(HTMLElement.prototype, {
activateFilter = evt.target.checked;
}
if (activateFilter) {
document.body.setAttribute('data-conflicts', evt.currentTarget.parentNode.host.getPluginCard().getName());
/* Un-highlight any existing filter plugin. */
var cards = document.getElementsByTagName('main')[0].getElementsByTagName('plugin-card');
for (var i = 0; i < cards.length; ++i) {
cards[i].classList.toggle('highlight', false);
}
evt.currentTarget.parentNode.host.getPluginCard().classList.toggle('highlight', true);
document.body.setAttribute('data-conflicts', evt.currentTarget.parentNode.host.getPluginCard().getName());
} else {
evt.currentTarget.parentNode.host.getPluginCard().classList.toggle('highlight', false);
document.body.removeAttribute('data-conflicts');
}
togglePlugins(evt);
applyFilters(evt);
}
},
@@ -123,25 +128,15 @@ var pluginMenuProto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
/* Add event listeners for the menu items. */
var conflictsPlugin = document.body.getAttribute('data-conflicts');
if (conflictsPlugin && conflictsPlugin != this.getPluginCard().getName()) {
/* The conflict filter is currently active for another plugin.
Prevent the filter being activated for this one. */
this.shadowRoot.getElementById('showOnlyConflicts').disabled = true;
this.shadowRoot.getElementById('showOnlyConflicts').parentElement.classList.toggle('disabled', true);
} else {
/* The conflicts filter is either inactive or active for this
plugin. Allow it to be activated or deactivated. For some
reason clicking on the label is processed slower than
the checkbox state, and in the time difference the menu
gets closed, so that the conflicts filter never gets applied.
To get around this, listen for a click on the label rather
than for checkbox state change. */
if (conflictsPlugin == this.getPluginCard().getName()) {
this.shadowRoot.getElementById('showOnlyConflicts').checked = true;
}
this.shadowRoot.getElementById('showOnlyConflicts').parentElement.addEventListener('click', this.onShowOnlyConflicts, false);
/* For some reason clicking on the label is processed slower
than the checkbox state, and in the time difference the menu
gets closed, so that the conflicts filter never gets applied.
To get around this, listen for a click on the label rather
than for checkbox state change. */
if (document.body.getAttribute('data-conflicts') == this.getPluginCard().getName()) {
this.shadowRoot.getElementById('showOnlyConflicts').checked = true;
}
this.shadowRoot.getElementById('showOnlyConflicts').parentElement.addEventListener('click', this.onShowOnlyConflicts, false);
this.shadowRoot.getElementById('editMetadata').addEventListener('click', this.onEditMetadata, false);
this.shadowRoot.getElementById('copyMetadata').addEventListener('click', this.onCopyMetadata, false);
this.shadowRoot.getElementById('clearMetadata').addEventListener('click', this.onClearMetadata, false);
@@ -541,13 +536,9 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
var card = evt.currentTarget.parentElement.parentElement.parentNode.host;
menu.setAttribute('data-for', card.id);
var main = document.getElementsByTagName('main')[0];
main.appendChild(menu);
/* Set page position of menu. */
function getOffset( el, stopEl ) {
var _x = 0;
var _y = 0;
@@ -563,6 +554,8 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
menu.style.top = (offset.top + evt.target.offsetHeight + 10) + 'px';
menu.style.right = (main.offsetWidth - offset.left - evt.target.offsetWidth - 10) + 'px';
main.appendChild(menu);
evt.stopPropagation();
/* To prevent the click event closing this menu just after it was
+23 -22
View File
@@ -22,6 +22,7 @@
<http://www.gnu.org/licenses/>.
*/
'use strict';
var marked;
var loot = {
hasFocus: true,
installedGames: [],
@@ -150,23 +151,24 @@ var loot = {
change.object.updateRedatePluginsButtonState();
}
});
},
/* Returns a cefQuery as a Promise. */
query: function(request) {
return new Promise(function(resolve, reject) {
window.cefQuery({
request: request,
persistent: false,
onSuccess: resolve,
onFailure: function(errorCode, errorMessage) {
reject(Error('Error code: ' + errorCode + '; ' + errorMessage))
}
});
});
}
};
Object.observe(loot, loot.observer);
/* Returns a cefQuery as a Promise. */
loot.query = function(request) {
return new Promise(function(resolve, reject) {
window.cefQuery({
request: request,
persistent: false,
onSuccess: resolve,
onFailure: function(errorCode, errorMessage) {
reject(Error('Error code: ' + errorCode + '; ' + errorMessage))
}
});
})
}
function processCefError(err) {
/* Error.stack seems to be Chromium-specific. It gives a lot more useful
info than just the error message. */
@@ -174,7 +176,6 @@ function processCefError(err) {
showMessageBox('error', 'Error', err.message);
}
var marked;
function saveFilterState(evt) {
if (evt.currentTarget.checked) {
if (!loot.settings.filters) {
@@ -324,11 +325,11 @@ function applyFilters(evt) {
if ((document.getElementById('hideMessagelessPlugins').checked && isMessageless)
|| conflicts.length > 0 && !isConflictingPlugin) {
hideElement(cards[i]);
hideElement(entries[i - 2]);
hideElement(entries[i]);
++hiddenPluginNo;
} else {
showElement(cards[i]);
showElement(entries[i - 2]);
showElement(entries[i]);
}
}
document.getElementById('hiddenMessageNo').textContent = hiddenMessageNo;
@@ -549,7 +550,7 @@ function sortUIElements(pluginNames) {
var main = document.getElementsByTagName('main')[0];
var pluginsNav = document.getElementById('pluginsNav');
var entries = pluginsNav.children;
if (main.children.length - 2 != entries.length) {
if (main.getElementsByTagName('plugin-card').length != entries.length) {
throw Error("Error: Number of plugins in sidebar doesn't match number of plugins in main area!");
}
pluginNames.forEach(function(name){
@@ -938,11 +939,11 @@ function setupEventHandlers() {
document.getElementById('hideVersionNumbers').addEventListener('click', toggleDisplayCSS, false);
document.getElementById('hideCRCs').addEventListener('click', toggleDisplayCSS, false);
document.getElementById('hideBashTags').addEventListener('click', toggleDisplayCSS, false);
document.getElementById('hideNotes').addEventListener('click', togglePlugins, false);
document.getElementById('hideDoNotCleanMessages').addEventListener('click', togglePlugins, false);
document.getElementById('hideInactivePluginMessages').addEventListener('click', togglePlugins, false);
document.getElementById('hideAllPluginMessages').addEventListener('click', togglePlugins, false);
document.getElementById('hideMessagelessPlugins').addEventListener('click', togglePlugins, false);
document.getElementById('hideNotes').addEventListener('click', applyFilters, false);
document.getElementById('hideDoNotCleanMessages').addEventListener('click', applyFilters, false);
document.getElementById('hideInactivePluginMessages').addEventListener('click', applyFilters, false);
document.getElementById('hideAllPluginMessages').addEventListener('click', applyFilters, false);
document.getElementById('hideMessagelessPlugins').addEventListener('click', applyFilters, false);
/* Set up handlers for buttons. */
document.getElementById('fileMenu').addEventListener('click', openMenu, false);