LibVT: Add a context menu to TerminalWidget

Starting with only the copy and paste actions. But I'm sure we can come
up with some more things to put here. :^)
This commit is contained in:
Andreas Kling 2019-11-20 21:39:26 +01:00
parent dbf8d6bc1e
commit dabdd484f7
Notes: sideshowbarker 2024-07-19 11:08:02 +09:00
2 changed files with 14 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GClipboard.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GScrollBar.h>
#include <LibGUI/GWindow.h>
@ -654,3 +655,13 @@ void TerminalWidget::beep()
};
force_repaint();
}
void TerminalWidget::context_menu_event(GContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = make<GMenu>();
m_context_menu->add_action(copy_action());
m_context_menu->add_action(paste_action());
}
m_context_menu->popup(event.screen_position());
}

View file

@ -72,6 +72,7 @@ private:
virtual void doubleclick_event(GMouseEvent&) override;
virtual void focusin_event(CEvent&) override;
virtual void focusout_event(CEvent&) override;
virtual void context_menu_event(GContextMenuEvent&) override;
// ^TerminalClient
virtual void beep() override;
@ -128,5 +129,7 @@ private:
RefPtr<GAction> m_copy_action;
RefPtr<GAction> m_paste_action;
OwnPtr<GMenu> m_context_menu;
CElapsedTimer m_triple_click_timer;
};