2007-07-07 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/Editors/_EditNote.py: Follow hyperlinks (updated). svn: r8704
This commit is contained in:
parent
219cebeaa2
commit
db1836bd3f
@ -1,3 +1,6 @@
|
|||||||
|
2007-07-07 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||||
|
* src/Editors/_EditNote.py: Follow hyperlinks (updated).
|
||||||
|
|
||||||
2007-07-06 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
2007-07-06 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||||
* src/Editors/_EditNote.py: Following hyperlinks (not complete).
|
* src/Editors/_EditNote.py: Following hyperlinks (not complete).
|
||||||
* src/MarkupText.py (class MarkupBuffer): Pattern matching feature.
|
* src/MarkupText.py (class MarkupBuffer): Pattern matching feature.
|
||||||
|
@ -54,15 +54,16 @@ from RelLib import Note
|
|||||||
# Constants
|
# Constants
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#USERCHARS = "-A-Za-z0-9"
|
USERCHARS = "-A-Za-z0-9"
|
||||||
#PASSCHARS = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
|
PASSCHARS = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
|
||||||
HOSTCHARS = "-A-Za-z0-9"
|
HOSTCHARS = "-A-Za-z0-9"
|
||||||
PATHCHARS = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%"
|
PATHCHARS = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%"
|
||||||
#SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
|
#SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
|
||||||
#USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?"
|
SCHEME = "(file:/|https?:|ftps?:|webcal:)"
|
||||||
|
USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?"
|
||||||
URLPATH = "/[" + PATHCHARS + "]*[^]'.}>) \t\r\n,\\\"]"
|
URLPATH = "/[" + PATHCHARS + "]*[^]'.}>) \t\r\n,\\\"]"
|
||||||
|
|
||||||
(HTTP, MAIL) = range(2)
|
(GENERAL, HTTP, MAIL) = range(3)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -201,11 +202,13 @@ class EditNote(EditPrimary):
|
|||||||
buffer = MarkupText.MarkupBuffer()
|
buffer = MarkupText.MarkupBuffer()
|
||||||
buffer.create_tag('hyperlink',
|
buffer.create_tag('hyperlink',
|
||||||
underline=UNDERLINE_SINGLE,
|
underline=UNDERLINE_SINGLE,
|
||||||
foreground='#0000FF')
|
foreground='blue')
|
||||||
buffer.match_add("(www|ftp)[" + HOSTCHARS + "]*\\.[" + HOSTCHARS +
|
buffer.match_add("(www|ftp)[" + HOSTCHARS + "]*\\.[" + HOSTCHARS +
|
||||||
".]+" + "(:[0-9]+)?(" + URLPATH + ")?/?", HTTP)
|
".]+" + "(:[0-9]+)?(" + URLPATH + ")?/?", HTTP)
|
||||||
buffer.match_add("(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*"
|
buffer.match_add("(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*"
|
||||||
"(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
|
"(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
|
||||||
|
buffer.match_add(SCHEME + "//(" + USER + "@)?[" + HOSTCHARS + ".]+" +
|
||||||
|
"(:[0-9]+)?(" + URLPATH + ")?/?", GENERAL)
|
||||||
self.match = None
|
self.match = None
|
||||||
self.last_match = None
|
self.last_match = None
|
||||||
|
|
||||||
@ -299,11 +302,7 @@ class EditNote(EditPrimary):
|
|||||||
|
|
||||||
flavor = self.match[MarkupText.MATCH_FLAVOR]
|
flavor = self.match[MarkupText.MATCH_FLAVOR]
|
||||||
url = self.match[MarkupText.MATCH_STRING]
|
url = self.match[MarkupText.MATCH_STRING]
|
||||||
|
self.open_url_cb(None, url, flavor)
|
||||||
if flavor == HTTP:
|
|
||||||
self.on_openlink_activate(None, url)
|
|
||||||
elif flavor == MAIL:
|
|
||||||
self.on_sendmail_activate(None, url)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -313,47 +312,44 @@ class EditNote(EditPrimary):
|
|||||||
flavor = self.match[MarkupText.MATCH_FLAVOR]
|
flavor = self.match[MarkupText.MATCH_FLAVOR]
|
||||||
url = self.match[MarkupText.MATCH_STRING]
|
url = self.match[MarkupText.MATCH_STRING]
|
||||||
|
|
||||||
if flavor == HTTP:
|
if flavor == MAIL:
|
||||||
#
|
open_menu = gtk.MenuItem(_('_Send Mail To...'))
|
||||||
menuitem_copylink = gtk.MenuItem(_('Copy _Link Address'))
|
copy_menu = gtk.MenuItem(_('Copy _E-mail Address'))
|
||||||
menuitem_copylink.connect('activate',
|
else:
|
||||||
self.on_copylink_activate, url)
|
open_menu = gtk.MenuItem(_('_Open Link'))
|
||||||
menuitem_copylink.show()
|
copy_menu = gtk.MenuItem(_('Copy _Link Address'))
|
||||||
menuitem_copylink.set_sensitive(False)
|
|
||||||
menu.prepend(menuitem_copylink)
|
copy_menu.connect('activate', self.copy_url_cb, url, flavor)
|
||||||
#
|
copy_menu.show()
|
||||||
menuitem_openlink = gtk.MenuItem(_('_Open Link'))
|
menu.prepend(copy_menu)
|
||||||
menuitem_openlink.connect('activate',
|
|
||||||
self.on_openlink_activate, url)
|
open_menu.connect('activate', self.open_url_cb, url, flavor)
|
||||||
menuitem_openlink.show()
|
open_menu.show()
|
||||||
menu.prepend(menuitem_openlink)
|
menu.prepend(open_menu)
|
||||||
elif flavor == MAIL:
|
|
||||||
#
|
def open_url_cb(self, menuitem, url, flavor):
|
||||||
menuitem_copymail = gtk.MenuItem(_('Copy _E-mail Address'))
|
if not url:
|
||||||
menuitem_copymail.connect('activate',
|
return
|
||||||
self.on_copymail_activate, url)
|
|
||||||
menuitem_copymail.show()
|
if flavor == HTTP:
|
||||||
menuitem_copymail.set_sensitive(False)
|
url = 'http:' + url
|
||||||
menu.prepend(menuitem_copymail)
|
elif flavor == MAIL:
|
||||||
#
|
if not url.startswith('mailto:'):
|
||||||
menuitem_sendmail = gtk.MenuItem(_('_Send Mail To...'))
|
url = 'mailto:' + url
|
||||||
menuitem_sendmail.connect('activate',
|
elif flavor == GENERAL:
|
||||||
self.on_sendmail_activate, url)
|
pass
|
||||||
menuitem_sendmail.show()
|
else:
|
||||||
menuitem_sendmail.set_sensitive(False)
|
return
|
||||||
menu.prepend(menuitem_sendmail)
|
|
||||||
|
|
||||||
def on_openlink_activate(self, menuitem, url):
|
|
||||||
GrampsDisplay.url(url)
|
GrampsDisplay.url(url)
|
||||||
|
|
||||||
def on_copylink_activate(self, menuitem, url):
|
def copy_url_cb(self, menuitem, url, flavor):
|
||||||
pass
|
"""Copy url to both useful selections."""
|
||||||
|
clipboard = gtk.Clipboard(selection="CLIPBOARD")
|
||||||
|
clipboard.set_text(url)
|
||||||
|
|
||||||
def on_sendmail_activate(self, menuitem, uri):
|
clipboard = gtk.Clipboard(selection="PRIMARY")
|
||||||
pass
|
clipboard.set_text(url)
|
||||||
|
|
||||||
def on_copymail_activate(self, menuitem, uri):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def update_note(self):
|
def update_note(self):
|
||||||
"""Update the Note object with current value."""
|
"""Update the Note object with current value."""
|
||||||
|
Loading…
Reference in New Issue
Block a user