Skip to content

Commit b2a32dc

Browse files
authored
Merge pull request #35 from TurboWarp/modal-mode
files: Add option to show file selector immediately
2 parents 7b3d2bf + 9ce97c4 commit b2a32dc

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

files.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
throw new Error('files extension must be run unsandboxed');
66
}
77

8+
const MODE_MODAL = 'modal';
9+
const MODE_IMMEDIATELY_SHOW_SELECTOR = 'selector';
10+
11+
let openFileSelectorMode = MODE_MODAL;
12+
813
const showFilePrompt = (accept) => new Promise((_resolve) => {
914
// We can't reliably show an <input> picker without "user interaction" in all environments,
1015
// so we have to show our own UI anyways. We may as well use this to implement some nice features
@@ -130,6 +135,10 @@
130135
modal.appendChild(subtitle);
131136

132137
document.body.appendChild(outer);
138+
139+
if (openFileSelectorMode === MODE_IMMEDIATELY_SHOW_SELECTOR) {
140+
input.click();
141+
}
133142
});
134143

135144
const download = (text, file) => {
@@ -184,8 +193,35 @@
184193
defaultValue: 'save.txt'
185194
}
186195
}
196+
},
197+
{
198+
opcode: 'setOpenMode',
199+
blockType: Scratch.BlockType.COMMAND,
200+
text: 'set open file selector mode to [mode]',
201+
arguments: {
202+
mode: {
203+
type: Scratch.ArgumentType.STRING,
204+
defaultValue: MODE_MODAL,
205+
menu: 'automaticallyOpen'
206+
}
207+
}
208+
}
209+
],
210+
menus: {
211+
automaticallyOpen: {
212+
acceptReporters: true,
213+
items: [
214+
{
215+
text: 'show modal',
216+
value: MODE_MODAL
217+
},
218+
{
219+
text: 'open selector immediately',
220+
value: MODE_IMMEDIATELY_SHOW_SELECTOR
221+
}
222+
]
187223
}
188-
]
224+
}
189225
};
190226
}
191227

@@ -200,6 +236,10 @@
200236
download (args) {
201237
download(args.text, args.file);
202238
}
239+
240+
setOpenMode (args) {
241+
openFileSelectorMode = args.mode;
242+
}
203243
}
204244

205245
Scratch.extensions.register(new Files());

0 commit comments

Comments
 (0)