use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<ContainerDTO> onSuccess, Consumer<Exception> onError) {
try {
final File containerFile = new File(container.getPath());
FileUtils.deleteDirectory(containerFile);
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
onError.accept(e);
}
// TODO: better way to get engine ID
final String engineId = container.getEngine().toLowerCase();
final List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
// remove the shortcuts leading to the container
categories.stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).forEach(shortcut -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include(\"engines." + engineId + ".shortcuts.reader\");", result -> {
final org.graalvm.polyglot.Value shortcutReaderClass = (org.graalvm.polyglot.Value) result;
final ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
shortcutReader.of(shortcut);
final String containerName = shortcutReader.getContainer();
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcut);
}
}, onError);
});
onSuccess.accept(container);
}
use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.
the class LibraryFeaturePanelSkin method createCombinedListWidget.
private CombinedListWidget<ShortcutDTO> createCombinedListWidget() {
final FilteredList<ShortcutDTO> filteredShortcuts = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName)), ShortcutCategoryDTO::getShortcuts)).filtered(getControl().getFilter()::filter);
filteredShortcuts.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedShortcutCategoryProperty()));
final SortedList<ShortcutDTO> sortedShortcuts = filteredShortcuts.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
final ObservableList<ListWidgetElement<ShortcutDTO>> listWidgetEntries = new MappedList<>(sortedShortcuts, ListWidgetElement::create);
final CombinedListWidget<ShortcutDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
// bind direction: controller property -> skin property
getControl().selectedShortcutProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
combinedListWidget.select(newValue);
} else {
combinedListWidget.deselect();
}
});
// bind direction: skin property -> controller properties
combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
final ShortcutDTO selectedItem = newValue.getItem();
final MouseEvent event = newValue.getEvent();
getControl().setSelectedShortcut(selectedItem);
getControl().setOpenedDetailsPanel(new ShortcutInformation(selectedItem));
if (event.getClickCount() == 2) {
getControl().runShortcut(selectedItem);
}
} else {
getControl().setSelectedShortcut(null);
getControl().setOpenedDetailsPanel(new None());
}
});
return combinedListWidget;
}
use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.
the class LibraryController method setDefaultLibraryCategoryIcons.
/**
* sets the default category icons for the library sidebar buttons
*
* We cannot use the default category buttons for this purpose for several reasons:
* - It cannot be guaranteed that the repository which contained the category of a certain app does still exist
* after the app has been installed (e.g. the repository might have been deleted).
* - It should not be required to fetch the repository to use the library.
*
* Therefore, use the following approach:
* - When installing an app, store the icon for its category together with the shortcut (i.e. in the library).
* - Use this icon as fallback if the theme does not specify an icon for this category.
*
* @param categories list of shortcut categories
*/
private void setDefaultLibraryCategoryIcons(List<ShortcutCategoryDTO> categories) {
Platform.runLater(() -> {
try {
StringBuilder cssBuilder = new StringBuilder();
for (ShortcutCategoryDTO category : categories) {
cssBuilder.append("#" + LibrarySidebarToggleGroupSkin.getToggleButtonId(category.getId()) + "{\n");
final String categoryIconPath = Optional.ofNullable(category.getIcon()).map(categoryIcon -> categoryIcon.toString()).orElse("/org/phoenicis/javafx/views/common/phoenicis.png");
cssBuilder.append(String.format("-fx-background-image: url('%s');\n", categoryIconPath));
cssBuilder.append("}\n");
}
String css = cssBuilder.toString();
Path temp = Files.createTempFile("defaultLibraryCategoryIcons", ".css").toAbsolutePath();
File tempFile = temp.toFile();
tempFile.deleteOnExit();
Files.write(temp, css.getBytes());
String defaultLibraryCategoryIconsCss = temp.toUri().toString();
this.themeManager.setDefaultLibraryCategoryIconsCss(defaultLibraryCategoryIconsCss);
} catch (IOException e) {
LOGGER.warn("Could not set default category icons.", e);
}
});
}
use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.
the class LibrarySidebarSkin method createSidebarToggleGroup.
/**
* Creates the {@link LibrarySidebarToggleGroup} which contains all known shortcut categories
*/
private LibrarySidebarToggleGroup createSidebarToggleGroup() {
final FilteredList<ShortcutCategoryDTO> filteredShortcutCategories = getControl().getItems().filtered(getControl().getFilter()::filter);
filteredShortcutCategories.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().searchTermProperty()));
final LibrarySidebarToggleGroup categoryView = new LibrarySidebarToggleGroup(tr("Categories"), filteredShortcutCategories);
getControl().selectedShortcutCategoryProperty().bind(categoryView.selectedElementProperty());
return categoryView;
}
use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.
the class LibraryFeaturePanelSkin method createSidebar.
/**
* {@inheritDoc}
*/
@Override
public ObjectExpression<SidebarBase<?, ?, ?>> createSidebar() {
final SortedList<ShortcutCategoryDTO> sortedCategories = getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName));
final LibrarySidebar sidebar = new LibrarySidebar(getControl().getFilter(), sortedCategories, this.selectedListWidget);
sidebar.applicationNameProperty().bind(getControl().applicationNameProperty());
sidebar.javaFxSettingsManagerProperty().bind(getControl().javaFxSettingsManagerProperty());
sidebar.setOnCreateShortcut(() -> {
// deselect the currently selected shortcut
getControl().setSelectedShortcut(null);
// open the shortcut creation details panel
getControl().setOpenedDetailsPanel(new ShortcutCreation());
});
sidebar.setOnOpenConsole(getControl()::openConsole);
// set the default selection
sidebar.setSelectedListWidget(Optional.ofNullable(getControl().getJavaFxSettingsManager()).map(JavaFxSettingsManager::getLibraryListType).orElse(ListWidgetType.ICONS_LIST));
// save changes to the list widget selection to the hard drive
sidebar.selectedListWidgetProperty().addListener((observable, oldValue, newValue) -> {
final JavaFxSettingsManager javaFxSettingsManager = getControl().getJavaFxSettingsManager();
if (newValue != null) {
javaFxSettingsManager.setLibraryListType(newValue);
javaFxSettingsManager.save();
}
});
return new SimpleObjectProperty<>(sidebar);
}
Aggregations