mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
draft request autocomplete suggestions
This commit is contained in:
parent
5a4fba93f1
commit
75ab8eb069
2 changed files with 93 additions and 0 deletions
25
config.json
25
config.json
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
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…
Add table
Add a link
Reference in a new issue