diff --git a/src/Entity/Browser/Menu/File.php b/src/Entity/Browser/Menu/File.php index 13faff02..00cc75aa 100644 --- a/src/Entity/Browser/Menu/File.php +++ b/src/Entity/Browser/Menu/File.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Yggverse\Yoda\Entity\Browser\Menu; use \Yggverse\Yoda\Entity\Browser\Menu\File\Open; +use \Yggverse\Yoda\Entity\Browser\Menu\File\Save; class File { @@ -30,7 +31,7 @@ class File // Init submenu container $file = new \GtkMenu; - // Init new tab menu item + // Init tab menu items $open = new Open( $this ); @@ -39,6 +40,14 @@ class File $open->gtk ); + $save = new Save( + $this + ); + + $file->append( + $save->gtk + ); + $this->gtk->set_submenu( $file ); diff --git a/src/Entity/Browser/Menu/File/Save.php b/src/Entity/Browser/Menu/File/Save.php new file mode 100644 index 00000000..195e446d --- /dev/null +++ b/src/Entity/Browser/Menu/File/Save.php @@ -0,0 +1,71 @@ +file = $file; + + // Init menu item + $this->gtk = \GtkMenuItem::new_with_label( + $this->_label + ); + + // Render + $this->gtk->show(); + + // Init events + $this->gtk->connect( + 'activate', + function() + { + $dialog = new \GtkFileChooserDialog( + 'Save to file', + $this->file->menu->browser->gtk, + \GtkFileChooserAction::SAVE, + [ + 'Cancel', + \GtkResponseType::CANCEL, + 'Save', + \GtkResponseType::APPLY + ] + ); + + if ($home = getenv('HOME')) // @TODO keep last path + { + $dialog->set_current_folder( + $home + ); + } + + $dialog->set_create_folders( + true + ); + + if (\GtkResponseType::APPLY == $dialog->run()) + { + file_put_contents( + $dialog->get_filename(), + '' // @TODO get active tab content + ); + } + + $dialog->destroy(); + } + ); + } +} \ No newline at end of file