Beispiel #1
0
def panel_enable_check(method="view", external=False):
    """Check if panel command can be enabled."""

    allow = bool(load_settings().get("last_activated_commands", True))
    enabled = False
    if method == "left":
        enabled = bool(load_settings().get("quick_panel_left_right_commands",
                                           True))
    elif method == "compare":
        enabled = (LEFT is not None and bool(load_settings().get(
            "quick_panel_left_right_commands", True)))
    elif method == "mru":
        current = get_mru_view(EasyDiffListener.current)
        last = get_mru_view(EasyDiffListener.last)
        enabled = (allow and bool(current and last))
    elif method == "clipboard":
        enabled = (bool(load_settings().get("use_clipboard", True))
                   and bool(get_mru_view(EasyDiffListener.current)))
    elif method == "svn":
        enabled = not bool(load_settings().get("svn_disabled", False))
    elif method == "git":
        enabled = not bool(load_settings().get("git_disabled", False))
    elif method == "hg":
        enabled = not bool(load_settings().get("hg_disabled", False))

    if external:
        enabled = (enabled and bool(load_settings().get("show_external", True))
                   and get_external_diff() is not None)
    else:
        enabled = (enabled
                   and bool(load_settings().get("show_internal", True)))
    return enabled
Beispiel #2
0
    def enable_check(method="view", external=False):
        """Enable check."""

        allow = bool(load_settings().get("last_activated_commands", True))
        enabled = False
        if method == "view":
            enabled = (allow and bool(EasyDiffListener.current
                                      and EasyDiffListener.last))
        elif method == "selection":
            enabled = (allow
                       and bool(load_settings().get("use_selections", True))
                       and bool(EasyDiffListener.current
                                and EasyDiffListener.last))
        elif method == "clipboard":
            enabled = (allow
                       and bool(load_settings().get("use_clipboard", True))
                       and bool(EasyDiffListener.last))
        elif method == "clipboard_selection":
            enabled = (allow
                       and bool(load_settings().get("use_clipboard", True))
                       and bool(load_settings().get("use_selections", True))
                       and bool(EasyDiffListener.last))
        if external:
            enabled = (enabled
                       and bool(load_settings().get("show_external", True))
                       and get_external_diff() is not None)
        else:
            enabled = (enabled
                       and bool(load_settings().get("show_internal", True)))
        return enabled
    def external_diff(self, name, **kwargs):
        """Diff with external diff command."""

        self.create_temp()
        f1, f2 = self.get_files(name, **kwargs)
        ext_diff = get_external_diff()
        if f1 is not None and f2 is not None:
            subprocess.Popen([ext_diff, f1, f2])
Beispiel #4
0
def update_menu(name="..."):
    menu_path = join(sublime.packages_path(), "User", MENU_FOLDER)
    if not exists(menu_path):
        makedirs(menu_path)
    if exists(menu_path):
        settings = load_settings()
        svn_disabled = multiget(settings, "svn_disabled", False) or multiget(
            settings, "svn_hide_menu", False)
        git_disabled = multiget(settings, "git_disabled", False) or multiget(
            settings, "git_hide_menu", False)
        hg_disabled = multiget(settings, "hg_disabled", False) or multiget(
            settings, "hg_hide_menu", False)
        show_ext = multiget(settings, "show_external",
                            False) and get_external_diff() is not None
        show_int = multiget(settings, "show_internal", True)
        menu = join(menu_path, CONTEXT_MENU)
        vc_internal = []
        vc_internal_menu = None
        if show_int:
            if not svn_disabled:
                vc_internal.append(SVN_INTERNAL_MENU)
            if not git_disabled:
                vc_internal.append(GIT_INTERNAL_MENU)
            if not hg_disabled:
                vc_internal.append(HG_INTERNAL_MENU)
            if len(vc_internal):
                vc_internal_menu = ",\n".join(vc_internal)
        vc_external = []
        vc_external_menu = None
        if show_ext:
            if not svn_disabled:
                vc_external.append(SVN_EXTERNAL_MENU)
            if not git_disabled:
                vc_external.append(GIT_EXTERNAL_MENU)
            if not hg_disabled:
                vc_external.append(HG_EXTERNAL_MENU)
            if len(vc_external):
                vc_external_menu = ",\n".join(vc_external)
        with open(menu, "w") as f:
            f.write(
                DIFF_MENU % {
                    "internal": ("" if not show_int else INTERNAL_MENU % {
                        "file_name": name
                    }),
                    "external": ("" if not show_ext else EXTERNAL_MENU % {
                        "file_name": name
                    }),
                    "vc_internal": ("" if vc_internal_menu is None
                                    or not show_int else VC_INTERNAL_MENU % {
                                        "vc": vc_internal_menu
                                    }),
                    "vc_external": ("" if vc_external_menu is None
                                    or not show_ext else VC_EXTERNAL_MENU % {
                                        "vc": vc_external_menu
                                    })
                })
 def __init__(self, name):
     self.name = name
     self.menu_path = join(sublime.packages_path(), "User", MENU_FOLDER)
     if not exists(self.menu_path):
         makedirs(self.menu_path)
     settings = load_settings()
     self.menu_types = multiget(settings, "menu_types", [])
     self.svn_disabled = multiget(settings, "svn_disabled", False) or multiget(settings, "svn_hide_menu", False)
     self.git_disabled = multiget(settings, "git_disabled", False) or multiget(settings, "git_hide_menu", False)
     self.hg_disabled = multiget(settings, "hg_disabled", False) or multiget(settings, "hg_hide_menu", False)
     self.show_ext = multiget(settings, "show_external", False) and get_external_diff() is not None
     self.show_int = multiget(settings, "show_internal", True)
Beispiel #6
0
 def external_diff(self, name, **kwargs):
     self.create_temp()
     f1, f2 = self.get_files(name, **kwargs)
     ext_diff = get_external_diff()
     debug(f1)
     debug(f2)
     if f1 is not None and f2 is not None:
         subprocess.Popen(
             [
                 ext_diff,
                 f1,
                 f2
             ]
         )
    def external_diff(self, name, **kwargs):
        """Diff with external diff command."""

        self.create_temp()
        f1, f2 = self.get_files(name, **kwargs)
        ext_diff = get_external_diff()
        if f1 is not None and f2 is not None:
            subprocess.Popen(
                [
                    ext_diff,
                    f1,
                    f2
                ]
            )
Beispiel #8
0
def diff(left, right, external=False):
    """
    Initiate diff by getting left side and right side compare.

    Call the appropriate diff method and call internal or external diff.
    """

    lw = None
    rw = None
    lv = None
    rv = None

    for w in sublime.windows():
        if w.id() == left["win_id"]:
            lw = w
        if w.id() == right["win_id"]:
            rw = w
        if lw is not None and rw is not None:
            break

    if lw is not None:
        for v in lw.views():
            if v.id() == left["view_id"]:
                lv = v
                break
    else:
        if left["clip"]:
            lv = left["clip"]

    if rw is not None:
        for v in rw.views():
            if v.id() == right["view_id"]:
                rv = v
                break
    else:
        if right["clip"]:
            rv = right["clip"]

    if lv is not None and rv is not None:
        ext_diff = get_external_diff()
        if external:
            EasyDiff.extcompare(EasyDiffInput(lv, rv, external=True), ext_diff)
        else:
            EasyDiff.compare(EasyDiffInput(lv, rv))
    else:
        log("Can't compare")
def diff(left, right, external=False):
    """
    Initiate diff by getting left side and right side compare.

    Call the appropriate diff method and call internal or external diff.
    """

    lw = None
    rw = None
    lv = None
    rv = None

    for w in sublime.windows():
        if w.id() == left["win_id"]:
            lw = w
        if w.id() == right["win_id"]:
            rw = w
        if lw is not None and rw is not None:
            break

    if lw is not None:
        for v in lw.views():
            if v.id() == left["view_id"]:
                lv = v
                break
    else:
        if left["clip"]:
            lv = left["clip"]

    if rw is not None:
        for v in rw.views():
            if v.id() == right["view_id"]:
                rv = v
                break
    else:
        if right["clip"]:
            rv = right["clip"]

    if lv is not None and rv is not None:
        ext_diff = get_external_diff()
        if external:
            EasyDiff.extcompare(EasyDiffInput(lv, rv, external=True), ext_diff)
        else:
            EasyDiff.compare(EasyDiffInput(lv, rv))
    else:
        log("Can't compare")
def panel_enable_check(method="view", external=False):
    """Check if panel command can be enabled."""

    allow = bool(load_settings().get("last_activated_commands", True))
    enabled = False
    if method == "left":
        enabled = bool(
            load_settings().get("quick_panel_left_right_commands", True)
        )
    elif method == "compare":
        enabled = (
            LEFT is not None and
            bool(load_settings().get("quick_panel_left_right_commands", True))
        )
    elif method == "mru":
        current = get_mru_view(EasyDiffListener.current)
        last = get_mru_view(EasyDiffListener.last)
        enabled = (
            allow and
            bool(current and last)
        )
    elif method == "clipboard":
        enabled = (
            bool(load_settings().get("use_clipboard", True)) and
            bool(get_mru_view(EasyDiffListener.current))
        )
    elif method == "svn":
        enabled = not bool(load_settings().get("svn_disabled", False))
    elif method == "git":
        enabled = not bool(load_settings().get("git_disabled", False))
    elif method == "hg":
        enabled = not bool(load_settings().get("hg_disabled", False))

    if external:
        enabled = (
            enabled and
            bool(load_settings().get("show_external", True)) and
            get_external_diff() is not None
        )
    else:
        enabled = (
            enabled and
            bool(load_settings().get("show_internal", True))
        )
    return enabled
def update_menu(name="..."):
    menu_path = join(sublime.packages_path(), "User", MENU_FOLDER)
    if not exists(menu_path):
        makedirs(menu_path)
    if exists(menu_path):
        settings = load_settings()
        svn_disabled = multiget(settings, "svn_disabled", False) or multiget(settings, "svn_hide_menu", False)
        git_disabled = multiget(settings, "git_disabled", False) or multiget(settings, "git_hide_menu", False)
        hg_disabled = multiget(settings, "hg_disabled", False) or multiget(settings, "hg_hide_menu", False)
        show_ext = multiget(settings, "show_external", False) and get_external_diff() is not None
        show_int = multiget(settings, "show_internal", True)
        menu = join(menu_path, CONTEXT_MENU)
        vc_internal = []
        vc_internal_menu = None
        if show_int:
            if not svn_disabled:
                vc_internal.append(SVN_INTERNAL_MENU)
            if not git_disabled:
                vc_internal.append(GIT_INTERNAL_MENU)
            if not hg_disabled:
                vc_internal.append(HG_INTERNAL_MENU)
            if len(vc_internal):
                vc_internal_menu = ",\n".join(vc_internal)
        vc_external = []
        vc_external_menu = None
        if show_ext:
            if not svn_disabled:
                vc_external.append(SVN_EXTERNAL_MENU)
            if not git_disabled:
                vc_external.append(GIT_EXTERNAL_MENU)
            if not hg_disabled:
                vc_external.append(HG_EXTERNAL_MENU)
            if len(vc_external):
                vc_external_menu = ",\n".join(vc_external)
        with open(menu, "w") as f:
            f.write(
                DIFF_MENU % {
                    "internal": ("" if not show_int else INTERNAL_MENU % {"file_name": name}),
                    "external": ("" if not show_ext else EXTERNAL_MENU % {"file_name": name}),
                    "vc_internal": ("" if vc_internal_menu is None or not show_int else VC_INTERNAL_MENU % {"vc": vc_internal_menu}),
                    "vc_external": ("" if vc_external_menu is None or not show_ext else VC_EXTERNAL_MENU % {"vc": vc_external_menu})
                }
            )
    def run(self, edit, external=False):
        self.set_right()

        lw = None
        rw = None
        lv = None
        rv = None

        for w in sublime.windows():
            if w.id() == LEFT["win_id"]:
                lw = w
            if w.id() == self.right["win_id"]:
                rw = w
            if lw is not None and rw is not None:
                break

        if lw is not None:
            for v in lw.views():
                if v.id() == LEFT["view_id"]:
                    lv = v
                    break
        else:
            if LEFT["clip"]:
                lv = LEFT["clip"]

        if rw is not None:
            for v in rw.views():
                if v.id() == self.right["view_id"]:
                    rv = v
                    break
        else:
            if self.right["clip"]:
                rv = self.right["clip"]

        if lv is not None and rv is not None:
            ext_diff = get_external_diff()
            if external:
                EasyDiff.extcompare(EasyDiffInput(lv, rv, external=True),
                                    ext_diff)
            else:
                EasyDiff.compare(EasyDiffInput(lv, rv))
        else:
            log("Can't compare")
    def run(self, edit, external=False):
        self.set_right()

        lw = None
        rw = None
        lv = None
        rv = None

        for w in sublime.windows():
            if w.id() == LEFT["win_id"]:
                lw = w
            if w.id() == self.right["win_id"]:
                rw = w
            if lw is not None and rw is not None:
                break

        if lw is not None:
            for v in lw.views():
                if v.id() == LEFT["view_id"]:
                    lv = v
                    break
        else:
            if LEFT["clip"]:
                lv = LEFT["clip"]

        if rw is not None:
            for v in rw.views():
                if v.id() == self.right["view_id"]:
                    rv = v
                    break
        else:
            if self.right["clip"]:
                rv = self.right["clip"]

        if lv is not None and rv is not None:
            ext_diff = get_external_diff()
            if external:
                EasyDiff.extcompare(EasyDiffInput(lv, rv, external=True), ext_diff)
            else:
                EasyDiff.compare(EasyDiffInput(lv, rv))
        else:
            log("Can't compare")
