File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 5
5
throw new Error ( 'files extension must be run unsandboxed' ) ;
6
6
}
7
7
8
+ const MODE_MODAL = 'modal' ;
9
+ const MODE_IMMEDIATELY_SHOW_SELECTOR = 'selector' ;
10
+
11
+ let openFileSelectorMode = MODE_MODAL ;
12
+
8
13
const showFilePrompt = ( accept ) => new Promise ( ( _resolve ) => {
9
14
// We can't reliably show an <input> picker without "user interaction" in all environments,
10
15
// so we have to show our own UI anyways. We may as well use this to implement some nice features
130
135
modal . appendChild ( subtitle ) ;
131
136
132
137
document . body . appendChild ( outer ) ;
138
+
139
+ if ( openFileSelectorMode === MODE_IMMEDIATELY_SHOW_SELECTOR ) {
140
+ input . click ( ) ;
141
+ }
133
142
} ) ;
134
143
135
144
const download = ( text , file ) => {
184
193
defaultValue : 'save.txt'
185
194
}
186
195
}
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
+ ]
187
223
}
188
- ]
224
+ }
189
225
} ;
190
226
}
191
227
200
236
download ( args ) {
201
237
download ( args . text , args . file ) ;
202
238
}
239
+
240
+ setOpenMode ( args ) {
241
+ openFileSelectorMode = args . mode ;
242
+ }
203
243
}
204
244
205
245
Scratch . extensions . register ( new Files ( ) ) ;
You can’t perform that action at this time.
0 commit comments