vimamsa 0.1.26 → 0.1.28
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 +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- 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 +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -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 +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- 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/terminal/terminal.rb +5 -5
- 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.rb +138 -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_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -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_action_ids.rb +232 -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 +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -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 +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -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_dot_repeat.rb +88 -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_easy_jump.rb +93 -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_form_input.rb +203 -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_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -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_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -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 +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
data/lib/vimamsa/gui_menu.rb
CHANGED
|
@@ -22,63 +22,78 @@ module Vimamsa
|
|
|
22
22
|
|
|
23
23
|
def add_menu_items()
|
|
24
24
|
add_to_menu "File.Example", { :label => "<span foreground='#888888'>Action, [mode] key binding</span>", :action => nil }
|
|
25
|
-
add_to_menu "File.Save", { :label => "Save", :action =>
|
|
26
|
-
add_to_menu "File.Save as", { :label => "Save As...", :action =>
|
|
27
|
-
add_to_menu "File.Open", { :label => "Open", :action =>
|
|
25
|
+
add_to_menu "File.Save", { :label => "Save", :action => "buf.save" }
|
|
26
|
+
add_to_menu "File.Save as", { :label => "Save As...", :action => "buf.save.as" }
|
|
27
|
+
add_to_menu "File.Open", { :label => "Open", :action => "file.open" }
|
|
28
28
|
|
|
29
|
-
add_to_menu "File.New", { :label => "New file", :action =>
|
|
30
|
-
add_to_menu "File.Revert", { :label => "Reload file from disk", :action =>
|
|
31
|
-
add_to_menu "File.List", { :label => "List open files", :action =>
|
|
32
|
-
add_to_menu "File.Close", { :label => "Close file", :action =>
|
|
29
|
+
add_to_menu "File.New", { :label => "New file", :action => "buf.new" }
|
|
30
|
+
add_to_menu "File.Revert", { :label => "Reload file from disk", :action => "buf.revert" }
|
|
31
|
+
add_to_menu "File.List", { :label => "List open files", :action => "buf.manager" }
|
|
32
|
+
add_to_menu "File.Close", { :label => "Close file", :action => "buf.close" }
|
|
33
33
|
|
|
34
|
-
add_to_menu "File.
|
|
34
|
+
add_to_menu "File.Restart", { :label => "Restart (reload config and files)", :action => "app.restart" }
|
|
35
|
+
add_to_menu "File.Quit", { :label => "Quit", :action => "app.quit" }
|
|
35
36
|
|
|
36
|
-
add_to_menu "Edit.Undo", { :label => "Undo edit", :action =>
|
|
37
|
-
add_to_menu "Edit.Redo", { :label => "Redo edit", :action =>
|
|
38
|
-
add_to_menu "Edit.SearchReplace", { :label => "Search and replace", :action =>
|
|
39
|
-
add_to_menu "Edit.Find", { :label => "Find", :action =>
|
|
37
|
+
add_to_menu "Edit.Undo", { :label => "Undo edit", :action => "undo.last" }
|
|
38
|
+
add_to_menu "Edit.Redo", { :label => "Redo edit", :action => "undo.redo" }
|
|
39
|
+
add_to_menu "Edit.SearchReplace", { :label => "Search and replace", :action => "search.replace" }
|
|
40
|
+
add_to_menu "Edit.Find", { :label => "Find", :action => "search.buf" }
|
|
41
|
+
add_to_menu "Edit.ToggleAutocomplete", { :label => "Toggle autocomplete", :action => "edit.complete.toggle" }
|
|
40
42
|
|
|
41
43
|
# add_to_menu "Edit.StartCompletion", { :label => "StartCompletion", :action => :start_autocomplete }
|
|
42
44
|
# add_to_menu "Edit.ShowCompletion", { :label => "ShowCompletion", :action => :show_autocomplete }
|
|
43
45
|
|
|
44
|
-
add_to_menu "Settings.Preferences", { :label => "Preferences...", :action =>
|
|
45
|
-
add_to_menu "Settings.Customize", { :action =>
|
|
46
|
-
add_to_menu "Settings.ReloadCustom", { :action =>
|
|
46
|
+
add_to_menu "Settings.Preferences", { :label => "Preferences...", :action => "app.settings" }
|
|
47
|
+
add_to_menu "Settings.Customize", { :action => "app.customrb.edit" }
|
|
48
|
+
add_to_menu "Settings.ReloadCustom", { :action => "app.customrb.reload" }
|
|
47
49
|
|
|
48
|
-
add_to_menu "Actions.SearchForActions", { :label => "Search for Actions", :action =>
|
|
50
|
+
add_to_menu "Actions.SearchForActions", { :label => "Search for Actions", :action => "search.actions" }
|
|
49
51
|
|
|
50
|
-
add_to_menu "Actions.Grep", { :label => "Grep lines", :action =>
|
|
52
|
+
add_to_menu "Actions.Grep", { :label => "Grep lines", :action => "grep.buf" }
|
|
51
53
|
|
|
52
|
-
add_to_menu "Actions.FileHistoryFinder", { :label => "Search files in history", :action =>
|
|
54
|
+
add_to_menu "Actions.FileHistoryFinder", { :label => "Search files in history", :action => "file.history" }
|
|
53
55
|
|
|
54
|
-
add_to_menu "Actions.experimental.Diff", { :label => "Show Diff of\nunsaved changes", :action =>
|
|
55
|
-
add_to_menu "Actions.experimental.GitDiff", { :label => "Show git diff", :action =>
|
|
56
|
-
add_to_menu "Actions.experimental.GitDiffW", { :label => "Show git diff -w (repo)", :action =>
|
|
56
|
+
add_to_menu "Actions.experimental.Diff", { :label => "Show Diff of\nunsaved changes", :action => "buf.diff" }
|
|
57
|
+
add_to_menu "Actions.experimental.GitDiff", { :label => "Show git diff", :action => "buf.diff.git" }
|
|
58
|
+
add_to_menu "Actions.experimental.GitDiffW", { :label => "Show git diff -w (repo)", :action => "file.diff.repo" }
|
|
57
59
|
|
|
58
|
-
add_to_menu "Actions.experimental.PrintBufferAccessList", { :label => "Print buffers by access time", :action =>
|
|
59
|
-
add_to_menu "Actions.experimental.EnableDebug", { :label => "Enable debug", :action =>
|
|
60
|
-
add_to_menu "Actions.experimental.DisableDebug", { :label => "Disable debug", :action =>
|
|
61
|
-
add_to_menu "Actions.experimental.ShowImages", { :label => "Show images ⟦img:path⟧", :action =>
|
|
60
|
+
add_to_menu "Actions.experimental.PrintBufferAccessList", { :label => "Print buffers by access time", :action => "debug.buf.access" }
|
|
61
|
+
add_to_menu "Actions.experimental.EnableDebug", { :label => "Enable debug", :action => "debug.on" }
|
|
62
|
+
add_to_menu "Actions.experimental.DisableDebug", { :label => "Disable debug", :action => "debug.off" }
|
|
63
|
+
add_to_menu "Actions.experimental.ShowImages", { :label => "Show images ⟦img:path⟧", :action => "style.images" }
|
|
62
64
|
|
|
63
|
-
add_to_menu "Actions.experimental.ShowImages", { :action =>
|
|
65
|
+
add_to_menu "Actions.experimental.ShowImages", { :action => "debug.eval.sel" }
|
|
64
66
|
|
|
65
67
|
|
|
66
|
-
add_to_menu "Actions.debug.dumpkbd", { :label => "Dump kbd state", :action =>
|
|
67
|
-
add_to_menu "Actions.debug.ToggleKbdPassthrough", { :label => "Toggle kbd event passthrough", :action =>
|
|
68
|
-
|
|
69
|
-
add_to_menu "View.BufferManager", { :label => "Show open files", :action =>
|
|
70
|
-
add_to_menu "View.
|
|
71
|
-
add_to_menu "
|
|
72
|
-
add_to_menu "View.
|
|
73
|
-
add_to_menu "View.
|
|
74
|
-
|
|
75
|
-
add_to_menu "
|
|
76
|
-
add_to_menu "
|
|
77
|
-
add_to_menu "
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
add_to_menu "Actions.debug.dumpkbd", { :label => "Dump kbd state", :action => "debug.kbd" }
|
|
69
|
+
add_to_menu "Actions.debug.ToggleKbdPassthrough", { :label => "Toggle kbd event passthrough", :action => "mode.passthrough.toggle" }
|
|
70
|
+
|
|
71
|
+
add_to_menu "View.BufferManager", { :label => "Show open files", :action => "buf.manager" }
|
|
72
|
+
add_to_menu "View.Bookmarks", { :label => "Show bookmarks", :action => "mark.list" }
|
|
73
|
+
add_to_menu "Edit.AddBookmark", { :label => "Add bookmark", :action => "mark.add" }
|
|
74
|
+
add_to_menu "View.SelectLanguage", { :label => "Set buffer language...", :action => "buf.language" }
|
|
75
|
+
add_to_menu "View.TwoColumn", { :label => "Toggle two column mode", :action => "view.columns.toggle" }
|
|
76
|
+
add_to_menu "View.FilePanel", { :label => "Toggle file panel", :action => "panel.files.toggle" }
|
|
77
|
+
add_to_menu "View.FuncPanel", { :label => "Toggle function panel (LSP)", :action => "panel.funcs.toggle" }
|
|
78
|
+
add_to_menu "View.KeyLog", { :label => "Toggle key log panel", :action => "panel.keylog.toggle" }
|
|
79
|
+
add_to_menu "View.MsgHistory", { :label => "Message history", :action => "help.messages" }
|
|
80
|
+
|
|
81
|
+
add_to_menu "Actions.EncryptFile", { :label => "Encrypt file", :action => "buf.encrypt" }
|
|
82
|
+
add_to_menu "Actions.LspRestart", { :label => "Restart LSP server", :action => "lsp.restart" }
|
|
83
|
+
add_to_menu "Help.Intro", { :label => "Introduction", :action => "help.intro" }
|
|
84
|
+
add_to_menu "Help.KeyBindings", { :label => "Show key bindings", :action => "help.keys" }
|
|
85
|
+
add_to_menu "Help.VimIntro", { :label => "Vimamsa for Vim users", :action => "help.vim_intro" }
|
|
86
|
+
add_to_menu "Help.VimConflicts", { :label => "Vim keys that differ in vimlike", :action => "help.vim_conflicts" }
|
|
87
|
+
DemoPlayer.demos.each { |name, d|
|
|
88
|
+
add_to_menu "Help.Demos.#{name}", { :label => d[:title], :action => d[:action] }
|
|
89
|
+
}
|
|
90
|
+
add_to_menu "Help.Demos.Record", { :label => "Record demo (again: stop)", :action => "help.demo.record" }
|
|
91
|
+
add_to_menu "Help.Demos.PlayRecorded", { :label => "Play the last recorded demo", :action => "help.demo.recorded.last" }
|
|
92
|
+
add_to_menu "Help.InstallDemo", { :action => "app.demo" }
|
|
93
|
+
|
|
94
|
+
#TODO: "edit.indent.buf"
|
|
95
|
+
|
|
96
|
+
# add_to_menu "Actions.Ack", { :label => "source code search (Ack)", :action => "ack.search" }
|
|
82
97
|
|
|
83
98
|
end
|
|
84
99
|
|
|
@@ -98,6 +113,30 @@ module Vimamsa
|
|
|
98
113
|
end
|
|
99
114
|
end
|
|
100
115
|
|
|
116
|
+
# Markup hint (e.g. " [C] , d") showing the key binding for an action,
|
|
117
|
+
# or "" if the action is unbound. Shared by regular and module menu items.
|
|
118
|
+
def kbd_hint(action)
|
|
119
|
+
for mode_str in ["C", "V"]
|
|
120
|
+
c_kbd = vma.kbd.act_bindings[mode_str][action]
|
|
121
|
+
if c_kbd.class == String
|
|
122
|
+
return " <span foreground='#888888'><span weight='bold'>[#{mode_str}]</span> #{c_kbd}</span>"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
return ""
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# "Help ▸ Show key bindings" for the menu item that runs action, or nil
|
|
129
|
+
def path_for(action, nfo = @nfo, path = [])
|
|
130
|
+
nfo.each_value { |x|
|
|
131
|
+
p = path + [x[:label].to_s]
|
|
132
|
+
return p.join(" ▸ ") if x[:action].to_s == action.to_s
|
|
133
|
+
if x[:items].is_a?(Hash) && (r = path_for(action, x[:items], p))
|
|
134
|
+
return r
|
|
135
|
+
end
|
|
136
|
+
}
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
|
|
101
140
|
# Add a menu item under the top-level "Modules" menu.
|
|
102
141
|
# Creates the Modules menu the first time it is called.
|
|
103
142
|
def add_module_action(action, label)
|
|
@@ -112,7 +151,8 @@ module Vimamsa
|
|
|
112
151
|
@app.add_action(act)
|
|
113
152
|
act.signal_connect("activate") { call_action(action) }
|
|
114
153
|
|
|
115
|
-
item = Gio::MenuItem.new(label, "app.#{action}")
|
|
154
|
+
item = Gio::MenuItem.new(label + kbd_hint(action), "app.#{action}")
|
|
155
|
+
item.set_attribute_value("use-markup", "true")
|
|
116
156
|
@module_menu.append_item(item)
|
|
117
157
|
@module_actions << action
|
|
118
158
|
end
|
|
@@ -134,16 +174,7 @@ module Vimamsa
|
|
|
134
174
|
def build_menu(nfo, parent)
|
|
135
175
|
menu = Gio::Menu.new
|
|
136
176
|
if nfo[:action]
|
|
137
|
-
|
|
138
|
-
for mode_str in ["C", "V"]
|
|
139
|
-
c_kbd = vma.kbd.act_bindings[mode_str][nfo[:action]]
|
|
140
|
-
if c_kbd.class == String
|
|
141
|
-
kbd_str = " <span foreground='#888888'><span weight='bold'>[#{mode_str}]</span> #{c_kbd}</span>"
|
|
142
|
-
break
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
label_str = nfo[:label] + kbd_str
|
|
177
|
+
label_str = nfo[:label] + kbd_hint(nfo[:action])
|
|
147
178
|
actkey = nfo[:action].to_s
|
|
148
179
|
menuitem = Gio::MenuItem.new(label_str, "app.#{actkey}")
|
|
149
180
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
def gui_select_update_window(item_list, jump_keys, select_callback, update_callback, opt = {})
|
|
2
4
|
$selup = SelectUpdateWindow.new(nil, item_list, jump_keys, select_callback, update_callback, opt)
|
|
3
5
|
$selup.run
|
|
@@ -6,7 +8,14 @@ def gui_select_update_window(item_list, jump_keys, select_callback, update_callb
|
|
|
6
8
|
# :desc
|
|
7
9
|
end
|
|
8
10
|
|
|
11
|
+
# A list filtered by a search field (action search, file finder, file
|
|
12
|
+
# history, macros, language). The field is edited through the key bindings in
|
|
13
|
+
# form mode (form_input.rb), so the typing shows in the key log and a demo can
|
|
14
|
+
# record it: up / down move the selection, enter picks, esc closes, delete
|
|
15
|
+
# deletes an item if the list allows it (opt[:delete_callback]).
|
|
9
16
|
class SelectUpdateWindow
|
|
17
|
+
attr_reader :form, :selected_row
|
|
18
|
+
|
|
10
19
|
COLUMN_JUMP_KEY = 0
|
|
11
20
|
COLUMN_DESCRIPTION = 1
|
|
12
21
|
|
|
@@ -41,25 +50,20 @@ class SelectUpdateWindow
|
|
|
41
50
|
end
|
|
42
51
|
|
|
43
52
|
def initialize(main_window, item_list, jump_keys, select_callback, update_callback, opt = {})
|
|
44
|
-
|
|
45
|
-
@window
|
|
46
|
-
# @window.screen = main_window.screen
|
|
47
|
-
@window.title = ""
|
|
48
|
-
if !opt[:title].nil?
|
|
49
|
-
@window.title = opt[:title]
|
|
50
|
-
end
|
|
53
|
+
# Modal: while it is up, its form takes the keys
|
|
54
|
+
@window = make_modal_window(opt[:title] || "")
|
|
51
55
|
|
|
52
56
|
@selected_row = 0
|
|
53
57
|
@opt = opt
|
|
54
58
|
|
|
55
59
|
debug item_list.inspect
|
|
56
60
|
|
|
57
|
-
if select_callback.class == Method
|
|
61
|
+
if select_callback.class == Method || select_callback.class == Proc
|
|
58
62
|
@select_callback = select_callback
|
|
59
63
|
else
|
|
60
64
|
@select_callback = method(select_callback)
|
|
61
65
|
end
|
|
62
|
-
if update_callback.class == Method
|
|
66
|
+
if update_callback.class == Method || update_callback.class == Proc
|
|
63
67
|
@update_callback = update_callback
|
|
64
68
|
else
|
|
65
69
|
@update_callback = method(update_callback)
|
|
@@ -70,11 +74,11 @@ class SelectUpdateWindow
|
|
|
70
74
|
vbox.margin_bottom = 8
|
|
71
75
|
vbox.margin_top = 8
|
|
72
76
|
|
|
73
|
-
@window.
|
|
77
|
+
@window.set_child(vbox)
|
|
74
78
|
|
|
75
79
|
if !opt[:desc].nil?
|
|
76
80
|
descl = Gtk::Label.new(opt[:desc])
|
|
77
|
-
|
|
81
|
+
descl.margin = 15
|
|
78
82
|
# vbox.append(descl, :expand => false, :fill => false, :padding => 0)
|
|
79
83
|
vbox.append(descl)
|
|
80
84
|
end
|
|
@@ -87,7 +91,9 @@ class SelectUpdateWindow
|
|
|
87
91
|
container.append(@entry)
|
|
88
92
|
|
|
89
93
|
# create tree view
|
|
90
|
-
|
|
94
|
+
# As many columns as opt[:columns] has (2 without)
|
|
95
|
+
ncols = opt[:columns] ? opt[:columns].map { |c| c[:id] }.max + 1 : 2
|
|
96
|
+
@model = Gtk::ListStore.new(*([String] * ncols))
|
|
91
97
|
treeview = Gtk::TreeView.new(@model)
|
|
92
98
|
treeview.search_column = COLUMN_DESCRIPTION
|
|
93
99
|
@tv = treeview
|
|
@@ -99,61 +105,17 @@ class SelectUpdateWindow
|
|
|
99
105
|
# @entry.handle_event(event)
|
|
100
106
|
# end
|
|
101
107
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if keyval == Gdk::Keyval::KEY_Down
|
|
114
|
-
debug "DOWN"
|
|
115
|
-
set_selected_row(@selected_row + 1)
|
|
116
|
-
true
|
|
117
|
-
elsif keyval == Gdk::Keyval::KEY_Up
|
|
118
|
-
set_selected_row(@selected_row - 1)
|
|
119
|
-
debug "UP"
|
|
120
|
-
true
|
|
121
|
-
elsif keyval == Gdk::Keyval::KEY_Return
|
|
122
|
-
path = Gtk::TreePath.new(@selected_row.to_s)
|
|
123
|
-
iter = @model.get_iter(path)
|
|
124
|
-
ret = iter[1]
|
|
125
|
-
@select_callback.call(ret, @selected_row)
|
|
126
|
-
@window.destroy
|
|
127
|
-
# debug iter[1].inspect
|
|
128
|
-
true
|
|
129
|
-
elsif keyval == Gdk::Keyval::KEY_Delete && @opt[:delete_callback]
|
|
130
|
-
path = Gtk::TreePath.new(@selected_row.to_s)
|
|
131
|
-
iter = @model.get_iter(path)
|
|
132
|
-
next false unless iter
|
|
133
|
-
name = iter[COLUMN_DESCRIPTION]
|
|
134
|
-
refresh = proc {
|
|
135
|
-
update_item_list(@update_callback.call(@entry.text))
|
|
136
|
-
@window.present
|
|
137
|
-
}
|
|
138
|
-
@opt[:delete_callback].call(name, refresh)
|
|
139
|
-
true
|
|
140
|
-
elsif keyval == Gdk::Keyval::KEY_Escape
|
|
141
|
-
@window.destroy
|
|
142
|
-
true
|
|
143
|
-
else
|
|
144
|
-
false
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
@entry.signal_connect("search-changed") do |widget|
|
|
149
|
-
debug "search changed: #{widget.text || ""}"
|
|
150
|
-
item_list = @update_callback.call(widget.text)
|
|
151
|
-
|
|
152
|
-
update_item_list(item_list)
|
|
153
|
-
# label.text = widget.text || ""
|
|
154
|
-
end
|
|
155
|
-
@entry.signal_connect("changed") { debug "[changed] " }
|
|
156
|
-
@entry.signal_connect("next-match") { debug "[next-match] " }
|
|
108
|
+
@form = FormInput.new(@window, submit: method(:select_current), cancel: method(:close))
|
|
109
|
+
@field = @form.add_field(@entry)
|
|
110
|
+
# The list follows the field, in an idle (typing stays quick with a slow
|
|
111
|
+
# update callback); enter first applies a pending update
|
|
112
|
+
@field.on_change = proc { |_t| schedule_update }
|
|
113
|
+
@form.key_handlers = {
|
|
114
|
+
up: proc { set_selected_row(@selected_row - 1) },
|
|
115
|
+
down: proc { set_selected_row(@selected_row + 1) },
|
|
116
|
+
}
|
|
117
|
+
@form.key_handlers[:delete] = method(:delete_current) if @opt[:delete_callback]
|
|
118
|
+
@window.signal_connect("close-request") { @form.deactivate; false }
|
|
157
119
|
|
|
158
120
|
# label = Gtk::Label.new(<<-EOF)
|
|
159
121
|
# Search:
|
|
@@ -203,14 +165,57 @@ class SelectUpdateWindow
|
|
|
203
165
|
end
|
|
204
166
|
|
|
205
167
|
def run
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
else
|
|
210
|
-
@window.destroy
|
|
211
|
-
# GLib::Source.remove(@tiemout) unless @timeout.zero?
|
|
212
|
-
@timeout = 0
|
|
213
|
-
end
|
|
168
|
+
@window.show
|
|
169
|
+
@form.activate
|
|
170
|
+
@form.focus(0)
|
|
214
171
|
@window
|
|
215
172
|
end
|
|
173
|
+
|
|
174
|
+
# The list for the field's text now
|
|
175
|
+
def update_now
|
|
176
|
+
remove_update
|
|
177
|
+
item_list = run_dialog_callback("select update") { @update_callback.call(@field.text) }
|
|
178
|
+
update_item_list(item_list) if item_list
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# enter: the selected row to the callback
|
|
182
|
+
def select_current
|
|
183
|
+
update_now if @update_pending
|
|
184
|
+
path = Gtk::TreePath.new(@selected_row.to_s)
|
|
185
|
+
iter = @model.get_iter(path)
|
|
186
|
+
@form.deactivate
|
|
187
|
+
run_dialog_callback("select") { @select_callback.call(iter[1], @selected_row) } if iter
|
|
188
|
+
close
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def close
|
|
192
|
+
remove_update
|
|
193
|
+
@form.deactivate
|
|
194
|
+
@window.destroy
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
private
|
|
198
|
+
|
|
199
|
+
def schedule_update
|
|
200
|
+
return if @update_pending
|
|
201
|
+
@update_pending = GLib::Idle.add { @update_pending = nil; update_now; false }
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def remove_update
|
|
205
|
+
GLib::Source.remove(@update_pending) rescue nil if @update_pending
|
|
206
|
+
@update_pending = nil
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def delete_current
|
|
210
|
+
path = Gtk::TreePath.new(@selected_row.to_s)
|
|
211
|
+
iter = @model.get_iter(path)
|
|
212
|
+
return if !iter
|
|
213
|
+
name = iter[COLUMN_DESCRIPTION]
|
|
214
|
+
refresh = proc {
|
|
215
|
+
update_now
|
|
216
|
+
@window.present
|
|
217
|
+
}
|
|
218
|
+
@opt[:delete_callback].call(name, refresh)
|
|
219
|
+
end
|
|
216
220
|
end
|
|
221
|
+
end # module Vimamsa
|
data/lib/vimamsa/gui_settings.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
SETTINGS_DEFS = [
|
|
2
4
|
{
|
|
3
5
|
:label => "Tab / Indent",
|
|
@@ -18,6 +20,9 @@ SETTINGS_DEFS = [
|
|
|
18
20
|
:label => "Appearance",
|
|
19
21
|
:settings => [
|
|
20
22
|
{ :key => [:match, :highlight, :color], :label => "Search highlight color", :type => :string },
|
|
23
|
+
{ :key => [:help, :button_style], :label => "Buttons on help pages (e.g. the introduction)", :type => :select,
|
|
24
|
+
:options => HELP_BUTTON_STYLES.keys },
|
|
25
|
+
{ :key => [:theme, :cyberpunk_glow], :label => "Cyberpunk glow theme (neon glow & shadows)", :type => :bool },
|
|
21
26
|
{ :key => [:kbd, :show_prev_action], :label => "Show previous action in toolbar", :type => :bool },
|
|
22
27
|
{ :key => [:style_scheme], :label => "Color scheme", :type => :select,
|
|
23
28
|
:options => proc {
|
|
@@ -25,6 +30,7 @@ SETTINGS_DEFS = [
|
|
|
25
30
|
ssm.set_search_path(ssm.search_path << ppath("styles/"))
|
|
26
31
|
ssm.scheme_ids.reject { |id| [VIMAMSA_OVERLAY_SCHEME_ID, VIMAMSA_CONTRAST_SCHEME_ID].include?(id) }.sort
|
|
27
32
|
} },
|
|
33
|
+
{ :key => [:color_adjustments, :enabled], :label => "Enable color scheme contrast/brightness adjustments", :type => :bool },
|
|
28
34
|
{ :key => [:color_contrast], :label => "Color scheme contrast (1.0 = original)", :type => :float, :min => 0.5, :max => 2.0, :step => 0.05 },
|
|
29
35
|
{ :key => [:color_brightness], :label => "Color scheme brightness (0.0 = original)", :type => :float, :min => -0.5, :max => 0.5, :step => 0.01 },
|
|
30
36
|
],
|
|
@@ -32,10 +38,28 @@ SETTINGS_DEFS = [
|
|
|
32
38
|
{
|
|
33
39
|
:label => "Behavior",
|
|
34
40
|
:settings => [
|
|
41
|
+
{ :key => [:keybindings, :scheme], :label => "Keybinding scheme (requires restart)",
|
|
42
|
+
:type => :select, :options => ["vimlike", "vim", "notepad"] },
|
|
35
43
|
{ :key => [:lsp, :enabled], :label => "Enable LSP (Language Server)", :type => :bool },
|
|
36
44
|
{ :key => [:experimental], :label => "Enable experimental features", :type => :bool },
|
|
37
45
|
{ :key => [:macro, :animation_delay], :label => "Macro animation delay (sec)", :type => :float, :min => 0.0, :max => 2.0, :step => 0.0001 },
|
|
46
|
+
{ :key => [:intro, :show_on_startup], :label => "Show the introduction page (Help ▸ Introduction) at the next start", :type => :bool },
|
|
47
|
+
{ :key => [:undo, :insert_one_step], :label => "Undo an Insert-mode session in one step (vim), even after pauses", :type => :bool },
|
|
38
48
|
{ :key => [:paste, :cursor_at_start], :label => "Leave cursor at start of pasted text", :type => :bool },
|
|
49
|
+
{ :key => [:mouse, :drag_selection], :label => "Move selected text by dragging it with the mouse (off: pressing inside a selection starts a new one)", :type => :bool },
|
|
50
|
+
{ :key => [:file_format, :on_save],
|
|
51
|
+
:label => "Saving files not in UTF-8 + LF (e.g. Latin-1, CRLF): ask / keep original format / convert to UTF-8 + LF",
|
|
52
|
+
:type => :select, :options => ["ask", "keep", "convert"] },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
:label => "Autocomplete",
|
|
57
|
+
:settings => [
|
|
58
|
+
{ :key => [:autocomplete, :enabled], :label => "Enable autocomplete", :type => :bool },
|
|
59
|
+
{ :key => [:autocomplete, :auto_trigger], :label => "Show popup while typing (off: manual key only)", :type => :bool },
|
|
60
|
+
{ :key => [:autocomplete, :min_chars], :label => "Min characters before auto popup", :type => :int, :min => 1, :max => 10, :step => 1 },
|
|
61
|
+
{ :key => [:autocomplete, :max_items], :label => "Max candidates in list", :type => :int, :min => 1, :max => 200, :step => 1 },
|
|
62
|
+
{ :key => [:autocomplete, :visible_items], :label => "Visible rows in popup", :type => :int, :min => 1, :max => 40, :step => 1 },
|
|
39
63
|
],
|
|
40
64
|
},
|
|
41
65
|
{
|
|
@@ -72,10 +96,7 @@ end
|
|
|
72
96
|
class SettingsDialog
|
|
73
97
|
def initialize
|
|
74
98
|
@widgets = {}
|
|
75
|
-
@window =
|
|
76
|
-
@window.set_transient_for($vmag.window) if $vmag&.window
|
|
77
|
-
@window.modal = true
|
|
78
|
-
@window.title = "Preferences"
|
|
99
|
+
@window = make_modal_window("Preferences")
|
|
79
100
|
@window.default_width = 500
|
|
80
101
|
|
|
81
102
|
outer = Gtk::Box.new(:vertical, 12)
|
|
@@ -133,17 +154,7 @@ class SettingsDialog
|
|
|
133
154
|
hbox.append(save_btn)
|
|
134
155
|
outer.append(hbox)
|
|
135
156
|
|
|
136
|
-
|
|
137
|
-
press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
|
|
138
|
-
@window.add_controller(press)
|
|
139
|
-
press.signal_connect("key-pressed") do |_g, keyval, _kc, _y|
|
|
140
|
-
if keyval == Gdk::Keyval::KEY_Escape
|
|
141
|
-
@window.destroy
|
|
142
|
-
true
|
|
143
|
-
else
|
|
144
|
-
false
|
|
145
|
-
end
|
|
146
|
-
end
|
|
157
|
+
on_submit_escape(@window, escape: proc { @window.destroy })
|
|
147
158
|
end
|
|
148
159
|
|
|
149
160
|
def make_widget(s)
|
|
@@ -180,17 +191,8 @@ class SettingsDialog
|
|
|
180
191
|
store = Gtk::ListStore.new(String)
|
|
181
192
|
paths.each { |p| store.append[0] = p }
|
|
182
193
|
|
|
183
|
-
tv =
|
|
184
|
-
|
|
185
|
-
renderer = Gtk::CellRendererText.new
|
|
186
|
-
renderer.ellipsize = Pango::EllipsizeMode::START
|
|
187
|
-
col = Gtk::TreeViewColumn.new("", renderer, text: 0)
|
|
188
|
-
col.expand = true
|
|
189
|
-
tv.append_column(col)
|
|
190
|
-
|
|
191
|
-
sw = Gtk::ScrolledWindow.new
|
|
192
|
-
sw.set_policy(:automatic, :automatic)
|
|
193
|
-
sw.set_child(tv)
|
|
194
|
+
tv, sw = build_list_tree(store, ellipsize: Pango::EllipsizeMode::START,
|
|
195
|
+
single_click: false, hpolicy: :automatic)
|
|
194
196
|
sw.set_size_request(-1, 120)
|
|
195
197
|
sw.vexpand = true
|
|
196
198
|
|
|
@@ -201,6 +203,7 @@ class SettingsDialog
|
|
|
201
203
|
:action => :select_folder,
|
|
202
204
|
:buttons => [["Select", :accept], ["Cancel", :cancel]],
|
|
203
205
|
)
|
|
206
|
+
chooser.add_css_class("vma-dialog")
|
|
204
207
|
chooser.set_transient_for(@window)
|
|
205
208
|
chooser.modal = true
|
|
206
209
|
chooser.signal_connect("response") do |dlg, resp|
|
|
@@ -249,9 +252,15 @@ class SettingsDialog
|
|
|
249
252
|
end
|
|
250
253
|
cnf_set(key, val) unless val.nil?
|
|
251
254
|
end
|
|
255
|
+
# Before save_settings_to_file: gui_refresh_colors re-reads every cnf color
|
|
256
|
+
# and reloads the CSS providers live, and (via gui_refresh_theme) may flip
|
|
257
|
+
# cnf.style_scheme to keep the buffer scheme in step with the theme toggle.
|
|
258
|
+
gui_refresh_colors
|
|
252
259
|
save_settings_to_file
|
|
253
260
|
gui_refresh_font
|
|
254
261
|
gui_refresh_style_scheme
|
|
262
|
+
# Re-highlight color swatches after a color change, if the plugin is loaded.
|
|
263
|
+
vma.gui.buffers.each_value { |v| v.highlight_colors if v.respond_to?(:highlight_colors) }
|
|
255
264
|
activate_no_restart_modules
|
|
256
265
|
@window.destroy
|
|
257
266
|
end
|
|
@@ -273,7 +282,7 @@ class SettingsDialog
|
|
|
273
282
|
next unless File.exist?(main_file)
|
|
274
283
|
load main_file
|
|
275
284
|
init_fn = "#{mod_name}_init"
|
|
276
|
-
send(init_fn) if respond_to?(init_fn, true)
|
|
285
|
+
vma.kbd.with_keywords(["module:#{mod_name}"]) { send(init_fn) } if respond_to?(init_fn, true)
|
|
277
286
|
elsif was_enabled && !now_enabled
|
|
278
287
|
# Toggled off: call <name>_disable to unregister actions and bindings.
|
|
279
288
|
disable_fn = "#{mod_name}_disable"
|
|
@@ -355,7 +364,7 @@ end
|
|
|
355
364
|
|
|
356
365
|
# Find the XML file on disk for a given scheme id.
|
|
357
366
|
def find_scheme_xml_path(scheme_id)
|
|
358
|
-
user_styles_dir =
|
|
367
|
+
user_styles_dir = get_dot_path("styles")
|
|
359
368
|
ssm = GtkSource::StyleSchemeManager.new
|
|
360
369
|
ssm.set_search_path(ssm.search_path << ppath("styles/") << user_styles_dir)
|
|
361
370
|
ssm.search_path.each do |dir|
|
|
@@ -386,7 +395,7 @@ def apply_contrast_transformation(base_scheme_id, contrast, brightness)
|
|
|
386
395
|
adjusted = adjusted.sub(/(<style-scheme\b[^>]*)id="[^"]*"/, "\\1id=\"#{VIMAMSA_CONTRAST_SCHEME_ID}\"")
|
|
387
396
|
adjusted = adjusted.sub(/(<style-scheme\b[^>]*)name="[^"]*"/, "\\1name=\"#{VIMAMSA_CONTRAST_SCHEME_ID}\"")
|
|
388
397
|
adjusted = adjusted.sub(/\s*parent-scheme="[^"]*"/, "") # avoid inheritance chains
|
|
389
|
-
user_styles_dir =
|
|
398
|
+
user_styles_dir = get_dot_path("styles")
|
|
390
399
|
FileUtils.mkdir_p(user_styles_dir)
|
|
391
400
|
IO.write(File.join(user_styles_dir, "_vimamsa_contrast.xml"), adjusted)
|
|
392
401
|
VIMAMSA_CONTRAST_SCHEME_ID
|
|
@@ -402,18 +411,52 @@ def style_fg_attr(sty, style_name, default_fg = nil)
|
|
|
402
411
|
fg ? " foreground=\"#{fg}\"" : ""
|
|
403
412
|
end
|
|
404
413
|
|
|
414
|
+
# Markup styles used by markdown.lang (and rst, asciidoc, ...). def.lang gives
|
|
415
|
+
# them no fallback, so a scheme that doesn't define them draws headings, code
|
|
416
|
+
# and links as plain text. Each is
|
|
417
|
+
# name => [attributes, styles to take the foreground from (first one set)]
|
|
418
|
+
MARKUP_OVERLAY_STYLES = {
|
|
419
|
+
"def:heading" => ['bold="true"', ["def:heading1", "def:keyword"]],
|
|
420
|
+
"def:strong-emphasis" => ['bold="true"', []],
|
|
421
|
+
"def:emphasis" => ['italic="true"', []],
|
|
422
|
+
"def:inline-code" => ["", ["def:string"]],
|
|
423
|
+
"def:preformatted-section" => ["", ["def:string"]],
|
|
424
|
+
"def:link-text" => ['underline="low"', ["def:hyperlink"]],
|
|
425
|
+
"def:link-destination" => ["", ["def:comment"]],
|
|
426
|
+
"def:link-symbol" => ["", ["def:comment"]],
|
|
427
|
+
"def:list-marker" => ['bold="true"', ["def:statement", "def:keyword"]],
|
|
428
|
+
"def:thematic-break" => ["", ["def:comment"]],
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
# <style> lines for the MARKUP_OVERLAY_STYLES the parent scheme lacks. Styles
|
|
432
|
+
# the parent defines (all stock GtkSourceView schemes do) are left alone.
|
|
433
|
+
def markup_overlay_styles(parent_sty)
|
|
434
|
+
MARKUP_OVERLAY_STYLES.filter_map { |name, (attrs, from)|
|
|
435
|
+
next if parent_sty&.get_style(name)
|
|
436
|
+
fg = from.lazy.map { |f| parent_sty&.get_style(f)&.foreground }.find { |c| c && !c.empty? }
|
|
437
|
+
fg = "#4FC3F7" if fg.nil? && name == "def:link-text"
|
|
438
|
+
a = [attrs, fg && "foreground=\"#{fg}\""].reject { |x| x.nil? || x.empty? }.join(" ")
|
|
439
|
+
" <style name=\"#{name}\" #{a}/>"
|
|
440
|
+
}.join("\n ")
|
|
441
|
+
end
|
|
442
|
+
|
|
405
443
|
# Generate a GtkSourceView style scheme that inherits from base_scheme_id
|
|
406
444
|
# (optionally contrast-adjusted) and overlays Vimamsa-specific heading/
|
|
407
445
|
# hyperlink styles on top. Written to styles/_vimamsa_overlay.xml.
|
|
408
446
|
# Foreground colors are read from the parent scheme so they are preserved.
|
|
409
447
|
def generate_vimamsa_overlay(base_scheme_id)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
448
|
+
adjustments_enabled = cnf_get([:color_adjustments, :enabled]) != false
|
|
449
|
+
parent_id = base_scheme_id
|
|
450
|
+
if adjustments_enabled
|
|
451
|
+
contrast = (cnf_get([:color_contrast]) || 1.0).to_f
|
|
452
|
+
brightness = (cnf_get([:color_brightness]) || 0.0).to_f
|
|
453
|
+
parent_id = apply_contrast_transformation(base_scheme_id, contrast, brightness)
|
|
454
|
+
end
|
|
413
455
|
|
|
414
456
|
# Load the parent scheme to read existing foreground colors for headings/links
|
|
457
|
+
user_styles_dir = get_dot_path("styles")
|
|
415
458
|
ssm = GtkSource::StyleSchemeManager.new
|
|
416
|
-
ssm.set_search_path(ssm.search_path << ppath("styles/"))
|
|
459
|
+
ssm.set_search_path(ssm.search_path << ppath("styles/") << user_styles_dir)
|
|
417
460
|
parent_sty = ssm.get_scheme(parent_id)
|
|
418
461
|
|
|
419
462
|
xml = <<~XML
|
|
@@ -421,17 +464,17 @@ def generate_vimamsa_overlay(base_scheme_id)
|
|
|
421
464
|
<style-scheme id="#{VIMAMSA_OVERLAY_SCHEME_ID}" name="#{VIMAMSA_OVERLAY_SCHEME_ID}" version="1.0" parent-scheme="#{parent_id}">
|
|
422
465
|
<style name="def:title" scale="2.0" bold="true"#{style_fg_attr(parent_sty, "def:title")}/>
|
|
423
466
|
<style name="def:hyperlink" bold="true"#{style_fg_attr(parent_sty, "def:hyperlink", "#4FC3F7")}/>
|
|
424
|
-
<style name="def:heading0" scale="2.0" bold="true"#{style_fg_attr(parent_sty, "def:heading0")}/>
|
|
425
|
-
<style name="def:heading1" scale="1.75" bold="true"#{style_fg_attr(parent_sty, "def:heading1")}/>
|
|
426
|
-
<style name="def:heading2" scale="1.5" bold="true"#{style_fg_attr(parent_sty, "def:heading2")}/>
|
|
467
|
+
<style name="def:heading0" scale="2.0" bold="true"#{style_fg_attr(parent_sty, "def:heading0")} underline="low"/>
|
|
468
|
+
<style name="def:heading1" scale="1.75" bold="true"#{style_fg_attr(parent_sty, "def:heading1")} underline="low"/>
|
|
469
|
+
<style name="def:heading2" scale="1.5" bold="true"#{style_fg_attr(parent_sty, "def:heading2")} underline="low"/>
|
|
427
470
|
<style name="def:heading3" scale="1.25" bold="true"#{style_fg_attr(parent_sty, "def:heading3")}/>
|
|
428
471
|
<style name="def:heading4" scale="1.175" bold="true"#{style_fg_attr(parent_sty, "def:heading4")}/>
|
|
429
472
|
<style name="def:heading5" scale="1.1" bold="true"#{style_fg_attr(parent_sty, "def:heading5")}/>
|
|
430
473
|
<style name="def:heading6" scale="1.0" bold="true"#{style_fg_attr(parent_sty, "def:heading6")}/>
|
|
431
474
|
<style name="def:bold" bold="true"/>
|
|
475
|
+
#{markup_overlay_styles(parent_sty)}
|
|
432
476
|
</style-scheme>
|
|
433
477
|
XML
|
|
434
|
-
user_styles_dir = File.expand_path("~/.config/vimamsa/styles")
|
|
435
478
|
FileUtils.mkdir_p(user_styles_dir)
|
|
436
479
|
IO.write(File.join(user_styles_dir, "_vimamsa_overlay.xml"), xml)
|
|
437
480
|
end
|
|
@@ -442,7 +485,7 @@ end
|
|
|
442
485
|
def load_vimamsa_scheme
|
|
443
486
|
base_id = cnf.style_scheme! || "molokai_edit"
|
|
444
487
|
generate_vimamsa_overlay(base_id)
|
|
445
|
-
user_styles_dir =
|
|
488
|
+
user_styles_dir = get_dot_path("styles")
|
|
446
489
|
ssm = GtkSource::StyleSchemeManager.new
|
|
447
490
|
ssm.set_search_path(ssm.search_path << ppath("styles/") << user_styles_dir)
|
|
448
491
|
ssm.get_scheme(VIMAMSA_OVERLAY_SCHEME_ID)
|
|
@@ -467,7 +510,9 @@ end
|
|
|
467
510
|
|
|
468
511
|
# Apply dark/light GTK preference to match the given style scheme.
|
|
469
512
|
def gui_apply_color_mode(sty)
|
|
470
|
-
|
|
513
|
+
light = scheme_is_light?(sty)
|
|
514
|
+
Gtk::Settings.default.gtk_application_prefer_dark_theme = !light
|
|
515
|
+
$vmag.scheme_is_light = light if $vmag
|
|
471
516
|
end
|
|
472
517
|
|
|
473
518
|
def gui_refresh_style_scheme
|
|
@@ -484,9 +529,9 @@ def gui_refresh_font
|
|
|
484
529
|
return unless $vmag
|
|
485
530
|
provider = Gtk::CssProvider.new
|
|
486
531
|
provider.load(data: "textview { font-family: #{get(cnf.font.family)}; font-size: #{get(cnf.font.size)}pt; }")
|
|
487
|
-
|
|
488
|
-
view = window[:sw].child
|
|
532
|
+
vma.gui.buffers.each_value do |view|
|
|
489
533
|
next if view.nil?
|
|
490
534
|
view.style_context.add_provider(provider)
|
|
491
535
|
end
|
|
492
536
|
end
|
|
537
|
+
end # module Vimamsa
|