mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-25 00:01:02 +00:00
Improve action confirm dialog
This commit is contained in:
3 files changed
+45
-26
No files matched your search
@@ -9,6 +9,8 @@ import io.xpipe.app.core.window.AppDialog;
|
||||
import io.xpipe.app.issue.ErrorEventFactory;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.platform.LabelGraphic;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.util.DataStoreFormatter;
|
||||
import io.xpipe.app.util.LicensedFeature;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
@@ -116,9 +118,32 @@ public abstract class AbstractAction {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean executeSyncImpl(boolean confirm) {
|
||||
if (confirm && !ActionConfirmation.confirmAction(this)) {
|
||||
return false;
|
||||
private List<DataStoreEntry> getEntryContext() {
|
||||
if (this instanceof StoreContextAction ca) {
|
||||
return ca.getStoreEntryContext();
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private boolean hasEnabledConfirmAllModifications() {
|
||||
var context = getEntryContext();
|
||||
return context.stream().anyMatch(dataStoreEntry -> {
|
||||
var config = DataStorage.get().getEffectiveCategoryConfig(dataStoreEntry);
|
||||
return config.getConfirmAllModifications() != null && config.getConfirmAllModifications();
|
||||
});
|
||||
}
|
||||
|
||||
public boolean requiresConfirmation() {
|
||||
return forceConfirmation() || (isMutation() && hasEnabledConfirmAllModifications());
|
||||
}
|
||||
|
||||
public boolean executeSyncImpl(boolean checkConfirm) {
|
||||
if (checkConfirm && requiresConfirmation()) {
|
||||
var r = ActionConfirmation.confirmAction(this);
|
||||
if (!r) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (closed) {
|
||||
|
||||
@@ -12,10 +12,6 @@ import java.util.List;
|
||||
public class ActionConfirmation {
|
||||
|
||||
public static boolean confirmAction(AbstractAction action) {
|
||||
if (!action.forceConfirmation() && (!action.isMutation() || !confirmAllModifications(action))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var ok = new SimpleBooleanProperty(false);
|
||||
var modal = ModalOverlay.of("confirmAction", new ActionConfirmComp(action).prefWidth(550));
|
||||
modal.addButton(ModalButton.cancel());
|
||||
@@ -23,20 +19,4 @@ public class ActionConfirmation {
|
||||
modal.showAndWait();
|
||||
return ok.get();
|
||||
}
|
||||
|
||||
private static boolean confirmAllModifications(AbstractAction action) {
|
||||
var context = getContext(action);
|
||||
return context.stream().anyMatch(dataStoreEntry -> {
|
||||
var config = DataStorage.get().getEffectiveCategoryConfig(dataStoreEntry);
|
||||
return config.getConfirmAllModifications() != null && config.getConfirmAllModifications();
|
||||
});
|
||||
}
|
||||
|
||||
private static List<DataStoreEntry> getContext(AbstractAction action) {
|
||||
if (action instanceof StoreContextAction ca) {
|
||||
return ca.getStoreEntryContext();
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.xpipe.app.action;
|
||||
|
||||
import io.xpipe.app.core.AppCache;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.core.AppRestart;
|
||||
import io.xpipe.app.core.window.AppDialog;
|
||||
import io.xpipe.app.ext.ProcModuleProvider;
|
||||
@@ -27,17 +28,25 @@ public class XPipeUrlProvider implements LauncherUrlProvider {
|
||||
}
|
||||
|
||||
if ("action".equals(a)) {
|
||||
if (!checkPermission()) {
|
||||
if (!checkEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var query = uri.getQuery();
|
||||
var action = ActionUrls.parse(query);
|
||||
|
||||
if (action.isPresent() && !action.get().requiresConfirmation()) {
|
||||
var r = ActionConfirmation.confirmAction(action.get());
|
||||
if (!r) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return action.orElse(null);
|
||||
}
|
||||
|
||||
if ("sync".equals(a)) {
|
||||
if (!checkPermission()) {
|
||||
if (!checkEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -49,6 +58,11 @@ public class XPipeUrlProvider implements LauncherUrlProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
var confirm = AppDialog.confirm("syncUrlSetTitle", AppI18n.observable("syncUrlSetContent", repo));
|
||||
if (!confirm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AppPrefs.get().setFromExternal(AppPrefs.get().storageGitRemote(), repo);
|
||||
AppPrefs.get().setFromExternal(AppPrefs.get().enableGitStorage(), true);
|
||||
AppPrefs.get().save();
|
||||
@@ -59,7 +73,7 @@ public class XPipeUrlProvider implements LauncherUrlProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkPermission() {
|
||||
private boolean checkEnabled() {
|
||||
var cache = AppCache.getBoolean("externalUrlsPermitted", false);
|
||||
if (cache) {
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user