Skip to content

Commit

Permalink
Bug fix: Empty Synced Clippings folder in Clippings Manager after cha…
Browse files Browse the repository at this point in the history
…nging data source location (issue #13)
  • Loading branch information
aecreations committed Aug 4, 2018
1 parent ac069ad commit ad7abdb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/chrome/content/clippingsMgr.js
Expand Up @@ -950,6 +950,10 @@ function init()
gClippingsTree.rebuild();
},

syncLocationChanged: function (aSyncURL) {
gClippingsTree.rebuild();
},

importDone: function (aNumItems) {}
};
gClippingsSvc.addListener(gClippingsListener);
Expand Down
6 changes: 5 additions & 1 deletion src/chrome/content/options/datasource.js
Expand Up @@ -235,6 +235,10 @@ function applyDataSourcePrefChanges()
var numBackupFiles = aeUtils.getPref("clippings.backup.maxfiles", 10);
gClippingsSvc.setMaxBackupFiles(numBackupFiles);

// Save clippings one last time before changing datasource and/or
// sync folder locations.
gClippingsSvc.flushDataSrc(true, true);

var newDataSrcPath;

if (gDataSrcLocationOpt.selectedIndex == 0) {
Expand Down Expand Up @@ -266,7 +270,7 @@ function applyDataSourcePrefChanges()
let syncDirPath = gSyncFilePath.value;
let syncDirURL = aeUtils.getURLFromFilePath(syncDirPath);
gClippingsSvc.setSyncDir(syncDirURL);
gClippingsSvc.refreshSyncedClippings();
gClippingsSvc.refreshSyncedClippings(true);
aeUtils.setPref("clippings.datasource.wx_sync.location", syncDirPath);
}
gClippingsSvc.enableSyncClippings(isWxSyncEnabled);
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/content/tbMessengerOverlay.js
Expand Up @@ -344,7 +344,7 @@ window.aecreations.clippings = {

let syncDirURL = this.aeUtils.getURLFromFilePath(syncDirPath);
this.clippingsSvc.setSyncDir(syncDirURL);
this.clippingsSvc.refreshSyncedClippings();
this.clippingsSvc.refreshSyncedClippings(false);
}

this.showDialog = !(this.aeUtils.getPref("clippings.entries.add_silently", false));
Expand Down
3 changes: 2 additions & 1 deletion src/chrome/content/tbMsgComposeOverlay.js
Expand Up @@ -653,7 +653,7 @@ window.aecreations.clippings = {

let syncDirURL = this.aeUtils.getURLFromFilePath(syncDirPath);
this.clippingsSvc.setSyncDir(syncDirURL);
this.clippingsSvc.refreshSyncedClippings();
this.clippingsSvc.refreshSyncedClippings(false);
}

// Attaching event handler to context menu
Expand All @@ -675,6 +675,7 @@ window.aecreations.clippings = {
that.initClippingsPopup(popup, menu);
},

syncLocationChanged: function (aSyncURL) {},
newFolderCreated: function (aFolderURI) {},
newClippingCreated: function (aClippingURI) {},
importDone: function (aNumItems) {}
Expand Down
24 changes: 22 additions & 2 deletions src/components/aeClippingsService.js
Expand Up @@ -1702,7 +1702,7 @@ aeClippingsService.prototype.refreshDataSrc = function ()
};


aeClippingsService.prototype.refreshSyncedClippings = function ()
aeClippingsService.prototype.refreshSyncedClippings = function (aNotify)
{
let that = this;

Expand Down Expand Up @@ -1783,6 +1783,10 @@ aeClippingsService.prototype.refreshSyncedClippings = function ()
let syncCount = that._importFromJSONHelper(that.kSyncFolderURI, jsonSyncData.userClippingsRoot, false, shortcutKeyLookup);

that._log("aeClippingsService.refreshSyncedClippings(): Refresh of Sync Clippings data completed: " + syncCount + " items synchronized.");

if (aNotify) {
that.notifySyncLocationChanged();
}
});
};

Expand Down Expand Up @@ -2037,13 +2041,29 @@ aeClippingsService.prototype.notifyDataSrcLocationChanged = function ()

for (let i = 0; i < this._listeners.length; i++) {
if (this._listeners[i]) {
this._log("aeClippingsService.notifyDataSrcLocationChange(): Notifying observer " + i + "; origin: " + this._listeners[i].origin + " (1 = Clippings Manager; 2 = host app window; 3 = New Clipping dialog)");
this._log("aeClippingsService.notifyDataSrcLocationChanged(): Notifying observer " + i + "; origin: " + this._listeners[i].origin + " (1 = Clippings Manager; 2 = host app window; 3 = New Clipping dialog)");
this._listeners[i].dataSrcLocationChanged(this._dsFileURL);
}
}
};


aeClippingsService.prototype.notifySyncLocationChanged = function ()
{
if (!this._dataSrc || !this._dsFileURL) {
throw Components.Exception("Datasource not initialized",
Components.results.NS_ERROR_NOT_INITIALIZED);
}

for (let i = 0; i < this._listeners.length; i++) {
if (this._listeners[i]) {
this._log("aeClippingsService.notifySyncLocationChanged(): Notifying observer " + i + "; origin: " + this._listeners[i].origin + " (1 = Clippings Manager; 2 = host app window; 3 = New Clipping dialog)");
this._listeners[i].syncLocationChanged(this._syncDirURL);
}
}
};


aeClippingsService.prototype.killDataSrc = function ()
{
this._log("aeClippingsService.killDataSrc(): URL of data source:\n"
Expand Down
8 changes: 7 additions & 1 deletion src/components/aeIClippingsService.idl
Expand Up @@ -23,6 +23,7 @@ interface aeIClippingsListener : nsISupports
void newClippingCreated(in uri aClippingURI);
void importDone(in size_t aNumItems);
void dataSrcLocationChanged(in uri aDataSrcURL);
void syncLocationChanged(in uri aSyncURL);
};


Expand Down Expand Up @@ -225,7 +226,7 @@ interface aeIClippingsService : nsISupports

void refreshDataSrc();

void refreshSyncedClippings();
void refreshSyncedClippings(in boolean aNotify);

void exportToFile(in uri aFileURL,
in short aFileType,
Expand Down Expand Up @@ -331,6 +332,11 @@ interface aeIClippingsService : nsISupports
*/
void notifyDataSrcLocationChanged();

/*
* Notifies all listeners that the sync file location has changed.
*/
void notifySyncLocationChanged();

void addListener(in aeIClippingsListener aListener);

void removeListener(in aeIClippingsListener aListener);
Expand Down

0 comments on commit ad7abdb

Please sign in to comment.