Skip to content

Commit

Permalink
Total overhaul of actions handling, references #616, fixes #592
Browse files Browse the repository at this point in the history
- use only numeric identifiers;
- do not rely on actions supplied by QtWebKit (they are often broken under Windows);
- decouple shortcuts from actions;
- create global actions on demand;
- always show keyboard shortcut of action, no matter if it is global or local instance;
- slightly reduced memory usage;
- hopefully no regressions other than keyboard shortcuts configuration being temporarily unavailable.
  • Loading branch information
Emdek committed Dec 28, 2014
1 parent 3d1295d commit 30719aa
Show file tree
Hide file tree
Showing 51 changed files with 1,743 additions and 2,016 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ set(otter_src
src/core/SearchSuggester.cpp
src/core/SessionsManager.cpp
src/core/SettingsManager.cpp
src/core/ShortcutsManager.cpp
src/core/TransfersManager.cpp
src/core/Utils.cpp
src/core/WebBackend.cpp
Expand Down Expand Up @@ -223,7 +222,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
qt5_use_modules(otter-browser WinExtras)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

qt5_use_modules(otter-browser Core Gui Multimedia Network PrintSupport Script Sql WebKit WebKitWidgets)
qt5_use_modules(otter-browser Core Gui Multimedia Network PrintSupport Script Sql WebKit WebKitWidgets Widgets)

set(OTTER_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
Expand Down
2 changes: 0 additions & 2 deletions otter.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ SOURCES += src/main.cpp \
src/core/SearchSuggester.cpp \
src/core/SessionsManager.cpp \
src/core/SettingsManager.cpp \
src/core/ShortcutsManager.cpp \
src/core/TransfersManager.cpp \
src/core/Utils.cpp \
src/core/WebBackend.cpp \
Expand Down Expand Up @@ -163,7 +162,6 @@ HEADERS += src/core/Action.h \
src/core/SearchSuggester.h \
src/core/SessionsManager.h \
src/core/SettingsManager.h \
src/core/ShortcutsManager.h \
src/core/TransfersManager.h \
src/core/Utils.h \
src/core/WebBackend.h \
Expand Down
22 changes: 11 additions & 11 deletions resources/keyboard/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; Description: Default configuration
; Type: keyboard-profile
; Author: Emdek <michal@emdek.pl>
; Version: 0.1
; Version: 0.2

[NewTab]
shortcuts=Ctrl+T
Expand Down Expand Up @@ -32,7 +32,7 @@ shortcuts=Ctrl+Shift+T
shortcuts=Alt+F11

[Exit]
shortcuts=native
shortcuts=Ctrl+Q

[Undo]
shortcuts=Ctrl+Z
Expand All @@ -53,37 +53,37 @@ shortcuts=Ctrl+Alt+C
shortcuts=Ctrl+V Shift+Ins

[Delete]
shortcuts=native
shortcuts=Delete

[SelectAll]
shortcuts=Ctrl+A

[Find]
shortcuts=native
shortcuts=Ctrl+F

[FindNext]
shortcuts=native Ctrl+G
shortcuts=Ctrl+G

[FindPrevious]
shortcuts=native Ctrl+Shift+G
shortcuts=Ctrl+Shift+G

[QuickFind]
shortcuts=/

[Reload]
shortcuts=native Ctrl+R
shortcuts=Ctrl+R

[ZoomIn]
shortcuts=native 0
shortcuts=0

[ZoomOut]
shortcuts=native 9
shortcuts=9

[GoBack]
shortcuts=native Z Backspace
shortcuts=Z Backspace

[GoForward]
shortcuts=native X Shift+Backspace
shortcuts=X Shift+Backspace

[GoToHomePage]
shortcuts=Ctrl+Space Alt+Home
Expand Down
8 changes: 4 additions & 4 deletions resources/other/menuBar.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
]
},
"separator",
"ViewHistory",
"History",
"separator",
"ClearHistory"
]
Expand All @@ -130,7 +130,7 @@
"actions":
[
"AddBookmark",
"ManageBookmarks",
"Bookmarks",
"separator"
]
},
Expand All @@ -143,8 +143,8 @@
"Transfers",
"Cookies",
"ContentBlocking",
"ErrorConsole",
"Sidebar",
"ShowErrorConsole",
"ShowSidebar",
"separator",
"Preferences"
]
Expand Down
4 changes: 2 additions & 2 deletions resources/other/menuButton.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
"actions":
[
"AddBookmark",
"ManageBookmarks",
"Bookmarks",
"separator"
]
},
"ViewHistory",
"History",
"Transfers",
"separator",
{
Expand Down
51 changes: 30 additions & 21 deletions src/core/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,57 @@
namespace Otter
{

Action::Action(const QIcon &icon, const QString &text, QObject *parent) : QAction(icon, text, parent),
m_identifier(UnknownAction),
m_scope(MainWindowScope)
Action::Action(int identifier, const QIcon &icon, const QString &text, QObject *parent) : QAction(icon, text, parent),
m_identifier(identifier)
{
setText(QCoreApplication::translate("actions", text.toUtf8().constData()));
update();
}

void Action::setName(const QString &name)
void Action::setup(Action *action)
{
setObjectName(name);
}
if (!action)
{
update();
setEnabled(false);

void Action::setIdentifier(ActionIdentifier identifier)
{
m_identifier = identifier;
}
return;
}

void Action::setScope(ActionScope scope)
{
m_scope = scope;
setEnabled(action->isEnabled());
setText(action->text());
setIcon(action->icon());
setCheckable(action->isCheckable());
setChecked(action->isChecked());
}

QString Action::getName() const
void Action::update()
{
return objectName();
const ActionDefinition action = ActionsManager::getActionDefinition(m_identifier);
QString text = QCoreApplication::translate("actions", action.text.toUtf8().constData());

if (!action.shortcuts.isEmpty())
{
text += QLatin1Char('\t') + action.shortcuts.first().toString(QKeySequence::NativeText);
}

setText(text);
}

ActionIdentifier Action::getIdentifier() const
QList<QKeySequence> Action::getShortcuts() const
{
return m_identifier;
return ActionsManager::getActionDefinition(m_identifier).shortcuts.toList();
}

ActionScope Action::getScope() const
int Action::getIdentifier() const
{
return m_scope;
return m_identifier;
}

bool Action::event(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
{
setText(QCoreApplication::translate("actions", ActionsManager::getActionDefinition(objectName()).text.toUtf8().constData()));
update();
}

return QAction::event(event);
Expand Down
Loading

5 comments on commit 30719aa

@beastie1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F4 and F5 don't work anymore. F2, F9, F11, and the ctrl/alt/shift+something in general seem to be working fine.

@beastie1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F3 too doesn't work.

@Emdek
Copy link
Member Author

@Emdek Emdek commented on 30719aa Dec 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which ones where these exactly (except F5, obviously ;-))?
I've dropped support for native keyword as part of the cleanup, so there might be few missing shortcuts changes in default.ini).

@beastie1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean F3 for find next and F4 to open the sidebar?

Also F12 (quick preferences) seems to cause an instant total lock.

@Emdek
Copy link
Member Author

@Emdek Emdek commented on 30719aa Dec 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beastie1, it's all done now, thanks for report, that lock-up was pretty nasty one and hard to spot (apparently I've used all of my testing luck earlier today by finding out off by one issue happening for edge case by accidentally testing it as first one - of more than 100 :-D).

Please sign in to comment.