mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +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;
|
namespace Yggverse\Yoda\Entity\Browser\Menu;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Entity\Browser\Menu\File\Open;
|
use \Yggverse\Yoda\Entity\Browser\Menu\File\Open;
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Menu\File\Save;
|
||||||
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +31,7 @@ class File
|
||||||
// Init submenu container
|
// Init submenu container
|
||||||
$file = new \GtkMenu;
|
$file = new \GtkMenu;
|
||||||
|
|
||||||
// Init new tab menu item
|
// Init tab menu items
|
||||||
$open = new Open(
|
$open = new Open(
|
||||||
$this
|
$this
|
||||||
);
|
);
|
||||||
|
|
@ -39,6 +40,14 @@ class File
|
||||||
$open->gtk
|
$open->gtk
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$save = new Save(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$file->append(
|
||||||
|
$save->gtk
|
||||||
|
);
|
||||||
|
|
||||||
$this->gtk->set_submenu(
|
$this->gtk->set_submenu(
|
||||||
$file
|
$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