mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement history actions tray, add history search feature
This commit is contained in:
parent
5927f00437
commit
970f8f6497
3 changed files with 225 additions and 12 deletions
30
config.json
30
config.json
|
|
@ -142,6 +142,36 @@
|
|||
"time":
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,16 @@ class History
|
|||
{
|
||||
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 \GtkTreeView $treeview;
|
||||
public \GtkScrolledWindow $container;
|
||||
|
|
@ -24,6 +33,129 @@ class History
|
|||
// Init config
|
||||
$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
|
||||
$this->treeview = new \GtkTreeView();
|
||||
|
||||
|
|
@ -45,7 +177,7 @@ class History
|
|||
)
|
||||
);
|
||||
|
||||
// Create list storage
|
||||
// Init list storage
|
||||
$this->list = new \GtkListStore(
|
||||
\GObject::TYPE_STRING,
|
||||
\GObject::TYPE_STRING
|
||||
|
|
@ -55,11 +187,8 @@ class History
|
|||
$this->list
|
||||
);
|
||||
|
||||
// Build history list from database records
|
||||
$this->refresh();
|
||||
|
||||
// Compose page
|
||||
$this->box = new \GtkBox(
|
||||
// Compose body
|
||||
$this->body = new \GtkBox(
|
||||
\GtkOrientation::VERTICAL
|
||||
);
|
||||
|
||||
|
|
@ -69,19 +198,64 @@ class History
|
|||
$this->treeview
|
||||
);
|
||||
|
||||
$this->box->pack_start(
|
||||
$this->body->set_margin_start(
|
||||
$this->config->body->margin
|
||||
);
|
||||
|
||||
$this->body->pack_start(
|
||||
$this->container,
|
||||
true,
|
||||
true,
|
||||
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();
|
||||
|
||||
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(
|
||||
[
|
||||
|
|
|
|||
|
|
@ -74,17 +74,26 @@ class Database
|
|||
}
|
||||
|
||||
public function getHistory(
|
||||
string $search = '',
|
||||
int $start = 0,
|
||||
int $limit = 1000
|
||||
): array
|
||||
{
|
||||
$query = $this->_database->query(
|
||||
$query = $this->_database->prepare(
|
||||
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,
|
||||
$limit
|
||||
)
|
||||
);
|
||||
|
||||
$query->execute(
|
||||
[
|
||||
':search' => sprintf(
|
||||
'%%%s%%',
|
||||
$search
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
return $query->fetchAll();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue