Merge branch 'fix/wiring_print_button_with_functionality' into 'main'
wiring the print button with the export service See merge request cse1105/2025-2026/teams/csep-team-76!51
This commit is contained in:
commit
5a17179fcb
2 changed files with 166 additions and 6 deletions
|
|
@ -6,11 +6,15 @@ import client.utils.Config;
|
|||
import client.utils.ConfigService;
|
||||
import client.utils.LocaleAware;
|
||||
import client.utils.LocaleManager;
|
||||
import client.utils.PrintExportService;
|
||||
import client.utils.ServerUtils;
|
||||
import client.utils.WebSocketDataService;
|
||||
import com.google.inject.Inject;
|
||||
import commons.Recipe;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -19,12 +23,13 @@ import javafx.scene.control.Button;
|
|||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.TextInputDialog;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
|
||||
/**
|
||||
* Controller for the recipe detail view.
|
||||
|
|
@ -251,15 +256,47 @@ public class RecipeDetailCtrl implements LocaleAware {
|
|||
}
|
||||
|
||||
/**
|
||||
* Print the currently viewed recipe.
|
||||
* Gives the User a download file prompt and lets the
|
||||
* user change the name of the downloaded file and
|
||||
* uses printExportService to create a downloadable file.
|
||||
*/
|
||||
@FXML
|
||||
private void printRecipe() {
|
||||
// TODO: actually make it print?
|
||||
throw new NotImplementedException("TODO:: Integrate with Print/Export service");
|
||||
// System.out.println("Recipe printed");
|
||||
}
|
||||
if (recipe == null) {
|
||||
return; // Do nothing if no recipe selected
|
||||
}
|
||||
|
||||
// Open directory chooser
|
||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||
directoryChooser.setTitle("Select Folder to Save Recipe");
|
||||
|
||||
File selectedDirectory = directoryChooser.showDialog(
|
||||
printRecipeButton.getScene().getWindow());
|
||||
|
||||
if (selectedDirectory == null) {
|
||||
return; // User cancelled
|
||||
}
|
||||
|
||||
// Ask for filename
|
||||
TextInputDialog dialog = new TextInputDialog(recipe.getName() + ".txt");
|
||||
dialog.setTitle("Save Recipe");
|
||||
dialog.setHeaderText("Enter filename for the recipe");
|
||||
dialog.setContentText("Filename:");
|
||||
|
||||
Optional<String> result = dialog.showAndWait();
|
||||
|
||||
if (result.isPresent()) {
|
||||
String filename = result.get();
|
||||
if (!filename.endsWith(".txt")) {
|
||||
filename = filename + ".txt";
|
||||
}
|
||||
|
||||
// Use PrintExportService methods
|
||||
String recipeText = PrintExportService.buildRecipeText(recipe);
|
||||
Path dirPath = selectedDirectory.toPath();
|
||||
PrintExportService.exportToFile(recipeText, dirPath, filename);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Toggles the favourite status of the currently viewed recipe in the
|
||||
* application configuration and writes the changes to disk.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue