Ladybird: Do not enable the reload button if history is empty
Not much of an issue currently, but will be once tabs are used to render plain HTML.
This commit is contained in:
parent
70830b711e
commit
9c4ce1b80b
Notes:
sideshowbarker
2024-07-16 20:12:13 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9c4ce1b80b Pull-request: https://github.com/SerenityOS/serenity/pull/20824 Reviewed-by: https://github.com/ADKaster ✅
5 changed files with 19 additions and 0 deletions
|
@ -139,6 +139,10 @@ enum class IsHistoryNavigation {
|
|||
|
||||
- (void)reload:(id)sender
|
||||
{
|
||||
if (m_history.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_is_history_navigation = IsHistoryNavigation::Yes;
|
||||
|
||||
auto url = m_history.current().url;
|
||||
|
@ -179,6 +183,9 @@ enum class IsHistoryNavigation {
|
|||
|
||||
auto* navigate_forward_button = (NSButton*)[[self navigate_forward_toolbar_item] view];
|
||||
[navigate_forward_button setEnabled:m_history.can_go_forward()];
|
||||
|
||||
auto* reload_button = (NSButton*)[[self reload_toolbar_item] view];
|
||||
[reload_button setEnabled:!m_history.is_empty()];
|
||||
}
|
||||
|
||||
- (void)showTabOverview:(id)sender
|
||||
|
@ -232,6 +239,7 @@ enum class IsHistoryNavigation {
|
|||
if (!_reload_toolbar_item) {
|
||||
auto* button = [self create_button:NSImageNameRefreshTemplate
|
||||
with_action:@selector(reload:)];
|
||||
[button setEnabled:NO];
|
||||
|
||||
_reload_toolbar_item = [[NSToolbarItem alloc] initWithItemIdentifier:TOOLBAR_RELOAD_IDENTIFIER];
|
||||
[_reload_toolbar_item setView:button];
|
||||
|
|
|
@ -401,6 +401,7 @@ BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, Browser::CookieJa
|
|||
m_reload_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Refresh));
|
||||
m_go_back_action->setEnabled(false);
|
||||
m_go_forward_action->setEnabled(false);
|
||||
m_reload_action->setEnabled(false);
|
||||
|
||||
if (initial_url.has_value()) {
|
||||
auto initial_url_string = qstring_from_ak_deprecated_string(initial_url->serialize());
|
||||
|
|
|
@ -132,6 +132,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView::
|
|||
|
||||
m_window->go_back_action().setEnabled(m_history.can_go_back());
|
||||
m_window->go_forward_action().setEnabled(m_history.can_go_forward());
|
||||
m_window->reload_action().setEnabled(!m_history.is_empty());
|
||||
|
||||
if (m_inspector_widget)
|
||||
m_inspector_widget->clear_dom_json();
|
||||
|
@ -587,6 +588,9 @@ void Tab::forward()
|
|||
|
||||
void Tab::reload()
|
||||
{
|
||||
if (m_history.is_empty())
|
||||
return;
|
||||
|
||||
m_is_history_navigation = true;
|
||||
view().load(m_history.current().url.to_deprecated_string());
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ public:
|
|||
bool can_go_forward(int steps = 1) { return (m_current + steps) < static_cast<int>(m_items.size()); }
|
||||
void clear();
|
||||
|
||||
bool is_empty() const { return m_items.is_empty(); }
|
||||
|
||||
private:
|
||||
Vector<URLTitlePair> m_items;
|
||||
int m_current { -1 };
|
||||
|
|
|
@ -732,6 +732,9 @@ URL Tab::url() const
|
|||
|
||||
void Tab::reload()
|
||||
{
|
||||
if (m_history.is_empty())
|
||||
return;
|
||||
|
||||
load(url());
|
||||
}
|
||||
|
||||
|
@ -762,6 +765,7 @@ void Tab::update_actions()
|
|||
return;
|
||||
window.go_back_action().set_enabled(m_history.can_go_back());
|
||||
window.go_forward_action().set_enabled(m_history.can_go_forward());
|
||||
window.reload_action().set_enabled(!m_history.is_empty());
|
||||
}
|
||||
|
||||
ErrorOr<void> Tab::bookmark_current_url()
|
||||
|
|
Loading…
Add table
Reference in a new issue