Browse Source

move statusbar feature to gtk header subtitle

PHP-GTK3
yggverse 2 months ago
parent
commit
cf3fde37fa
  1. 12
      src/Entity/Browser/Container/Tab.php
  2. 17
      src/Entity/Browser/Container/Tab/Page.php
  3. 71
      src/Entity/Browser/Container/Tab/Page/Content.php
  4. 83
      src/Entity/Browser/Container/Tab/Page/Statusbar.php
  5. 35
      src/Entity/Browser/Container/Tab/Page/Title.php
  6. 7
      src/Entity/Browser/Header.php
  7. 22
      src/Gtk/Browser/Container/Tab/Page/Title/Label.php

12
src/Entity/Browser/Container/Tab.php

@ -41,10 +41,13 @@ class Tab @@ -41,10 +41,13 @@ class Tab
\GtkWidget $child,
int $position
) {
$label = $entity->get_tab_label(
$child
);
$this->container->browser->header->setTitle(
$entity->get_tab_label(
$child
)->get_text()
$label->get_text(),
$label->get_subtitle() // @TODO extension not supported by GTK-PHP
);
// Keep current selection
@ -92,7 +95,8 @@ class Tab @@ -92,7 +95,8 @@ class Tab
// Update application title
$this->container->browser->header->setTitle(
$page->title->gtk->get_text()
$page->title->getValue(),
$page->title->getSubtitle()
);
}

17
src/Entity/Browser/Container/Tab/Page.php

@ -7,7 +7,6 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab; @@ -7,7 +7,6 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar;
class Page
{
@ -20,7 +19,6 @@ class Page @@ -20,7 +19,6 @@ class Page
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar $statusbar;
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab $tab
@ -52,20 +50,8 @@ class Page @@ -52,20 +50,8 @@ class Page
$this
);
$this->gtk->pack_start(
$this->content->gtk,
true,
true,
0
);
// Init statusbar
$this->statusbar = new Statusbar(
$this
);
$this->gtk->add(
$this->statusbar->gtk
$this->content->gtk
);
// Render
@ -76,7 +62,6 @@ class Page @@ -76,7 +62,6 @@ class Page
{
$this->navbar->refresh();
$this->content->refresh();
$this->statusbar->refresh();
}
public function update(

71
src/Entity/Browser/Container/Tab/Page/Content.php

@ -37,6 +37,18 @@ class Content @@ -37,6 +37,18 @@ class Content
$this->_margin
);
$this->gtk->set_margin_bottom(
$this->_margin
);
$this->gtk->set_propagate_natural_height( // instead of pack to parent
true
);
$this->gtk->set_propagate_natural_width(
true
);
// Init viewport
// to integrate scrolled window features for data label
$this->viewport = new Viewport(
@ -73,7 +85,8 @@ class Content @@ -73,7 +85,8 @@ class Content
// Init new title
$this->page->title->setValue(
$address->getHost()
$address->getHost(),
'loading...'
);
if ($history)
@ -90,11 +103,6 @@ class Content @@ -90,11 +103,6 @@ class Content
);
}
// Update statusbar indicator
$this->page->statusbar->setValue(
'Loading...'
);
// Detect protocol
switch ($address->getScheme())
{
@ -124,45 +132,36 @@ class Content @@ -124,45 +132,36 @@ class Content
if ($title) // detect title by document h1
{
$this->page->title->setValue(
$title
$title,
$this->page->title->subtitle
);
}
$this->page->statusbar->setValue(
null
);
break;
default:
$this->page->title->setValue(
'Oops!'
'Oops!',
'file extension not supported'
);
$this->data->setPlain(
'File extension not supported'
);
$this->page->statusbar->setValue(
null
);
}
}
else
{
$this->page->title->setValue(
'Failure'
'Failure',
'resource not found or not readable'
);
$this->data->setPlain(
'Could not open file'
);
$this->page->statusbar->setValue(
'Resource not found or not readable'
);
}
break;
@ -212,7 +211,7 @@ class Content @@ -212,7 +211,7 @@ class Content
);
}
$this->page->statusbar->setValue(
$this->page->title->setSubtitle(
$response->getMeta()
);
}
@ -220,21 +219,18 @@ class Content @@ -220,21 +219,18 @@ class Content
else
{
$this->page->title->setValue(
'Failure'
);
$this->data->setPlain(
'Resource not available!'
);
$this->page->statusbar->setValue(
'Failure',
sprintf(
'code %d',
'could not open resource (code %d)',
intval(
$response->getCode()
)
)
);
$this->data->setPlain(
'Requested resource not available!'
);
}
break;
@ -283,16 +279,13 @@ class Content @@ -283,16 +279,13 @@ class Content
default:
$this->page->title->setValue(
'Oops!'
'Oops!',
'protocol not supported!'
);
$this->data->setPlain(
'Protocol not supported!'
);
$this->page->statusbar->setValue(
null
);
}
// Render content
@ -300,5 +293,11 @@ class Content @@ -300,5 +293,11 @@ class Content
// Refresh page components
$this->page->refresh();
// Update window header
$this->page->tab->container->browser->header->setTitle(
$this->page->title->getValue(),
$this->page->title->getSubtitle(),
);
}
}

83
src/Entity/Browser/Container/Tab/Page/Statusbar.php

@ -1,83 +0,0 @@ @@ -1,83 +0,0 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
class Statusbar
{
public \GtkLabel $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
// Defaults
private int $_margin = 8;
private string $_value = '';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page
) {
// Init dependency
$this->page = $page;
// Init container
$this->gtk = new \GtkLabel;
$this->gtk->set_use_markup(
true
);
$this->gtk->set_selectable(
true
);
$this->gtk->set_line_wrap(
true
);
$this->gtk->set_xalign(
0
);
$this->gtk->set_yalign(
0
);
$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_markup(
$this->_value
);
}
public function setValue(
?string $value = null
): void
{
$this->gtk->set_markup(
is_null($value) ? $this->_value : trim(
$value
)
);
}
public function refresh()
{
// @TODO
}
}

35
src/Entity/Browser/Container/Tab/Page/Title.php

@ -4,9 +4,11 @@ declare(strict_types=1); @@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
use \Yggverse\Yoda\Gtk\Browser\Container\Tab\Page\Title\Label;
class Title
{
public \GtkLabel $gtk;
public Label $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
@ -15,6 +17,7 @@ class Title @@ -15,6 +17,7 @@ class Title
private int $_ellipsize = 3;
private int $_length = 12;
private string $_value = 'New page';
private string $_subtitle = '';
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page,
@ -23,7 +26,7 @@ class Title @@ -23,7 +26,7 @@ class Title
$this->page = $page;
// Init container
$this->gtk = new \GtkLabel(
$this->gtk = new Label(
$this->_value
);
@ -37,7 +40,8 @@ class Title @@ -37,7 +40,8 @@ class Title
}
public function setValue(
?string $value = null
?string $value = null,
?string $subtitle = null
): void
{
$this->gtk->set_text(
@ -45,5 +49,30 @@ class Title @@ -45,5 +49,30 @@ class Title
$value
)
);
$this->setSubtitle(
$subtitle
);
}
public function setSubtitle(
?string $subtitle = null
): void
{
$this->gtk->set_subtitle(
is_null($subtitle) ? $this->_subtitle : trim(
$subtitle
)
);
}
public function getValue(): string
{
return $this->gtk->get_text();
}
public function getSubtitle(): string
{
return $this->gtk->get_subtitle();
}
}

7
src/Entity/Browser/Header.php

@ -53,7 +53,8 @@ class Header @@ -53,7 +53,8 @@ class Header
}
public function setTitle(
?string $value = null
?string $value = null,
?string $subtitle = null
): void
{
$this->gtk->set_title(
@ -65,6 +66,10 @@ class Header @@ -65,6 +66,10 @@ class Header
$this->_title
)
);
$this->setSubtitle(
$subtitle
);
}
public function setSubtitle(

22
src/Gtk/Browser/Container/Tab/Page/Title/Label.php

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Gtk\Browser\Container\Tab\Page\Title;
class Label extends \GtkLabel
{
private string $_subtitle;
public function set_subtitle(
string $value
): void
{
$this->_subtitle = $value;
}
public function get_subtitle(): string
{
return $this->_subtitle;
}
}
Loading…
Cancel
Save