mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
init request completion feature
This commit is contained in:
parent
f6c2ca475d
commit
dab0d33789
4 changed files with 163 additions and 23 deletions
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Navbar;
|
|
||||||
|
|
||||||
use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar;
|
|
||||||
|
|
||||||
abstract class Entry extends \Yggverse\Yoda\Abstract\Entity\Entry
|
|
||||||
{
|
|
||||||
public Navbar $navbar;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
Navbar $navbar
|
|
||||||
) {
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->navbar = $navbar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -8,14 +8,43 @@ use \GdkEvent;
|
||||||
use \Gtk;
|
use \Gtk;
|
||||||
use \GtkEntry;
|
use \GtkEntry;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Navbar\Entry;
|
use \Yggverse\Yoda\Abstract\Entity\Entry;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar;
|
||||||
|
|
||||||
class Request extends Entry
|
class Request extends Entry
|
||||||
{
|
{
|
||||||
|
// Defaults
|
||||||
public const PLACEHOLDER = 'URL or search term...';
|
public const PLACEHOLDER = 'URL or search term...';
|
||||||
|
|
||||||
|
// Extras
|
||||||
private ?int $_changed = null;
|
private ?int $_changed = null;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public Navbar $navbar;
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
public Request\Completion $completion;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Navbar $navbar
|
||||||
|
) {
|
||||||
|
// Build entry
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
$this->navbar = $navbar;
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
$this->completion = new Request\Completion(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_completion(
|
||||||
|
$this->completion->gtk
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function _onActivate(
|
protected function _onActivate(
|
||||||
GtkEntry $entry
|
GtkEntry $entry
|
||||||
): void
|
): void
|
||||||
|
|
@ -50,10 +79,13 @@ class Request extends Entry
|
||||||
// Refresh navigation elements
|
// Refresh navigation elements
|
||||||
$this->navbar->refresh();
|
$this->navbar->refresh();
|
||||||
|
|
||||||
// Update session on tab initiated only
|
// Show suggestions autocomplete
|
||||||
|
$this->completion->refresh();
|
||||||
|
|
||||||
|
// Update session
|
||||||
if (isset($this->navbar->page->container->tab))
|
if (isset($this->navbar->page->container->tab))
|
||||||
{
|
{
|
||||||
// Reset previous event
|
// Reset keyup time
|
||||||
if ($this->_changed)
|
if ($this->_changed)
|
||||||
{
|
{
|
||||||
Gtk::source_remove(
|
Gtk::source_remove(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Navbar\Request;
|
||||||
|
|
||||||
|
use \GtkEntryCompletion;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar\Request;
|
||||||
|
|
||||||
|
class Completion
|
||||||
|
{
|
||||||
|
// GTK
|
||||||
|
public GtkEntryCompletion $gtk;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
public const INLINE_COMPLETION = true;
|
||||||
|
public const INLINE_SELECTION = true;
|
||||||
|
public const MINIMUM_KEY_LENGTH = 1; // @TODO
|
||||||
|
public const TEXT_COLUMN = 0;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public Request $request;
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
public Completion\Suggestion $suggestion;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Request $request
|
||||||
|
) {
|
||||||
|
// Dependencies
|
||||||
|
$this->request = $request;
|
||||||
|
|
||||||
|
// GTK
|
||||||
|
$this->gtk = new GtkEntryCompletion;
|
||||||
|
|
||||||
|
$this->gtk->set_inline_completion(
|
||||||
|
$this::INLINE_COMPLETION
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_inline_selection(
|
||||||
|
$this::INLINE_SELECTION
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_minimum_key_length(
|
||||||
|
$this::MINIMUM_KEY_LENGTH
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_text_column(
|
||||||
|
$this::TEXT_COLUMN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
$this->suggestion = new Completion\Suggestion(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_model(
|
||||||
|
$this->suggestion->gtk
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refresh(
|
||||||
|
int $limit = 5,
|
||||||
|
int $offset = 0
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->suggestion->clear();
|
||||||
|
|
||||||
|
foreach ($this->request->navbar->page->container->browser->database->findHistory(
|
||||||
|
$this->request->getValue(),
|
||||||
|
$offset,
|
||||||
|
$limit
|
||||||
|
) as $history)
|
||||||
|
{
|
||||||
|
$this->suggestion->append(
|
||||||
|
$history->url
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Navbar\Request\Completion;
|
||||||
|
|
||||||
|
use \GObject;
|
||||||
|
use \GtkListStore;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Page\Navbar\Request\Completion;
|
||||||
|
|
||||||
|
class Suggestion
|
||||||
|
{
|
||||||
|
// GTK
|
||||||
|
public GtkListStore $gtk;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public Completion $completion;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Completion $completion
|
||||||
|
) {
|
||||||
|
// GTK
|
||||||
|
$this->gtk = new GtkListStore(
|
||||||
|
GObject::TYPE_STRING
|
||||||
|
);
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
$this->completion = $completion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append(
|
||||||
|
string $request
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->gtk->append(
|
||||||
|
[
|
||||||
|
$request
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear(): void
|
||||||
|
{
|
||||||
|
$this->gtk->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue