disable auto indent when pasting text into the python console.

This commit is contained in:
Campbell Barton 2013-05-24 01:04:37 +00:00
parent ebe86abb46
commit 8e6ce736c4
3 changed files with 20 additions and 9 deletions

@ -126,7 +126,7 @@ PROMPT = '>>> '
PROMPT_MULTI = '... ' PROMPT_MULTI = '... '
def execute(context): def execute(context, is_interactive):
sc = context.space_data sc = context.space_data
try: try:
@ -190,9 +190,12 @@ def execute(context):
if is_multiline: if is_multiline:
sc.prompt = PROMPT_MULTI sc.prompt = PROMPT_MULTI
indent = line[:len(line) - len(line.lstrip())] if is_interactive:
if line.rstrip().endswith(":"): indent = line[:len(line) - len(line.lstrip())]
indent += " " if line.rstrip().endswith(":"):
indent += " "
else:
indent = ""
else: else:
sc.prompt = PROMPT sc.prompt = PROMPT
indent = "" indent = ""

@ -20,7 +20,9 @@
import bpy import bpy
from bpy.types import Operator from bpy.types import Operator
from bpy.props import StringProperty from bpy.props import (BoolProperty,
StringProperty,
)
def _lang_module_get(sc): def _lang_module_get(sc):
@ -34,6 +36,10 @@ class ConsoleExec(Operator):
bl_idname = "console.execute" bl_idname = "console.execute"
bl_label = "Console Execute" bl_label = "Console Execute"
interactive = BoolProperty(
options={'SKIP_SAVE'},
)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return (context.area and context.area.type == 'CONSOLE') return (context.area and context.area.type == 'CONSOLE')
@ -44,8 +50,8 @@ class ConsoleExec(Operator):
module = _lang_module_get(sc) module = _lang_module_get(sc)
execute = getattr(module, "execute", None) execute = getattr(module, "execute", None)
if execute: if execute is not None:
return execute(context) return execute(context, self.interactive)
else: else:
print("Error: bpy.ops.console.execute_%s - not found" % print("Error: bpy.ops.console.execute_%s - not found" %
sc.language) sc.language)

@ -319,8 +319,10 @@ static void console_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CONSOLE_OT_clear_line", RETKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "CONSOLE_OT_clear_line", RETKEY, KM_PRESS, KM_SHIFT, 0);
#ifdef WITH_PYTHON #ifdef WITH_PYTHON
WM_keymap_add_item(keymap, "CONSOLE_OT_execute", RETKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */ kmi = WM_keymap_add_item(keymap, "CONSOLE_OT_execute", RETKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CONSOLE_OT_execute", PADENTER, KM_PRESS, 0, 0); RNA_boolean_set(kmi->ptr, "interactive", true);
kmi = WM_keymap_add_item(keymap, "CONSOLE_OT_execute", PADENTER, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "interactive", true);
//WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", TABKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */ //WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", TABKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */ WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */