Esempio n. 1
0
    def run(self, edit, external=False):
        """Run command."""

        self.external = external
        self.menu_options = []
        self.menu_callback = []
        if (
            (not external and bool(load_settings().get("show_internal", True))) or
            (external and bool(load_settings().get("show_external", True)))
        ):
            left_name = self.get_left_name()
            selections = bool(load_settings().get("use_selections", True)) and self.has_selections()
            mru_last_sel, mru_current_sel = self.get_mru_sels()
            mru_last = " [sel]" if mru_last_sel else "Tab"
            mru_current = " [sel]" if mru_current_sel else "Tab"
            for entry in self.panel_entries:
                if panel_enable_check(entry["condition"], external):
                    self.menu_options.append(
                        entry["caption"] % {
                            "file": left_name,
                            "selections": ' [sel]' if selections else 'Tab',
                            "mru_last_sel": mru_last,
                            "mru_current_sel": mru_current
                        }
                    )
                    target = self.view.window() if entry["type"] == "window" else self.view
                    args = entry.get("args", {}).copy()
                    args["external"] = external
                    self.menu_callback.append(
                        lambda t=target, e=entry, a=args: t.run_command(e["cmd"], a)
                    )
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options, self.check_selection)
        elif len(self.menu_options) == 1:
            self.check_selection(0)
Esempio n. 2
0
    def run(self, edit, external=False):
        """Run command."""

        self.external = external
        self.menu_options = []
        self.menu_callback = []
        if ((not external and bool(load_settings().get("show_internal", True)))
                or
            (external and bool(load_settings().get("show_external", True)))):
            left_name = self.get_left_name()
            selections = bool(load_settings().get(
                "use_selections", True)) and self.has_selections()
            mru_last_sel, mru_current_sel = self.get_mru_sels()
            mru_last = " [sel]" if mru_last_sel else "Tab"
            mru_current = " [sel]" if mru_current_sel else "Tab"
            for entry in self.panel_entries:
                if panel_enable_check(entry["condition"], external):
                    self.menu_options.append(
                        entry["caption"] % {
                            "file": left_name,
                            "selections": ' [sel]' if selections else 'Tab',
                            "mru_last_sel": mru_last,
                            "mru_current_sel": mru_current
                        })
                    target = self.view.window(
                    ) if entry["type"] == "window" else self.view
                    args = entry.get("args", {}).copy()
                    args["external"] = external
                    self.menu_callback.append(lambda t=target, e=entry, a=args:
                                              t.run_command(e["cmd"], a))
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options,
                                                self.check_selection)
        elif len(self.menu_options) == 1:
            self.check_selection(0)
Esempio n. 3
0
    def is_enabled(self, external=False):
        """Check if command is enabled."""

        return (
            (not external and bool(load_settings().get("show_internal", True))) or
            (external and bool(load_settings().get("show_external", True)))
        ) and bool(load_settings().get("quick_panel_commands", True))
Esempio n. 4
0
    def is_enabled(self, external=False):
        """Check if command is enabled."""

        return ((not external
                 and bool(load_settings().get("show_internal", True))) or
                (external and bool(load_settings().get("show_external", True)))
                ) and bool(load_settings().get("quick_panel_commands", True))
Esempio n. 5
0
    def is_enabled(self, external):
        """Check if command is enabled."""

        enabled = False
        if not external and bool(load_settings().get("show_internal", True)):
            enabled = True
        elif external and bool(load_settings().get("show_external", True)):
            enabled = True
        return LEFT is not None and enabled
Esempio n. 6
0
    def is_enabled(self, external):
        """Check if command is enabled."""

        enabled = False
        if not external and bool(load_settings().get("show_internal", True)):
            enabled = True
        elif external and bool(load_settings().get("show_external", True)):
            enabled = True
        return LEFT is not None and enabled
Esempio n. 7
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
Esempio n. 8
0
    def run(self, edit, external):
        """Run command."""

        self.menu_options = ["View"]
        if bool(load_settings().get("use_selections", True)):
            self.menu_options.append("Selection(s)")
        if bool(load_settings().get("use_clipboard", True)):
            self.menu_options.append("Clipboard")
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options, self.check_selection)
        else:
            self.check_selection(0)
Esempio n. 9
0
    def run(self, edit, external):
        """Run command."""

        self.menu_options = ["View"]
        if bool(load_settings().get("use_selections", True)):
            self.menu_options.append("Selection(s)")
        if bool(load_settings().get("use_clipboard", True)):
            self.menu_options.append("Clipboard")
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options,
                                                self.check_selection)
        else:
            self.check_selection(0)
Esempio n. 10
0
    def check_enabled(self, paths=[], group=-1, index=-1):
        """Check if command is enabled."""

        valid_path = get_target(
            paths, group,
            index) is not None if len(paths) or index != -1 else True
        return bool(load_settings().get("use_clipboard", True)) and valid_path
Esempio n. 11
0
    def compare(cls, inputs):
        """Compare the views."""

        diff = difflib.unified_diff(
            inputs.b1, inputs.b2,
            inputs.f1, inputs.f2,
            inputs.t1, inputs.t2,
            lineterm=''
        )
        result = u"\n".join(line for line in diff)

        if result == "":
            notify("No Difference")
            return

        use_buffer = bool(load_settings().get("use_buffer", False))

        win = sublime.active_window()
        if use_buffer:
            v = win.new_file()
            v.set_name("EasyDiff: %s -> %s (%s)" % (basename(inputs.f1), basename(inputs.f2), time.ctime()))
            v.set_scratch(True)
            v.assign_syntax('Packages/Diff/Diff.tmLanguage')
            v.run_command('append', {'characters': result})
        else:
            v = win.create_output_panel('easy_diff')
            v.assign_syntax('Packages/Diff/Diff.tmLanguage')
            v.run_command('append', {'characters': result})
            win.run_command("show_panel", {"panel": "output.easy_diff"})
Esempio n. 12
0
def basic_reload():
    global LEFT
    LEFT = None
    update_menu()
    settings = load_settings()
    settings.clear_on_change('reload_basic')
    settings.add_on_change('reload_basic', basic_reload)
    def internal_diff(self, name, **kwargs):
        """Diff with internal diff."""

        result = self.get_diff(name, **kwargs)

        if result == "":
            notify("No Difference")
            result = None

        if result is not None:
            use_buffer = bool(load_settings().get("use_buffer", False))

            win = sublime.active_window()
            if use_buffer:
                v = win.new_file()
                v.set_name("EasyDiff: %s (%s)" %
                           (self.control_type, basename(name)))
                v.set_scratch(True)
                v.assign_syntax('Packages/Diff/Diff.tmLanguage')
                v.run_command('append', {'characters': result})
            else:
                v = win.create_output_panel('easy_diff')
                v.assign_syntax('Packages/Diff/Diff.tmLanguage')
                v.run_command('append', {'characters': result})
                win.run_command("show_panel", {"panel": "output.easy_diff"})
Esempio n. 14
0
def basic_reload():
    global LEFT
    LEFT = None
    update_menu()
    settings = load_settings()
    settings.clear_on_change('reload_basic')
    settings.add_on_change('reload_basic', basic_reload)
Esempio n. 15
0
    def compare(cls, inputs):
        """Compare the views."""

        diff = difflib.unified_diff(inputs.b1,
                                    inputs.b2,
                                    inputs.f1,
                                    inputs.f2,
                                    inputs.t1,
                                    inputs.t2,
                                    lineterm='')
        result = u"\n".join(line for line in diff)

        if result == "":
            notify("No Difference")
            return

        use_buffer = bool(load_settings().get("use_buffer", False))

        win = sublime.active_window()
        if use_buffer:
            v = win.new_file()
            v.set_name(
                "EasyDiff: %s -> %s (%s)" %
                (basename(inputs.f1), basename(inputs.f2), time.ctime()))
            v.set_scratch(True)
            v.assign_syntax('Packages/Diff/Diff.tmLanguage')
            v.run_command('append', {'characters': result})
        else:
            v = win.create_output_panel('easy_diff')
            v.assign_syntax('Packages/Diff/Diff.tmLanguage')
            v.run_command('append', {'characters': result})
            win.run_command("show_panel", {"panel": "output.easy_diff"})
Esempio n. 16
0
    def run(self, external=False, paths=[], group=-1, index=-1):
        """Run command."""

        global LEFT
        self.external = external
        self.set_view(paths, group, index)
        if self.view is not None:
            if bool(load_settings().get("use_selections",
                                        True)) and self.has_selections():
                LEFT = {
                    "win_id":
                    None,
                    "view_id":
                    None,
                    "clip":
                    EasyDiffView("sel", self.get_selections(),
                                 self.get_encoding())
                }
            else:
                LEFT = {
                    "win_id": self.view.window().id(),
                    "view_id": self.view.id(),
                    "clip": None
                }
                name = self.view.file_name()
                if name is None:
                    name = "Untitled"
def refresh_menu():
    """Refresh teh menus."""

    update_menu()
    debug("refresh menu")
    settings = load_settings()
    settings.clear_on_change('reload_menu')
    settings.add_on_change('reload_menu', refresh_menu)
Esempio n. 18
0
def refresh_menu():
    """Refresh teh menus."""

    update_menu()
    debug("refresh menu")
    settings = load_settings()
    settings.clear_on_change('reload_menu')
    settings.add_on_change('reload_menu', refresh_menu)
Esempio n. 19
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
Esempio n. 20
0
    def description(self, external=False, paths=[], group=-1, index=-1):
        """Return menu description."""

        self.set_view(paths, group, index, False)
        if self.view is not None and bool(load_settings().get("use_selections", True)) and self.has_selections():
            description = "%sDiff Set Left Side [sel]" % ('' if external else 'Easy')
        else:
            description = "%sDiff Set Left Side" % ('' if external else 'Easy')
        return description
Esempio n. 21
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
                                    })
                })
Esempio n. 22
0
 def has_selections(self):
     selections = False
     if bool(load_settings().get("multi_select", False)):
         for s in self.view.sel():
             if s.size() > 0:
                 selections = True
                 break
     else:
         selections = len(self.view.sel()) == 1 and self.view.sel()[0].size() > 0
     return selections
Esempio n. 23
0
    def is_visible(self,
                   clipboard=False,
                   external=False,
                   paths=[],
                   group=-1,
                   index=-1):
        """Check if visible in menu."""

        return bool(load_settings().get("use_clipboard",
                                        True)) if clipboard else True
Esempio n. 24
0
    def run(self, edit, external=False):
        """Run command."""

        self.external = external
        self.menu_options = []
        self.menu_callback = []
        if (
            (not external and bool(load_settings().get("show_internal", True))) or
            (external and bool(load_settings().get("show_external", True)))
        ):
            left_name = self.get_left_name()
            for entry in PANEL_ENTRIES:
                if entry["condition"](self, external):
                    self.menu_options.append(entry["caption"] % {"file": left_name})
                    self.menu_callback.append(entry["cmd"])
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options, self.check_selection)
        elif len(self.menu_options) == 1:
            self.check_selection(0)
Esempio n. 25
0
 def has_selections(self):
     selections = False
     if bool(load_settings().get("multi_select", False)):
         for s in self.view.sel():
             if s.size() > 0:
                 selections = True
                 break
     else:
         selections = len(
             self.view.sel()) == 1 and self.view.sel()[0].size() > 0
     return selections
Esempio n. 26
0
    def run(self, edit, external=False):
        """Run command."""

        self.external = external
        self.menu_options = []
        self.menu_callback = []
        if ((not external and bool(load_settings().get("show_internal", True)))
                or
            (external and bool(load_settings().get("show_external", True)))):
            left_name = self.get_left_name()
            for entry in PANEL_ENTRIES:
                if entry["condition"](self, external):
                    self.menu_options.append(entry["caption"] %
                                             {"file": left_name})
                    self.menu_callback.append(entry["cmd"])
        if len(self.menu_options) > 1:
            self.view.window().show_quick_panel(self.menu_options,
                                                self.check_selection)
        elif len(self.menu_options) == 1:
            self.check_selection(0)
Esempio n. 27
0
    def description(self, external=False, paths=[], group=-1, index=-1):
        """Return menu description."""

        self.set_view(paths, group, index, False)
        if self.view is not None and bool(load_settings().get(
                "use_selections", True)) and self.has_selections():
            description = "%sDiff Set Left Side [sel]" % ('' if external else
                                                          'Easy')
        else:
            description = "%sDiff Set Left Side" % ('' if external else 'Easy')
        return description
 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)
Esempio n. 29
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
    def vc_is_enabled(self, name):
        """Check if version control command is enabled."""

        enabled = False
        if name is not None:
            try:
                enabled = (self.control_enabled and
                           (multiget(load_settings(),
                                     "skip_version_check_on_is_enabled", False)
                            or self.is_versioned(name)))
            except Exception:
                pass
        return enabled
Esempio n. 31
0
    def get_mru_sels(self):
        """Get mru sels."""

        mru_last_sel = False
        mru_current_sel = False
        if bool(load_settings().get("use_selections", True)):
            view = get_mru_view(EasyDiffListener.last)
            if self.view is not None:
                mru_last_sel = self.has_selections(view)
                view = get_mru_view(EasyDiffListener.current)
                if self.view is not None:
                    mru_current_sel = self.has_selections(view)
        return mru_last_sel, mru_current_sel
Esempio n. 32
0
    def get_mru_sels(self):
        """Get mru sels."""

        mru_last_sel = False
        mru_current_sel = False
        if bool(load_settings().get("use_selections", True)):
            view = get_mru_view(EasyDiffListener.last)
            if self.view is not None:
                mru_last_sel = self.has_selections(view)
                view = get_mru_view(EasyDiffListener.current)
                if self.view is not None:
                    mru_current_sel = self.has_selections(view)
        return mru_last_sel, mru_current_sel
Esempio n. 33
0
    def has_selections(self, view=None):
        """Check if view has a valid selection."""

        if view is None:
            view = self.view
        selections = False
        if bool(load_settings().get("multi_select", False)):
            for s in view.sel():
                if s.size() > 0:
                    selections = True
                    break
        else:
            selections = len(view.sel()) == 1 and view.sel()[0].size() > 0
        return selections
Esempio n. 34
0
 def view_has_selections(self, group=-1, index=-1):
     has_selections = False
     if index != -1:
         view = sublime.active_window().views_in_group(group)[index]
         if bool(load_settings().get("multi_select", False)):
             for sel in view.sel():
                 if sel.size() > 0:
                     has_selections = True
                     break
         else:
             has_selections = len(view.sel()) == 1 and view.sel()[0].size() > 0
     else:
         has_selections = self.has_selections()
     return has_selections
Esempio n. 35
0
    def has_selections(self, view=None):
        """Check if view has a valid selection."""

        if view is None:
            view = self.view
        selections = False
        if bool(load_settings().get("multi_select", False)):
            for s in view.sel():
                if s.size() > 0:
                    selections = True
                    break
        else:
            selections = len(view.sel()) == 1 and view.sel()[0].size() > 0
        return selections
Esempio n. 36
0
    def is_enabled(self, clipboard=False, external=False, paths=[], group=-1, index=-1):
        """Check if command is enabled."""

        if clipboard:
            enabled = (
                bool(load_settings().get("use_clipboard", True)) and
                (get_target(paths, group, index) is not None if len(paths) or index != -1 else True)
            )
        else:
            enabled = (
                LEFT is not None and
                (get_target(paths, group, index) is not None if len(paths) or index != -1 else True)
            )
        return enabled
Esempio n. 37
0
 def is_enabled(self):
     enabled = False
     name = self.view.file_name() if self.view is not None else None
     if name is not None:
         try:
             enabled = (
                 self.control_enabled and
                 (
                     multiget(load_settings(), "skip_version_check_on_is_enabled", False) or
                     self.is_versioned(name)
                 )
             )
         except:
             pass
     return enabled
    def vc_is_enabled(self, name):
        """Check if version control command is enabled."""

        enabled = False
        if name is not None:
            try:
                enabled = (
                    self.control_enabled and
                    (
                        multiget(load_settings(), "skip_version_check_on_is_enabled", False) or
                        self.is_versioned(name)
                    )
                )
            except Exception:
                pass
        return enabled
