summaryrefslogtreecommitdiff
path: root/DevTools/HackStudio
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-05 20:55:50 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-05 20:56:36 +0100
commit538d5f82c141536c3517ff8321be8ed7316fbd3a (patch)
tree6589bfb990c47e9a4c858e7389c3241663ad0498 /DevTools/HackStudio
parentf844715106a0abbe55fba34c53c10bf2da77e6d9 (diff)
downloadserenity-538d5f82c141536c3517ff8321be8ed7316fbd3a.zip
HackStudio: Allow switching between editors with Ctrl+E / Ctrl+Shift+E
Diffstat (limited to 'DevTools/HackStudio')
-rw-r--r--DevTools/HackStudio/EditorWrapper.h6
-rw-r--r--DevTools/HackStudio/main.cpp34
2 files changed, 35 insertions, 5 deletions
diff --git a/DevTools/HackStudio/EditorWrapper.h b/DevTools/HackStudio/EditorWrapper.h
index 2180d8da73..c84c5e4e98 100644
--- a/DevTools/HackStudio/EditorWrapper.h
+++ b/DevTools/HackStudio/EditorWrapper.h
@@ -24,3 +24,9 @@ private:
RefPtr<GLabel> m_cursor_label;
RefPtr<Editor> m_editor;
};
+
+template<>
+inline bool is<EditorWrapper>(const CObject& object)
+{
+ return !strcmp(object.class_name(), "EditorWrapper");
+}
diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp
index 47a8b043c6..a53a921479 100644
--- a/DevTools/HackStudio/main.cpp
+++ b/DevTools/HackStudio/main.cpp
@@ -133,12 +133,36 @@ int main(int argc, char** argv)
auto switch_to_next_editor = GAction::create("Switch to next editor", { Mod_Ctrl, Key_E }, [&](auto&) {
if (g_all_editor_wrappers.size() <= 1)
return;
- // FIXME: This will only work correctly when there are 2 editors. Make it work for any editor count.
- for (auto& wrapper : g_all_editor_wrappers) {
- if (&wrapper == &current_editor_wrapper())
- continue;
- wrapper.editor().set_focus(true);
+ Vector<EditorWrapper*> wrappers;
+ inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
+ wrappers.append(&child);
+ return IterationDecision::Continue;
+ });
+ for (int i = 0; i < wrappers.size(); ++i) {
+ if (g_current_editor_wrapper.ptr() == wrappers[i]) {
+ if (i == wrappers.size() - 1)
+ wrappers[0]->editor().set_focus(true);
+ else
+ wrappers[i + 1]->editor().set_focus(true);
+ }
+ }
+ });
+
+ auto switch_to_previous_editor = GAction::create("Switch to previous editor", { Mod_Ctrl | Mod_Shift, Key_E }, [&](auto&) {
+ if (g_all_editor_wrappers.size() <= 1)
return;
+ Vector<EditorWrapper*> wrappers;
+ inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
+ wrappers.append(&child);
+ return IterationDecision::Continue;
+ });
+ for (int i = wrappers.size() - 1; i >= 0; --i) {
+ if (g_current_editor_wrapper.ptr() == wrappers[i]) {
+ if (i == 0)
+ wrappers.last()->editor().set_focus(true);
+ else
+ wrappers[i - 1]->editor().set_focus(true);
+ }
}
});