use of qupath.lib.projects.Projects in project qupath by qupath.
the class QuPathGUI method createRecentProjectsMenu.
private Menu createRecentProjectsMenu() {
// Create a recent projects list in the File menu
ObservableList<URI> recentProjects = PathPrefs.getRecentProjectList();
Menu menuRecent = MenuTools.createMenu("Recent projects...");
EventHandler<Event> validationHandler = e -> {
menuRecent.getItems().clear();
for (URI uri : recentProjects) {
if (uri == null)
continue;
String name = Project.getNameFromURI(uri);
name = ".../" + name;
MenuItem item = new MenuItem(name);
item.setOnAction(e2 -> {
Project<BufferedImage> project;
try {
project = ProjectIO.loadProject(uri, BufferedImage.class);
setProject(project);
} catch (Exception e1) {
Dialogs.showErrorMessage("Project error", "Cannot find project " + uri);
logger.error("Error loading project", e1);
}
});
menuRecent.getItems().add(item);
}
};
// Ensure the menu is populated
menuRecent.parentMenuProperty().addListener((v, o, n) -> {
if (o != null && o.getOnMenuValidation() == validationHandler)
o.setOnMenuValidation(null);
if (n != null)
n.setOnMenuValidation(validationHandler);
});
return menuRecent;
}
Aggregations