mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
init multi-window implementation
This commit is contained in:
parent
6f99b36a44
commit
847a0fb01d
45 changed files with 904 additions and 833 deletions
59
src/Entity/Browser/History/Container.php
Normal file
59
src/Entity/Browser/History/Container.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Navbar;
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Content;
|
||||
|
||||
class Container
|
||||
{
|
||||
public \GtkBox $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History $history;
|
||||
|
||||
// Requirements
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Navbar $navbar;
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content $content;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History $history
|
||||
) {
|
||||
// Init dependency
|
||||
$this->history = $history;
|
||||
|
||||
// Init container
|
||||
$this->gtk = new \GtkBox(
|
||||
\GtkOrientation::VERTICAL
|
||||
);
|
||||
|
||||
// Init navbar
|
||||
$this->navbar = new Navbar(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->navbar->gtk
|
||||
);
|
||||
|
||||
// Init content
|
||||
$this->content = new Content(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->pack_start(
|
||||
$this->content->gtk,
|
||||
true,
|
||||
true,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
$this->navbar->refresh();
|
||||
$this->content->refresh();
|
||||
}
|
||||
}
|
||||
230
src/Entity/Browser/History/Container/Content.php
Normal file
230
src/Entity/Browser/History/Container/Content.php
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container;
|
||||
|
||||
class Content
|
||||
{
|
||||
public \GtkScrolledWindow $gtk;
|
||||
|
||||
// Requirements @TODO entity
|
||||
public \GtkTreeView $treeview;
|
||||
public \GtkListStore $list;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container $container;
|
||||
|
||||
// Defaults
|
||||
private string $_time = 'Time';
|
||||
private string $_title = 'Title';
|
||||
private string $_url = 'URL';
|
||||
private string $_format = 'c';
|
||||
private int $_margin = 8;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container $container
|
||||
) {
|
||||
// Init dependency
|
||||
$this->container = $container;
|
||||
|
||||
// Init container
|
||||
$this->gtk = new \GtkScrolledWindow;
|
||||
|
||||
// Init records listing
|
||||
$this->treeview = new \GtkTreeView;
|
||||
|
||||
$this->treeview->set_margin_start(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->treeview->set_margin_end(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_time,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_url,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_title,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
3
|
||||
)
|
||||
);
|
||||
|
||||
$this->list = new \GtkListStore(
|
||||
\GObject::TYPE_INT,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING
|
||||
);
|
||||
|
||||
$this->treeview->set_model(
|
||||
$this->list
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->treeview
|
||||
);
|
||||
|
||||
// Connect events
|
||||
$this->treeview->connect(
|
||||
'row-activated',
|
||||
function(
|
||||
\GtkTreeView $treeview
|
||||
) {
|
||||
$this->container->history->browser->container->tab->append(
|
||||
$this->getSelectedUrl()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$this->treeview->connect(
|
||||
'cursor-changed',
|
||||
function(
|
||||
\GtkTreeView $treeview
|
||||
) {
|
||||
$this->container->navbar->open->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->getSelectedId()
|
||||
)
|
||||
);
|
||||
|
||||
$this->container->navbar->delete->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Make initial search
|
||||
$this->search();
|
||||
}
|
||||
|
||||
// Append new row
|
||||
public function append(
|
||||
int $id,
|
||||
int $time,
|
||||
string $url,
|
||||
?string $title
|
||||
): void
|
||||
{
|
||||
$this->list->append(
|
||||
[
|
||||
$id,
|
||||
date(
|
||||
$this->_format,
|
||||
$time
|
||||
),
|
||||
$url,
|
||||
strval(
|
||||
$title
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Remove rows from list
|
||||
public function clear(): void
|
||||
{
|
||||
$this->list->clear();
|
||||
}
|
||||
|
||||
// Refresh rows using current navbar value
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->search(
|
||||
$this->container->navbar->filter->gtk->get_text()
|
||||
);
|
||||
}
|
||||
|
||||
// Do records search in database
|
||||
public function search(
|
||||
string $filter = ''
|
||||
): void
|
||||
{
|
||||
$this->clear();
|
||||
|
||||
if ($records = $this->container->history->browser->database->findHistory($filter))
|
||||
{
|
||||
foreach ($records as $record)
|
||||
{
|
||||
$this->append(
|
||||
$record->id,
|
||||
$record->time,
|
||||
$record->url,
|
||||
$record->title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$this->container->navbar->open->gtk->set_sensitive(
|
||||
false
|
||||
);
|
||||
|
||||
$this->container->navbar->delete->gtk->set_sensitive(
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSelectedId(): ?int
|
||||
{
|
||||
if ($id = $this->_getSelected(0))
|
||||
{
|
||||
return $id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getSelectedUrl(): ?string
|
||||
{
|
||||
if ($url = $this->_getSelected(2))
|
||||
{
|
||||
return $url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function _getSelected(
|
||||
int $column
|
||||
): null|int|string
|
||||
{
|
||||
list(
|
||||
$list,
|
||||
$row
|
||||
) = $this->treeview->get_selection()->get_selected();
|
||||
|
||||
if ($list && $row)
|
||||
{
|
||||
if ($value = $list->get_value($row, $column))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
104
src/Entity/Browser/History/Container/Navbar.php
Normal file
104
src/Entity/Browser/History/Container/Navbar.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Delete;
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Filter;
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Open;
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Search;
|
||||
|
||||
class Navbar
|
||||
{
|
||||
public \GtkBox $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container $container;
|
||||
|
||||
// Requirements
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Delete $delete;
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Filter $filter;
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Open $open;
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Navbar\Search $search;
|
||||
|
||||
// Defaults
|
||||
private int $_margin = 8;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container $container
|
||||
) {
|
||||
// Init dependency
|
||||
$this->container = $container;
|
||||
|
||||
// Init container
|
||||
$this->gtk = new \GtkBox(
|
||||
\GtkOrientation::HORIZONTAL
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_top(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_bottom(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_start(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_end(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_spacing(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
// Init open button
|
||||
$this->open = new Open(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->open->gtk
|
||||
);
|
||||
|
||||
// Init delete button
|
||||
$this->delete = new Delete(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->delete->gtk
|
||||
);
|
||||
|
||||
// Init filter entry
|
||||
$this->filter = new Filter(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->pack_start(
|
||||
$this->filter->gtk,
|
||||
true,
|
||||
true,
|
||||
0
|
||||
);
|
||||
|
||||
// Init search button
|
||||
$this->search = new Search(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->search->gtk
|
||||
);
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->delete->refresh();
|
||||
$this->open->refresh();
|
||||
}
|
||||
}
|
||||
33
src/Entity/Browser/History/Container/Navbar/Delete.php
Normal file
33
src/Entity/Browser/History/Container/Navbar/Delete.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Navbar;
|
||||
|
||||
class Delete extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navbar\Button
|
||||
{
|
||||
protected string $_label = 'Delete';
|
||||
|
||||
protected function _onCLick(
|
||||
\GtkButton $entity
|
||||
): void
|
||||
{
|
||||
if ($id = $this->navbar->container->content->getSelectedId())
|
||||
{
|
||||
$this->navbar->container->history->browser->database->deleteHistory(
|
||||
$id
|
||||
);
|
||||
}
|
||||
|
||||
$this->navbar->container->refresh();
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->navbar->container->content->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
29
src/Entity/Browser/History/Container/Navbar/Filter.php
Normal file
29
src/Entity/Browser/History/Container/Navbar/Filter.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Navbar;
|
||||
|
||||
class Filter extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navbar\Entry
|
||||
{
|
||||
private string $_placeholder = 'Search in history...';
|
||||
|
||||
protected function _onActivate(
|
||||
\GtkEntry $entry
|
||||
): void
|
||||
{
|
||||
$this->navbar->container->content->search(
|
||||
$entry->get_text()
|
||||
);
|
||||
}
|
||||
|
||||
protected function _onKeyRelease(
|
||||
\GtkEntry $entry,
|
||||
\GdkEvent $event
|
||||
): void
|
||||
{
|
||||
$this->navbar->container->content->search(
|
||||
$entry->get_text()
|
||||
);
|
||||
}
|
||||
}
|
||||
28
src/Entity/Browser/History/Container/Navbar/Open.php
Normal file
28
src/Entity/Browser/History/Container/Navbar/Open.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Navbar;
|
||||
|
||||
class Open extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navbar\Button
|
||||
{
|
||||
protected string $_label = 'Open';
|
||||
|
||||
protected function _onCLick(
|
||||
\GtkButton $entity
|
||||
): void
|
||||
{
|
||||
$this->navbar->container->history->browser->container->tab->append(
|
||||
$this->navbar->container->content->getSelectedUrl()
|
||||
);
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->navbar->container->content->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
20
src/Entity/Browser/History/Container/Navbar/Search.php
Normal file
20
src/Entity/Browser/History/Container/Navbar/Search.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Navbar;
|
||||
|
||||
class Search extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navbar\Button
|
||||
{
|
||||
protected bool $_sensitive = true;
|
||||
protected string $_label = 'Search';
|
||||
|
||||
protected function _onCLick(
|
||||
\GtkButton $entity
|
||||
): void
|
||||
{
|
||||
$this->navbar->container->content->search(
|
||||
$this->navbar->filter->gtk->get_text()
|
||||
);
|
||||
}
|
||||
}
|
||||
10
src/Entity/Browser/History/Header.php
Normal file
10
src/Entity/Browser/History/Header.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History;
|
||||
|
||||
class Header extends \Yggverse\Yoda\Abstract\Entity\HeaderBar
|
||||
{
|
||||
protected string $_title = 'History - Yoda';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue