@@ -33,9 +33,12 @@ define(function (require, exports, module) {
3333 const PathUtils = require ( "thirdparty/path-utils/path-utils" ) ;
3434 const StringMatch = require ( "utils/StringMatch" ) ;
3535 const Dialogs = require ( "widgets/Dialogs" ) ;
36-
36+ const StateManager = require ( "preferences/StateManager" ) ;
3737 const ImageFolderDialogTemplate = require ( "text!htmlContent/image-folder-dialog.html" ) ;
3838
39+ // state manager key, to save the download location of the image
40+ const IMAGE_DOWNLOAD_FOLDER_KEY = "imageGallery.downloadFolder" ;
41+
3942 /**
4043 * This function syncs text content changes between the original source code
4144 * and the live preview DOM after a text edit in the browser
@@ -1005,12 +1008,21 @@ define(function (require, exports, module) {
10051008 const projectRoot = ProjectManager . getProjectRoot ( ) ;
10061009 if ( ! projectRoot ) { return ; }
10071010
1011+ // check if user has already saved a folder preference for this project
1012+ const savedFolder = StateManager . get ( IMAGE_DOWNLOAD_FOLDER_KEY , StateManager . PROJECT_CONTEXT ) ;
1013+ // we specifically check for nullish type vals because empty string is possible as it means project root
1014+ if ( savedFolder !== null && savedFolder !== undefined ) {
1015+ _downloadToFolder ( message , savedFolder ) ;
1016+ return ;
1017+ }
1018+
10081019 // show the dialog with a text box to select a folder
10091020 // dialog html is written in 'image-folder-dialog.html'
10101021 const dialog = Dialogs . showModalDialogUsingTemplate ( ImageFolderDialogTemplate , false ) ;
10111022 const $dlg = dialog . getElement ( ) ;
10121023 const $input = $dlg . find ( "#folder-path-input" ) ;
10131024 const $suggestions = $dlg . find ( "#folder-suggestions" ) ;
1025+ const $rememberCheckbox = $dlg . find ( "#remember-folder-checkbox" ) ;
10141026
10151027 let folderList = [ ] ;
10161028 let stringMatcher = null ;
@@ -1036,6 +1048,12 @@ define(function (require, exports, module) {
10361048 $dlg . one ( "buttonClick" , function ( e , buttonId ) {
10371049 if ( buttonId === Dialogs . DIALOG_BTN_OK ) {
10381050 const folderPath = $input . val ( ) . trim ( ) ;
1051+
1052+ // if the checkbox is checked, we save the folder preference for this project
1053+ if ( $rememberCheckbox . is ( ':checked' ) ) {
1054+ StateManager . set ( IMAGE_DOWNLOAD_FOLDER_KEY , folderPath , StateManager . PROJECT_CONTEXT ) ;
1055+ }
1056+
10391057 _downloadToFolder ( message , folderPath ) ;
10401058 }
10411059 dialog . close ( ) ;
0 commit comments