diff --git a/index.js b/index.js index b0732db..aedb7d0 100644 --- a/index.js +++ b/index.js @@ -2161,7 +2161,7 @@ async function hasSelectionChanged(new_selection, old_selection) { async function easyModeGenerate(mode) { try { - //1)check if documnet has background layer + //1)check if the documnet has a background layer if ( (await layer_util.hasBackgroundLayer()) === false && //doesn't have backround layer (await note.Notification.backgroundLayerIsMissing()) === false //and the user cancled the creation of background layer @@ -2175,8 +2175,12 @@ async function easyModeGenerate(mode) { let active_layer = await app.activeDocument.activeLayers[0] // store the active layer so we could reselected after the session end clean up //make sure you have selection area active on the canvas const isSelectionAreaValid = await psapi.checkIfSelectionAreaIsActive() - if (!isSelectionAreaValid) { - await psapi.promptForMarqueeTool() + if ( + !isSelectionAreaValid && // no selection area + (await note.Notification.inactiveSelectionArea( + g_generation_session.isActive() + )) === false // means did not activate the session selection area if it's available + ) { return null } @@ -4034,19 +4038,31 @@ async function downloadItExe(link, writeable_entry, image_file_name) { return new_layer } +//REFACTOR: move to session.js or selection.js +async function activateSessionSelectionArea() { + try { + if (psapi.isSelectionValid(g_generation_session.selectionInfo)) { + await psapi.reSelectMarqueeExe(g_generation_session.selectionInfo) + await eventHandler() + } + } catch (e) { + console.warn(e) + } +} document .getElementById('btnSelectionArea') .addEventListener('click', async () => { - try { - if (psapi.isSelectionValid(g_generation_session.selectionInfo)) { - await psapi.reSelectMarqueeExe( - g_generation_session.selectionInfo - ) - await eventHandler() - } - } catch (e) { - console.warn(e) - } + // try { + // if (psapi.isSelectionValid(g_generation_session.selectionInfo)) { + // await psapi.reSelectMarqueeExe( + // g_generation_session.selectionInfo + // ) + // await eventHandler() + // } + // } catch (e) { + // console.warn(e) + // } + await activateSessionSelectionArea() }) function addPresetMenuItem(preset_title) { diff --git a/psapi.js b/psapi.js index 4830c2b..7d6b491 100644 --- a/psapi.js +++ b/psapi.js @@ -291,7 +291,8 @@ async function unSelectMarqueeExe() { console.warn(e) } } -////selection: + +//REFACTOR: move to selection.js async function selectMarqueeRectangularToolExe() { async function selectMarqueeRectangularToolCommand() { const result = await batchPlay( diff --git a/utility/notification.js b/utility/notification.js index e006e2f..4676ec5 100644 --- a/utility/notification.js +++ b/utility/notification.js @@ -75,6 +75,30 @@ class Notification { } return false } + static async inactiveSelectionArea(is_active_session) { + let buttons = ['Cancel', 'Rectangular Marquee'] + if (is_active_session) { + buttons.push('Continue Session') + } + const r1 = await dialog_box.prompt( + 'Please Select a Rectangular Area', + 'You Forgot to select a Rectangular Area', + buttons + ) + if (r1 === 'Cancel') { + /* cancelled or No */ + console.log('cancel') + return false + } else if (r1 === 'Rectangular Marquee') { + console.log('Rectangular Marquee') + psapi.selectMarqueeRectangularToolExe() + return false // should this be false?! what does true and false means in this context?! Yes: it should be false since boolean value represent wither we have an active selection area or not + } else if (r1 === 'Continue Session') { + await activateSessionSelectionArea() + return true + } + return false + } } module.exports = {