diff --git a/CHANGES.rst b/CHANGES.rst index 58af2c7..574f1db 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -40,6 +40,11 @@ Changelog - Grouped task entries can now be sorted by start date, name, duration or according to tasks.txt order (GH: #228). +- There's a new hidden setting to override the text editor (GH: #113). + You can use ``gsettings set org.gtimelog editor gvim`` (or dconf-editor). + More complicated settings like ``'gnome-terminal -e "vim %s"'`` also work + (``%s`` is replaced with the file name). + 0.11.3 (2019-04-23) ~~~~~~~~~~~~~~~~~~~ diff --git a/src/gtimelog/data/gschemas.compiled b/src/gtimelog/data/gschemas.compiled index 1091c74..d89b915 100644 Binary files a/src/gtimelog/data/gschemas.compiled and b/src/gtimelog/data/gschemas.compiled differ diff --git a/src/gtimelog/data/org.gtimelog.gschema.xml b/src/gtimelog/data/org.gtimelog.gschema.xml index 6b8c7d0..357e974 100644 --- a/src/gtimelog/data/org.gtimelog.gschema.xml +++ b/src/gtimelog/data/org.gtimelog.gschema.xml @@ -38,7 +38,7 @@ "start-time" - Log Tasks/Groups order + Log Tasks/Groups order Order of tasks and groups in Log view @@ -163,6 +163,12 @@ If true, the task entry will use the standard GTK+ completion. If false, it'll only use the custom prefix completion on PageUp/PageDown. + + "" + Text editor to use for editing timelog.txt or tasks.txt + If blank, gtimelog will use your system default editor. If the value contains '%s', it will be replaced with the filename, otherwise the filename will be appended as an extra argument. + + diff --git a/src/gtimelog/main.py b/src/gtimelog/main.py index 6033145..db40eb9 100644 --- a/src/gtimelog/main.py +++ b/src/gtimelog/main.py @@ -1,4 +1,6 @@ """An application for keeping track of your time.""" +import shlex +import subprocess import sys import time @@ -307,9 +309,30 @@ def do_startup(self): def on_quit(self, action, parameter): self.quit() + @staticmethod + def prepare_args(program, filename): + args = shlex.split(program) + had_percent_s = False + for i, arg in enumerate(args): + if '%s' in arg: + args[i] = arg.replace('%s', filename) + had_percent_s = True + if not had_percent_s: + args.append(filename) + return args + + def run_in_background(self, program, filename): + args = self.prepare_args(program, filename) + subprocess.Popen(args) + # XXX: error handling! + def open_in_editor(self, filename): self.create_if_missing(filename) - if os.name == 'nt': + gsettings = Gio.Settings.new("org.gtimelog") + editor = gsettings.get_string('editor') + if editor: + self.run_in_background(editor, filename) + elif os.name == 'nt': os.startfile(filename) else: uri = GLib.filename_to_uri(filename, None)