mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
show file open/save dialogs on the same screen as the currently focussed window
This commit is contained in:
parent
93f9539f7b
commit
9feefe8203
8 changed files with 32 additions and 5 deletions
|
@ -384,6 +384,7 @@ public class AppController implements Initializable {
|
|||
new FileChooser.ExtensionFilter("TXN", "*.txn")
|
||||
);
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showOpenDialog(window);
|
||||
if (file != null) {
|
||||
openTransactionFile(file);
|
||||
|
@ -523,6 +524,7 @@ public class AppController implements Initializable {
|
|||
fileChooser.setInitialFileName(fileName);
|
||||
}
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try(PrintWriter writer = new PrintWriter(file, StandardCharsets.UTF_8)) {
|
||||
|
@ -574,6 +576,7 @@ public class AppController implements Initializable {
|
|||
fileChooser.setInitialFileName(fileName);
|
||||
}
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
if(!asText && !file.getName().toLowerCase().endsWith(".psbt")) {
|
||||
|
@ -715,6 +718,7 @@ public class AppController implements Initializable {
|
|||
fileChooser.setTitle("Open Wallet");
|
||||
fileChooser.setInitialDirectory(Storage.getWalletsDir());
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showOpenDialog(window);
|
||||
if(file != null) {
|
||||
openWalletFile(file, forceSameWindow);
|
||||
|
|
|
@ -524,13 +524,24 @@ public class AppServices {
|
|||
}
|
||||
}
|
||||
|
||||
public static Window getActiveWindow() {
|
||||
return Stage.getWindows().stream().filter(Window::isFocused).findFirst().orElse(get().walletWindows.keySet().iterator().hasNext() ? get().walletWindows.keySet().iterator().next() : null);
|
||||
}
|
||||
|
||||
public static void moveToActiveWindowScreen(Dialog<?> dialog) {
|
||||
Window activeWindow = Stage.getWindows().stream().filter(Window::isFocused).findFirst().orElse(get().walletWindows.keySet().iterator().hasNext() ? get().walletWindows.keySet().iterator().next() : null);
|
||||
Window activeWindow = getActiveWindow();
|
||||
if(activeWindow != null) {
|
||||
moveToWindowScreen(activeWindow, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public static void moveToActiveWindowScreen(Window newWindow, double newWindowWidth, double newWindowHeight) {
|
||||
Window activeWindow = getActiveWindow();
|
||||
if(activeWindow != null) {
|
||||
moveToWindowScreen(activeWindow, newWindow, newWindowWidth, newWindowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void moveToWalletWindowScreen(Storage storage, Dialog<?> dialog) {
|
||||
moveToWindowScreen(getWindowForWallet(storage), dialog);
|
||||
}
|
||||
|
@ -538,12 +549,16 @@ public class AppServices {
|
|||
public static void moveToWindowScreen(Window currentWindow, Dialog<?> dialog) {
|
||||
Window newWindow = dialog.getDialogPane().getScene().getWindow();
|
||||
DialogPane dialogPane = dialog.getDialogPane();
|
||||
Screen currentScreen = Screen.getScreens().stream().filter(screen -> screen.getVisualBounds().contains(currentWindow.getX(), currentWindow.getY())).findFirst().orElse(null);
|
||||
if(currentScreen != null && !Screen.getPrimary().getVisualBounds().contains(currentWindow.getX(), currentWindow.getY()) && !currentScreen.getVisualBounds().contains(newWindow.getX(), newWindow.getY())) {
|
||||
double dialogWidth = dialogPane.getPrefWidth() > 0.0 ? dialogPane.getPrefWidth() : (dialogPane.getWidth() > 0.0 ? dialogPane.getWidth() : 360);
|
||||
double dialogHeight = dialogPane.getPrefHeight() > 0.0 ? dialogPane.getPrefHeight() : (dialogPane.getHeight() > 0.0 ? dialogPane.getHeight() : 200);
|
||||
double x = currentWindow.getX() + (currentWindow.getWidth() / 2) - (dialogWidth / 2);
|
||||
double y = currentWindow.getY() + (currentWindow.getHeight() / 2.2) - (dialogHeight / 2);
|
||||
moveToWindowScreen(currentWindow, newWindow, dialogWidth, dialogHeight);
|
||||
}
|
||||
|
||||
public static void moveToWindowScreen(Window currentWindow, Window newWindow, double newWindowWidth, double newWindowHeight) {
|
||||
Screen currentScreen = Screen.getScreens().stream().filter(screen -> screen.getVisualBounds().contains(currentWindow.getX(), currentWindow.getY())).findFirst().orElse(null);
|
||||
if(currentScreen != null && !Screen.getPrimary().getVisualBounds().contains(currentWindow.getX(), currentWindow.getY()) && !currentScreen.getVisualBounds().contains(newWindow.getX(), newWindow.getY())) {
|
||||
double x = currentWindow.getX() + (currentWindow.getWidth() / 2) - (newWindowWidth / 2);
|
||||
double y = currentWindow.getY() + (currentWindow.getHeight() / 2.2) - (newWindowHeight / 2);
|
||||
newWindow.setX(x);
|
||||
newWindow.setY(y);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.sparrowwallet.drongo.crypto.InvalidPasswordException;
|
|||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.FileImport;
|
||||
import com.sparrowwallet.sparrow.io.ImportException;
|
||||
|
@ -95,6 +96,7 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
|||
new FileChooser.ExtensionFilter("TXT", "*.txt")
|
||||
);
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showOpenDialog(window);
|
||||
if(file != null) {
|
||||
importFile(file, null);
|
||||
|
|
|
@ -87,6 +87,7 @@ public class FileWalletExportPane extends TitledDescriptionPane {
|
|||
exporter.getWalletModel().toDisplayString().toLowerCase().replace(" ", "") +
|
||||
(extension == null || extension.isEmpty() ? "" : "." + extension));
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
exportWallet(file);
|
||||
|
|
|
@ -277,6 +277,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
new FileChooser.ExtensionFilter("CRT", "*.crt")
|
||||
);
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showOpenDialog(window);
|
||||
if(file != null) {
|
||||
electrumCertificate.setText(file.getAbsolutePath());
|
||||
|
|
|
@ -670,6 +670,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
fileChooser.setInitialFileName(headersForm.getName() + ".psbt");
|
||||
}
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
if(!file.getName().toLowerCase().endsWith(".psbt")) {
|
||||
|
@ -880,6 +881,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
fileChooser.setInitialFileName(headersForm.getName().replace(".psbt", "") + ".txn");
|
||||
}
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try {
|
||||
|
|
|
@ -117,6 +117,7 @@ public class AddressesController extends WalletFormController implements Initial
|
|||
WalletNode purposeNode = copy.getNode(keyPurpose);
|
||||
purposeNode.fillToIndex(Math.max(purposeNode.getChildren().size(), DEFAULT_EXPORT_ADDRESSES_LENGTH));
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try(FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
|
|
|
@ -108,6 +108,7 @@ public class TransactionsController extends WalletFormController implements Init
|
|||
fileChooser.setTitle("Export Transactions as CSV");
|
||||
fileChooser.setInitialFileName(getWalletForm().getWallet().getName() + ".csv");
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try(FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
|
|
Loading…
Reference in a new issue