Edit location and rename key bindings
This commit is contained in:
parent
1dc9b9c1b1
commit
24ccc9bd82
4 changed files with 35 additions and 2 deletions
21
src/app.rs
21
src/app.rs
|
|
@ -44,6 +44,7 @@ pub enum Action {
|
||||||
About,
|
About,
|
||||||
Copy,
|
Copy,
|
||||||
Cut,
|
Cut,
|
||||||
|
EditLocation,
|
||||||
HistoryNext,
|
HistoryNext,
|
||||||
HistoryPrevious,
|
HistoryPrevious,
|
||||||
LocationUp,
|
LocationUp,
|
||||||
|
|
@ -74,6 +75,7 @@ impl Action {
|
||||||
Action::About => Message::ToggleContextPage(ContextPage::About),
|
Action::About => Message::ToggleContextPage(ContextPage::About),
|
||||||
Action::Copy => Message::Copy(entity_opt),
|
Action::Copy => Message::Copy(entity_opt),
|
||||||
Action::Cut => Message::Cut(entity_opt),
|
Action::Cut => Message::Cut(entity_opt),
|
||||||
|
Action::EditLocation => Message::EditLocation(entity_opt),
|
||||||
Action::HistoryNext => Message::TabMessage(None, tab::Message::GoNext),
|
Action::HistoryNext => Message::TabMessage(None, tab::Message::GoNext),
|
||||||
Action::HistoryPrevious => Message::TabMessage(None, tab::Message::GoPrevious),
|
Action::HistoryPrevious => Message::TabMessage(None, tab::Message::GoPrevious),
|
||||||
Action::LocationUp => Message::TabMessage(None, tab::Message::LocationUp),
|
Action::LocationUp => Message::TabMessage(None, tab::Message::LocationUp),
|
||||||
|
|
@ -114,6 +116,7 @@ pub enum Message {
|
||||||
DialogCancel,
|
DialogCancel,
|
||||||
DialogComplete,
|
DialogComplete,
|
||||||
DialogUpdate(DialogPage),
|
DialogUpdate(DialogPage),
|
||||||
|
EditLocation(Option<segmented_button::Entity>),
|
||||||
Key(Modifiers, Key),
|
Key(Modifiers, Key),
|
||||||
LaunchUrl(String),
|
LaunchUrl(String),
|
||||||
Modifiers(Modifiers),
|
Modifiers(Modifiers),
|
||||||
|
|
@ -739,6 +742,21 @@ impl Application for App {
|
||||||
//TODO: panicless way to do this?
|
//TODO: panicless way to do this?
|
||||||
self.dialog_pages[0] = dialog_page;
|
self.dialog_pages[0] = dialog_page;
|
||||||
}
|
}
|
||||||
|
Message::EditLocation(entity_opt) => {
|
||||||
|
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||||
|
if let Some(location) = self.tab_model.data::<Tab>(entity).and_then(|tab| {
|
||||||
|
if tab.edit_location.is_none() {
|
||||||
|
Some(tab.location.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
return self.update(Message::TabMessage(
|
||||||
|
Some(entity),
|
||||||
|
tab::Message::EditLocation(Some(location)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::Key(modifiers, key) => {
|
Message::Key(modifiers, key) => {
|
||||||
let entity = self.tab_model.active();
|
let entity = self.tab_model.active();
|
||||||
for (key_bind, action) in self.key_binds.iter() {
|
for (key_bind, action) in self.key_binds.iter() {
|
||||||
|
|
@ -1024,6 +1042,9 @@ impl Application for App {
|
||||||
self.rescan_tab(entity, tab_path),
|
self.rescan_tab(entity, tab_path),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
tab::Command::FocusTextInput(id) => {
|
||||||
|
commands.push(widget::text_input::focus(id));
|
||||||
|
}
|
||||||
tab::Command::OpenFile(item_path) => {
|
tab::Command::OpenFile(item_path) => {
|
||||||
match open::that_detached(&item_path) {
|
match open::that_detached(&item_path) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
|
|
|
||||||
|
|
@ -572,6 +572,9 @@ impl Application for App {
|
||||||
commands
|
commands
|
||||||
.push(Command::batch([self.update_watcher(), self.rescan_tab()]));
|
.push(Command::batch([self.update_watcher(), self.rescan_tab()]));
|
||||||
}
|
}
|
||||||
|
tab::Command::FocusTextInput(id) => {
|
||||||
|
commands.push(widget::text_input::focus(id));
|
||||||
|
}
|
||||||
tab::Command::OpenFile(_item_path) => {
|
tab::Command::OpenFile(_item_path) => {
|
||||||
if self.flags.kind.save() {
|
if self.flags.kind.save() {
|
||||||
commands.push(self.update(Message::Save(false)));
|
commands.push(self.update(Message::Save(false)));
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
||||||
let mut key_binds = HashMap::new();
|
let mut key_binds = HashMap::new();
|
||||||
|
|
||||||
macro_rules! bind {
|
macro_rules! bind {
|
||||||
([$($modifier:ident),+ $(,)?], $key:expr, $action:ident) => {{
|
([$($modifier:ident),* $(,)?], $key:expr, $action:ident) => {{
|
||||||
key_binds.insert(
|
key_binds.insert(
|
||||||
KeyBind {
|
KeyBind {
|
||||||
modifiers: vec![$(Modifier::$modifier),+],
|
modifiers: vec![$(Modifier::$modifier),*],
|
||||||
key: $key,
|
key: $key,
|
||||||
},
|
},
|
||||||
Action::$action,
|
Action::$action,
|
||||||
|
|
@ -62,10 +62,12 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
||||||
|
|
||||||
bind!([Ctrl], Key::Character("c".into()), Copy);
|
bind!([Ctrl], Key::Character("c".into()), Copy);
|
||||||
bind!([Ctrl], Key::Character("x".into()), Cut);
|
bind!([Ctrl], Key::Character("x".into()), Cut);
|
||||||
|
bind!([Ctrl], Key::Character("l".into()), EditLocation);
|
||||||
bind!([Alt], Key::Named(Named::ArrowRight), HistoryNext);
|
bind!([Alt], Key::Named(Named::ArrowRight), HistoryNext);
|
||||||
bind!([Alt], Key::Named(Named::ArrowLeft), HistoryPrevious);
|
bind!([Alt], Key::Named(Named::ArrowLeft), HistoryPrevious);
|
||||||
bind!([Alt], Key::Named(Named::ArrowUp), LocationUp);
|
bind!([Alt], Key::Named(Named::ArrowUp), LocationUp);
|
||||||
bind!([Ctrl], Key::Character("v".into()), Paste);
|
bind!([Ctrl], Key::Character("v".into()), Paste);
|
||||||
|
bind!([], Key::Named(Named::F2), Rename);
|
||||||
bind!([Ctrl], Key::Character("a".into()), SelectAll);
|
bind!([Ctrl], Key::Character("a".into()), SelectAll);
|
||||||
bind!([Ctrl], Key::Character("w".into()), TabClose);
|
bind!([Ctrl], Key::Character("w".into()), TabClose);
|
||||||
bind!([Ctrl], Key::Character("t".into()), TabNew);
|
bind!([Ctrl], Key::Character("t".into()), TabNew);
|
||||||
|
|
|
||||||
|
|
@ -357,6 +357,7 @@ impl Location {
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Action(Action),
|
Action(Action),
|
||||||
ChangeLocation(String, Location),
|
ChangeLocation(String, Location),
|
||||||
|
FocusTextInput(widget::Id),
|
||||||
OpenFile(PathBuf),
|
OpenFile(PathBuf),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -530,6 +531,7 @@ pub struct Tab {
|
||||||
pub drag_opt: Option<Point>,
|
pub drag_opt: Option<Point>,
|
||||||
pub scroll_opt: Option<Viewport>,
|
pub scroll_opt: Option<Viewport>,
|
||||||
pub edit_location: Option<Location>,
|
pub edit_location: Option<Location>,
|
||||||
|
pub edit_location_id: widget::Id,
|
||||||
pub history_i: usize,
|
pub history_i: usize,
|
||||||
pub history: Vec<Location>,
|
pub history: Vec<Location>,
|
||||||
pub config: TabConfig,
|
pub config: TabConfig,
|
||||||
|
|
@ -551,6 +553,7 @@ impl Tab {
|
||||||
drag_opt: None,
|
drag_opt: None,
|
||||||
scroll_opt: None,
|
scroll_opt: None,
|
||||||
edit_location: None,
|
edit_location: None,
|
||||||
|
edit_location_id: widget::Id::unique(),
|
||||||
history_i: 0,
|
history_i: 0,
|
||||||
history,
|
history,
|
||||||
config,
|
config,
|
||||||
|
|
@ -678,6 +681,9 @@ impl Tab {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::EditLocation(edit_location) => {
|
Message::EditLocation(edit_location) => {
|
||||||
|
if self.edit_location.is_none() && edit_location.is_some() {
|
||||||
|
commands.push(Command::FocusTextInput(self.edit_location_id.clone()));
|
||||||
|
}
|
||||||
self.edit_location = edit_location;
|
self.edit_location = edit_location;
|
||||||
}
|
}
|
||||||
Message::GoNext => {
|
Message::GoNext => {
|
||||||
|
|
@ -883,6 +889,7 @@ impl Tab {
|
||||||
);
|
);
|
||||||
row = row.push(
|
row = row.push(
|
||||||
widget::text_input("", path.to_string_lossy())
|
widget::text_input("", path.to_string_lossy())
|
||||||
|
.id(self.edit_location_id.clone())
|
||||||
.on_input(|input| {
|
.on_input(|input| {
|
||||||
Message::EditLocation(Some(Location::Path(PathBuf::from(input))))
|
Message::EditLocation(Some(Location::Path(PathBuf::from(input))))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue