diff --git a/notes.md b/notes.md index 88cd76fd..0a006033 100644 --- a/notes.md +++ b/notes.md @@ -1,3 +1,5 @@ +* Persist location of the server list frame for every Studio window + `dz4.1` 2024.01.29 ----- * Added line inspection (new popup menu in the table result) diff --git a/src/studio/kdb/Config.java b/src/studio/kdb/Config.java index 741d624d..039fa6a0 100755 --- a/src/studio/kdb/Config.java +++ b/src/studio/kdb/Config.java @@ -8,7 +8,6 @@ import studio.kdb.config.AbstractConfig; import studio.kdb.config.ActionOnExit; import studio.kdb.config.KdbMessageLimitAction; -import studio.ui.ServerList; import studio.utils.*; import studio.utils.log4j.EnvConfig; @@ -34,7 +33,6 @@ public class Config extends AbstractConfig { public static final String SHOW_SERVER_COMBOBOX = configDefault("showServerComboBox", ConfigType.BOOLEAN, true); public static final String AUTO_SAVE = configDefault("isAutoSave", ConfigType.BOOLEAN, false); public static final String ACTION_ON_EXIT = configDefault("actionOnExit", ConfigType.ENUM, ActionOnExit.SAVE); - public static final String SERVER_LIST_BOUNDS = configDefault("serverList", ConfigType.BOUNDS, new Dimension(ServerList.DEFAULT_WIDTH, ServerList.DEFAULT_HEIGHT)); public static final String CHART_BOUNDS = configDefault("chartBounds", ConfigType.BOUNDS, 0.5); public static final String CELL_RIGHT_PADDING = configDefault("cellRightPadding", ConfigType.DOUBLE, 0.5); public static final String CELL_MAX_WIDTH = configDefault("cellMaxWidth", ConfigType.INT, 200); @@ -368,6 +366,13 @@ private void migrateSaveOnExit() { } } + private void removeServerListConfig() { + config.remove("serverList.x"); + config.remove("serverList.y"); + config.remove("serverList.width"); + config.remove("serverList.height"); + } + private void checkForUpgrade() { if (config.size() == 0) { log.info("Found no or empty config"); @@ -391,6 +396,7 @@ private void checkForUpgrade() { } initServerHistory(); migrateSaveOnExit(); + removeServerListConfig(); config.setProperty("version", VERSION); } diff --git a/src/studio/kdb/Workspace.java b/src/studio/kdb/Workspace.java index 986acb7a..4739b79d 100644 --- a/src/studio/kdb/Workspace.java +++ b/src/studio/kdb/Workspace.java @@ -22,6 +22,7 @@ public class Workspace { private final static String Y = "y"; private final static String WIDTH = "width"; private final static String HEIGHT = "height"; + private final static String SERVER_LIST = "serverlist."; private final static String WINDOW = "window"; private final static String TAB = "tab"; private final static String LEFT = "left"; @@ -37,6 +38,7 @@ public class Workspace { private final static String LINE_ENDING = "lineEnding"; private final static String CARET = "caret"; + private final static Rectangle DEFAULT_BOUNDS = new Rectangle(-1,-1,0,0); private final static Logger log = LogManager.getLogger(); @@ -64,6 +66,10 @@ private static int getInt(Properties p, String key, int defValue) { } } + private static void setInt(Properties p, String key, int value) { + p.setProperty(key, Integer.toString(value)); + } + private static double getDouble(Properties p, String key, double defValue) { try { return Double.parseDouble(p.getProperty(key, "" + defValue)); @@ -72,6 +78,26 @@ private static double getDouble(Properties p, String key, double defValue) { } } + private static void setDouble(Properties p, String key, double value) { + p.setProperty(key, Double.toString(value)); + } + + private static Rectangle getBounds(Properties p, String prefix, Rectangle defValue) { + int x = getInt(p, prefix + X, defValue.x); + int y = getInt(p, prefix + Y, defValue.y); + int width = getInt(p, prefix + WIDTH, defValue.width); + int height = getInt(p, prefix + HEIGHT, defValue.height); + + return new Rectangle(x, y, width, height); + } + + public static void setBounds(Properties p, String prefix, Rectangle value) { + setInt(p, prefix + X, value.x); + setInt(p, prefix + Y, value.y); + setInt(p, prefix + WIDTH, value.width); + setInt(p, prefix + HEIGHT, value.height); + } + private static boolean hasKeysWithPrefix(Properties p, String prefix) { for(Object key : p.keySet() ) { if (key.toString().startsWith(prefix)) return true; @@ -220,6 +246,7 @@ private Window loadChild(String prefix, Properties p) { public static class TopWindow extends Window { private double resultDividerLocation = 0.5; private Rectangle location; + private Rectangle serverListBounds; public TopWindow() {} @@ -244,24 +271,28 @@ public void setLocation(Rectangle location) { this.location = location; } - protected void load(String prefix, Properties p) { - resultDividerLocation = Double.parseDouble(p.getProperty(prefix + RESULT_DIVIDER_LOCATION, "0.5")); - int x = Integer.parseInt(p.getProperty(prefix + X, "-1")); - int y = Integer.parseInt(p.getProperty(prefix + Y, "-1")); - int width = Integer.parseInt(p.getProperty(prefix + WIDTH, "0")); - int height = Integer.parseInt(p.getProperty(prefix + HEIGHT, "0")); - location = new Rectangle(x,y, width, height); + public Rectangle getServerListBounds() { + return serverListBounds; + } + public void setServerListBounds(Rectangle serverListBounds) { + this.serverListBounds = serverListBounds; + } + + protected void load(String prefix, Properties p) { + resultDividerLocation = getDouble(p, prefix + RESULT_DIVIDER_LOCATION, 0.5); + location = getBounds(p, prefix, DEFAULT_BOUNDS); + serverListBounds = getBounds(p, prefix + SERVER_LIST, DEFAULT_BOUNDS); super.load(prefix, p); } protected void save(String prefix, Properties p) { p.setProperty(prefix + RESULT_DIVIDER_LOCATION, Double.toString(resultDividerLocation)); if (location != null) { - p.setProperty(prefix + X, Integer.toString(location.x)); - p.setProperty(prefix + Y, Integer.toString(location.y)); - p.setProperty(prefix + WIDTH, Integer.toString(location.width)); - p.setProperty(prefix + HEIGHT, Integer.toString(location.height)); + setBounds(p, prefix, location); + } + if (serverListBounds != null) { + setBounds(p, prefix + SERVER_LIST, serverListBounds); } super.save(prefix, p); diff --git a/src/studio/ui/ServerList.java b/src/studio/ui/ServerList.java index acaf477f..75562abe 100644 --- a/src/studio/ui/ServerList.java +++ b/src/studio/ui/ServerList.java @@ -58,9 +58,27 @@ public class ServerList extends EscapeDialog implements TreeExpansionListener { private static final int menuShortcutKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); private final KeyStroke TREE_VIEW_KEYSTROKE = KeyStroke.getKeyStroke(KeyEvent.VK_T, menuShortcutKeyMask); - public ServerList(JFrame parent) { + public ServerList(JFrame parent, Rectangle bounds) { super(parent, "Server List"); initComponents(); + + if (bounds != null && Util.fitToScreen(bounds)) { + setBounds(bounds); + } else { + setBounds(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT); + setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); + Util.centerChildOnParent(this, parent); + } + } + + + public Server showServerTree(Server activeServer, List serverHistory, boolean selectHistoryTab) { + updateServerTree(Config.getInstance().getServerTree(), activeServer); + updateServerHistory(serverHistory); + selectHistoryTab(selectHistoryTab); + setVisible(true); + + return getSelectedServer(); } public void updateServerTree(ServerTreeNode serverTree, Server activeServer) { diff --git a/src/studio/ui/StudioWindow.java b/src/studio/ui/StudioWindow.java index 924c4b7f..187d1c3e 100755 --- a/src/studio/ui/StudioWindow.java +++ b/src/studio/ui/StudioWindow.java @@ -1061,22 +1061,13 @@ private void selectConnectionString() { } } - private void showServerList(boolean selectHistory) { - if (serverList == null) { - serverList = new ServerList(this); - } - Rectangle bounds = Config.getInstance().getBounds(Config.SERVER_LIST_BOUNDS); - serverList.setBounds(bounds); - - serverList.updateServerTree(CONFIG.getServerTree(), editor.getServer()); - serverList.updateServerHistory(serverHistory); - serverList.selectHistoryTab(selectHistory); - serverList.setVisible(true); + public ServerList getServerList() { + return serverList; + } - bounds = serverList.getBounds(); - CONFIG.setBounds(Config.SERVER_LIST_BOUNDS, bounds); + private void showServerList(boolean selectHistory) { + Server selectedServer = serverList.showServerTree(editor.getServer(), serverHistory, selectHistory); - Server selectedServer = serverList.getSelectedServer(); if (selectedServer == null || selectedServer.equals(editor.getServer())) return; setServer(selectedServer); @@ -1355,6 +1346,7 @@ public StudioWindow(Workspace.TopWindow workspaceWindow) { topPanel.add(rootEditorsPanel, BorderLayout.CENTER); initFrame(workspaceWindow.getLocation(), toolbar, splitpane, mainStatusBar); + serverList = new ServerList(this, workspaceWindow.getServerListBounds()); splitpane.setDividerLocation(workspaceWindow.getResultDividerLocation()); rootEditorsPanel.loadDividerLocation(workspaceWindow); @@ -1743,6 +1735,7 @@ public static Workspace getWorkspace() { Workspace.TopWindow workspaceWindow = workspace.addWindow(window == activeWindow); workspaceWindow.setResultDividerLocation(Util.getDividerLocation(window.splitpane)); workspaceWindow.setLocation(window.getBounds()); + workspaceWindow.setServerListBounds(window.getServerList().getBounds()); window.rootEditorsPanel.getWorkspace(workspaceWindow); } return workspace;