-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core Editor: Show notification banner in case of error or outdated file
- Loading branch information
1 parent
075e4f1
commit ec53e52
Showing
21 changed files
with
360 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...shade/decima/ui/editor/impl/notifications/LoadedWithErrorsEditorNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.shade.decima.ui.editor.impl.notifications; | ||
|
||
import com.shade.decima.ui.editor.core.CoreEditor; | ||
import com.shade.platform.ui.editors.Editor; | ||
import com.shade.platform.ui.editors.EditorNotification; | ||
import com.shade.platform.ui.editors.spi.EditorNotificationProvider; | ||
import com.shade.util.NotNull; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class LoadedWithErrorsEditorNotificationProvider implements EditorNotificationProvider { | ||
@NotNull | ||
@Override | ||
public Collection<EditorNotification> getNotifications(@NotNull Editor editor) { | ||
if (!(editor instanceof CoreEditor coreEditor) || coreEditor.getErrorCount() == 0) { | ||
return List.of(); | ||
} | ||
|
||
return List.of(new EditorNotification( | ||
EditorNotification.Status.ERROR, | ||
MessageFormat.format( | ||
"<html>This file was loaded with <b>{0}</b> {0,choice,1#error|1<errors}. " | ||
+ "Refer to the console output for more information</html>", | ||
coreEditor.getErrorCount() | ||
), | ||
List.of() | ||
)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...hade/decima/ui/editor/impl/notifications/SupersededByPatchEditorNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.shade.decima.ui.editor.impl.notifications; | ||
|
||
import com.shade.decima.model.archive.ArchiveFile; | ||
import com.shade.decima.ui.Application; | ||
import com.shade.decima.ui.editor.NodeEditorInput; | ||
import com.shade.decima.ui.editor.NodeEditorInputSimple; | ||
import com.shade.decima.ui.navigator.NavigatorPath; | ||
import com.shade.decima.ui.navigator.impl.NavigatorFileNode; | ||
import com.shade.platform.model.runtime.VoidProgressMonitor; | ||
import com.shade.platform.ui.editors.Editor; | ||
import com.shade.platform.ui.editors.EditorManager; | ||
import com.shade.platform.ui.editors.EditorNotification; | ||
import com.shade.platform.ui.editors.spi.EditorNotificationProvider; | ||
import com.shade.util.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class SupersededByPatchEditorNotificationProvider implements EditorNotificationProvider { | ||
@NotNull | ||
@Override | ||
public Collection<EditorNotification> getNotifications(@NotNull Editor editor) { | ||
if (!(editor.getInput() instanceof NodeEditorInput input)) { | ||
return List.of(); | ||
} | ||
|
||
final NavigatorFileNode node = input.getNode(); | ||
final ArchiveFile currentFile = node.getFile(); | ||
final ArchiveFile actualFile = node.getArchive().getManager().getFile(currentFile.getIdentifier()); | ||
|
||
if (currentFile.equals(actualFile)) { | ||
return List.of(); | ||
} | ||
|
||
return List.of(new EditorNotification( | ||
EditorNotification.Status.WARNING, | ||
"<html>This file has been superseded by a patch file. The displayed content may be outdated</html>", | ||
List.of( | ||
new EditorNotification.Action("Open File", () -> Application.getNavigator().getModel() | ||
.findFileNode(new VoidProgressMonitor(), NavigatorPath.of( | ||
node.getProject().getContainer(), | ||
actualFile.getArchive(), | ||
node.getPath() | ||
)) | ||
.thenApply(n -> EditorManager.getInstance().openEditor(new NodeEditorInputSimple(n), true))) | ||
) | ||
)); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
modules/decima-ui/src/main/java/com/shade/decima/ui/navigator/NavigatorPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package com.shade.decima.ui.navigator; | ||
|
||
import com.shade.decima.model.app.ProjectContainer; | ||
import com.shade.decima.model.packfile.Packfile; | ||
import com.shade.decima.model.archive.Archive; | ||
import com.shade.decima.model.util.FilePath; | ||
import com.shade.util.NotNull; | ||
|
||
public record NavigatorPath(@NotNull String projectId, @NotNull String packfileId, @NotNull FilePath filePath) { | ||
@NotNull | ||
public static NavigatorPath of(@NotNull ProjectContainer container, @NotNull Packfile packfile, @NotNull FilePath filePath) { | ||
return new NavigatorPath(container.getId().toString(), packfile.getPath().getFileName().toString(), filePath); | ||
public static NavigatorPath of(@NotNull ProjectContainer container, @NotNull Archive archive, @NotNull FilePath filePath) { | ||
return new NavigatorPath(container.getId().toString(), archive.getId(), filePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
.../resources/META-INF/services/com.shade.platform.ui.editors.spi.EditorNotificationProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
com.shade.decima.ui.editor.impl.notifications.LoadedWithErrorsEditorNotificationProvider | ||
com.shade.decima.ui.editor.impl.notifications.SupersededByPatchEditorNotificationProvider |
Oops, something went wrong.