Skip to content

Commit

Permalink
Refactored the onAfterDeactivate event handler of Sync Clippings list…
Browse files Browse the repository at this point in the history
…ener
  • Loading branch information
aecreations committed Dec 14, 2018
1 parent 35ce777 commit c57c258
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
14 changes: 4 additions & 10 deletions wx-src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ let gSyncClippingsListeners = {
};

let gSyncClippingsListener = {
_oldSyncFldrID: null,

onActivate(aSyncFolderID)
{
// No need to do anything here. The Clippings context menu is automatically
Expand All @@ -148,8 +146,6 @@ let gSyncClippingsListener = {
onDeactivate(aOldSyncFolderID)
{
log("Clippings/wx: gSyncClippingsListener.onDeactivate()");
this._oldSyncFldrID = aOldSyncFolderID;

let syncFldrMenuID = gFolderMenuItemIDMap[aOldSyncFolderID];

try {
Expand All @@ -163,17 +159,15 @@ let gSyncClippingsListener = {
}
},

onAfterDeactivate(aRemoveSyncFolder)
onAfterDeactivate(aRemoveSyncFolder, aOldSyncFolderID)
{
log("Clippings/wx: gSyncClippingsListeners.onAfterDeactivate(): Remove Synced Clippings folder: " + aRemoveSyncFolder);

let that = this;

if (aRemoveSyncFolder) {
log(`Removing old Synced Clippings folder (ID = ${that._oldSyncFldrID})`);
purgeFolderItems(this._oldSyncFldrID, false).then(() => {
that._oldSyncFldrID = null;
});
log(`Removing old Synced Clippings folder (ID = ${aOldSyncFolderID})`);
purgeFolderItems(aOldSyncFolderID, false).then(() => {});
}
},

Expand Down Expand Up @@ -1738,7 +1732,7 @@ function alertEx(aMessageID)
window.alert(message);
}
else {
console.info("Clippings/wx: " + message);
info("Clippings/wx: " + message);
let url = "pages/msgbox.html?msgid=" + aMessageID;

chrome.windows.create({
Expand Down
14 changes: 3 additions & 11 deletions wx-src/pages/clippingsMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@ let gClippingsListener = {
};

let gSyncClippingsListener = {
_oldSyncFldrID: null,

onActivate(aSyncFolderID)
{
log("Clippings/wx::clippingsMgr.js::gSyncClippingsListener.onActivate()");
Expand All @@ -384,7 +382,6 @@ let gSyncClippingsListener = {
onDeactivate(aOldSyncFolderID)
{
log(`Clippings/wx::clippingsMgr.js::gSyncClippingsListener.onDeactivate(): ID of old sync folder: ${aOldSyncFolderID}`);
this._oldSyncFldrID = aOldSyncFolderID;
gSyncedItemsIDs = {};

gReloadSyncFldrBtn.hide();
Expand All @@ -394,20 +391,15 @@ let gSyncClippingsListener = {
syncFldrTreeNode.removeClass("ae-synced-clippings-fldr");
},

onAfterDeactivate(aRemoveSyncFolder)
onAfterDeactivate(aRemoveSyncFolder, aOldSyncFolderID)
{
log("Clippings/wx::clippingsMgr.js: gSyncClippingsListener.onAfterDeactivate(): Remove Synced Clippings folder: " + aRemoveSyncFolder)
log(`Clippings/wx::clippingsMgr.js: gSyncClippingsListener.onAfterDeactivate(): Remove Synced Clippings folder = ${aRemoveSyncFolder}; old sync folder ID = ${aOldSyncFolderID}`)

if (aRemoveSyncFolder) {
let clippingsTree = getClippingsTree();

// TO DO: This won't work if Clippings Manager was opened right after
// turning off Sync Clippings, but before selecting the option to remove
// the Synced Clippings folder, from the Clippings preferences page.
let syncFldrTreeNode = clippingsTree.getNodeByKey(this._oldSyncFldrID + "F");
let syncFldrTreeNode = clippingsTree.getNodeByKey(aOldSyncFolderID + "F");
syncFldrTreeNode.remove();
this._oldSyncFldrID = null;

setStatusBarMsg();

// TO DO: If there are no longer any clippings and folders, then show the
Expand Down
5 changes: 4 additions & 1 deletion wx-src/pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,23 @@ function initDialogs()
listener.onDeactivate(aOldSyncFldrID);
}

gDialogs.turnOffSyncAck.oldSyncFldrID = aOldSyncFldrID;
gDialogs.turnOffSyncAck.showModal();
});
};

gDialogs.turnOffSyncAck = new aeDialog("#turn-off-sync-clippings-ack-dlg");
gDialogs.turnOffSyncAck.oldSyncFldrID = null;
gDialogs.turnOffSyncAck.onInit = () => {
$("#delete-sync-fldr").prop("checked", true);
};
gDialogs.turnOffSyncAck.onAfterAccept = () => {
let that = gDialogs.turnOffSyncAck;
let removeSyncFldr = $("#delete-sync-fldr").prop("checked");
let syncClippingsListeners = gClippings.getSyncClippingsListeners().getListeners();

for (let listener of syncClippingsListeners) {
listener.onAfterDeactivate(removeSyncFldr);
listener.onAfterDeactivate(removeSyncFldr, that.oldSyncFldrID);
}
};

Expand Down

0 comments on commit c57c258

Please sign in to comment.