Skip to content

Commit

Permalink
addon support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsuo Ishimoto committed Dec 30, 2013
1 parent 05469aa commit 12fcc11
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
41 changes: 41 additions & 0 deletions kaa/addon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from kaa.keyboard import *

_class_addoons = {}

def add_class_addon(classname, key, value):
d = _class_addoons.setdefault(classname, {})
d.setdefault(key, []).append(value)

def get_addon(name, key):
d = _class_addoons.get(name, None)
if d:
return d.get(key, ())
return ()

# keybind(filetype='kaa.filetype.python', editmode='input', {
# })

def keybind(filetype=None, editmode='input', keymap=None):
pass


# @command(filetype='kaa.filetype.python.pythonmode.PythonMode',
# commandid='abc.def')
# @norec
# def abc_def(wnd):
# pass

def command(commandid, filetype=None):
pass


#styledef(filetype='kaa.filetype.python', theme='basic', [
# Sytle('default', 'white', 'black'),
#])

def styledef(filetype, theme, styles):
pass

# addfiletype('my.python.filetype',
# overrides='kaa.filetype.python')

10 changes: 5 additions & 5 deletions kaa/cui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ def __init__(self, config):
self.commands = {}
self.is_availables = {}

def register_command(self, cmds):
def register_commandobj(self, cmds):
self.commands.update(cmds.get_commands())
self.is_availables.update(cmds.get_commands_is_enable())

def init_commands(self):
from kaa.commands import appcommand, toolcommand, filecommand

self.app_commands = appcommand.ApplicationCommands()
self.register_command(self.app_commands)
self.register_commandobj(self.app_commands)

self.file_commands = filecommand.FileCommands()
self.register_command(self.file_commands)
self.register_commandobj(self.file_commands)

self.register_command(toolcommand.ToolCommands())
self.register_command(appcommand.MacroCommands())
self.register_commandobj(toolcommand.ToolCommands())
self.register_commandobj(appcommand.MacroCommands())

for name in dir(self):
attr = getattr(self, name)
Expand Down
49 changes: 41 additions & 8 deletions kaa/filetype/default/modebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from kaa import highlight
from kaa import theme
from kaa import screen

from kaa import addon

class SearchOption:
RE = gappedbuf.re
Expand Down Expand Up @@ -90,12 +90,16 @@ def __init__(self):
self.keybind_vi_visualmode = keyboard.KeyBind()
self.keybind_vi_visuallinewisemode = keyboard.KeyBind()
self.init_keybind()
self.init_addon_keys()

self.init_commands()
self.init_addon_commands()

self.init_menu()

self.themes = []
self.init_themes()
self.init_addon_themes()
self._build_theme()
kaa.app.translate_theme(self.theme)

Expand Down Expand Up @@ -179,31 +183,60 @@ def register_keys(self, keybind, keys):
def init_keybind(self):
pass

def get_class_name(self):
modulename = self.__class__.__module__
name = '.'.join((modulename, self.__class__.__name__))
return name

def init_addon_keys(self):
name = self.get_class_name()
keydef = addon.get_addon(name, 'keybind')
for editmode, keys in keydef:
if editmode == 'input':
self.keybind.add_keybind(keys)
elif editmode == 'command':
self.keybind_vi_commandmode.add_keybind(keys)
elif editmode == 'visual':
self.keybind_vi_visualmode.add_keybind(keys)
elif editmode == 'visualline':
self.keybind_vi_visuallinewisemode.add_keybind(keys)

def init_commands(self):
from kaa.commands import (editorcommand, editmodecommand)

self.register_command(editorcommand.CursorCommands())
self.register_command(editorcommand.EditCommands())
self.register_command(editorcommand.CodeCommands())
self.register_command(editorcommand.SelectionCommands())
self.register_command(editorcommand.SearchCommands())
self.register_command(editmodecommand.EditModeCommands())
self.register_commandobj(editorcommand.CursorCommands())
self.register_commandobj(editorcommand.EditCommands())
self.register_commandobj(editorcommand.CodeCommands())
self.register_commandobj(editorcommand.SelectionCommands())
self.register_commandobj(editorcommand.SearchCommands())
self.register_commandobj(editmodecommand.EditModeCommands())

for name in dir(self):
attr = getattr(self, name)
if hasattr(attr, 'COMMAND_ID') and callable(attr):
self.commands[getattr(attr, 'COMMAND_ID')] = attr

def init_addon_commands(self):
name = self.get_class_name()
commands = addon.get_addon(name, 'commands')
for commandid, f in commands:
self.commands[commandid] = f

def init_menu(self):
pass

def init_themes(self):
pass

def init_addon_themes(self):
name = self.get_class_name()
themes = addon.get_addon(name, 'themes')
self.themes.extend(themes)

def init_tokenizers(self):
pass

def register_command(self, cmds):
def register_commandobj(self, cmds):
self.commands.update(cmds.get_commands())
self.is_availables.update(cmds.get_commands_is_enable())

Expand Down

0 comments on commit 12fcc11

Please sign in to comment.