Skip to content

Commit 88ed049

Browse files
committed
Merge branch 'issue/3833'
# Conflicts: # app/src/workspace.js
2 parents 01422a1 + 0833b7a commit 88ed049

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

app/src/native_controll.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,13 @@ Entry.plugin = (function () {
486486
}
487487
}
488488
});
489+
}
489490

491+
that.saveImage = function(data, path) {
492+
var buff = new Buffer(data.replace(/^data:image\/(png|gif|jpeg);base64,/,''), 'base64');
493+
fs.writeFile(path, buff, function (err) {
494+
// console.log('done');
495+
});
490496
}
491497

492498
// 프로젝트 저장

app/src/workspace.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ angular.module('workspace').controller("WorkspaceController", ['$scope', '$rootS
6363

6464
Entry.init(workspace, initOptions);
6565

66+
Entry.playground.board._contextOptions[3].option.callback = function() {
67+
dialog.showOpenDialog({
68+
properties: [
69+
'openDirectory'
70+
],
71+
filters: [
72+
{ name: 'Image', extensions: ['png'] }
73+
]
74+
}, function(paths) {
75+
Entry.playground.board.code.getThreads().forEach(function(t, index) {
76+
var topBlock = t.getFirstBlock();
77+
if (!topBlock) return;
78+
(function(i) {
79+
topBlock.view.getDataUrl().then(function(data) {
80+
var savePath = path.resolve(paths[0], i + '.png');
81+
Entry.plugin.saveImage(data.src, savePath);
82+
});
83+
})(++index);
84+
})
85+
})
86+
}
6687
var beforeUnload = window.onbeforeunload;
6788
window.onbeforeunload = function(e) {
6889
if (window.isNowSaving === true) {
@@ -200,8 +221,7 @@ angular.module('workspace').controller("WorkspaceController", ['$scope', '$rootS
200221
fs.writeFile(filePath, stream, 'utf8', function(err) {
201222
if (err) {
202223
alert("Unable to save file");
203-
}
204-
else {
224+
} else {
205225
console.log("File Saved");
206226
}
207227

@@ -822,23 +842,23 @@ angular.module('workspace').controller("WorkspaceController", ['$scope', '$rootS
822842
var maxx = 0;
823843
var maxy = 0;
824844

825-
if(pix.x.length > 0) {
845+
if (pix.x.length > 0) {
826846
minx = pix.x[0];
827847
maxx = pix.x[n];
828848
w = maxx - minx;
829-
if(w % 2 != 0) {
849+
if (w % 2 != 0) {
830850
w += 1;
831851
}
832852
} else {
833853
w = 1;
834854
minx = 0;
835855
}
836856

837-
if(pix.y.length > 0) {
857+
if (pix.y.length > 0) {
838858
miny = pix.y[0];
839859
maxy = pix.y[n]
840860
h = maxy - miny;
841-
if(h % 2 != 0) {
861+
if (h % 2 != 0) {
842862
h += 1;
843863
}
844864
} else {
@@ -920,7 +940,7 @@ angular.module('workspace').controller("WorkspaceController", ['$scope', '$rootS
920940
modalInstance.result.then(function(selectedItems) {
921941
selectedItems.data.forEach(function(item) {
922942
item.id = Entry.generateHash();
923-
if(item.fileurl) {
943+
if (item.fileurl) {
924944
item.fileurl = item.fileurl.replace(/%5C/gi, '/');
925945
}
926946
Entry.dispatchEvent('pictureImport', item);

0 commit comments

Comments
 (0)