-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghoul.rb
116 lines (94 loc) · 2.28 KB
/
ghoul.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require 'shoes'
require_relative 'profile'
require_relative 'entry'
Shoes.app title: 'Ghoul', width: 570, height: 350, scroll: true do
@profile = Profile.new
stack(margin: 8) do
flow do
banner 'GHOUL'
image 'ghoul.png', width: '48px', height: '48px', left: 500
end
end
stack do
@entry_stack = stack margin: 8 do
@profile.entries.each do |entry|
flow do
key = edit_line entry.key
value = edit_line entry.value
save_button = button 'save'
delete_button = button 'delete'
save_button.click do
entry.save_changes(key.text, value.text)
end
delete_button.click do
if confirm('Are you sure?')
del(entry)
end
end
end
end
end
@new_row = stack(margin: 8) do
tagline 'New Entry'
flow do
key = edit_line
value = edit_line
save_button = button 'save'
cancel_button = button 'cancel'
save_button.click do
e = Entry.new
e.key = key.text
e.value = value.text
@profile.entries << e
refresh
key.text = ''
value.text = ''
@new_row.hide
@new_stack.show
end
cancel_button.click do
@new_row.hide
@new_stack.show
end
end
end
@new_row.hide
@new_stack = stack(margin: 8) do
new_button = button 'New'
new_button.click do
@new_row.show
@new_stack.hide
end
save_button = button 'Write changes'
save_button.click do
@profile.write_profile
end
end
end
# methods
def refresh
@entry_stack.clear
@profile.entries.each do |entry|
@entry_stack.append do
flow do
key = edit_line entry.key
value = edit_line entry.value
save_button = button 'save'
delete_button = button 'delete'
save_button.click do
entry.save_changes(key.text, value.text)
end
delete_button.click do
if confirm('Are you sure?')
del(entry)
end
end
end
end
end
end
def del(entry)
@profile.entries.delete(entry)
refresh
end
end