From 5115bb028b87924ceea71448e04ae42d06365c6a Mon Sep 17 00:00:00 2001 From: xfarrow Date: Wed, 9 Aug 2023 11:33:43 +0200 Subject: [PATCH] Bugfix + code readability --- Guify/src/views/Desktop.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Guify/src/views/Desktop.java b/Guify/src/views/Desktop.java index 80b718b..c925b78 100644 --- a/Guify/src/views/Desktop.java +++ b/Guify/src/views/Desktop.java @@ -201,25 +201,29 @@ public class Desktop extends JFrame implements IDesktopFrame { * @param directory */ public void drawComponentsForDirectory(String directory) { + controller.clearSelectedNodes(); + updateToolBarItems(); + controller.setCurrentWorkingDirectory(directory); + + // Only loadDesktop() can tell whether we have the permission to view + // the content of the directory try { - controller.clearSelectedNodes(); - updateToolBarItems(); - controller.setCurrentWorkingDirectory(directory); - pathTextBox.setText(controller.getCurrentWorkingDirectory()); - loadTree(); loadDesktop(); } catch (Exception ex) { if (controller.getLastSafeDirectory() == null) { System.exit(ERROR); } else { - drawComponentsForDirectory(controller.getLastSafeDirectory()); + String lastSafeDirectory = controller.getLastSafeDirectory(); controller.setLastSafeDirectory(null); // Prevents infinite // re-tries + drawComponentsForDirectory(lastSafeDirectory); return; } } - controller.setLastSafeDirectory(directory); + loadTree(); + pathTextBox.setText(controller.getCurrentWorkingDirectory()); + controller.setLastSafeDirectory(directory); repaint(); revalidate(); } @@ -1158,7 +1162,8 @@ public class Desktop extends JFrame implements IDesktopFrame { private void unselectAllNodes() { for (IDirectoryNodeButton directoryNode : controller .getSelectedNodes()) { - ((JDirectoryNodeButton)directoryNode).setBackground(new Color(255, 255, 255)); + ((JDirectoryNodeButton) directoryNode) + .setBackground(new Color(255, 255, 255)); } controller.clearSelectedNodes(); updateToolBarItems();