When opening a path in an existing window, move it to the foreground
This commit is contained in:
parent
7c233ed682
commit
fbca28337a
5 changed files with 20 additions and 4 deletions
|
@ -851,6 +851,12 @@ impl MutableAppContext {
|
||||||
self.cx.windows.keys().cloned()
|
self.cx.windows.keys().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn activate_window(&self, window_id: usize) {
|
||||||
|
if let Some((_, window)) = self.presenters_and_platform_windows.get(&window_id) {
|
||||||
|
window.activate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn root_view<T: View>(&self, window_id: usize) -> Option<ViewHandle<T>> {
|
pub fn root_view<T: View>(&self, window_id: usize) -> Option<ViewHandle<T>> {
|
||||||
self.cx
|
self.cx
|
||||||
.windows
|
.windows
|
||||||
|
|
|
@ -96,6 +96,7 @@ pub trait Window: WindowContext {
|
||||||
answers: &[&str],
|
answers: &[&str],
|
||||||
done_fn: Box<dyn FnOnce(usize)>,
|
done_fn: Box<dyn FnOnce(usize)>,
|
||||||
);
|
);
|
||||||
|
fn activate(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WindowContext {
|
pub trait WindowContext {
|
||||||
|
|
|
@ -347,6 +347,12 @@ impl platform::Window for Window {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn activate(&self) {
|
||||||
|
unsafe {
|
||||||
|
let _: () = msg_send![self.0.borrow().native_window, makeKeyAndOrderFront: nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl platform::WindowContext for Window {
|
impl platform::WindowContext for Window {
|
||||||
|
|
|
@ -223,6 +223,8 @@ impl super::Window for Window {
|
||||||
fn prompt(&self, _: crate::PromptLevel, _: &str, _: &[&str], f: Box<dyn FnOnce(usize)>) {
|
fn prompt(&self, _: crate::PromptLevel, _: &str, _: &[&str], f: Box<dyn FnOnce(usize)>) {
|
||||||
self.last_prompt.replace(Some(f));
|
self.last_prompt.replace(Some(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn activate(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn platform() -> Platform {
|
pub fn platform() -> Platform {
|
||||||
|
|
|
@ -1462,10 +1462,11 @@ pub fn open_paths(
|
||||||
// Open paths in existing workspace if possible
|
// Open paths in existing workspace if possible
|
||||||
let mut existing = None;
|
let mut existing = None;
|
||||||
for window_id in cx.window_ids().collect::<Vec<_>>() {
|
for window_id in cx.window_ids().collect::<Vec<_>>() {
|
||||||
if let Some(workspace) = cx.root_view::<Workspace>(window_id) {
|
if let Some(workspace_handle) = cx.root_view::<Workspace>(window_id) {
|
||||||
if workspace.update(cx, |view, cx| {
|
if workspace_handle.update(cx, |workspace, cx| {
|
||||||
if view.contains_paths(abs_paths, cx.as_ref()) {
|
if workspace.contains_paths(abs_paths, cx.as_ref()) {
|
||||||
existing = Some(workspace.clone());
|
cx.activate_window(window_id);
|
||||||
|
existing = Some(workspace_handle.clone());
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue