@@ -37,75 +37,113 @@ const CREDITS = params.credits;
3737const CREDITS_URL = params . creditsURL ;
3838const PREVIEW_URL = params . previewURL ;
3939const BACK_URL = params . backURL ;
40+ let projectLocation = null , projectName = null ;
4041
41- function _validateProjectLocation ( ) {
42- if ( ! window . showDirectoryPicker ) { // fs access apis not present
43- $ ( document . getElementById ( "projectLocation" ) ) . addClass ( "forced-hidden" ) ;
44- return true ;
42+ function _computeProjectPath ( ) {
43+ if ( $ ( projectNameInput ) . is ( ":visible" ) ) {
44+ let suggestedName = projectNameInput . value ;
45+ if ( suggestedName && projectLocation ) {
46+ return projectLocation + suggestedName ;
47+ }
48+ return null ;
4549 }
46- let location = locationInput . value ;
47- if ( location === Strings . PLEASE_SELECT_A_FOLDER ) {
50+ return projectLocation ;
51+ }
52+
53+ async function _validateProjectLocation ( ) {
54+ if ( $ ( locationInput ) . is ( ":visible" ) ) {
55+ // this is desktop or browsers with fs access api
56+ let isLocationValid = projectLocation &&
57+ await newProjectExtension . alreadyExists ( projectLocation ) ;
58+ if ( isLocationValid ) {
59+ $ ( locationInput ) . removeClass ( "error-border" ) ;
60+ return true ;
61+ }
4862 $ ( locationInput ) . addClass ( "error-border" ) ;
4963 return false ;
5064 }
51- $ ( locationInput ) . removeClass ( "error-border" ) ;
65+ // location input is hidden only in browsers with no fs access API. If its hidden,
66+ // we dont need to validate location, as _validateSuggestedName will be in effect
5267 return true ;
5368}
5469
5570async function _validateSuggestedName ( ) {
56- let suggestedName = projectNameInput . value ;
57- if ( await newProjectExtension . alreadyExists ( suggestedName ) ) {
58- $ ( projectNameInput ) . addClass ( "error-border" ) ;
59- return ;
71+ if ( $ ( projectNameInput ) . is ( ":visible" ) ) {
72+ // the project name input is only visible in desktop and browsers with no fs access api.
73+ let suggestedName = projectNameInput . value ;
74+ if ( ! suggestedName || ! projectLocation ||
75+ await newProjectExtension . alreadyExists ( projectLocation + suggestedName ) ) {
76+ $ ( projectNameInput ) . addClass ( "error-border" ) ;
77+ return false ;
78+ }
79+ $ ( projectNameInput ) . removeClass ( "error-border" ) ;
6080 }
61- $ ( projectNameInput ) . removeClass ( "error-border" ) ;
81+ return true ;
82+ }
83+
84+ async function _validateAll ( ) {
85+ const locIsValid = await _validateProjectLocation ( ) ;
86+ const nameIsValid = await _validateSuggestedName ( ) ;
87+ document . getElementById ( 'createProjectBtn' ) . disabled = ! ( locIsValid && nameIsValid ) ;
88+ document . getElementById ( 'createProjectWithNameBtn' ) . disabled = ! ( locIsValid && nameIsValid ) ;
89+ return locIsValid && nameIsValid ;
6290}
6391
6492function _selectFolder ( ) {
6593 newProjectExtension . showFolderSelect ( )
6694 . then ( file => {
67- locationInput . fullPath = file ;
68- locationInput . value = file . replace ( newProjectExtension . getMountDir ( ) , "" ) ;
69- _validateProjectLocation ( ) ;
95+ projectLocation = file ;
96+ if ( ! projectLocation . endsWith ( "/" ) ) {
97+ projectLocation = projectLocation + "/" ;
98+ }
99+ locationInput . value = window . parent . Phoenix . app . getDisplayPath ( file ) ;
100+ _validateAll ( ) ;
70101 } ) ;
71102}
72103
73- function _createProjectClicked ( ) {
74- if ( _validateProjectLocation ( ) ) {
75- newProjectExtension . downloadAndOpenProject (
76- PARAM_SUGGESTED_URL ,
77- locationInput . fullPath , PARAM_SUGGESTED_NAME , FLATTEN_ZIP_FIRST_LEVEL_DIR )
78- . then ( ( ) => {
79- Metrics . countEvent ( Metrics . EVENT_TYPE . NEW_PROJECT , "createProject.Click" , "create.success" ) ;
80- newProjectExtension . closeDialogue ( ) ;
81- } ) ;
82- } else {
104+ async function _createProjectClicked ( ) {
105+ const projectPath = _computeProjectPath ( ) ;
106+ if ( ! projectPath ) {
83107 newProjectExtension . showErrorDialogue (
84108 Strings . MISSING_FIELDS ,
85109 Strings . PLEASE_FILL_ALL_REQUIRED ) ;
110+ return ;
86111 }
112+ await window . parent . Phoenix . VFS . ensureExistsDirAsync ( projectPath ) ;
113+ newProjectExtension . downloadAndOpenProject (
114+ PARAM_SUGGESTED_URL ,
115+ projectPath , PARAM_SUGGESTED_NAME , FLATTEN_ZIP_FIRST_LEVEL_DIR )
116+ . then ( ( ) => {
117+ Metrics . countEvent ( Metrics . EVENT_TYPE . NEW_PROJECT , "createProject.Click" , "create.success" ) ;
118+ newProjectExtension . closeDialogue ( ) ;
119+ } ) ;
87120 Metrics . countEvent ( Metrics . EVENT_TYPE . NEW_PROJECT , "createProject.Click" , "create" ) ;
88121}
89122
90123function _showLicensingInfo ( ) {
91- if ( LICENSE || LICENSE_URL ) {
124+ if ( LICENSE || LICENSE_URL || CREDITS || CREDITS_URL ) {
92125 $ ( document . getElementById ( "License" ) ) . removeClass ( "forced-hidden" ) ;
126+ }
127+ if ( LICENSE || LICENSE_URL ) {
93128 let el = document . getElementById ( "licenseLink" ) ;
94129 el . textContent = LICENSE || LICENSE_URL ;
95- let licenseURL = LICENSE_URL || '#' ;
96- el . href = licenseURL ;
97- if ( licenseURL === '#' ) {
98- $ ( el ) . attr ( 'target' , '' ) ;
130+ if ( LICENSE_URL ) {
131+ $ ( el ) . click ( ( evt ) => {
132+ window . parent . brackets . app . openURLInDefaultBrowser ( LICENSE_URL ) ;
133+ evt . preventDefault ( ) ;
134+ evt . stopPropagation ( ) ;
135+ } ) ;
99136 }
100137 }
101138 if ( CREDITS || CREDITS_URL ) {
102- $ ( document . getElementById ( "Credits" ) ) . removeClass ( "forced-hidden" ) ;
103139 let el = document . getElementById ( "creditsLink" ) ;
104140 el . textContent = CREDITS || CREDITS_URL ;
105- let creditsURL = CREDITS_URL || '#' ;
106- el . href = creditsURL ;
107- if ( creditsURL === '#' ) {
108- $ ( el ) . attr ( 'target' , '' ) ;
141+ if ( CREDITS_URL ) {
142+ $ ( el ) . click ( ( evt ) => {
143+ window . parent . brackets . app . openURLInDefaultBrowser ( CREDITS_URL ) ;
144+ evt . preventDefault ( ) ;
145+ evt . stopPropagation ( ) ;
146+ } ) ;
109147 }
110148 }
111149}
@@ -127,10 +165,16 @@ function _setupNavigation() {
127165
128166function initNewProjectFromURL ( ) {
129167 _setupNavigation ( ) ;
130- if ( ! window . showDirectoryPicker ) { // fs access apis not present
131- $ ( document . getElementById ( "projectLocation" ) ) . addClass ( "forced-hidden" ) ;
132- } else {
168+ if ( window . parent . Phoenix . browser . isTauri ) { // desktop builds
169+ projectLocation = newProjectExtension . getLocalProjectsPath ( ) ;
170+ projectName = PARAM_SUGGESTED_NAME ;
171+ $ ( document . getElementById ( "createProjectBtn" ) ) . addClass ( "forced-inVisible" ) ;
172+ } else if ( window . showDirectoryPicker ) { // fs access apis- chrome/opera etc..
133173 $ ( document . getElementById ( "projectName" ) ) . addClass ( "forced-hidden" ) ;
174+ } else {
175+ projectName = PARAM_SUGGESTED_NAME ;
176+ projectLocation = newProjectExtension . getLocalProjectsPath ( ) ;
177+ $ ( document . getElementById ( "projectLocation" ) ) . addClass ( "forced-hidden" ) ;
134178 }
135179 document . getElementById ( "titleNewProject" ) . textContent = PARAM_SUGGESTED_TITLE ;
136180 projectNameInput = document . getElementById ( "projectNameInput" ) ;
@@ -139,12 +183,14 @@ function initNewProjectFromURL() {
139183 createProjectWithNameBtn = document . getElementById ( "createProjectWithNameBtn" ) ;
140184 createProjectBtn . onclick = _createProjectClicked ;
141185 createProjectWithNameBtn . onclick = _createProjectClicked ;
142- $ ( projectNameInput ) . keyup ( _validateSuggestedName ) ;
186+ $ ( projectNameInput ) . keyup ( _validateAll ) ;
143187 locationInput . value = Strings . PLEASE_SELECT_A_FOLDER ;
144- projectNameInput . value = PARAM_SUGGESTED_NAME ;
188+ projectNameInput . value = projectName ;
145189 locationInput . onclick = _selectFolder ;
190+ if ( projectLocation ) {
191+ locationInput . value = window . parent . Phoenix . app . getDisplayPath ( projectLocation ) ;
192+ }
146193 _showLicensingInfo ( ) ;
147194 _showPreview ( ) ;
148- _validateProjectLocation ( ) ;
149- _validateSuggestedName ( ) ;
195+ _validateAll ( ) ;
150196}
0 commit comments