81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from talon import Context, Module, actions, imgui, settings, ui
|
|
|
|
ctx = Context()
|
|
ctx.matches = r"""
|
|
mode: user.csharp
|
|
mode: command
|
|
and code.language: csharp
|
|
"""
|
|
ctx.lists["user.code_functions"] = {
|
|
"integer": "int.TryParse",
|
|
"print": "Console.WriteLine",
|
|
"string": ".ToString",
|
|
}
|
|
|
|
|
|
@ctx.action_class("user")
|
|
class user_actions:
|
|
def code_insert_function(text: str, selection: str):
|
|
if selection:
|
|
text = text + "({})".format(selection)
|
|
else:
|
|
text = text + "()"
|
|
|
|
actions.user.paste(text)
|
|
actions.edit.left()
|
|
|
|
def code_private_function(text: str):
|
|
"""Inserts private function declaration"""
|
|
result = "private void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_private_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|
|
|
|
def code_private_static_function(text: str):
|
|
"""Inserts private static function"""
|
|
result = "private static void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_private_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|
|
|
|
def code_protected_function(text: str):
|
|
result = "private void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_protected_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|
|
|
|
def code_protected_static_function(text: str):
|
|
result = "protected static void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_protected_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|
|
|
|
def code_public_function(text: str):
|
|
result = "public void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_public_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|
|
|
|
def code_public_static_function(text: str):
|
|
result = "public static void {}".format(
|
|
actions.user.formatted_text(
|
|
text, settings.get("user.code_public_function_formatter")
|
|
)
|
|
)
|
|
|
|
actions.user.code_insert_function(result, None)
|