forked from Mirrors/apostrophe
use local paths when possible on DnD
parent
a00298e0db
commit
9ece36b5ac
|
@ -2,6 +2,7 @@ import mimetypes
|
||||||
import urllib
|
import urllib
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
|
from uberwriter.settings import Settings
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ class DragDropHandler:
|
||||||
def __init__(self, text_view, *targets):
|
def __init__(self, text_view, *targets):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
self.settings = Settings.new()
|
||||||
|
|
||||||
self.target_list = Gtk.TargetList.new([])
|
self.target_list = Gtk.TargetList.new([])
|
||||||
if TARGET_URI in targets:
|
if TARGET_URI in targets:
|
||||||
self.target_list.add_uri_targets(TARGET_URI)
|
self.target_list.add_uri_targets(TARGET_URI)
|
||||||
|
@ -35,8 +38,17 @@ class DragDropHandler:
|
||||||
mime = mimetypes.guess_type(uri)
|
mime = mimetypes.guess_type(uri)
|
||||||
|
|
||||||
if mime[0] is not None and mime[0].startswith('image/'):
|
if mime[0] is not None and mime[0].startswith('image/'):
|
||||||
|
basepath = self.settings.get_string("open-file-path")
|
||||||
|
basepath = urllib.parse.quote(basepath)
|
||||||
|
|
||||||
if uri.startswith("file://"):
|
if uri.startswith("file://"):
|
||||||
uri = uri[7:]
|
uri = uri[7:]
|
||||||
|
|
||||||
|
# for handling local URIs we need to substract the basepath
|
||||||
|
# except when it is "/" (document not saved)
|
||||||
|
if uri.startswith(basepath) and basepath != "/":
|
||||||
|
uri = uri[len(basepath)+1:]
|
||||||
|
|
||||||
text = "![{}]({})".format(name, uri)
|
text = "![{}]({})".format(name, uri)
|
||||||
limit_left = 2
|
limit_left = 2
|
||||||
limit_right = len(name)
|
limit_right = len(name)
|
||||||
|
|
Loading…
Reference in New Issue