Bugfix + code readability

This commit is contained in:
xfarrow
2023-08-09 11:33:43 +02:00
parent 37a1f7248a
commit 5115bb028b

View File

@@ -201,25 +201,29 @@ public class Desktop extends JFrame implements IDesktopFrame {
* @param directory * @param directory
*/ */
public void drawComponentsForDirectory(String 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 { try {
controller.clearSelectedNodes();
updateToolBarItems();
controller.setCurrentWorkingDirectory(directory);
pathTextBox.setText(controller.getCurrentWorkingDirectory());
loadTree();
loadDesktop(); loadDesktop();
} catch (Exception ex) { } catch (Exception ex) {
if (controller.getLastSafeDirectory() == null) { if (controller.getLastSafeDirectory() == null) {
System.exit(ERROR); System.exit(ERROR);
} else { } else {
drawComponentsForDirectory(controller.getLastSafeDirectory()); String lastSafeDirectory = controller.getLastSafeDirectory();
controller.setLastSafeDirectory(null); // Prevents infinite controller.setLastSafeDirectory(null); // Prevents infinite
// re-tries // re-tries
drawComponentsForDirectory(lastSafeDirectory);
return; return;
} }
} }
controller.setLastSafeDirectory(directory);
loadTree();
pathTextBox.setText(controller.getCurrentWorkingDirectory());
controller.setLastSafeDirectory(directory);
repaint(); repaint();
revalidate(); revalidate();
} }
@@ -1158,7 +1162,8 @@ public class Desktop extends JFrame implements IDesktopFrame {
private void unselectAllNodes() { private void unselectAllNodes() {
for (IDirectoryNodeButton directoryNode : controller for (IDirectoryNodeButton directoryNode : controller
.getSelectedNodes()) { .getSelectedNodes()) {
((JDirectoryNodeButton)directoryNode).setBackground(new Color(255, 255, 255)); ((JDirectoryNodeButton) directoryNode)
.setBackground(new Color(255, 255, 255));
} }
controller.clearSelectedNodes(); controller.clearSelectedNodes();
updateToolBarItems(); updateToolBarItems();