mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
separate entities, use viewport container for history listing
This commit is contained in:
parent
f38aab0906
commit
d4bf1f6c56
6 changed files with 257 additions and 160 deletions
|
|
@ -4,23 +4,22 @@ declare(strict_types=1);
|
|||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Content\Viewport;
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Content\Table;
|
||||
|
||||
class Content
|
||||
{
|
||||
public \GtkScrolledWindow $gtk;
|
||||
|
||||
// Requirements @TODO entity
|
||||
public \GtkTreeView $treeview;
|
||||
public \GtkListStore $list;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container $container;
|
||||
|
||||
// Requirements
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content\Viewport $viewport;
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content\Table $table;
|
||||
|
||||
// Defaults
|
||||
private string $_time = 'Time';
|
||||
private string $_title = 'Title';
|
||||
private string $_url = 'URL';
|
||||
private string $_format = 'c';
|
||||
private int $_margin = 8;
|
||||
private int $_margin = 8;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container $container
|
||||
|
|
@ -31,146 +30,52 @@ class Content
|
|||
// Init container
|
||||
$this->gtk = new \GtkScrolledWindow;
|
||||
|
||||
// Init records listing
|
||||
$this->treeview = new \GtkTreeView;
|
||||
|
||||
$this->treeview->set_margin_start(
|
||||
$this->gtk->set_margin_start(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->treeview->set_margin_end(
|
||||
$this->gtk->set_margin_end(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_time,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
1
|
||||
)
|
||||
$this->gtk->set_margin_bottom(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_url,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
2
|
||||
)
|
||||
// Init history records table
|
||||
$this->table = new Table(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->treeview->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_title,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
3
|
||||
)
|
||||
// Init viewport to integrate scrolled window features
|
||||
$this->viewport = new Viewport(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->list = new \GtkListStore(
|
||||
\GObject::TYPE_INT,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING
|
||||
);
|
||||
|
||||
$this->treeview->set_model(
|
||||
$this->list
|
||||
$this->viewport->gtk->add(
|
||||
$this->table->gtk
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->treeview
|
||||
$this->viewport->gtk
|
||||
);
|
||||
|
||||
// Connect events
|
||||
$this->treeview->connect(
|
||||
'row-activated',
|
||||
function(
|
||||
\GtkTreeView $treeview
|
||||
) {
|
||||
// Focus on browser
|
||||
// $this->container->history->browser->gtk->present();
|
||||
|
||||
$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
|
||||
// Do 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();
|
||||
$this->table->data->clear();
|
||||
|
||||
if ($records = $this->container->history->browser->database->findHistory($filter))
|
||||
{
|
||||
foreach ($records as $record)
|
||||
{
|
||||
$this->append(
|
||||
$this->table->data->append(
|
||||
$record->id,
|
||||
$record->time,
|
||||
$record->url,
|
||||
|
|
@ -191,43 +96,11 @@ class Content
|
|||
}
|
||||
}
|
||||
|
||||
public function getSelectedId(): ?int
|
||||
// Refresh rows using current filter value in the navbar
|
||||
public function refresh(): void
|
||||
{
|
||||
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;
|
||||
$this->search(
|
||||
$this->container->navbar->filter->gtk->get_text()
|
||||
);
|
||||
}
|
||||
}
|
||||
141
src/Entity/Browser/History/Container/Content/Table.php
Normal file
141
src/Entity/Browser/History/Container/Content/Table.php
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Content;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\History\Container\Content\Table\Data;
|
||||
|
||||
class Table
|
||||
{
|
||||
public \GtkTreeView $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content $content;
|
||||
|
||||
// Requirements
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content\Table\Data $data;
|
||||
|
||||
// Defaults
|
||||
private string $_time = 'Time';
|
||||
private string $_title = 'Title';
|
||||
private string $_url = 'URL';
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container\Content $content
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->content = $content;
|
||||
|
||||
// Init tree view
|
||||
$this->gtk = new \GtkTreeView;
|
||||
|
||||
$this->gtk->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_time,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
$this->gtk->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_url,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
$this->gtk->append_column(
|
||||
new \GtkTreeViewColumn(
|
||||
$this->_title,
|
||||
new \GtkCellRendererText(),
|
||||
'text',
|
||||
3
|
||||
)
|
||||
);
|
||||
|
||||
// Init data model
|
||||
$this->data = new Data(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->set_model(
|
||||
$this->data->gtk
|
||||
);
|
||||
|
||||
// Connect events
|
||||
$this->gtk->connect(
|
||||
'row-activated',
|
||||
function()
|
||||
{
|
||||
// Focus on browser
|
||||
// $this->content->container->history->browser->gtk->present();
|
||||
|
||||
$this->content->container->history->browser->container->tab->append(
|
||||
$this->getSelectedUrl()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$this->gtk->connect(
|
||||
'cursor-changed',
|
||||
function()
|
||||
{
|
||||
$this->content->container->navbar->open->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->getSelectedId()
|
||||
)
|
||||
);
|
||||
|
||||
$this->content->container->navbar->delete->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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->gtk->get_selection()->get_selected();
|
||||
|
||||
if ($list && $row)
|
||||
{
|
||||
if ($value = $list->get_value($row, $column))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
60
src/Entity/Browser/History/Container/Content/Table/Data.php
Normal file
60
src/Entity/Browser/History/Container/Content/Table/Data.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Content\Table;
|
||||
|
||||
class Data
|
||||
{
|
||||
public \GtkListStore $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content\Table $table;
|
||||
|
||||
// Defaults
|
||||
private string $_time = 'c';
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container\Content\Table $table
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->table = $table;
|
||||
|
||||
// Init tree view
|
||||
$this->gtk = new \GtkListStore(
|
||||
\GObject::TYPE_INT,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING
|
||||
);
|
||||
}
|
||||
|
||||
// Append new row
|
||||
public function append(
|
||||
int $id,
|
||||
int $time,
|
||||
string $url,
|
||||
?string $title
|
||||
): void
|
||||
{
|
||||
$this->gtk->append(
|
||||
[
|
||||
$id,
|
||||
date(
|
||||
$this->_time,
|
||||
$time
|
||||
),
|
||||
$url,
|
||||
strval(
|
||||
$title
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Remove rows from list
|
||||
public function clear(): void
|
||||
{
|
||||
$this->gtk->clear();
|
||||
}
|
||||
}
|
||||
23
src/Entity/Browser/History/Container/Content/Viewport.php
Normal file
23
src/Entity/Browser/History/Container/Content/Viewport.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\History\Container\Content;
|
||||
|
||||
class Viewport
|
||||
{
|
||||
public \GtkViewport $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\History\Container\Content $content;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\History\Container\Content $content
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->content = $content;
|
||||
|
||||
// Init viewport
|
||||
$this->gtk = new \GtkViewport;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ class Delete extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Na
|
|||
\GtkButton $entity
|
||||
): void
|
||||
{
|
||||
if ($id = $this->navbar->container->content->getSelectedId())
|
||||
if ($id = $this->navbar->container->content->table->getSelectedId())
|
||||
{
|
||||
$this->navbar->container->history->browser->database->deleteHistory(
|
||||
$id
|
||||
|
|
@ -26,7 +26,7 @@ class Delete extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Na
|
|||
{
|
||||
$this->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->navbar->container->content->getSelectedId()
|
||||
$this->navbar->container->content->table->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Open extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navb
|
|||
): void
|
||||
{
|
||||
$this->navbar->container->history->browser->container->tab->append(
|
||||
$this->navbar->container->content->getSelectedUrl()
|
||||
$this->navbar->container->content->table->getSelectedUrl()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class Open extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navb
|
|||
{
|
||||
$this->gtk->set_sensitive(
|
||||
boolval(
|
||||
$this->navbar->container->content->getSelectedId()
|
||||
$this->navbar->container->content->table->getSelectedId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue