Browse Source

implement history action buttons

PHP-GTK3
yggverse 7 months ago
parent
commit
3123bd14c3
  1. 4
      config.json
  2. 188
      src/Entity/Tab/History.php

4
config.json

@ -160,10 +160,10 @@
"visible":true, "visible":true,
"label":"Open" "label":"Open"
}, },
"clear": "delete":
{ {
"visible":true, "visible":true,
"label":"Clear" "label":"Delete"
}, },
"search": "search":
{ {

188
src/Entity/Tab/History.php

@ -13,7 +13,7 @@ class History
$body; $body;
public \GtkButton $open, public \GtkButton $open,
$clear, $delete,
$search; $search;
public \GtkEntry $filter; public \GtkEntry $filter;
@ -67,16 +67,6 @@ class History
false false
); );
$this->open->connect(
'clicked',
function ()
{
// @TODO
$this->refresh();
}
);
if ($this->config->header->button->open->visible) if ($this->config->header->button->open->visible)
{ {
$this->header->add( $this->header->add(
@ -84,29 +74,19 @@ class History
); );
} }
// Clear button // Delete button
$this->clear = \GtkButton::new_with_label( $this->delete = \GtkButton::new_with_label(
$this->config->header->button->clear->label $this->config->header->button->delete->label
); );
$this->clear->set_sensitive( $this->delete->set_sensitive(
false false
); );
$this->clear->connect( if ($this->config->header->button->delete->visible)
'clicked',
function ()
{
// @TODO
$this->refresh();
}
);
if ($this->config->header->button->clear->visible)
{ {
$this->header->add( $this->header->add(
$this->clear $this->delete
); );
} }
@ -117,16 +97,6 @@ class History
$this->config->header->filter->placeholder $this->config->header->filter->placeholder
); );
$this->filter->connect(
'activate',
function ($entry)
{
$this->refresh(
$entry->get_text()
);
}
);
$this->header->pack_start( $this->header->pack_start(
$this->filter, $this->filter,
true, true,
@ -139,16 +109,6 @@ class History
$this->config->header->button->search->label $this->config->header->button->search->label
); );
$this->search->connect(
'clicked',
function ()
{
$this->refresh(
$this->filter->get_text()
);
}
);
if ($this->config->header->button->search->visible) if ($this->config->header->button->search->visible)
{ {
$this->header->add( $this->header->add(
@ -164,7 +124,7 @@ class History
'Time', 'Time',
new \GtkCellRendererText(), new \GtkCellRendererText(),
'text', 'text',
0 1
) )
); );
@ -173,7 +133,7 @@ class History
'Title', 'Title',
new \GtkCellRendererText(), new \GtkCellRendererText(),
'text', 'text',
1 2
) )
); );
@ -182,12 +142,13 @@ class History
'URL', 'URL',
new \GtkCellRendererText(), new \GtkCellRendererText(),
'text', 'text',
2 3
) )
); );
// Init list storage // Init list storage
$this->list = new \GtkListStore( $this->list = new \GtkListStore(
\GObject::TYPE_INT,
\GObject::TYPE_STRING, \GObject::TYPE_STRING,
\GObject::TYPE_STRING, \GObject::TYPE_STRING,
\GObject::TYPE_STRING \GObject::TYPE_STRING
@ -249,25 +210,98 @@ class History
'row-activated', 'row-activated',
function ($tree) function ($tree)
{ {
list($list, $row) = $tree->get_selection() if ($url = $this->getSelectedColumn(3, $tree))
->get_selected(); {
$page = $this->app->blankPage();
$page->open(
$url
);
}
}
);
$url = $list->get_value( $this->treeview->connect(
$row, 2 'cursor-changed',
function ($tree)
{
$url = $this->getSelectedColumn(
3, $tree
); );
$page = $this->app->blankPage(); $this->open->set_sensitive(
(bool) $url
);
$page->open( $this->delete->set_sensitive(
$url (bool) $url
); );
} }
); );
$this->filter->connect(
'activate',
function ($entry)
{
$this->refresh(
$entry->get_text()
);
}
);
if ($this->config->header->button->open->visible)
{
$this->open->connect(
'clicked',
function ()
{
if ($url = $this->getSelectedColumn(3))
{
$page = $this->app->blankPage();
$page->open(
$url
);
$this->refresh();
}
}
);
}
if ($this->config->header->button->delete->visible)
{
$this->delete->connect(
'clicked',
function ()
{
if ($id = $this->getSelectedColumn(0))
{
$this->app->database->deleteHistory(
$id
);
$this->refresh();
}
}
);
}
if ($this->config->header->button->search->visible)
{
$this->search->connect(
'clicked',
function ()
{
$this->refresh(
$this->filter->get_text()
);
}
);
}
} }
public function refresh( public function refresh(): void
string $filter = ''
): void
{ {
// Reset previous state // Reset previous state
$this->list->clear(); $this->list->clear();
@ -277,15 +311,16 @@ class History
false false
); );
$this->clear->set_sensitive( $this->delete->set_sensitive(
false false
); );
// Build history list from database records // Build history list from database records
foreach ($this->app->database->getHistory($filter) as $record) foreach ($this->app->database->getHistory($this->filter->get_text()) as $record)
{ {
$this->list->append( $this->list->append(
[ [
$record->id,
date( date(
$this->config->time->format, $this->config->time->format,
$record->time $record->time
@ -295,5 +330,34 @@ class History
] ]
); );
} }
// Update tree
$this->treeview->show_all();
}
public function getSelectedColumn(
int $column,
\GtkTreeView $treeview = null
): null|int|string
{
if (is_null($treeview))
{
$treeview = $this->treeview;
}
list(
$list,
$row
) = $treeview->get_selection()->get_selected();
if ($list && $row)
{
if ($value = $list->get_value($row, $column))
{
return $value;
}
}
return null;
} }
} }
Loading…
Cancel
Save