Skip to content

Commit

Permalink
Remove changedMode for clarity's sake
Browse files Browse the repository at this point in the history
  • Loading branch information
javierllorente committed Oct 29, 2024
1 parent 36cdb23 commit 2ddf01b
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions src/main/java/com/javierllorente/obsfx/BrowserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class BrowserController implements Initializable {
private ListProperty<String> packagesListProperty;
private HostServices hostServices;
private ObservableList<OBSPackage> searchResults;
private boolean changedMode;
private boolean loaded;
private String currentProject;
private String currentPackage;
Expand Down Expand Up @@ -255,13 +254,12 @@ private void load(String location) {
if (getLocationPackage().isBlank()) {
tabPane.getTabs().remove(filesTab);
tabPane.getTabs().remove(revisionsTab);
handleProjectTasks();
handleProjectTasks();
} else {
handlePackageTasks();
}
handlePackageTasks();
}

loaded = true;
logger.log(Level.INFO, "changedMode = {0}", changedMode);
}

public void goTo(String location) {
Expand Down Expand Up @@ -321,14 +319,14 @@ private void initPackageListView() {
String prj = currentProject;

String selectedPackage = (newValue == null) ? "" : newValue;

currentPackage = selectedPackage;

logger.log(Level.INFO, "selectedPackage = {0}", selectedPackage);
logger.log(Level.INFO, "currentPackage = {0}", currentPackage);
bookmarksController.setPkg(selectedPackage);
overviewController.toggleButtons(!selectedPackage.isEmpty());

// project/package -> project
if (selectedPackage.isEmpty() && getLocationPackage().isBlank()) {
overviewController.clearPkgData();
filesController.clear();
Expand All @@ -355,7 +353,6 @@ private void initPackageListView() {
tabPane.getTabs().add(2, revisionsTab);
overviewController.setDataLoaded(false);
requestsController.setDataLoaded(false);
changedMode = true;
}

// Achtung! selectedPackage is empty when projectA/package -> projectB/package
Expand All @@ -365,8 +362,8 @@ private void initPackageListView() {

locationTextField.setText(prj + "/" + selectedPackage);
int tabIndex = tabPane.getSelectionModel().getSelectedIndex();

logger.log(Level.INFO, "Tab index = {0}", tabIndex);

switch (tabIndex) {
case 0:
startPkgMetaConfigTask(prj, selectedPackage);
Expand All @@ -380,26 +377,12 @@ private void initPackageListView() {
startRevisionsTask(prj, selectedPackage);
break;
case 3:
if (changedMode) {
changedMode = false;
return;
}

if ((!prj.equals(requestsController.getPrj())
&& !selectedPackage.equals(requestsController.getPkg())
|| prj.equals(requestsController.getPrj())
&& !selectedPackage.equals(requestsController.getPkg()))
|| !prj.equals(requestsController.getPrj())
&& selectedPackage.equals(requestsController.getPkg())) {
requestsController.clear();
startRequestsTask(prj, selectedPackage);
}
startRequestsTask(prj, selectedPackage);
break;
}

lastProject = currentProject;
lastPackage = currentPackage;
changedMode = false;
});

packagesObservableList = FXCollections.observableArrayList();
Expand Down Expand Up @@ -432,17 +415,15 @@ public int compare(String t, String t1) {
private void initTabPane() {
tabPane.getTabs().remove(filesTab);
tabPane.getTabs().remove(revisionsTab);
changedMode = false;

tabPane.getSelectionModel().selectedIndexProperty().addListener((var ov, var t, var t1) -> {
logger.log(Level.INFO, "old tab {0}, new tab {1}",
new Object[]{t.intValue(), t1.intValue()});
logger.log(Level.INFO, "changedMode is {0}", changedMode);

// Avoid fetching requests twice when going from project to project/package (and viceversa);
// tabs are added/removed, so tab index changes which triggers this listener
if (changedMode && !(t1.intValue() == 1 || t1.intValue() == 3)) {
changedMode = false;
if ((lastPackage.isBlank() && !currentPackage.isBlank() && t1.intValue() == 3)
|| (!lastPackage.isBlank() && currentPackage.isBlank() && t1.intValue() == 1)) {
return;
}

Expand Down

0 comments on commit 2ddf01b

Please sign in to comment.