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

18
src/Entity/App.php

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

24
src/Entity/Tab/Page.php

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

Loading…
Cancel
Save