Esempio n. 39
0
    def is_enabled(self,
                   clipboard=False,
                   external=False,
                   paths=[],
                   group=-1,
                   index=-1):
        """Check if command is enabled."""

        if clipboard:
            enabled = (bool(load_settings().get("use_clipboard", True))
                       and (get_target(paths, group, index) is not None
                            if len(paths) or index != -1 else True))
        else:
            enabled = (LEFT is not None
                       and (get_target(paths, group, index) is not None
                            if len(paths) or index != -1 else True))
        return enabled
Esempio n. 40
0
    def view_has_selections(self, group=-1, index=-1):
        """Check if view has selections."""

        has_selections = False
        if index != -1:
            view = get_group_view(sublime.active_window(), group, index)
            if view is not None:
                if bool(load_settings().get("multi_select", False)):
                    for sel in view.sel():
                        if sel.size() > 0:
                            has_selections = True
                            break
                else:
                    has_selections = len(view.sel()) == 1 and view.sel()[0].size() > 0
        else:
            has_selections = self.has_selections()
        return has_selections
Esempio n. 41
0
    def run(self, external=False, paths=[], group=-1, index=-1):
        """Run command."""

        global LEFT
        self.external = external
        self.set_view(paths, group, index)
        if self.view is not None:
            if bool(load_settings().get("use_selections", True)) and self.has_selections():
                LEFT = {
                    "win_id": None, "view_id": None,
                    "clip": EasyDiffView("sel", self.get_selections(), self.get_encoding())
                }
            else:
                LEFT = {"win_id": self.view.window().id(), "view_id": self.view.id(), "clip": None}
                name = self.view.file_name()
                if name is None:
                    name = "Untitled"
Esempio n. 42
0
    def view_has_selections(self, group=-1, index=-1):
        """Check if view has selections."""

        has_selections = False
        if index != -1:
            view = get_group_view(sublime.active_window(), group, index)
            if view is not None:
                if bool(load_settings().get("multi_select", False)):
                    for sel in view.sel():
                        if sel.size() > 0:
                            has_selections = True
                            break
                else:
                    has_selections = len(
                        view.sel()) == 1 and view.sel()[0].size() > 0
        else:
            has_selections = self.has_selections()
        return has_selections
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})
                }
            )
Esempio n. 44
0
    def description(self, external=False, clipboard=False, paths=[], group=-1, index=-1):
        """Return menu description."""

        self.set_view(paths, group, index, False)
        if clipboard:
            if self.view is not None and bool(load_settings().get("use_selections", True)) and self.has_selections():
                description = "%sDiff Compare [sel] with Clipboard" % ('' if external else 'Easy')
            else:
                description = "%sDiff Compare Tab with Clipboard" % ('' if external else 'Easy')
        elif self.view is not None and self.has_selections():
            description = "%sDiff Compare [sel] with %s" % (
                '' if external else 'Easy',
                self.get_left_name()
            )
        else:
            description = "%sDiff Compare with %s" % (
                '' if external else 'Easy',
                self.get_left_name()
            )
        return description
Esempio n. 45
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)
Esempio n. 46
0
    def description(self, external=False, paths=[], group=-1, index=-1):
        """Return menu description."""

        view_l = get_mru_view(EasyDiffListener.last)
        view_c = get_mru_view(EasyDiffListener.current)
        use_selections = bool(load_settings().get("use_selections", True))
        sel_l = "Tab"
        sel_c = "Tab"

        if view_l and use_selections:
            self.view = view_l
            if self.has_selections():
                sel_l = "[sel]"
        if view_c and use_selections:
            self.view = view_c
            if self.has_selections():
                sel_c = "[sel]"
        self.view = None

        description = "%sDiff Last %s with Current %s" % ('' if external else 'Easy', sel_l, sel_c)
        return description
Esempio n. 47
0
    def description(self, external=False, paths=[], group=-1, index=-1):
        """Return menu description."""

        view_l = get_mru_view(EasyDiffListener.last)
        view_c = get_mru_view(EasyDiffListener.current)
        use_selections = bool(load_settings().get("use_selections", True))
        sel_l = "Tab"
        sel_c = "Tab"

        if view_l and use_selections:
            self.view = view_l
            if self.has_selections():
                sel_l = "[sel]"
        if view_c and use_selections:
            self.view = view_c
            if self.has_selections():
                sel_c = "[sel]"
        self.view = None

        description = "%sDiff Last %s with Current %s" % ('' if external else
                                                          'Easy', sel_l, sel_c)
        return description
    def internal_diff(self, name, **kwargs):
        result = self.get_diff(name, **kwargs)

        if result == "":
            sublime.status_message("No Difference")
            result = None

        if result is not None:
            use_buffer = bool(load_settings().get("use_buffer", False))

            win = sublime.active_window()
            if use_buffer:
                v = win.new_file()
                v.set_name("EasyDiff: %s (%s)" % (self.control_type, basename(name)))
                v.set_scratch(True)
                v.assign_syntax('Packages/Diff/Diff.tmLanguage')
                v.run_command('append', {'characters': result})
            else:
                v = win.create_output_panel('easy_diff')
                v.assign_syntax('Packages/Diff/Diff.tmLanguage')
                v.run_command('append', {'characters': result})
                win.run_command("show_panel", {"panel": "output.easy_diff"})
 def update_sidebar_menu(self):
     menus = {
         "internal": INTERNAL_SIDEBAR_MENU,
         "external": EXTERNAL_SIDEBAR_MENU,
         "svn": {
             "internal": SVN_SIDEBAR_INTERNAL_MENU,
             "external": SVN_SIDEBAR_EXTERNAL_MENU
         },
         "git": {
             "internal": GIT_SIDEBAR_INTERNAL_MENU,
             "external": GIT_SIDEBAR_EXTERNAL_MENU
         },
         "hg": {
             "internal": HG_SIDEBAR_INTERNAL_MENU,
             "external": HG_SIDEBAR_EXTERNAL_MENU
         }
     }
     if "sidebar" in self.menu_types:
         submenu = load_settings().get("submenu", [])
         self.update_menu(SIDEBAR_MENU, menus, "sidebar" in submenu)
     else:
         self.remove_menu(SIDEBAR_MENU)
 def update_tab_menu(self):
     menus = {
         "internal": INTERNAL_TAB_MENU,
         "external": EXTERNAL_TAB_MENU,
         "svn": {
             "internal": SVN_TAB_INTERNAL_MENU,
             "external": SVN_TAB_EXTERNAL_MENU
         },
         "git": {
             "internal": GIT_TAB_INTERNAL_MENU,
             "external": GIT_TAB_EXTERNAL_MENU
         },
         "hg": {
             "internal": HG_TAB_INTERNAL_MENU,
             "external": HG_TAB_EXTERNAL_MENU
         }
     }
     if "tab" in self.menu_types:
         submenu = load_settings().get("submenu", [])
         self.update_menu(TAB_MENU, menus, "tab" in submenu)
     else:
         self.remove_menu(TAB_MENU)
 def update_context_menu(self):
     menus = {
         "internal": INTERNAL_MENU,
         "external": EXTERNAL_MENU,
         "svn": {
             "internal": SVN_INTERNAL_MENU,
             "external": SVN_EXTERNAL_MENU
         },
         "git": {
             "internal": GIT_INTERNAL_MENU,
             "external": GIT_EXTERNAL_MENU
         },
         "hg": {
             "internal": HG_INTERNAL_MENU,
             "external": HG_EXTERNAL_MENU
         }
     }
     if "view" in self.menu_types:
         submenu = load_settings().get("submenu", [])
         self.update_menu(CONTEXT_MENU, menus, "view" in submenu)
     else:
         self.remove_menu(CONTEXT_MENU)
Esempio n. 52
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 setup_vc_binaries():
    """Setup version control binaries."""

    global SVN_ENABLED
    global GIT_ENABLED
    global HG_ENABLED

    settings = load_settings()
    svn_path = multiget(settings, "svn", None)
    git_path = multiget(settings, "git", None)
    hg_path = multiget(settings, "hg", None)
    if svn_path is not None and svn_path != "":
        svn.set_svn_path(svn_path)
        SVN_ENABLED = None
    if git_path is not None and git_path != "":
        git.set_git_path(git_path)
        GIT_ENABLED = None
    if hg_path is not None and hg_path != "":
        hg.set_hg_path(hg_path)
        HG_ENABLED = None

    settings.clear_on_change('reload_vc')
    settings.add_on_change('reload_vc', setup_vc_binaries)
Esempio n. 54
0
def setup_vc_binaries():
    global SVN_ENABLED
    global GIT_ENABLED
    global HG_ENABLED

    settings = load_settings()
    svn_path = multiget(settings, "svn", None)
    git_path = multiget(settings, "git", None)
    hg_path = multiget(settings, "hg", None)
    if svn_path is not None and svn_path != "":
        svn.set_svn_path(svn_path)
    if git_path is not None and git_path != "":
        git.set_git_path(git_path)
    if hg_path is not None and hg_path != "":
        hg.set_hg_path(hg_path)

    try:
        log("svn %s" % svn.version())
        SVN_ENABLED = True
    except:
        log("svn not found or is not working!")
        pass
    try:
        log("git %s" % git.version())
        GIT_ENABLED = True
    except:
        log("git not found or is not working!")
        pass
    try:
        log("hg %s" % hg.version())
        HG_ENABLED = True
    except:
        log("hg not found or is not working!")
        pass

    settings.clear_on_change('reload_vc')
    settings.add_on_change('reload_vc', setup_vc_binaries)
Esempio n. 55
0
    def update_sidebar_menu(self):
        """Update the sidebar menu."""

        menus = {
            "internal": INTERNAL_SIDEBAR_MENU,
            "external": EXTERNAL_SIDEBAR_MENU,
            "svn": {
                "internal": SVN_SIDEBAR_INTERNAL_MENU,
                "external": SVN_SIDEBAR_EXTERNAL_MENU
            },
            "git": {
                "internal": GIT_SIDEBAR_INTERNAL_MENU,
                "external": GIT_SIDEBAR_EXTERNAL_MENU
            },
            "hg": {
                "internal": HG_SIDEBAR_INTERNAL_MENU,
                "external": HG_SIDEBAR_EXTERNAL_MENU
            }
        }
        if "sidebar" in self.menu_types:
            submenu = load_settings().get("submenu", [])
            self.update_menu(SIDEBAR_MENU, menus, "sidebar" in submenu)
        else:
            self.remove_menu(SIDEBAR_MENU)
Esempio n. 56
0
    def update_tab_menu(self):
        """Update tab menu."""

        menus = {
            "internal": INTERNAL_TAB_MENU,
            "external": EXTERNAL_TAB_MENU,
            "svn": {
                "internal": SVN_TAB_INTERNAL_MENU,
                "external": SVN_TAB_EXTERNAL_MENU
            },
            "git": {
                "internal": GIT_TAB_INTERNAL_MENU,
                "external": GIT_TAB_EXTERNAL_MENU
            },
            "hg": {
                "internal": HG_TAB_INTERNAL_MENU,
                "external": HG_TAB_EXTERNAL_MENU
            }
        }
        if "tab" in self.menu_types:
            submenu = load_settings().get("submenu", [])
            self.update_menu(TAB_MENU, menus, "tab" in submenu)
        else:
            self.remove_menu(TAB_MENU)
Esempio n. 57
0
    def description(self,
                    external=False,
                    clipboard=False,
                    paths=[],
                    group=-1,
                    index=-1):
        """Return menu description."""

        self.set_view(paths, group, index, False)
        if clipboard:
            if self.view is not None and bool(load_settings().get(
                    "use_selections", True)) and self.has_selections():
                description = "%sDiff Compare [sel] with Clipboard" % (
                    '' if external else 'Easy')
            else:
                description = "%sDiff Compare Tab with Clipboard" % (
                    '' if external else 'Easy')
        elif self.view is not None and self.has_selections():
            description = "%sDiff Compare [sel] with %s" % (
                '' if external else 'Easy', self.get_left_name())
        else:
            description = "%sDiff Compare with %s" % (
                '' if external else 'Easy', self.get_left_name())
        return description