Skip to content

Commit a2cc4ef

Browse files
committed
feat: save folder location in state manager project wise
1 parent 4107776 commit a2cc4ef

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/htmlContent/image-folder-dialog.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ <h1 class="dialog-title">Select Folder to Save Image</h1>
1717
<p class="folder-help-text">
1818
💡 Type folder path or leave empty to download in project root
1919
</p>
20+
21+
<div class="remember-folder-container">
22+
<label>
23+
<input type="checkbox" id="remember-folder-checkbox" checked>
24+
<span>Don't ask again for this project</span>
25+
</label>
26+
</div>
2027
</div>
2128
<div class="modal-footer">
2229
<button class="dialog-button btn" data-button-id="cancel">Cancel</button>

src/styles/brackets_patterns_override.less

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,4 +2603,23 @@ code {
26032603
color: @dark-bc-text-quiet;
26042604
}
26052605
}
2606+
2607+
.remember-folder-container {
2608+
display: flex;
2609+
justify-content: right;
2610+
}
2611+
2612+
.remember-folder-container label {
2613+
font-size: 12px;
2614+
letter-spacing: 0.3px;
2615+
color: @bc-text-quiet;
2616+
2617+
.dark & {
2618+
color: @dark-bc-text-quiet;
2619+
}
2620+
}
2621+
2622+
.remember-folder-container input {
2623+
margin-top: 2px;
2624+
}
26062625
}

0 commit comments

Comments
 (0)