Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Pythonista 311013 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zrzka committed Oct 18, 2017
1 parent b25ede3 commit 2898075
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

## master (unreleased)

* `lib/pep8` removed, not used
* Fixed `get_actions` (exception when user has no custom actions)
*

## 1.2.2 (2017-10-18)

* Bundled `lib/pep8` removed, unused
* Fixed `get_actions` (exception when user has no custom actions)
* Pythonista 3.1.1 (311013)
* Compatibility check with 311013
* Shortcuts `Cmd W`, `Ctrl Tab`, `Ctrl Shift Tab` no longer work (1)
* Shortcuts `Cmd 1..9`, `Cmd Shift ]`, `Cmd Shift [`, `Cmd Shift W` still work

(1) Pythonista 311013 provides these shortcuts natively. Unfortunately,
they do not work. Also these shortcuts are provided elsewhere in the
responder chain, so, even if I register them via the Black Mamba, responder
chain catches them sooner then Black Mamba and they do not work.

All these shortcuts do work prior to 311013. If you have 311013 installed, you
can use `Cmd Q` to close tab (temporary) and `Cmd Shift ]` / `Cmd Shift [`
to show next / previous tab.

## 1.2.1 (2017-10-11)

Expand Down
58 changes: 47 additions & 11 deletions blackmamba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from blackmamba.log import info, error, get_level, set_level, ERROR
import blackmamba.system as system

__version__ = '1.2.1'
__version__ = '1.2.2'
__author__ = 'Robert Vojta'

_LATEST_VERSION_COMPATIBILITY_TEST = (311009, '3.1.1')
_LATEST_VERSION_COMPATIBILITY_TEST = (311013, '3.1.1')


def _register_key_command(input, modifier, function, title=None):
Expand Down Expand Up @@ -65,6 +65,48 @@ def _register_ios11_default_key_commands():
_register_key_command(*command)


@system.Pythonista(appex=False)
def _register_pre_311013_key_commands():
from blackmamba.uikit.keyboard import UIKeyModifier
import blackmamba.ide.tab as tab

if system.PYTHONISTA_BUNDLE_VERSION >= 311013:
return

commands = [
('W', UIKeyModifier.command,
tab.close_selected_tab,
'Close Tab'),
('\t', UIKeyModifier.control,
tab.select_next_tab,
'Show Next Tab'),
('\t', UIKeyModifier.control | UIKeyModifier.shift,
tab.select_previous_tab,
'Show Previous Tab')
]

for command in commands:
_register_key_command(*command)


@system.Pythonista(appex=False)
def _register_post_311013_key_commands():
from blackmamba.uikit.keyboard import UIKeyModifier
import blackmamba.ide.tab as tab

if system.PYTHONISTA_BUNDLE_VERSION < 311013:
return

commands = [
('Q', UIKeyModifier.command,
tab.close_selected_tab,
'Close Tab')
]

for command in commands:
_register_key_command(*command)


@system.Pythonista(appex=False)
def _register_default_key_commands():
from blackmamba.uikit.keyboard import UIKeyModifier, UIKeyInput
Expand Down Expand Up @@ -113,15 +155,6 @@ def _register_default_key_commands():
('0', UIKeyModifier.command,
tab.toggle_navigator,
'Toggle Navigator'),
('W', UIKeyModifier.command,
tab.close_selected_tab,
'Close Tab'),
('\t', UIKeyModifier.control,
tab.select_next_tab,
'Show Next Tab'),
('\t', UIKeyModifier.control | UIKeyModifier.shift,
tab.select_previous_tab,
'Show Previous Tab'),
(']', UIKeyModifier.command | UIKeyModifier.shift,
tab.select_next_tab),
('[', UIKeyModifier.command | UIKeyModifier.shift,
Expand All @@ -145,6 +178,9 @@ def select_tab():
for i in range(9):
_register_key_command(str(i + 1), UIKeyModifier.command, _make_select_tab(i))

_register_pre_311013_key_commands()
_register_post_311013_key_commands()

# No need to show Cmd-[Shift]-S to users
_log_level = get_level()
set_level(ERROR)
Expand Down
4 changes: 2 additions & 2 deletions blackmamba/uikit/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _blackmamba_keyCommands(_self, _cmd):
"""Swizzled version of keyCommands(). It calls original method to
get Pythonista shortcuts and then appends custom ones."""
obj = ObjCInstance(_self)
commands = list(obj.originalkeyCommands())
commands = list(obj.originalkeyCommands() or [])
commands.extend(_key_commands)
return ns(commands).ptr

Expand Down Expand Up @@ -308,7 +308,7 @@ def _register_key_command(input, modifier_flags, function, title=None):

selector_name = _key_command_selector_name(input, modifier_flags)
selector = sel(selector_name)
obj = UIApplication.sharedApplication().keyWindow()
obj = UIApplication.sharedApplication()

info('Registering key command "{}" ({})'.format(
_shortcut_name(input, modifier_flags),
Expand Down

0 comments on commit 2898075

Please sign in to comment.