Browse Source

move statusbar feature to gtk header subtitle

PHP-GTK3
yggverse 4 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
\GtkWidget $child, \GtkWidget $child,
int $position int $position
) { ) {
$label = $entity->get_tab_label(
$child
);
$this->container->browser->header->setTitle( $this->container->browser->header->setTitle(
$entity->get_tab_label( $label->get_text(),
$child $label->get_subtitle() // @TODO extension not supported by GTK-PHP
)->get_text()
); );
// Keep current selection // Keep current selection
@ -92,7 +95,8 @@ class Tab
// Update application title // Update application title
$this->container->browser->header->setTitle( $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;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title; 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\Navbar;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content;
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar;
class Page 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\Title $title;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar; 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\Content $content;
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar $statusbar;
public function __construct( public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab $tab \Yggverse\Yoda\Entity\Browser\Container\Tab $tab
@ -52,20 +50,8 @@ class Page
$this $this
); );
$this->gtk->pack_start(
$this->content->gtk,
true,
true,
0
);
// Init statusbar
$this->statusbar = new Statusbar(
$this
);
$this->gtk->add( $this->gtk->add(
$this->statusbar->gtk $this->content->gtk
); );
// Render // Render
@ -76,7 +62,6 @@ class Page
{ {
$this->navbar->refresh(); $this->navbar->refresh();
$this->content->refresh(); $this->content->refresh();
$this->statusbar->refresh();
} }
public function update( public function update(

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

@ -37,6 +37,18 @@ class Content
$this->_margin $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 // Init viewport
// to integrate scrolled window features for data label // to integrate scrolled window features for data label
$this->viewport = new Viewport( $this->viewport = new Viewport(
@ -73,7 +85,8 @@ class Content
// Init new title // Init new title
$this->page->title->setValue( $this->page->title->setValue(
$address->getHost() $address->getHost(),
'loading...'
); );
if ($history) if ($history)
@ -90,11 +103,6 @@ class Content
); );
} }
// Update statusbar indicator
$this->page->statusbar->setValue(
'Loading...'
);
// Detect protocol // Detect protocol
switch ($address->getScheme()) switch ($address->getScheme())
{ {
@ -124,45 +132,36 @@ class Content
if ($title) // detect title by document h1 if ($title) // detect title by document h1
{ {
$this->page->title->setValue( $this->page->title->setValue(
$title $title,
$this->page->title->subtitle
); );
} }
$this->page->statusbar->setValue(
null
);
break; break;
default: default:
$this->page->title->setValue( $this->page->title->setValue(
'Oops!' 'Oops!',
'file extension not supported'
); );
$this->data->setPlain( $this->data->setPlain(
'File extension not supported' 'File extension not supported'
); );
$this->page->statusbar->setValue(
null
);
} }
} }
else else
{ {
$this->page->title->setValue( $this->page->title->setValue(
'Failure' 'Failure',
'resource not found or not readable'
); );
$this->data->setPlain( $this->data->setPlain(
'Could not open file' 'Could not open file'
); );
$this->page->statusbar->setValue(
'Resource not found or not readable'
);
} }
break; break;
@ -212,7 +211,7 @@ class Content
); );
} }
$this->page->statusbar->setValue( $this->page->title->setSubtitle(
$response->getMeta() $response->getMeta()
); );
} }
@ -220,21 +219,18 @@ class Content
else else
{ {
$this->page->title->setValue( $this->page->title->setValue(
'Failure' 'Failure',
);
$this->data->setPlain(
'Resource not available!'
);
$this->page->statusbar->setValue(
sprintf( sprintf(
'code %d', 'could not open resource (code %d)',
intval( intval(
$response->getCode() $response->getCode()
) )
) )
); );
$this->data->setPlain(
'Requested resource not available!'
);
} }
break; break;
@ -283,16 +279,13 @@ class Content
default: default:
$this->page->title->setValue( $this->page->title->setValue(
'Oops!' 'Oops!',
'protocol not supported!'
); );
$this->data->setPlain( $this->data->setPlain(
'Protocol not supported!' 'Protocol not supported!'
); );
$this->page->statusbar->setValue(
null
);
} }
// Render content // Render content
@ -300,5 +293,11 @@ class Content
// Refresh page components // Refresh page components
$this->page->refresh(); $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 @@
<?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);
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
use \Yggverse\Yoda\Gtk\Browser\Container\Tab\Page\Title\Label;
class Title class Title
{ {
public \GtkLabel $gtk; public Label $gtk;
// Dependencies // Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
@ -15,6 +17,7 @@ class Title
private int $_ellipsize = 3; private int $_ellipsize = 3;
private int $_length = 12; private int $_length = 12;
private string $_value = 'New page'; private string $_value = 'New page';
private string $_subtitle = '';
public function __construct( public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page, \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page,
@ -23,7 +26,7 @@ class Title
$this->page = $page; $this->page = $page;
// Init container // Init container
$this->gtk = new \GtkLabel( $this->gtk = new Label(
$this->_value $this->_value
); );
@ -37,7 +40,8 @@ class Title
} }
public function setValue( public function setValue(
?string $value = null ?string $value = null,
?string $subtitle = null
): void ): void
{ {
$this->gtk->set_text( $this->gtk->set_text(
@ -45,5 +49,30 @@ class Title
$value $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
} }
public function setTitle( public function setTitle(
?string $value = null ?string $value = null,
?string $subtitle = null
): void ): void
{ {
$this->gtk->set_title( $this->gtk->set_title(
@ -65,6 +66,10 @@ class Header
$this->_title $this->_title
) )
); );
$this->setSubtitle(
$subtitle
);
} }
public function setSubtitle( public function setSubtitle(

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

@ -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