@@ -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+ const StateManager = require ( "preferences/StateManager" ) ;
3637 const ProDialogs = require ( "services/pro-dialogs" ) ;
3738 const ImageFolderDialogTemplate = require ( "text!htmlContent/image-folder-dialog.html" ) ;
3839
40+ // state manager key, to save the download location of the image
41+ const IMAGE_DOWNLOAD_FOLDER_KEY = "imageGallery.downloadFolder" ;
3942
4043 const KernalModeTrust = window . KernalModeTrust ;
4144 if ( ! KernalModeTrust ) {
@@ -1020,12 +1023,21 @@ define(function (require, exports, module) {
10201023 const projectRoot = ProjectManager . getProjectRoot ( ) ;
10211024 if ( ! projectRoot ) { return ; }
10221025
1026+ // check if user has already saved a folder preference for this project
1027+ const savedFolder = StateManager . get ( IMAGE_DOWNLOAD_FOLDER_KEY , StateManager . PROJECT_CONTEXT ) ;
1028+ // we specifically check for nullish type vals because empty string is possible as it means project root
1029+ if ( savedFolder !== null && savedFolder !== undefined ) {
1030+ _downloadToFolder ( message , savedFolder ) ;
1031+ return ;
1032+ }
1033+
10231034 // show the dialog with a text box to select a folder
10241035 // dialog html is written in 'image-folder-dialog.html'
10251036 const dialog = Dialogs . showModalDialogUsingTemplate ( ImageFolderDialogTemplate , false ) ;
10261037 const $dlg = dialog . getElement ( ) ;
10271038 const $input = $dlg . find ( "#folder-path-input" ) ;
10281039 const $suggestions = $dlg . find ( "#folder-suggestions" ) ;
1040+ const $rememberCheckbox = $dlg . find ( "#remember-folder-checkbox" ) ;
10291041
10301042 let folderList = [ ] ;
10311043 let stringMatcher = null ;
@@ -1051,6 +1063,12 @@ define(function (require, exports, module) {
10511063 $dlg . one ( "buttonClick" , function ( e , buttonId ) {
10521064 if ( buttonId === Dialogs . DIALOG_BTN_OK ) {
10531065 const folderPath = $input . val ( ) . trim ( ) ;
1066+
1067+ // if the checkbox is checked, we save the folder preference for this project
1068+ if ( $rememberCheckbox . is ( ':checked' ) ) {
1069+ StateManager . set ( IMAGE_DOWNLOAD_FOLDER_KEY , folderPath , StateManager . PROJECT_CONTEXT ) ;
1070+ }
1071+
10541072 _downloadToFolder ( message , folderPath ) ;
10551073 }
10561074 dialog . close ( ) ;
0 commit comments