# Path: meld/vc/_vc.py
# (STATE_IGNORED, STATE_NONE, STATE_NORMAL, STATE_NOCHANGE,
#     STATE_ERROR, STATE_EMPTY, STATE_NEW,
#     STATE_MODIFIED, STATE_RENAMED, STATE_CONFLICT, STATE_REMOVED,
#     STATE_MISSING, STATE_NONEXIST, STATE_SPINNER, STATE_MAX) = list(range(15))
# (CONFLICT_MERGED, CONFLICT_BASE, CONFLICT_LOCAL,
#     CONFLICT_REMOTE, CONFLICT_MAX) = list(range(5))
# CONFLICT_OTHER = CONFLICT_REMOTE
# CONFLICT_THIS = CONFLICT_LOCAL
#     VC_DIR: ClassVar[str]
#     VC_ROOT_WALK: ClassVar[bool] = True
# def partition(pred, iterable):
#     def __init__(self, path, name, state, isdir, options=None):
#     def __str__(self):
#     def __repr__(self):
#     def get_status(self):
#     def is_present(self):
#     def is_modified(entry):
#     def is_normal(entry):
#     def is_nonvc(entry):
#     def is_ignored(entry):
#     def __init__(self, path):
#     def run(self, *args, use_locale_encoding=True):
#     def get_files_to_commit(self, paths):
#     def get_commit_message_prefill(self):
#     def get_commits_to_push_summary(self):
#     def get_valid_actions(self, path_states):
#     def get_path_for_repo_file(self, path, commit=None):
#     def get_path_for_conflict(self, path, conflict):
#     def refresh_vc_state(self, path=None):
#     def get_entries(self, base):
#     def _add_missing_cache_entry(self, path, state):
#     def get_entry(self, path):
#     def is_installed(cls):
#     def is_in_repo(cls, path):
#     def check_repo_root(cls, location):
#     def find_repo_root(cls, location):
#     def valid_repo(cls, path):
#     def __init__(self, vc, path, err):
#     def __str__(self):
#     def __init__(self, vc, rev, err):
#     def __str__(self):
# def popen(cmd, cwd=None, use_locale_encoding=True):
# def call_temp_output(cmd, cwd, file_id='', suffix=None):
# def call(cmd, cwd=None):
# def base_from_diff3(merged):
# class Entry:
# class Vc:
# class InvalidVCPath(ValueError):
# class InvalidVCRevision(ValueError):


import os
from gi.module import get_introspection_module
from gi.repository import Gdk, GLib, GObject, Pango
from meld.style import colour_lookup_with_fallback
from meld.treehelpers import SearchableTreeStore
from meld.vc._vc import (  # noqa: F401
    CONFLICT_BASE,
    CONFLICT_LOCAL,
    CONFLICT_MERGED,
    CONFLICT_OTHER,
    CONFLICT_REMOTE,
    CONFLICT_THIS,
    STATE_CONFLICT,
    STATE_EMPTY,
    STATE_ERROR,
    STATE_IGNORED,
    STATE_MAX,
    STATE_MISSING,
    STATE_MODIFIED,
    STATE_NEW,
    STATE_NOCHANGE,
    STATE_NONE,
    STATE_NONEXIST,
    STATE_NORMAL,
    STATE_REMOVED,
    STATE_SPINNER,
)

COL_TYPES = (str, str, str, str, Gdk.RGBA, Gdk.RGBA, Pango.Style,
             Pango.Weight, bool)


class DiffTreeStore(SearchableTreeStore):

    def __init__(self, ntree, types):
        full_types = []
        for col_type in (COL_TYPES + tuple(types)):
            full_types.extend([col_type] * ntree)
        super().__init__(*full_types)
        self._none_of_cols = {
            col_num: GObject.Value(col_type, None)
            for col_num, col_type in enumerate(full_types)
        }
        self.ntree = ntree
        self._setup_default_styles()

    def on_style_updated(self, widget):
        style = widget.get_style_context()
        self._setup_default_styles(style)

    def _setup_default_styles(self, style=None):
        roman, italic = Pango.Style.NORMAL, Pango.Style.ITALIC
        normal, bold = Pango.Weight.NORMAL, Pango.Weight.BOLD

        lookup = colour_lookup_with_fallback
        unk_fg = lookup("meld:unknown-text", "foreground")
        new_fg = lookup("meld:insert", "foreground")

# Path: meld/vc/_vc.py
# (STATE_IGNORED, STATE_NONE, STATE_NORMAL, STATE_NOCHANGE,
#     STATE_ERROR, STATE_EMPTY, STATE_NEW,
#     STATE_MODIFIED, STATE_RENAMED, STATE_CONFLICT, STATE_REMOVED,
#     STATE_MISSING, STATE_NONEXIST, STATE_SPINNER, STATE_MAX) = list(range(15))
# (CONFLICT_MERGED, CONFLICT_BASE, CONFLICT_LOCAL,
#     CONFLICT_REMOTE, CONFLICT_MAX) = list(range(5))
# CONFLICT_OTHER = CONFLICT_REMOTE
# CONFLICT_THIS = CONFLICT_LOCAL
#     VC_DIR: ClassVar[str]
#     VC_ROOT_WALK: ClassVar[bool] = True
# def partition(pred, iterable):
#     def __init__(self, path, name, state, isdir, options=None):
#     def __str__(self):
#     def __repr__(self):
#     def get_status(self):
#     def is_present(self):
#     def is_modified(entry):
#     def is_normal(entry):
#     def is_nonvc(entry):
#     def is_ignored(entry):
#     def __init__(self, path):
#     def run(self, *args, use_locale_encoding=True):
#     def get_files_to_commit(self, paths):
#     def get_commit_message_prefill(self):
#     def get_commits_to_push_summary(self):
#     def get_valid_actions(self, path_states):
#     def get_path_for_repo_file(self, path, commit=None):
#     def get_path_for_conflict(self, path, conflict):
#     def refresh_vc_state(self, path=None):
#     def get_entries(self, base):
#     def _add_missing_cache_entry(self, path, state):
#     def get_entry(self, path):
#     def is_installed(cls):
#     def is_in_repo(cls, path):
#     def check_repo_root(cls, location):
#     def find_repo_root(cls, location):
#     def valid_repo(cls, path):
#     def __init__(self, vc, path, err):
#     def __str__(self):
#     def __init__(self, vc, rev, err):
#     def __str__(self):
# def popen(cmd, cwd=None, use_locale_encoding=True):
# def call_temp_output(cmd, cwd, file_id='', suffix=None):
# def call(cmd, cwd=None):
# def base_from_diff3(merged):
# class Entry:
# class Vc:
# class InvalidVCPath(ValueError):
# class InvalidVCRevision(ValueError):


# Path: meld/tree.py
import os
from gi.module import get_introspection_module
from gi.repository import Gdk, GLib, GObject, Pango
from meld.style import colour_lookup_with_fallback
from meld.treehelpers import SearchableTreeStore
from meld.vc._vc import (  # noqa: F401
    CONFLICT_BASE,
    CONFLICT_LOCAL,
    CONFLICT_MERGED,
    CONFLICT_OTHER,
    CONFLICT_REMOTE,
    CONFLICT_THIS,
    STATE_CONFLICT,
    STATE_EMPTY,
    STATE_ERROR,
    STATE_IGNORED,
    STATE_MAX,
    STATE_MISSING,
    STATE_MODIFIED,
    STATE_NEW,
    STATE_NOCHANGE,
    STATE_NONE,
    STATE_NONEXIST,
    STATE_NORMAL,
    STATE_REMOVED,
    STATE_SPINNER,
)


COL_TYPES = (str, str, str, str, Gdk.RGBA, Gdk.RGBA, Pango.Style,
             Pango.Weight, bool)


class DiffTreeStore(SearchableTreeStore):

    def __init__(self, ntree, types):
        full_types = []
        for col_type in (COL_TYPES + tuple(types)):
            full_types.extend([col_type] * ntree)
        super().__init__(*full_types)
        self._none_of_cols = {
            col_num: GObject.Value(col_type, None)
            for col_num, col_type in enumerate(full_types)
        }
        self.ntree = ntree
        self._setup_default_styles()

    def on_style_updated(self, widget):
        style = widget.get_style_context()
        self._setup_default_styles(style)

    def _setup_default_styles(self, style=None):
        roman, italic = Pango.Style.NORMAL, Pango.Style.ITALIC
        normal, bold = Pango.Weight.NORMAL, Pango.Weight.BOLD

        lookup = colour_lookup_with_fallback
        unk_fg = lookup("meld:unknown-text", "foreground")
        new_fg = lookup("meld:insert", "foreground")

        mod_fg = lookup("meld:replace", "foreground")