mirror of https://github.com/YGGverse/Yoda.git
yggverse
4 months ago
5 changed files with 243 additions and 2 deletions
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; |
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query; |
||||
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send; |
||||
|
||||
use \Yggverse\Net\Address; |
||||
|
||||
class Response |
||||
{ |
||||
public \GtkBox $gtk; |
||||
|
||||
// Dependencies |
||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; |
||||
|
||||
// Requirements |
||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query $query; |
||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send $send; |
||||
|
||||
// Defaults |
||||
private int $_margin = 8; |
||||
|
||||
public function __construct( |
||||
\Yggverse\Yoda\Entity\Browser\Container\Tab\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(): void |
||||
{ |
||||
$this->gtk->show_all(); |
||||
} |
||||
|
||||
public function hide(): void |
||||
{ |
||||
$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(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response; |
||||
|
||||
class Query extends \Yggverse\Yoda\Abstract\Entity\Entry |
||||
{ |
||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response; |
||||
|
||||
// Defaults |
||||
protected string $_placeholder = 'Enter response...'; |
||||
|
||||
public function __construct( |
||||
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response |
||||
) { |
||||
// Use parent features |
||||
parent::__construct(); |
||||
|
||||
// Init dependency |
||||
$this->response = $response; |
||||
} |
||||
|
||||
protected function _onActivate( |
||||
\GtkEntry $entry |
||||
): void |
||||
{ |
||||
$this->response->send(); |
||||
} |
||||
|
||||
protected function _onKeyRelease( |
||||
\GtkEntry $entry, |
||||
\GdkEvent $event |
||||
): void |
||||
{ |
||||
$this->response->refresh(); |
||||
} |
||||
|
||||
public function refresh(): void |
||||
{ |
||||
// @TODO |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response; |
||||
|
||||
class Send extends \Yggverse\Yoda\Abstract\Entity\Button |
||||
{ |
||||
// Dependencies |
||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response; |
||||
|
||||
// Defaults |
||||
protected string $_label = 'Send'; |
||||
|
||||
public function __construct( |
||||
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response |
||||
) { |
||||
// Use parent features |
||||
parent::__construct(); |
||||
|
||||
// Init dependency |
||||
$this->response = $response; |
||||
} |
||||
|
||||
protected function _onCLick( |
||||
\GtkButton $entity |
||||
): void |
||||
{ |
||||
$this->response->send(); |
||||
} |
||||
|
||||
public function refresh(): void |
||||
{ |
||||
$this->gtk->set_sensitive( |
||||
!empty($this->response->query->getValue()) |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue