forked from evandrocoan/PlantUmlDiagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagram_plugin.py
61 lines (47 loc) · 1.51 KB
/
diagram_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: UTF-8 -*-
import sublime
import sublime_plugin
import os
import re
import time
import threading
import plantuml_connection
from debug_tools import getLogger
log = getLogger(1, __package__)
try:
from .diagram import setup, process
except ValueError:
from diagram import setup, process
try:
all_views_active
except NameError:
all_views_active = {}
def process_diagram_image(view):
all_views_active[view.id()] = view
try:
if not process(view):
sublime.error_message("No diagrams found, nothing to process.")
except plantuml_connection.PlantUMLSyntaxError as error:
# TODO show syntax error use mdpop
sublime.error_message("Syntax error on diagram: %s",
re.findall(r'X-PlantUML-Diagram-Description:((?:.|\n)*?)X-Powered-By', str(error)))
class DisplayDiagramsContinuallyEventListener(sublime_plugin.ViewEventListener):
def on_modified_async(self):
if self.view.id() not in all_views_active:
return
process_diagram_image(self.view)
class DisplayDiagrams(sublime_plugin.TextCommand):
def run(self, edit):
process_diagram_image(self.view)
def isEnabled(self):
return True
if sublime.version()[0] == '2':
setup()
else:
def plugin_loaded():
"""Sublime Text 3 callback to do after-loading initialization"""
try:
setup()
except Exception as error:
print("Unable to load diagram plugin, check console for details.\n\n%s" % error)
raise