mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
rename widgets
This commit is contained in:
parent
38b2ac4f04
commit
57f43e2dd9
28 changed files with 365 additions and 365 deletions
20
src/app/browser/main/tab/page/navigation/base.cpp
Normal file
20
src/app/browser/main/tab/page/navigation/base.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "base.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation;
|
||||
|
||||
Base::Base()
|
||||
{
|
||||
set_action_name(
|
||||
"tab.base"
|
||||
);
|
||||
|
||||
set_icon_name(
|
||||
"go-home-symbolic"
|
||||
);
|
||||
|
||||
set_tooltip_text(
|
||||
_("Base")
|
||||
);
|
||||
}
|
||||
|
||||
Base::~Base() = default;
|
||||
19
src/app/browser/main/tab/page/navigation/base.hpp
Normal file
19
src/app/browser/main/tab/page/navigation/base.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BASE_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BASE_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation
|
||||
{
|
||||
class Base : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
||||
Base();
|
||||
|
||||
~Base();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BASE_HPP
|
||||
20
src/app/browser/main/tab/page/navigation/bookmark.cpp
Normal file
20
src/app/browser/main/tab/page/navigation/bookmark.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "bookmark.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation;
|
||||
|
||||
Bookmark::Bookmark()
|
||||
{
|
||||
set_action_name(
|
||||
"tab.bookmark"
|
||||
);
|
||||
|
||||
set_icon_name(
|
||||
"starred-symbolic" // | non-starred-symbolic
|
||||
);
|
||||
|
||||
set_tooltip_text(
|
||||
_("Toggle bookmark")
|
||||
);
|
||||
}
|
||||
|
||||
Bookmark::~Bookmark() = default;
|
||||
19
src/app/browser/main/tab/page/navigation/bookmark.hpp
Normal file
19
src/app/browser/main/tab/page/navigation/bookmark.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BOOKMARK_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BOOKMARK_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation
|
||||
{
|
||||
class Bookmark : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
||||
Bookmark();
|
||||
|
||||
~Bookmark();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_BOOKMARK_HPP
|
||||
113
src/app/browser/main/tab/page/navigation/history.cpp
Normal file
113
src/app/browser/main/tab/page/navigation/history.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#include "history.hpp"
|
||||
#include "history/back.hpp"
|
||||
#include "history/forward.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation;
|
||||
|
||||
History::History()
|
||||
{
|
||||
add_css_class(
|
||||
"linked" // merge children elements
|
||||
);
|
||||
|
||||
historyBack = Gtk::make_managed<history::Back>();
|
||||
|
||||
append(
|
||||
* historyBack
|
||||
);
|
||||
|
||||
historyForward = Gtk::make_managed<history::Forward>();
|
||||
|
||||
append(
|
||||
* historyForward
|
||||
);
|
||||
}
|
||||
|
||||
// Actions
|
||||
void History::add(
|
||||
const Glib::ustring & REQUEST,
|
||||
const bool & FOLLOW
|
||||
) {
|
||||
memory.push_back(
|
||||
{
|
||||
REQUEST,
|
||||
std::time(
|
||||
nullptr
|
||||
),
|
||||
true
|
||||
}
|
||||
);
|
||||
|
||||
if (FOLLOW)
|
||||
{
|
||||
index = memory.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void History::refresh()
|
||||
{
|
||||
Memory match;
|
||||
|
||||
historyBack->set_sensitive(
|
||||
try_back(
|
||||
match,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
historyForward->set_sensitive(
|
||||
try_forward(
|
||||
match,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool History::try_back(
|
||||
Memory & match,
|
||||
const bool & FOLLOW
|
||||
) {
|
||||
try
|
||||
{
|
||||
match = memory.at(
|
||||
index - 1
|
||||
);
|
||||
|
||||
if (FOLLOW)
|
||||
{
|
||||
index--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool History::try_forward(
|
||||
Memory & match,
|
||||
const bool & FOLLOW
|
||||
) {
|
||||
try
|
||||
{
|
||||
match = memory.at(
|
||||
index + 1
|
||||
);
|
||||
|
||||
if (FOLLOW)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
64
src/app/browser/main/tab/page/navigation/history.hpp
Normal file
64
src/app/browser/main/tab/page/navigation/history.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP
|
||||
|
||||
#include <ctime>
|
||||
#include <glibmm/i18n.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/object.h>
|
||||
#include <vector>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation
|
||||
{
|
||||
namespace history
|
||||
{
|
||||
class Back;
|
||||
class Forward;
|
||||
}
|
||||
|
||||
class History : public Gtk::Box
|
||||
{
|
||||
// Components
|
||||
history::Back * historyBack;
|
||||
history::Forward * historyForward;
|
||||
|
||||
int index = -1;
|
||||
|
||||
public:
|
||||
|
||||
// Extras
|
||||
struct Memory
|
||||
{
|
||||
Glib::ustring request;
|
||||
std::time_t time; // event unix time
|
||||
bool permanent; // save in database (on application close) @TODO
|
||||
};
|
||||
|
||||
// Define navigation history storage
|
||||
std::vector<Memory> memory;
|
||||
|
||||
History();
|
||||
|
||||
// Actions
|
||||
void add(
|
||||
const Glib::ustring & REQUEST,
|
||||
const bool & FOLLOW = true
|
||||
);
|
||||
|
||||
void refresh();
|
||||
|
||||
void save(); // @TODO save history to the permanent storage
|
||||
|
||||
bool try_back(
|
||||
Memory & match,
|
||||
const bool & FOLLOW = true
|
||||
);
|
||||
|
||||
bool try_forward(
|
||||
Memory & match,
|
||||
const bool & FOLLOW = true
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP
|
||||
33
src/app/browser/main/tab/page/navigation/history/back.cpp
Normal file
33
src/app/browser/main/tab/page/navigation/history/back.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "back.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation::history;
|
||||
|
||||
Back::Back()
|
||||
{
|
||||
set_action_name(
|
||||
"win.tab_history_back"
|
||||
);
|
||||
|
||||
set_icon_name(
|
||||
"go-previous-symbolic"
|
||||
);
|
||||
|
||||
set_tooltip_text(
|
||||
_("Back")
|
||||
);
|
||||
|
||||
set_sensitive(
|
||||
false // @TODO no effect by set_action_name
|
||||
);
|
||||
|
||||
signal_clicked().connect(
|
||||
[this]
|
||||
{
|
||||
activate_action(
|
||||
"win.tab_history_back"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Back::~Back() = default;
|
||||
19
src/app/browser/main/tab/page/navigation/history/back.hpp
Normal file
19
src/app/browser/main/tab/page/navigation/history/back.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation::history
|
||||
{
|
||||
class Back : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
||||
Back();
|
||||
|
||||
~Back();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP
|
||||
33
src/app/browser/main/tab/page/navigation/history/forward.cpp
Normal file
33
src/app/browser/main/tab/page/navigation/history/forward.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "forward.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation::history;
|
||||
|
||||
Forward::Forward()
|
||||
{
|
||||
set_action_name(
|
||||
"win.tab_history_forward"
|
||||
);
|
||||
|
||||
set_icon_name(
|
||||
"go-next-symbolic"
|
||||
);
|
||||
|
||||
set_tooltip_text(
|
||||
_("Forward")
|
||||
);
|
||||
|
||||
set_sensitive(
|
||||
false // @TODO no effect by set_action_name
|
||||
);
|
||||
|
||||
signal_clicked().connect(
|
||||
[this]
|
||||
{
|
||||
activate_action(
|
||||
"win.tab_history_forward"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Forward::~Forward() = default;
|
||||
19
src/app/browser/main/tab/page/navigation/history/forward.hpp
Normal file
19
src/app/browser/main/tab/page/navigation/history/forward.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation::history
|
||||
{
|
||||
class Forward : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
||||
Forward();
|
||||
|
||||
~Forward();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP
|
||||
106
src/app/browser/main/tab/page/navigation/request.cpp
Normal file
106
src/app/browser/main/tab/page/navigation/request.cpp
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include "request.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation;
|
||||
|
||||
// Construct
|
||||
Request::Request(
|
||||
const Glib::ustring & TEXT
|
||||
) {
|
||||
// Init entry
|
||||
set_placeholder_text(
|
||||
_("URL or search term...")
|
||||
);
|
||||
|
||||
set_hexpand(
|
||||
HEXPAND
|
||||
);
|
||||
|
||||
if (!TEXT.empty())
|
||||
{
|
||||
set_text(
|
||||
TEXT
|
||||
);
|
||||
|
||||
parse();
|
||||
}
|
||||
|
||||
// Connect events
|
||||
signal_changed().connect(
|
||||
[this]
|
||||
{
|
||||
parse();
|
||||
|
||||
activate_action(
|
||||
"navigation.refresh"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
signal_activate().connect(
|
||||
[this]
|
||||
{
|
||||
parse();
|
||||
|
||||
activate_action(
|
||||
"page.update"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Getters
|
||||
Glib::ustring Request::get_scheme()
|
||||
{
|
||||
return scheme;
|
||||
}
|
||||
|
||||
Glib::ustring Request::get_host()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
Glib::ustring Request::get_port()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
Glib::ustring Request::get_path()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
Glib::ustring Request::get_query()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
void Request::parse()
|
||||
{
|
||||
auto match = Glib::Regex::split_simple(
|
||||
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex",
|
||||
get_text()
|
||||
);
|
||||
|
||||
scheme = "";
|
||||
host = "";
|
||||
port = "";
|
||||
path = "";
|
||||
query = "";
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (const Glib::ustring & VALUE : match)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 2: scheme = VALUE; break;
|
||||
case 3: host = VALUE; break;
|
||||
case 5: port = VALUE; break;
|
||||
case 6: path = VALUE; break;
|
||||
case 8: query = VALUE; break;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
37
src/app/browser/main/tab/page/navigation/request.hpp
Normal file
37
src/app/browser/main/tab/page/navigation/request.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <glibmm/regex.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <gtkmm/entry.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation
|
||||
{
|
||||
class Request : public Gtk::Entry
|
||||
{
|
||||
const bool HEXPAND = true;
|
||||
|
||||
Glib::ustring scheme,
|
||||
host,
|
||||
port,
|
||||
path,
|
||||
query;
|
||||
|
||||
void parse();
|
||||
|
||||
public:
|
||||
|
||||
Request(
|
||||
const Glib::ustring & VALUE = ""
|
||||
);
|
||||
|
||||
Glib::ustring get_scheme();
|
||||
Glib::ustring get_host();
|
||||
Glib::ustring get_port();
|
||||
Glib::ustring get_path();
|
||||
Glib::ustring get_query();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST_HPP
|
||||
18
src/app/browser/main/tab/page/navigation/update.cpp
Normal file
18
src/app/browser/main/tab/page/navigation/update.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "update.hpp"
|
||||
|
||||
using namespace app::browser::main::tab::page::navigation;
|
||||
|
||||
Update::Update()
|
||||
{
|
||||
set_action_name(
|
||||
"page.update"
|
||||
);
|
||||
|
||||
set_icon_name(
|
||||
"view-refresh-symbolic"
|
||||
);
|
||||
|
||||
set_tooltip_text(
|
||||
_("Update")
|
||||
);
|
||||
}
|
||||
17
src/app/browser/main/tab/page/navigation/update.hpp
Normal file
17
src/app/browser/main/tab/page/navigation/update.hpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_UPDATE_HPP
|
||||
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_UPDATE_HPP
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
namespace app::browser::main::tab::page::navigation
|
||||
{
|
||||
class Update : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
||||
Update();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_UPDATE_HPP
|
||||
Loading…
Add table
Add a link
Reference in a new issue