diff --git a/src/Abstract/Entity/Browser/Container/Page/Navbar/Entry.php b/src/Abstract/Entity/Browser/Container/Page/Navbar/Entry.php deleted file mode 100644 index ec2241a0..00000000 --- a/src/Abstract/Entity/Browser/Container/Page/Navbar/Entry.php +++ /dev/null @@ -1,20 +0,0 @@ -navbar = $navbar; - } -} diff --git a/src/Entity/Browser/Container/Page/Navbar/Request.php b/src/Entity/Browser/Container/Page/Navbar/Request.php index 1b90b628..ddc5aae8 100644 --- a/src/Entity/Browser/Container/Page/Navbar/Request.php +++ b/src/Entity/Browser/Container/Page/Navbar/Request.php @@ -8,14 +8,43 @@ use \GdkEvent; use \Gtk; 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 { + // Defaults public const PLACEHOLDER = 'URL or search term...'; + // Extras 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( GtkEntry $entry ): void @@ -50,10 +79,13 @@ class Request extends Entry // Refresh navigation elements $this->navbar->refresh(); - // Update session on tab initiated only + // Show suggestions autocomplete + $this->completion->refresh(); + + // Update session if (isset($this->navbar->page->container->tab)) { - // Reset previous event + // Reset keyup time if ($this->_changed) { Gtk::source_remove( diff --git a/src/Entity/Browser/Container/Page/Navbar/Request/Completion.php b/src/Entity/Browser/Container/Page/Navbar/Request/Completion.php new file mode 100644 index 00000000..7fbd8a9f --- /dev/null +++ b/src/Entity/Browser/Container/Page/Navbar/Request/Completion.php @@ -0,0 +1,81 @@ +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 + ); + } + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Page/Navbar/Request/Completion/Suggestion.php b/src/Entity/Browser/Container/Page/Navbar/Request/Completion/Suggestion.php new file mode 100644 index 00000000..954103fd --- /dev/null +++ b/src/Entity/Browser/Container/Page/Navbar/Request/Completion/Suggestion.php @@ -0,0 +1,47 @@ +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(); + } +} \ No newline at end of file