Skip to content

Commit ae7b6ff

Browse files
committed
DirectoryPicker for saving file
1 parent 4102702 commit ae7b6ff

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/graph-builder/graph-core/5-load-save.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,30 @@ class GraphLoadSave extends GraphUndoRedo {
100100
return `${this.projectName}`;
101101
}
102102

103-
saveToDisk(fileName) {
103+
async saveToDisk() {
104104
const str = graphmlBuilder(this.jsonifyGraph());
105105
const bytes = new TextEncoder().encode(str);
106106
const blob = new Blob([bytes], { type: 'application/json;charset=utf-8' });
107-
saveAs(blob, `${fileName || `${this.getName()}-concore`}.graphml`);
107+
if (navigator.userAgent.indexOf('Edg') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
108+
const options = {
109+
types: [
110+
{
111+
description: 'GraphMl Files',
112+
accept: {
113+
'text/graphml': ['.graphml'],
114+
},
115+
},
116+
],
117+
};
118+
const handle = await window.showSaveFilePicker(options);
119+
const stream = await handle.createWritable();
120+
await stream.write(blob);
121+
await stream.close();
122+
} else {
123+
// eslint-disable-next-line no-alert
124+
const fileName = prompt('Filename:');
125+
saveAs(blob, `${fileName || `${this.getName()}-concore`}.graphml`);
126+
}
108127
}
109128

110129
saveToFolder() {

src/toolbarActions/toolbarFunctions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const downloadImg = (state, setState, format) => {
7575
getGraphFun(state).downloadImg(format);
7676
};
7777

78-
const saveAction = (state, d, fileName) => {
79-
getGraphFun(state).saveToDisk(fileName);
78+
const saveAction = (state) => {
79+
getGraphFun(state).saveToDisk();
8080
};
8181

8282
async function saveGraphMLFile(state) {

src/toolbarActions/toolbarList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const toolbarList = (state, dispatcher) => [
4545
type: 'action',
4646
text: 'Save As',
4747
icon: FaSave,
48-
action: (s, d) => saveAction(s, d, prompt('File Name:')),
48+
action: (s, d) => saveAction(s, d),
4949
active: true,
5050
},
5151
{

0 commit comments

Comments
 (0)