moebius#350: Don't display storage-sidebar after deleting all cookies

Issue #31
https://github.com/MoonchildProductions/moebius/pull/350
This commit is contained in:
janekptacijarabaci 2018-03-02 18:46:58 +01:00 • committed by Roy Tam
commit 558c645ef6
3 changed files with 46 additions and 32 deletions

View file

@ -143,7 +143,12 @@ TableWidget.prototype = {
*/ */
set selectedRow(id) { set selectedRow(id) {
for (let column of this.columns.values()) { for (let column of this.columns.values()) {
column.selectRow(id[this.uniqueId] || id); if (id) {
column.selectRow(id[this.uniqueId] || id);
} else {
column.selectedRow = null;
column.selectRow(null);
}
} }
}, },
@ -842,7 +847,8 @@ TableWidget.prototype = {
column.remove(item); column.remove(item);
column.updateZebra(); column.updateZebra();
} }
if (this.items.size == 0) { if (this.items.size === 0) {
this.selectedRow = null;
this.tbody.setAttribute("empty", "empty"); this.tbody.setAttribute("empty", "empty");
} }
@ -885,6 +891,8 @@ TableWidget.prototype = {
this.tbody.setAttribute("empty", "empty"); this.tbody.setAttribute("empty", "empty");
this.setPlaceholderText(this.emptyText); this.setPlaceholderText(this.emptyText);
this.selectedRow = null;
this.emit(EVENTS.TABLE_CLEARED, this); this.emit(EVENTS.TABLE_CLEARED, this);
}, },
@ -1227,15 +1235,16 @@ Column.prototype = {
*/ */
selectRowAt: function (index) { selectRowAt: function (index) {
if (this.selectedRow != null) { if (this.selectedRow != null) {
this.cells[this.items[this.selectedRow]].toggleClass("theme-selected"); this.cells[this.items[this.selectedRow]].classList.remove("theme-selected");
}
if (index < 0) {
this.selectedRow = null;
return;
} }
let cell = this.cells[index]; let cell = this.cells[index];
cell.toggleClass("theme-selected"); if (cell) {
this.selectedRow = cell.id; cell.classList.add("theme-selected");
this.selectedRow = cell.id;
} else {
this.selectedRow = null;
}
}, },
/** /**
@ -1399,7 +1408,6 @@ Column.prototype = {
this.cells = []; this.cells = [];
this.items = {}; this.items = {};
this._itemsDirty = false; this._itemsDirty = false;
this.selectedRow = null;
while (this.header.nextSibling) { while (this.header.nextSibling) {
this.header.nextSibling.remove(); this.header.nextSibling.remove();
} }
@ -1430,7 +1438,7 @@ Column.prototype = {
} }
if (this.selectedRow) { if (this.selectedRow) {
this.cells[this.items[this.selectedRow]].toggleClass("theme-selected"); this.cells[this.items[this.selectedRow]].classList.remove("theme-selected");
} }
this.items = {}; this.items = {};
// Otherwise, just use the sorted array passed to update the cells value. // Otherwise, just use the sorted array passed to update the cells value.
@ -1440,7 +1448,7 @@ Column.prototype = {
this.cells[i].id = item[this.uniqueId]; this.cells[i].id = item[this.uniqueId];
}); });
if (this.selectedRow) { if (this.selectedRow) {
this.cells[this.items[this.selectedRow]].toggleClass("theme-selected"); this.cells[this.items[this.selectedRow]].classList.add("theme-selected");
} }
this._itemsDirty = false; this._itemsDirty = false;
this.updateZebra(); this.updateZebra();
@ -1454,7 +1462,9 @@ Column.prototype = {
if (!cell.hidden) { if (!cell.hidden) {
i++; i++;
} }
cell.toggleClass("even", !(i % 2));
let even = !(i % 2);
cell.classList.toggle("even", even);
} }
}, },
@ -1590,8 +1600,8 @@ Cell.prototype = {
return this._value; return this._value;
}, },
toggleClass: function (className, condition) { get classList() {
this.label.classList.toggle(className, condition); return this.label.classList;
}, },
/** /**

View file

@ -26,7 +26,7 @@ add_task(function* () {
for (let i = 0; i < UPDATE_COUNT; i++) { for (let i = 0; i < UPDATE_COUNT; i++) {
info(`Performing update #${i}`); info(`Performing update #${i}`);
updates.push(gUI.once("sidebar-updated")); updates.push(gUI.once("sidebar-updated"));
gUI.displayObjectSidebar(); gUI.updateObjectSidebar();
} }
yield promise.all(updates); yield promise.all(updates);

View file

@ -113,8 +113,8 @@ function StorageUI(front, target, panelWin, toolbox) {
cellContextMenuId: "storage-table-popup" cellContextMenuId: "storage-table-popup"
}); });
this.displayObjectSidebar = this.displayObjectSidebar.bind(this); this.updateObjectSidebar = this.updateObjectSidebar.bind(this);
this.table.on(TableWidget.EVENTS.ROW_SELECTED, this.displayObjectSidebar); this.table.on(TableWidget.EVENTS.ROW_SELECTED, this.updateObjectSidebar);
this.handleScrollEnd = this.handleScrollEnd.bind(this); this.handleScrollEnd = this.handleScrollEnd.bind(this);
this.table.on(TableWidget.EVENTS.SCROLL_END, this.handleScrollEnd); this.table.on(TableWidget.EVENTS.SCROLL_END, this.handleScrollEnd);
@ -217,7 +217,7 @@ StorageUI.prototype = {
}, },
destroy: function () { destroy: function () {
this.table.off(TableWidget.EVENTS.ROW_SELECTED, this.displayObjectSidebar); this.table.off(TableWidget.EVENTS.ROW_SELECTED, this.updateObjectSidebar);
this.table.off(TableWidget.EVENTS.SCROLL_END, this.handleScrollEnd); this.table.off(TableWidget.EVENTS.SCROLL_END, this.handleScrollEnd);
this.table.off(TableWidget.EVENTS.CELL_EDIT, this.editItem); this.table.off(TableWidget.EVENTS.CELL_EDIT, this.editItem);
this.table.destroy(); this.table.destroy();
@ -285,17 +285,16 @@ StorageUI.prototype = {
* being removed was selected. * being removed was selected.
*/ */
removeItemFromTable: function (name) { removeItemFromTable: function (name) {
if (this.table.isSelected(name)) { if (this.table.isSelected(name) && this.table.items.size > 1) {
if (this.table.selectedIndex == 0) { if (this.table.selectedIndex == 0) {
this.table.selectNextRow(); this.table.selectNextRow();
} else { } else {
this.table.selectPreviousRow(); this.table.selectPreviousRow();
} }
this.table.remove(name);
this.displayObjectSidebar();
} else {
this.table.remove(name);
} }
this.table.remove(name);
this.updateObjectSidebar();
}, },
/** /**
@ -634,20 +633,25 @@ StorageUI.prototype = {
* Populates the selected entry from the table in the sidebar for a more * Populates the selected entry from the table in the sidebar for a more
* detailed view. * detailed view.
*/ */
displayObjectSidebar: Task.async(function* () { updateObjectSidebar: Task.async(function* () {
let item = this.table.selectedRow; let item = this.table.selectedRow;
if (!item) { let value;
// Make sure that sidebar is hidden and return
this.sidebar.hidden = true;
return;
}
// Get the string value (async action) and the update the UI synchronously. // Get the string value (async action) and the update the UI synchronously.
let value; if (item && item.name && item.valueActor) {
if (item.name && item.valueActor) {
value = yield item.valueActor.string(); value = yield item.valueActor.string();
} }
// Bail if the selectedRow is no longer selected, the item doesn't exist or the state
// changed in another way during the above yield.
if (this.table.items.size === 0 ||
!item ||
!this.table.selectedRow ||
item.uniqueKey !== this.table.selectedRow.uniqueKey) {
this.hideSidebar();
return;
}
// Start updating the UI. Everything is sync beyond this point. // Start updating the UI. Everything is sync beyond this point.
this.sidebar.hidden = false; this.sidebar.hidden = false;
this.view.empty(); this.view.empty();
@ -945,7 +949,7 @@ StorageUI.prototype = {
case REASON.UPDATE: case REASON.UPDATE:
this.table.update(item); this.table.update(item);
if (item == this.table.selectedRow && !this.sidebar.hidden) { if (item == this.table.selectedRow && !this.sidebar.hidden) {
this.displayObjectSidebar(); this.updateObjectSidebar();
} }
break; break;
} }