Browse Source

draft request autocomplete suggestions

PHP-GTK3
yggverse 5 months ago
parent
commit
75ab8eb069
  1. 25
      config.json
  2. 68
      src/Entity/Tab/Page.php

25
config.json

@ -129,6 +129,31 @@ @@ -129,6 +129,31 @@
"length":
{
"max":1024
},
"autocomplete":
{
"enabled":true,
"inline":
{
"completion":true,
"selection":true
},
"key":
{
"length":1
},
"ignore":
{
"keycode":
[
111,
116
]
},
"result":
{
"limit":15
}
}
}
}

68
src/Entity/Tab/Page.php

@ -30,6 +30,10 @@ class Page @@ -30,6 +30,10 @@ class Page
public \GtkProgressBar $progressbar;
public \GtkEntryCompletion $completion;
public \GtkListStore $suggestion;
public object $config;
public function __construct(
@ -202,6 +206,70 @@ class Page @@ -202,6 +206,70 @@ class Page
0
);
// Init autocomplete
if ($this->config->header->entry->request->autocomplete->enabled)
{
$this->completion = new \GtkEntryCompletion();
$this->completion->set_inline_completion(
$this->config->header->entry->request->autocomplete->inline->completion
);
$this->completion->set_inline_selection(
$this->config->header->entry->request->autocomplete->inline->selection
);
$this->completion->set_minimum_key_length(
$this->config->header->entry->request->autocomplete->key->length
);
$this->completion->set_text_column(
0
);
$this->suggestion = new \GtkListStore(
\GObject::TYPE_STRING
);
$this->completion->set_model(
$this->suggestion
);
$this->request->connect(
'key-release-event',
function ($entry, $event)
{
if (
mb_strlen($entry->get_text()) >= $this->config->header->entry->request->autocomplete->key->length
&&
isset($event->key->keycode)
&&
!in_array(
$event->key->keycode,
$this->config->header->entry->request->autocomplete->ignore->keycode
)
) {
$this->suggestion->clear();
foreach ($this->app->database->getHistory(
$entry->get_text(), 0, $this->config->header->entry->request->autocomplete->result->limit
) as $suggestion)
{
$this->suggestion->append(
[
$suggestion->url
]
);
}
$this->request->set_completion(
$this->completion
);
}
}
);
}
// Go button
$this->go = \GtkButton::new_with_label(
$this->config->header->button->go->label

Loading…
Cancel
Save