Skip to content

Commit bd25b9a

Browse files
committed
feat: add download folder button reset mechanism
1 parent 26bf5ab commit bd25b9a

File tree

2 files changed

+100
-18
lines changed

2 files changed

+100
-18
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,12 @@ function RemoteFunctions(config = {}) {
12191219
<svg viewBox="0 0 640 640" fill="currentColor">
12201220
<path d="M352 96C352 78.3 337.7 64 320 64C302.3 64 288 78.3 288 96L288 306.7L246.6 265.3C234.1 252.8 213.8 252.8 201.3 265.3C188.8 277.8 188.8 298.1 201.3 310.6L297.3 406.6C309.8 419.1 330.1 419.1 342.6 406.6L438.6 310.6C451.1 298.1 451.1 277.8 438.6 265.3C426.1 252.8 405.8 252.8 393.3 265.3L352 306.7L352 96zM160 384C124.7 384 96 412.7 96 448L96 480C96 515.3 124.7 544 160 544L480 544C515.3 544 544 515.3 544 480L544 448C544 412.7 515.3 384 480 384L433.1 384L376.5 440.6C345.3 471.8 294.6 471.8 263.4 440.6L206.9 384L160 384zM464 440C477.3 440 488 450.7 488 464C488 477.3 477.3 488 464 488C450.7 488 440 477.3 440 464C440 450.7 450.7 440 464 440z"/>
12211221
</svg>
1222+
`,
1223+
1224+
folderSettings: `
1225+
<svg viewBox="0 0 24 24" fill="currentColor">
1226+
<path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>
1227+
</svg>
12221228
`
12231229
};
12241230

@@ -2301,10 +2307,35 @@ function RemoteFunctions(config = {}) {
23012307
.phoenix-select-image-btn:hover {
23022308
background: rgba(21,25,36,0.85) !important;
23032309
border-color: rgba(255,255,255,0.25) !important;
2304-
transform: scale(1.05) !important;
23052310
box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
23062311
}
23072312
2313+
.phoenix-ribbon-folder-settings {
2314+
background: rgba(21,25,36,0.65) !important;
2315+
border: 1px solid rgba(255,255,255,0.14) !important;
2316+
color: #eaeaf0 !important;
2317+
cursor: pointer !important;
2318+
padding: 2px 6px 1px 6px !important;
2319+
border-radius: 6px !important;
2320+
margin-right: 8px !important;
2321+
transition: all 0.2s ease !important;
2322+
font-size: 12px !important;
2323+
display: flex !important;
2324+
align-items: center !important;
2325+
justify-content: center !important;
2326+
}
2327+
2328+
.phoenix-ribbon-folder-settings:hover {
2329+
background: rgba(21,25,36,0.85) !important;
2330+
border-color: rgba(255,255,255,0.25) !important;
2331+
box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
2332+
}
2333+
2334+
.phoenix-ribbon-folder-settings svg {
2335+
width: 16px !important;
2336+
height: 16px !important;
2337+
}
2338+
23082339
.phoenix-ribbon-close {
23092340
background: rgba(21,25,36,0.65) !important;
23102341
border: 1px solid rgba(255,255,255,0.14) !important;
@@ -2320,7 +2351,6 @@ function RemoteFunctions(config = {}) {
23202351
.phoenix-ribbon-close:hover {
23212352
background: rgba(21,25,36,0.85) !important;
23222353
border-color: rgba(255,255,255,0.25) !important;
2323-
transform: scale(1.05) !important;
23242354
box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
23252355
}
23262356
@@ -2461,6 +2491,9 @@ function RemoteFunctions(config = {}) {
24612491
</div>
24622492
</div>
24632493
<div class="phoenix-ribbon-header-right">
2494+
<button class="phoenix-ribbon-folder-settings" title="Select image download folder">
2495+
${ICONS.folderSettings}
2496+
</button>
24642497
<button class="phoenix-ribbon-close">×</button>
24652498
</div>
24662499
</div>
@@ -2725,6 +2758,7 @@ function RemoteFunctions(config = {}) {
27252758
const searchInput = this._shadow.querySelector('.phoenix-ribbon-search input');
27262759
const searchButton = this._shadow.querySelector('.phoenix-ribbon-search-btn');
27272760
const closeButton = this._shadow.querySelector('.phoenix-ribbon-close');
2761+
const folderSettingsButton = this._shadow.querySelector('.phoenix-ribbon-folder-settings');
27282762
const navLeft = this._shadow.querySelector('.phoenix-ribbon-nav.left');
27292763
const navRight = this._shadow.querySelector('.phoenix-ribbon-nav.right');
27302764
const selectImageBtn = this._shadow.querySelector('.phoenix-select-image-btn');
@@ -2778,6 +2812,20 @@ function RemoteFunctions(config = {}) {
27782812
});
27792813
}
27802814

2815+
if (folderSettingsButton) {
2816+
folderSettingsButton.addEventListener('click', (e) => {
2817+
e.stopPropagation();
2818+
// send message to LivePreviewEdit to show folder selection dialog
2819+
const tagId = this.element.getAttribute("data-brackets-id");
2820+
window._Brackets_MessageBroker.send({
2821+
livePreviewEditEnabled: true,
2822+
resetImageFolderSelection: true,
2823+
element: this.element,
2824+
tagId: Number(tagId)
2825+
});
2826+
});
2827+
}
2828+
27812829
if (navLeft) {
27822830
navLeft.addEventListener('click', (e) => {
27832831
e.stopPropagation();

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,25 +1012,14 @@ define(function (require, exports, module) {
10121012
}
10131013

10141014
/**
1015-
* This function is called when 'use this image' button is clicked in the image ribbon gallery
1016-
* or user loads an image file from the computer
1017-
* this is responsible to download the image in the appropriate place
1018-
* and also change the src attribute of the element (by calling appropriate helper functions)
1019-
*
1020-
* @param {Object} message - the message object which stores all the required data for this operation
1015+
* this shows the folder selection dialog for choosing where to download images
1016+
* @param {Object} message - the message object (optional, only needed when downloading image)
1017+
* @private
10211018
*/
1022-
function _handleUseThisImage(message) {
1019+
function _showFolderSelectionDialog(message) {
10231020
const projectRoot = ProjectManager.getProjectRoot();
10241021
if (!projectRoot) { return; }
10251022

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-
10341023
// show the dialog with a text box to select a folder
10351024
// dialog html is written in 'image-folder-dialog.html'
10361025
const dialog = Dialogs.showModalDialogUsingTemplate(ImageFolderDialogTemplate, false);
@@ -1069,12 +1058,38 @@ define(function (require, exports, module) {
10691058
StateManager.set(IMAGE_DOWNLOAD_FOLDER_KEY, folderPath, StateManager.PROJECT_CONTEXT);
10701059
}
10711060

1072-
_downloadToFolder(message, folderPath);
1061+
// if message is provided, download the image
1062+
if (message) {
1063+
_downloadToFolder(message, folderPath);
1064+
}
10731065
}
10741066
dialog.close();
10751067
});
10761068
}
10771069

1070+
/**
1071+
* This function is called when 'use this image' button is clicked in the image ribbon gallery
1072+
* or user loads an image file from the computer
1073+
* this is responsible to download the image in the appropriate place
1074+
* and also change the src attribute of the element (by calling appropriate helper functions)
1075+
*
1076+
* @param {Object} message - the message object which stores all the required data for this operation
1077+
*/
1078+
function _handleUseThisImage(message) {
1079+
const projectRoot = ProjectManager.getProjectRoot();
1080+
if (!projectRoot) { return; }
1081+
1082+
// check if user has already saved a folder preference for this project
1083+
const savedFolder = StateManager.get(IMAGE_DOWNLOAD_FOLDER_KEY, StateManager.PROJECT_CONTEXT);
1084+
// we specifically check for nullish type vals because empty string is possible as it means project root
1085+
if (savedFolder !== null && savedFolder !== undefined) {
1086+
_downloadToFolder(message, savedFolder);
1087+
} else {
1088+
// show the folder selection dialog
1089+
_showFolderSelectionDialog(message);
1090+
}
1091+
}
1092+
10781093
/**
10791094
* Helper function to download image to the specified directory
10801095
*
@@ -1096,6 +1111,19 @@ define(function (require, exports, module) {
10961111
});
10971112
}
10981113

1114+
/**
1115+
* Handles reset of image folder selection - clears the saved preference and shows the dialog
1116+
* @private
1117+
*/
1118+
function _handleResetImageFolderSelection() {
1119+
// clear the saved folder preference for this project
1120+
StateManager.set(IMAGE_DOWNLOAD_FOLDER_KEY, null, StateManager.PROJECT_CONTEXT);
1121+
1122+
// show the folder selection dialog for the user to choose a new folder
1123+
// we pass null because we're not downloading an image, just setting the preference
1124+
_showFolderSelectionDialog(null);
1125+
}
1126+
10991127
/**
11001128
* This is the main function that is exported.
11011129
* it will be called by LiveDevProtocol when it receives a message from RemoteFunctions.js
@@ -1120,6 +1148,12 @@ define(function (require, exports, module) {
11201148
* these are the main properties that are passed through the message
11211149
*/
11221150
function handleLivePreviewEditOperation(message) {
1151+
// handle reset image folder selection
1152+
if (message.resetImageFolderSelection) {
1153+
_handleResetImageFolderSelection();
1154+
return;
1155+
}
1156+
11231157
// handle move(drag & drop)
11241158
if (message.move && message.sourceId && message.targetId) {
11251159
_moveElementInSource(message.sourceId, message.targetId, message.insertAfter, message.insertInside);

0 commit comments

Comments
 (0)