Skip to content

Commit 90c1530

Browse files
committed
fix: new html/other project dialog was broken
1 parent 3c8193f commit 90c1530

File tree

5 files changed

+107
-61
lines changed

5 files changed

+107
-61
lines changed

src/assets/new-project/assets/css/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,11 @@ img {
964964
cursor: pointer;
965965
}
966966

967+
.create-btn:disabled {
968+
background: #555555;
969+
cursor: unset;
970+
}
971+
967972
.flex-column-fill{
968973
display: flex;
969974
flex-flow: column;
@@ -1071,6 +1076,10 @@ img {
10711076
display: none !important;
10721077
}
10731078

1079+
.forced-inVisible {
1080+
visibility: hidden !important;
1081+
}
1082+
10741083
/* notification ui styles */
10751084
.notification-ui-arrow {
10761085
position: absolute;

src/assets/new-project/assets/js/new-project-from-url.js

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,75 +37,113 @@ const CREDITS = params.credits;
3737
const CREDITS_URL = params.creditsURL;
3838
const PREVIEW_URL = params.previewURL;
3939
const 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

5570
async 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

6492
function _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

90123
function _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

128166
function 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
}

src/assets/new-project/new-project-from-url.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,19 @@
5050
</div>
5151

5252
<div class="website-main-content flex-column-fill flex-1-1-auto">
53-
<div id="projectLocation" class="website-detail d-flex align-items-center flex-0-1-auto">
54-
<span class="localize">{{LOCATION}}</span>
55-
<input id="locationInput" type="button" name="web-url" value="">
56-
<button id="createProjectBtn" class="create-btn localize">{{CREATE_PROJECT}}</button>
57-
</div>
5853
<div id="projectName" class="website-detail d-flex align-items-center flex-0-1-auto">
5954
<span class="localize">{{PROJECT_NAME}}</span>
6055
<input id="projectNameInput" class="" type="text" name="project-name" value="project"/>
6156
<button id="createProjectWithNameBtn" class="create-btn localize">{{CREATE_PROJECT}}</button>
6257
</div>
63-
<div id="License" class="forced-hidden website-detail d-flex align-items-center flex-0-1-auto">
64-
<span class="localize">{{LICENSE}}</span>
65-
<a id="licenseLink" href="#" target="_blank"></a>
58+
<div id="projectLocation" class="website-detail d-flex align-items-center flex-0-1-auto">
59+
<span class="localize">{{LOCATION}}</span>
60+
<input id="locationInput" type="button" name="web-url" value="">
61+
<button id="createProjectBtn" class="create-btn localize">{{CREATE_PROJECT}}</button>
6662
</div>
67-
<div id="Credits" class="forced-hidden website-detail d-flex align-items-center flex-0-1-auto">
68-
<span class="localize">{{CREDITS}}</span>
63+
<div id="License" class="forced-hidden website-detail d-flex align-items-center flex-0-1-auto" style="color: white">
64+
<span class="localize">{{LICENSE}}</span>
65+
<a id="licenseLink" href="#" target="_blank"></a>,&nbsp;
6966
<a id="creditsLink" href="#" target="_blank"></a>
7067
</div>
7168
<div id="previewBox" class="website-preview-content flex-1-1-auto forced-hidden">

src/extensionsIntegrated/Phoenix/new-project.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ define(function (require, exports, module) {
175175
async function _validateProjectFolder(projectPath) {
176176
return new Promise((resolve, reject)=>{
177177
let dir = FileSystem.getDirectoryForPath(projectPath);
178-
let displayPath = projectPath.replace(Phoenix.VFS.getMountDir(), "");
178+
let displayPath = Phoenix.app.getDisplayPath(projectPath);
179179
if(!dir){
180180
_showProjectErrorDialogue(Strings.REQUEST_NATIVE_FILE_SYSTEM_ERROR, displayPath, Strings.NOT_FOUND_ERR);
181181
reject();
@@ -225,11 +225,6 @@ define(function (require, exports, module) {
225225
});
226226
}
227227

228-
async function alreadyExists(suggestedProjectName) {
229-
let projectPath = `${ProjectManager.getLocalProjectsPath()}${suggestedProjectName}`; // try suggested path first
230-
return window.Phoenix.VFS.existsAsync(projectPath);
231-
}
232-
233228
async function _getSuggestedProjectDir(suggestedProjectName) {
234229
return new Promise(async (resolve, reject)=>{ // eslint-disable-line
235230
try{
@@ -391,7 +386,7 @@ define(function (require, exports, module) {
391386
exports.downloadAndOpenProject = downloadAndOpenProject;
392387
exports.showFolderSelect = showFolderSelect;
393388
exports.showErrorDialogue = showErrorDialogue;
394-
exports.alreadyExists = alreadyExists;
389+
exports.alreadyExists = window.Phoenix.VFS.existsAsync;
395390
exports.Metrics = Metrics;
396391
exports.EVENT_NEW_PROJECT_DIALOGUE_CLOSED = "newProjectDlgClosed";
397392
exports.getWelcomeProjectPath = ProjectManager.getWelcomeProjectPath;

src/nls/root/strings.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,7 @@ define({
10851085
"PHOENIX_DEFAULT_PROJECT": "Default Project",
10861086
"PROJECT_NAME": "Project name:",
10871087
"NEW_HTML": "New HTML Project",
1088-
"LICENSE": "License:",
1089-
"CREDITS": "Credits:",
1088+
"LICENSE": "License & Credits:",
10901089
"PREVIEW": "Preview",
10911090
"BUILD_WEBSITE": "Build Website",
10921091
"VIEW_MORE": "View More...",

0 commit comments

Comments
 (0)