mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement history navigation
This commit is contained in:
parent
4fb0cb884c
commit
7b38e00089
2 changed files with 130 additions and 6 deletions
71
src/Model/History.php
Normal file
71
src/Model/History.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Model;
|
||||
|
||||
class History
|
||||
{
|
||||
private int $_position = -1;
|
||||
|
||||
private array $_record = [];
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->_position = -1;
|
||||
|
||||
$this->_record = [];
|
||||
}
|
||||
|
||||
public function add(
|
||||
string $record
|
||||
): int
|
||||
{
|
||||
$this->_record[] = $record;
|
||||
|
||||
$this->_position = array_key_last(
|
||||
$this->_record
|
||||
);
|
||||
|
||||
return $this->_position;
|
||||
}
|
||||
|
||||
public function get(
|
||||
int $position
|
||||
): ?string
|
||||
{
|
||||
return isset($this->_record[$position]) ? $this->_record[$position] : null;
|
||||
}
|
||||
|
||||
public function getBack(): ?string
|
||||
{
|
||||
return $this->get(
|
||||
$this->_position - 1
|
||||
);
|
||||
}
|
||||
|
||||
public function getForward(): ?string
|
||||
{
|
||||
return $this->get(
|
||||
$this->_position + 1
|
||||
);
|
||||
}
|
||||
|
||||
public function goBack(): ?string
|
||||
{
|
||||
$this->_position--;
|
||||
|
||||
return $this->get(
|
||||
$this->_position
|
||||
);
|
||||
}
|
||||
|
||||
public function goForward(): ?string
|
||||
{
|
||||
$this->_position++;
|
||||
|
||||
return $this->get(
|
||||
$this->_position
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,8 @@ namespace Yggverse\Yoda\Tab;
|
|||
|
||||
class Page
|
||||
{
|
||||
public \Yggverse\Yoda\Model\Memory $dns;
|
||||
public \Yggverse\Yoda\Model\Memory $history;
|
||||
public \Yggverse\Yoda\Model\Memory $dns;
|
||||
public \Yggverse\Yoda\Model\History $history;
|
||||
|
||||
public \GtkBox $box,
|
||||
$header,
|
||||
|
|
@ -34,9 +34,11 @@ class Page
|
|||
// Init config
|
||||
$this->config = \Yggverse\Yoda\Model\File::getConfig()->window->tab->page;
|
||||
|
||||
// Init memory
|
||||
// Init DNS memory
|
||||
$this->dns = new \Yggverse\Yoda\Model\Memory();
|
||||
$this->history = new \Yggverse\Yoda\Model\Memory();
|
||||
|
||||
// Init history
|
||||
$this->history = new \Yggverse\Yoda\Model\History();
|
||||
|
||||
// Compose header
|
||||
$this->header = new \GtkBox(
|
||||
|
|
@ -76,6 +78,8 @@ class Page
|
|||
'released',
|
||||
function ($entry)
|
||||
{
|
||||
$this->history->reset();
|
||||
|
||||
$this->open(
|
||||
$this->config->header->button->home->url
|
||||
);
|
||||
|
|
@ -94,11 +98,41 @@ class Page
|
|||
$this->config->header->button->back->label
|
||||
);
|
||||
|
||||
$this->back->set_sensitive(
|
||||
false
|
||||
);
|
||||
|
||||
$this->back->connect(
|
||||
'released',
|
||||
function ($entry)
|
||||
{
|
||||
$this->open(
|
||||
$this->history->goBack(),
|
||||
false
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Forward button
|
||||
$this->forward = \GtkButton::new_with_label(
|
||||
$this->config->header->button->forward->label
|
||||
);
|
||||
|
||||
$this->forward->set_sensitive(
|
||||
false
|
||||
);
|
||||
|
||||
$this->forward->connect(
|
||||
'released',
|
||||
function ($entry)
|
||||
{
|
||||
$this->open(
|
||||
$this->history->goForward(),
|
||||
false
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
/// Group buttons
|
||||
if ($this->config->header->button->back->visible || $this->config->header->button->forward->visible)
|
||||
{
|
||||
|
|
@ -284,7 +318,8 @@ class Page
|
|||
}
|
||||
|
||||
public function open(
|
||||
string $url
|
||||
string $url,
|
||||
bool $history = true
|
||||
): void
|
||||
{
|
||||
// Update address field by requested
|
||||
|
|
@ -292,11 +327,29 @@ class Page
|
|||
$url
|
||||
);
|
||||
|
||||
// Update home button sensitivity on match requested
|
||||
// Update history pool
|
||||
if ($history)
|
||||
{
|
||||
$this->history->add(
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
// Update home button sensibility on match requested
|
||||
$this->home->set_sensitive(
|
||||
!($url == $this->config->header->button->home->url)
|
||||
);
|
||||
|
||||
// Update back button sensibility
|
||||
$this->back->set_sensitive(
|
||||
(bool) $this->history->getBack()
|
||||
);
|
||||
|
||||
// Update forward button sensibility
|
||||
$this->forward->set_sensitive(
|
||||
(bool) $this->history->getForward()
|
||||
);
|
||||
|
||||
// Open current address
|
||||
switch (true)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue