Browse Source

update page title behaviour

PHP-GTK3
yggverse 7 months ago
parent
commit
a011d5e004
  1. 5
      config.json
  2. 18
      src/Entity/App.php
  3. 24
      src/Entity/Tab/Page.php

5
config.json

@ -1,6 +1,7 @@
{ {
"app": "app":
{ {
"name":"Yoda",
"theme":"Default", "theme":"Default",
"database": "database":
{ {
@ -13,11 +14,9 @@
"enabled":true, "enabled":true,
"title": "title":
{ {
"default":"Yoda",
"postfix":" - Yoda",
"length": "length":
{ {
"max":32 "max":64
} }
}, },
"button": "button":

18
src/Entity/App.php

@ -57,7 +57,7 @@ class App
$this->header = new \GtkHeaderBar; $this->header = new \GtkHeaderBar;
$this->header->set_title( $this->header->set_title(
$this->config->header->title->default $this->config->name
); );
$this->header->set_show_close_button( $this->header->set_show_close_button(
@ -121,15 +121,18 @@ class App
// Init event listener // Init event listener
$this->tabs->connect( $this->tabs->connect(
'switch-page', 'switch-page',
function ($tabs, $child, $position) function (
{ \GtkNotebook $tabs,
\GtkWidget $child,
int $position
) {
// Update window title on tab change // Update window title on tab change
$this->setTitle( $this->setTitle(
$tabs->get_tab_label_text($child) $tabs->get_tab_label($child)->get_text()
); );
// Add new tab event // Add new tab event
if ('+' == $tabs->get_tab_label_text($child)) if ('+' == $tabs->get_tab_label($child)->get_text())
{ {
\Gtk::timeout_add( \Gtk::timeout_add(
0, 0,
@ -188,15 +191,18 @@ class App
{ {
if ($value) if ($value)
{ {
/* @TODO
$title = urldecode( $title = urldecode(
mb_strlen($value) > $this->config->header->title->length->max ? mb_substr($value, 0, $this->config->header->title->length->max) . '...' mb_strlen($value) > $this->config->header->title->length->max ? mb_substr($value, 0, $this->config->header->title->length->max) . '...'
: $value : $value
); );
*/ $title = $value;
} }
else else
{ {
$title = $this->config->header->title->default; $title = $this->config->name;
} }
$this->header->set_title( $this->header->set_title(

24
src/Entity/Tab/Page.php

@ -637,17 +637,31 @@ class Page
$response->getBody() $response->getBody()
); );
// Try to detect document title
if ($h1 = $body->getH1()) if ($h1 = $body->getH1())
{ {
$title = reset( $title = reset(
$h1 $h1
) . $this->app->config->header->title->postfix; );
}
else if ($h2 = $body->getH2())
{
$title = reset(
$h2
);
}
else if ($h3 = $body->getH3())
{
$title = reset(
$h3
);
} }
else else
{ {
$title = $origin->getHost() . $title = $origin->getHost();
$this->app->config->header->title->postfix;
} }
$this->app->setTitle( $this->app->setTitle(
@ -759,10 +773,12 @@ class Page
{ {
if ($value) if ($value)
{ {
/* @TODO
$title = urldecode( $title = urldecode(
mb_strlen($value) > $this->config->title->length->max ? mb_substr($value, 0, $this->config->title->length->max) . '...' mb_strlen($value) > $this->config->title->length->max ? mb_substr($value, 0, $this->config->title->length->max) . '...'
: $value : $value
); );
*/ $title = $value;
} }
else else

Loading…
Cancel
Save