Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ux issues in project open workflows when path doesnt exist #1989

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Welcome to Phoenix!

**Website: https://phcode.dev**
**Website: https://phcode.io**

Phoenix is a modern open-source and [free software](https://www.gnu.org/philosophy/free-sw.en.html) code editor for the web, built for the browser.
Phoenix is a modern open-source and [free software](https://www.gnu.org/philosophy/free-sw.en.html) text editor
designed to make coding as simple and fun as playing a video game.

#### Code Guardian
[![Phoenix build verification](https://github.com/phcode-dev/phoenix/actions/workflows/build_verify.yml/badge.svg)](https://github.com/phcode-dev/phoenix/actions/workflows/build_verify.yml)
Expand All @@ -27,7 +28,7 @@ Phoenix is a modern open-source and [free software](https://www.gnu.org/philosop
<img src="https://assets-global.website-files.com/607f4f6df411bd01527dc7d5/63bc40cd9d502eda8ea74ce7_Bugsnag%20Full%20Color.svg" alt="bugsnag" style="width:200px;"/>
</a>

#### Development status: Stable/Release-candidate.
#### Development status: Stable/Active.

![Screenshot from 2022-09-20 13-35-03](https://user-images.githubusercontent.com/5336369/191202975-6069d270-526a-443d-bd76-903353ae1222.png)

Expand Down
2 changes: 0 additions & 2 deletions src/extensionsIntegrated/CSSColorPreview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ define(function (require, exports, module) {
// Add listener for all editor changes
EditorManager.on("activeEditorChange", function (event, newEditor, oldEditor) {
if (newEditor && newEditor.isGutterActive(GUTTER_NAME)) {
console.time("xxxxxxxxxxx");
newEditor.off("cursorActivity.colorPreview");
newEditor.on("cursorActivity.colorPreview", _cursorActivity);
// Unbind the previous editor's change event if it exists
Expand All @@ -241,7 +240,6 @@ define(function (require, exports, module) {
newEditor.on("change", onChanged);
showColorMarks();
_cursorActivity(null, newEditor);
console.timeEnd("xxxxxxxxxxx");
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/extensionsIntegrated/RecentProjects/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ define(function (require, exports, module) {
}
FileSystem.resolve(fullPath, function (err, item) {
if (err) {
recentProjects.splice(index, 1);
removeFromRecentProject(fullPath);
}
reject();
});
Expand Down
81 changes: 56 additions & 25 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ define(function (require, exports, module) {
entryType = isFolder ? Strings.DIRECTORY : Strings.FILE,
title,
message;
path = Phoenix.app.getDisplayPath(path);
path = StringUtils.breakableUrl(path);

switch (errType) {
Expand Down Expand Up @@ -1312,7 +1313,9 @@ define(function (require, exports, module) {
// which is now partially torn down (see #6574).
model.projectRoot = null;

_loadProject(getWelcomeProjectPath()).always(function () {
_loadProject(getPlaceholderProjectPath()).always(function () {
// we dont load any other project here as the saved project state will not get restored
// if we load an actual project at this time.
// Make sure not to reject the original deferred until the fallback
// project is loaded, so we don't violate expectations that there is always
// a current project before continuing after _loadProject().
Expand Down Expand Up @@ -1409,6 +1412,33 @@ define(function (require, exports, module) {
|| window.showOpenFilePicker; // fs access file picker
}

function _openProject(path, result) {
// Confirm any unsaved changes first. We run the command in "prompt-only" mode, meaning it won't
// actually close any documents even on success; we'll do that manually after the user also oks
// the folder-browse dialog.
CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
.done(function () {
if (path) {
// use specified path
_loadProject(path).then(result.resolve, result.reject);
} else {
// Pop up a folder browse dialog
FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null,
function (err, files) {
if (!err && files.length > 0) {
// Load the new project into the folder tree
_loadProject(files[0]).then(result.resolve, result.reject);
} else {
result.reject();
}
});
}
})
.fail(function () {
result.reject();
});
}

/**
* Open a new project. Currently, Brackets must always have a project open, so
* this method handles both closing the current project and opening a new project.
Expand All @@ -1422,7 +1452,7 @@ define(function (require, exports, module) {
*/
function openProject(path) {

var result = new $.Deferred();
const result = new $.Deferred();

if(!path && !_filePickerSupported()){
Dialogs.showModalDialog(
Expand All @@ -1434,29 +1464,30 @@ define(function (require, exports, module) {
return result.promise();
}

// Confirm any unsaved changes first. We run the command in "prompt-only" mode, meaning it won't
// actually close any documents even on success; we'll do that manually after the user also oks
// the folder-browse dialog.
CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
.done(function () {
if (path) {
// use specified path
_loadProject(path).then(result.resolve, result.reject);
} else {
// Pop up a folder browse dialog
FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null, function (err, files) {
if (!err && files.length > 0) {
// Load the new project into the folder tree
_loadProject(files[0]).then(result.resolve, result.reject);
} else {
result.reject();
}
});
}
})
.fail(function () {
result.reject();
});
if(!path){
_openProject(null, result);
return result.promise();
}
const rootPath = ProjectModel._ensureTrailingSlash(path);
if(rootPath === getWelcomeProjectPath()) {
// welcome project path is always guaranteed to be present!
_openProject(rootPath, result);
return result.promise();
}

const rootEntry = FileSystem.getDirectoryForPath(path);
rootEntry.exists(function (err, exists) {
if (exists) {
_openProject(path, result);
return;
}
console.error("error project open path doesnt exist: ", path, err);
exports.trigger(EVENT_PROJECT_OPEN_FAILED, path);
_showErrorDialog(ERR_TYPE_LOADING_PROJECT_NATIVE, true, FileSystemError.NOT_FOUND, path)
.done(function () {
result.reject();
});
});

// if fail, don't open new project: user canceled (or we failed to save its unsaved changes)
return result.promise();
Expand Down
2 changes: 1 addition & 1 deletion test/spec/CSSColorPreview-test-files/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
.class-6 {color: #ff0090 #802095 #954e3e #454e3e #150e3e;}

.class-vars {
color: var(--slight-red); background-color: @blue-light; color: var(--red); background-color: @blue;
color: var(--slight-red); background-color: @blue-light; color: var(--red); background-color: @blue; color: $white;
}
Loading