From 0bff451b705068d0765e7a43dd848bdfb2f772f7 2014-01-28 00:27:25 From: Brian E. Granger Date: 2014-01-28 00:27:25 Subject: [PATCH] Added platform dep. logic. --- diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 90eca6e..723f90a 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -459,6 +459,16 @@ IPython.utils = (function (IPython) { return M; })(); + // http://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript + var platform = (function () { + var OSName="Unknown OS"; + if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; + if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; + if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; + if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; + return OSName + })(); + var is_or_has = function (a, b) { // Is b a child of a or a itself? return a.has(b).length !==0 || a.is(b); @@ -500,6 +510,7 @@ IPython.utils = (function (IPython) { splitext : splitext, always_new : always_new, browser : browser, + platform: platform, is_or_has : is_or_has, is_focused : is_focused }; diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index b6e09f9..8fe5be2 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -50,6 +50,7 @@ var IPython = (function (IPython) { } var browser = IPython.utils.browser[0]; + var platform = IPython.utils.platform; if (browser === 'Firefox' || browser === 'Opera') { $.extend(_keycodes, _mozilla_keycodes); @@ -78,24 +79,6 @@ var IPython = (function (IPython) { // Default keyboard shortcuts var default_common_shortcuts = { - 'meta+s' : { - help : 'save notebook', - help_index : 'fb', - handler : function (event) { - IPython.notebook.save_checkpoint(); - event.preventDefault(); - return false; - } - }, - 'ctrl+s' : { - help : 'save notebook', - help_index : 'fc', - handler : function (event) { - IPython.notebook.save_checkpoint(); - event.preventDefault(); - return false; - } - }, 'shift' : { help : '', help_index : '', @@ -130,6 +113,30 @@ var IPython = (function (IPython) { } } + if (platform === 'MacOS') { + default_common_shortcuts['cmd+s'] = + { + help : 'save notebook', + help_index : 'fb', + handler : function (event) { + IPython.notebook.save_checkpoint(); + event.preventDefault(); + return false; + } + }; + } else { + default_common_shortcuts['ctrl+s'] = + { + help : 'save notebook', + help_index : 'fb', + handler : function (event) { + IPython.notebook.save_checkpoint(); + event.preventDefault(); + return false; + } + }; + } + // Edit mode defaults var default_edit_shortcuts = { @@ -195,6 +202,48 @@ var IPython = (function (IPython) { return false; } }, + 'tab' : { + help : 'indent or complete', + help_index : 'ec', + }, + 'shift+tab' : { + help : 'tooltip', + help_index : 'ed', + }, + } + + if (platform === 'MacOS') { + default_edit_shortcuts['cmd+/'] = + { + help : 'toggle comment', + help_index : 'ee' + }; + default_edit_shortcuts['cmd+]'] = + { + help : 'indent', + help_index : 'ef' + }; + default_edit_shortcuts['cmd+['] = + { + help : 'dedent', + help_index : 'eg' + }; + } else { + default_edit_shortcuts['ctrl+/'] = + { + help : 'toggle comment', + help_index : 'ee' + }; + default_edit_shortcuts['ctrl+]'] = + { + help : 'indent', + help_index : 'ef' + }; + default_edit_shortcuts['ctrl+['] = + { + help : 'dedent', + help_index : 'eg' + }; } // Command mode defaults @@ -402,7 +451,7 @@ var IPython = (function (IPython) { } }, 'shift+o' : { - help : 'toggle output', + help : 'toggle output scroll', help_index : 'gc', handler : function (event) { IPython.notebook.toggle_output_scroll(); @@ -483,6 +532,14 @@ var IPython = (function (IPython) { return false; } }, + 'shift+m' : { + help : 'merge cell below', + help_index : 'ek', + handler : function (event) { + IPython.notebook.merge_cell_below(); + return false; + } + }, } @@ -500,6 +557,9 @@ var IPython = (function (IPython) { var help_string = this._shortcuts[shortcut]['help']; var help_index = this._shortcuts[shortcut]['help_index']; if (help_string) { + if (platform === 'MacOS') { + shortcut = shortcut.replace('meta', 'cmd'); + } help.push({ shortcut: shortcut, help: help_string, @@ -523,6 +583,7 @@ var IPython = (function (IPython) { ShortcutManager.prototype.normalize_shortcut = function (shortcut) { // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift + shortcut = shortcut.replace('cmd', 'meta').toLowerCase(); var values = shortcut.split("+"); if (values.length === 1) { return this.normalize_key(values[0]) diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 0f52b7e..1f1830e 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -88,7 +88,7 @@ var IPython = (function (IPython) { }); $([IPython.events]).on('status_interrupting.Kernel',function () { - knw.set_message("Interrupting kernel"); + knw.set_message("Interrupting kernel", 2000); }); $([IPython.events]).on('status_dead.Kernel',function () {