# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# def max_calls(limit = 1500, name=""):
#     """Decorator which allows its wrapped function to be called `limit` times"""
#     def decorator(func):
#         # Disable limit:
#         return func
#         @wraps(func)
#         def wrapper(*args, **kwargs):
#             calls = getattr(wrapper, 'calls', 0)
#             calls += 1
#             setattr(wrapper, 'calls', calls)
#             fname = name if name != "" else func.__name__
# 
#             if calls == limit + 1:
#                 Debug('max_calls', "LIMIT !! ## !!: Fkt %s has %i calls, stop" % (fname, calls - 1))
# 
#             if calls >= limit + 1:
#                 return None
# 
#             Debug('max_calls', "CALL: Fkt %s has %i calls -> +1" % (fname, calls - 1))
# 
#             return func(*args, **kwargs)
#         setattr(wrapper, 'calls', 0)
#         return wrapper
#     return decorator


import sublime
from ...utils import Debug, max_calls
    def _search_existing_view(self):
        """
            returns True if a view with the name of
            this ArcticTypescript view is open and sets it as reference
        """
        for w in sublime.windows():
            for v in w.views():
                if v.name() == self.name:
                    self._view_reference = v
                    self.on_overtook_existing_view()
                    return self._is_view_still_open()
        return False

    @max_calls()
    def set_text(self, edit_token, content):
        if not self._is_view_still_open():
            return
        self.is_updating = True
        self._view_reference.set_read_only(False)
        self._view_reference.erase(edit_token, sublime.Region(0, self._view_reference.size()))
        self._view_reference.insert(edit_token, 0, content)
        self._view_reference.set_read_only(True)
        self.is_updating = False


    window = None # remember last group before close, so we can remove that exact group if empty
    group = None
    def on_pre_close(self):
        Debug('layout', 'ON_PRE_CLOSE')
        if self._is_view_still_open():

# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# def max_calls(limit = 1500, name=""):
#     """Decorator which allows its wrapped function to be called `limit` times"""
#     def decorator(func):
#         # Disable limit:
#         return func
#         @wraps(func)
#         def wrapper(*args, **kwargs):
#             calls = getattr(wrapper, 'calls', 0)
#             calls += 1
#             setattr(wrapper, 'calls', calls)
#             fname = name if name != "" else func.__name__
# 
#             if calls == limit + 1:
#                 Debug('max_calls', "LIMIT !! ## !!: Fkt %s has %i calls, stop" % (fname, calls - 1))
# 
#             if calls >= limit + 1:
#                 return None
# 
#             Debug('max_calls', "CALL: Fkt %s has %i calls -> +1" % (fname, calls - 1))
# 
#             return func(*args, **kwargs)
#         setattr(wrapper, 'calls', 0)
#         return wrapper
#     return decorator


# Path: lib/display/views/Base.py
import sublime
from ...utils import Debug, max_calls

    def _search_existing_view(self):
        """
            returns True if a view with the name of
            this ArcticTypescript view is open and sets it as reference
        """
        for w in sublime.windows():
            for v in w.views():
                if v.name() == self.name:
                    self._view_reference = v
                    self.on_overtook_existing_view()
                    return self._is_view_still_open()
        return False

    @max_calls()
    def set_text(self, edit_token, content):
        if not self._is_view_still_open():
            return
        self.is_updating = True
        self._view_reference.set_read_only(False)
        self._view_reference.erase(edit_token, sublime.Region(0, self._view_reference.size()))
        self._view_reference.insert(edit_token, 0, content)
        self._view_reference.set_read_only(True)
        self.is_updating = False


    window = None # remember last group before close, so we can remove that exact group if empty
    group = None
    def on_pre_close(self):
        Debug('layout', 'ON_PRE_CLOSE')
        if self._is_view_still_open():

            Debug('layout', '  remember win and gr')