Beispiel #14
0
    def enable_check(method="view", external=False):
        """Enable check."""

        allow = bool(load_settings().get("last_activated_commands", True))
        enabled = False
        if method == "view":
            enabled = (
                allow and
                bool(EasyDiffListener.current and EasyDiffListener.last)
            )
        elif method == "selection":
            enabled = (
                allow and
                bool(load_settings().get("use_selections", True)) and
                bool(EasyDiffListener.current and EasyDiffListener.last)
            )
        elif method == "clipboard":
            enabled = (
                allow and
                bool(load_settings().get("use_clipboard", True)) and
                bool(EasyDiffListener.last)
            )
        elif method == "clipboard_selection":
            enabled = (
                allow and
                bool(load_settings().get("use_clipboard", True)) and
                bool(load_settings().get("use_selections", True)) and
                bool(EasyDiffListener.last)
            )
        if external:
            enabled = (
                enabled and
                bool(load_settings().get("show_external", True)) and
                get_external_diff() is not None
            )
        else:
            enabled = (
                enabled and
                bool(load_settings().get("show_internal", True))
            )
        return enabled
Beispiel #15
0
    def __init__(self, name):
        """Initialize."""

        self.name = name
        self.menu_path = join(sublime.packages_path(), "User", MENU_FOLDER)
        if not exists(self.menu_path):
            makedirs(self.menu_path)
        settings = load_settings()
        self.menu_types = multiget(settings, "menu_types", [])
        self.svn_disabled = multiget(settings, "svn_disabled",
                                     False) or multiget(
                                         settings, "svn_hide_menu", False)
        self.git_disabled = multiget(settings, "git_disabled",
                                     False) or multiget(
                                         settings, "git_hide_menu", False)
        self.hg_disabled = multiget(settings,
                                    "hg_disabled", False) or multiget(
                                        settings, "hg_hide_menu", False)
        self.show_ext = multiget(settings, "show_external",
                                 False) and get_external_diff() is not None
        self.show_int = multiget(settings, "show_internal", True)