Prefer .map
for conditionals with else
conditions (#15118)
This PR updates instances where we were using `.when_else` and `.when_else_some` to use `.map` with a conditional inside. This allows us to avoid reinventing Rust's syntax for conditionals and (IMO) makes the code easier to read. Release Notes: - N/A
This commit is contained in:
parent
596ee58be8
commit
298ca5ff1b
6 changed files with 55 additions and 93 deletions
|
@ -464,15 +464,12 @@ impl ProjectPanel {
|
|||
let is_remote = project.is_remote() && project.dev_server_project_id().is_none();
|
||||
|
||||
let context_menu = ContextMenu::build(cx, |menu, cx| {
|
||||
menu.context(self.focus_handle.clone()).when_else(
|
||||
is_read_only,
|
||||
|menu| {
|
||||
menu.action("Copy Relative Path", Box::new(CopyRelativePath))
|
||||
.when(is_dir, |menu| {
|
||||
menu.action("Search Inside", Box::new(NewSearchInDirectory))
|
||||
})
|
||||
},
|
||||
|menu| {
|
||||
menu.context(self.focus_handle.clone()).map(|menu| {
|
||||
if is_read_only {
|
||||
menu.when(is_dir, |menu| {
|
||||
menu.action("Search Inside", Box::new(NewSearchInDirectory))
|
||||
})
|
||||
} else {
|
||||
menu.action("New File", Box::new(NewFile))
|
||||
.action("New Folder", Box::new(NewDirectory))
|
||||
.separator()
|
||||
|
@ -545,8 +542,8 @@ impl ProjectPanel {
|
|||
menu.separator()
|
||||
.action("Collapse All", Box::new(CollapseAllEntries))
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
cx.focus_view(&context_menu);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue