Browse Source

draft save to file menu

PHP-GTK3
yggverse 5 months ago
parent
commit
ffe582e694
  1. 11
      src/Entity/Browser/Menu/File.php
  2. 71
      src/Entity/Browser/Menu/File/Save.php

11
src/Entity/Browser/Menu/File.php

@ -5,6 +5,7 @@ declare(strict_types=1); @@ -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 @@ -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 @@ -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

@ -0,0 +1,71 @@ @@ -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…
Cancel
Save