forked from Mirrors/apostrophe
Abstract the path base of open files
parent
132b3d6022
commit
e0c4854613
|
@ -13,6 +13,13 @@
|
||||||
asked to install them manually.
|
asked to install them manually.
|
||||||
</description>
|
</description>
|
||||||
</key>
|
</key>
|
||||||
|
<key name='open-file-path' type='s'>
|
||||||
|
<default>"/tmp"</default>
|
||||||
|
<summary>Open file base path</summary>
|
||||||
|
<description>
|
||||||
|
Open file paths of the current session
|
||||||
|
</description>
|
||||||
|
</key>
|
||||||
|
|
||||||
</schema>
|
</schema>
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
### END LICENSE
|
### END LICENSE
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import http.client
|
import http.client
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -28,6 +29,7 @@ from pprint import pprint
|
||||||
|
|
||||||
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject
|
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject
|
||||||
from uberwriter_lib import LatexToPNG
|
from uberwriter_lib import LatexToPNG
|
||||||
|
from .Settings import Settings
|
||||||
|
|
||||||
from .FixTable import FixTable
|
from .FixTable import FixTable
|
||||||
|
|
||||||
|
@ -276,6 +278,7 @@ class UberwriterInlinePreview():
|
||||||
self.TextView.connect_after('popup-menu', self.move_popup)
|
self.TextView.connect_after('popup-menu', self.move_popup)
|
||||||
self.TextView.connect('button-press-event', self.click_move_button)
|
self.TextView.connect('button-press-event', self.click_move_button)
|
||||||
self.popover = None
|
self.popover = None
|
||||||
|
self.settings = Settings.new()
|
||||||
|
|
||||||
def open_popover_with_widget(self, widget):
|
def open_popover_with_widget(self, widget):
|
||||||
a = self.TextBuffer.create_child_anchor(self.TextBuffer.get_iter_at_mark(self.ClickMark))
|
a = self.TextBuffer.create_child_anchor(self.TextBuffer.get_iter_at_mark(self.ClickMark))
|
||||||
|
@ -363,7 +366,7 @@ class UberwriterInlinePreview():
|
||||||
link = MarkupBuffer.regex["LINK"]
|
link = MarkupBuffer.regex["LINK"]
|
||||||
|
|
||||||
footnote = re.compile('\[\^([^\s]+?)\]')
|
footnote = re.compile('\[\^([^\s]+?)\]')
|
||||||
image = re.compile("!\[(.+?)\]\((.+?)\)")
|
image = re.compile("!\[(.*?)\]\((.+?)\)")
|
||||||
|
|
||||||
buf = self.TextBuffer
|
buf = self.TextBuffer
|
||||||
context_offset = 0
|
context_offset = 0
|
||||||
|
@ -457,6 +460,11 @@ class UberwriterInlinePreview():
|
||||||
path = match.group(2)
|
path = match.group(2)
|
||||||
if path.startswith("file://"):
|
if path.startswith("file://"):
|
||||||
path = path[7:]
|
path = path[7:]
|
||||||
|
elif not path.startswith("/"):
|
||||||
|
# then the path is relative
|
||||||
|
base_path = self.settings.get_value("open-file-path").get_string()
|
||||||
|
path = base_path + "/" + path
|
||||||
|
|
||||||
logger.info(path)
|
logger.info(path)
|
||||||
pb = GdkPixbuf.Pixbuf.new_from_file_at_size(path, 400, 300)
|
pb = GdkPixbuf.Pixbuf.new_from_file_at_size(path, 400, 300)
|
||||||
image = Gtk.Image.new_from_pixbuf(pb)
|
image = Gtk.Image.new_from_pixbuf(pb)
|
||||||
|
|
|
@ -378,7 +378,7 @@ class UberwriterWindow(Window):
|
||||||
f.write(self.get_text())
|
f.write(self.get_text())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.filename = filename
|
self.set_filename(filename)
|
||||||
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
||||||
|
|
||||||
self.did_change = False
|
self.did_change = False
|
||||||
|
@ -416,7 +416,7 @@ class UberwriterWindow(Window):
|
||||||
f.write(self.get_text())
|
f.write(self.get_text())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.filename = filename
|
self.set_filename(filename)
|
||||||
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -594,7 +594,7 @@ class UberwriterWindow(Window):
|
||||||
self.TextEditor.redos = []
|
self.TextEditor.redos = []
|
||||||
|
|
||||||
self.did_change = False
|
self.did_change = False
|
||||||
self.filename = None
|
self.set_filename()
|
||||||
self.set_headerbar_title("New File" + self.title_end)
|
self.set_headerbar_title("New File" + self.title_end)
|
||||||
|
|
||||||
def menu_activate_focusmode(self, widget=None):
|
def menu_activate_focusmode(self, widget=None):
|
||||||
|
@ -709,7 +709,7 @@ class UberwriterWindow(Window):
|
||||||
os.environ['PANDOC_PREFIX'] = base_path + '/'
|
os.environ['PANDOC_PREFIX'] = base_path + '/'
|
||||||
|
|
||||||
# Set the styles according the color theme
|
# Set the styles according the color theme
|
||||||
if self.settings.get_value("dark-mode"):
|
if Settings.get_value("dark-mode"):
|
||||||
stylesheet = helpers.get_media_path('uberwriter_dark.css')
|
stylesheet = helpers.get_media_path('uberwriter_dark.css')
|
||||||
else:
|
else:
|
||||||
stylesheet = helpers.get_media_path('uberwriter.css')
|
stylesheet = helpers.get_media_path('uberwriter.css')
|
||||||
|
@ -806,7 +806,7 @@ class UberwriterWindow(Window):
|
||||||
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
self.set_headerbar_title(os.path.basename(filename) + self.title_end)
|
||||||
self.TextEditor.undo_stack = []
|
self.TextEditor.undo_stack = []
|
||||||
self.TextEditor.redo_stack = []
|
self.TextEditor.redo_stack = []
|
||||||
self.filename = filename
|
self.set_filename(filename)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Error Reading File: %r" % e)
|
logger.warning("Error Reading File: %r" % e)
|
||||||
|
@ -1108,7 +1108,7 @@ class UberwriterWindow(Window):
|
||||||
self.text_change_event = self.TextBuffer.connect('changed', self.text_changed)
|
self.text_change_event = self.TextBuffer.connect('changed', self.text_changed)
|
||||||
|
|
||||||
# Init file name with None
|
# Init file name with None
|
||||||
self.filename = None
|
self.set_filename()
|
||||||
|
|
||||||
self.generate_recent_files_menu(self.builder.get_object('recent'))
|
self.generate_recent_files_menu(self.builder.get_object('recent'))
|
||||||
|
|
||||||
|
@ -1241,6 +1241,14 @@ class UberwriterWindow(Window):
|
||||||
self.hb.props.title = title
|
self.hb.props.title = title
|
||||||
self.set_title(title)
|
self.set_title(title)
|
||||||
|
|
||||||
|
def set_filename(self, filename=None):
|
||||||
|
if filename:
|
||||||
|
self.filename = filename
|
||||||
|
base_path = os.path.dirname(self.filename)
|
||||||
|
else:
|
||||||
|
self.filename = None
|
||||||
|
base_path = "/"
|
||||||
|
self.settings.set_value("open-file-path", GLib.Variant("s", base_path))
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
if not os.path.exists(CONFIG_PATH):
|
if not os.path.exists(CONFIG_PATH):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue