todo_txt_viewer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/todo_txt_viewer/ui.rb +35 -12
- data/lib/todo_txt_viewer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a69fd8bd3e1b655560b79e099b77ca6929e009d7a6ded5e3678942a64fc9a4a9
|
4
|
+
data.tar.gz: 130056a1c4c8e7d81e15ecec1d6cb65a56d5fc4d758ad9ae219aee5a5192bafa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c84eb37bbec014b1a89c885952377a8b2744757926a0a30ed5cd527b7f801cc69a81b8da2aeecced436a7fac00fab609ccf1cf92fbb0b2fdce617346e92c28
|
7
|
+
data.tar.gz: db79b47882db96a94332866c696f45c4156057912725ada5076b9cea3772eb10704b5047dd97a1e538a7a9d3c44c9ca095c33d544d66215ea9c06fb1fabbd326
|
data/Gemfile.lock
CHANGED
data/lib/todo_txt_viewer/ui.rb
CHANGED
@@ -14,6 +14,7 @@ module TodoTxtViewer
|
|
14
14
|
@main_file = main_file.to_s
|
15
15
|
@archive_file = archive_file.to_s
|
16
16
|
load_file
|
17
|
+
self.selection += 1 if selected_line.is_a? HeaderLine
|
17
18
|
end
|
18
19
|
|
19
20
|
def key_press key # rubocop:disable Metrics/CyclomaticComplexity
|
@@ -31,15 +32,30 @@ module TodoTxtViewer
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
def go_up
|
36
|
+
super
|
37
|
+
selection.zero? ? go_down : super if selected_line.is_a? HeaderLine
|
38
|
+
end
|
39
|
+
|
40
|
+
def go_down
|
41
|
+
super
|
42
|
+
selection == lines.size - 1 ? go_up : super if selected_line.is_a? HeaderLine
|
43
|
+
end
|
44
|
+
|
34
45
|
private
|
35
46
|
|
36
47
|
def task_action action
|
48
|
+
return if selected_line.is_a? HeaderLine
|
49
|
+
|
50
|
+
task = selected_line.task
|
37
51
|
selected_line.task_action action
|
38
52
|
@list.save!
|
39
|
-
load_lines
|
53
|
+
load_lines selected_task: task
|
40
54
|
end
|
41
55
|
|
42
56
|
def archive_task
|
57
|
+
return if selected_line.is_a? HeaderLine
|
58
|
+
|
43
59
|
archive = Todo::List.new @archive_file
|
44
60
|
task = selected_line.task
|
45
61
|
@list.delete_if {|other| other.object_id == task.object_id }
|
@@ -47,16 +63,18 @@ module TodoTxtViewer
|
|
47
63
|
archive.save!
|
48
64
|
@list.save!
|
49
65
|
load_lines
|
50
|
-
|
66
|
+
footer.message = "Archived the Task #{task}"
|
51
67
|
end
|
52
68
|
|
53
69
|
def select_priority key
|
70
|
+
return if selected_line.is_a? HeaderLine
|
71
|
+
|
54
72
|
task = selected_line.task
|
55
73
|
key = key.to_i
|
56
74
|
priority = key.zero? ? nil : ('A'.ord + key - 1).chr
|
57
75
|
task.instance_variable_set :@priority, priority
|
58
76
|
@list.save!
|
59
|
-
load_lines
|
77
|
+
load_lines selected_task: task
|
60
78
|
end
|
61
79
|
|
62
80
|
def create_task
|
@@ -65,8 +83,8 @@ module TodoTxtViewer
|
|
65
83
|
task.instance_variable_set(:@created_on, Date.today) unless task.created_on
|
66
84
|
@list << task
|
67
85
|
@list.save!
|
68
|
-
load_lines
|
69
|
-
|
86
|
+
load_lines selected_task: task
|
87
|
+
footer.message = 'Task inserted'
|
70
88
|
end
|
71
89
|
|
72
90
|
def help
|
@@ -76,17 +94,22 @@ module TodoTxtViewer
|
|
76
94
|
def load_file
|
77
95
|
@list = Todo::List.new @main_file
|
78
96
|
load_lines
|
79
|
-
|
97
|
+
footer.message = "Loaded: #{@main_file}"
|
80
98
|
end
|
81
99
|
|
82
|
-
def load_lines
|
83
|
-
|
100
|
+
def load_lines selected_task: nil
|
101
|
+
self.lines = []
|
102
|
+
|
103
|
+
lines << HeaderLine.new('# todo')
|
104
|
+
@list.by_not_done.sort.reverse_each {|t| lines << TaskLine.new(t) }
|
105
|
+
|
106
|
+
lines << HeaderLine.new('# done')
|
107
|
+
@list.by_done.sort.reverse_each {|t| lines << TaskLine.new(t) }
|
84
108
|
|
85
|
-
|
86
|
-
@list.by_not_done.sort.reverse_each {|t| @lines << TaskLine.new(t) }
|
109
|
+
return if selected_task.nil?
|
87
110
|
|
88
|
-
|
89
|
-
|
111
|
+
idx = lines.index {|l| l.respond_to?(:task) && l.task.object_id == selected_task.object_id }
|
112
|
+
self.selection = idx if idx
|
90
113
|
end
|
91
114
|
end
|
92
115
|
end
|