示例#1
0
    def handleURL(self, url):
        """handleUrl - user clicked an URL / UNL link

        :param str url: URL for link
        """
        g.es(url)
        # UNL detection copied from g.handleUrl()
        if (
            url.lower().startswith('unl:' + '//') or
            url.lower().startswith('file://') and url.find('-->') > -1 or
            url.startswith('#')
        ):
            our_unl = 'unl://'+self.c.p.get_UNL(with_index=False)
            # don't use .get_UNL(with_proto=True), that
            # unecessarily does ' ' -> %20 conversion
            new_c = g.handleUnl(url, self.c)
            if new_c and hasattr(new_c, 'backlinkController'):
                unl = url.replace('%20', ' ').split('#', 1)[-1].split('-->')
                found, _, new_p = g.recursiveUNLFind(unl, new_c)
                if not found:
                    g.es("No perfect match, not creating backlink")
                    return
                new_c.backlinkController.initBacklink(new_p.v)
                if our_unl not in [i.rsplit('##', 1)[0] for i in new_p.v.u['_bklnk']['urls']]:
                    new_p.v.u['_bklnk']['urls'].append("%s##%s" % (our_unl, self.c.p.h))
                    new_c.backlinkController.updateTabInt()
                    new_p.setDirty()
                    new_c.setChanged(True)
                    g.es("NOTE: created back link automatically")
        else:
            g.handleUrl(url, c=self.c)
示例#2
0
    def handleURL(self, url):
        """handleUrl - user clicked an URL / UNL link

        :param str url: URL for link
        """
        g.es(url)
        # UNL detection copied from g.handleUrl()
        if (
            url.lower().startswith('unl:' + '//') or
            url.lower().startswith('file://') and url.find('-->') > -1 or
            url.startswith('#')
        ):
            our_unl = 'unl://'+self.c.p.get_UNL(with_index=False)
            # don't use .get_UNL(with_proto=True), that
            # unecessarily does ' ' -> %20 conversion
            new_c = g.handleUnl(url, self.c)
            if new_c and hasattr(new_c, 'backlinkController'):
                unl = url.replace('%20', ' ').split('#', 1)[-1].split('-->')
                found, _, new_p = g.recursiveUNLFind(unl, new_c)
                if not found:
                    g.es("No perfect match, not creating backlink")
                    return
                new_c.backlinkController.initBacklink(new_p.v)
                if our_unl not in [i.rsplit('##', 1)[0] for i in new_p.v.u['_bklnk']['urls']]:
                    new_p.v.u['_bklnk']['urls'].append("%s##%s" % (our_unl, self.c.p.h))
                    new_c.backlinkController.updateTabInt()
                    new_p.setDirty()
                    new_c.setChanged(True)
                    g.es("NOTE: created back link automatically")
        else:
            g.handleUrl(url, c=self.c)
示例#3
0
    def handleURL(self, url):
        """handleUrl - user clicked an URL / UNL link

        :param str url: URL for link
        """
        g.es(url)
        # UNL detection copied from g.handleUrl()
        if (url.lower().startswith('unl://')
                or url.lower().startswith('file://') and url.find('-->') > -1
                or url.startswith('#')):
            our_unl = 'unl://' + self.c.p.get_UNL()
            new_c = g.handleUnl(url, self.c)
            if new_c and hasattr(new_c, 'backlinkController'):
                unlList = url.replace('%20', ' ').split('#',
                                                        1)[-1].split('-->')
                new_p = g.findUNL(unlList, new_c)
                if not new_p:
                    g.es("No perfect match, not creating backlink")
                    return
                new_c.backlinkController.initBacklink(new_p.v)
                if our_unl not in [
                        i.rsplit('##', 1)[0]
                        for i in new_p.v.u['_bklnk']['urls']
                ]:
                    new_p.v.u['_bklnk']['urls'].append("%s##%s" %
                                                       (our_unl, self.c.p.h))
                    new_c.backlinkController.updateTabInt()
                    new_p.setDirty()
                    new_c.setChanged()
                    g.es("NOTE: created back link automatically")
        else:
            g.handleUrl(url, c=self.c)
示例#4
0
    def find_setting(self, setting):
        # g.es("Settings finder: find %s" % setting)
        key = g.app.config.canonicalizeSettingName(setting)
        value = self.c.config.settingsDict.get(key)
        which = None
        while value and isinstance(value.val,
                                   str) and value.val.startswith('@'):
            msg = (
                "The relevant setting, '@{specific}', is using the value of "
                "a more general setting, '{general}'.  Would you like to edit the "
                "more specific setting, '@{specific}', or the more general setting, "
                "'{general}'?  The more general setting may alter appearance / "
                "behavior in more places, which may or may not be what you prefer."
            ).format(specific=setting, general=value.val)
            which = g.app.gui.runAskYesNoCancelDialog(
                self.c,
                "Which setting?",
                message=msg,
                yesMessage='Edit Specific',
                noMessage='Edit General')
            if which != 'no':
                break
            setting = value.val
            key = g.app.config.canonicalizeSettingName(setting[1:])
            value = self.c.config.settingsDict.get(key)
        if which == 'cancel' or not value:
            return
        unl = value and value.unl
        if (g.os_path_realpath(value.path) == g.os_path_realpath(
                g.os_path_join(g.app.loadManager.computeGlobalConfigDir(),
                               'leoSettings.leo'))):

            msg = (
                "The setting '@{specific}' is in the Leo global configuration "
                "file 'leoSettings.leo'\nand should be copied to "
                "'myLeoSettings.leo' before editing.\n"
                "It may make more sense to copy a group or category of settings.\nIf "
                "'myLeoSettings.leo' contains duplicate settings, the last definition "
                "is used."
                "\n\nChoice:\n"
                "1. just select the node in 'leoSettings.leo', I will decide how much\n"
                "   to copy into 'myLeoSettings.leo' (Recommended).\n"
                "2. copy the one setting, '@{specific}'\n")

            # get the settings already defined in myLeoSettings
            my_settings_c = self.c.openMyLeoSettings()
            _, settingsDict = g.app.loadManager.createSettingsDicts(
                my_settings_c, False)
            # find this setting's node
            path, src_unl = unl.split('#', 1)
            path = path.replace("file://", "").replace("unl://", "")
            src_unl = src_unl.replace('%20', ' ').split("-->")
            c2 = g.app.loadManager.openSettingsFile(path)
            maxp = g.findUNL(src_unl, c2)
            if not maxp:
                return  # 2022/01/30
            # scan this setting's group and category for conflicts
            up = maxp.parent()
            if up and self.no_conflict(up, settingsDict):
                msg += "3. copy the setting group, '{group}'\n"
                up = up.parent()
                if up and self.no_conflict(up, settingsDict):
                    msg += "4. copy the whole setting category, '{category}'\n"

            msg = msg.format(
                specific=setting.lstrip('@'),
                group=unl.split('-->')[-2].split(':',
                                                 1)[0].replace('%20', ' '),
                category=unl.split('-->')[-3].split(':',
                                                    1)[0].replace('%20', ' '))
            which = g.app.gui.runAskOkCancelNumberDialog(self.c,
                                                         "Copy setting?",
                                                         message=msg)
            if which is None:
                return
            which = int(which)
            if which > 1:
                unl = self.copy_to_my_settings(unl, which - 1)
        if unl:
            g.handleUnl(unl, c=self.c)
示例#5
0
    def find_setting(self, setting):
        # g.es("Settings finder: find %s" % setting)
        key = g.app.config.canonicalizeSettingName(setting)
        value = self.c.config.settingsDict.get(key)
        which = None
        while value and g.isString(value.val) and value.val.startswith('@'):
            msg = ("The relevant setting, '@{specific}', is using the value of "
            "a more general setting, '{general}'.  Would you like to edit the "
            "more specific setting, '@{specific}', or the more general setting, "
            "'{general}'?  The more general setting may alter appearance / "
            "behavior in more places, which may or may not be what you prefer."
            ).format(specific=setting, general=value.val)
            which = g.app.gui.runAskYesNoCancelDialog(self.c, "Which setting?",
                message=msg, yesMessage='Edit Specific', noMessage='Edit General')
            if which != 'no':
                break
            setting = value.val
            key = g.app.config.canonicalizeSettingName(setting[1:])
            value = self.c.config.settingsDict.get(key)
        if which == 'cancel' or not value:
            return
        unl = value and value.unl
        if (
            g.os_path_realpath(value.path) == g.os_path_realpath(g.os_path_join(
            g.app.loadManager.computeGlobalConfigDir(), 'leoSettings.leo')
        )):

            msg = ("The setting '@{specific}' is in the Leo global configuration "
            "file 'leoSettings.leo'\nand should be copied to "
            "'myLeoSettings.leo' before editing.\n"
            "It may make more sense to copy a group or category of settings.\nIf "
            "'myLeoSettings.leo' contains duplicate settings, the last definition "
            "is used."
            "\n\nChoice:\n"
            "1. just select the node in 'leoSettings.leo', I will decide how much\n"
            "   to copy into 'myLeoSettings.leo' (Recommended).\n"
            "2. copy the one setting, '@{specific}'\n")

            # get the settings already defined in myLeoSettings
            my_settings_c = self.c.openMyLeoSettings()
            _, settingsDict = g.app.loadManager.createSettingsDicts(my_settings_c, False)
            # find this setting's node
            path, src_unl = unl.split('#', 1)
            path = path.replace("file://", "").replace("unl://", "")
            src_unl = src_unl.replace('%20', ' ').split("-->")
            c2 = g.app.loadManager.openSettingsFile(path)
            found, maxdepth, maxp = g.recursiveUNLFind(src_unl, c2)
            # scan this setting's group and category for conflicts
            up = maxp.parent()
            if up and self.no_conflict(up, settingsDict):
                msg += "3. copy the setting group, '{group}'\n"
                up = up.parent()
                if up and self.no_conflict(up, settingsDict):
                    msg += "4. copy the whole setting category, '{category}'\n"

            msg = msg.format(specific=setting.lstrip('@'),
                group=unl.split('-->')[-2].split(':', 1)[0].replace('%20', ' '),
                category=unl.split('-->')[-3].split(':', 1)[0].replace('%20', ' '))
            which = g.app.gui.runAskOkCancelNumberDialog(
                self.c, "Copy setting?", message=msg)
            if which is None:
                return
            which = int(which)
            if which > 1:
                unl = self.copy_to_my_settings(unl, which-1)
        if unl:
            g.handleUnl(unl, c=self.c)