Skip to content

Commit 8514512

Browse files
committed
feat: save folder location in state manager project wise
1 parent 7ef055e commit 8514512

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 19 additions & 1 deletion
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-
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();

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)