-
Notifications
You must be signed in to change notification settings - Fork 814
feat:优化世界管理界面和世界信息界面 #4823
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
feat:优化世界管理界面和世界信息界面 #4823
Changes from 15 commits
a02e44b
6c85f9d
cc099b0
85777e4
eb07b8f
6f7a53a
bec4e83
a005ec7
c6ecfc5
aa1be7d
34adf97
32905b3
f5d19d2
34b43cd
28c2a2e
90235be
32e10c7
2d20e7d
66ec94a
81fca70
0ae56a6
836bbed
ae070c7
345f2d6
af00011
7f97f55
88a2c6c
e6ff6c1
48e76e4
765e537
797b412
fc3727a
c6cb77c
2fc124a
32c231b
98d77b7
933f8f3
b69e4c7
85008ab
987e032
d34ca49
d1be359
98ee173
9864b08
742bc19
03a999b
d3efcc0
375ac4d
238a1cb
a1e5d62
e2eb62c
7641e2a
8578cfa
a99902c
26d6163
123dcd9
afa7ad7
3da183a
29daf82
9723e1a
effebb8
d85eb63
a9a9e57
8dbd78e
23f879b
0f9e1bd
6d97a71
c196ed5
5259759
d6a4582
3e2114e
834960a
82a5f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||
| package org.jackhuang.hmcl.ui.versions; | ||||||||
|
|
||||||||
| import javafx.stage.FileChooser; | ||||||||
| import org.jackhuang.hmcl.game.World; | ||||||||
| import org.jackhuang.hmcl.game.WorldLockedException; | ||||||||
| import org.jackhuang.hmcl.task.Schedulers; | ||||||||
| import org.jackhuang.hmcl.task.Task; | ||||||||
| import org.jackhuang.hmcl.ui.Controllers; | ||||||||
| import org.jackhuang.hmcl.ui.construct.MessageDialogPane; | ||||||||
| import org.jackhuang.hmcl.ui.wizard.SinglePageWizardProvider; | ||||||||
| import org.jackhuang.hmcl.util.StringUtils; | ||||||||
| import org.jackhuang.hmcl.util.io.FileUtils; | ||||||||
|
|
||||||||
| import java.io.IOException; | ||||||||
| import java.nio.channels.FileChannel; | ||||||||
| import java.nio.file.Path; | ||||||||
|
|
||||||||
| import static org.jackhuang.hmcl.util.i18n.I18n.i18n; | ||||||||
| import static org.jackhuang.hmcl.util.logging.Logger.LOG; | ||||||||
|
|
||||||||
| public final class WorldManageUIUtils { | ||||||||
| private WorldManageUIUtils() { | ||||||||
| } | ||||||||
|
|
||||||||
| public static void delete(World world, Runnable runnable) { | ||||||||
| delete(world, runnable, null); | ||||||||
| } | ||||||||
|
|
||||||||
| public static void delete(World world, Runnable runnable, FileChannel sessionLockChannel) { | ||||||||
| Controllers.confirm( | ||||||||
| i18n("button.remove.confirm"), | ||||||||
| i18n("world.delete"), | ||||||||
| () -> Task.runAsync(() -> closeSessionLockChannel(world, sessionLockChannel)) | ||||||||
| .thenRunAsync(world::delete) | ||||||||
| .whenComplete(Schedulers.javafx(), (result, exception) -> { | ||||||||
| if (exception == null) { | ||||||||
| runnable.run(); | ||||||||
| } else if (exception instanceof WorldLockedException) { | ||||||||
| Controllers.dialog(i18n("world.locked.failed"), null, MessageDialogPane.MessageType.WARNING); | ||||||||
| } else { | ||||||||
| Controllers.dialog(i18n("world.delete.failed", StringUtils.getStackTrace(exception)), null, MessageDialogPane.MessageType.WARNING); | ||||||||
| } | ||||||||
| }).start(), | ||||||||
| null | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| public static void export(World world) { | ||||||||
| export(world, null); | ||||||||
| } | ||||||||
|
|
||||||||
| public static void export(World world, FileChannel sessionLockChannel) { | ||||||||
| FileChooser fileChooser = new FileChooser(); | ||||||||
| fileChooser.setTitle(i18n("world.export.title")); | ||||||||
| fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(i18n("world"), "*.zip")); | ||||||||
| fileChooser.setInitialFileName(world.getWorldName()); | ||||||||
| Path file = FileUtils.toPath(fileChooser.showSaveDialog(Controllers.getStage())); | ||||||||
| if (file == null) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| closeSessionLockChannel(world, sessionLockChannel); | ||||||||
| } catch (IOException e) { | ||||||||
|
||||||||
| } catch (IOException e) { | |
| } catch (IOException e) { | |
| Controllers.dialog(i18n("world.export.failed", StringUtils.getStackTrace(e)), null, MessageDialogPane.MessageType.WARNING); |
Mine-diamond marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onExited method doesn't reset sessionLockChannel to null after closing it. This could cause issues if onNavigated is called again, as it checks if sessionLockChannel is null but won't recreate it if it's a closed (but non-null) channel. Consider setting sessionLockChannel = null after closing it in the try block.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这都onExited 了,再次打开只会重新new一个而不是再次Navigating,这个说法是错误的