Skip to content

Commit

Permalink
Merge 50e3f4b into e9fcae0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Jan 30, 2024
2 parents e9fcae0 + 50e3f4b commit cb9f036
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Changelog

- Add the ability to change the last entry using Ctrl+Shift+BackSpace (GH: #247).

- 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""An application for keeping track of your time."""
import shlex
import subprocess
import sys
import time

Expand Down Expand Up @@ -309,9 +311,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 cb9f036

Please sign in to comment.