# 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()
# 
# Path: lib/utils/pathutils.py
# def add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# Path: lib/utils/disabling.py
# def set_plugin_temporarily_disabled(folder=None):
#     """ Enables the plugin globally or for folder.
#         Folder can be a view """
#     if folder is None:
#         if not is_plugin_globally_disabled():
#             plugin_disabled_for_folders.append("*global")
#     else:
#         if isinstance(folder, sublime.View):
#             folder = os.path.dirname(folder.file_name())
#         folder = os.path.normcase(folder)
#         Debug('project', 'Disable ArcticTypescript for %s' % folder)
#         if folder not in plugin_disabled_for_folders:
#             plugin_disabled_for_folders.append(folder)
# 
# def set_plugin_temporarily_enabled(folder=None):
#     """ Disables the plugin globally or for folder.
#         Folder can be a view """
#     if folder is None:
#         if is_plugin_globally_disabled():
#             plugin_disabled_for_folders.remove("*global")
#     else:
#         if isinstance(folder, sublime.View):
#             folder = os.path.dirname(folder.file_name())
#         folder = os.path.normcase(folder)
#         Debug('project', 'Enable ArcticTypescript for %s' % folder)
#         if folder in plugin_disabled_for_folders:
#             plugin_disabled_for_folders.remove(folder)
# 
# def is_plugin_temporarily_disabled(folder=None):
#     """ Returns True if the plugin is disabled globally or for folder.
#         Folder can be a view """
#     if is_plugin_globally_disabled() or folder is None:
#         return is_plugin_globally_disabled()
#     if folder is not None and isinstance(folder, sublime.View):
#         if folder.file_name() is None:
#             return is_plugin_globally_disabled()
#         folder = os.path.dirname(folder.file_name())
#     folder = os.path.normcase(folder)
#     return folder in plugin_disabled_for_folders


import sublime
import json
import os
from ..utils import package_path, Debug
from ..utils.disabling import set_plugin_temporarily_disabled, \
                               set_plugin_temporarily_enabled, \
                               is_plugin_temporarily_disabled

    def _finish(self):
        """ make and write tsconfig.json. Call finished_callback """
        Debug('project+', 'Wizzard finished: Create and write tsconfig.json')
        content = { "compilerOptions" : {}, "files" : {}}
        if self.module is None:
            content['compilerOptions']['out'] = self.outfile
            content['compilerOptions']['target'] = self.target
            content['compilerOptions']['sourceMap'] = self.sourcemap
        elif self.module == "commonjs" or self.module == "amd":
            content['compilerOptions']['outDir'] = self.outdir
            content['compilerOptions']['target'] = self.target
            content['compilerOptions']['sourceMap'] = self.sourcemap
            content['compilerOptions']['module'] = self.module

        content['files'] = self.files

        self.write_json_to_tsconfigfile(content)

        if self.finished_callback:
            self.finished_callback()

        sublime.active_window().open_file(self.tspath)
        sublime.message_dialog("For more compilerOptions, see tsc --help.\n\n To configure ArcticTypescript, see README.md")

        self._cleanup()


    def _cleanup(self):
        Debug('project+', 'Enable ArcticTypescript again')

# 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()
# 
# Path: lib/utils/pathutils.py
# def add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# Path: lib/utils/disabling.py
# def set_plugin_temporarily_disabled(folder=None):
#     """ Enables the plugin globally or for folder.
#         Folder can be a view """
#     if folder is None:
#         if not is_plugin_globally_disabled():
#             plugin_disabled_for_folders.append("*global")
#     else:
#         if isinstance(folder, sublime.View):
#             folder = os.path.dirname(folder.file_name())
#         folder = os.path.normcase(folder)
#         Debug('project', 'Disable ArcticTypescript for %s' % folder)
#         if folder not in plugin_disabled_for_folders:
#             plugin_disabled_for_folders.append(folder)
# 
# def set_plugin_temporarily_enabled(folder=None):
#     """ Disables the plugin globally or for folder.
#         Folder can be a view """
#     if folder is None:
#         if is_plugin_globally_disabled():
#             plugin_disabled_for_folders.remove("*global")
#     else:
#         if isinstance(folder, sublime.View):
#             folder = os.path.dirname(folder.file_name())
#         folder = os.path.normcase(folder)
#         Debug('project', 'Enable ArcticTypescript for %s' % folder)
#         if folder in plugin_disabled_for_folders:
#             plugin_disabled_for_folders.remove(folder)
# 
# def is_plugin_temporarily_disabled(folder=None):
#     """ Returns True if the plugin is disabled globally or for folder.
#         Folder can be a view """
#     if is_plugin_globally_disabled() or folder is None:
#         return is_plugin_globally_disabled()
#     if folder is not None and isinstance(folder, sublime.View):
#         if folder.file_name() is None:
#             return is_plugin_globally_disabled()
#         folder = os.path.dirname(folder.file_name())
#     folder = os.path.normcase(folder)
#     return folder in plugin_disabled_for_folders


# Path: lib/system/ProjectWizzard.py
import sublime
import json
import os
from ..utils import package_path, Debug
from ..utils.disabling import set_plugin_temporarily_disabled, \
                               set_plugin_temporarily_enabled, \
                               is_plugin_temporarily_disabled


    def _finish(self):
        """ make and write tsconfig.json. Call finished_callback """
        Debug('project+', 'Wizzard finished: Create and write tsconfig.json')
        content = { "compilerOptions" : {}, "files" : {}}
        if self.module is None:
            content['compilerOptions']['out'] = self.outfile
            content['compilerOptions']['target'] = self.target
            content['compilerOptions']['sourceMap'] = self.sourcemap
        elif self.module == "commonjs" or self.module == "amd":
            content['compilerOptions']['outDir'] = self.outdir
            content['compilerOptions']['target'] = self.target
            content['compilerOptions']['sourceMap'] = self.sourcemap
            content['compilerOptions']['module'] = self.module

        content['files'] = self.files

        self.write_json_to_tsconfigfile(content)

        if self.finished_callback:
            self.finished_callback()

        sublime.active_window().open_file(self.tspath)
        sublime.message_dialog("For more compilerOptions, see tsc --help.\n\n To configure ArcticTypescript, see README.md")

        self._cleanup()


    def _cleanup(self):
        Debug('project+', 'Enable ArcticTypescript again')

        set_plugin_temporarily_enabled()