diff --git a/src/bin/edit/draw_menubar.rs b/src/bin/edit/draw_menubar.rs index 9fe8b7cefb63..ddd5431ce1d8 100644 --- a/src/bin/edit/draw_menubar.rs +++ b/src/bin/edit/draw_menubar.rs @@ -178,3 +178,58 @@ pub fn draw_dialog_about(ctx: &mut Context, state: &mut State) { state.wants_about = false; } } + +pub fn draw_dialog_shortcuts(ctx: &mut Context, state: &mut State) { + ctx.modal_begin("Shortcuts", loc(LocId::KeyboardShortcutDialogTitle)); + { + ctx.block_begin("content"); + ctx.inherit_focus(); + ctx.attr_padding(Rect::three(1, 2, 1)); + { + ctx.attr_position(Position::Center); + + let shortcuts = [ + (loc(LocId::EditCopy), "Ctrl + C"), + (loc(LocId::EditCut), "Ctrl + X"), + (loc(LocId::EditPaste), "Ctrl + V"), + (loc(LocId::EditUndo), "Ctrl + Z"), + (loc(LocId::EditRedo), "Ctrl + Y"), + (loc(LocId::EditFind), "Ctrl + F"), + (loc(LocId::EditReplace), "Ctrl + R"), + (loc(LocId::EditSelectAll), "Ctrl + A"), + (loc(LocId::FileNew), "Ctrl + N"), + (loc(LocId::FileOpen), "Ctrl + O"), + (loc(LocId::FileSave), "Ctrl + S"), + (loc(LocId::FileClose), "Ctrl + W"), + (loc(LocId::FileExit), "Ctrl + Q"), + (loc(LocId::FileGoto), "Ctrl + G"), + (loc(LocId::ShortcutSelectLine), "Ctrl + L"), + ]; + + ctx.table_begin("shortcuts_table"); + ctx.table_set_cell_gap(Size { width: (5), height: (0) }); + for (desc, key) in shortcuts.iter() { + ctx.table_next_row(); + ctx.label("shortcut_desc", desc); + ctx.label("shortcut_key", key); + } + ctx.table_end(); + + ctx.block_begin("choices"); + ctx.inherit_focus(); + ctx.attr_padding(Rect::three(1, 2, 0)); + ctx.attr_position(Position::Center); + { + if ctx.button("ok", loc(LocId::Ok), ButtonStyle::default()) { + state.wants_shortcuts_list = false; + } + ctx.inherit_focus(); + } + ctx.block_end(); + } + ctx.block_end(); + } + if ctx.modal_end() { + state.wants_shortcuts_list = false; + } +} diff --git a/src/bin/edit/draw_statusbar.rs b/src/bin/edit/draw_statusbar.rs index f7a631ace129..d81bc1756b1d 100644 --- a/src/bin/edit/draw_statusbar.rs +++ b/src/bin/edit/draw_statusbar.rs @@ -25,6 +25,7 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) { let mut tb = doc.buffer.borrow_mut(); ctx.table_next_row(); + ctx.label("help-hint", "[F1=Help]"); if ctx.button("newline", if tb.is_crlf() { "CRLF" } else { "LF" }, ButtonStyle::default()) { let is_crlf = tb.is_crlf(); @@ -121,7 +122,7 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) { } } ctx.list_end(); - + ctx.list_begin("width"); ctx.attr_padding(Rect::two(0, 2)); { @@ -171,7 +172,7 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) { if tb.is_dirty() { ctx.label("dirty", "*"); } - + ctx.block_begin("filename-container"); ctx.attr_intrinsic_size(Size { width: COORD_TYPE_SAFE_MAX, height: 1 }); { diff --git a/src/bin/edit/localization.rs b/src/bin/edit/localization.rs index f42838625b6f..59b5a8d0f414 100644 --- a/src/bin/edit/localization.rs +++ b/src/bin/edit/localization.rs @@ -91,6 +91,9 @@ pub enum LocId { FileOverwriteWarning, FileOverwriteWarningDescription, + // Keyboard shortcuts dialog + KeyboardShortcutDialogTitle, + ShortcutSelectLine, Count, } @@ -959,6 +962,34 @@ const S_LANG_LUT: [[&str; LangId::Count as usize]; LocId::Count as usize] = [ /* zh_hans */ "文件已存在。要覆盖它吗?", /* zh_hant */ "檔案已存在。要覆蓋它嗎?", ], + //KeyboardShortcutsDialogTitle + [ + /* en */ "Keyboard Shortcuts", + /* de */ "Tastenkürzel", + /* es */ "Atajos de teclado", + /* fr */ "Raccourcis clavier", + /* it */ "Scorciatoie da tastiera", + /* ja */ "キーボードショートカット", + /* ko */ "키보드 단축키", + /* pt_br */ "Atalhos de teclado", + /* ru */ "Сочетания клавиш", + /* zh_hans */ "键盘快捷键", + /* zh_hant */ "鍵盤快速鍵", + ], + // ShortcutSelectLine + [ + /* en */ "Select line", + /* de */ "Zeile auswählen", + /* es */ "Seleccionar línea", + /* fr */ "Sélectionner la ligne", + /* it */ "Seleziona riga", + /* ja */ "行を選択", + /* ko */ "줄 선택", + /* pt_br */ "Selecionar linha", + /* ru */ "Выделить строку", + /* zh_hans */ "选择行", + /* zh_hant */ "選取行", + ], ]; static mut S_LANG: LangId = LangId::en; diff --git a/src/bin/edit/main.rs b/src/bin/edit/main.rs index 39b218d78c85..eb1ad69735c9 100644 --- a/src/bin/edit/main.rs +++ b/src/bin/edit/main.rs @@ -317,6 +317,9 @@ fn draw(ctx: &mut Context, state: &mut State) { if state.error_log_count != 0 { draw_error_log(ctx, state); } + if state.wants_shortcuts_list { + draw_dialog_shortcuts(ctx, state); + } if let Some(key) = ctx.keyboard_input() { // Shortcuts that are not handled as part of the textarea, etc. @@ -347,7 +350,10 @@ fn draw(ctx: &mut Context, state: &mut State) { state.wants_search.focus = true; } else if key == vk::F3 { search_execute(ctx, state, SearchAction::Search); - } else { + } else if key == vk:: F1 { + state.wants_shortcuts_list = true; + } + else { return; } diff --git a/src/bin/edit/state.rs b/src/bin/edit/state.rs index a42d8c095739..bdefc750820b 100644 --- a/src/bin/edit/state.rs +++ b/src/bin/edit/state.rs @@ -164,6 +164,7 @@ pub struct State { pub wants_close: bool, pub wants_exit: bool, pub wants_goto: bool, + pub wants_shortcuts_list: bool, pub goto_target: String, pub goto_invalid: bool, @@ -209,6 +210,7 @@ impl State { wants_indentation_picker: false, wants_go_to_file: false, wants_about: false, + wants_shortcuts_list:false, wants_close: false, wants_exit: false, wants_goto: false,