use of com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution in project tactview by helospark.
the class DefaultWindowMenuItemConfiguration method saveLayoutMenuItem.
@Bean
@Order(3997)
public SelectableMenuContribution saveLayoutMenuItem(MessagingService messagingService, QuerySaveFilenameService querySaveFilenameService, @Value("${tactview.homedirectory}") String homeDirectory, AlertDialogFactory alertDialogFactory) {
return new DefaultMenuContribution(List.of(WINDOW_MENU_ITEM, "Save layout"), e -> {
QuerySaveFileNameRequest request = QuerySaveFileNameRequest.builder().withInitialDirectory(homeDirectory).withTitle("Save layout file").build();
Optional<String> optionalFileName = querySaveFilenameService.queryUserAboutFileName(request);
if (optionalFileName.isPresent()) {
try {
String fileName = optionalFileName.get();
if (!fileName.endsWith("." + TACTVIEW_LAYOUT_EXTENSION)) {
fileName += ("." + TACTVIEW_LAYOUT_EXTENSION);
}
DetachableTabPaneLoadModel data = dockableTabRepository.extractLoadModel();
String result = objectMapper.writeValueAsString(data);
try (FileOutputStream fos = new FileOutputStream(new File(fileName))) {
fos.write(result.getBytes(StandardCharsets.UTF_8));
}
} catch (Exception e1) {
alertDialogFactory.showExceptionDialog("Unable to save layout", e1);
LOGGER.error("Unable to save layout", e1);
}
}
});
}
use of com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution in project tactview by helospark.
the class DefaultEditMenuItemConfiguration method addChapterMenuItem.
@Bean
@Order(1950)
public SelectableMenuContribution addChapterMenuItem(AlertDialogFactory dialogFactory, TimelineState timelineState, MarkerRepository chapterRepository) {
KeyCodeCombination combination = hotKeyRepository.registerOrGetHotKey("addChapter", new KeyCodeCombination(KeyCode.P, KeyCodeCombination.CONTROL_DOWN), "Add chapter").getCombination();
return new DefaultMenuContribution(List.of(EDIT_ROOT, CHAPTER_ROOT, "Add chapter at current position"), event -> {
TimelinePosition position = timelineState.getPlaybackPosition();
Optional<String> result = dialogFactory.showTextInputDialog("Add chapter", "Label of the chapter", "Chapter x");
if (result.isPresent()) {
chapterRepository.addChapter(position, result.get());
}
}, combination);
}
use of com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution in project tactview by helospark.
the class DefaultEditMenuItemConfiguration method cutAllAtCurrentPositionMenuItem.
@Bean
@Order(1910)
public SelectableMenuContribution cutAllAtCurrentPositionMenuItem(AlertDialogFactory dialogFactory, TimelineState timelineState, UiCutHandler uiCutHandler) {
String title = "Cut at current position";
KeyCodeCombination combination = hotKeyRepository.registerOrGetHotKey("cutAllAtCurrentPosition", new KeyCodeCombination(KeyCode.K, KeyCodeCombination.CONTROL_DOWN), title).getCombination();
return new DefaultMenuContribution(List.of(EDIT_ROOT, CUT_MENU_ITEM, title), event -> {
uiCutHandler.cutAllAtCurrentPosition();
}, combination);
}
use of com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution in project tactview by helospark.
the class DefaultEditMenuItemConfiguration method cutSelectedUntilCurrent.
@Bean
@Order(1911)
public SelectableMenuContribution cutSelectedUntilCurrent(AlertDialogFactory dialogFactory, TimelineState timelineState, UiCutHandler uiCutHandler) {
String title = "Set selected startpoint";
KeyCodeCombination combination = hotKeyRepository.registerOrGetHotKey("cutSelectedUntilCursor", new KeyCodeCombination(KeyCode.I, KeyCodeCombination.CONTROL_DOWN), title).getCombination();
return new DefaultMenuContribution(List.of(EDIT_ROOT, CUT_MENU_ITEM, title), event -> {
uiCutHandler.cutSelectedUntilCursor(true);
}, combination);
}
use of com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution in project tactview by helospark.
the class DefaultEditMenuItemConfiguration method exportAsYoutubeChapterMenuItem.
@Bean
@Order(1952)
public SelectableMenuContribution exportAsYoutubeChapterMenuItem(MarkerRepository chapterRepository, AlertDialogFactory alertDialogFactory) {
return new DefaultMenuContribution(List.of(EDIT_ROOT, CHAPTER_ROOT, "Show as Youtube chapter"), event -> {
String result = "";
String errors = "";
int numberOfChapters = 0;
TimelinePosition previousPosition = null;
if (chapterRepository.getMarkers().get(TimelinePosition.ofZero()) == null) {
result += "00:00 Intro\n";
errors += "[WARN] No chapter is defined in position 00:00, added intro chapter at 0\n";
previousPosition = TimelinePosition.ofZero();
++numberOfChapters;
}
for (var chapter : chapterRepository.getMarkers().entrySet()) {
long allSeconds = chapter.getKey().getSeconds().longValue();
long minutes = allSeconds / 60;
long seconds = allSeconds % 60;
result += (String.format("%02d:%02d %s\n", minutes, seconds, chapter.getValue()));
++numberOfChapters;
if (previousPosition != null && chapter.getKey().subtract(previousPosition).isLessThan(10)) {
errors += "[ERROR] Chapter at " + minutes + ":" + seconds + " is less than 10s from previous chapter which is unaccaptable by YouTube\n";
}
previousPosition = chapter.getKey();
}
if (numberOfChapters < 3) {
errors += "[ERROR] Minimum 3 chapters needed by YouTube";
}
alertDialogFactory.showTextDialog("Youtube chapters", "Copy the below in your description to add chapters to Youtube", errors, result);
});
}
Aggregations