mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
draft save to file menu
This commit is contained in:
parent
689667fe94
commit
ffe582e694
2 changed files with 81 additions and 1 deletions
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
71
src/Entity/Browser/Menu/File/Save.php
Normal file
71
src/Entity/Browser/Menu/File/Save.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Menu\File;
|
||||
|
||||
class Save
|
||||
{
|
||||
public \GtkMenuItem $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\Menu\File $file;
|
||||
|
||||
// Defaults
|
||||
private string $_label = 'Save As..';
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\Menu\File $file
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->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();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue