Move app commands to strings

This commit is contained in:
Paul Betts 2015-06-25 11:25:55 -05:00
parent 210417b428
commit cde7c6a4ef
9 changed files with 125 additions and 63 deletions

View file

@ -162,8 +162,8 @@ void Window::OnDevToolsClosed() {
devtools_web_contents_.Reset();
}
void Window::OnExecuteWindowsCommand(int command_id) {
Emit("app-command", command_id);
void Window::OnExecuteWindowsCommand(std::string& command_name) {
Emit("app-command", command_name);
}
// static

View file

@ -71,7 +71,7 @@ class Window : public mate::TrackableObject<Window>,
void OnDevToolsFocus() override;
void OnDevToolsOpened() override;
void OnDevToolsClosed() override;
void OnExecuteWindowsCommand(int command_id) override;
void OnExecuteWindowsCommand(std::string& command_name) override;
private:
// APIs for NativeWindow.

View file

@ -1,55 +0,0 @@
module.exports =
APPCOMMAND_BROWSER_BACKWARD: 1
APPCOMMAND_BROWSER_FORWARD: 2
APPCOMMAND_BROWSER_REFRESH: 3
APPCOMMAND_BROWSER_STOP: 4
APPCOMMAND_BROWSER_SEARCH: 5
APPCOMMAND_BROWSER_FAVORITES: 6
APPCOMMAND_BROWSER_HOME: 7
APPCOMMAND_VOLUME_MUTE: 8
APPCOMMAND_VOLUME_DOWN: 9
APPCOMMAND_VOLUME_UP: 10
APPCOMMAND_MEDIA_NEXTTRACK: 11
APPCOMMAND_MEDIA_PREVIOUSTRACK: 12
APPCOMMAND_MEDIA_STOP: 13
APPCOMMAND_MEDIA_PLAY_PAUSE: 14
APPCOMMAND_LAUNCH_MAIL: 15
APPCOMMAND_LAUNCH_MEDIA_SELECT: 16
APPCOMMAND_LAUNCH_APP1: 17
APPCOMMAND_LAUNCH_APP2: 18
APPCOMMAND_BASS_DOWN: 19
APPCOMMAND_BASS_BOOST: 20
APPCOMMAND_BASS_UP: 21
APPCOMMAND_TREBLE_DOWN: 22
APPCOMMAND_TREBLE_UP: 23
APPCOMMAND_MICROPHONE_VOLUME_MUTE: 24
APPCOMMAND_MICROPHONE_VOLUME_DOWN: 25
APPCOMMAND_MICROPHONE_VOLUME_UP: 26
APPCOMMAND_HELP: 27
APPCOMMAND_FIND: 28
APPCOMMAND_NEW: 29
APPCOMMAND_OPEN: 30
APPCOMMAND_CLOSE: 31
APPCOMMAND_SAVE: 32
APPCOMMAND_PRINT: 33
APPCOMMAND_UNDO: 34
APPCOMMAND_REDO: 35
APPCOMMAND_COPY: 36
APPCOMMAND_CUT: 37
APPCOMMAND_PASTE: 38
APPCOMMAND_REPLY_TO_MAIL: 39
APPCOMMAND_FORWARD_MAIL: 40
APPCOMMAND_SEND_MAIL: 41
APPCOMMAND_SPELL_CHECK: 42
APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:43
APPCOMMAND_MIC_ON_OFF_TOGGLE: 44
APPCOMMAND_CORRECTION_LIST: 45
APPCOMMAND_MEDIA_PLAY: 46
APPCOMMAND_MEDIA_PAUSE: 47
APPCOMMAND_MEDIA_RECORD: 48
APPCOMMAND_MEDIA_FAST_FORWARD: 49
APPCOMMAND_MEDIA_REWIND: 50
APPCOMMAND_MEDIA_CHANNEL_UP: 51
APPCOMMAND_MEDIA_CHANNEL_DOWN: 52
APPCOMMAND_DELETE: 53
APPCOMMAND_DWM_FLIP3D: 54

View file

@ -581,9 +581,11 @@ void NativeWindow::NotifyWindowUnresponsive() {
}
void NativeWindow::NotifyExecuteWindowsCommand(int command_id) {
std::string command = AppCommandToString(command_id);
FOR_EACH_OBSERVER(NativeWindowObserver,
observers_,
OnExecuteWindowsCommand(command_id));
OnExecuteWindowsCommand(command));
}
@ -593,4 +595,117 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
callback.Run(bitmap);
}
const char* NativeWindow::AppCommandToString(int command_id) {
switch(command_id) {
case APPCOMMAND_BROWSER_BACKWARD:
return "browser-backward";
case APPCOMMAND_BROWSER_FORWARD:
return "browser-forward";
case APPCOMMAND_BROWSER_REFRESH:
return "browser-refresh";
case APPCOMMAND_BROWSER_STOP:
return "browser-stop";
case APPCOMMAND_BROWSER_SEARCH:
return "browser-search";
case APPCOMMAND_BROWSER_FAVORITES:
return "browser-favorites";
case APPCOMMAND_BROWSER_HOME:
return "browser-home";
case APPCOMMAND_VOLUME_MUTE:
return "volume-mute";
case APPCOMMAND_VOLUME_DOWN:
return "volume-down";
case APPCOMMAND_VOLUME_UP:
return "volume-up";
case APPCOMMAND_MEDIA_NEXTTRACK:
return "media-nexttrack";
case APPCOMMAND_MEDIA_PREVIOUSTRACK:
return "media-previoustrack";
case APPCOMMAND_MEDIA_STOP:
return "media-stop";
case APPCOMMAND_MEDIA_PLAY_PAUSE:
return "media-play_pause";
case APPCOMMAND_LAUNCH_MAIL:
return "launch-mail";
case APPCOMMAND_LAUNCH_MEDIA_SELECT:
return "launch-media-select";
case APPCOMMAND_LAUNCH_APP1:
return "launch-app1";
case APPCOMMAND_LAUNCH_APP2:
return "launch-app2";
case APPCOMMAND_BASS_DOWN:
return "bass-down";
case APPCOMMAND_BASS_BOOST:
return "bass-boost";
case APPCOMMAND_BASS_UP:
return "bass-up";
case APPCOMMAND_TREBLE_DOWN:
return "treble-down";
case APPCOMMAND_TREBLE_UP:
return "treble-up";
case APPCOMMAND_MICROPHONE_VOLUME_MUTE:
return "microphone-volume-mute";
case APPCOMMAND_MICROPHONE_VOLUME_DOWN:
return "microphone-volume-down";
case APPCOMMAND_MICROPHONE_VOLUME_UP:
return "microphone-volume-up";
case APPCOMMAND_HELP:
return "help";
case APPCOMMAND_FIND:
return "find";
case APPCOMMAND_NEW:
return "new";
case APPCOMMAND_OPEN:
return "open";
case APPCOMMAND_CLOSE:
return "close";
case APPCOMMAND_SAVE:
return "save";
case APPCOMMAND_PRINT:
return "print";
case APPCOMMAND_UNDO:
return "undo";
case APPCOMMAND_REDO:
return "redo";
case APPCOMMAND_COPY:
return "copy";
case APPCOMMAND_CUT:
return "cut";
case APPCOMMAND_PASTE:
return "paste";
case APPCOMMAND_REPLY_TO_MAIL:
return "reply-to-mail";
case APPCOMMAND_FORWARD_MAIL:
return "forward-mail";
case APPCOMMAND_SEND_MAIL:
return "send-mail";
case APPCOMMAND_SPELL_CHECK:
return "spell-check";
case APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE:
return "dictate-or-command-control-toggle";
case APPCOMMAND_MIC_ON_OFF_TOGGLE:
return "mic-on-off-toggle";
case APPCOMMAND_CORRECTION_LIST:
return "correction-list";
case APPCOMMAND_MEDIA_PLAY:
return "media-play";
case APPCOMMAND_MEDIA_PAUSE:
return "media-pause";
case APPCOMMAND_MEDIA_RECORD:
return "media-record";
case APPCOMMAND_MEDIA_FAST_FORWARD:
return "media-fast-forward";
case APPCOMMAND_MEDIA_REWIND:
return "media-rewind";
case APPCOMMAND_MEDIA_CHANNEL_UP:
return "media-channel-up";
case APPCOMMAND_MEDIA_CHANNEL_DOWN:
return "media-channel-down";
case APPCOMMAND_DELETE:
return "delete";
default:
return "";
}
}
} // namespace atom

View file

@ -261,6 +261,9 @@ class NativeWindow : public content::WebContentsObserver,
const SkBitmap& bitmap,
content::ReadbackResponse response);
// Convert Win32 WM_APPCOMMANDS to strings
const char* AppCommandToString(int command_id);
// Observers of this window.
ObserverList<NativeWindowObserver> observers_;

View file

@ -67,7 +67,7 @@ class NativeWindowObserver {
virtual void OnRendererResponsive() {}
// Called on Windows when App Commands arrive (WM_APPCOMMAND)
virtual void OnExecuteWindowsCommand(int command) {}
virtual void OnExecuteWindowsCommand(std::string& command_name) {}
};
} // namespace atom

View file

@ -9,7 +9,6 @@
],
'coffee_sources': [
'atom/browser/api/lib/app.coffee',
'atom/browser/api/lib/app-command.coffee',
'atom/browser/api/lib/atom-delegate.coffee',
'atom/browser/api/lib/auto-updater.coffee',
'atom/browser/api/lib/browser-window.coffee',

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit b05e019d2f66023fad1ae2f16cc765e3d62ffd5e
Subproject commit 2dc473cada4f118880241c6cd62ffb59dc58ef50

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6
Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0