Handle standard pasteboard keybindings in the dev tools

This commit adds a boolean constructor parameter to the AtomCefClient indicating whether it should handle the standard pasteboard commands for its associated browser. We pass `true` when constructing the client for the dev tools, so these commands work there.
This commit is contained in:
Nathan Sobo 2012-10-29 11:44:56 -06:00
parent 86c4f7a805
commit e649b2e6c6
3 changed files with 16 additions and 2 deletions

View File

@ -15,6 +15,10 @@
AtomCefClient::AtomCefClient(){
}
AtomCefClient::AtomCefClient(bool handlePasteboardCommands) {
m_HandlePasteboardCommands = handlePasteboardCommands;
}
AtomCefClient::~AtomCefClient() {
}
@ -105,6 +109,15 @@ bool AtomCefClient::OnKeyEvent(CefRefPtr<CefBrowser> browser,
if (event.modifiers == KEY_META && event.unmodified_character == 'r') {
browser->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("reload"));
}
if (m_HandlePasteboardCommands && event.modifiers == KEY_META && event.unmodified_character == 'x') {
browser->GetFocusedFrame()->Cut();
}
if (m_HandlePasteboardCommands && event.modifiers == KEY_META && event.unmodified_character == 'c') {
browser->GetFocusedFrame()->Copy();
}
if (m_HandlePasteboardCommands && event.modifiers == KEY_META && event.unmodified_character == 'v') {
browser->GetFocusedFrame()->Paste();
}
else if (event.modifiers == (KEY_META | KEY_ALT) && event.unmodified_character == 'i') {
ToggleDevTools(browser);
} else if (event.modifiers == KEY_META && event.unmodified_character == '`') {

View File

@ -16,9 +16,9 @@ class AtomCefClient : public CefClient,
public CefRequestHandler {
public:
AtomCefClient();
AtomCefClient(bool handlePasteboardCommands);
virtual ~AtomCefClient();
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
@ -97,6 +97,7 @@ class AtomCefClient : public CefClient,
protected:
CefRefPtr<CefBrowser> m_Browser;
bool m_HandlePasteboardCommands = false;
void FocusNextWindow();
void Open(std::string path);

View File

@ -131,7 +131,7 @@
// devtools don't resize properly.
// HACK: I hate this and want to place this code directly in showDevTools
- (void)attachDevTools {
_cefDevToolsClient = new AtomCefClient();
_cefDevToolsClient = new AtomCefClient(true);
std::string devtools_url = _cefClient->GetBrowser()->GetHost()->GetDevToolsURL(true);
[self addBrowserToView:_devToolsView url:devtools_url.c_str() cefHandler:_cefDevToolsClient];
}