@@ -30,10 +30,11 @@ import FileExplorerDialog, { FileExplorerDialogProps } from '../gitHubOverlay/Fi
3030import RepositoryDialog , { RepositoryDialogProps } from '../gitHubOverlay/RepositoryDialog' ;
3131import { actions } from '../utils/ActionsHelper' ;
3232import Constants from '../utils/Constants' ;
33- import { promisifyDialog } from '../utils/DialogHelper' ;
33+ import { promisifyDialog , showSimpleErrorDialog } from '../utils/DialogHelper' ;
3434import { dismiss , showMessage , showSuccessMessage , showWarningMessage } from '../utils/notifications/NotificationsHelper' ;
3535import { EditorTabState } from '../workspace/WorkspaceTypes' ;
3636import { Intent } from '@blueprintjs/core' ;
37+ import { filePathRegex } from '../utils/PersistenceHelper' ;
3738
3839export function * GitHubPersistenceSaga ( ) : SagaIterator {
3940 yield takeLatest ( LOGIN_GITHUB , githubLoginSaga ) ;
@@ -288,6 +289,39 @@ function* githubSaveAll(): any {
288289 > ;
289290
290291 if ( store . getState ( ) . fileSystem . persistenceFileArray . length === 0 ) {
292+ // check if there is only one top level folder
293+ const fileSystem : FSModule | null = yield select (
294+ ( state : OverallState ) => state . fileSystem . inBrowserFileSystem
295+ ) ;
296+
297+ // If the file system is not initialised, do nothing.
298+ if ( fileSystem === null ) {
299+ yield call ( console . log , 'no filesystem!' ) ; // TODO change to throw new Error
300+ return ;
301+ }
302+ const currFiles : Record < string , string > = yield call (
303+ retrieveFilesInWorkspaceAsRecord ,
304+ 'playground' ,
305+ fileSystem
306+ ) ;
307+ const testPaths : Set < string > = new Set ( ) ;
308+ Object . keys ( currFiles ) . forEach ( e => {
309+ const regexResult = filePathRegex . exec ( e ) ! ;
310+ testPaths . add ( regexResult ! [ 1 ] . slice ( '/playground/' . length , - 1 ) . split ( '/' ) [ 0 ] ) ; //TODO hardcoded playground
311+ } ) ;
312+ if ( testPaths . size !== 1 ) {
313+ yield call ( showSimpleErrorDialog , {
314+ title : 'Unable to Save All' ,
315+ contents : (
316+ "There must be exactly one top level folder present in order to use Save All."
317+ ) ,
318+ label : 'OK'
319+ } ) ;
320+ return ;
321+ }
322+
323+ //only one top level folder, proceeding to selection
324+
291325 type ListForAuthenticatedUserData = GetResponseDataTypeFromEndpointMethod <
292326 typeof octokit . repos . listForAuthenticatedUser
293327 > ;
0 commit comments