def newline_mode(self, new, old): undoman = self.undo_manager if not (undoman.isUndoing() or undoman.isRedoing()): replace_newlines(self.text_view, const.EOLS[new]) self.document.props.newline_mode = new def undo(): self.proxy.newline_mode = old register_undo_callback(undoman, undo)
def newline_mode(self, new, old): undoman = self.document.undoManager() if not (undoman.isUndoing() or undoman.isRedoing()): replace_newlines(self.text_view, const.EOLS[new]) self.document.props.newline_mode = new def undo(): self.props.newline_mode = old register_undo_callback(undoman, undo)
def test_register_undo(): from editxt.util import register_undo_callback m = Mocker() inv_class = m.replace(mod, 'Invoker') cb = m.mock() und = m.mock(fn.NSUndoManager) inv = inv_class.alloc().init(cb) >> m.mock(mod.Invoker) und.registerUndoWithTarget_selector_object_(inv_class, "invoke:", inv) with m: register_undo_callback(und, cb)
def change_indentation(self, old_mode, old_size, new_mode, new_size, convert_text): if convert_text: old_indent = "\t" if old_mode == const.INDENT_MODE_TAB else (" " * old_size) new_indent = "\t" if new_mode == const.INDENT_MODE_TAB else (" " * new_size) change_indentation(self.text_view, old_indent, new_indent, new_size) if old_mode != new_mode: self.document.props.indent_mode = new_mode if old_size != new_size: self.document.props.indent_size = new_size if convert_text or convert_text is None: def undo(): self.change_indentation(new_mode, new_size, old_mode, old_size, None) register_undo_callback(self.undo_manager, undo)
def change_indentation(self, old_mode, old_size, new_mode, new_size, convert_text): if convert_text: old_indent = "\t" if old_mode == const.INDENT_MODE_TAB else ( " " * old_size) new_indent = "\t" if new_mode == const.INDENT_MODE_TAB else ( " " * new_size) change_indentation(self.text_view, old_indent, new_indent, new_size) if old_mode != new_mode: self.document.props.indent_mode = new_mode if old_size != new_size: self.document.props.indent_size = new_size if convert_text or convert_text is None: def undo(): self.change_indentation(new_mode, new_size, old_mode, old_size, None) register_undo_callback(self.document.undoManager(), undo)