distinguished project name from scene names

also removed hidden "export as plain text" option
snap7
jmoenig 2021-05-21 14:28:03 +02:00
rodzic 498c4c8edf
commit 45376a2977
2 zmienionych plików z 73 dodań i 80 usunięć

Wyświetl plik

@ -10,6 +10,7 @@
### 2021-05-21 ### 2021-05-21
* gui, scenes, store: proxied thumbnail, name and notes in project, restored in XML * gui, scenes, store: proxied thumbnail, name and notes in project, restored in XML
* gui: distinguished project name from scene names, removed hidden "export as plain text" option
### 2021-05-20 ### 2021-05-20
* gui: marked projectName to be refactored and sceneified * gui: marked projectName to be refactored and sceneified

Wyświetl plik

@ -248,8 +248,7 @@ IDE_Morph.prototype.init = function (isAutoFill) {
this.globalVariables = this.scene.globalVariables; this.globalVariables = this.scene.globalVariables;
this.currentSprite = this.scene.addDefaultSprite(); this.currentSprite = this.scene.addDefaultSprite();
this.sprites = this.scene.sprites; this.sprites = this.scene.sprites;
this.projectName = this.scene.name; this.projectNotes = this.scene.notes; // +++ sceneify rename to scene notes
this.projectNotes = this.scene.notes;
this.currentCategory = 'motion'; this.currentCategory = 'motion';
this.currentTab = 'scripts'; this.currentTab = 'scripts';
@ -1189,7 +1188,7 @@ IDE_Morph.prototype.createControlBar = function () {
return; return;
} }
txt = new StringMorph( txt = new StringMorph(
prefix + (myself.projectName || localize('untitled')) + suffix, prefix + (myself.scene.name || localize('untitled')) + suffix,
14, 14,
'sans-serif', 'sans-serif',
true, true,
@ -2113,10 +2112,24 @@ IDE_Morph.prototype.fixLayout = function (situation) {
} }
}; };
IDE_Morph.prototype.setProjectName = function (string) { // ++++ change to scene name / distinguish scene name an project name // IDE_Morph project name
this.projectName = string.replace(/['"]/g, ''); // filter quotation marks
this.hasChangedMedia = true; IDE_Morph.prototype.getProjectName = function () {
this.controlBar.updateLabel(); return this.scenes.at(1).name;
};
IDE_Morph.prototype.setProjectName = function (string) {
var projectScene = this.scenes.at(1),
name = this.newSceneName(string, projectScene);
if (name !== projectScene.name) {
projectScene.name = name;
projectScene.stage.version = Date.now();
this.hasChangedMedia = true; // +++ sceneify this
if (projectScene === this.scene) {
this.controlBar.updateLabel();
}
}
return name;
}; };
// IDE_Morph resizing // IDE_Morph resizing
@ -3213,10 +3226,11 @@ IDE_Morph.prototype.newSpriteName = function (name, ignoredSprite) {
}; };
IDE_Morph.prototype.newSceneName = function (name, ignoredScene) { IDE_Morph.prototype.newSceneName = function (name, ignoredScene) {
var all = this.scenes.asArray().filter(each => var sName = name.replace(/['"]/g, ''), // filter out quotation marks
all = this.scenes.asArray().filter(each =>
each !== ignoredScene each !== ignoredScene
).map(each => each.name); ).map(each => each.name);
return this.newName(name, all); return this.newName(sName, all);
}; };
IDE_Morph.prototype.newName = function (name, elements) { IDE_Morph.prototype.newName = function (name, elements) {
@ -3362,8 +3376,9 @@ IDE_Morph.prototype.cloudMenu = function () {
menu.addItem( menu.addItem(
'export project media only...', 'export project media only...',
() => { () => {
if (this.projectName) { var pn = this.getProjectName();
this.exportProjectMedia(this.projectName); if (pn) {
this.exportProjectMedia(pn);
} else { } else {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
@ -3379,8 +3394,9 @@ IDE_Morph.prototype.cloudMenu = function () {
menu.addItem( menu.addItem(
'export project without media...', 'export project without media...',
() => { () => {
if (this.projectName) { var pn = this.getProjectName();
this.exportProjectNoMedia(this.projectName); if (pn) {
this.exportProjectNoMedia(pn);
} else { } else {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
@ -3396,8 +3412,9 @@ IDE_Morph.prototype.cloudMenu = function () {
menu.addItem( menu.addItem(
'export project as cloud data...', 'export project as cloud data...',
() => { () => {
if (this.projectName) { var pn = this.getProjectName();
this.exportProjectAsCloudData(this.projectName); if (pn) {
this.exportProjectAsCloudData(pn);
} else { } else {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
@ -3983,46 +4000,22 @@ IDE_Morph.prototype.projectMenu = function () {
'importLocalFile', 'importLocalFile',
'file menu import hint' // looks up the actual text in the translator 'file menu import hint' // looks up the actual text in the translator
); );
if (shiftClicked) {
menu.addItem(
localize(
'Export project...') + ' ' + localize('(in a new window)'
),
() => {
if (this.projectName) {
this.exportProject(this.projectName, shiftClicked);
} else {
this.prompt(
'Export Project As...',
// false - override the shiftClick setting to use XML:
name => this.exportProject(name, false),
null,
'exportProject'
);
}
},
'show project data as XML\nin a new browser window',
new Color(100, 0, 0)
);
}
menu.addItem( menu.addItem(
shiftClicked ? 'Export project...',
'Export project as plain text...' : 'Export project...',
() => { () => {
if (this.projectName) { var pn = this.getProjectName();
this.exportProject(this.projectName, shiftClicked); if (this.pn) {
this.exportProject(pn);
} else { } else {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
name => this.exportProject(name, shiftClicked), name => this.exportProject(name),
null, null,
'exportProject' 'exportProject'
); );
} }
}, },
'save project data as XML\nto your downloads folder', 'save project data as XML\nto your downloads folder'
shiftClicked ? new Color(100, 0, 0) : null
); );
if (this.stage.globalBlocks.length) { if (this.stage.globalBlocks.length) {
@ -4721,13 +4714,14 @@ IDE_Morph.prototype.createNewScene = function () { // +++
IDE_Morph.prototype.save = function () { IDE_Morph.prototype.save = function () {
// temporary hack - only allow exporting projects to disk // temporary hack - only allow exporting projects to disk
// when running Snap! locally without a web server // when running Snap! locally without a web server
var pn = this.getProjectName();
if (location.protocol === 'file:') { if (location.protocol === 'file:') {
if (this.projectName) { if (pn) {
this.exportProject(this.projectName, false); this.exportProject(pn);
} else { } else {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
name => this.exportProject(name, false), name => this.exportProject(name),
null, null,
'exportProject' 'exportProject'
); );
@ -4742,11 +4736,11 @@ IDE_Morph.prototype.save = function () {
if (this.cloud.disabled) {this.source = 'disk'; } if (this.cloud.disabled) {this.source = 'disk'; }
if (this.projectName) { if (pn) {
if (this.source === 'disk') { if (this.source === 'disk') {
this.exportProject(this.projectName); this.exportProject(pn);
} else if (this.source === 'cloud') { } else if (this.source === 'cloud') {
this.saveProjectToCloud(this.projectName); this.saveProjectToCloud(pn);
} else { } else {
this.saveProjectsBrowser(); this.saveProjectsBrowser();
} }
@ -4755,22 +4749,17 @@ IDE_Morph.prototype.save = function () {
} }
}; };
IDE_Morph.prototype.exportProject = function (name, plain) { IDE_Morph.prototype.exportProject = function (name) {
// Export project XML, saving a file to disk // Export project XML, saving a file to disk
// newWindow requests displaying the project in a new tab. var menu, str;
var menu, str, dataPrefix;
name = this.scenes.at(1).name; // +++++
if (name) { if (name) {
this.setProjectName(name); name = this.setProjectName(name);
dataPrefix = 'data:text/' + plain ? 'plain,' : 'xml,';
try { try {
menu = this.showMessage('Exporting'); menu = this.showMessage('Exporting');
str = this.serializer.serialize( str = this.serializer.serialize(
new Project(this.scenes, this.scene) new Project(this.scenes, this.scene)
); );
this.setURL('#open:' + dataPrefix + encodeURIComponent(str)); this.setURL('#open:data:text/xml,' + encodeURIComponent(str));
this.saveXMLAs(str, name); this.saveXMLAs(str, name);
menu.destroy(); menu.destroy();
this.recordSavedChanges(); this.recordSavedChanges();
@ -4896,10 +4885,10 @@ IDE_Morph.prototype.exportScriptsPicture = function () {
y += padding; y += padding;
y += each.height; y += each.height;
}); });
this.saveCanvasAs(pic, this.projectName || localize('Untitled')); this.saveCanvasAs(pic, this.scene.name || localize('Untitled'));
}; };
IDE_Morph.prototype.exportProjectSummary = function (useDropShadows) { IDE_Morph.prototype.exportProjectSummary = function (useDropShadows) { // ++++ sceneify: make it "scene summary" and include it in the scene icon context menu
var html, head, meta, css, body, pname, notes, toc, globalVars, var html, head, meta, css, body, pname, notes, toc, globalVars,
stage = this.stage; stage = this.stage;
@ -4999,7 +4988,7 @@ IDE_Morph.prototype.exportProjectSummary = function (useDropShadows) {
} }
} }
pname = this.projectName || localize('untitled'); pname = this.getProjectName() || localize('untitled'); // ++++ sceneify
html = new XML_Element('html'); html = new XML_Element('html');
html.attributes.lang = SnapTranslator.language; html.attributes.lang = SnapTranslator.language;
@ -5474,7 +5463,7 @@ IDE_Morph.prototype.switchToScene = function (scene, refreshAlbum) {
); );
this.scene.captureGlobalSettings(); this.scene.captureGlobalSettings();
this.scene = scene; this.scene = scene;
this.projectName = scene.name; // +++ this.projectName = scene.name; // remove
this.projectNotes = scene.notes || ''; this.projectNotes = scene.notes || '';
this.globalVariables = scene.globalVariables; this.globalVariables = scene.globalVariables;
this.stage.destroy(); this.stage.destroy();
@ -5984,7 +5973,7 @@ IDE_Morph.prototype.saveProjectsBrowser = function () {
if (location.protocol === 'file:') { if (location.protocol === 'file:') {
this.prompt( this.prompt(
'Export Project As...', 'Export Project As...',
name => this.exportProject(name, false), name => this.exportProject(name),
null, null,
'exportProject' 'exportProject'
); );
@ -6609,7 +6598,7 @@ IDE_Morph.prototype.saveProjectToCloud = function (name) {
var projectBody, projectSize; var projectBody, projectSize;
if (name) { if (name) {
this.setProjectName(name); name = this.setProjectName(name);
} }
this.showMessage('Saving project\nto the cloud...'); this.showMessage('Saving project\nto the cloud...');
@ -6620,7 +6609,7 @@ IDE_Morph.prototype.saveProjectToCloud = function (name) {
'Uploading ' + Math.round(projectSize / 1024) + ' KB...' 'Uploading ' + Math.round(projectSize / 1024) + ' KB...'
); );
this.cloud.saveProject( this.cloud.saveProject(
this.projectName, name,
projectBody, projectBody,
() => { () => {
this.recordSavedChanges(); this.recordSavedChanges();
@ -6639,7 +6628,7 @@ IDE_Morph.prototype.exportProjectMedia = function (name) {
menu = this.showMessage('Exporting'); menu = this.showMessage('Exporting');
this.serializer.serialize(new Project(this.scenes, this.scene)); this.serializer.serialize(new Project(this.scenes, this.scene));
media = this.serializer.mediaXML(name); media = this.serializer.mediaXML(name);
this.saveXMLAs(media, this.projectName + ' media'); this.saveXMLAs(media, this.getProjectName() + ' media');
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} catch (err) { } catch (err) {
@ -6660,14 +6649,14 @@ IDE_Morph.prototype.exportProjectNoMedia = function (name) {
var menu, str; var menu, str;
this.serializer.isCollectingMedia = true; this.serializer.isCollectingMedia = true;
if (name) { if (name) {
this.setProjectName(name); name = this.setProjectName(name);
if (Process.prototype.isCatchingErrors) { if (Process.prototype.isCatchingErrors) {
try { try {
menu = this.showMessage('Exporting'); menu = this.showMessage('Exporting');
str = this.serializer.serialize( str = this.serializer.serialize(
new Project(this.scenes, this.scene) new Project(this.scenes, this.scene)
); );
this.saveXMLAs(str, this.projectName); this.saveXMLAs(str, name);
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} catch (err) { } catch (err) {
@ -6679,7 +6668,7 @@ IDE_Morph.prototype.exportProjectNoMedia = function (name) {
str = this.serializer.serialize( str = this.serializer.serialize(
new Project(this.scenes, this.scene) new Project(this.scenes, this.scene)
); );
this.saveXMLAs(str, this.projectName); this.saveXMLAs(str, name);
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} }
@ -6692,7 +6681,7 @@ IDE_Morph.prototype.exportProjectAsCloudData = function (name) {
var menu, str, media, dta; var menu, str, media, dta;
this.serializer.isCollectingMedia = true; this.serializer.isCollectingMedia = true;
if (name) { if (name) {
this.setProjectName(name); name = this.setProjectName(name);
if (Process.prototype.isCatchingErrors) { if (Process.prototype.isCatchingErrors) {
try { try {
menu = this.showMessage('Exporting'); menu = this.showMessage('Exporting');
@ -6701,7 +6690,7 @@ IDE_Morph.prototype.exportProjectAsCloudData = function (name) {
); );
media = this.serializer.mediaXML(name); media = this.serializer.mediaXML(name);
dta = '<snapdata>' + str + media + '</snapdata>'; dta = '<snapdata>' + str + media + '</snapdata>';
this.saveXMLAs(dta, this.projectName); this.saveXMLAs(dta, name);
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} catch (err) { } catch (err) {
@ -6715,7 +6704,7 @@ IDE_Morph.prototype.exportProjectAsCloudData = function (name) {
); );
media = this.serializer.mediaXML(name); media = this.serializer.mediaXML(name);
dta = '<snapdata>' + str + media + '</snapdata>'; dta = '<snapdata>' + str + media + '</snapdata>';
this.saveXMLAs(str, this.projectName); this.saveXMLAs(str, name);
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} }
@ -7078,7 +7067,7 @@ ProjectDialogMorph.prototype.buildContents = function () {
this.body.add(this.srcBar); this.body.add(this.srcBar);
if (this.task === 'save') { if (this.task === 'save') {
this.nameField = new InputFieldMorph(this.ide.projectName); this.nameField = new InputFieldMorph(this.ide.getProjectName());
this.body.add(this.nameField); this.body.add(this.nameField);
} }
@ -7789,7 +7778,7 @@ ProjectDialogMorph.prototype.saveProject = function () {
this.saveCloudProject(); this.saveCloudProject();
} }
} else if (this.source === 'disk') { } else if (this.source === 'disk') {
this.ide.exportProject(name, false); this.ide.exportProject(name);
this.ide.source = 'disk'; this.ide.source = 'disk';
this.destroy(); this.destroy();
} }
@ -7876,7 +7865,7 @@ ProjectDialogMorph.prototype.shareProject = function () {
this.ide.showMessage('shared.', 2); this.ide.showMessage('shared.', 2);
// Set the Shared URL if the project is currently open // Set the Shared URL if the project is currently open
if (proj.projectname === ide.projectName) { if (proj.projectname === ide.getProjectName()) {
var usr = ide.cloud.username, var usr = ide.cloud.username,
projectId = 'Username=' + projectId = 'Username=' +
encodeURIComponent(usr.toLowerCase()) + encodeURIComponent(usr.toLowerCase()) +
@ -7920,7 +7909,7 @@ ProjectDialogMorph.prototype.unshareProject = function () {
this.buttons.fixLayout(); this.buttons.fixLayout();
this.rerender(); this.rerender();
this.ide.showMessage('unshared.', 2); this.ide.showMessage('unshared.', 2);
if (proj.projectname === ide.projectName) { if (proj.projectname === ide.getProjectName()) {
location.hash = ''; location.hash = '';
} }
}, },
@ -7960,7 +7949,7 @@ ProjectDialogMorph.prototype.publishProject = function () {
this.ide.showMessage('published.', 2); this.ide.showMessage('published.', 2);
// Set the Shared URL if the project is currently open // Set the Shared URL if the project is currently open
if (proj.projectname === ide.projectName) { if (proj.projectname === ide.getProjectName()) {
var usr = ide.cloud.username, var usr = ide.cloud.username,
projectId = 'Username=' + projectId = 'Username=' +
encodeURIComponent(usr.toLowerCase()) + encodeURIComponent(usr.toLowerCase()) +
@ -10389,7 +10378,10 @@ SceneIconMorph.prototype.renameScene = function () {
scene scene
); );
scene.stage.version = Date.now(); // +++ also do this in other places scene.stage.version = Date.now(); // +++ also do this in other places
ide.recordUnsavedChanges(); if (scene === ide.scene) {
ide.controlBar.updateLabel();
}
ide.recordUnsavedChanges(); // ++++ sceneify unsaved changes
} }
} }
).prompt( ).prompt(