# Path: plugins/create_package.py
# def open_folder_in_st(path):
#     sublime.run_command('new_window')
#     new_window = sublime.active_window()
#     new_window.set_project_data({'folders': [{'path': path}]})
#     return new_window
# 
# def get_default_packages():
#     default_path = os.path.join(os.path.dirname(sublime.executable_path()), "Packages")
#     return _archived_packages_in_path(default_path)
# 
# def get_installed_packages():
#     return _archived_packages_in_path(sublime.installed_packages_path())


import glob
import logging
import os
import sublime
import sublime_plugin
from .create_package import (
    open_folder_in_st, get_default_packages, get_installed_packages,
)



__all__ = ('PackagedevOpenPackageCommand',)

OVERRIDE_SUFFIX = " [*Override*]"

logger = logging.getLogger(__name__)


def _list_normal_packages():

    pkgspath = sublime.packages_path()
    folders = glob.glob(os.path.join(pkgspath, "*/", ""))
    names = (os.path.basename(fold.strip("\\/")) for fold in folders)

    existing_packages = get_default_packages() | get_installed_packages()
    for name in names:
        yield (name, name in existing_packages)


class NameInputHandler(sublime_plugin.ListInputHandler):

    def placeholder(self):
        return "Package"

    def list_items(self):
        packages = list(sorted(_list_normal_packages()))

# Path: plugins/create_package.py
# def open_folder_in_st(path):
#     sublime.run_command('new_window')
#     new_window = sublime.active_window()
#     new_window.set_project_data({'folders': [{'path': path}]})
#     return new_window
# 
# def get_default_packages():
#     default_path = os.path.join(os.path.dirname(sublime.executable_path()), "Packages")
#     return _archived_packages_in_path(default_path)
# 
# def get_installed_packages():
#     return _archived_packages_in_path(sublime.installed_packages_path())


# Path: plugins/open_package.py
import glob
import logging
import os
import sublime
import sublime_plugin
from .create_package import (
    open_folder_in_st, get_default_packages, get_installed_packages,
)




__all__ = ('PackagedevOpenPackageCommand',)

OVERRIDE_SUFFIX = " [*Override*]"

logger = logging.getLogger(__name__)


def _list_normal_packages():

    pkgspath = sublime.packages_path()
    folders = glob.glob(os.path.join(pkgspath, "*/", ""))
    names = (os.path.basename(fold.strip("\\/")) for fold in folders)

    existing_packages = get_default_packages() | get_installed_packages()
    for name in names:
        yield (name, name in existing_packages)


class NameInputHandler(sublime_plugin.ListInputHandler):

    def placeholder(self):
        return "Package"

    def list_items(self):
        packages = list(sorted(_list_normal_packages()))

        logger.debug(packages)