-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENYO-1020: implement "Save As" under the Text Editor #243
Changes from 19 commits
2e6594a
70c27b5
339007f
38053bb
537b486
5d6c9c5
10eecb9
26ba6fa
d0b53bc
473c47e
060d91a
469e3b4
24cd519
a9dda05
dc13cdc
80ac06c
3156e11
b85335c
dc8be21
7c0f3dd
0b63dd1
742da01
a846119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,14 @@ enyo.kind({ | |
components: [ | ||
{kind: "Panels", arrangerKind: "CarouselArranger", draggable: false, classes:"enyo-fit ares-panels", components: [ | ||
{components: [ | ||
{kind: "Phobos", onSaveDocument: "saveDocument", onCloseDocument: "closeDocument", onDesignDocument: "designDocument", onUpdate: "phobosUpdate"} | ||
{kind: "Phobos", onSaveDocument: "saveDocument", onSaveAsDocument: "saveAsDocument", onCloseDocument: "closeDocument", onDesignDocument: "designDocument", onUpdate: "phobosUpdate"} | ||
]}, | ||
{components: [ | ||
{kind: "Deimos", onCloseDesigner: "closeDesigner", onDesignerUpdate: "designerUpdate", onUndo: "designerUndo", onRedo: "designerRedo"} | ||
]} | ||
]}, | ||
{kind: "Slideable", layoutKind: "FittableRowsLayout", classes: "onyx ares-files-slider", axis: "v", value: 0, min: -500, max: 0, unit: "px", onAnimateFinish: "finishedSliding", components: [ | ||
{kind: "ProjectView", fit: true, classes: "onyx", onFileDblClick: "doubleclickFile", onProjectSelected: "projectSelected"}, | ||
{name: "projectView", kind: "ProjectView", fit: true, classes: "onyx", onFileDblClick: "openDocument", onProjectSelected: "projectSelected"}, | ||
{name: "bottomBar", kind: "DocumentToolbar", | ||
onToggleOpen: "toggleFiles", | ||
onSwitchFile: "switchFile", | ||
|
@@ -24,15 +24,15 @@ enyo.kind({ | |
} | ||
]}, | ||
{name: "waitPopup", kind: "onyx.Popup", centered: true, floating: true, autoDismiss: false, modal: true, style: "text-align: center; padding: 20px;", components: [ | ||
{kind: "Image", src: "$phobos/images/save-spinner.gif", style: "width: 54px; height: 55px;"}, | ||
{kind: "Image", src: "$phobos/assets/images/save-spinner.gif", style: "width: 54px; height: 55px;"}, | ||
{name: "waitPopupMessage", content: "Ongoing...", style: "padding-top: 10px;"} | ||
]}, | ||
{kind: "ServiceRegistry"} | ||
], | ||
handlers: { | ||
onReloadServices: "handleReloadServices", | ||
onUpdateAuth: "handleUpdateAuth", | ||
onShowWaitPopup: "handleShowWaitPopup", | ||
onShowWaitPopup: "showWaitPopup", | ||
onHideWaitPopup: "hideWaitPopup" | ||
}, | ||
phobosViewIndex: 0, | ||
|
@@ -71,65 +71,148 @@ enyo.kind({ | |
if (this.debug) this.log("sender:", inSender, ", event:", inEvent); | ||
this.$.serviceRegistry.setConfig(inEvent.serviceId, {auth: inEvent.auth}, inEvent.next); | ||
}, | ||
doubleclickFile: function(inSender, inEvent) { | ||
var f = inEvent.file; | ||
var id = Ares.Workspace.files.computeId(f); | ||
var d = Ares.Workspace.files.get(id); | ||
if (d) { | ||
this.switchToDocument(d); | ||
} else { | ||
this.$.bottomBar.createFileTab(f.name, id); | ||
this.$.slideable.setDraggable(true); | ||
this.openDocument(inSender, inEvent); | ||
} | ||
}, | ||
projectSelected: function() { | ||
setTimeout(enyo.bind(this, function() { this.$.deimos.projectSelected(this.$.projectView.currentProject); }), 500); // <-- TODO - using timeout here because project url is set asynchronously | ||
return true; | ||
}, | ||
openDocument: function(inSender, inEvent) { | ||
var f = inEvent.file; | ||
var projectData = inEvent.projectData; | ||
|
||
var service = projectData.getService(); | ||
this.$.phobos.beginOpenDoc(); | ||
service.getFile(f.id) | ||
.response(this, function(inEvent, inData) { | ||
if (inData.content) { | ||
inData=inData.content; | ||
this._openDocument(inEvent.projectData, inEvent.file, function(inErr) {}); | ||
}, | ||
/** @private */ | ||
_openDocument: function(projectData, file, next) { | ||
var self = this; | ||
var fileDataId = Ares.Workspace.files.computeId(file); | ||
var fileData = Ares.Workspace.files.get(fileDataId); | ||
if (fileData) { | ||
this.switchToDocument(fileData); | ||
} else { | ||
this.showWaitPopup(this, {msg: $L("Opening...")}); | ||
this.$.bottomBar.createFileTab(file.name, fileDataId); | ||
this.$.slideable.setDraggable(true); | ||
this._fetchDocument(projectData, file, function(inErr, inContent) { | ||
self.hideWaitPopup(); | ||
if (inErr) { | ||
self.warn("Open failed", inErr); | ||
} else { | ||
// no data? Empty file | ||
inData=""; | ||
} | ||
var id = Ares.Workspace.files.computeId(f); | ||
if (Ares.Workspace.files.get(id)) { | ||
alert("Duplicate File ID in cache!"); | ||
fileData = Ares.Workspace.files.newEntry(file, inContent, projectData); | ||
self.switchToDocument(fileData); | ||
} | ||
var doc = Ares.Workspace.files.newEntry(f, inData, projectData); | ||
this.switchToDocument(doc); | ||
}) | ||
.error(this, function(inEvent, inData) { | ||
enyo.log("Open failed", inData); | ||
this.$.phobos.hideWaitPopup(); | ||
}); | ||
} | ||
}, | ||
saveDocument: function(inSender, inEvent) { | ||
var service = inEvent.file.service; | ||
service.putFile(inEvent.file.id, inEvent.content) | ||
/** @private */ | ||
_fetchDocument: function(projectData, file, next) { | ||
if (this.debug) this.log("projectData:", projectData, ", file:", file); | ||
var service = projectData.getService(); | ||
service.getFile(file.id) | ||
.response(this, function(inEvent, inData) { | ||
inSender.saveComplete(); | ||
this.$.deimos.saveComplete(); | ||
next(null, inData && inData.content || ""); | ||
}) | ||
.error(this, function(inEvent, inData) { | ||
inSender.saveFailed(inData); | ||
.error(this, function(inEvent, inErr) { | ||
next(inErr); | ||
}); | ||
}, | ||
saveDocument: function(inSender, inEvent) { | ||
if (this.debug) this.log("sender:", inSender, ", event:", inEvent); | ||
var self = this; | ||
this._saveDocument(inEvent.content, {service: inEvent.file.service, fileId: inEvent.file.id}, function(err) { | ||
if (err) { | ||
self.$.phobos.saveFailed(err); | ||
} else { | ||
self.$.phobos.saveComplete(); | ||
self.$.deimos.saveComplete(); | ||
} | ||
}); | ||
}, | ||
_saveDocument: function(content, where, next) { | ||
var req; | ||
if (where.fileId) { | ||
req = where.service.putFile(where.fileId, content); | ||
} else { | ||
req = where.service.createFile(where.folderId, where.name, content); | ||
} | ||
req.response(this, function(inEvent, inData) { | ||
next(null, inData); | ||
}).error(this, function(inEvent, inErr) { | ||
next(inErr); | ||
}); | ||
|
||
}, | ||
saveAsDocument: function(inSender, inEvent) { | ||
if (this.debug) this.log("sender:", inSender, ", event:", inEvent); | ||
var self = this, | ||
file = inEvent.file, | ||
name = inEvent.name, | ||
content = inEvent.content; | ||
|
||
if (!file) { | ||
_footer(new Error("missing file/folder description")); | ||
return; | ||
} | ||
|
||
async.waterfall([ | ||
this._closeDocument.bind(this, inEvent.docId), | ||
function(next) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the purpose of this anonymous function is not easy to understand. You should either add a comment or put this function in a local variable with a descriptive name. The latter is preferred as the waterfall sequence would be easier to read |
||
var where, err; | ||
if (file.isDir && name) { | ||
// create given file in given dir | ||
where = { | ||
service: file.service, | ||
folderId: file.id, | ||
name: name | ||
}; | ||
} else if (!file.isDir && !name) { | ||
// overwrite the given file | ||
where = { | ||
service: file.service, | ||
fileId: file.id | ||
}; | ||
} else if (!file.isDir && name) { | ||
// create a new file in the same folder as the | ||
// given file | ||
where = { | ||
service: file.service, | ||
folderId: file.parent.id, | ||
name: name | ||
}; | ||
} else { | ||
err = new Error("wrong file/folder description"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe mention that's an internal error. |
||
} | ||
next(err, where); | ||
}, | ||
this._saveDocument.bind(this, inEvent.content), | ||
_savedToOpen.bind(this), | ||
this._openDocument.bind(this, inEvent.projectData) | ||
], _footer); | ||
|
||
function _savedToOpen(inData, next) { | ||
this.$.projectView.refreshFile(file); | ||
// FIXME: only HermesFileTree report built-in file#service | ||
var hermesFile = inData[0]; | ||
hermesFile.service = file.service; | ||
hermesFile.name = ares.basename(hermesFile.path); | ||
next(null, hermesFile); | ||
} | ||
|
||
function _footer(err, result) { | ||
if (self.debug) enyo.log("err:", err, "result:", result); | ||
if (typeof inEvent.next === 'function') { | ||
inEvent.next(err, result); | ||
} | ||
} | ||
}, | ||
closeDocument: function(inSender, inEvent) { | ||
if (this.debug) this.log("sender:", inSender, ", event:", inEvent); | ||
this._closeDocument(inEvent.id, function() {}); | ||
}, | ||
/** @private */ | ||
_closeDocument: function(docId, next) { | ||
// remove file from cache | ||
Ares.Workspace.files.removeEntry(inEvent.id); | ||
this.$.bottomBar.removeTab(inEvent.id); | ||
Ares.Workspace.files.removeEntry(docId); | ||
this.$.bottomBar.removeTab(docId); | ||
this.$.slideable.setDraggable(Ares.Workspace.files.length > 0); | ||
this.showFiles(); | ||
next(); | ||
}, | ||
designDocument: function(inSender, inEvent) { | ||
this.syncEditedFiles(); | ||
|
@@ -282,11 +365,8 @@ enyo.kind({ | |
syncJSFile: function(inCode) { | ||
this.$.deimos.syncJSFile(inCode); | ||
}, | ||
handleShowWaitPopup: function(inSender, inEvent) { | ||
this.showWaitPopup(inEvent.msg); | ||
}, | ||
showWaitPopup: function(inMessage) { | ||
this.$.waitPopupMessage.setContent(inMessage); | ||
showWaitPopup: function(inSender, inEvent) { | ||
this.$.waitPopupMessage.setContent(inEvent.msg); | ||
this.$.waitPopup.show(); | ||
}, | ||
hideWaitPopup: function() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
enyo.depends( | ||
"Ares.js", | ||
"DocumentToolbar.js" | ||
"DocumentToolbar.js", | ||
"FileData.js", | ||
"WorkspaceData.js" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 2 classes with the same properties ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although they have the same properties now (and their visual look is equally ugly), they are not use at the same place & I expect them to evolve differently as @opopova will work on them.