Skip to content

Commit 99d06fc

Browse files
committed
about window from appdata, and clear selection in contexts and projects
1 parent 20ed2c3 commit 99d06fc

11 files changed

+131
-70
lines changed

data/meson.build

-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ if desktop_utils.found()
1212
test('Validate desktop file', desktop_utils, args: [desktop_file])
1313
endif
1414

15-
appstream_file = i18n.merge_file(
16-
input: 'net.hemish.kaar.metainfo.xml.in',
17-
output: 'net.hemish.kaar.metainfo.xml',
18-
po_dir: '../po',
19-
install: true,
20-
install_dir: get_option('datadir') / 'metainfo'
21-
)
22-
23-
appstreamcli = find_program('appstreamcli', required: false, disabler: true)
24-
test('Validate appstream file', appstreamcli,
25-
args: ['validate', '--no-net', '--explain', appstream_file])
26-
2715
install_data('net.hemish.kaar.gschema.xml',
2816
install_dir: get_option('datadir') / 'glib-2.0' / 'schemas'
2917
)

src/blp/ui.blp

+63-17
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ template $KaarWindow: Adw.ApplicationWindow {
5757
Gtk.Box {
5858
vexpand: true;
5959
orientation: vertical;
60-
spacing: 15;
60+
spacing: 10;
6161

6262
Gtk.ListBox filters_box {
6363
valign: start;
@@ -91,14 +91,32 @@ template $KaarWindow: Adw.ApplicationWindow {
9191
}
9292
}
9393

94-
Gtk.Label {
95-
label: "Projects";
96-
halign: start;
97-
margin-start: 15;
94+
Gtk.Box {
95+
orientation: horizontal;
9896

99-
styles [
100-
"heading"
101-
]
97+
Gtk.Label {
98+
label: "Projects";
99+
halign: start;
100+
margin-start: 15;
101+
102+
styles [
103+
"heading"
104+
]
105+
}
106+
107+
Separator {
108+
hexpand: true;
109+
110+
styles [
111+
"spacer"
112+
]
113+
}
114+
115+
Gtk.Button projects_clear {
116+
icon-name: "edit-clear-symbolic";
117+
tooltip-text: "Clear Selection";
118+
margin-end: 8;
119+
}
102120
}
103121

104122
Gtk.ListBox projects_box {
@@ -109,14 +127,32 @@ template $KaarWindow: Adw.ApplicationWindow {
109127
selection-mode: multiple;
110128
}
111129

112-
Gtk.Label {
113-
label: "Contexts";
114-
halign: start;
115-
margin-start: 15;
130+
Gtk.Box {
131+
orientation: horizontal;
116132

117-
styles [
118-
"heading"
119-
]
133+
Gtk.Label {
134+
label: "Contexts";
135+
halign: start;
136+
margin-start: 15;
137+
138+
styles [
139+
"heading"
140+
]
141+
}
142+
143+
Separator {
144+
hexpand: true;
145+
146+
styles [
147+
"spacer"
148+
]
149+
}
150+
151+
Gtk.Button contexts_clear {
152+
icon-name: "edit-clear-symbolic";
153+
tooltip-text: "Clear Selection";
154+
margin-end: 8;
155+
}
120156
}
121157

122158
Gtk.ListBox contexts_box {
@@ -165,7 +201,8 @@ template $KaarWindow: Adw.ApplicationWindow {
165201
"flat"
166202
]
167203

168-
icon-name: "document-open-symbolic";
204+
visible: bind tab_bar.tabs-revealed inverted;
205+
icon-name: "tab-new-symbolic";
169206
tooltip-text: "Open File";
170207
}
171208

@@ -193,8 +230,17 @@ template $KaarWindow: Adw.ApplicationWindow {
193230
}
194231

195232
[top]
196-
Adw.TabBar tab_bar{
233+
Adw.TabBar tab_bar {
197234
view: tab_view;
235+
236+
end-action-widget: Gtk.Button trailing_open_button {
237+
icon-name: "tab-new-symbolic";
238+
tooltip-text: "Open File";
239+
240+
styles [
241+
"flat"
242+
]
243+
};
198244
}
199245

200246
[bottom]

src/gtk/help-overlay.ui

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
<property name="action-name">win.reload</property>
7777
</object>
7878
</child>
79+
<child>
80+
<object class="GtkShortcutsShortcut">
81+
<property name="title">Close Tab</property>
82+
<property name="action-name">win.close_tab</property>
83+
</object>
84+
</child>
7985
</object>
8086
</child>
8187
</object>

src/kaar.gresource.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<file preprocess="xml-stripblanks">blp/task.ui</file>
77
<file preprocess="xml-stripblanks">blp/tab.ui</file>
88
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
9+
<file preprocess="xml-stripblanks">net.hemish.kaar.metainfo.xml</file>
910
<file>style.css</file>
1011
</gresource>
1112
</gresources>

src/main.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,8 @@ def open_file(self, file: Gio.File):
7979

8080
def on_about_action(self, widget, _):
8181
"""Callback for the app.about action."""
82-
about = Adw.AboutWindow(transient_for=self.props.active_window,
83-
application_name='Kaar',
84-
application_icon='net.hemish.kaar',
85-
developer_name='Hemish',
86-
version='0.1.0',
87-
developers=['Hemish'],
88-
copyright='© 2023 Hemish')
82+
about = Adw.AboutWindow.new_from_appdata("/net/hemish/kaar/net.hemish.kaar.metainfo.xml")
83+
about.set_transient_for(self.props.active_window)
8984
about.present()
9085

9186
def on_preferences_action(self, widget, _):

src/meson.build

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ blueprints = custom_target('blueprints',
1313
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
1414
)
1515

16+
appstream_file = i18n.merge_file(
17+
input: 'net.hemish.kaar.metainfo.xml.in',
18+
output: 'net.hemish.kaar.metainfo.xml',
19+
po_dir: '../po',
20+
install: true,
21+
install_dir: get_option('datadir') / 'metainfo'
22+
)
23+
24+
appstreamcli = find_program('appstreamcli', required: false, disabler: true)
25+
test('Validate appstream file', appstreamcli,
26+
args: ['validate', '--no-net', '--explain', appstream_file])
27+
1628
gnome.compile_resources('kaar',
1729
'kaar.gresource.xml',
1830
gresource_bundle: true,
1931
install: true,
2032
install_dir: pkgdatadir,
21-
dependencies: blueprints,
33+
dependencies: [blueprints, appstream_file],
2234
)
2335

2436
python = import('python')

src/model.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, render_pango_markup: bool, **kwargs):
7575
super().__init__(**kwargs)
7676
self.connect("setup", self.create_task_item)
7777
self.connect("bind", self.bind_task_item)
78+
self.connect("unbind", self.unbind_task_item)
7879
self.render_pango_markup = render_pango_markup
7980

8081
def create_task_item(self, fact, list_item):
@@ -85,7 +86,7 @@ def create_task_item(self, fact, list_item):
8586

8687
def bind_task_item(self, fact, list_item):
8788
task_stack = list_item.get_child()
88-
task_object: GObject.Object = list_item.get_item()
89+
task_object: TodoTask = list_item.get_item()
8990
task_stack.object = task_object
9091

9192
task_stack.task_label.set_label(task_object.duplicatedescription)
@@ -96,12 +97,9 @@ def bind_task_item(self, fact, list_item):
9697

9798
task_stack.entry_row.set_text(task_object.line)
9899

99-
if task_object.completed:
100-
task_stack.check_button.set_active(True)
101-
task_object.bind_property("completed", task_stack.check_button, "active", GObject.BindingFlags.BIDIRECTIONAL)
100+
task_stack.check_button.set_active(task_object.completed)
101+
task_stack.completed_binding = task_object.bind_property("completed", task_stack.check_button, "active", GObject.BindingFlags.BIDIRECTIONAL)
102102

103-
# FIXME: completing tasks via check button does not autosave
104-
#task_object.connect("notify::completed", lambda *args: )
105103

106104
if task_object.duplicatepriority != None:
107105
task_stack.priority_label.set_label(task_object.duplicatepriority)
@@ -115,10 +113,18 @@ def bind_task_item(self, fact, list_item):
115113
for date in task_object._dates:
116114
task_stack.dates_flow_box.append(task_stack.create_flow_box_item(date))
117115

116+
task_object.completed_signal = task_object.connect("notify::completed", lambda *args: task_stack.activate_action("win.save"))
118117

118+
def unbind_task_item(self, fact, list_item):
119+
task_object: TodoTask = list_item.get_item()
120+
task_stack = list_item.get_child()
121+
122+
task_object.disconnect(task_object.completed_signal)
123+
124+
task_stack.completed_binding.unbind()
119125

120126

121-
# a subclass of pytodotxt.Task to be consumed by Gtk Widgets and GObjects
127+
# a subclass of pytodotxt.Task to be consumed by Gtk Widgets and GListModels
122128
class TodoTask(Task, GObject.Object):
123129
mode = GObject.Property(type=str, default="view")
124130
__gtype_name__ = "TodoTask"
@@ -130,6 +136,7 @@ def __init__(self, *args):
130136
self._line = str(self)
131137
self._dates = self.calculate_date_strings()
132138
self.tags = [*map(lambda x: "+"+x, self.projects), *map(lambda x: "@"+x, self.contexts)]
139+
self.notify("completed")
133140

134141

135142

@@ -143,7 +150,7 @@ def line(self, value):
143150
self.parse(value)
144151
self._line = str(self)
145152
self.notify("duplicatedescription")
146-
self.completed = self.is_completed
153+
self.notify("completed")
147154
self._dates = self.calculate_date_strings() # Doesnt matter what value you pass here
148155
self.duplicatepriority = self.priority
149156
self.tags = [*map(lambda x: "+"+x, self.projects), *map(lambda x: "@"+x, self.contexts)]
@@ -155,10 +162,6 @@ def duplicatedescription(self):
155162
@GObject.Property(type=bool, default=False)
156163
def completed(self):
157164
return self.is_completed
158-
159-
@completed.setter
160-
def completed(self, value):
161-
self.is_completed = value
162165

163166
@GObject.Property(type=str)
164167
def duplicatepriority(self):

data/net.hemish.kaar.metainfo.xml.in src/net.hemish.kaar.metainfo.xml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
<value key="Purism::form_factor">workstation</value>
4444
<value key="Purism::form_factor">mobile</value>
4545
</custom>
46-
</component>
46+
</component>

src/tab.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,19 @@ def reload_file(self, *args):
134134
self.file_monitor.disconnect(self.file_monitor_signal)
135135

136136
except: pass
137-
138-
139-
file_path = self.file_obj.get_parse_name()
140137

141-
# FIXME: read from Gfile itself to have support for non-local files
142-
self.todotxt = TodoTxt(file_path, parser=TodoTxtParser(task_type=TodoTask))
138+
done, contents, tag = self.file_obj.load_contents(cancellable=None)
139+
143140
try:
144-
self.todotxt.parse()
141+
if done:
142+
for task in TodoTxtParser(task_type=TodoTask).parse(contents):
143+
self.list_store.append(task)
144+
print(task)
145145
except Exception as e:
146146
print(e)
147147
finally:
148148
self.file_monitor_signal = self.file_monitor.connect("changed", lambda *args: print("File Changed"))
149-
for task in self.todotxt.tasks:
150-
self.list_store.append(task)
149+
151150
# Reload filters
152151
self.tasks_filter.changed(Gtk.FilterChange.DIFFERENT)
153152
self.search_filter.changed(Gtk.FilterChange.DIFFERENT)
@@ -157,8 +156,6 @@ def save_file(self, *args):
157156
pb.set_fraction(0)
158157
pb.set_visible(True)
159158

160-
self.todotxt.tasks = []
161-
162159
@_async
163160
def report_progress():
164161
for i in range(10):
@@ -167,11 +164,19 @@ def report_progress():
167164
sleep(0.15)
168165
pb.set_visible(False)
169166

167+
tasks = []
168+
170169
for item in self.list_store:
171-
self.todotxt.tasks.append(item)
170+
tasks.append(str(item))
172171

173172
self.file_monitor.disconnect(self.file_monitor_signal)
174-
self.todotxt.save()
173+
174+
readwrite = self.file_obj.open_readwrite()
175+
176+
readwrite.get_output_stream().write_all(buffer=bytes("\n".join(tasks), 'utf-8'), cancellable=None)
177+
178+
readwrite.close(cancellable=None)
179+
175180
self.file_monitor_signal = self.file_monitor.connect('changed', lambda *args: print("file Changed"))
176181

177182
report_progress()

src/todo

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
TODO: improve sorting and its UI for preferences
2-
3-
TODO: improve projects and contexts filtering UI
1+
TODO: improve sorting and its UI for preferences (high)
42

53
TODO: internationalisation
64

7-
TODO: notify user that file changed on disk
5+
TODO: notify user that file changed on disk (high)
86

9-
TODO: remember last selected page on session save
7+
TODO: remember last selected page on session save (low priority)
108

11-
TODO: add content menu for each task for edit, delete
9+
TODO: add content menu for each task for edit, delete (low priority)
1210

13-
TODO: increase, decrease priority buttons and preference
11+
TODO: increase, decrease priority buttons and preference (low priority)

0 commit comments

Comments
 (0)