Browse Source

implement history actions tray, add history search feature

main
yggverse 3 months ago
parent
commit
970f8f6497
  1. 30
      config.json
  2. 194
      src/Entity/Tab/History.php
  3. 13
      src/Model/Database.php

30
config.json

@ -142,6 +142,36 @@
"time": "time":
{ {
"format":"c" "format":"c"
},
"header":
{
"margin":8,
"button":
{
"open":
{
"visible":true,
"label":"Open"
},
"clear":
{
"visible":true,
"label":"Clear"
},
"go":
{
"visible":true,
"label":"Go"
}
},
"search":
{
"placeholder":"Search in history..."
}
},
"body":
{
"margin":8
} }
} }
} }

194
src/Entity/Tab/History.php

@ -8,7 +8,16 @@ class History
{ {
public \Yggverse\Yoda\Entity\App $app; public \Yggverse\Yoda\Entity\App $app;
public \GtkBox $box; public \GtkBox $box,
$header,
$body;
public \GtkButton $open,
$clear,
$go;
public \GtkEntry $search;
public \GtkListStore $list; public \GtkListStore $list;
public \GtkTreeView $treeview; public \GtkTreeView $treeview;
public \GtkScrolledWindow $container; public \GtkScrolledWindow $container;
@ -24,6 +33,129 @@ class History
// Init config // Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->history; $this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->history;
// Compose header
$this->header = new \GtkBox(
\GtkOrientation::HORIZONTAL
);
$this->header->set_margin_top(
$this->config->header->margin
);
$this->header->set_margin_bottom(
$this->config->header->margin
);
$this->header->set_margin_start(
$this->config->header->margin
);
$this->header->set_margin_end(
$this->config->header->margin
);
$this->header->set_spacing(
$this->config->header->margin
);
// Open button
$this->open = \GtkButton::new_with_label(
$this->config->header->button->open->label
);
$this->open->set_sensitive(
false
);
$this->open->connect(
'clicked',
function ()
{
// @TODO
$this->refresh();
}
);
if ($this->config->header->button->open->visible)
{
$this->header->add(
$this->open
);
}
// Clear button
$this->clear = \GtkButton::new_with_label(
$this->config->header->button->clear->label
);
$this->clear->set_sensitive(
false
);
$this->clear->connect(
'clicked',
function ()
{
// @TODO
$this->refresh();
}
);
if ($this->config->header->button->clear->visible)
{
$this->header->add(
$this->clear
);
}
// Search field
$this->search = new \GtkEntry;
$this->search->set_placeholder_text(
$this->config->header->search->placeholder
);
$this->search->connect(
'activate',
function ($entry)
{
$this->refresh(
$entry->get_text()
);
}
);
$this->header->pack_start(
$this->search,
true,
true,
0
);
// Go button
$this->go = \GtkButton::new_with_label(
$this->config->header->button->go->label
);
$this->go->connect(
'clicked',
function ()
{
$this->refresh(
$this->search->get_text()
);
}
);
if ($this->config->header->button->go->visible)
{
$this->header->add(
$this->go
);
}
// Build history list // Build history list
$this->treeview = new \GtkTreeView(); $this->treeview = new \GtkTreeView();
@ -45,7 +177,7 @@ class History
) )
); );
// Create list storage // Init list storage
$this->list = new \GtkListStore( $this->list = new \GtkListStore(
\GObject::TYPE_STRING, \GObject::TYPE_STRING,
\GObject::TYPE_STRING \GObject::TYPE_STRING
@ -55,11 +187,8 @@ class History
$this->list $this->list
); );
// Build history list from database records // Compose body
$this->refresh(); $this->body = new \GtkBox(
// Compose page
$this->box = new \GtkBox(
\GtkOrientation::VERTICAL \GtkOrientation::VERTICAL
); );
@ -69,19 +198,64 @@ class History
$this->treeview $this->treeview
); );
$this->box->pack_start( $this->body->set_margin_start(
$this->config->body->margin
);
$this->body->pack_start(
$this->container, $this->container,
true, true,
true, true,
0 0
); );
// Compose page
$this->box = new \GtkBox(
\GtkOrientation::VERTICAL
);
$this->box->add(
$this->header
);
$this->box->pack_start(
$this->body,
true,
true,
0
);
// Refresh history
$this->refresh();
// Activate events
$this->treeview->connect(
'row-activated',
function ()
{
// @TODO
}
);
} }
public function refresh(): void public function refresh(
string $search = ''
): void
{ {
// Reset previous state
$this->list->clear(); $this->list->clear();
foreach ($this->app->database->getHistory() as $record) // Update buttons sensibility
$this->open->set_sensitive(
false
);
$this->clear->set_sensitive(
false
);
// Build history list from database records
foreach ($this->app->database->getHistory($search) as $record)
{ {
$this->list->append( $this->list->append(
[ [

13
src/Model/Database.php

@ -74,17 +74,26 @@ class Database
} }
public function getHistory( public function getHistory(
string $search = '',
int $start = 0, int $start = 0,
int $limit = 1000 int $limit = 1000
): array ): array
{ {
$query = $this->_database->query( $query = $this->_database->prepare(
sprintf( sprintf(
'SELECT * FROM `history` ORDER BY `id` DESC LIMIT %d,%d', 'SELECT * FROM `history` WHERE `url` LIKE :search ORDER BY `id` DESC LIMIT %d,%d',
$start, $start,
$limit $limit
) )
);
$query->execute(
[
':search' => sprintf(
'%%%s%%',
$search
)
]
); );
return $query->fetchAll(); return $query->fetchAll();

Loading…
Cancel
Save