mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
move Page entity out of Tab namespace
This commit is contained in:
parent
46adc640e9
commit
63bc991bda
21 changed files with 111 additions and 111 deletions
152
src/Entity/Browser/Container/Page/Response.php
Normal file
152
src/Entity/Browser/Container/Page/Response.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Container\Page;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Query;
|
||||
use \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Send;
|
||||
|
||||
use \Yggverse\Net\Address;
|
||||
|
||||
class Response
|
||||
{
|
||||
public \GtkBox $gtk;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\Container\Page $page;
|
||||
|
||||
// Requirements
|
||||
public \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Query $query;
|
||||
public \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Send $send;
|
||||
|
||||
// Defaults
|
||||
private int $_margin = 8;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\Container\Page $page
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->page = $page;
|
||||
|
||||
// Init container
|
||||
$this->gtk = new \GtkBox(
|
||||
\GtkOrientation::HORIZONTAL
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_top(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_bottom(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_start(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_margin_end(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
$this->gtk->set_spacing(
|
||||
$this->_margin
|
||||
);
|
||||
|
||||
// Init query field
|
||||
$this->query = new Query(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->pack_start(
|
||||
$this->query->gtk,
|
||||
true,
|
||||
true,
|
||||
0
|
||||
);
|
||||
|
||||
// Init send button
|
||||
$this->send = new Send(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->gtk->add(
|
||||
$this->send->gtk
|
||||
);
|
||||
|
||||
// Hide widget by default
|
||||
$this->hide();
|
||||
}
|
||||
|
||||
public function show(
|
||||
?string $placeholder = null,
|
||||
?bool $visible = null,
|
||||
bool $focus = true
|
||||
): void
|
||||
{
|
||||
if ($focus)
|
||||
{
|
||||
$this->query->focus();
|
||||
}
|
||||
|
||||
if (!is_null($placeholder))
|
||||
{
|
||||
$this->query->setPlaceholder(
|
||||
$placeholder
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_null($visible))
|
||||
{
|
||||
$this->query->setVisible(
|
||||
$visible
|
||||
);
|
||||
}
|
||||
|
||||
$this->gtk->show();
|
||||
}
|
||||
|
||||
public function hide(): void
|
||||
{
|
||||
$this->query->setPlaceholder(
|
||||
null
|
||||
);
|
||||
|
||||
$this->query->setVisible(
|
||||
null
|
||||
);
|
||||
|
||||
$this->gtk->hide();
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
$this->query->refresh();
|
||||
$this->send->refresh();
|
||||
}
|
||||
|
||||
public function send(): void
|
||||
{
|
||||
$address = new Address(
|
||||
$this->page->navbar->request->getValue()
|
||||
);
|
||||
|
||||
$address->setQuery(
|
||||
urlencode(
|
||||
trim(
|
||||
strval(
|
||||
$this->query->getValue()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->page->open(
|
||||
$address->get(),
|
||||
false // disable history recording
|
||||
);
|
||||
|
||||
$this->hide();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue