Skip to content

Commit

Permalink
feat: use cmd key for keybindings on macos (fluxxcode#205)
Browse files Browse the repository at this point in the history
* change all ctrl keys to command
  • Loading branch information
hacknus authored and fluxxcode committed Nov 23, 2024
1 parent fd8649e commit 5511090
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The latest changes included in the next release can be found in the [CHANGELOG.m
- Select a file or a directory
- Save a file (Prompt user for a destination path)
- Dialog to ask the user if the existing file should be overwritten
- Select multiple files and folders at once (ctrl/shift + click)
- Select multiple files and folders at once (ctrl/shift + click on linux/windows and cmd/shift + click on macOS)
- Open the dialog in a normal or modal window
- Create a new folder
- Keyboard navigation
Expand Down Expand Up @@ -127,12 +127,13 @@ The following table lists all available keybindings and their default values.
| back | Go back | `Mouse button 1` <br/> `ALT` + `` <br/> `Backspace` |
| forward | Go forward | `Mouse button 2` <br/> `ALT` + `` |
| reload | Reload the file dialog data and the currently open directory | `F5` |
| new_folder | Open the dialog to create a new folder | `CTRL` + `N` |
| new_folder | Open the dialog to create a new folder | `CTRL` + `N` on linux/windows or `CMD` + `N` on macOS |
| edit_path | Text edit the current path | `/` |
| home_edit_path | Open the home directory and start text editing the path | `~` |
| selection_up | Move the selection one item up | `` |
| selection_down | Move the selection one item down | `` |
| select_all | Select every item in the directory when using the file dialog to select multiple files and folders | `CTRL` + `A` |
| select_all | Select every item in the directory when using the file dialog to select multiple files and folders |
`CTRL` + `A` on linux/windows or `CMD` + `A` on macOS |

## Customization
Many things can be customized so that the dialog can be used in different situations. \
Expand Down
4 changes: 2 additions & 2 deletions src/config/keybindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ impl Default for FileDialogKeyBindings {
KeyBinding::keyboard_shortcut(Modifiers::ALT, Key::ArrowRight),
],
reload: vec![KeyBinding::key(egui::Key::F5)],
new_folder: vec![KeyBinding::keyboard_shortcut(Modifiers::CTRL, Key::N)],
new_folder: vec![KeyBinding::keyboard_shortcut(Modifiers::COMMAND, Key::N)],
edit_path: vec![KeyBinding::key(Key::Slash)],
home_edit_path: vec![
KeyBinding::keyboard_shortcut(Modifiers::SHIFT, egui::Key::Backtick),
KeyBinding::text("~".to_string()),
],
selection_up: vec![KeyBinding::key(Key::ArrowUp)],
selection_down: vec![KeyBinding::key(Key::ArrowDown)],
select_all: vec![KeyBinding::keyboard_shortcut(Modifiers::CTRL, Key::A)],
select_all: vec![KeyBinding::keyboard_shortcut(Modifiers::COMMAND, Key::A)],
}
}
}
8 changes: 5 additions & 3 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ impl FileDialog {

// The user wants to select the item as the primary selected item
if re.clicked()
&& !ui.input(|i| i.modifiers.ctrl)
&& !ui.input(|i| i.modifiers.command)
&& !ui.input(|i| i.modifiers.shift_only())
{
self.select_item(item);
Expand All @@ -2208,7 +2208,9 @@ impl FileDialog {

// The user wants to select or unselect the item as part of a
// multi selection
if self.mode == DialogMode::SelectMultiple && re.clicked() && ui.input(|i| i.modifiers.ctrl)
if self.mode == DialogMode::SelectMultiple
&& re.clicked()
&& ui.input(|i| i.modifiers.command)
{
if primary_selected {
// If the clicked item is the primary selected item,
Expand Down Expand Up @@ -2244,7 +2246,7 @@ impl FileDialog {

// The user double clicked on the directory entry.
// Either open the directory or submit the dialog.
if re.double_clicked() && !ui.input(|i| i.modifiers.ctrl) {
if re.double_clicked() && !ui.input(|i| i.modifiers.command) {
if item.is_dir() {
self.load_directory(&item.to_path_buf());
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! - Select a file or a directory
//! - Save a file (Prompt user for a destination path)
//! - Dialog to ask the user if the existing file should be overwritten
//! - Select multiple files and folders at once (ctrl/shift + click)
//! - Select multiple files and folders at once (ctrl/shift + click on linux/windows or cmd/shift + click on macOS)
//! - Open the dialog in a normal or modal window
//! - Create a new folder
//! - Keyboard navigation
Expand Down Expand Up @@ -78,12 +78,12 @@
//! | `back` | Go back | `Mouse button 1` <br/> `ALT` + `←` <br/> `Backspace` |
//! | `forward` | Go forward | `Mouse button 2` <br/> `ALT` + `→` |
//! | `reload` | Reload the file dialog data and the currently open directory | `F5` |
//! | `new_folder` | Open the dialog to create a new folder | `CTRL` + `N` |
//! | `new_folder` | Open the dialog to create a new folder | `CTRL` + `N` on linux/windows or `CMD` + `N` on macOS |
//! | `edit_path` | Text edit the current path | `/` |
//! | `home_edit_path` | Open the home directory and start text editing the path | `~` |
//! | `selection_up` | Move the selection one item up | `↑` |
//! | `selection_down` | Move the selection one item down | `↓` |
//! | `select_all` | Select every item in the directory when using the file dialog to select multiple files and folders | `CTRL` + `A` |
//! | `select_all` | Select every item in the directory when using the file dialog to select multiple files and folders | `CTRL` + `A` on linux/windows or `CMD` + `A` on macOS |
//!
//! ### Customization
//! Many things can be customized so that the dialog can be used in different situations. \
Expand Down

0 comments on commit 5511090

Please sign in to comment.