Skip to content

Commit

Permalink
Hidden setting to override the text editor.
Browse files Browse the repository at this point in the history
Note that people who run gtimelog straight from Git will need to
manually run ``make`` to recompile the gsettings schema, or gtimelog
will segfault when you press Ctrl+E.

Also note that using `gsettings` is a pain when the schema is not
installed globally, but you can use

    dconf write /org/gtimelog/editor '"gvim %s"'

and then tweak it with dconf-editor.

Error handling is missing: if you set editor to gvim and gvim is not
installed, you'll see a Python traceback on the console.

Application.prepare_args() is a separate static method so I could write
unit tests for it, but I haven't done so.

Closes #113.
  • Loading branch information
mgedmin committed Nov 29, 2023
1 parent ba606cb commit 5012a08
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -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)
~~~~~~~~~~~~~~~~~~~
Expand Down
Binary file modified src/gtimelog/data/gschemas.compiled
Binary file not shown.
8 changes: 7 additions & 1 deletion src/gtimelog/data/org.gtimelog.gschema.xml
Expand Up @@ -38,7 +38,7 @@

<key name="log-order" enum="org.gtimelog.LogOrder">
<default>"start-time"</default>
<summary>Log Tasks/Groups order</summary>
<summary>Log Tasks/Groups order</summary>
<description>Order of tasks and groups in Log view</description>
</key>

Expand Down Expand Up @@ -163,6 +163,12 @@
<description>If true, the task entry will use the standard GTK+ completion. If false, it'll only use the custom prefix completion on PageUp/PageDown.</description>
</key>

<key name="editor" type="s">
<default>""</default>
<summary>Text editor to use for editing timelog.txt or tasks.txt</summary>
<description>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.</description>
</key>

</schema>

</schemalist>
25 changes: 24 additions & 1 deletion src/gtimelog/main.py
@@ -1,4 +1,6 @@
"""An application for keeping track of your time."""
import shlex
import subprocess
import sys
import time

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5012a08

Please sign in to comment.