Skip to content

Commit

Permalink
Prevent sequential jobs from being executed when user cancels the lis…
Browse files Browse the repository at this point in the history
…t repair dialog
  • Loading branch information
Borewit committed Sep 17, 2023
1 parent 0ca0795 commit 5457ceb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/main/java/listfix/view/GUIScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -1700,12 +1700,12 @@ private void updateTabTitleForPlaylist(Playlist list, JDocumentComponent<Playlis

public void runClosestMatchOnAllTabs()
{
this._playlistTabbedPane.getAllEmbeddedMainComponent().forEach(ctrl -> {
for (PlaylistEditCtrl ctrl : this._playlistTabbedPane.getAllEmbeddedMainComponent()) {
this._playlistTabbedPane.setActiveDocument(ctrl.getPlaylist().getPath());
ctrl.locateMissingFiles();
ctrl.bulkFindClosestMatches();
});

if (!ctrl.locateMissingFiles() || !ctrl.bulkFindClosestMatches()) {
break;
}
}
}

private void reloadAllTabs()
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/listfix/view/controls/PlaylistEditCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ private void moveSelectedRowsDown()
}
}

public void locateMissingFiles()
/**
* Locate missing files
* @return false if cancelled, otherwise true
*/
public boolean locateMissingFiles()
{
_logger.debug(markerRepair, "Start locateMissingFiles()");
ProgressWorker<List<Integer>, String> worker = new ProgressWorker<>()
Expand Down Expand Up @@ -261,8 +265,10 @@ protected void done()
}
}
};

ProgressDialog pd = new ProgressDialog(getParentFrame(), true, worker, "Repairing...");
pd.setVisible(true);
pd.setVisible(true); // Wait until the worker completed
return !worker.isCancelled();
}

private void reorderList()
Expand Down Expand Up @@ -386,7 +392,10 @@ protected List<BatchMatchItem> doInBackground()
this.findClosestMatches(worker);
}

public void bulkFindClosestMatches()
/**
* @return false if cancelled otherwise true
*/
public boolean bulkFindClosestMatches()
{
final Collection<String> libraryFiles = listFixGui.getApplicationConfiguration().getMediaLibrary().getNestedMediaFiles();
ProgressWorker<List<BatchMatchItem>, String> worker = new ProgressWorker<>()
Expand All @@ -398,6 +407,7 @@ protected List<BatchMatchItem> doInBackground()
}
};
this.findClosestMatches(worker);
return !worker.isCancelled();
}

private void findClosestMatches(ProgressWorker<List<BatchMatchItem>, String> worker)
Expand Down Expand Up @@ -730,8 +740,9 @@ public void mouseClicked(MouseEvent evt)
_btnMagicFix.setToolTipText("Repair playlist");
_btnMagicFix.setEnabled(_playlist != null && _playlist.getFile().exists());
_btnMagicFix.addActionListener(evt -> {
locateMissingFiles();
bulkFindClosestMatches();
if (locateMissingFiles()) {
bulkFindClosestMatches();
}
});
_uiToolbar.add(_btnMagicFix);

Expand Down

0 comments on commit 5457ceb

Please sign in to comment.