@@ -2374,232 +2374,234 @@ impl Pane {
let is_pinned = self.is_tab_pinned(ix);
let pane = cx.entity().downgrade();
let menu_context = item.item_focus_handle(cx);
- right_click_menu(ix).trigger(tab).menu(move |window, cx| {
- let pane = pane.clone();
- let menu_context = menu_context.clone();
- ContextMenu::build(window, cx, move |mut menu, window, cx| {
- if let Some(pane) = pane.upgrade() {
- menu = menu
- .entry(
- "Close",
- Some(Box::new(CloseActiveItem {
- save_intent: None,
- close_pinned: true,
- })),
- window.handler_for(&pane, move |pane, window, cx| {
- pane.close_item_by_id(item_id, SaveIntent::Close, window, cx)
- .detach_and_log_err(cx);
- }),
- )
- .item(ContextMenuItem::Entry(
- ContextMenuEntry::new("Close Others")
- .action(Box::new(CloseInactiveItems {
+ right_click_menu(ix)
+ .trigger(|_| tab)
+ .menu(move |window, cx| {
+ let pane = pane.clone();
+ let menu_context = menu_context.clone();
+ ContextMenu::build(window, cx, move |mut menu, window, cx| {
+ if let Some(pane) = pane.upgrade() {
+ menu = menu
+ .entry(
+ "Close",
+ Some(Box::new(CloseActiveItem {
save_intent: None,
- close_pinned: false,
- }))
- .disabled(total_items == 1)
- .handler(window.handler_for(&pane, move |pane, window, cx| {
- pane.close_items(window, cx, SaveIntent::Close, |id| {
- id != item_id
- })
- .detach_and_log_err(cx);
+ close_pinned: true,
})),
- ))
- .separator()
- .item(ContextMenuItem::Entry(
- ContextMenuEntry::new("Close Left")
- .action(Box::new(CloseItemsToTheLeft {
+ window.handler_for(&pane, move |pane, window, cx| {
+ pane.close_item_by_id(item_id, SaveIntent::Close, window, cx)
+ .detach_and_log_err(cx);
+ }),
+ )
+ .item(ContextMenuItem::Entry(
+ ContextMenuEntry::new("Close Others")
+ .action(Box::new(CloseInactiveItems {
+ save_intent: None,
+ close_pinned: false,
+ }))
+ .disabled(total_items == 1)
+ .handler(window.handler_for(&pane, move |pane, window, cx| {
+ pane.close_items(window, cx, SaveIntent::Close, |id| {
+ id != item_id
+ })
+ .detach_and_log_err(cx);
+ })),
+ ))
+ .separator()
+ .item(ContextMenuItem::Entry(
+ ContextMenuEntry::new("Close Left")
+ .action(Box::new(CloseItemsToTheLeft {
+ close_pinned: false,
+ }))
+ .disabled(!has_items_to_left)
+ .handler(window.handler_for(&pane, move |pane, window, cx| {
+ pane.close_items_to_the_left_by_id(
+ item_id,
+ &CloseItemsToTheLeft {
+ close_pinned: false,
+ },
+ pane.get_non_closeable_item_ids(false),
+ window,
+ cx,
+ )
+ .detach_and_log_err(cx);
+ })),
+ ))
+ .item(ContextMenuItem::Entry(
+ ContextMenuEntry::new("Close Right")
+ .action(Box::new(CloseItemsToTheRight {
+ close_pinned: false,
+ }))
+ .disabled(!has_items_to_right)
+ .handler(window.handler_for(&pane, move |pane, window, cx| {
+ pane.close_items_to_the_right_by_id(
+ item_id,
+ &CloseItemsToTheRight {
+ close_pinned: false,
+ },
+ pane.get_non_closeable_item_ids(false),
+ window,
+ cx,
+ )
+ .detach_and_log_err(cx);
+ })),
+ ))
+ .separator()
+ .entry(
+ "Close Clean",
+ Some(Box::new(CloseCleanItems {
close_pinned: false,
- }))
- .disabled(!has_items_to_left)
- .handler(window.handler_for(&pane, move |pane, window, cx| {
- pane.close_items_to_the_left_by_id(
- item_id,
- &CloseItemsToTheLeft {
+ })),
+ window.handler_for(&pane, move |pane, window, cx| {
+ if let Some(task) = pane.close_clean_items(
+ &CloseCleanItems {
close_pinned: false,
},
- pane.get_non_closeable_item_ids(false),
window,
cx,
- )
- .detach_and_log_err(cx);
- })),
- ))
- .item(ContextMenuItem::Entry(
- ContextMenuEntry::new("Close Right")
- .action(Box::new(CloseItemsToTheRight {
+ ) {
+ task.detach_and_log_err(cx)
+ }
+ }),
+ )
+ .entry(
+ "Close All",
+ Some(Box::new(CloseAllItems {
+ save_intent: None,
close_pinned: false,
- }))
- .disabled(!has_items_to_right)
- .handler(window.handler_for(&pane, move |pane, window, cx| {
- pane.close_items_to_the_right_by_id(
- item_id,
- &CloseItemsToTheRight {
+ })),
+ window.handler_for(&pane, |pane, window, cx| {
+ if let Some(task) = pane.close_all_items(
+ &CloseAllItems {
+ save_intent: None,
close_pinned: false,
},
- pane.get_non_closeable_item_ids(false),
window,
cx,
+ ) {
+ task.detach_and_log_err(cx)
+ }
+ }),
+ );
+
+ let pin_tab_entries = |menu: ContextMenu| {
+ menu.separator().map(|this| {
+ if is_pinned {
+ this.entry(
+ "Unpin Tab",
+ Some(TogglePinTab.boxed_clone()),
+ window.handler_for(&pane, move |pane, window, cx| {
+ pane.unpin_tab_at(ix, window, cx);
+ }),
+ )
+ } else {
+ this.entry(
+ "Pin Tab",
+ Some(TogglePinTab.boxed_clone()),
+ window.handler_for(&pane, move |pane, window, cx| {
+ pane.pin_tab_at(ix, window, cx);
+ }),
)
- .detach_and_log_err(cx);
- })),
- ))
- .separator()
- .entry(
- "Close Clean",
- Some(Box::new(CloseCleanItems {
- close_pinned: false,
- })),
- window.handler_for(&pane, move |pane, window, cx| {
- if let Some(task) = pane.close_clean_items(
- &CloseCleanItems {
- close_pinned: false,
- },
- window,
- cx,
- ) {
- task.detach_and_log_err(cx)
- }
- }),
- )
- .entry(
- "Close All",
- Some(Box::new(CloseAllItems {
- save_intent: None,
- close_pinned: false,
- })),
- window.handler_for(&pane, |pane, window, cx| {
- if let Some(task) = pane.close_all_items(
- &CloseAllItems {
- save_intent: None,
- close_pinned: false,
- },
- window,
- cx,
- ) {
- task.detach_and_log_err(cx)
}
- }),
- );
-
- let pin_tab_entries = |menu: ContextMenu| {
- menu.separator().map(|this| {
- if is_pinned {
- this.entry(
- "Unpin Tab",
- Some(TogglePinTab.boxed_clone()),
- window.handler_for(&pane, move |pane, window, cx| {
- pane.unpin_tab_at(ix, window, cx);
- }),
- )
- } else {
- this.entry(
- "Pin Tab",
- Some(TogglePinTab.boxed_clone()),
- window.handler_for(&pane, move |pane, window, cx| {
- pane.pin_tab_at(ix, window, cx);
- }),
- )
- }
- })
- };
- if let Some(entry) = single_entry_to_resolve {
- let project_path = pane
- .read(cx)
- .item_for_entry(entry, cx)
- .and_then(|item| item.project_path(cx));
- let worktree = project_path.as_ref().and_then(|project_path| {
- pane.read(cx)
- .project
- .upgrade()?
- .read(cx)
- .worktree_for_id(project_path.worktree_id, cx)
- });
- let has_relative_path = worktree.as_ref().is_some_and(|worktree| {
- worktree
- .read(cx)
- .root_entry()
- .map_or(false, |entry| entry.is_dir())
- });
-
- let entry_abs_path = pane.read(cx).entry_abs_path(entry, cx);
- let parent_abs_path = entry_abs_path
- .as_deref()
- .and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
- let relative_path = project_path
- .map(|project_path| project_path.path)
- .filter(|_| has_relative_path);
-
- let visible_in_project_panel = relative_path.is_some()
- && worktree.is_some_and(|worktree| worktree.read(cx).is_visible());
-
- let entry_id = entry.to_proto();
- menu = menu
- .separator()
- .when_some(entry_abs_path, |menu, abs_path| {
- menu.entry(
- "Copy Path",
- Some(Box::new(zed_actions::workspace::CopyPath)),
- window.handler_for(&pane, move |_, _, cx| {
- cx.write_to_clipboard(ClipboardItem::new_string(
- abs_path.to_string_lossy().to_string(),
- ));
- }),
- )
- })
- .when_some(relative_path, |menu, relative_path| {
- menu.entry(
- "Copy Relative Path",
- Some(Box::new(zed_actions::workspace::CopyRelativePath)),
- window.handler_for(&pane, move |_, _, cx| {
- cx.write_to_clipboard(ClipboardItem::new_string(
- relative_path.to_string_lossy().to_string(),
- ));
- }),
- )
- })
- .map(pin_tab_entries)
- .separator()
- .when(visible_in_project_panel, |menu| {
- menu.entry(
- "Reveal In Project Panel",
- Some(Box::new(RevealInProjectPanel {
- entry_id: Some(entry_id),
- })),
- window.handler_for(&pane, move |pane, _, cx| {
- pane.project
- .update(cx, |_, cx| {
- cx.emit(project::Event::RevealInProjectPanel(
- ProjectEntryId::from_proto(entry_id),
- ))
- })
- .ok();
- }),
- )
})
- .when_some(parent_abs_path, |menu, parent_abs_path| {
- menu.entry(
- "Open in Terminal",
- Some(Box::new(OpenInTerminal)),
- window.handler_for(&pane, move |_, window, cx| {
- window.dispatch_action(
- OpenTerminal {
- working_directory: parent_abs_path.clone(),
- }
- .boxed_clone(),
- cx,
- );
- }),
- )
+ };
+ if let Some(entry) = single_entry_to_resolve {
+ let project_path = pane
+ .read(cx)
+ .item_for_entry(entry, cx)
+ .and_then(|item| item.project_path(cx));
+ let worktree = project_path.as_ref().and_then(|project_path| {
+ pane.read(cx)
+ .project
+ .upgrade()?
+ .read(cx)
+ .worktree_for_id(project_path.worktree_id, cx)
});
- } else {
- menu = menu.map(pin_tab_entries);
+ let has_relative_path = worktree.as_ref().is_some_and(|worktree| {
+ worktree
+ .read(cx)
+ .root_entry()
+ .map_or(false, |entry| entry.is_dir())
+ });
+
+ let entry_abs_path = pane.read(cx).entry_abs_path(entry, cx);
+ let parent_abs_path = entry_abs_path
+ .as_deref()
+ .and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
+ let relative_path = project_path
+ .map(|project_path| project_path.path)
+ .filter(|_| has_relative_path);
+
+ let visible_in_project_panel = relative_path.is_some()
+ && worktree.is_some_and(|worktree| worktree.read(cx).is_visible());
+
+ let entry_id = entry.to_proto();
+ menu = menu
+ .separator()
+ .when_some(entry_abs_path, |menu, abs_path| {
+ menu.entry(
+ "Copy Path",
+ Some(Box::new(zed_actions::workspace::CopyPath)),
+ window.handler_for(&pane, move |_, _, cx| {
+ cx.write_to_clipboard(ClipboardItem::new_string(
+ abs_path.to_string_lossy().to_string(),
+ ));
+ }),
+ )
+ })
+ .when_some(relative_path, |menu, relative_path| {
+ menu.entry(
+ "Copy Relative Path",
+ Some(Box::new(zed_actions::workspace::CopyRelativePath)),
+ window.handler_for(&pane, move |_, _, cx| {
+ cx.write_to_clipboard(ClipboardItem::new_string(
+ relative_path.to_string_lossy().to_string(),
+ ));
+ }),
+ )
+ })
+ .map(pin_tab_entries)
+ .separator()
+ .when(visible_in_project_panel, |menu| {
+ menu.entry(
+ "Reveal In Project Panel",
+ Some(Box::new(RevealInProjectPanel {
+ entry_id: Some(entry_id),
+ })),
+ window.handler_for(&pane, move |pane, _, cx| {
+ pane.project
+ .update(cx, |_, cx| {
+ cx.emit(project::Event::RevealInProjectPanel(
+ ProjectEntryId::from_proto(entry_id),
+ ))
+ })
+ .ok();
+ }),
+ )
+ })
+ .when_some(parent_abs_path, |menu, parent_abs_path| {
+ menu.entry(
+ "Open in Terminal",
+ Some(Box::new(OpenInTerminal)),
+ window.handler_for(&pane, move |_, window, cx| {
+ window.dispatch_action(
+ OpenTerminal {
+ working_directory: parent_abs_path.clone(),
+ }
+ .boxed_clone(),
+ cx,
+ );
+ }),
+ )
+ });
+ } else {
+ menu = menu.map(pin_tab_entries);
+ }
}
- }
- menu.context(menu_context)
+ menu.context(menu_context)
+ })
})
- })
}
fn render_tab_bar(&mut self, window: &mut Window, cx: &mut Context<Pane>) -> AnyElement {