vimamsa 0.1.26 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +62 -16
- data/custom_example.rb +43 -13
- data/doc/TODO.md +461 -0
- data/doc/bundling_plan.md +569 -0
- data/doc/key_bindings_report_plan.md +168 -0
- data/doc/missing_vim_bindings.md +71 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +296 -0
- data/doc/vimlike_vim_conflicts.md +254 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/exe/run_tests.rb +117 -3
- data/exe/vimamsa +24 -4
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/lang/hyperplaintext.lang +6 -0
- data/lib/vimamsa/ack.rb +11 -1
- data/lib/vimamsa/actions.rb +4 -1
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +593 -82
- data/lib/vimamsa/buffer_changetext.rb +102 -42
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +4 -0
- data/lib/vimamsa/buffer_manager.rb +4 -1
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/clipboard.rb +3 -0
- data/lib/vimamsa/conf.rb +59 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +4 -1
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +39 -10
- data/lib/vimamsa/easy_jump.rb +3 -0
- data/lib/vimamsa/editor.rb +263 -57
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +3 -0
- data/lib/vimamsa/file_manager.rb +30 -15
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/gui.rb +520 -106
- data/lib/vimamsa/gui_command_line.rb +208 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +59 -35
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_keylog_panel.rb +246 -0
- data/lib/vimamsa/gui_menu.rb +23 -11
- data/lib/vimamsa/gui_select_window.rb +19 -48
- data/lib/vimamsa/gui_settings.rb +78 -37
- data/lib/vimamsa/gui_sourceview.rb +273 -19
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +606 -0
- data/lib/vimamsa/hook.rb +3 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/key_actions.rb +112 -13
- data/lib/vimamsa/key_binding_tree.rb +242 -215
- data/lib/vimamsa/key_bindings_notepad.rb +43 -0
- data/lib/vimamsa/key_bindings_report.rb +261 -0
- data/lib/vimamsa/key_bindings_vim.rb +354 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/macro.rb +3 -0
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +26 -1
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +11 -10
- data/lib/vimamsa/string_util.rb +120 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +3 -0
- data/lib/vimamsa/text_objects.rb +353 -0
- data/lib/vimamsa/text_transforms.rb +14 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +0 -1
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.sh +130 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -0
- data/scripts/demo/demo_steps.txt +59 -0
- data/scripts/demo/record_demo.rb +177 -0
- data/scripts/demo/shapes.rb +28 -0
- data/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +33 -3
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +85 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +129 -0
- data/tests/test_copy_paste.rb +80 -0
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_keylog_panel.rb +101 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +329 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_vim_bindings.rb +252 -0
- data/tests/test_vim_conflicts.rb +63 -0
- data/tests/test_window_layout.rb +219 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +109 -0
- metadata +112 -10
data/lib/vimamsa/gui.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
$idle_scroll_to_mark = false
|
|
2
4
|
|
|
3
5
|
$removed_controllers = []
|
|
@@ -19,25 +21,6 @@ def end_profiler
|
|
|
19
21
|
printer.print(STDOUT)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
# Wait for window resize to take effect
|
|
23
|
-
# GTk3 had a resize notify event which got removed in gtk4
|
|
24
|
-
# https://discourse.gnome.org/t/gtk4-any-way-to-connect-to-a-window-resize-signal/14869/3
|
|
25
|
-
def wait_for_resize(window, tries = 200)
|
|
26
|
-
i = 0
|
|
27
|
-
widthold = @window.width
|
|
28
|
-
heightold = @window.height
|
|
29
|
-
while true
|
|
30
|
-
iterate_gui_main_loop
|
|
31
|
-
break if widthold != window.width
|
|
32
|
-
break if heightold != window.height
|
|
33
|
-
if i >= tries
|
|
34
|
-
debug "i >= tries", 2
|
|
35
|
-
break
|
|
36
|
-
end
|
|
37
|
-
i += 1
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
24
|
def gui_remove_controllers(widget)
|
|
42
25
|
clist = widget.observe_controllers
|
|
43
26
|
to_remove = []
|
|
@@ -61,6 +44,7 @@ def gui_open_file_dialog(dirpath)
|
|
|
61
44
|
:action => :open,
|
|
62
45
|
:buttons => [["Open", :accept],
|
|
63
46
|
["Cancel", :cancel]])
|
|
47
|
+
dialog.add_css_class("vma-dialog")
|
|
64
48
|
dialog.set_current_folder(Gio::File.new_for_path(dirpath))
|
|
65
49
|
|
|
66
50
|
dialog.signal_connect("response") do |dialog, response_id|
|
|
@@ -79,6 +63,7 @@ def gui_file_saveas(dirpath)
|
|
|
79
63
|
:action => :save,
|
|
80
64
|
:buttons => [["Save", :accept],
|
|
81
65
|
["Cancel", :cancel]])
|
|
66
|
+
dialog.add_css_class("vma-dialog")
|
|
82
67
|
dialog.set_current_folder(Gio::File.new_for_path(dirpath))
|
|
83
68
|
dialog.signal_connect("response") do |dialog, response_id|
|
|
84
69
|
if response_id == Gtk::ResponseType::ACCEPT
|
|
@@ -135,6 +120,7 @@ def gui_create_buffer(id, bufo)
|
|
|
135
120
|
view.set_highlight_current_line(true)
|
|
136
121
|
view.set_show_line_numbers(true)
|
|
137
122
|
view.set_buffer(buf1)
|
|
123
|
+
view.register_buffer_signals()
|
|
138
124
|
|
|
139
125
|
provider = Gtk::CssProvider.new
|
|
140
126
|
|
|
@@ -184,17 +170,26 @@ def gui_set_current_buffer(id)
|
|
|
184
170
|
return
|
|
185
171
|
end
|
|
186
172
|
|
|
187
|
-
def gui_set_window_title(wtitle, subtitle = "")
|
|
173
|
+
def gui_set_window_title(wtitle, subtitle = "", modified: false)
|
|
188
174
|
wtitle = wtitle[0..150]
|
|
189
175
|
$vmag.window.title = "Vimamsa - #{wtitle}"
|
|
190
|
-
#
|
|
191
|
-
|
|
176
|
+
# Subtitle shows the file path: dim directory, bright basename,
|
|
177
|
+
# "+ " when there are unsaved changes (same marker as the window title;
|
|
178
|
+
# no fixed color, so it follows the theme).
|
|
179
|
+
subtitle = subtitle.to_s
|
|
180
|
+
dir = File.dirname(subtitle)
|
|
181
|
+
dir = (dir == ".") ? "" : (dir == "/" ? "/" : "#{dir}/")
|
|
182
|
+
base = File.basename(subtitle)
|
|
183
|
+
mark = modified ? "<span weight='bold'>+ </span>" : ""
|
|
184
|
+
$vmag.subtitle.markup = "<span size='small'>#{mark}" \
|
|
185
|
+
"<span alpha='55%'>#{CGI.escapeHTML(dir)}</span>" \
|
|
186
|
+
"<span weight='bold' alpha='92%'>#{CGI.escapeHTML(base)}</span></span>"
|
|
192
187
|
# $vmag.window.titlebar.subtitle = subtitle #TODO:gtk4
|
|
193
188
|
end
|
|
194
189
|
|
|
195
190
|
class VMAgui
|
|
196
|
-
attr_accessor :buffers, :sw1, :sw2, :view, :buf1, :window, :delex, :statnfo, :overlay, :sws, :two_c
|
|
197
|
-
attr_reader :two_column, :windows, :subtitle, :app, :active_window, :action_trail_label, :file_panel, :func_panel
|
|
191
|
+
attr_accessor :buffers, :sw1, :sw2, :view, :buf1, :window, :delex, :statnfo, :overlay, :sws, :two_c, :scheme_is_light, :cyber_css_provider, :chrome_css_provider, :minibuf_css_provider, :orig_icon_theme
|
|
192
|
+
attr_reader :two_column, :windows, :subtitle, :app, :active_window, :action_trail_label, :file_panel, :func_panel, :keylog_panel, :keytrail, :cmd_line
|
|
198
193
|
|
|
199
194
|
def initialize()
|
|
200
195
|
@two_column = false
|
|
@@ -217,6 +212,12 @@ class VMAgui
|
|
|
217
212
|
@entry_has_focus = active
|
|
218
213
|
end
|
|
219
214
|
|
|
215
|
+
# True while a text entry (command line, calculator field, ...) owns the
|
|
216
|
+
# keyboard focus and the editor view must not steal it back.
|
|
217
|
+
def entry_focused?
|
|
218
|
+
@entry_has_focus
|
|
219
|
+
end
|
|
220
|
+
|
|
220
221
|
def run
|
|
221
222
|
init_window
|
|
222
223
|
# init_rtext
|
|
@@ -395,9 +396,9 @@ class VMAgui
|
|
|
395
396
|
@minibuf_expanded = false
|
|
396
397
|
@minibuf_history_height = 120
|
|
397
398
|
|
|
398
|
-
css = "label.minibuf, textview.minibuf { color: #cdd6f4; font-family: Monospace; font-size: 10pt; padding: 3px 8px; background-color: #1e1e2e; }"
|
|
399
399
|
provider = Gtk::CssProvider.new
|
|
400
|
-
provider.load(data:
|
|
400
|
+
provider.load(data: minibuf_css) # colors from gui_theme.rb (cnf-backed)
|
|
401
|
+
self.minibuf_css_provider = provider
|
|
401
402
|
|
|
402
403
|
# Collapsed view: single line, latest message
|
|
403
404
|
@minibuf_label = Gtk::Label.new("")
|
|
@@ -428,6 +429,10 @@ class VMAgui
|
|
|
428
429
|
@minibuf_stack.add_named(@minibuf_label, "label")
|
|
429
430
|
@minibuf_stack.add_named(scroll, "history")
|
|
430
431
|
|
|
432
|
+
# Interactive command line (vim-style ":"), third stack child
|
|
433
|
+
@cmd_line = CommandLine.new(provider)
|
|
434
|
+
@minibuf_stack.add_named(@cmd_line.widget, "cmdline")
|
|
435
|
+
|
|
431
436
|
@minibuf_content = Gtk::Box.new(:vertical, 0)
|
|
432
437
|
@minibuf_content.append(Gtk::Separator.new(:horizontal))
|
|
433
438
|
@minibuf_content.append(@minibuf_stack)
|
|
@@ -450,6 +455,24 @@ class VMAgui
|
|
|
450
455
|
@minibuf_hide_source = nil
|
|
451
456
|
end
|
|
452
457
|
|
|
458
|
+
# ── command line (vim-style ":", see gui_command_line.rb) ─────────────────
|
|
459
|
+
|
|
460
|
+
def cmd_line_show
|
|
461
|
+
GLib::Source.remove(@minibuf_hide_source) if @minibuf_hide_source
|
|
462
|
+
@minibuf_hide_source = nil
|
|
463
|
+
@minibuf_content.visible = true
|
|
464
|
+
@minibuf_stack.visible_child_name = "cmdline"
|
|
465
|
+
@minibuf_vpane.position = @minibuf_vpane.height - 34 unless @minibuf_expanded
|
|
466
|
+
notify_entry_focus(true)
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
def cmd_line_hide
|
|
470
|
+
notify_entry_focus(false)
|
|
471
|
+
@minibuf_stack.visible_child_name = @minibuf_expanded ? "history" : "label"
|
|
472
|
+
@minibuf_content.visible = false unless @minibuf_expanded
|
|
473
|
+
vma.buf.view.grab_focus if vma.buf&.view
|
|
474
|
+
end
|
|
475
|
+
|
|
453
476
|
def make_header_button(action_id, icon, cb)
|
|
454
477
|
act = Gio::SimpleAction.new(action_id)
|
|
455
478
|
@app.add_action(act)
|
|
@@ -498,7 +521,6 @@ class VMAgui
|
|
|
498
521
|
start_ripl
|
|
499
522
|
end
|
|
500
523
|
|
|
501
|
-
sleep 0.02
|
|
502
524
|
return true
|
|
503
525
|
end
|
|
504
526
|
|
|
@@ -584,33 +606,15 @@ class VMAgui
|
|
|
584
606
|
end
|
|
585
607
|
end
|
|
586
608
|
|
|
587
|
-
def idle_set_size()
|
|
588
|
-
# Need to wait for a while to window to be maximized to get correct @window.width
|
|
589
|
-
@window.maximize
|
|
590
|
-
wait_for_resize(@window)
|
|
591
|
-
# Set new size as half of the screeen
|
|
592
|
-
width = @window.width / 2
|
|
593
|
-
height = @window.height - 5
|
|
594
|
-
width = 600 if width < 600
|
|
595
|
-
height = 600 if height < 600
|
|
596
|
-
|
|
597
|
-
#Minimum size:
|
|
598
|
-
@window.set_size_request(600, 600)
|
|
599
|
-
@window.set_default_size(width, height)
|
|
600
|
-
debug "size #{[width, height]}", 2
|
|
601
|
-
@window.unmaximize
|
|
602
|
-
|
|
603
|
-
#set_default_size doesn't always have effect if run immediately
|
|
604
|
-
wait_for_resize(@window)
|
|
605
|
-
@window.set_default_size(width, height)
|
|
606
|
-
|
|
607
|
-
return false
|
|
608
|
-
end
|
|
609
|
-
|
|
610
609
|
def init_window
|
|
611
610
|
@last_debug_idle = Time.now
|
|
612
|
-
|
|
611
|
+
# Stable application id so desktop environments can match the running window
|
|
612
|
+
# to its launcher entry / icon (see desktop_install.rb). :non_unique avoids
|
|
613
|
+
# GTK's D-Bus single-instance enforcement (single-instance forwarding is
|
|
614
|
+
# handled separately via the listen file in exe/vimamsa).
|
|
615
|
+
app = Gtk::Application.new(VMA_APP_ID, :non_unique)
|
|
613
616
|
@app = app
|
|
617
|
+
Gtk::Window.set_default_icon_name("vimamsa")
|
|
614
618
|
|
|
615
619
|
Gtk::Settings.default.gtk_application_prefer_dark_theme = true
|
|
616
620
|
Gtk::Settings.default.gtk_theme_name = "Adwaita"
|
|
@@ -632,9 +636,10 @@ class VMAgui
|
|
|
632
636
|
@vbox = Gtk::Grid.new()
|
|
633
637
|
@window.set_child(@vbox)
|
|
634
638
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
639
|
+
# Periodic timeouts, not idles that always return true: an idle that is
|
|
640
|
+
# always ready keeps GLib from ever dispatching lower-priority sources,
|
|
641
|
+
# e.g. GtkSourceView's matching-bracket highlight never ran.
|
|
642
|
+
GLib::Timeout.add(200) { debug_idle_func }
|
|
638
643
|
|
|
639
644
|
reset_controllers
|
|
640
645
|
|
|
@@ -662,23 +667,31 @@ class VMAgui
|
|
|
662
667
|
|
|
663
668
|
@last_adj_time = Time.now
|
|
664
669
|
|
|
665
|
-
# To show keyboard key binding state
|
|
670
|
+
# To show keyboard key binding state (mode badge, e.g. COMMAND)
|
|
666
671
|
@statnfo = Gtk::Label.new
|
|
672
|
+
@statnfo.add_css_class("mode-badge")
|
|
673
|
+
|
|
674
|
+
# Pending key chord / repeat count next to the mode badge
|
|
675
|
+
@keytrail = Gtk::Label.new("")
|
|
676
|
+
@keytrail.add_css_class("keytrail")
|
|
667
677
|
|
|
668
678
|
# To show e.g. current folder
|
|
669
679
|
@subtitle = Gtk::Label.new("")
|
|
670
680
|
|
|
671
|
-
|
|
672
|
-
|
|
681
|
+
# Persistent status slots for long-running work that outlives a minibuf
|
|
682
|
+
# line — e.g. dictation reporting that its speech model is still loading.
|
|
683
|
+
# Modules claim a slot by key via #set_status_indicator; core attaches no
|
|
684
|
+
# meaning to the keys.
|
|
685
|
+
@status_indicators = {}
|
|
686
|
+
@status_indicator_css = {}
|
|
687
|
+
@status_indicator_box = Gtk::Box.new(:horizontal, 6)
|
|
688
|
+
|
|
689
|
+
@statbox = Gtk::Box.new(:horizontal, 6)
|
|
673
690
|
@statbox.append(@subtitle)
|
|
674
691
|
@subtitle.hexpand = true
|
|
692
|
+
@statbox.append(@status_indicator_box)
|
|
693
|
+
@statbox.append(@keytrail)
|
|
675
694
|
@statbox.append(@statnfo)
|
|
676
|
-
provider = Gtk::CssProvider.new
|
|
677
|
-
@statnfo.add_css_class("statnfo")
|
|
678
|
-
provider.load(data: "label.statnfo { background-color:#353535; font-size: 10pt; margin-top:2px; margin-bottom:2px; align:right;}")
|
|
679
|
-
|
|
680
|
-
provider = Gtk::CssProvider.new
|
|
681
|
-
@statnfo.style_context.add_provider(provider)
|
|
682
695
|
|
|
683
696
|
# numbers: left, top, width, height
|
|
684
697
|
@vbox.attach(@windows[1][:overlay], 0, 2, 2, 1)
|
|
@@ -701,6 +714,7 @@ class VMAgui
|
|
|
701
714
|
@action_trail_label = Gtk::Label.new("")
|
|
702
715
|
@action_trail_label.add_css_class("action-trail")
|
|
703
716
|
menubar_row = Gtk::Box.new(:horizontal, 0)
|
|
717
|
+
menubar_row.add_css_class("menubar-row")
|
|
704
718
|
menubar_row.append(menubar_bar)
|
|
705
719
|
menubar_row.append(@action_trail_label)
|
|
706
720
|
@vbox.attach(menubar_row, 0, 0, 2, 1)
|
|
@@ -710,7 +724,11 @@ class VMAgui
|
|
|
710
724
|
init_header_bar
|
|
711
725
|
file_panel_init
|
|
712
726
|
func_panel_init
|
|
727
|
+
keylog_panel_init
|
|
713
728
|
|
|
729
|
+
# Size the window before it is first shown (see apply_startup_window_size)
|
|
730
|
+
apply_startup_window_size
|
|
731
|
+
@window.signal_connect("map") { layout_recheck_monitor }
|
|
714
732
|
@window.show
|
|
715
733
|
|
|
716
734
|
surface = @window.native.surface
|
|
@@ -719,61 +737,115 @@ class VMAgui
|
|
|
719
737
|
# puts "Window resized or moved, other redraw."
|
|
720
738
|
end
|
|
721
739
|
|
|
722
|
-
run_as_idle proc { idle_set_size }
|
|
723
740
|
|
|
724
|
-
|
|
741
|
+
# Baseline chrome CSS + all its colors live in gui_theme.rb (cnf-backed).
|
|
725
742
|
# See gtk-4.9.4/gtk/theme/Default/_common.scss on how to theme
|
|
726
743
|
# gtksourceview/gtksourcestyleschemepreview.c
|
|
727
744
|
# gtksourceview/gtksourcestylescheme.c
|
|
728
|
-
prov
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
textview border.left gutter { padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; color: #8aa; font-size:9pt; }
|
|
733
|
-
|
|
734
|
-
headerbar .title {
|
|
735
|
-
font-weight: bold;
|
|
736
|
-
font-size: 11pt;
|
|
737
|
-
color: #cdffee;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
headerbar > windowhandle > box .start {
|
|
741
|
-
border-spacing: 6px;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
headerbar windowcontrols button {
|
|
745
|
-
min-height: 15px;
|
|
746
|
-
min-width: 15px;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
popover background > contents { padding: 8px; border-radius: 20px; }
|
|
750
|
-
|
|
751
|
-
label.action-trail { font-family: monospace; font-size: 10pt; margin-right: 8px; color: #aaaaaa; }
|
|
752
|
-
")
|
|
745
|
+
prov = Gtk::CssProvider.new
|
|
746
|
+
prov.load(data: base_chrome_css)
|
|
747
|
+
self.chrome_css_provider = prov
|
|
753
748
|
@window.style_context.add_provider(prov)
|
|
754
749
|
|
|
755
750
|
sc = Gtk::StyleContext.add_provider_for_display(Gdk::Display.default, prov)
|
|
756
751
|
|
|
757
752
|
vma.start
|
|
753
|
+
|
|
754
|
+
# After vma.start: user settings.rb (which may enable the theme) is
|
|
755
|
+
# loaded during Editor#start. Refresh reads any cnf color overrides and
|
|
756
|
+
# installs the cyberpunk provider if enabled.
|
|
757
|
+
gui_refresh_colors
|
|
758
758
|
end
|
|
759
759
|
|
|
760
|
-
GLib::
|
|
760
|
+
GLib::Timeout.add(200) { self.monitor }
|
|
761
761
|
|
|
762
762
|
app.run
|
|
763
763
|
end
|
|
764
764
|
|
|
765
|
+
# CSS class of mode badge label per mode key_name; others get "mode-other"
|
|
766
|
+
MODE_BADGE_CSS = { "C" => "mode-command", "I" => "mode-insert", "V" => "mode-visual",
|
|
767
|
+
"B" => "mode-browse", "X" => "mode-replace" }.freeze
|
|
768
|
+
|
|
769
|
+
# Render the mode badge and pending key chord in the status area.
|
|
770
|
+
# Subscribed to KeyBindingTree's :state_trail_changed event.
|
|
771
|
+
def update_mode_badge(badge, badge_key, trail)
|
|
772
|
+
cls = MODE_BADGE_CSS.fetch(badge_key, "mode-other")
|
|
773
|
+
if cls != @badge_css_class
|
|
774
|
+
@statnfo.remove_css_class(@badge_css_class) if @badge_css_class
|
|
775
|
+
@statnfo.add_css_class(cls)
|
|
776
|
+
@badge_css_class = cls
|
|
777
|
+
end
|
|
778
|
+
@statnfo.text = badge if badge != @last_badge_text
|
|
779
|
+
@keytrail.text = trail if trail != @last_trail_text
|
|
780
|
+
@last_badge_text = badge
|
|
781
|
+
@last_trail_text = trail
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
# Show a persistent status message in its own slot in the status area, for
|
|
785
|
+
# work that takes long enough that the user needs to see it is still going —
|
|
786
|
+
# a minibuf line scrolls away and is easy to miss. `key` namespaces the slot
|
|
787
|
+
# (one per module/feature), `text` nil or empty removes it, `css_class` styles
|
|
788
|
+
# the label. Call from the main thread (GLib::Idle.add from a worker thread).
|
|
789
|
+
def set_status_indicator(key, text, css_class: nil)
|
|
790
|
+
return if @status_indicator_box.nil? # GUI not built yet
|
|
791
|
+
label = @status_indicators[key]
|
|
792
|
+
|
|
793
|
+
if text.nil? || text.to_s.empty?
|
|
794
|
+
return if label.nil?
|
|
795
|
+
@status_indicator_box.remove(label)
|
|
796
|
+
@status_indicators.delete(key)
|
|
797
|
+
@status_indicator_css.delete(key)
|
|
798
|
+
return
|
|
799
|
+
end
|
|
800
|
+
|
|
801
|
+
if label.nil?
|
|
802
|
+
label = Gtk::Label.new("")
|
|
803
|
+
label.add_css_class("status-indicator")
|
|
804
|
+
@status_indicators[key] = label
|
|
805
|
+
@status_indicator_box.append(label)
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
if css_class != @status_indicator_css[key]
|
|
809
|
+
prev = @status_indicator_css[key]
|
|
810
|
+
label.remove_css_class(prev) if prev
|
|
811
|
+
label.add_css_class(css_class) if css_class
|
|
812
|
+
@status_indicator_css[key] = css_class
|
|
813
|
+
end
|
|
814
|
+
label.text = text.to_s
|
|
815
|
+
end
|
|
816
|
+
|
|
817
|
+
# Text currently shown in a status slot, nil when the slot is empty.
|
|
818
|
+
def status_indicator(key)
|
|
819
|
+
@status_indicators[key]&.text
|
|
820
|
+
end
|
|
821
|
+
|
|
822
|
+
# Show the last executed key chord and action next to the menubar.
|
|
823
|
+
# Subscribed to KeyBindingTree's :action_handled event.
|
|
824
|
+
def show_action_trail(trail_str, action)
|
|
825
|
+
return if !cnf.kbd.show_prev_action? or trail_str.class != String
|
|
826
|
+
len_limit = 35
|
|
827
|
+
if action.class == String && (m = action.match(/\Abuf\.insert_txt\((.+)\)\z/))
|
|
828
|
+
action_desc = "insert #{m[1]}"
|
|
829
|
+
else
|
|
830
|
+
action_desc = vma.actions[action]&.method_name || action.to_s
|
|
831
|
+
action_desc = action_desc[0..len_limit] if action_desc.size > len_limit
|
|
832
|
+
end
|
|
833
|
+
trail_esc = CGI.escapeHTML(trail_str)
|
|
834
|
+
action_esc = CGI.escapeHTML(action_desc)
|
|
835
|
+
# Completed key chord bright, executed action name dim
|
|
836
|
+
@action_trail_label.markup = "<span alpha='70%'>#{trail_esc} #{action_esc}</span>"
|
|
837
|
+
end
|
|
838
|
+
|
|
765
839
|
def monitor
|
|
840
|
+
return true if @windows[1].nil?
|
|
766
841
|
swa = @windows[1][:sw]
|
|
767
|
-
@monitor_time ||= Time.now
|
|
768
842
|
@sw_width ||= swa.width
|
|
769
|
-
return true if Time.now - @monitor_time < 0.2
|
|
770
843
|
# Detect element resize
|
|
771
844
|
if swa.width != @sw_width
|
|
772
845
|
debug "Width change sw_width #{@sw_width}"
|
|
773
846
|
@sw_width = swa.width
|
|
774
847
|
DelayExecutioner.exec(id: :scale_images, wait: 0.7, callable: proc { debug ":scale_images"; vma.gui.scale_all_images })
|
|
775
848
|
end
|
|
776
|
-
@monitor_time = Time.now
|
|
777
849
|
return true
|
|
778
850
|
end
|
|
779
851
|
|
|
@@ -791,6 +863,7 @@ class VMAgui
|
|
|
791
863
|
else
|
|
792
864
|
set_two_column
|
|
793
865
|
end
|
|
866
|
+
save_window_layout
|
|
794
867
|
end
|
|
795
868
|
|
|
796
869
|
def set_one_column
|
|
@@ -798,6 +871,7 @@ class VMAgui
|
|
|
798
871
|
#This always closes the leftmost column/window
|
|
799
872
|
#TODO: close rightmost column if left active
|
|
800
873
|
set_active_window(1)
|
|
874
|
+
@column_split = @pane.position # kept for the next set_two_column
|
|
801
875
|
|
|
802
876
|
@windows[2][:sw].set_child(nil)
|
|
803
877
|
@windows.delete(2)
|
|
@@ -819,6 +893,7 @@ class VMAgui
|
|
|
819
893
|
def new_window(win_id)
|
|
820
894
|
n_sw = Gtk::ScrolledWindow.new
|
|
821
895
|
n_sw.set_policy(:automatic, :automatic)
|
|
896
|
+
n_sw.add_css_class("editor-frame")
|
|
822
897
|
n_overlay = Gtk::Overlay.new
|
|
823
898
|
n_overlay.add_overlay(n_sw)
|
|
824
899
|
# @pane = Gtk::Paned.new(:horizontal)
|
|
@@ -864,6 +939,7 @@ class VMAgui
|
|
|
864
939
|
|
|
865
940
|
# Remove overlay from its current parent and add the Gtk::Paned instead
|
|
866
941
|
@pane = Gtk::Paned.new(:horizontal)
|
|
942
|
+
@pane.set_position(@column_split) if @column_split.to_i > 0
|
|
867
943
|
if @func_panel_shown
|
|
868
944
|
@func_panel_pane.set_end_child(nil)
|
|
869
945
|
@pane.set_start_child(w2[:overlay])
|
|
@@ -1037,6 +1113,21 @@ class VMAgui
|
|
|
1037
1113
|
view.draw_cursor
|
|
1038
1114
|
end
|
|
1039
1115
|
|
|
1116
|
+
# Wrap a side panel widget and the current editor content in a horizontal
|
|
1117
|
+
# Paned with the panel on the left at the given divider position.
|
|
1118
|
+
def make_side_pane(panel_widget, inner, pos)
|
|
1119
|
+
pane = Gtk::Paned.new(:horizontal)
|
|
1120
|
+
pane.hexpand = true
|
|
1121
|
+
pane.vexpand = true
|
|
1122
|
+
pane.set_start_child(panel_widget)
|
|
1123
|
+
pane.set_end_child(inner)
|
|
1124
|
+
# The panel keeps its width when the window is resized (or maximized
|
|
1125
|
+
# during startup); the editor takes the difference
|
|
1126
|
+
pane.resize_start_child = false
|
|
1127
|
+
pane.set_position(pos)
|
|
1128
|
+
pane
|
|
1129
|
+
end
|
|
1130
|
+
|
|
1040
1131
|
def file_panel_init
|
|
1041
1132
|
@file_panel = FileTreePanel.new
|
|
1042
1133
|
@file_panel_shown = false
|
|
@@ -1047,6 +1138,37 @@ class VMAgui
|
|
|
1047
1138
|
@file_panel.refresh
|
|
1048
1139
|
end
|
|
1049
1140
|
|
|
1141
|
+
# Marks of the current buffer changed (set, or shifted by an edit): update
|
|
1142
|
+
# the panel's marks section, coalescing bursts (typing) into one update.
|
|
1143
|
+
def file_panel_marks_changed
|
|
1144
|
+
return unless @file_panel_shown
|
|
1145
|
+
return if @file_panel_marks_pending
|
|
1146
|
+
@file_panel_marks_pending = true
|
|
1147
|
+
GLib::Timeout.add(300) do
|
|
1148
|
+
@file_panel_marks_pending = false
|
|
1149
|
+
@file_panel.refresh_marks if @file_panel_shown
|
|
1150
|
+
false
|
|
1151
|
+
end
|
|
1152
|
+
end
|
|
1153
|
+
|
|
1154
|
+
def file_panel_shown?
|
|
1155
|
+
@file_panel_shown
|
|
1156
|
+
end
|
|
1157
|
+
|
|
1158
|
+
# alt-h / alt-l: previous/next file in the panel's display order.
|
|
1159
|
+
# A no-op while the panel is hidden.
|
|
1160
|
+
def file_panel_select_adjacent(delta)
|
|
1161
|
+
return unless @file_panel_shown
|
|
1162
|
+
@file_panel.select_adjacent(delta)
|
|
1163
|
+
end
|
|
1164
|
+
|
|
1165
|
+
# g s: label the panel's file rows and switch to the file whose label is
|
|
1166
|
+
# typed (see FileTreePanel#easy_jump_start). A no-op while the panel is hidden.
|
|
1167
|
+
def file_panel_easy_jump
|
|
1168
|
+
return unless @file_panel_shown
|
|
1169
|
+
@file_panel.easy_jump_start
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1050
1172
|
def show_file_panel
|
|
1051
1173
|
return if @file_panel_shown
|
|
1052
1174
|
# If func panel is shown it sits in minibuf_vpane; wrap it too
|
|
@@ -1058,12 +1180,7 @@ class VMAgui
|
|
|
1058
1180
|
@windows[1][:overlay]
|
|
1059
1181
|
end
|
|
1060
1182
|
@minibuf_vpane.set_start_child(nil) # unparent inner before re-parenting
|
|
1061
|
-
@file_panel_pane =
|
|
1062
|
-
@file_panel_pane.hexpand = true
|
|
1063
|
-
@file_panel_pane.vexpand = true
|
|
1064
|
-
@file_panel_pane.set_start_child(@file_panel.widget)
|
|
1065
|
-
@file_panel_pane.set_end_child(inner)
|
|
1066
|
-
@file_panel_pane.set_position(180)
|
|
1183
|
+
@file_panel_pane = make_side_pane(@file_panel.widget, inner, @file_panel_width || PANEL_DEFAULT_WIDTH[:file_panel])
|
|
1067
1184
|
set_editor_area(@file_panel_pane)
|
|
1068
1185
|
@file_panel_shown = true
|
|
1069
1186
|
@file_panel.refresh
|
|
@@ -1071,6 +1188,7 @@ class VMAgui
|
|
|
1071
1188
|
|
|
1072
1189
|
def hide_file_panel
|
|
1073
1190
|
return unless @file_panel_shown
|
|
1191
|
+
@file_panel_width = @file_panel_pane.position
|
|
1074
1192
|
inner = @file_panel_pane.end_child
|
|
1075
1193
|
@file_panel_pane.set_start_child(nil)
|
|
1076
1194
|
@file_panel_pane.set_end_child(nil)
|
|
@@ -1078,8 +1196,11 @@ class VMAgui
|
|
|
1078
1196
|
@file_panel_shown = false
|
|
1079
1197
|
end
|
|
1080
1198
|
|
|
1199
|
+
# The shown/hidden state is remembered across restarts (see
|
|
1200
|
+
# save_window_layout). Tests toggle the panel too; they must not clobber it.
|
|
1081
1201
|
def toggle_file_panel
|
|
1082
1202
|
@file_panel_shown ? hide_file_panel : show_file_panel
|
|
1203
|
+
save_window_layout
|
|
1083
1204
|
end
|
|
1084
1205
|
|
|
1085
1206
|
def func_panel_init
|
|
@@ -1104,12 +1225,7 @@ class VMAgui
|
|
|
1104
1225
|
inner = @windows[1][:overlay]
|
|
1105
1226
|
@minibuf_vpane.set_start_child(nil)
|
|
1106
1227
|
end
|
|
1107
|
-
@func_panel_pane =
|
|
1108
|
-
@func_panel_pane.hexpand = true
|
|
1109
|
-
@func_panel_pane.vexpand = true
|
|
1110
|
-
@func_panel_pane.set_start_child(@func_panel.widget)
|
|
1111
|
-
@func_panel_pane.set_end_child(inner)
|
|
1112
|
-
@func_panel_pane.set_position(160)
|
|
1228
|
+
@func_panel_pane = make_side_pane(@func_panel.widget, inner, @func_panel_width || PANEL_DEFAULT_WIDTH[:func_panel])
|
|
1113
1229
|
if @file_panel_shown
|
|
1114
1230
|
@file_panel_pane.set_end_child(@func_panel_pane)
|
|
1115
1231
|
else
|
|
@@ -1121,6 +1237,7 @@ class VMAgui
|
|
|
1121
1237
|
|
|
1122
1238
|
def hide_func_panel
|
|
1123
1239
|
return unless @func_panel_shown
|
|
1240
|
+
@func_panel_width = @func_panel_pane.position
|
|
1124
1241
|
inner = @func_panel_pane.end_child
|
|
1125
1242
|
@func_panel_pane.set_start_child(nil)
|
|
1126
1243
|
@func_panel_pane.set_end_child(nil)
|
|
@@ -1134,5 +1251,302 @@ class VMAgui
|
|
|
1134
1251
|
|
|
1135
1252
|
def toggle_func_panel
|
|
1136
1253
|
@func_panel_shown ? hide_func_panel : show_func_panel
|
|
1254
|
+
save_window_layout
|
|
1255
|
+
end
|
|
1256
|
+
|
|
1257
|
+
def keylog_panel_init
|
|
1258
|
+
@keylog_panel = KeyLogPanel.new
|
|
1259
|
+
@keylog_shown = false
|
|
1260
|
+
end
|
|
1261
|
+
|
|
1262
|
+
# The key log wraps @minibuf_vpane at the grid level (right side), so it is
|
|
1263
|
+
# independent of the file/func panel and two-column nesting, which only
|
|
1264
|
+
# touch @minibuf_vpane's start child.
|
|
1265
|
+
def show_keylog_panel
|
|
1266
|
+
return if @keylog_shown
|
|
1267
|
+
@vbox.remove(@minibuf_vpane)
|
|
1268
|
+
@keylog_pane = Gtk::Paned.new(:horizontal)
|
|
1269
|
+
@keylog_pane.hexpand = true
|
|
1270
|
+
@keylog_pane.vexpand = true
|
|
1271
|
+
@keylog_pane.set_start_child(@minibuf_vpane)
|
|
1272
|
+
@keylog_pane.set_end_child(@keylog_panel.widget)
|
|
1273
|
+
@keylog_pane.resize_start_child = true # editor absorbs window resize
|
|
1274
|
+
@keylog_pane.resize_end_child = false # log keeps its width
|
|
1275
|
+
@keylog_pane.shrink_end_child = false
|
|
1276
|
+
@vbox.attach(@keylog_pane, 0, 2, 2, 1)
|
|
1277
|
+
@keylog_shown = true
|
|
1278
|
+
@keylog_panel.set_active(true)
|
|
1279
|
+
# Always set a position: left unset, GtkPaned sizes the panel from the
|
|
1280
|
+
# natural (unwrapped) width of its labels, so long entries widen it
|
|
1281
|
+
set_keylog_width(@keylog_width || PANEL_DEFAULT_WIDTH[:keylog])
|
|
1282
|
+
end
|
|
1283
|
+
|
|
1284
|
+
def hide_keylog_panel
|
|
1285
|
+
return unless @keylog_shown
|
|
1286
|
+
@keylog_width = keylog_width
|
|
1287
|
+
@keylog_panel.set_active(false)
|
|
1288
|
+
@keylog_pane.set_start_child(nil)
|
|
1289
|
+
@keylog_pane.set_end_child(nil)
|
|
1290
|
+
@vbox.remove(@keylog_pane)
|
|
1291
|
+
@vbox.attach(@minibuf_vpane, 0, 2, 2, 1)
|
|
1292
|
+
@keylog_shown = false
|
|
1293
|
+
end
|
|
1294
|
+
|
|
1295
|
+
def toggle_keylog_panel
|
|
1296
|
+
@keylog_shown ? hide_keylog_panel : show_keylog_panel
|
|
1297
|
+
save_window_layout
|
|
1298
|
+
end
|
|
1299
|
+
|
|
1300
|
+
# ── Window geometry and view layout, restored on startup ─────────────────
|
|
1301
|
+
# doc/TODO.md: "Restore window geometry and view layout on startup".
|
|
1302
|
+
# Saved by Editor#save_state (shutdown, restart) and when a column or panel
|
|
1303
|
+
# is toggled, to get_data_path("window_layout"): one layout per screen
|
|
1304
|
+
# resolution ("1920x1080@1" = logical monitor size @ scale factor), the
|
|
1305
|
+
# LAYOUT_KEEP most recently used. With no layout for the current resolution
|
|
1306
|
+
# the most recent one is fitted to the screen (fit_view_layout). GTK4 can't
|
|
1307
|
+
# place windows on Wayland, so only the size and maximized state are kept.
|
|
1308
|
+
# Test runs neither read nor write it; cnf.restore_layout = false turns it off.
|
|
1309
|
+
|
|
1310
|
+
LAYOUT_FILE = "window_layout"
|
|
1311
|
+
LAYOUT_KEEP = 5
|
|
1312
|
+
EDITOR_MIN_WIDTH = 300
|
|
1313
|
+
WINDOW_MIN_SIZE = 600
|
|
1314
|
+
DEFAULT_WINDOW_SIZE = [1000, 800]
|
|
1315
|
+
PANEL_DEFAULT_WIDTH = { :file_panel => 180, :func_panel => 160, :keylog => 320 }
|
|
1316
|
+
SIDE_PANELS = [:file_panel, :func_panel, :keylog]
|
|
1317
|
+
|
|
1318
|
+
def layout_enabled?
|
|
1319
|
+
!vma_test_mode? && cnf.restore_layout? != false
|
|
1320
|
+
end
|
|
1321
|
+
|
|
1322
|
+
# Monitor the window is on. Before the window is mapped that isn't known:
|
|
1323
|
+
# then the first monitor (layout_recheck_monitor corrects a wrong guess).
|
|
1324
|
+
def layout_monitor
|
|
1325
|
+
d = Gdk::Display.default
|
|
1326
|
+
surface = (@window.native&.surface rescue nil)
|
|
1327
|
+
m = (d.get_monitor_at_surface(surface) rescue nil) if surface
|
|
1328
|
+
m || (d.monitors.get_item(0) rescue nil)
|
|
1329
|
+
end
|
|
1330
|
+
|
|
1331
|
+
def monitor_key(m)
|
|
1332
|
+
return "unknown" if m.nil?
|
|
1333
|
+
g = m.geometry
|
|
1334
|
+
"#{g.width}x#{g.height}@#{m.scale_factor}"
|
|
1335
|
+
end
|
|
1336
|
+
|
|
1337
|
+
def monitor_size(m)
|
|
1338
|
+
return [100_000, 100_000] if m.nil?
|
|
1339
|
+
g = m.geometry
|
|
1340
|
+
[g.width, g.height]
|
|
1341
|
+
end
|
|
1342
|
+
|
|
1343
|
+
def file_panel_width
|
|
1344
|
+
@file_panel_shown ? @file_panel_pane.position : @file_panel_width
|
|
1345
|
+
end
|
|
1346
|
+
|
|
1347
|
+
def func_panel_width
|
|
1348
|
+
@func_panel_shown ? @func_panel_pane.position : @func_panel_width
|
|
1349
|
+
end
|
|
1350
|
+
|
|
1351
|
+
def keylog_width
|
|
1352
|
+
return @keylog_width unless @keylog_shown && @keylog_pane.width > 0
|
|
1353
|
+
@keylog_pane.width - @keylog_pane.position
|
|
1354
|
+
end
|
|
1355
|
+
|
|
1356
|
+
# The key log is on the right: its divider position depends on the total
|
|
1357
|
+
# width, which is known only once the pane has been allocated.
|
|
1358
|
+
def set_keylog_width(w)
|
|
1359
|
+
tries = 0
|
|
1360
|
+
GLib::Timeout.add(50) {
|
|
1361
|
+
if !@keylog_shown
|
|
1362
|
+
false
|
|
1363
|
+
elsif @keylog_pane.width > 0
|
|
1364
|
+
@keylog_pane.position = [@keylog_pane.width - w, EDITOR_MIN_WIDTH].max
|
|
1365
|
+
false
|
|
1366
|
+
else
|
|
1367
|
+
(tries += 1) < 100
|
|
1368
|
+
end
|
|
1369
|
+
}
|
|
1370
|
+
end
|
|
1371
|
+
|
|
1372
|
+
# Current geometry and layout as a Hash (see apply_view_layout). Widths are
|
|
1373
|
+
# in pixels, plus as a fraction of the window width (:frac) for a screen of
|
|
1374
|
+
# another size.
|
|
1375
|
+
def window_layout
|
|
1376
|
+
max = @window.maximized?
|
|
1377
|
+
# While maximized, the default size is the size to unmaximize to
|
|
1378
|
+
width, height = max ? [@window.default_width, @window.default_height] : [@window.width, @window.height]
|
|
1379
|
+
win_w = @window.width
|
|
1380
|
+
part = ->(shown, w) {
|
|
1381
|
+
{ :shown => !!shown, :width => w, :frac => (w && win_w > 0 ? w.to_f / win_w : nil) }
|
|
1382
|
+
}
|
|
1383
|
+
w2 = @two_column && @windows[2] && @windows[2][:sw].child
|
|
1384
|
+
{
|
|
1385
|
+
:width => width, :height => height, :maximized => max, :win_width => win_w,
|
|
1386
|
+
:file_panel => part.(@file_panel_shown, file_panel_width),
|
|
1387
|
+
:func_panel => part.(@func_panel_shown, func_panel_width),
|
|
1388
|
+
:keylog => part.(@keylog_shown, keylog_width),
|
|
1389
|
+
:two_column => part.(@two_column, @two_column ? @pane.position : @column_split),
|
|
1390
|
+
:column2_file => (w2.respond_to?(:bufo) ? w2.bufo.fname : nil),
|
|
1391
|
+
:minibuf_history_height => @minibuf_history_height,
|
|
1392
|
+
}
|
|
1393
|
+
end
|
|
1394
|
+
|
|
1395
|
+
def load_layouts
|
|
1396
|
+
f = get_data_path(LAYOUT_FILE)
|
|
1397
|
+
h = File.exist?(f) ? Marshal.load(File.binread(f)) : {}
|
|
1398
|
+
h.class == Hash ? h : {}
|
|
1399
|
+
rescue => ex
|
|
1400
|
+
debug "load_layouts failed: #{ex}"
|
|
1401
|
+
{}
|
|
1402
|
+
end
|
|
1403
|
+
|
|
1404
|
+
# all with layout l stored under key, keeping the LAYOUT_KEEP most recent
|
|
1405
|
+
def merge_layouts(all, key, l, now = Time.now.to_f)
|
|
1406
|
+
all = all.merge(key => l.merge(:used => now))
|
|
1407
|
+
all.sort_by { |_k, v| -v[:used].to_f }.first(LAYOUT_KEEP).to_h
|
|
1408
|
+
end
|
|
1409
|
+
|
|
1410
|
+
def save_window_layout
|
|
1411
|
+
return if !layout_enabled? || @window.nil?
|
|
1412
|
+
all = merge_layouts(load_layouts, monitor_key(layout_monitor), window_layout)
|
|
1413
|
+
File.binwrite(get_data_path(LAYOUT_FILE), Marshal.dump(all))
|
|
1414
|
+
rescue => ex
|
|
1415
|
+
debug "save_window_layout failed: #{ex}"
|
|
1416
|
+
end
|
|
1417
|
+
|
|
1418
|
+
# Layout to start with on a key/mw x mh monitor: the one saved for this
|
|
1419
|
+
# resolution, else the most recently used one fitted to this screen.
|
|
1420
|
+
# Never nil: with nothing saved, the default window and no panels.
|
|
1421
|
+
def pick_layout(all, key, mw, mh)
|
|
1422
|
+
return fit_view_layout(all[key], mw, mh, true) if all[key]
|
|
1423
|
+
recent = all.values.max_by { |v| v[:used].to_f }
|
|
1424
|
+
if recent.nil? && vma.marshal_load("file_panel_shown", false)
|
|
1425
|
+
recent = { :file_panel => { :shown => true } } # saved by older versions
|
|
1426
|
+
end
|
|
1427
|
+
fit_view_layout(recent || {}, mw, mh, recent.nil?)
|
|
1428
|
+
end
|
|
1429
|
+
|
|
1430
|
+
# Fit saved layout l to a mw x mh monitor. exact = saved for this
|
|
1431
|
+
# resolution: only clamp to the monitor. Otherwise (layout from another
|
|
1432
|
+
# screen) limit the window to 90% of the monitor, don't maximize if the
|
|
1433
|
+
# saved window was bigger than the screen, and scale the widths by their
|
|
1434
|
+
# fraction of the window width. Side panels that would leave the editor
|
|
1435
|
+
# narrower than EDITOR_MIN_WIDTH are hidden.
|
|
1436
|
+
def fit_view_layout(saved, mw, mh, exact)
|
|
1437
|
+
l = Marshal.load(Marshal.dump(saved || {}))
|
|
1438
|
+
w, h = l[:width], l[:height]
|
|
1439
|
+
if w.to_i <= 0 || h.to_i <= 0
|
|
1440
|
+
# First start: the default size, leaving some room on a small screen
|
|
1441
|
+
# (a window nearly as big as the screen gets maximized by e.g. GNOME)
|
|
1442
|
+
w, h = DEFAULT_WINDOW_SIZE
|
|
1443
|
+
exact = false
|
|
1444
|
+
end
|
|
1445
|
+
if exact
|
|
1446
|
+
w, h = [w, mw].min, [h, mh].min
|
|
1447
|
+
else
|
|
1448
|
+
l[:maximized] = false if w > mw || h > mh
|
|
1449
|
+
w, h = [w, (mw * 0.9).to_i].min, [h, (mh * 0.9).to_i].min
|
|
1450
|
+
end
|
|
1451
|
+
l[:width] = [w, [WINDOW_MIN_SIZE, mw].min].max
|
|
1452
|
+
l[:height] = [h, [WINDOW_MIN_SIZE, mh].min].max
|
|
1453
|
+
l[:maximized] = !!l[:maximized]
|
|
1454
|
+
|
|
1455
|
+
# Width the window will have. Maximized, that's the monitor minus panels
|
|
1456
|
+
# and docks (e.g. GNOME's), which isn't known here: approximately mw.
|
|
1457
|
+
eff = l[:maximized] ? mw : l[:width]
|
|
1458
|
+
# Saved on this resolution: the pixel widths are right as they are
|
|
1459
|
+
same = exact || eff == l[:win_width]
|
|
1460
|
+
(SIDE_PANELS + [:two_column]).each { |k|
|
|
1461
|
+
p = (l[k] ||= {})
|
|
1462
|
+
p[:shown] = !!p[:shown]
|
|
1463
|
+
p[:width] = (p[:frac] * eff).round if !same && p[:frac] && p[:width]
|
|
1464
|
+
}
|
|
1465
|
+
side = ->() {
|
|
1466
|
+
SIDE_PANELS.sum { |k| l[k][:shown] ? (l[k][:width] || PANEL_DEFAULT_WIDTH[k]) : 0 }
|
|
1467
|
+
}
|
|
1468
|
+
[:keylog, :func_panel, :file_panel].each { |k|
|
|
1469
|
+
break if eff - side.() >= EDITOR_MIN_WIDTH
|
|
1470
|
+
l[k][:shown] = false
|
|
1471
|
+
}
|
|
1472
|
+
# Split of the two columns: inside the editor area
|
|
1473
|
+
sp = l[:two_column][:width]
|
|
1474
|
+
l[:two_column][:width] = nil if sp && sp >= eff - side.() - 100
|
|
1475
|
+
l
|
|
1476
|
+
end
|
|
1477
|
+
|
|
1478
|
+
# Before the window is first shown: pick the layout for this screen and
|
|
1479
|
+
# size the window (GTK ignores a new default size once it is mapped).
|
|
1480
|
+
# The columns and panels come later, in restore_view_layout.
|
|
1481
|
+
def apply_startup_window_size
|
|
1482
|
+
m = layout_monitor
|
|
1483
|
+
mw, mh = monitor_size(m)
|
|
1484
|
+
@startup_monitor_key = monitor_key(m)
|
|
1485
|
+
l = layout_enabled? ? pick_layout(load_layouts, @startup_monitor_key, mw, mh) : fit_view_layout({}, mw, mh, true)
|
|
1486
|
+
@startup_layout = l
|
|
1487
|
+
@window.set_size_request([WINDOW_MIN_SIZE, mw].min, [WINDOW_MIN_SIZE, mh].min)
|
|
1488
|
+
@window.set_default_size(l[:width], l[:height])
|
|
1489
|
+
@window.maximize if l[:maximized]
|
|
1490
|
+
end
|
|
1491
|
+
|
|
1492
|
+
# On the first map the real monitor is known. If it isn't the one guessed
|
|
1493
|
+
# in apply_startup_window_size, use the layout for the real one.
|
|
1494
|
+
def layout_recheck_monitor
|
|
1495
|
+
return if @layout_rechecked || !layout_enabled?
|
|
1496
|
+
@layout_rechecked = true
|
|
1497
|
+
GLib::Timeout.add(300) {
|
|
1498
|
+
m = layout_monitor
|
|
1499
|
+
key = monitor_key(m)
|
|
1500
|
+
if key != @startup_monitor_key
|
|
1501
|
+
mw, mh = monitor_size(m)
|
|
1502
|
+
l = pick_layout(load_layouts, key, mw, mh)
|
|
1503
|
+
@startup_layout = l
|
|
1504
|
+
l[:maximized] ? @window.maximize : @window.set_default_size(l[:width], l[:height])
|
|
1505
|
+
apply_view_layout(l) if @view_layout_restored
|
|
1506
|
+
end
|
|
1507
|
+
false
|
|
1508
|
+
}
|
|
1509
|
+
end
|
|
1510
|
+
|
|
1511
|
+
# Called at startup once the first buffer exists: columns and panels.
|
|
1512
|
+
def restore_view_layout
|
|
1513
|
+
return if !layout_enabled? || @startup_layout.nil?
|
|
1514
|
+
apply_view_layout(@startup_layout)
|
|
1515
|
+
@view_layout_restored = true
|
|
1516
|
+
end
|
|
1517
|
+
|
|
1518
|
+
# Show the columns and panels of layout l (from window_layout or
|
|
1519
|
+
# fit_view_layout) with their widths. Columns go first: show_file_panel /
|
|
1520
|
+
# show_func_panel wrap whatever is in the editor area.
|
|
1521
|
+
def apply_view_layout(l)
|
|
1522
|
+
got = ->(k) { l[k] || {} }
|
|
1523
|
+
@column_split = got.(:two_column)[:width] || @column_split
|
|
1524
|
+
@file_panel_width = got.(:file_panel)[:width] || @file_panel_width
|
|
1525
|
+
@func_panel_width = got.(:func_panel)[:width] || @func_panel_width
|
|
1526
|
+
@keylog_width = got.(:keylog)[:width] || @keylog_width
|
|
1527
|
+
@minibuf_history_height = l[:minibuf_history_height] if l[:minibuf_history_height]
|
|
1528
|
+
|
|
1529
|
+
got.(:two_column)[:shown] ? set_two_column : set_one_column
|
|
1530
|
+
got.(:func_panel)[:shown] ? show_func_panel : hide_func_panel
|
|
1531
|
+
got.(:file_panel)[:shown] ? show_file_panel : hide_file_panel
|
|
1532
|
+
got.(:keylog)[:shown] ? show_keylog_panel : hide_keylog_panel
|
|
1533
|
+
# Already shown panels keep their old widths otherwise
|
|
1534
|
+
@pane.set_position(@column_split) if @two_column && @column_split.to_i > 0
|
|
1535
|
+
@file_panel_pane.set_position(@file_panel_width) if @file_panel_shown && @file_panel_width.to_i > 0
|
|
1536
|
+
@func_panel_pane.set_position(@func_panel_width) if @func_panel_shown && @func_panel_width.to_i > 0
|
|
1537
|
+
set_keylog_width(@keylog_width) if @keylog_shown && @keylog_width.to_i > 0
|
|
1538
|
+
@column2_file = l[:column2_file]
|
|
1539
|
+
restore_column2_buffer
|
|
1540
|
+
end
|
|
1541
|
+
|
|
1542
|
+
# Put the file that was in the second column back there, once it is open
|
|
1543
|
+
# (the session's files load after the layout; see restore_session_files).
|
|
1544
|
+
def restore_column2_buffer
|
|
1545
|
+
return if !@two_column || @column2_file.nil?
|
|
1546
|
+
id = vma.buffers.get_buffer_by_filename(@column2_file)
|
|
1547
|
+
return if id.nil? || id == vma.buf.id
|
|
1548
|
+
set_buffer_to_window(id, 2)
|
|
1549
|
+
@column2_file = nil
|
|
1137
1550
|
end
|
|
1138
1551
|
end
|
|
1552
|
+
end # module Vimamsa
|