vimamsa 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vma_project +0 -0
- data/README.md +110 -16
- data/exe/vimamsa +30 -22
- data/ext/vmaext/vmaext.c +0 -3
- data/lib/vimamsa.rb +1 -31
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +20 -32
- data/lib/vimamsa/buffer.rb +84 -48
- data/lib/vimamsa/buffer_list.rb +4 -4
- data/lib/vimamsa/debug.rb +6 -6
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +51 -28
- data/lib/vimamsa/file_finder.rb +2 -2
- data/lib/vimamsa/file_history.rb +12 -5
- data/lib/vimamsa/gui.rb +561 -0
- data/lib/vimamsa/gui_gtk_sourceview.rb +294 -0
- data/lib/vimamsa/gui_menu.rb +100 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +67 -189
- data/lib/vimamsa/key_binding_tree.rb +21 -9
- data/lib/vimamsa/key_bindings_vimlike.rb +259 -0
- data/lib/vimamsa/macro.rb +1 -1
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +17 -966
- data/lib/vimamsa/search.rb +0 -4
- data/lib/vimamsa/search_replace.rb +1 -2
- data/lib/vimamsa/util.rb +1 -1
- data/lib/vimamsa/version.rb +1 -1
- data/vimamsa.gemspec +4 -2
- metadata +43 -10
- data/ext/vimamsa/extconf.rb +0 -11
- data/ext/vimamsa/vimamsa.c +0 -174
@@ -53,7 +53,7 @@ end
|
|
53
53
|
|
54
54
|
class KeyBindingTree
|
55
55
|
attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action
|
56
|
-
attr_reader :mode_root_state, :state_trail
|
56
|
+
attr_reader :mode_root_state, :state_trail, :act_bindings
|
57
57
|
|
58
58
|
def initialize()
|
59
59
|
@modes = {}
|
@@ -67,6 +67,10 @@ class KeyBindingTree
|
|
67
67
|
|
68
68
|
@modifiers = [] # TODO: create a queue
|
69
69
|
@last_event = [nil, nil, nil, nil, nil]
|
70
|
+
|
71
|
+
@override_keyhandling_callback = nil
|
72
|
+
# Allows h["foo"]["faa"]=1
|
73
|
+
@act_bindings = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
70
74
|
end
|
71
75
|
|
72
76
|
def set_default_mode(label)
|
@@ -110,6 +114,14 @@ class KeyBindingTree
|
|
110
114
|
return nil
|
111
115
|
end
|
112
116
|
|
117
|
+
def set_keyhandling_override(_callback)
|
118
|
+
@override_keyhandling_callback = _callback
|
119
|
+
end
|
120
|
+
|
121
|
+
def remove_keyhandling_override()
|
122
|
+
@override_keyhandling_callback = nil
|
123
|
+
end
|
124
|
+
|
113
125
|
def match(key_name)
|
114
126
|
new_state = []
|
115
127
|
@match_state.each { |parent|
|
@@ -129,9 +141,7 @@ class KeyBindingTree
|
|
129
141
|
end
|
130
142
|
}
|
131
143
|
}
|
132
|
-
|
133
|
-
# Ripl.start :binding => binding
|
134
|
-
end
|
144
|
+
|
135
145
|
|
136
146
|
if new_state.any? # Match found
|
137
147
|
@match_state = new_state
|
@@ -242,8 +252,10 @@ class KeyBindingTree
|
|
242
252
|
# $cur_key_dict = $key_bind_dict[$context[:mode]]
|
243
253
|
print "MATCH KEY CONF: #{[c, translated_c]}" if $debug
|
244
254
|
|
245
|
-
|
246
|
-
|
255
|
+
if !@override_keyhandling_callback.nil?
|
256
|
+
ret = @override_keyhandling_callback.call(c, event_type)
|
257
|
+
return if ret
|
258
|
+
end
|
247
259
|
|
248
260
|
eval_s = nil
|
249
261
|
|
@@ -306,7 +318,6 @@ class KeyBindingTree
|
|
306
318
|
# act_s = cstate.action.to_s if cstate.action != nil
|
307
319
|
# puts " #{cstate.to_s} #{act_s}"
|
308
320
|
# end
|
309
|
-
# Ripl.start :binding => binding
|
310
321
|
# new_state[0].children.collect{|x|x.to_s}
|
311
322
|
end
|
312
323
|
|
@@ -328,7 +339,7 @@ class KeyBindingTree
|
|
328
339
|
|
329
340
|
printf("\n") if $debug
|
330
341
|
else
|
331
|
-
|
342
|
+
|
332
343
|
# Don't execute action if one of the states has children
|
333
344
|
state_with_children = new_state.select { |s| s.children.any? }
|
334
345
|
s_act = new_state.select { |s| s.action != nil }
|
@@ -432,7 +443,7 @@ class KeyBindingTree
|
|
432
443
|
@last_event = event #TODO: outside if?
|
433
444
|
end
|
434
445
|
|
435
|
-
#
|
446
|
+
# gui_refresh_cursor
|
436
447
|
|
437
448
|
event_handle_time = Time.now - t1
|
438
449
|
debug "RB key event handle time: #{event_handle_time}" if event_handle_time > 1 / 40.0
|
@@ -484,6 +495,7 @@ class KeyBindingTree
|
|
484
495
|
|
485
496
|
modes.each { |mode_id|
|
486
497
|
mode_bind_key(mode_id, keydef, action)
|
498
|
+
@act_bindings[mode_id][action] = keydef
|
487
499
|
}
|
488
500
|
end
|
489
501
|
|
@@ -0,0 +1,259 @@
|
|
1
|
+
|
2
|
+
bindkey ["VCB M","B m"], :run_last_macro
|
3
|
+
|
4
|
+
bindkey "VC s", :easy_jump
|
5
|
+
bindkey "VC , m f", [:find_macro_gui, proc{$macro.find_macro_gui}, "Find named macro"]
|
6
|
+
bindkey "C , m n", [:gui_name_macro, proc{$macro.gui_name_macro}, "Name last macro"]
|
7
|
+
bindkey "C , j r", :jump_to_random
|
8
|
+
bindkey "I enter", :insert_new_line
|
9
|
+
bindkey "C , ; s k", :show_key_bindings #TODO: better binding
|
10
|
+
bindkey "C , , c b", :put_file_path_to_clipboard #TODO: better binding or remove?
|
11
|
+
bindkey "C , , e", :encrypt_file #TODO: better binding
|
12
|
+
bindkey "C , ; u", :set_unencrypted #TODO: better binding
|
13
|
+
bindkey "C , c b", :close_current_buffer
|
14
|
+
bindkey "V ctrl-c", :comment_selection
|
15
|
+
bindkey "C x", :delete_char_forward
|
16
|
+
bindkey "C , , l t", :load_theme
|
17
|
+
bindkey "C , f", :gui_file_finder
|
18
|
+
bindkey "C , h", :gui_file_history_finder
|
19
|
+
bindkey "C , r r", :gui_search_replace
|
20
|
+
bindkey "V , r r", :gui_search_replace
|
21
|
+
bindkey "V , t b", :set_style_bold
|
22
|
+
bindkey "V , t l", :set_style_link
|
23
|
+
bindkey "V J", :V_join_lines
|
24
|
+
bindkey "V , t c", :clear_formats
|
25
|
+
bindkey "C , t h", :set_line_style_heading
|
26
|
+
bindkey "C , t 1", :set_line_style_h1
|
27
|
+
bindkey "C , t 2", :set_line_style_h2
|
28
|
+
bindkey "C , t 3", :set_line_style_h3
|
29
|
+
bindkey "C , t 4", :set_line_style_h4
|
30
|
+
bindkey "C , t b", :set_line_style_bold
|
31
|
+
bindkey "C , t t", :set_line_style_title
|
32
|
+
bindkey "C , t c", :clear_line_styles
|
33
|
+
bindkey "C , b", :gui_select_buffer
|
34
|
+
# bindkey "C , f o", :open_file_dialog
|
35
|
+
bindkey "CI ctrl-o", :open_file_dialog
|
36
|
+
# bindkey "M enter", :minibuffer_end
|
37
|
+
bindkey "C , a", :ack_search
|
38
|
+
bindkey "C d w", :delete_to_word_end
|
39
|
+
bindkey "C d 0", :delete_to_line_start
|
40
|
+
bindkey "C , , f", :file_finder
|
41
|
+
bindkey "VC h", :e_move_backward_char
|
42
|
+
bindkey "C , , .", :backup_all_buffers
|
43
|
+
bindkey "C z ", :start_browse_mode
|
44
|
+
bindkey "B h", :history_switch_backwards
|
45
|
+
bindkey "B l", :history_switch_forwards
|
46
|
+
#bindkey 'B z', :center_on_current_line
|
47
|
+
bindkey "B z", "center_on_current_line();call(:exit_browse_mode)"
|
48
|
+
bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
|
49
|
+
bindkey "B s", :page_up
|
50
|
+
bindkey "B d", :page_down
|
51
|
+
bindkey "B s", :page_up
|
52
|
+
bindkey "B d", :page_down
|
53
|
+
bindkey "B i", :jump_to_start_of_buffer
|
54
|
+
bindkey "B o", :jump_to_end_of_buffer
|
55
|
+
bindkey "B c", :close_current_buffer
|
56
|
+
bindkey "B ;", "buf.jump_to_last_edit"
|
57
|
+
bindkey "B q", :jump_to_last_edit
|
58
|
+
bindkey "B w", :jump_to_next_edit
|
59
|
+
bindkey "C , d", :diff_buffer
|
60
|
+
bindkey "C , g", :invoke_grep_search
|
61
|
+
#bindkey 'C , g', proc{invoke_grep_search}
|
62
|
+
bindkey "C , v", :auto_indent_buffer
|
63
|
+
bindkey "C , , d", :savedebug
|
64
|
+
bindkey "C , , u", :update_file_index
|
65
|
+
bindkey "C , s a", :buf_save_as
|
66
|
+
bindkey "C d d", [:delete_line, proc{buf.delete_line}, "Delete current line"]
|
67
|
+
bindkey "C enter || C return", [:line_action,proc{buf.handle_line_action()}, "Line action"]
|
68
|
+
bindkey "C p" , [:paste_after,proc{buf.paste(AFTER)},""] # TODO: implement as replace for visual mode
|
69
|
+
bindkey "V d" , [:delete_selection,proc{buf.delete(SELECTION)},""]
|
70
|
+
|
71
|
+
default_keys = {
|
72
|
+
|
73
|
+
# File handling
|
74
|
+
"C ctrl-s" => :buf_save,
|
75
|
+
|
76
|
+
# Buffer handling
|
77
|
+
"C B" => "bufs.switch",
|
78
|
+
"C tab" => "bufs.switch_to_last_buf",
|
79
|
+
# 'C , s'=> 'gui_select_buffer',
|
80
|
+
"C , r v b" => :buf_revert,
|
81
|
+
"C , c b" => "bufs.close_current_buffer",
|
82
|
+
#"C , b" => '$kbd.set_mode("S");gui_select_buffer',
|
83
|
+
"C , n b" => :buf_new,
|
84
|
+
# "C , , ." => "backup_all_buffers()",
|
85
|
+
"VC , , s" => :search_actions,
|
86
|
+
|
87
|
+
|
88
|
+
# MOVING
|
89
|
+
# 'VC h' => 'buf.move(BACKWARD_CHAR)',
|
90
|
+
"VC l" => "buf.move(FORWARD_CHAR)",
|
91
|
+
"VC j" => "buf.move(FORWARD_LINE)",
|
92
|
+
"VC k" => "buf.move(BACKWARD_LINE)",
|
93
|
+
|
94
|
+
"VC pagedown" => "page_down",
|
95
|
+
"VC pageup" => "page_up",
|
96
|
+
|
97
|
+
"VCI left" => "buf.move(BACKWARD_CHAR)",
|
98
|
+
"VCI right" => "buf.move(FORWARD_CHAR)",
|
99
|
+
"VCI down" => "buf.move(FORWARD_LINE)",
|
100
|
+
"VCI up" => "buf.move(BACKWARD_LINE)",
|
101
|
+
|
102
|
+
"VC w" => "buf.jump_word(FORWARD,WORD_START)",
|
103
|
+
"VC b" => "buf.jump_word(BACKWARD,WORD_START)",
|
104
|
+
"VC e" => "buf.jump_word(FORWARD,WORD_END)",
|
105
|
+
# 'C '=> 'buf.jump_word(BACKWARD,END)',#TODO
|
106
|
+
"VC f <char>" => "buf.jump_to_next_instance_of_char(<char>)",
|
107
|
+
"VC F <char>" => "buf.jump_to_next_instance_of_char(<char>,BACKWARD)",
|
108
|
+
"VC f space" => "buf.jump_to_next_instance_of_char(' ')",
|
109
|
+
"VC F space" => "buf.jump_to_next_instance_of_char(' ',BACKWARD)",
|
110
|
+
|
111
|
+
"VC /[1-9]/" => "set_next_command_count(<char>)",
|
112
|
+
# 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
|
113
|
+
# 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
|
114
|
+
"VC ^" => "buf.jump(BEGINNING_OF_LINE)",
|
115
|
+
"VC G($next_command_count!=nil)" => "buf.jump_to_line()",
|
116
|
+
"VC 0($next_command_count!=nil)" => "set_next_command_count(<char>)",
|
117
|
+
"VC 0($next_command_count==nil)" => "buf.jump(BEGINNING_OF_LINE)",
|
118
|
+
# 'C 0'=> 'buf.jump(BEGINNING_OF_LINE)',
|
119
|
+
"VC g g" => "buf.jump(START_OF_BUFFER)",
|
120
|
+
"VC g ;" => "buf.jump_to_last_edit",
|
121
|
+
"VC G" => "buf.jump(END_OF_BUFFER)",
|
122
|
+
# 'VC z z' => 'center_on_current_line',
|
123
|
+
"VC *" => "buf.jump_to_next_instance_of_word",
|
124
|
+
|
125
|
+
"C , e" => "invoke_command", # Currently eval
|
126
|
+
|
127
|
+
"VC /" => :find_in_buffer,
|
128
|
+
|
129
|
+
# READCHAR bindings
|
130
|
+
|
131
|
+
"R <char>" => "readchar_new_char(<char>)",
|
132
|
+
|
133
|
+
"C n" => "$search.jump_to_next()",
|
134
|
+
"C N" => "$search.jump_to_previous()",
|
135
|
+
|
136
|
+
# Debug
|
137
|
+
"C , d r p" => "start_ripl",
|
138
|
+
"C , D" => "debug_print_buffer",
|
139
|
+
"C , c s" => "bufs.close_scrap_buffers",
|
140
|
+
"C , d b" => "debug_print_buffer",
|
141
|
+
"C , d c" => "debug_dump_clipboard",
|
142
|
+
"C , d d" => "debug_dump_deltas",
|
143
|
+
"VC O" => "buf.jump(END_OF_LINE)",
|
144
|
+
"VC $" => "buf.jump(END_OF_LINE)",
|
145
|
+
|
146
|
+
"C o" => 'buf.jump(END_OF_LINE);buf.insert_txt("\n");$kbd.set_mode(:insert)',
|
147
|
+
"C X" => 'buf.jump(END_OF_LINE);buf.insert_txt("\n");',
|
148
|
+
"C A" => "buf.jump(END_OF_LINE);$kbd.set_mode(:insert)",
|
149
|
+
"C I" => "buf.jump(FIRST_NON_WHITESPACE);$kbd.set_mode(:insert)",
|
150
|
+
"C a" => "buf.move(FORWARD_CHAR);$kbd.set_mode(:insert)",
|
151
|
+
"C J" => "buf.join_lines()",
|
152
|
+
"C u" => "buf.undo()",
|
153
|
+
|
154
|
+
"C ^" => "buf.jump(BEGINNING_OF_LINE)",
|
155
|
+
"C /[1-9]/" => "set_next_command_count(<char>)",
|
156
|
+
|
157
|
+
# Command mode only:
|
158
|
+
"C ctrl-r" => "buf.redo()", # TODO:???
|
159
|
+
"C R" => "buf.redo()",
|
160
|
+
"C v" => "buf.start_visual_mode",
|
161
|
+
"C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
|
162
|
+
"C space <char>" => "buf.insert_txt(<char>)",
|
163
|
+
"C space space" => "buf.insert_txt(' ')",
|
164
|
+
"C y y" => "buf.copy_line",
|
165
|
+
"C y O" => "buf.copy(:to_line_end)",
|
166
|
+
"C y 0" => "buf.copy(:to_line_start)",
|
167
|
+
"C y e" => "buf.copy(:to_word_end)", # TODO
|
168
|
+
#### Deleting
|
169
|
+
"C x" => "buf.delete(CURRENT_CHAR_FORWARD)",
|
170
|
+
# 'C d k'=> 'delete_line(BACKWARD)', #TODO
|
171
|
+
# 'C d j'=> 'delete_line(FORWARD)', #TODO
|
172
|
+
# 'C d d'=> 'buf.delete_cur_line',
|
173
|
+
"C d e" => "buf.delete2(:to_word_end)",
|
174
|
+
"C d O" => "buf.delete2(:to_line_end)",
|
175
|
+
"C d $" => "buf.delete2(:to_line_end)",
|
176
|
+
# 'C d e'=> 'buf.delete_to_next_word_end',
|
177
|
+
"C d <num> e" => "delete_next_word",
|
178
|
+
"C r <char>" => "buf.replace_with_char(<char>)", # TODO
|
179
|
+
"C , l b" => "load_buffer_list",
|
180
|
+
"C , l l" => "save_buffer_list",
|
181
|
+
"C , r <char>" => "set_register(<char>)", # TODO
|
182
|
+
"C , p <char>" => "buf.paste(BEFORE,<char>)", # TODO
|
183
|
+
|
184
|
+
"C ctrl-c" => "buf.comment_line()",
|
185
|
+
"C ctrl-x" => "buf.comment_line(:uncomment)",
|
186
|
+
|
187
|
+
# 'C 0($next_command_count==nil)'=> 'jump_to_beginning_of_line',
|
188
|
+
|
189
|
+
# Visual mode only:
|
190
|
+
"V esc" => "buf.end_visual_mode",
|
191
|
+
"V ctrl!" => "buf.end_visual_mode",
|
192
|
+
"V y" => "buf.copy_active_selection",
|
193
|
+
"V g U" => "buf.transform_selection(:upcase)",
|
194
|
+
"V g u" => "buf.transform_selection(:downcase)",
|
195
|
+
"V g c" => "buf.transform_selection(:capitalize)",
|
196
|
+
"V g s" => "buf.transform_selection(:swapcase)",
|
197
|
+
"V g r" => "buf.transform_selection(:reverse)",
|
198
|
+
|
199
|
+
"V x" => "buf.delete(SELECTION)",
|
200
|
+
# "V ctrl-c" => "buf.comment_selection",
|
201
|
+
"V ctrl-x" => "buf.comment_selection(:uncomment)",
|
202
|
+
|
203
|
+
"CI ctrl-v" => "buf.paste(BEFORE)",
|
204
|
+
"CI backspace" => "buf.delete(BACKWARD_CHAR)",
|
205
|
+
|
206
|
+
# Marks
|
207
|
+
"CV m <char>" => "buf.mark_current_position(<char>)",
|
208
|
+
'CV \' <char>' => "buf.jump_to_mark(<char>)",
|
209
|
+
# "CV ''" =>'jump_to_mark(NEXT_MARK)', #TODO
|
210
|
+
|
211
|
+
"C i" => "$kbd.set_mode(:insert)",
|
212
|
+
"C ctrl!" => "$kbd.set_mode(:insert)",
|
213
|
+
|
214
|
+
# Macros
|
215
|
+
# (experimental, may not work correctly)
|
216
|
+
# "C q a" => '$macro.start_recording("a")',
|
217
|
+
"VC q <char>" => '$macro.start_recording(<char>)',
|
218
|
+
"VC q($macro.is_recording==true) " => "$macro.end_recording", # TODO
|
219
|
+
# 'C q'=> '$macro.end_recording', #TODO
|
220
|
+
"C q v" => "$macro.end_recording",
|
221
|
+
# 'C v'=> '$macro.end_recording',
|
222
|
+
# "C M" => '$macro.run_last_macro',
|
223
|
+
"C @ <char>" => '$macro.run_macro(<char>)',
|
224
|
+
"C , m S" => '$macro.save_macro("a")',
|
225
|
+
"C , m s" => '$macro.save',
|
226
|
+
"C , t r" => "run_tests()",
|
227
|
+
|
228
|
+
# "C ." => "repeat_last_action", # TODO
|
229
|
+
"VC ;" => "repeat_last_find",
|
230
|
+
# "CV Q" => :quit,
|
231
|
+
"CV ctrl-q" => :quit,
|
232
|
+
"CV , R" => "restart_application",
|
233
|
+
"I ctrl!" => "$kbd.set_mode(:command)",
|
234
|
+
"C shift!" => "buf.save",
|
235
|
+
"I <char>" => "buf.insert_txt(<char>)",
|
236
|
+
"I esc" => "$kbd.set_mode(:command)",
|
237
|
+
|
238
|
+
"I ctrl-d" => "buf.delete2(:to_word_end)",
|
239
|
+
|
240
|
+
# INSERT MODE: Moving
|
241
|
+
"I ctrl-a" => "buf.jump(BEGINNING_OF_LINE)",
|
242
|
+
"I ctrl-b" => "buf.move(BACKWARD_CHAR)",
|
243
|
+
"I ctrl-f" => "buf.move(FORWARD_CHAR)",
|
244
|
+
"I ctrl-n" => "buf.move(FORWARD_LINE)",
|
245
|
+
"I ctrl-p" => "buf.move(BACKWARD_LINE)",
|
246
|
+
"I ctrl-e" => "buf.jump(END_OF_LINE)", # context: mode:I, buttons down: {C}
|
247
|
+
"I alt-f" => "buf.jump_word(FORWARD,WORD_START)",
|
248
|
+
"I alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
|
249
|
+
|
250
|
+
"I tab" => 'buf.insert_txt(" ")',
|
251
|
+
"I space" => 'buf.insert_txt(" ")',
|
252
|
+
# "I return" => 'buf.insert_new_line()',
|
253
|
+
}
|
254
|
+
|
255
|
+
default_keys.each { |key, value|
|
256
|
+
bindkey(key, value)
|
257
|
+
}
|
258
|
+
|
259
|
+
|
data/lib/vimamsa/macro.rb
CHANGED
@@ -58,7 +58,7 @@ class Macro
|
|
58
58
|
$macro_search_list = l
|
59
59
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
60
60
|
|
61
|
-
|
61
|
+
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
62
62
|
"gui_find_macro_select_callback",
|
63
63
|
"gui_find_macro_update_callback")
|
64
64
|
end
|
data/lib/vimamsa/main.rb
CHANGED
@@ -28,7 +28,6 @@ $search_dirs = []
|
|
28
28
|
$errors = []
|
29
29
|
|
30
30
|
$cur_register = "a"
|
31
|
-
$input_char_call_func = nil
|
32
31
|
$debuginfo = {}
|
33
32
|
|
34
33
|
$jump_sequence = []
|
@@ -51,7 +50,7 @@ end
|
|
51
50
|
|
52
51
|
require "vimamsa/editor.rb"
|
53
52
|
|
54
|
-
# load "
|
53
|
+
# load "gui_funcs.rb"
|
55
54
|
|
56
55
|
$vma = Editor.new
|
57
56
|
def vma()
|
data/lib/vimamsa/rbvma.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "rbvma/version"
|
2
1
|
require "gtk3"
|
3
2
|
require "gtksourceview3"
|
4
3
|
#require "gtksourceview4"
|
@@ -8,17 +7,24 @@ require "pathname"
|
|
8
7
|
require "date"
|
9
8
|
require "ripl/multi_line"
|
10
9
|
require "json"
|
11
|
-
|
12
|
-
puts "INIT rbvma"
|
10
|
+
require "listen"
|
13
11
|
|
14
12
|
require "vimamsa/util"
|
15
|
-
|
16
|
-
|
17
|
-
require "vimamsa/
|
18
|
-
require "vimamsa/
|
19
|
-
require "vimamsa/
|
20
|
-
|
21
|
-
|
13
|
+
require "vimamsa/main"
|
14
|
+
|
15
|
+
require "vimamsa/actions"
|
16
|
+
require "vimamsa/key_binding_tree"
|
17
|
+
require "vimamsa/key_actions"
|
18
|
+
|
19
|
+
|
20
|
+
require "vimamsa/gui"
|
21
|
+
require "vimamsa/gui_menu"
|
22
|
+
require "vimamsa/gui_select_window"
|
23
|
+
require "vimamsa/gui_sourceview"
|
24
|
+
|
25
|
+
require "vimamsa/macro"
|
26
|
+
require "vimamsa/buffer"
|
27
|
+
require "vimamsa/debug"
|
22
28
|
require "vimamsa/constants"
|
23
29
|
require "vimamsa/easy_jump"
|
24
30
|
require "vimamsa/hook"
|
@@ -41,418 +47,12 @@ def vma()
|
|
41
47
|
return $vma
|
42
48
|
end
|
43
49
|
|
44
|
-
$idle_scroll_to_mark = false
|
45
|
-
|
46
|
-
def idle_func
|
47
|
-
# puts "IDLEFUNC"
|
48
|
-
if $idle_scroll_to_mark
|
49
|
-
# Ripl.start :binding => binding
|
50
|
-
# $view.get_visible_rect
|
51
|
-
vr = $view.visible_rect
|
52
|
-
|
53
|
-
# iter = b.get_iter_at(:offset => i)
|
54
|
-
|
55
|
-
b = $view.buffer
|
56
|
-
iter = b.get_iter_at(:offset => b.cursor_position)
|
57
|
-
iterxy = $view.get_iter_location(iter)
|
58
|
-
# puts "ITERXY" + iterxy.inspect
|
59
|
-
# Ripl.start :binding => binding
|
60
|
-
|
61
|
-
intr = iterxy.intersect(vr)
|
62
|
-
if intr.nil?
|
63
|
-
$view.set_cursor_pos($view.buffer.cursor_position)
|
64
|
-
else
|
65
|
-
$idle_scroll_to_mark = false
|
66
|
-
end
|
67
|
-
|
68
|
-
sleep(0.1)
|
69
|
-
end
|
70
|
-
sleep(0.01)
|
71
|
-
return true
|
72
|
-
end
|
73
|
-
|
74
|
-
# qt_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
75
|
-
# "gui_find_macro_select_callback",
|
76
|
-
# "gui_find_macro_update_callback")
|
77
|
-
class SelectUpdateWindow
|
78
|
-
COLUMN_JUMP_KEY = 0
|
79
|
-
COLUMN_DESCRIPTION = 1
|
80
|
-
|
81
|
-
def update_item_list(item_list)
|
82
|
-
# puts item_list.inspect
|
83
|
-
# Ripl.start :binding => binding
|
84
|
-
@model.clear
|
85
|
-
for item in item_list
|
86
|
-
iter = @model.append
|
87
|
-
v = ["", item[0]]
|
88
|
-
puts v.inspect
|
89
|
-
iter.set_values(v)
|
90
|
-
end
|
91
|
-
|
92
|
-
set_selected_row(0)
|
93
|
-
end
|
94
|
-
|
95
|
-
def set_selected_row(rownum)
|
96
|
-
rownum = 0 if rownum < 0
|
97
|
-
@selected_row = rownum
|
98
|
-
|
99
|
-
if @model.count > 0
|
100
|
-
path = Gtk::TreePath.new(@selected_row.to_s)
|
101
|
-
iter = @model.get_iter(path)
|
102
|
-
@tv.selection.select_iter(iter)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def initialize(main_window, item_list, jump_keys, select_callback, update_callback)
|
107
|
-
@window = Gtk::Window.new(:toplevel)
|
108
|
-
# @window.screen = main_window.screen
|
109
|
-
@window.title = "List Store"
|
110
|
-
|
111
|
-
@selected_row = 0
|
112
|
-
|
113
|
-
puts item_list.inspect
|
114
|
-
@update_callback = method(update_callback)
|
115
|
-
@select_callback = method(select_callback)
|
116
|
-
# puts @update_callback_m.call("").inspect
|
117
|
-
|
118
|
-
vbox = Gtk::Box.new(:vertical, 8)
|
119
|
-
vbox.margin = 8
|
120
|
-
@window.add(vbox)
|
121
|
-
|
122
|
-
@entry = Gtk::SearchEntry.new
|
123
|
-
@entry.width_chars = 45
|
124
|
-
container = Gtk::Box.new(:horizontal, 10)
|
125
|
-
# container.halign = :start
|
126
|
-
container.halign = :center
|
127
|
-
container.pack_start(@entry,
|
128
|
-
:expand => false, :fill => false, :padding => 0)
|
129
|
-
|
130
|
-
# create tree view
|
131
|
-
@model = Gtk::ListStore.new(String, String)
|
132
|
-
treeview = Gtk::TreeView.new(@model)
|
133
|
-
treeview.search_column = COLUMN_DESCRIPTION
|
134
|
-
@tv = treeview
|
135
|
-
# item_list = @update_callback.call("")
|
136
|
-
update_item_list(item_list)
|
137
|
-
|
138
|
-
# Ripl.start :binding => binding
|
139
|
-
@window.signal_connect("key-press-event") do |_widget, event|
|
140
|
-
# puts "KEYPRESS 1"
|
141
|
-
@entry.handle_event(event)
|
142
|
-
end
|
143
|
-
|
144
|
-
@entry.signal_connect("key_press_event") do |widget, event|
|
145
|
-
# puts "KEYPRESS 2"
|
146
|
-
if event.keyval == Gdk::Keyval::KEY_Down
|
147
|
-
puts "DOWN"
|
148
|
-
set_selected_row(@selected_row + 1)
|
149
|
-
# fixed = iter[COLUMN_FIXED]
|
150
|
-
|
151
|
-
true
|
152
|
-
elsif event.keyval == Gdk::Keyval::KEY_Up
|
153
|
-
set_selected_row(@selected_row - 1)
|
154
|
-
puts "UP"
|
155
|
-
true
|
156
|
-
elsif event.keyval == Gdk::Keyval::KEY_Return
|
157
|
-
path = Gtk::TreePath.new(@selected_row.to_s)
|
158
|
-
iter = @model.get_iter(path)
|
159
|
-
ret = iter[1]
|
160
|
-
@select_callback.call(ret, @selected_row)
|
161
|
-
@window.destroy
|
162
|
-
# puts iter[1].inspect
|
163
|
-
true
|
164
|
-
elsif event.keyval == Gdk::Keyval::KEY_Escape
|
165
|
-
@window.destroy
|
166
|
-
true
|
167
|
-
else
|
168
|
-
false
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
@entry.signal_connect("search-changed") do |widget|
|
173
|
-
puts "search changed: #{widget.text || ""}"
|
174
|
-
item_list = @update_callback.call(widget.text)
|
175
|
-
update_item_list(item_list)
|
176
|
-
# label.text = widget.text || ""
|
177
|
-
end
|
178
|
-
@entry.signal_connect("changed") { puts "[changed] " }
|
179
|
-
@entry.signal_connect("next-match") { puts "[next-match] " }
|
180
|
-
|
181
|
-
label = Gtk::Label.new(<<-EOF)
|
182
|
-
|
183
|
-
Search:
|
184
|
-
EOF
|
185
|
-
vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
|
186
|
-
|
187
|
-
vbox.pack_start(container, :expand => false, :fill => false, :padding => 0)
|
188
|
-
sw = Gtk::ScrolledWindow.new(nil, nil)
|
189
|
-
sw.shadow_type = :etched_in
|
190
|
-
sw.set_policy(:never, :automatic)
|
191
|
-
vbox.pack_start(sw, :expand => true, :fill => true, :padding => 0)
|
192
|
-
|
193
|
-
sw.add(treeview)
|
194
|
-
|
195
|
-
renderer = Gtk::CellRendererText.new
|
196
|
-
column = Gtk::TreeViewColumn.new("JMP",
|
197
|
-
renderer,
|
198
|
-
"text" => COLUMN_JUMP_KEY)
|
199
|
-
column.sort_column_id = COLUMN_JUMP_KEY
|
200
|
-
treeview.append_column(column)
|
201
|
-
|
202
|
-
renderer = Gtk::CellRendererText.new
|
203
|
-
column = Gtk::TreeViewColumn.new("Description",
|
204
|
-
renderer,
|
205
|
-
"text" => COLUMN_DESCRIPTION)
|
206
|
-
column.sort_column_id = COLUMN_DESCRIPTION
|
207
|
-
treeview.append_column(column)
|
208
|
-
|
209
|
-
@window.set_default_size(280, 500)
|
210
|
-
puts "SelectUpdateWindow"
|
211
|
-
end
|
212
|
-
|
213
|
-
def run
|
214
|
-
if !@window.visible?
|
215
|
-
@window.show_all
|
216
|
-
# add_spinner
|
217
|
-
else
|
218
|
-
@window.destroy
|
219
|
-
# GLib::Source.remove(@tiemout) unless @timeout.zero?
|
220
|
-
@timeout = 0
|
221
|
-
end
|
222
|
-
@window
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def center_on_current_line()
|
227
|
-
b = $view.buffer
|
228
|
-
iter = b.get_iter_at(:offset => b.cursor_position)
|
229
|
-
within_margin = 0.0 #margin as a [0.0,0.5) fraction of screen size
|
230
|
-
use_align = true
|
231
|
-
xalign = 0.0 #0.0=top 1.0=bottom, 0.5=center
|
232
|
-
yalign = 0.5
|
233
|
-
$view.scroll_to_iter(iter, within_margin, use_align, xalign, yalign)
|
234
|
-
end
|
235
|
-
|
236
|
-
def qt_select_update_window(item_list, jump_keys, select_callback, update_callback)
|
237
|
-
$selup = SelectUpdateWindow.new(nil, item_list, jump_keys, select_callback, update_callback)
|
238
|
-
$selup.run
|
239
|
-
end
|
240
|
-
|
241
|
-
# ~/Drive/code/ruby-gnome/gtk3/sample/gtk-demo/search_entry2.rb
|
242
|
-
# ~/Drive/code/ruby-gnome/gtk3/sample/gtk-demo/list_store.rb
|
243
|
-
|
244
|
-
def qt_open_file_dialog(dirpath)
|
245
|
-
dialog = Gtk::FileChooserDialog.new(:title => "Open file",
|
246
|
-
:action => :open,
|
247
|
-
:buttons => [[Gtk::Stock::OPEN, :accept],
|
248
|
-
[Gtk::Stock::CANCEL, :cancel]])
|
249
|
-
dialog.set_current_folder(dirpath)
|
250
|
-
|
251
|
-
dialog.signal_connect("response") do |dialog, response_id|
|
252
|
-
if response_id == Gtk::ResponseType::ACCEPT
|
253
|
-
open_new_file(dialog.filename)
|
254
|
-
# puts "uri = #{dialog.uri}"
|
255
|
-
end
|
256
|
-
dialog.destroy
|
257
|
-
end
|
258
|
-
dialog.run
|
259
|
-
end
|
260
|
-
|
261
|
-
def qt_file_saveas(dirpath)
|
262
|
-
dialog = Gtk::FileChooserDialog.new(:title => "Save as",
|
263
|
-
:action => :save,
|
264
|
-
:buttons => [[Gtk::Stock::SAVE, :accept],
|
265
|
-
[Gtk::Stock::CANCEL, :cancel]])
|
266
|
-
dialog.set_current_folder(dirpath)
|
267
|
-
dialog.signal_connect("response") do |dialog, response_id|
|
268
|
-
if response_id == Gtk::ResponseType::ACCEPT
|
269
|
-
file_saveas(dialog.filename)
|
270
|
-
end
|
271
|
-
dialog.destroy
|
272
|
-
end
|
273
|
-
|
274
|
-
dialog.run
|
275
|
-
end
|
276
|
-
|
277
|
-
def qt_create_buffer(id)
|
278
|
-
puts "qt_create_buffer(#{id})"
|
279
|
-
buf1 = GtkSource::Buffer.new()
|
280
|
-
view = VSourceView.new()
|
281
|
-
|
282
|
-
view.set_highlight_current_line(true)
|
283
|
-
view.set_show_line_numbers(true)
|
284
|
-
view.set_buffer(buf1)
|
285
|
-
|
286
|
-
ssm = GtkSource::StyleSchemeManager.new
|
287
|
-
ssm.set_search_path(ssm.search_path << ppath("styles/"))
|
288
|
-
# sty = ssm.get_scheme("dark")
|
289
|
-
sty = ssm.get_scheme("molokai_edit")
|
290
|
-
# puts ssm.scheme_ids
|
291
|
-
|
292
|
-
view.buffer.highlight_matching_brackets = true
|
293
|
-
view.buffer.style_scheme = sty
|
294
|
-
|
295
|
-
provider = Gtk::CssProvider.new
|
296
|
-
provider.load(data: "textview { font-family: Monospace; font-size: 11pt; }")
|
297
|
-
# provider.load(data: "textview { font-family: Arial; font-size: 12pt; }")
|
298
|
-
view.style_context.add_provider(provider)
|
299
|
-
view.wrap_mode = :char
|
300
|
-
|
301
|
-
$vmag.buffers[id] = view
|
302
|
-
end
|
303
|
-
|
304
|
-
def gui_set_file_lang(id, lname)
|
305
|
-
view = $vmag.buffers[id]
|
306
|
-
lm = GtkSource::LanguageManager.new
|
307
|
-
lang = nil
|
308
|
-
lm.set_search_path(lm.search_path << ppath("lang/"))
|
309
|
-
lang = lm.get_language(lname)
|
310
|
-
|
311
|
-
view.buffer.language = lang
|
312
|
-
view.buffer.highlight_syntax = true
|
313
|
-
end
|
314
|
-
|
315
|
-
def qt_process_deltas
|
316
|
-
end
|
317
|
-
|
318
|
-
def qt_add_image(imgpath, pos)
|
319
|
-
end
|
320
|
-
|
321
|
-
def qt_process_deltas
|
322
|
-
end
|
323
|
-
|
324
|
-
def qt_process_events
|
325
|
-
end
|
326
|
-
|
327
|
-
def qt_select_window_close(arg = nil)
|
328
|
-
end
|
329
|
-
|
330
|
-
def set_window_title(str)
|
331
|
-
unimplemented
|
332
|
-
end
|
333
|
-
|
334
|
-
def render_text(tmpbuf, pos, selection_start, reset)
|
335
|
-
unimplemented
|
336
|
-
end
|
337
|
-
|
338
|
-
def qt_set_buffer_contents(id, txt)
|
339
|
-
# $vbuf.set_text(txt)
|
340
|
-
puts "qt_set_buffer_contents(#{id}, txt)"
|
341
|
-
|
342
|
-
$vmag.buffers[id].buffer.set_text(txt)
|
343
|
-
end
|
344
|
-
|
345
|
-
def qt_set_cursor_pos(id, pos)
|
346
|
-
$view.set_cursor_pos(pos)
|
347
|
-
# Ripl.start :binding => binding
|
348
|
-
end
|
349
|
-
|
350
|
-
def qt_set_selection_start(id, selection_start)
|
351
|
-
end
|
352
|
-
|
353
|
-
def qt_set_current_buffer(id)
|
354
|
-
view = $vmag.buffers[id]
|
355
|
-
puts "qt_set_current_buffer(#{id}), view=#{view}"
|
356
|
-
buf1 = view.buffer
|
357
|
-
$vmag.view = view
|
358
|
-
$vmag.buf1 = buf1
|
359
|
-
$view = view
|
360
|
-
$vbuf = buf1
|
361
|
-
|
362
|
-
$vmag.sw.remove($vmag.sw.child) if !$vmag.sw.child.nil?
|
363
|
-
$vmag.sw.add(view)
|
364
|
-
|
365
|
-
view.grab_focus
|
366
|
-
#view.set_focus(10)
|
367
|
-
view.set_cursor_visible(true)
|
368
|
-
#view.move_cursor(1, 1, false)
|
369
|
-
view.place_cursor_onscreen
|
370
|
-
|
371
|
-
#TODO:
|
372
|
-
# itr = view.buffer.get_iter_at(:offset => 0)
|
373
|
-
# view.buffer.place_cursor(itr)
|
374
|
-
|
375
|
-
wtitle = ""
|
376
|
-
wtitle = buf.fname if !buf.fname.nil?
|
377
|
-
$vmag.window.title = wtitle
|
378
|
-
$vmag.sw.show_all
|
379
|
-
end
|
380
|
-
|
381
50
|
def unimplemented
|
382
51
|
puts "unimplemented"
|
383
52
|
end
|
384
53
|
|
385
|
-
def center_where_cursor
|
386
|
-
unimplemented
|
387
|
-
end
|
388
|
-
|
389
|
-
def paste_system_clipboard()
|
390
|
-
# clipboard = $vmag.window.get_clipboard(Gdk::Selection::CLIPBOARD)
|
391
|
-
utf8_string = Gdk::Atom.intern("UTF8_STRING")
|
392
|
-
# x = clipboard.request_contents(utf8_string)
|
393
|
-
|
394
|
-
widget = Gtk::Invisible.new
|
395
|
-
clipboard = Gtk::Clipboard.get_default($vmag.window.display)
|
396
|
-
received_text = ""
|
397
54
|
|
398
|
-
|
399
|
-
ti = clipboard.request_contents(target_string)
|
400
|
-
|
401
|
-
# clipboard.request_contents(target_string) do |_clipboard, selection_data|
|
402
|
-
# received_text = selection_data.text
|
403
|
-
# puts "received_text=#{received_text}"
|
404
|
-
# end
|
405
|
-
if clipboard.wait_is_text_available?
|
406
|
-
received_text = clipboard.wait_for_text
|
407
|
-
end
|
408
|
-
|
409
|
-
if received_text != "" and !received_text.nil?
|
410
|
-
max_clipboard_items = 100
|
411
|
-
if received_text != $clipboard[-1]
|
412
|
-
#TODO: HACK
|
413
|
-
$paste_lines = false
|
414
|
-
end
|
415
|
-
$clipboard << received_text
|
416
|
-
# puts $clipboard[-1]
|
417
|
-
$clipboard = $clipboard[-([$clipboard.size, max_clipboard_items].min)..-1]
|
418
|
-
end
|
419
|
-
return received_text
|
420
|
-
end
|
421
|
-
|
422
|
-
def set_system_clipboard(arg)
|
423
|
-
# return if arg.class != String
|
424
|
-
# return if s.size < 1
|
425
|
-
# utf8_string = Gdk::Atom.intern("UTF8_STRING")
|
426
|
-
widget = Gtk::Invisible.new
|
427
|
-
clipboard = Gtk::Clipboard.get_default($vmag.window.display)
|
428
|
-
clipboard.text = arg
|
429
|
-
end
|
430
|
-
|
431
|
-
def get_visible_area()
|
432
|
-
view = $view
|
433
|
-
vr = view.visible_rect
|
434
|
-
startpos = view.get_iter_at_position_raw(vr.x, vr.y)[1].offset
|
435
|
-
endpos = view.get_iter_at_position_raw(vr.x + vr.width, vr.y + vr.height)[1].offset
|
436
|
-
return [startpos, endpos]
|
437
|
-
end
|
438
|
-
|
439
|
-
def page_up
|
440
|
-
$view.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), -1, false)
|
441
|
-
return true
|
442
|
-
end
|
443
|
-
|
444
|
-
def page_down
|
445
|
-
$view.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), 1, false)
|
446
|
-
return true
|
447
|
-
end
|
448
|
-
|
449
|
-
# module Rbvma
|
450
|
-
# # Your code goes here...
|
451
|
-
# def foo
|
452
|
-
# puts "BAR"
|
453
|
-
# end
|
454
|
-
# end
|
455
|
-
$debug = true
|
55
|
+
$debug = false
|
456
56
|
|
457
57
|
def scan_indexes(txt, regex)
|
458
58
|
# indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) + 1 }
|
@@ -462,553 +62,4 @@ end
|
|
462
62
|
|
463
63
|
$update_cursor = false
|
464
64
|
|
465
|
-
class VSourceView < GtkSource::View
|
466
|
-
def initialize(title = nil)
|
467
|
-
# super(:toplevel)
|
468
|
-
super()
|
469
|
-
puts "vsource init"
|
470
|
-
@last_keyval = nil
|
471
|
-
@last_event = [nil, nil]
|
472
|
-
|
473
|
-
signal_connect("key_press_event") do |widget, event|
|
474
|
-
handle_key_event(event, :key_press_event)
|
475
|
-
true
|
476
|
-
end
|
477
|
-
|
478
|
-
signal_connect("key_release_event") do |widget, event|
|
479
|
-
handle_key_event(event, :key_release_event)
|
480
|
-
true
|
481
|
-
end
|
482
|
-
|
483
|
-
signal_connect("move-cursor") do |widget, event|
|
484
|
-
$update_cursor = true
|
485
|
-
false
|
486
|
-
end
|
487
|
-
|
488
|
-
signal_connect "button-release-event" do |widget, event|
|
489
|
-
$buffer.set_pos(buffer.cursor_position)
|
490
|
-
false
|
491
|
-
end
|
492
|
-
@curpos_mark = nil
|
493
|
-
end
|
494
|
-
|
495
|
-
def handle_key_event(event, sig)
|
496
|
-
if $update_cursor
|
497
|
-
curpos = buffer.cursor_position
|
498
|
-
puts "MOVE CURSOR: #{curpos}"
|
499
|
-
buf.set_pos(curpos)
|
500
|
-
$update_cursor = false
|
501
|
-
end
|
502
|
-
puts $view.visible_rect.inspect
|
503
|
-
|
504
|
-
puts "key event"
|
505
|
-
puts event
|
506
|
-
|
507
|
-
key_name = event.string
|
508
|
-
if event.state.control_mask?
|
509
|
-
key_name = Gdk::Keyval.to_name(event.keyval)
|
510
|
-
# Gdk::Keyval.to_name()
|
511
|
-
end
|
512
|
-
|
513
|
-
keyval_trans = {}
|
514
|
-
keyval_trans[Gdk::Keyval::KEY_Control_L] = "ctrl"
|
515
|
-
keyval_trans[Gdk::Keyval::KEY_Control_R] = "ctrl"
|
516
|
-
|
517
|
-
keyval_trans[Gdk::Keyval::KEY_Escape] = "esc"
|
518
|
-
|
519
|
-
keyval_trans[Gdk::Keyval::KEY_Return] = "enter"
|
520
|
-
keyval_trans[Gdk::Keyval::KEY_ISO_Enter] = "enter"
|
521
|
-
keyval_trans[Gdk::Keyval::KEY_KP_Enter] = "enter"
|
522
|
-
keyval_trans[Gdk::Keyval::KEY_Alt_L] = "alt"
|
523
|
-
keyval_trans[Gdk::Keyval::KEY_Alt_R] = "alt"
|
524
|
-
|
525
|
-
keyval_trans[Gdk::Keyval::KEY_BackSpace] = "backspace"
|
526
|
-
keyval_trans[Gdk::Keyval::KEY_KP_Page_Down] = "pagedown"
|
527
|
-
keyval_trans[Gdk::Keyval::KEY_KP_Page_Up] = "pageup"
|
528
|
-
keyval_trans[Gdk::Keyval::KEY_Page_Down] = "pagedown"
|
529
|
-
keyval_trans[Gdk::Keyval::KEY_Page_Up] = "pageup"
|
530
|
-
keyval_trans[Gdk::Keyval::KEY_Left] = "left"
|
531
|
-
keyval_trans[Gdk::Keyval::KEY_Right] = "right"
|
532
|
-
keyval_trans[Gdk::Keyval::KEY_Down] = "down"
|
533
|
-
keyval_trans[Gdk::Keyval::KEY_Up] = "up"
|
534
|
-
keyval_trans[Gdk::Keyval::KEY_space] = "space"
|
535
|
-
|
536
|
-
keyval_trans[Gdk::Keyval::KEY_Shift_L] = "shift"
|
537
|
-
keyval_trans[Gdk::Keyval::KEY_Shift_R] = "shift"
|
538
|
-
keyval_trans[Gdk::Keyval::KEY_Tab] = "tab"
|
539
|
-
|
540
|
-
key_trans = {}
|
541
|
-
key_trans["\e"] = "esc"
|
542
|
-
tk = keyval_trans[event.keyval]
|
543
|
-
key_name = tk if !tk.nil?
|
544
|
-
|
545
|
-
key_str_parts = []
|
546
|
-
key_str_parts << "ctrl" if event.state.control_mask? and key_name != "ctrl"
|
547
|
-
key_str_parts << "alt" if event.state.mod1_mask? and key_name != "alt"
|
548
|
-
|
549
|
-
key_str_parts << key_name
|
550
|
-
key_str = key_str_parts.join("-")
|
551
|
-
keynfo = { :key_str => key_str, :key_name => key_name, :keyval => event.keyval }
|
552
|
-
puts keynfo.inspect
|
553
|
-
# $kbd.match_key_conf(key_str, nil, :key_press)
|
554
|
-
# puts "key_str=#{key_str} key_"
|
555
|
-
|
556
|
-
if key_str != "" # or prefixed_key_str != ""
|
557
|
-
if sig == :key_release_event and event.keyval == @last_keyval
|
558
|
-
$kbd.match_key_conf(key_str + "!", nil, :key_release)
|
559
|
-
@last_event = [event, :key_release]
|
560
|
-
elsif sig == :key_press_event
|
561
|
-
$kbd.match_key_conf(key_str, nil, :key_press)
|
562
|
-
@last_event = [event, key_str, :key_press]
|
563
|
-
end
|
564
|
-
@last_keyval = event.keyval #TODO: outside if?
|
565
|
-
end
|
566
|
-
|
567
|
-
handle_deltas
|
568
|
-
|
569
|
-
# set_focus(5)
|
570
|
-
# false
|
571
|
-
|
572
|
-
end
|
573
|
-
|
574
|
-
def pos_to_coord(i)
|
575
|
-
b = buffer
|
576
|
-
iter = b.get_iter_at(:offset => i)
|
577
|
-
iterxy = get_iter_location(iter)
|
578
|
-
winw = parent_window.width
|
579
|
-
view_width = visible_rect.width
|
580
|
-
gutter_width = winw - view_width
|
581
|
-
|
582
|
-
x = iterxy.x + gutter_width
|
583
|
-
y = iterxy.y
|
584
|
-
|
585
|
-
# buffer_to_window_coords(Gtk::TextWindowType::TEXT, iterxy.x, iterxy.y).inspect
|
586
|
-
# puts buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
|
587
|
-
(x, y) = buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y)
|
588
|
-
# Ripl.start :binding => binding
|
589
|
-
|
590
|
-
return [x, y]
|
591
|
-
end
|
592
|
-
|
593
|
-
def handle_deltas()
|
594
|
-
any_change = false
|
595
|
-
while d = buf.deltas.shift
|
596
|
-
any_change = true
|
597
|
-
pos = d[0]
|
598
|
-
op = d[1]
|
599
|
-
num = d[2]
|
600
|
-
txt = d[3]
|
601
|
-
if op == DELETE
|
602
|
-
startiter = buffer.get_iter_at(:offset => pos)
|
603
|
-
enditer = buffer.get_iter_at(:offset => pos + num)
|
604
|
-
buffer.delete(startiter, enditer)
|
605
|
-
elsif op == INSERT
|
606
|
-
startiter = buffer.get_iter_at(:offset => pos)
|
607
|
-
buffer.insert(startiter, txt)
|
608
|
-
end
|
609
|
-
end
|
610
|
-
if any_change
|
611
|
-
qt_set_cursor_pos($buffer.id, $buffer.pos) #TODO: only when necessary
|
612
|
-
end
|
613
|
-
|
614
|
-
# sanity_check #TODO
|
615
|
-
end
|
616
|
-
|
617
|
-
def sanity_check()
|
618
|
-
a = buffer.text
|
619
|
-
b = buf.to_s
|
620
|
-
# puts "===================="
|
621
|
-
# puts a.lines[0..10].join()
|
622
|
-
# puts "===================="
|
623
|
-
# puts b.lines[0..10].join()
|
624
|
-
# puts "===================="
|
625
|
-
if a == b
|
626
|
-
puts "Buffers match"
|
627
|
-
else
|
628
|
-
puts "ERROR: Buffer's don't match."
|
629
|
-
end
|
630
|
-
end
|
631
|
-
|
632
|
-
def set_cursor_pos(pos)
|
633
|
-
# return
|
634
|
-
itr = buffer.get_iter_at(:offset => pos)
|
635
|
-
itr2 = buffer.get_iter_at(:offset => pos + 1)
|
636
|
-
buffer.place_cursor(itr)
|
637
|
-
|
638
|
-
# $view.signal_emit("extend-selection", Gtk::MovementStep.new(:PAGES), -1, false)
|
639
|
-
|
640
|
-
within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
|
641
|
-
use_align = false
|
642
|
-
xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
|
643
|
-
yalign = 0.5
|
644
|
-
|
645
|
-
if @curpos_mark.nil?
|
646
|
-
@curpos_mark = buffer.create_mark("cursor", itr, false)
|
647
|
-
else
|
648
|
-
buffer.move_mark(@curpos_mark, itr)
|
649
|
-
end
|
650
|
-
scroll_to_mark(@curpos_mark, within_margin, use_align, xalign, yalign)
|
651
|
-
$idle_scroll_to_mark = true
|
652
|
-
ensure_cursor_visible
|
653
|
-
|
654
|
-
# scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
|
655
|
-
|
656
|
-
# $view.signal_emit("extend-selection", Gtk::TextExtendSelection.new, itr,itr,itr2)
|
657
|
-
# Ripl.start :binding => binding
|
658
|
-
draw_cursor
|
659
|
-
|
660
|
-
return true
|
661
|
-
end
|
662
|
-
|
663
|
-
def cursor_visible_idle_func
|
664
|
-
puts "cursor_visible_idle_func"
|
665
|
-
# From https://picheta.me/articles/2013/08/gtk-plus--a-method-to-guarantee-scrolling.html
|
666
|
-
# vr = visible_rect
|
667
|
-
|
668
|
-
# b = $view.buffer
|
669
|
-
# iter = buffer.get_iter_at(:offset => buffer.cursor_position)
|
670
|
-
# iterxy = get_iter_location(iter)
|
671
|
-
|
672
|
-
sleep(0.01)
|
673
|
-
# intr = iterxy.intersect(vr)
|
674
|
-
if is_cursor_visible == false
|
675
|
-
# set_cursor_pos(buffer.cursor_position)
|
676
|
-
|
677
|
-
itr = buffer.get_iter_at(:offset => buffer.cursor_position)
|
678
|
-
|
679
|
-
within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
|
680
|
-
use_align = false
|
681
|
-
xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
|
682
|
-
yalign = 0.5
|
683
|
-
|
684
|
-
scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
|
685
|
-
|
686
|
-
# return true # Call this func again
|
687
|
-
else
|
688
|
-
return false # Don't call this idle func again
|
689
|
-
end
|
690
|
-
end
|
691
|
-
|
692
|
-
def is_cursor_visible
|
693
|
-
vr = visible_rect
|
694
|
-
iter = buffer.get_iter_at(:offset => buffer.cursor_position)
|
695
|
-
iterxy = get_iter_location(iter)
|
696
|
-
iterxy.width = 1 if iterxy.width == 0
|
697
|
-
iterxy.height = 1 if iterxy.height == 0
|
698
|
-
|
699
|
-
intr = iterxy.intersect(vr)
|
700
|
-
if intr.nil?
|
701
|
-
puts iterxy.inspect
|
702
|
-
puts vr.inspect
|
703
|
-
# Ripl.start :binding => binding
|
704
|
-
|
705
|
-
# exit!
|
706
|
-
return false
|
707
|
-
else
|
708
|
-
return true
|
709
|
-
end
|
710
|
-
end
|
711
65
|
|
712
|
-
def ensure_cursor_visible
|
713
|
-
if is_cursor_visible == false
|
714
|
-
Thread.new {
|
715
|
-
sleep 0.01
|
716
|
-
GLib::Idle.add(proc { cursor_visible_idle_func })
|
717
|
-
}
|
718
|
-
end
|
719
|
-
end
|
720
|
-
|
721
|
-
def draw_cursor
|
722
|
-
if is_command_mode
|
723
|
-
itr = buffer.get_iter_at(:offset => buf.pos)
|
724
|
-
itr2 = buffer.get_iter_at(:offset => buf.pos + 1)
|
725
|
-
$view.buffer.select_range(itr, itr2)
|
726
|
-
elsif buf.visual_mode?
|
727
|
-
puts "VISUAL MODE"
|
728
|
-
(_start, _end) = buf.get_visual_mode_range2
|
729
|
-
puts "#{_start}, #{_end}"
|
730
|
-
itr = buffer.get_iter_at(:offset => _start)
|
731
|
-
itr2 = buffer.get_iter_at(:offset => _end + 1)
|
732
|
-
$view.buffer.select_range(itr, itr2)
|
733
|
-
else # Insert mode
|
734
|
-
itr = buffer.get_iter_at(:offset => buf.pos)
|
735
|
-
$view.buffer.select_range(itr, itr)
|
736
|
-
puts "INSERT MODE"
|
737
|
-
end
|
738
|
-
end
|
739
|
-
|
740
|
-
# def quit
|
741
|
-
# destroy
|
742
|
-
# true
|
743
|
-
# end
|
744
|
-
end
|
745
|
-
|
746
|
-
class VMAg
|
747
|
-
attr_accessor :buffers, :sw, :view, :buf1, :window
|
748
|
-
|
749
|
-
VERSION = "1.0"
|
750
|
-
|
751
|
-
HEART = "♥"
|
752
|
-
RADIUS = 150
|
753
|
-
N_WORDS = 5
|
754
|
-
FONT = "Serif 18"
|
755
|
-
TEXT = "I ♥ GTK+"
|
756
|
-
|
757
|
-
def initialize()
|
758
|
-
@show_overlay = true
|
759
|
-
@da = nil
|
760
|
-
@buffers = {}
|
761
|
-
@view = nil
|
762
|
-
@buf1 = nil
|
763
|
-
end
|
764
|
-
|
765
|
-
def run
|
766
|
-
init_window
|
767
|
-
# init_rtext
|
768
|
-
Gtk.main
|
769
|
-
end
|
770
|
-
|
771
|
-
def start_overlay_draw()
|
772
|
-
@da = Gtk::Fixed.new
|
773
|
-
@overlay.add_overlay(@da)
|
774
|
-
@overlay.set_overlay_pass_through(@da, true)
|
775
|
-
end
|
776
|
-
|
777
|
-
def clear_overlay()
|
778
|
-
if @da != nil
|
779
|
-
@overlay.remove(@da)
|
780
|
-
end
|
781
|
-
end
|
782
|
-
|
783
|
-
def overlay_draw_text(text, textpos)
|
784
|
-
# puts "overlay_draw_text #{[x,y]}"
|
785
|
-
(x, y) = @view.pos_to_coord(textpos)
|
786
|
-
# puts "overlay_draw_text #{[x,y]}"
|
787
|
-
label = Gtk::Label.new("<span background='#00000088' foreground='#ff0000' weight='ultrabold'>#{text}</span>")
|
788
|
-
label.use_markup = true
|
789
|
-
@da.put(label, x, y)
|
790
|
-
end
|
791
|
-
|
792
|
-
def end_overlay_draw()
|
793
|
-
@da.show_all
|
794
|
-
end
|
795
|
-
|
796
|
-
def toggle_overlay
|
797
|
-
@show_overlay = @show_overlay ^ 1
|
798
|
-
if !@show_overlay
|
799
|
-
if @da != nil
|
800
|
-
@overlay.remove(@da)
|
801
|
-
end
|
802
|
-
return
|
803
|
-
else
|
804
|
-
@da = Gtk::Fixed.new
|
805
|
-
@overlay.add_overlay(@da)
|
806
|
-
@overlay.set_overlay_pass_through(@da, true)
|
807
|
-
end
|
808
|
-
|
809
|
-
(startpos, endpos) = get_visible_area
|
810
|
-
s = @view.buffer.text
|
811
|
-
wpos = s.enum_for(:scan, /\W(\w)/).map { Regexp.last_match.begin(0) + 1 }
|
812
|
-
wpos = wpos[0..130]
|
813
|
-
|
814
|
-
# vr = @view.visible_rect
|
815
|
-
# # gtk_text_view_get_line_at_y
|
816
|
-
# # gtk_text_view_get_iter_at_position
|
817
|
-
# gtk_text_view_get_iter_at_position(vr.
|
818
|
-
# istart = @view.get_iter_at_position(vr.x,vr.y)
|
819
|
-
# istart = @view.get_iter_at_y(vr.y)
|
820
|
-
# startpos = @view.get_iter_at_position_raw(vr.x,vr.y)[1].offset
|
821
|
-
# endpos = @view.get_iter_at_position_raw(vr.x+vr.width,vr.y+vr.height)[1].offset
|
822
|
-
# puts "startpos,endpos:#{[startpos, endpos]}"
|
823
|
-
|
824
|
-
da = @da
|
825
|
-
if false
|
826
|
-
da.signal_connect "draw" do |widget, cr|
|
827
|
-
cr.save
|
828
|
-
for pos in wpos
|
829
|
-
(x, y) = @view.pos_to_coord(pos)
|
830
|
-
|
831
|
-
layout = da.create_pango_layout("XY")
|
832
|
-
desc = Pango::FontDescription.new("sans bold 11")
|
833
|
-
layout.font_description = desc
|
834
|
-
|
835
|
-
cr.move_to(x, y)
|
836
|
-
# cr.move_to(gutter_width, 300)
|
837
|
-
cr.pango_layout_path(layout)
|
838
|
-
|
839
|
-
cr.set_source_rgb(1.0, 0.0, 0.0)
|
840
|
-
cr.fill_preserve
|
841
|
-
end
|
842
|
-
cr.restore
|
843
|
-
false # = draw other
|
844
|
-
# true # = Don't draw others
|
845
|
-
end
|
846
|
-
end
|
847
|
-
|
848
|
-
for pos in wpos
|
849
|
-
(x, y) = @view.pos_to_coord(pos)
|
850
|
-
# da.put(Gtk::Label.new("AB"), x, y)
|
851
|
-
label = Gtk::Label.new("<span background='#00000088' foreground='#ff0000' weight='ultrabold'>AB</span>")
|
852
|
-
label.use_markup = true
|
853
|
-
da.put(label, x, y)
|
854
|
-
end
|
855
|
-
|
856
|
-
# puts @view.pos_to_coord(300).inspect
|
857
|
-
|
858
|
-
@da.show_all
|
859
|
-
end
|
860
|
-
|
861
|
-
def init_keybindings
|
862
|
-
$kbd = KeyBindingTree.new()
|
863
|
-
$kbd.add_mode("C", :command)
|
864
|
-
$kbd.add_mode("I", :insert)
|
865
|
-
$kbd.add_mode("V", :visual)
|
866
|
-
$kbd.add_mode("M", :minibuffer)
|
867
|
-
$kbd.add_mode("R", :readchar)
|
868
|
-
$kbd.add_mode("B", :browse)
|
869
|
-
$kbd.set_default_mode(:command)
|
870
|
-
require "default_key_bindings"
|
871
|
-
|
872
|
-
$macro = Macro.new
|
873
|
-
|
874
|
-
# bindkey "VC j", "buf.move(FORWARD_LINE)"
|
875
|
-
bindkey "VC j", "puts('j_key_action')"
|
876
|
-
bindkey "VC ctrl-j", "puts('ctrl_j_key_action')"
|
877
|
-
|
878
|
-
bindkey "VC l", "buf.move(FORWARD_CHAR)"
|
879
|
-
bindkey "C x", "buf.delete(CURRENT_CHAR_FORWARD)"
|
880
|
-
# bindkey "C r <char>", "buf.replace_with_char(<char>)"
|
881
|
-
bindkey "I space", 'buf.insert_txt(" ")'
|
882
|
-
|
883
|
-
bindkey "VC l", "buf.move(FORWARD_CHAR)"
|
884
|
-
bindkey "VC j", "buf.move(FORWARD_LINE)"
|
885
|
-
bindkey "VC k", "buf.move(BACKWARD_LINE)"
|
886
|
-
bindkey "VC h", "buf.move(BACKWARD_CHAR)"
|
887
|
-
end
|
888
|
-
|
889
|
-
def handle_deltas()
|
890
|
-
while d = buf.deltas.shift
|
891
|
-
pos = d[0]
|
892
|
-
op = d[1]
|
893
|
-
num = d[2]
|
894
|
-
txt = d[3]
|
895
|
-
if op == DELETE
|
896
|
-
startiter = @buf1.get_iter_at(:offset => pos)
|
897
|
-
enditer = @buf1.get_iter_at(:offset => pos + num)
|
898
|
-
@buf1.delete(startiter, enditer)
|
899
|
-
elsif op == INSERT
|
900
|
-
startiter = @buf1.get_iter_at(:offset => pos)
|
901
|
-
@buf1.insert(startiter, txt)
|
902
|
-
end
|
903
|
-
end
|
904
|
-
end
|
905
|
-
|
906
|
-
def add_to_minibuf(msg)
|
907
|
-
startiter = @minibuf.buffer.get_iter_at(:offset => 0)
|
908
|
-
@minibuf.buffer.insert(startiter, "#{msg}\n")
|
909
|
-
@minibuf.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), -1, false)
|
910
|
-
end
|
911
|
-
|
912
|
-
def init_minibuffer()
|
913
|
-
# Init minibuffer
|
914
|
-
sw = Gtk::ScrolledWindow.new
|
915
|
-
sw.set_policy(:automatic, :automatic)
|
916
|
-
overlay = Gtk::Overlay.new
|
917
|
-
overlay.add(sw)
|
918
|
-
@vpaned.pack2(overlay, :resize => false)
|
919
|
-
# overlay.set_size_request(-1, 50)
|
920
|
-
# $ovrl = overlay
|
921
|
-
# $ovrl.set_size_request(-1, 30)
|
922
|
-
$sw2 = sw
|
923
|
-
sw.set_size_request(-1, 12)
|
924
|
-
|
925
|
-
view = VSourceView.new()
|
926
|
-
view.set_highlight_current_line(false)
|
927
|
-
view.set_show_line_numbers(false)
|
928
|
-
# view.set_buffer(buf1)
|
929
|
-
ssm = GtkSource::StyleSchemeManager.new
|
930
|
-
ssm.set_search_path(ssm.search_path << ppath("styles/"))
|
931
|
-
sty = ssm.get_scheme("molokai_edit")
|
932
|
-
view.buffer.highlight_matching_brackets = false
|
933
|
-
view.buffer.style_scheme = sty
|
934
|
-
provider = Gtk::CssProvider.new
|
935
|
-
# provider.load(data: "textview { font-family: Monospace; font-size: 11pt; }")
|
936
|
-
provider.load(data: "textview { font-family: Arial; font-size: 10pt; color:#ff0000}")
|
937
|
-
view.style_context.add_provider(provider)
|
938
|
-
view.wrap_mode = :char
|
939
|
-
@minibuf = view
|
940
|
-
# Ripl.start :binding => binding
|
941
|
-
# startiter = view.buffer.get_iter_at(:offset => 0)
|
942
|
-
message("STARTUP")
|
943
|
-
sw.add(view)
|
944
|
-
end
|
945
|
-
|
946
|
-
def init_header_bar()
|
947
|
-
# @window = Gtk::Window.new(:toplevel)
|
948
|
-
# @window.screen = main_window.screen
|
949
|
-
# @window.set_default_size(600, 400)
|
950
|
-
|
951
|
-
header = Gtk::HeaderBar.new
|
952
|
-
header.show_close_button = true
|
953
|
-
header.title = "Welcome to Facebook - Log in, sign up or learn more"
|
954
|
-
header.has_subtitle = false
|
955
|
-
|
956
|
-
# icon = Gio::ThemedIcon.new("mail-send-receive-symbolic")
|
957
|
-
# icon = Gio::ThemedIcon.new("document-open-symbolic")
|
958
|
-
# icon = Gio::ThemedIcon.new("dialog-password")
|
959
|
-
|
960
|
-
#edit-redo edit-paste edit-find-replace edit-undo edit-find edit-cut edit-copy
|
961
|
-
#document-open document-save document-save-as document-properties document-new
|
962
|
-
button = Gtk::Button.new
|
963
|
-
icon = Gio::ThemedIcon.new("open-menu-symbolic")
|
964
|
-
image = Gtk::Image.new(:icon => icon, :size => :button)
|
965
|
-
button.add(image)
|
966
|
-
header.pack_end(button)
|
967
|
-
|
968
|
-
button = Gtk::Button.new
|
969
|
-
icon = Gio::ThemedIcon.new("document-revert-symbolic")
|
970
|
-
image = Gtk::Image.new(:icon => icon, :size => :button)
|
971
|
-
button.add(image)
|
972
|
-
header.pack_end(button)
|
973
|
-
|
974
|
-
box = Gtk::Box.new(:horizontal, 0)
|
975
|
-
box.style_context.add_class("linked")
|
976
|
-
|
977
|
-
button = Gtk::Button.new
|
978
|
-
image = Gtk::Image.new(:icon_name => "pan-start-symbolic", :size => :button)
|
979
|
-
button.add(image)
|
980
|
-
box.add(button)
|
981
|
-
|
982
|
-
button = Gtk::Button.new
|
983
|
-
image = Gtk::Image.new(:icon_name => "pan-end-symbolic", :size => :button)
|
984
|
-
button.add(image)
|
985
|
-
box.add(button)
|
986
|
-
|
987
|
-
header.pack_start(box)
|
988
|
-
@window.titlebar = header
|
989
|
-
@window.add(Gtk::TextView.new)
|
990
|
-
end
|
991
|
-
|
992
|
-
def init_window
|
993
|
-
@window = Gtk::Window.new(:toplevel)
|
994
|
-
@window.set_default_size(650, 850)
|
995
|
-
@window.title = "Multiple Views"
|
996
|
-
@window.show_all
|
997
|
-
# vpaned = Gtk::Paned.new(:horizontal)
|
998
|
-
@vpaned = Gtk::Paned.new(:vertical)
|
999
|
-
@window.add(@vpaned)
|
1000
|
-
|
1001
|
-
@sw = Gtk::ScrolledWindow.new
|
1002
|
-
@sw.set_policy(:automatic, :automatic)
|
1003
|
-
@overlay = Gtk::Overlay.new
|
1004
|
-
@overlay.add(@sw)
|
1005
|
-
@vpaned.pack1(@overlay, :resize => true)
|
1006
|
-
|
1007
|
-
init_minibuffer
|
1008
|
-
init_header_bar
|
1009
|
-
|
1010
|
-
@window.show_all
|
1011
|
-
|
1012
|
-
vma.start
|
1013
|
-
end
|
1014
|
-
end
|