3636import javafx .scene .control .TreeItem ;
3737import javafx .scene .control .TreeView ;
3838import javafx .stage .DirectoryChooser ;
39+ import javafx .stage .FileChooser ;
3940import javafx .stage .Stage ;
4041
4142public class MainController {
@@ -298,6 +299,18 @@ void new_todo_list(ActionEvent event) throws IOException {
298299 }
299300 }
300301
302+ @ FXML
303+ void saveFileAs () throws IOException {
304+ //Open file explorer
305+ FileChooser chooser = new FileChooser ();
306+ File file = chooser .showSaveDialog (null );
307+ //Save current view to file
308+ Object controller = getController (get_current_tab ().getContent ());
309+ if (controller .getClass ().equals (new TodolistController ().getClass ())) {
310+ ((TodolistController ) controller ).saveFileAs (Paths .get (file .getAbsolutePath ()));
311+ }
312+ }
313+
301314 void openFile (String filename ) throws IOException {
302315 if (filename .endsWith (".todo" )) {
303316 //Load todolist view
@@ -320,4 +333,13 @@ Tab get_current_tab() {
320333 SingleSelectionModel <Tab > selectionModel = tab_pane .getSelectionModel ();
321334 return (selectionModel .getSelectedItem ());
322335 }
336+
337+ public static Object getController (Node node ) {
338+ Object controller = null ;
339+ do {
340+ controller = node .getProperties ().get ("foo" );
341+ node = node .getParent ();
342+ } while (controller == null && node != null );
343+ return controller ;
344+ }
323345}
0 commit comments