From d2eb981e33e866da5550eca5d919dd1cd5c54c58 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 28 May 2016 03:23:40 -1000 Subject: [PATCH] Create contextmanager for SimpleRevisionCommand --- src/mcedit2/editorsession.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mcedit2/editorsession.py b/src/mcedit2/editorsession.py index f6ae9ac..27c88fc 100644 --- a/src/mcedit2/editorsession.py +++ b/src/mcedit2/editorsession.py @@ -1001,6 +1001,16 @@ class EditorSession(QtCore.QObject): finally: self.pushCommand(command) + @contextmanager + def beginSimpleCommand(self, text): + command = SimpleRevisionCommand(self, text) + command.foo() + try: + with command.begin(): + yield + finally: + self.pushCommand(command) + def pushCommand(self, command): log.info("Pushing command %s" % command.text()) self.undoStack.push(command)