New extension pattern

This commit is contained in:
benweet 2013-05-27 00:38:13 +01:00
parent 1f0fea1428
commit 56fa0c5873
7 changed files with 85 additions and 88 deletions

View File

@ -68,7 +68,7 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
var importPaths = []; var importPaths = [];
_.each(paths, function(path) { _.each(paths, function(path) {
var syncIndex = createSyncIndex(path); var syncIndex = createSyncIndex(path);
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
core.showError('"' + fileDesc.title + '" was already imported'); core.showError('"' + fileDesc.title + '" was already imported');
return; return;
@ -87,7 +87,7 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
} }
// Check that file is not synchronized with an other one // Check that file is not synchronized with an other one
var syncIndex = createSyncIndex(path); var syncIndex = createSyncIndex(path);
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
var existingTitle = fileDesc.title; var existingTitle = fileDesc.title;
core.showError('File path is already synchronized with "' + existingTitle + '"'); core.showError('File path is already synchronized with "' + existingTitle + '"');
@ -101,7 +101,7 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
} }
var syncAttributes = createSyncAttributes(result.path, result.versionTag, content); var syncAttributes = createSyncAttributes(result.path, result.versionTag, content);
localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes); localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes);
callback(undefined, syncIndex, syncAttributes); callback(undefined, syncAttributes);
}); });
} }
@ -168,7 +168,7 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
_.each(changes, function(change) { _.each(changes, function(change) {
var syncAttributes = change.syncAttributes; var syncAttributes = change.syncAttributes;
var syncIndex = syncAttributes.syncIndex; var syncIndex = syncAttributes.syncIndex;
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
// No file corresponding (file may have been deleted locally) // No file corresponding (file may have been deleted locally)
if(fileDesc === undefined) { if(fileDesc === undefined) {
return; return;
@ -177,10 +177,10 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
// File deleted // File deleted
if (change.wasRemoved === true) { if (change.wasRemoved === true) {
core.showError('"' + localTitle + '" has been removed from Dropbox.'); core.showError('"' + localTitle + '" has been removed from Dropbox.');
core.fileManager.removeSync(syncIndex); core.fileManager.removeSync(syncAttributes);
return; return;
} }
var localContent = localStorage[fileDesc.index + ".content"]; var localContent = localStorage[fileDesc.fileIndex + ".content"];
var localContentChanged = syncAttributes.contentCRC != utils.crc32(localContent); var localContentChanged = syncAttributes.contentCRC != utils.crc32(localContent);
var file = change.stat; var file = change.stat;
var remoteContentCRC = utils.crc32(file.content); var remoteContentCRC = utils.crc32(file.content);
@ -194,7 +194,7 @@ define(["core", "utils", "extension-manager", "dropbox-helper"], function(core,
} }
// If file content changed // If file content changed
if(fileContentChanged && remoteContentChanged === true) { if(fileContentChanged && remoteContentChanged === true) {
localStorage[fileDesc.index + ".content"] = file.content; localStorage[fileDesc.fileIndex + ".content"] = file.content;
core.showMessage('"' + localTitle + '" has been updated from Dropbox.'); core.showMessage('"' + localTitle + '" has been updated from Dropbox.');
if(core.fileManager.isCurrentFile(fileDesc)) { if(core.fileManager.isCurrentFile(fileDesc)) {
updateFileTitles = false; // Done by next function updateFileTitles = false; // Done by next function

View File

@ -36,7 +36,7 @@ define( [ "jquery", "underscore" ], function($) {
$("#file-selector li:not(.stick)").empty(); $("#file-selector li:not(.stick)").empty();
_.each(sortedDescriptor, function(fileDescToPrint) { _.each(sortedDescriptor, function(fileDescToPrint) {
var a = $("<a>").html(composeTitle(fileDescToPrint.index)); var a = $("<a>").html(composeTitle(fileDescToPrint.fileIndex));
var li = $("<li>").append(a); var li = $("<li>").append(a);
if (fileDescToPrint === fileDesc) { if (fileDescToPrint === fileDesc) {
li.addClass("disabled"); li.addClass("disabled");

View File

@ -46,7 +46,7 @@ define( [ "jquery", "underscore" ], function($) {
publishDesc: publishDesc publishDesc: publishDesc
})); }));
lineElement.append($(removeButtonTemplate).click(function() { lineElement.append($(removeButtonTemplate).click(function() {
fileManager.removePublish(publishIndex); fileManager.removePublish(publishAttributes);
})); }));
publishList.append(lineElement); publishList.append(lineElement);
}); });

View File

@ -18,7 +18,7 @@ define([
.reduce(function(fileSystemDescriptor, fileIndex) { .reduce(function(fileSystemDescriptor, fileIndex) {
var title = localStorage[fileIndex + ".title"]; var title = localStorage[fileIndex + ".title"];
var fileDesc = { var fileDesc = {
index : fileIndex, fileIndex : fileIndex,
title : title, title : title,
syncLocations: {}, syncLocations: {},
publishLocations: {} publishLocations: {}
@ -52,8 +52,8 @@ define([
if(fileDesc === undefined) { if(fileDesc === undefined) {
localStorage.removeItem("file.current"); localStorage.removeItem("file.current");
} }
else if(fileDesc.index != TEMPORARY_FILE_INDEX) { else if(fileDesc.fileIndex != TEMPORARY_FILE_INDEX) {
localStorage["file.current"] = fileDesc.index; localStorage["file.current"] = fileDesc.fileIndex;
} }
}; };
@ -78,7 +78,7 @@ define([
extensionManager.onFileSelected(fileDesc); extensionManager.onFileSelected(fileDesc);
// Hide the viewer pencil button // Hide the viewer pencil button
if(fileDesc.index == TEMPORARY_FILE_INDEX) { if(fileDesc.fileIndex == TEMPORARY_FILE_INDEX) {
$(".action-edit-document").removeClass("hide"); $(".action-edit-document").removeClass("hide");
} }
else { else {
@ -86,7 +86,7 @@ define([
} }
// Recreate the editor // Recreate the editor
$("#wmd-input").val(localStorage[fileDesc.index + ".content"]); $("#wmd-input").val(localStorage[fileDesc.fileIndex + ".content"]);
core.createEditor(function() { core.createEditor(function() {
// Callback to save content when textarea changes // Callback to save content when textarea changes
fileManager.saveFile(); fileManager.saveFile();
@ -128,7 +128,7 @@ define([
// Create the file descriptor // Create the file descriptor
var fileDesc = { var fileDesc = {
index : fileIndex, fileIndex : fileIndex,
title : title, title : title,
syncLocations: syncLocations, syncLocations: syncLocations,
publishLocations: {} publishLocations: {}
@ -151,17 +151,17 @@ define([
} }
// Remove synchronized locations // Remove synchronized locations
_.each(fileDesc.syncLocations, function(syncAttributes, syncIndex) { _.each(fileDesc.syncLocations, function(syncAttributes) {
fileManager.removeSync(syncIndex, true); fileManager.removeSync(syncAttributes, true);
}); });
// Remove publish locations // Remove publish locations
_.each(fileDesc.publishLocations, function(publishAttributes, publishIndex) { _.each(fileDesc.publishLocations, function(publishAttributes) {
fileManager.removePublish(publishIndex); fileManager.removePublish(publishAttributes, true);
}); });
// Remove the index from the file list // Remove the index from the file list
var fileIndex = fileDesc.index; var fileIndex = fileDesc.fileIndex;
localStorage["file.list"] = localStorage["file.list"].replace(";" localStorage["file.list"] = localStorage["file.list"].replace(";"
+ fileIndex + ";", ";"); + fileIndex + ";", ";");
localStorage.removeItem(fileIndex + ".title"); localStorage.removeItem(fileIndex + ".title");
@ -176,29 +176,28 @@ define([
fileManager.saveFile = function() { fileManager.saveFile = function() {
var content = $("#wmd-input").val(); var content = $("#wmd-input").val();
var fileDesc = fileManager.getCurrentFile(); var fileDesc = fileManager.getCurrentFile();
localStorage[fileDesc.index + ".content"] = content; localStorage[fileDesc.fileIndex + ".content"] = content;
extensionManager.onFileChanged(fileDesc); extensionManager.onFileChanged(fileDesc);
synchronizer.notifyChange(fileDesc); synchronizer.notifyChange(fileDesc);
}; };
// Add a syncIndex (synchronized location) to a file // Add a synchronized location to a file
fileManager.addSync = function(fileDesc, syncIndex, syncAttributes) { fileManager.addSync = function(fileDesc, syncAttributes) {
localStorage[fileDesc.index + ".sync"] += syncIndex + ";"; localStorage[fileDesc.fileIndex + ".sync"] += syncAttributes.syncIndex + ";";
fileDesc.syncLocations[syncIndex] = syncAttributes; fileDesc.syncLocations[syncAttributes.syncIndex] = syncAttributes;
// addSync is only used for export, not for import // addSync is only used for export, not for import
extensionManager.onSyncExportSuccess(fileDesc, syncIndex, syncAttributes); extensionManager.onSyncExportSuccess(fileDesc, syncAttributes);
}; };
// Remove a syncIndex (synchronized location) // Remove a synchronized location
fileManager.removeSync = function(syncIndex, skipExtensions) { fileManager.removeSync = function(syncAttributes, skipExtensions) {
var fileDesc = fileManager.getFileFromSync(syncIndex); var fileDesc = fileManager.getFileFromSyncIndex(syncAttributes.syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
localStorage[fileDesc.index + ".sync"] = localStorage[fileDesc.index + ".sync"].replace(";" localStorage[fileDesc.fileIndex + ".sync"] = localStorage[fileDesc.fileIndex + ".sync"].replace(";"
+ syncIndex + ";", ";"); + syncAttributes.syncIndex + ";", ";");
} }
// Remove sync attributes // Remove sync attributes
localStorage.removeItem(syncIndex); localStorage.removeItem(syncAttributes.syncIndex);
var syncAttributes = fileDesc.syncLocations[syncIndex];
fileDesc.syncLocations.removeItem(syncIndex); fileDesc.syncLocations.removeItem(syncIndex);
if(!skipExtensions) { if(!skipExtensions) {
extensionManager.onSyncRemoved(fileDesc, syncAttributes); extensionManager.onSyncRemoved(fileDesc, syncAttributes);
@ -206,7 +205,7 @@ define([
}; };
// Get the file descriptor associated to a syncIndex // Get the file descriptor associated to a syncIndex
fileManager.getFileFromSync = function(syncIndex) { fileManager.getFileFromSyncIndex = function(syncIndex) {
return _.find(fileSystemDescriptor, function(fileDesc) { return _.find(fileSystemDescriptor, function(fileDesc) {
return _.has(fileDesc.syncLocations, syncIndex); return _.has(fileDesc.syncLocations, syncIndex);
}); });
@ -214,7 +213,7 @@ define([
// Get syncAttributes from syncIndex // Get syncAttributes from syncIndex
fileManager.getSyncAttributes = function(syncIndex) { fileManager.getSyncAttributes = function(syncIndex) {
var fileDesc = fileManager.getFileFromSync(syncIndex); var fileDesc = fileManager.getFileFromSyncIndex(syncIndex);
return fileDesc && fileDesc.syncLocations[syncIndex]; return fileDesc && fileDesc.syncLocations[syncIndex];
}; };
@ -228,25 +227,24 @@ define([
}; };
// Add a publishIndex (publish location) to a file // Add a publishIndex (publish location) to a file
fileManager.addPublish = function(fileDesc, publishIndex, publishAttributes) { fileManager.addPublish = function(fileDesc, publishAttributes) {
localStorage[fileDesc.index + ".publish"] += publishIndex + ";"; localStorage[fileDesc.fileIndex + ".publish"] += publishAttributes.publishIndex + ";";
fileDesc.publishLocations[publishIndex] = publishAttributes; fileDesc.publishLocations[publishAttributes.publishIndex] = publishAttributes;
extensionManager.onNewPublishSuccess(fileDesc, publishIndex, publishAttributes); extensionManager.onNewPublishSuccess(fileDesc, publishAttributes);
}; };
// Remove a publishIndex (publish location) // Remove a publishIndex (publish location)
fileManager.removePublish = function(publishIndex, skipExtensions) { fileManager.removePublish = function(publishAttributes, skipExtensions) {
var fileDesc = fileManager.getFileFromPublish(publishIndex); var fileDesc = fileManager.getFileFromPublish(publishAttributes.publishIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
localStorage[fileDesc.index + ".publish"] = localStorage[fileDesc.index + ".publish"].replace(";" localStorage[fileDesc.fileIndex + ".publish"] = localStorage[fileDesc.fileIndex + ".publish"].replace(";"
+ publishIndex + ";", ";"); + publishAttributes.publishIndex + ";", ";");
if(fileManager.isCurrentFile(fileDesc)) { if(fileManager.isCurrentFile(fileDesc)) {
publisher.notifyPublish(); publisher.notifyPublish();
} }
} }
// Remove publish attributes // Remove publish attributes
localStorage.removeItem(publishIndex); localStorage.removeItem(publishAttributes.publishIndex);
var publishAttributes = fileDesc.publishLocations[publishIndex];
fileDesc.publishLocations.removeItem(publishIndex); fileDesc.publishLocations.removeItem(publishIndex);
if(!skipExtensions) { if(!skipExtensions) {
extensionManager.onPublishRemoved(fileDesc, publishAttributes); extensionManager.onPublishRemoved(fileDesc, publishAttributes);
@ -308,7 +306,7 @@ define([
$("#file-title").show(); $("#file-title").show();
var title = $.trim(input.val()); var title = $.trim(input.val());
var fileDesc = fileManager.getCurrentFile(); var fileDesc = fileManager.getCurrentFile();
var fileIndexTitle = fileDesc.index + ".title"; var fileIndexTitle = fileDesc.fileIndex + ".title";
if (title) { if (title) {
if (title != localStorage[fileIndexTitle]) { if (title != localStorage[fileIndexTitle]) {
localStorage[fileIndexTitle] = title; localStorage[fileIndexTitle] = title;

View File

@ -9,6 +9,10 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
exportPreferencesInputIds: ["gdrive-parentid"] exportPreferencesInputIds: ["gdrive-parentid"]
}; };
function createSyncIndex(id) {
return "sync." + PROVIDER_GDRIVE + "." + id;
}
function createSyncAttributes(id, etag, content, title) { function createSyncAttributes(id, etag, content, title) {
var syncAttributes = {}; var syncAttributes = {};
syncAttributes.provider = gdriveProvider; syncAttributes.provider = gdriveProvider;
@ -16,13 +20,10 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
syncAttributes.etag = etag; syncAttributes.etag = etag;
syncAttributes.contentCRC = utils.crc32(content); syncAttributes.contentCRC = utils.crc32(content);
syncAttributes.titleCRC = utils.crc32(title); syncAttributes.titleCRC = utils.crc32(title);
syncAttributes.syncIndex = createSyncIndex(id);
return syncAttributes; return syncAttributes;
} }
function createSyncIndex(id) {
return "sync." + PROVIDER_GDRIVE + "." + id;
}
function importFilesFromIds(ids) { function importFilesFromIds(ids) {
googleHelper.downloadMetadata(ids, function(error, result) { googleHelper.downloadMetadata(ids, function(error, result) {
if(error) { if(error) {
@ -35,10 +36,9 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
var fileDescList = []; var fileDescList = [];
_.each(result, function(file) { _.each(result, function(file) {
var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title); var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
var syncIndex = createSyncIndex(syncAttributes.id); localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes);
localStorage[syncIndex] = utils.serializeAttributes(syncAttributes);
var syncLocations = {}; var syncLocations = {};
syncLocations[syncIndex] = syncAttributes; syncLocations[syncAttributes.syncIndex] = syncAttributes;
var fileDesc = core.fileManager.createFile(file.title, file.content, syncLocations); var fileDesc = core.fileManager.createFile(file.title, file.content, syncLocations);
core.fileManager.selectFile(fileDesc); core.fileManager.selectFile(fileDesc);
fileDescList.push(fileDesc); fileDescList.push(fileDesc);
@ -56,7 +56,7 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
var importIds = []; var importIds = [];
_.each(ids, function(id) { _.each(ids, function(id) {
var syncIndex = createSyncIndex(id); var syncIndex = createSyncIndex(id);
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
core.showError('"' + fileDesc.title + '" was already imported'); core.showError('"' + fileDesc.title + '" was already imported');
return; return;
@ -75,9 +75,8 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
return; return;
} }
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title); var syncAttributes = createSyncAttributes(result.id, result.etag, content, title);
var syncIndex = createSyncIndex(syncAttributes.id); localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes);
localStorage[syncIndex] = utils.serializeAttributes(syncAttributes); callback(undefined, syncAttributes);
callback(undefined, syncIndex, syncAttributes);
}); });
}; };
@ -88,7 +87,7 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
} }
// Check that file is not synchronized with an other one // Check that file is not synchronized with an other one
var syncIndex = createSyncIndex(id); var syncIndex = createSyncIndex(id);
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
core.showError('File ID is already synchronized with "' + fileDesc.title + '"'); core.showError('File ID is already synchronized with "' + fileDesc.title + '"');
callback(true); callback(true);
@ -100,9 +99,8 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
return; return;
} }
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title); var syncAttributes = createSyncAttributes(result.id, result.etag, content, title);
var syncIndex = createSyncIndex(syncAttributes.id); localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes);
localStorage[syncIndex] = utils.serializeAttributes(syncAttributes); callback(undefined, syncAttributes);
callback(undefined, syncIndex, syncAttributes);
}); });
}; };
@ -140,8 +138,8 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
if(syncAttributes === undefined) { if(syncAttributes === undefined) {
return; return;
} }
// Store syncIndex to avoid 2 times formating // Store syncAttributes to avoid 2 times searching
change.syncIndex = syncIndex; change.syncAttributes = syncAttributes;
// Delete // Delete
if(change.deleted === true) { if(change.deleted === true) {
interestingChanges.push(change); interestingChanges.push(change);
@ -150,8 +148,6 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
// Modify // Modify
if(syncAttributes.etag != change.file.etag) { if(syncAttributes.etag != change.file.etag) {
interestingChanges.push(change); interestingChanges.push(change);
// Store syncAttributes to avoid 2 times searching
change.syncAttributes = syncAttributes;
} }
}); });
googleHelper.downloadContent(interestingChanges, function(error, changes) { googleHelper.downloadContent(interestingChanges, function(error, changes) {
@ -161,8 +157,9 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
} }
var updateFileTitles = false; var updateFileTitles = false;
_.each(changes, function(change) { _.each(changes, function(change) {
var syncIndex = change.syncIndex; var syncAttributes = change.syncAttributes;
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var syncIndex = syncAttributes.syncIndex;
var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
// No file corresponding (file may have been deleted locally) // No file corresponding (file may have been deleted locally)
if(fileDesc === undefined) { if(fileDesc === undefined) {
return; return;
@ -171,12 +168,11 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
// File deleted // File deleted
if (change.deleted === true) { if (change.deleted === true) {
core.showError('"' + localTitle + '" has been removed from Google Drive.'); core.showError('"' + localTitle + '" has been removed from Google Drive.');
core.fileManager.removeSync(syncIndex); core.fileManager.removeSync(syncAttributes);
return; return;
} }
var syncAttributes = change.syncAttributes;
var localTitleChanged = syncAttributes.titleCRC != utils.crc32(localTitle); var localTitleChanged = syncAttributes.titleCRC != utils.crc32(localTitle);
var localContent = localStorage[fileDesc.index + ".content"]; var localContent = localStorage[fileDesc.fileIndex + ".content"];
var localContentChanged = syncAttributes.contentCRC != utils.crc32(localContent); var localContentChanged = syncAttributes.contentCRC != utils.crc32(localContent);
var file = change.file; var file = change.file;
var remoteTitleCRC = utils.crc32(file.title); var remoteTitleCRC = utils.crc32(file.title);
@ -194,14 +190,14 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
} }
// If file title changed // If file title changed
if(fileTitleChanged && remoteTitleChanged === true) { if(fileTitleChanged && remoteTitleChanged === true) {
localStorage[fileDesc.index + ".title"] = file.title; localStorage[fileDesc.fileIndex + ".title"] = file.title;
fileDesc.title = file.title; fileDesc.title = file.title;
updateFileTitles = true; updateFileTitles = true;
core.showMessage('"' + localTitle + '" has been renamed to "' + file.title + '" on Google Drive.'); core.showMessage('"' + localTitle + '" has been renamed to "' + file.title + '" on Google Drive.');
} }
// If file content changed // If file content changed
if(fileContentChanged && remoteContentChanged === true) { if(fileContentChanged && remoteContentChanged === true) {
localStorage[fileDesc.index + ".content"] = file.content; localStorage[fileDesc.fileIndex + ".content"] = file.content;
core.showMessage('"' + file.title + '" has been updated from Google Drive.'); core.showMessage('"' + file.title + '" has been updated from Google Drive.');
if(core.fileManager.isCurrentFile(fileDesc)) { if(core.fileManager.isCurrentFile(fileDesc)) {
updateFileTitles = false; // Done by next function updateFileTitles = false; // Done by next function
@ -264,8 +260,11 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
if(error) { if(error) {
return; return;
} }
var syncIndex = createSyncAttributes(file.id, file.etag, file.content, file.title); var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
var fileDesc = core.fileManager.createFile(file.title, file.content, [syncIndex]); localStorage[syncAttributes.syncIndex] = utils.serializeAttributes(syncAttributes);
var syncLocations = {};
syncLocations[syncAttributes.syncIndex] = syncAttributes;
var fileDesc = core.fileManager.createFile(file.title, file.content, syncAttributes);
core.fileManager.selectFile(fileDesc); core.fileManager.selectFile(fileDesc);
core.showMessage('"' + file.title + '" created successfully on Google Drive.'); core.showMessage('"' + file.title + '" created successfully on Google Drive.');
}); });
@ -274,7 +273,7 @@ define(["core", "utils", "extension-manager", "google-helper", "underscore"], fu
var importIds = []; var importIds = [];
_.each(state.ids, function(id) { _.each(state.ids, function(id) {
var syncIndex = createSyncIndex(id); var syncIndex = createSyncIndex(id);
var fileDesc = core.fileManager.getFileFromSync(syncIndex); var fileDesc = core.fileManager.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
core.fileManager.selectFile(fileDesc); core.fileManager.selectFile(fileDesc);
} }

View File

@ -96,8 +96,7 @@ define([
} }
// Dequeue a synchronized location // Dequeue a synchronized location
var publishIndex = publishAttributesList.pop(); var publishAttributes = publishAttributesList.pop();
var publishAttributes = JSON.parse(localStorage[publishIndex]);
var content = getPublishContent(publishAttributes); var content = getPublishContent(publishAttributes);
// Call the provider // Call the provider
@ -106,7 +105,7 @@ define([
if(error !== undefined) { if(error !== undefined) {
var errorMsg = error.toString(); var errorMsg = error.toString();
if(errorMsg.indexOf("|removePublish") !== -1) { if(errorMsg.indexOf("|removePublish") !== -1) {
core.fileManager.removePublish(publishIndex); core.fileManager.removePublish(publishAttributes);
} }
if(errorMsg.indexOf("|stopPublish") !== -1) { if(errorMsg.indexOf("|stopPublish") !== -1) {
callback(error); callback(error);
@ -144,8 +143,9 @@ define([
do { do {
publishIndex = "publish." + utils.randomString(); publishIndex = "publish." + utils.randomString();
} while(_.has(localStorage, publishIndex)); } while(_.has(localStorage, publishIndex));
publishAttributes.publishIndex = publishIndex;
localStorage[publishIndex] = JSON.stringify(publishAttributes); localStorage[publishIndex] = JSON.stringify(publishAttributes);
core.fileManager.addPublish(fileDesc, publishIndex, publishAttributes); core.fileManager.addPublish(fileDesc, publishAttributes);
} }
// Initialize the "New publication" dialog // Initialize the "New publication" dialog
@ -210,7 +210,7 @@ define([
// Retrieve file's publish locations from localStorage // Retrieve file's publish locations from localStorage
publisher.populatePublishLocations = function(fileDesc) { publisher.populatePublishLocations = function(fileDesc) {
_.chain(localStorage[fileDesc.index + ".publish"].split(";")) _.chain(localStorage[fileDesc.fileIndex + ".publish"].split(";"))
.compact() .compact()
.each(function(publishIndex) { .each(function(publishIndex) {
var publishAttributes = JSON.parse(localStorage[publishIndex]); var publishAttributes = JSON.parse(localStorage[publishIndex]);

View File

@ -108,7 +108,7 @@ define([
} }
// Get document title/content // Get document title/content
uploadContent = localStorage[fileDesc.index + ".content"]; uploadContent = localStorage[fileDesc.fileIndex + ".content"];
uploadContentCRC = utils.crc32(uploadContent); uploadContentCRC = utils.crc32(uploadContent);
uploadTitle = fileDesc.title; uploadTitle = fileDesc.title;
uploadTitleCRC = utils.crc32(uploadTitle); uploadTitleCRC = utils.crc32(uploadTitle);
@ -202,7 +202,7 @@ define([
// Retrieve file's sync locations from localStorage // Retrieve file's sync locations from localStorage
publisher.populateSyncLocations = function(fileDesc) { publisher.populateSyncLocations = function(fileDesc) {
_.chain(localStorage[fileDesc.index + ".sync"].split(";")) _.chain(localStorage[fileDesc.fileIndex + ".sync"].split(";"))
.compact() .compact()
.each(function(syncIndex) { .each(function(syncIndex) {
var syncAttributes = JSON.parse(localStorage[syncIndex]); var syncAttributes = JSON.parse(localStorage[syncIndex]);
@ -249,12 +249,12 @@ define([
// Perform the provider's export // Perform the provider's export
var fileDesc = core.fileManager.getCurrentFile(); var fileDesc = core.fileManager.getCurrentFile();
var title = fileDesc.title; var title = fileDesc.title;
var content = localStorage[fileDesc.index + ".content"]; var content = localStorage[fileDesc.fileIndex + ".content"];
provider.exportFile(event, title, content, function(error, syncIndex, syncAttributes) { provider.exportFile(event, title, content, function(error, syncAttributes) {
if(error) { if(error) {
return; return;
} }
core.fileManager.addSync(fileDesc, syncIndex, syncAttributes); core.fileManager.addSync(fileDesc, syncAttributes);
}); });
// Store input values as preferences for next time we open the export dialog // Store input values as preferences for next time we open the export dialog
@ -268,12 +268,12 @@ define([
$(".action-sync-manual-" + provider.providerId).click(function(event) { $(".action-sync-manual-" + provider.providerId).click(function(event) {
var fileDesc = core.fileManager.getCurrentFile(); var fileDesc = core.fileManager.getCurrentFile();
var title = fileDesc.title; var title = fileDesc.title;
var content = localStorage[fileDesc.index + ".content"]; var content = localStorage[fileDesc.fileIndex + ".content"];
provider.exportManual(event, title, content, function(error, syncIndex, syncAttributes) { provider.exportManual(event, title, content, function(error, syncAttributes) {
if(error) { if(error) {
return; return;
} }
core.fileManager.addSync(fileDesc, syncIndex, syncAttributes); core.fileManager.addSync(fileDesc, syncAttributes);
}); });
}); });
}); });