mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
Store an AnyWindowHandle in WindowContext
This commit is contained in:
parent
49f1f1c6c2
commit
d896d89842
@ -305,7 +305,7 @@ impl ContactList {
|
|||||||
github_login
|
github_login
|
||||||
);
|
);
|
||||||
let mut answer = cx.prompt(PromptLevel::Warning, &prompt_message, &["Remove", "Cancel"]);
|
let mut answer = cx.prompt(PromptLevel::Warning, &prompt_message, &["Remove", "Cancel"]);
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
if answer.next().await == Some(0) {
|
if answer.next().await == Some(0) {
|
||||||
if let Err(e) = user_store
|
if let Err(e) = user_store
|
||||||
@ -313,7 +313,7 @@ impl ContactList {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
cx.prompt(
|
cx.prompt(
|
||||||
window_id,
|
window,
|
||||||
PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
&format!("Failed to remove contact: {}", e),
|
&format!("Failed to remove contact: {}", e),
|
||||||
&["Ok"],
|
&["Ok"],
|
||||||
|
@ -5,7 +5,7 @@ use gpui::{
|
|||||||
elements::*,
|
elements::*,
|
||||||
geometry::{rect::RectF, vector::vec2f},
|
geometry::{rect::RectF, vector::vec2f},
|
||||||
platform::{CursorStyle, MouseButton, WindowBounds, WindowKind, WindowOptions},
|
platform::{CursorStyle, MouseButton, WindowBounds, WindowKind, WindowOptions},
|
||||||
AppContext, BorrowWindowContext, Entity, View, ViewContext,
|
AppContext, Entity, View, ViewContext,
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use workspace::AppState;
|
use workspace::AppState;
|
||||||
@ -52,20 +52,20 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||||||
notification_windows
|
notification_windows
|
||||||
.entry(*project_id)
|
.entry(*project_id)
|
||||||
.or_insert(Vec::new())
|
.or_insert(Vec::new())
|
||||||
.push(window.id());
|
.push(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
room::Event::RemoteProjectUnshared { project_id } => {
|
room::Event::RemoteProjectUnshared { project_id } => {
|
||||||
if let Some(window_ids) = notification_windows.remove(&project_id) {
|
if let Some(windows) = notification_windows.remove(&project_id) {
|
||||||
for window_id in window_ids {
|
for window in windows {
|
||||||
cx.update_window(window_id, |cx| cx.remove_window());
|
window.remove(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
room::Event::Left => {
|
room::Event::Left => {
|
||||||
for (_, window_ids) in notification_windows.drain() {
|
for (_, windows) in notification_windows.drain() {
|
||||||
for window_id in window_ids {
|
for window in windows {
|
||||||
cx.update_window(window_id, |cx| cx.remove_window());
|
window.remove(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,11 +80,11 @@ impl PickerDelegate for CommandPaletteDelegate {
|
|||||||
query: String,
|
query: String,
|
||||||
cx: &mut ViewContext<Picker<Self>>,
|
cx: &mut ViewContext<Picker<Self>>,
|
||||||
) -> gpui::Task<()> {
|
) -> gpui::Task<()> {
|
||||||
let window_id = cx.window_id();
|
|
||||||
let view_id = self.focused_view_id;
|
let view_id = self.focused_view_id;
|
||||||
|
let window = cx.window();
|
||||||
cx.spawn(move |picker, mut cx| async move {
|
cx.spawn(move |picker, mut cx| async move {
|
||||||
let actions = cx
|
let actions = cx
|
||||||
.available_actions(window_id, view_id)
|
.available_actions(window, view_id)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(name, action, bindings)| {
|
.filter_map(|(name, action, bindings)| {
|
||||||
let filtered = cx.read(|cx| {
|
let filtered = cx.read(|cx| {
|
||||||
@ -162,13 +162,13 @@ impl PickerDelegate for CommandPaletteDelegate {
|
|||||||
|
|
||||||
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
|
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
|
||||||
if !self.matches.is_empty() {
|
if !self.matches.is_empty() {
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
let focused_view_id = self.focused_view_id;
|
let focused_view_id = self.focused_view_id;
|
||||||
let action_ix = self.matches[self.selected_ix].candidate_id;
|
let action_ix = self.matches[self.selected_ix].candidate_id;
|
||||||
let action = self.actions.remove(action_ix).action;
|
let action = self.actions.remove(action_ix).action;
|
||||||
cx.app_context()
|
cx.app_context()
|
||||||
.spawn(move |mut cx| async move {
|
.spawn(move |mut cx| async move {
|
||||||
cx.dispatch_action(window_id, focused_view_id, action.as_ref())
|
cx.dispatch_action(window, focused_view_id, action.as_ref())
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
@ -218,12 +218,12 @@ impl ContextMenu {
|
|||||||
if let Some(ContextMenuItem::Item { action, .. }) = self.items.get(ix) {
|
if let Some(ContextMenuItem::Item { action, .. }) = self.items.get(ix) {
|
||||||
match action {
|
match action {
|
||||||
ContextMenuItemAction::Action(action) => {
|
ContextMenuItemAction::Action(action) => {
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
let view_id = self.parent_view_id;
|
let view_id = self.parent_view_id;
|
||||||
let action = action.boxed_clone();
|
let action = action.boxed_clone();
|
||||||
cx.app_context()
|
cx.app_context()
|
||||||
.spawn(|mut cx| async move {
|
.spawn(|mut cx| async move {
|
||||||
cx.dispatch_action(window_id, view_id, action.as_ref())
|
cx.dispatch_action(window, view_id, action.as_ref())
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
@ -480,17 +480,13 @@ impl ContextMenu {
|
|||||||
.on_down(MouseButton::Left, |_, _, _| {}) // Capture these events
|
.on_down(MouseButton::Left, |_, _, _| {}) // Capture these events
|
||||||
.on_click(MouseButton::Left, move |_, menu, cx| {
|
.on_click(MouseButton::Left, move |_, menu, cx| {
|
||||||
menu.cancel(&Default::default(), cx);
|
menu.cancel(&Default::default(), cx);
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
match &action {
|
match &action {
|
||||||
ContextMenuItemAction::Action(action) => {
|
ContextMenuItemAction::Action(action) => {
|
||||||
let action = action.boxed_clone();
|
let action = action.boxed_clone();
|
||||||
cx.app_context()
|
cx.app_context()
|
||||||
.spawn(|mut cx| async move {
|
.spawn(|mut cx| async move {
|
||||||
cx.dispatch_action(
|
cx.dispatch_action(window, view_id, action.as_ref())
|
||||||
window_id,
|
|
||||||
view_id,
|
|
||||||
action.as_ref(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
@ -619,7 +619,7 @@ mod tests {
|
|||||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
cx.dispatch_action(window.id(), Toggle);
|
cx.dispatch_action(window.into(), Toggle);
|
||||||
|
|
||||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||||
finder
|
finder
|
||||||
@ -632,8 +632,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
cx.dispatch_action(window.id(), SelectNext);
|
cx.dispatch_action(window.into(), SelectNext);
|
||||||
cx.dispatch_action(window.id(), Confirm);
|
cx.dispatch_action(window.into(), Confirm);
|
||||||
active_pane
|
active_pane
|
||||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||||
.await;
|
.await;
|
||||||
@ -674,7 +674,7 @@ mod tests {
|
|||||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
cx.dispatch_action(window.id(), Toggle);
|
cx.dispatch_action(window.into(), Toggle);
|
||||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||||
|
|
||||||
let file_query = &first_file_name[..3];
|
let file_query = &first_file_name[..3];
|
||||||
@ -706,8 +706,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
cx.dispatch_action(window.id(), SelectNext);
|
cx.dispatch_action(window.into(), SelectNext);
|
||||||
cx.dispatch_action(window.id(), Confirm);
|
cx.dispatch_action(window.into(), Confirm);
|
||||||
active_pane
|
active_pane
|
||||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||||
.await;
|
.await;
|
||||||
@ -758,7 +758,7 @@ mod tests {
|
|||||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
cx.dispatch_action(window.id(), Toggle);
|
cx.dispatch_action(window.into(), Toggle);
|
||||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||||
|
|
||||||
let file_query = &first_file_name[..3];
|
let file_query = &first_file_name[..3];
|
||||||
@ -790,8 +790,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
cx.dispatch_action(window.id(), SelectNext);
|
cx.dispatch_action(window.into(), SelectNext);
|
||||||
cx.dispatch_action(window.id(), Confirm);
|
cx.dispatch_action(window.into(), Confirm);
|
||||||
active_pane
|
active_pane
|
||||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||||
.await;
|
.await;
|
||||||
@ -1168,7 +1168,6 @@ mod tests {
|
|||||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let worktree_id = cx.read(|cx| {
|
let worktree_id = cx.read(|cx| {
|
||||||
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
||||||
assert_eq!(worktrees.len(), 1);
|
assert_eq!(worktrees.len(), 1);
|
||||||
@ -1186,7 +1185,7 @@ mod tests {
|
|||||||
"fir",
|
"fir",
|
||||||
1,
|
1,
|
||||||
"first.rs",
|
"first.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1201,7 +1200,7 @@ mod tests {
|
|||||||
"sec",
|
"sec",
|
||||||
1,
|
1,
|
||||||
"second.rs",
|
"second.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1223,7 +1222,7 @@ mod tests {
|
|||||||
"thi",
|
"thi",
|
||||||
1,
|
1,
|
||||||
"third.rs",
|
"third.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1255,7 +1254,7 @@ mod tests {
|
|||||||
"sec",
|
"sec",
|
||||||
1,
|
1,
|
||||||
"second.rs",
|
"second.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1294,7 +1293,7 @@ mod tests {
|
|||||||
"thi",
|
"thi",
|
||||||
1,
|
1,
|
||||||
"third.rs",
|
"third.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1376,7 +1375,6 @@ mod tests {
|
|||||||
|
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let worktree_id = cx.read(|cx| {
|
let worktree_id = cx.read(|cx| {
|
||||||
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
||||||
assert_eq!(worktrees.len(), 1,);
|
assert_eq!(worktrees.len(), 1,);
|
||||||
@ -1411,7 +1409,7 @@ mod tests {
|
|||||||
"sec",
|
"sec",
|
||||||
1,
|
1,
|
||||||
"second.rs",
|
"second.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1433,7 +1431,7 @@ mod tests {
|
|||||||
"fir",
|
"fir",
|
||||||
1,
|
1,
|
||||||
"first.rs",
|
"first.rs",
|
||||||
window_id,
|
window.into(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&deterministic,
|
&deterministic,
|
||||||
cx,
|
cx,
|
||||||
@ -1465,12 +1463,12 @@ mod tests {
|
|||||||
input: &str,
|
input: &str,
|
||||||
expected_matches: usize,
|
expected_matches: usize,
|
||||||
expected_editor_title: &str,
|
expected_editor_title: &str,
|
||||||
window_id: usize,
|
window: gpui::AnyWindowHandle,
|
||||||
workspace: &ViewHandle<Workspace>,
|
workspace: &ViewHandle<Workspace>,
|
||||||
deterministic: &gpui::executor::Deterministic,
|
deterministic: &gpui::executor::Deterministic,
|
||||||
cx: &mut gpui::TestAppContext,
|
cx: &mut gpui::TestAppContext,
|
||||||
) -> Vec<FoundPath> {
|
) -> Vec<FoundPath> {
|
||||||
cx.dispatch_action(window_id, Toggle);
|
cx.dispatch_action(window, Toggle);
|
||||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||||
finder
|
finder
|
||||||
.update(cx, |finder, cx| {
|
.update(cx, |finder, cx| {
|
||||||
@ -1487,8 +1485,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
cx.dispatch_action(window_id, SelectNext);
|
cx.dispatch_action(window, SelectNext);
|
||||||
cx.dispatch_action(window_id, Confirm);
|
cx.dispatch_action(window, Confirm);
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
active_pane
|
active_pane
|
||||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||||
|
@ -135,16 +135,14 @@ impl Entity for GoToLine {
|
|||||||
|
|
||||||
fn release(&mut self, cx: &mut AppContext) {
|
fn release(&mut self, cx: &mut AppContext) {
|
||||||
let scroll_position = self.prev_scroll_position.take();
|
let scroll_position = self.prev_scroll_position.take();
|
||||||
if let Some(window) = self.active_editor.window(cx) {
|
self.active_editor.window().update(cx, |cx| {
|
||||||
window.update(cx, |cx| {
|
self.active_editor.update(cx, |editor, cx| {
|
||||||
self.active_editor.update(cx, |editor, cx| {
|
editor.highlight_rows(None);
|
||||||
editor.highlight_rows(None);
|
if let Some(scroll_position) = scroll_position {
|
||||||
if let Some(scroll_position) = scroll_position {
|
editor.set_scroll_position(scroll_position, cx);
|
||||||
editor.set_scroll_position(scroll_position, cx);
|
}
|
||||||
}
|
})
|
||||||
})
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -72,8 +72,8 @@ impl TestAppContext {
|
|||||||
cx
|
cx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_action<A: Action>(&mut self, window_id: usize, action: A) {
|
pub fn dispatch_action<A: Action>(&mut self, window: AnyWindowHandle, action: A) {
|
||||||
self.update_window(window_id, |window| {
|
self.update_window(window, |window| {
|
||||||
window.dispatch_action(window.focused_view_id(), &action);
|
window.dispatch_action(window.focused_view_id(), &action);
|
||||||
})
|
})
|
||||||
.expect("window not found");
|
.expect("window not found");
|
||||||
@ -81,10 +81,10 @@ impl TestAppContext {
|
|||||||
|
|
||||||
pub fn available_actions(
|
pub fn available_actions(
|
||||||
&self,
|
&self,
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
view_id: usize,
|
view_id: usize,
|
||||||
) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> {
|
) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> {
|
||||||
self.read_window(window_id, |cx| cx.available_actions(view_id))
|
self.read_window(window, |cx| cx.available_actions(view_id))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,18 +127,18 @@ impl TestAppContext {
|
|||||||
|
|
||||||
pub fn read_window<T, F: FnOnce(&WindowContext) -> T>(
|
pub fn read_window<T, F: FnOnce(&WindowContext) -> T>(
|
||||||
&self,
|
&self,
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
callback: F,
|
callback: F,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
self.cx.borrow().read_window(window_id, callback)
|
self.cx.borrow().read_window(window, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
pub fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
callback: F,
|
callback: F,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
self.cx.borrow_mut().update_window(window_id, callback)
|
self.cx.borrow_mut().update_window(window, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_model<T, F>(&mut self, build_model: F) -> ModelHandle<T>
|
pub fn add_model<T, F>(&mut self, build_model: F) -> ModelHandle<T>
|
||||||
@ -317,36 +317,36 @@ impl BorrowAppContext for TestAppContext {
|
|||||||
impl BorrowWindowContext for TestAppContext {
|
impl BorrowWindowContext for TestAppContext {
|
||||||
type Result<T> = T;
|
type Result<T> = T;
|
||||||
|
|
||||||
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, window: AnyWindowHandle, f: F) -> T {
|
||||||
self.cx
|
self.cx
|
||||||
.borrow()
|
.borrow()
|
||||||
.read_window(window_id, f)
|
.read_window(window, f)
|
||||||
.expect("window was closed")
|
.expect("window was closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_window_optional<T, F>(&self, window_id: usize, f: F) -> Option<T>
|
fn read_window_optional<T, F>(&self, window: AnyWindowHandle, f: F) -> Option<T>
|
||||||
where
|
where
|
||||||
F: FnOnce(&WindowContext) -> Option<T>,
|
F: FnOnce(&WindowContext) -> Option<T>,
|
||||||
{
|
{
|
||||||
BorrowWindowContext::read_window(self, window_id, f)
|
BorrowWindowContext::read_window(self, window, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
f: F,
|
f: F,
|
||||||
) -> T {
|
) -> T {
|
||||||
self.cx
|
self.cx
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.update_window(window_id, f)
|
.update_window(window, f)
|
||||||
.expect("window was closed")
|
.expect("window was closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_window_optional<T, F>(&mut self, window_id: usize, f: F) -> Option<T>
|
fn update_window_optional<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Option<T>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut WindowContext) -> Option<T>,
|
F: FnOnce(&mut WindowContext) -> Option<T>,
|
||||||
{
|
{
|
||||||
BorrowWindowContext::update_window(self, window_id, f)
|
BorrowWindowContext::update_window(self, window, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ use crate::{
|
|||||||
},
|
},
|
||||||
text_layout::TextLayoutCache,
|
text_layout::TextLayoutCache,
|
||||||
util::post_inc,
|
util::post_inc,
|
||||||
Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
|
Action, AnyView, AnyViewHandle, AnyWindowHandle, AppContext, BorrowAppContext,
|
||||||
Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription,
|
BorrowWindowContext, Effect, Element, Entity, Handle, LayoutContext, MouseRegion,
|
||||||
View, ViewContext, ViewHandle, WindowHandle, WindowInvalidation,
|
MouseRegionId, SceneBuilder, Subscription, View, ViewContext, ViewHandle, WindowInvalidation,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
@ -60,7 +60,7 @@ pub struct Window {
|
|||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new<V, F>(
|
pub fn new<V, F>(
|
||||||
window_id: usize,
|
handle: AnyWindowHandle,
|
||||||
platform_window: Box<dyn platform::Window>,
|
platform_window: Box<dyn platform::Window>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
build_view: F,
|
build_view: F,
|
||||||
@ -92,7 +92,7 @@ impl Window {
|
|||||||
appearance,
|
appearance,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut window_context = WindowContext::mutable(cx, &mut window, window_id);
|
let mut window_context = WindowContext::mutable(cx, &mut window, handle);
|
||||||
let root_view = window_context.add_view(|cx| build_view(cx));
|
let root_view = window_context.add_view(|cx| build_view(cx));
|
||||||
if let Some(invalidation) = window_context.window.invalidation.take() {
|
if let Some(invalidation) = window_context.window.invalidation.take() {
|
||||||
window_context.invalidate(invalidation, appearance);
|
window_context.invalidate(invalidation, appearance);
|
||||||
@ -113,7 +113,7 @@ impl Window {
|
|||||||
pub struct WindowContext<'a> {
|
pub struct WindowContext<'a> {
|
||||||
pub(crate) app_context: Reference<'a, AppContext>,
|
pub(crate) app_context: Reference<'a, AppContext>,
|
||||||
pub(crate) window: Reference<'a, Window>,
|
pub(crate) window: Reference<'a, Window>,
|
||||||
pub(crate) window_id: usize,
|
pub(crate) window_handle: AnyWindowHandle,
|
||||||
pub(crate) removed: bool,
|
pub(crate) removed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,15 +144,15 @@ impl BorrowAppContext for WindowContext<'_> {
|
|||||||
impl BorrowWindowContext for WindowContext<'_> {
|
impl BorrowWindowContext for WindowContext<'_> {
|
||||||
type Result<T> = T;
|
type Result<T> = T;
|
||||||
|
|
||||||
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
fn read_window<T, F: FnOnce(&WindowContext) -> T>(&self, handle: AnyWindowHandle, f: F) -> T {
|
||||||
if self.window_id == window_id {
|
if self.window_handle == handle {
|
||||||
f(self)
|
f(self)
|
||||||
} else {
|
} else {
|
||||||
panic!("read_with called with id of window that does not belong to this context")
|
panic!("read_with called with id of window that does not belong to this context")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_window_optional<T, F>(&self, window_id: usize, f: F) -> Option<T>
|
fn read_window_optional<T, F>(&self, window_id: AnyWindowHandle, f: F) -> Option<T>
|
||||||
where
|
where
|
||||||
F: FnOnce(&WindowContext) -> Option<T>,
|
F: FnOnce(&WindowContext) -> Option<T>,
|
||||||
{
|
{
|
||||||
@ -161,21 +161,21 @@ impl BorrowWindowContext for WindowContext<'_> {
|
|||||||
|
|
||||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
handle: AnyWindowHandle,
|
||||||
f: F,
|
f: F,
|
||||||
) -> T {
|
) -> T {
|
||||||
if self.window_id == window_id {
|
if self.window_handle == handle {
|
||||||
f(self)
|
f(self)
|
||||||
} else {
|
} else {
|
||||||
panic!("update called with id of window that does not belong to this context")
|
panic!("update called with id of window that does not belong to this context")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_window_optional<T, F>(&mut self, window_id: usize, f: F) -> Option<T>
|
fn update_window_optional<T, F>(&mut self, handle: AnyWindowHandle, f: F) -> Option<T>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut WindowContext) -> Option<T>,
|
F: FnOnce(&mut WindowContext) -> Option<T>,
|
||||||
{
|
{
|
||||||
BorrowWindowContext::update_window(self, window_id, f)
|
BorrowWindowContext::update_window(self, handle, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,21 +183,25 @@ impl<'a> WindowContext<'a> {
|
|||||||
pub fn mutable(
|
pub fn mutable(
|
||||||
app_context: &'a mut AppContext,
|
app_context: &'a mut AppContext,
|
||||||
window: &'a mut Window,
|
window: &'a mut Window,
|
||||||
window_id: usize,
|
handle: AnyWindowHandle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
app_context: Reference::Mutable(app_context),
|
app_context: Reference::Mutable(app_context),
|
||||||
window: Reference::Mutable(window),
|
window: Reference::Mutable(window),
|
||||||
window_id,
|
window_handle: handle,
|
||||||
removed: false,
|
removed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn immutable(app_context: &'a AppContext, window: &'a Window, window_id: usize) -> Self {
|
pub fn immutable(
|
||||||
|
app_context: &'a AppContext,
|
||||||
|
window: &'a Window,
|
||||||
|
handle: AnyWindowHandle,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
app_context: Reference::Immutable(app_context),
|
app_context: Reference::Immutable(app_context),
|
||||||
window: Reference::Immutable(window),
|
window: Reference::Immutable(window),
|
||||||
window_id,
|
window_handle: handle,
|
||||||
removed: false,
|
removed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,17 +211,11 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_id(&self) -> usize {
|
pub fn window_id(&self) -> usize {
|
||||||
self.window_id
|
self.window_handle.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window<V: View>(&self) -> Option<WindowHandle<V>> {
|
pub fn window(&self) -> AnyWindowHandle {
|
||||||
self.window.root_view.as_ref().and_then(|root_view| {
|
self.window_handle
|
||||||
if root_view.is::<V>() {
|
|
||||||
Some(WindowHandle::new(self.window_id))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app_context(&mut self) -> &mut AppContext {
|
pub fn app_context(&mut self) -> &mut AppContext {
|
||||||
@ -240,10 +238,10 @@ impl<'a> WindowContext<'a> {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut dyn AnyView, &mut Self) -> T,
|
F: FnOnce(&mut dyn AnyView, &mut Self) -> T,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
let mut view = self.views.remove(&(window_id, view_id))?;
|
let mut view = self.views.remove(&(handle.id(), view_id))?;
|
||||||
let result = f(view.as_mut(), self);
|
let result = f(view.as_mut(), self);
|
||||||
self.views.insert((window_id, view_id), view);
|
self.views.insert((handle.id(), view_id), view);
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,9 +266,9 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn defer(&mut self, callback: impl 'static + FnOnce(&mut WindowContext)) {
|
pub fn defer(&mut self, callback: impl 'static + FnOnce(&mut WindowContext)) {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
self.app_context.defer(move |cx| {
|
self.app_context.defer(move |cx| {
|
||||||
cx.update_window(window_id, |cx| callback(cx));
|
cx.update_window(handle, |cx| callback(cx));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,10 +308,10 @@ impl<'a> WindowContext<'a> {
|
|||||||
H: Handle<E>,
|
H: Handle<E>,
|
||||||
F: 'static + FnMut(H, &E::Event, &mut WindowContext) -> bool,
|
F: 'static + FnMut(H, &E::Event, &mut WindowContext) -> bool,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let window_handle = self.window_handle;
|
||||||
self.app_context
|
self.app_context
|
||||||
.subscribe_internal(handle, move |emitter, event, cx| {
|
.subscribe_internal(handle, move |emitter, event, cx| {
|
||||||
cx.update_window(window_id, |cx| callback(emitter, event, cx))
|
cx.update_window(window_handle, |cx| callback(emitter, event, cx))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -322,17 +320,17 @@ impl<'a> WindowContext<'a> {
|
|||||||
where
|
where
|
||||||
F: 'static + FnMut(bool, &mut WindowContext) -> bool,
|
F: 'static + FnMut(bool, &mut WindowContext) -> bool,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||||
self.pending_effects
|
self.pending_effects
|
||||||
.push_back(Effect::WindowActivationObservation {
|
.push_back(Effect::WindowActivationObservation {
|
||||||
window_id,
|
window: handle,
|
||||||
subscription_id,
|
subscription_id,
|
||||||
callback: Box::new(callback),
|
callback: Box::new(callback),
|
||||||
});
|
});
|
||||||
Subscription::WindowActivationObservation(
|
Subscription::WindowActivationObservation(
|
||||||
self.window_activation_observations
|
self.window_activation_observations
|
||||||
.subscribe(window_id, subscription_id),
|
.subscribe(handle.id(), subscription_id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,17 +338,17 @@ impl<'a> WindowContext<'a> {
|
|||||||
where
|
where
|
||||||
F: 'static + FnMut(bool, &mut WindowContext) -> bool,
|
F: 'static + FnMut(bool, &mut WindowContext) -> bool,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let window = self.window_handle;
|
||||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||||
self.pending_effects
|
self.pending_effects
|
||||||
.push_back(Effect::WindowFullscreenObservation {
|
.push_back(Effect::WindowFullscreenObservation {
|
||||||
window_id,
|
window,
|
||||||
subscription_id,
|
subscription_id,
|
||||||
callback: Box::new(callback),
|
callback: Box::new(callback),
|
||||||
});
|
});
|
||||||
Subscription::WindowActivationObservation(
|
Subscription::WindowActivationObservation(
|
||||||
self.window_activation_observations
|
self.window_activation_observations
|
||||||
.subscribe(window_id, subscription_id),
|
.subscribe(window.id(), subscription_id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,17 +356,17 @@ impl<'a> WindowContext<'a> {
|
|||||||
where
|
where
|
||||||
F: 'static + FnMut(WindowBounds, Uuid, &mut WindowContext) -> bool,
|
F: 'static + FnMut(WindowBounds, Uuid, &mut WindowContext) -> bool,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let window = self.window_handle;
|
||||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||||
self.pending_effects
|
self.pending_effects
|
||||||
.push_back(Effect::WindowBoundsObservation {
|
.push_back(Effect::WindowBoundsObservation {
|
||||||
window_id,
|
window,
|
||||||
subscription_id,
|
subscription_id,
|
||||||
callback: Box::new(callback),
|
callback: Box::new(callback),
|
||||||
});
|
});
|
||||||
Subscription::WindowBoundsObservation(
|
Subscription::WindowBoundsObservation(
|
||||||
self.window_bounds_observations
|
self.window_bounds_observations
|
||||||
.subscribe(window_id, subscription_id),
|
.subscribe(window.id(), subscription_id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,13 +375,13 @@ impl<'a> WindowContext<'a> {
|
|||||||
F: 'static
|
F: 'static
|
||||||
+ FnMut(&Keystroke, &MatchResult, Option<&Box<dyn Action>>, &mut WindowContext) -> bool,
|
+ FnMut(&Keystroke, &MatchResult, Option<&Box<dyn Action>>, &mut WindowContext) -> bool,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let window = self.window_handle;
|
||||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||||
self.keystroke_observations
|
self.keystroke_observations
|
||||||
.add_callback(window_id, subscription_id, Box::new(callback));
|
.add_callback(window.id(), subscription_id, Box::new(callback));
|
||||||
Subscription::KeystrokeObservation(
|
Subscription::KeystrokeObservation(
|
||||||
self.keystroke_observations
|
self.keystroke_observations
|
||||||
.subscribe(window_id, subscription_id),
|
.subscribe(window.id(), subscription_id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,11 +389,11 @@ impl<'a> WindowContext<'a> {
|
|||||||
&self,
|
&self,
|
||||||
view_id: usize,
|
view_id: usize,
|
||||||
) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> {
|
) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
let mut contexts = Vec::new();
|
let mut contexts = Vec::new();
|
||||||
let mut handler_depths_by_action_id = HashMap::<TypeId, usize>::default();
|
let mut handler_depths_by_action_id = HashMap::<TypeId, usize>::default();
|
||||||
for (depth, view_id) in self.ancestors(view_id).enumerate() {
|
for (depth, view_id) in self.ancestors(view_id).enumerate() {
|
||||||
if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) {
|
if let Some(view_metadata) = self.views_metadata.get(&(handle.id(), view_id)) {
|
||||||
contexts.push(view_metadata.keymap_context.clone());
|
contexts.push(view_metadata.keymap_context.clone());
|
||||||
if let Some(actions) = self.actions.get(&view_metadata.type_id) {
|
if let Some(actions) = self.actions.get(&view_metadata.type_id) {
|
||||||
handler_depths_by_action_id
|
handler_depths_by_action_id
|
||||||
@ -440,13 +438,13 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_keystroke(&mut self, keystroke: &Keystroke) -> bool {
|
pub(crate) fn dispatch_keystroke(&mut self, keystroke: &Keystroke) -> bool {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
if let Some(focused_view_id) = self.focused_view_id() {
|
if let Some(focused_view_id) = self.focused_view_id() {
|
||||||
let dispatch_path = self
|
let dispatch_path = self
|
||||||
.ancestors(focused_view_id)
|
.ancestors(focused_view_id)
|
||||||
.filter_map(|view_id| {
|
.filter_map(|view_id| {
|
||||||
self.views_metadata
|
self.views_metadata
|
||||||
.get(&(window_id, view_id))
|
.get(&(handle.id(), view_id))
|
||||||
.map(|view| (view_id, view.keymap_context.clone()))
|
.map(|view| (view_id, view.keymap_context.clone()))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -471,15 +469,10 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.keystroke(
|
self.keystroke(handle, keystroke.clone(), handled_by, match_result.clone());
|
||||||
window_id,
|
|
||||||
keystroke.clone(),
|
|
||||||
handled_by,
|
|
||||||
match_result.clone(),
|
|
||||||
);
|
|
||||||
keystroke_handled
|
keystroke_handled
|
||||||
} else {
|
} else {
|
||||||
self.keystroke(window_id, keystroke.clone(), None, MatchResult::None);
|
self.keystroke(handle, keystroke.clone(), None, MatchResult::None);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +480,7 @@ impl<'a> WindowContext<'a> {
|
|||||||
pub(crate) fn dispatch_event(&mut self, event: Event, event_reused: bool) -> bool {
|
pub(crate) fn dispatch_event(&mut self, event: Event, event_reused: bool) -> bool {
|
||||||
let mut mouse_events = SmallVec::<[_; 2]>::new();
|
let mut mouse_events = SmallVec::<[_; 2]>::new();
|
||||||
let mut notified_views: HashSet<usize> = Default::default();
|
let mut notified_views: HashSet<usize> = Default::default();
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
|
|
||||||
// 1. Handle platform event. Keyboard events get dispatched immediately, while mouse events
|
// 1. Handle platform event. Keyboard events get dispatched immediately, while mouse events
|
||||||
// get mapped into the mouse-specific MouseEvent type.
|
// get mapped into the mouse-specific MouseEvent type.
|
||||||
@ -851,19 +844,19 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for view_id in notified_views {
|
for view_id in notified_views {
|
||||||
self.notify_view(window_id, view_id);
|
self.notify_view(handle, view_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
any_event_handled
|
any_event_handled
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_key_down(&mut self, event: &KeyDownEvent) -> bool {
|
pub(crate) fn dispatch_key_down(&mut self, event: &KeyDownEvent) -> bool {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
if let Some(focused_view_id) = self.window.focused_view_id {
|
if let Some(focused_view_id) = self.window.focused_view_id {
|
||||||
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
||||||
if let Some(mut view) = self.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {
|
||||||
let handled = view.key_down(event, self, view_id);
|
let handled = view.key_down(event, self, view_id);
|
||||||
self.views.insert((window_id, view_id), view);
|
self.views.insert((handle.id(), view_id), view);
|
||||||
if handled {
|
if handled {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -877,12 +870,12 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_key_up(&mut self, event: &KeyUpEvent) -> bool {
|
pub(crate) fn dispatch_key_up(&mut self, event: &KeyUpEvent) -> bool {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
if let Some(focused_view_id) = self.window.focused_view_id {
|
if let Some(focused_view_id) = self.window.focused_view_id {
|
||||||
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
||||||
if let Some(mut view) = self.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {
|
||||||
let handled = view.key_up(event, self, view_id);
|
let handled = view.key_up(event, self, view_id);
|
||||||
self.views.insert((window_id, view_id), view);
|
self.views.insert((handle.id(), view_id), view);
|
||||||
if handled {
|
if handled {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -896,12 +889,12 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_modifiers_changed(&mut self, event: &ModifiersChangedEvent) -> bool {
|
pub(crate) fn dispatch_modifiers_changed(&mut self, event: &ModifiersChangedEvent) -> bool {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
if let Some(focused_view_id) = self.window.focused_view_id {
|
if let Some(focused_view_id) = self.window.focused_view_id {
|
||||||
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {
|
||||||
if let Some(mut view) = self.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {
|
||||||
let handled = view.modifiers_changed(event, self, view_id);
|
let handled = view.modifiers_changed(event, self, view_id);
|
||||||
self.views.insert((window_id, view_id), view);
|
self.views.insert((handle.id(), view_id), view);
|
||||||
if handled {
|
if handled {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -936,14 +929,14 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_view(&mut self, params: RenderParams) -> Result<Box<dyn AnyRootElement>> {
|
pub fn render_view(&mut self, params: RenderParams) -> Result<Box<dyn AnyRootElement>> {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
let view_id = params.view_id;
|
let view_id = params.view_id;
|
||||||
let mut view = self
|
let mut view = self
|
||||||
.views
|
.views
|
||||||
.remove(&(window_id, view_id))
|
.remove(&(handle.id(), view_id))
|
||||||
.ok_or_else(|| anyhow!("view not found"))?;
|
.ok_or_else(|| anyhow!("view not found"))?;
|
||||||
let element = view.render(self, view_id);
|
let element = view.render(self, view_id);
|
||||||
self.views.insert((window_id, view_id), view);
|
self.views.insert((handle.id(), view_id), view);
|
||||||
Ok(element)
|
Ok(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,9 +964,9 @@ impl<'a> WindowContext<'a> {
|
|||||||
} else if old_parent_id == new_parent_id {
|
} else if old_parent_id == new_parent_id {
|
||||||
current_view_id = *old_parent_id.unwrap();
|
current_view_id = *old_parent_id.unwrap();
|
||||||
} else {
|
} else {
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
for view_id_to_notify in view_ids_to_notify {
|
for view_id_to_notify in view_ids_to_notify {
|
||||||
self.notify_view(window_id, view_id_to_notify);
|
self.notify_view(handle, view_id_to_notify);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1141,7 +1134,7 @@ impl<'a> WindowContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus(&mut self, view_id: Option<usize>) {
|
pub fn focus(&mut self, view_id: Option<usize>) {
|
||||||
self.app_context.focus(self.window_id, view_id);
|
self.app_context.focus(self.window_handle, view_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_bounds(&self) -> WindowBounds {
|
pub fn window_bounds(&self) -> WindowBounds {
|
||||||
@ -1194,26 +1187,26 @@ impl<'a> WindowContext<'a> {
|
|||||||
T: View,
|
T: View,
|
||||||
F: FnOnce(&mut ViewContext<T>) -> Option<T>,
|
F: FnOnce(&mut ViewContext<T>) -> Option<T>,
|
||||||
{
|
{
|
||||||
let window_id = self.window_id;
|
let handle = self.window_handle;
|
||||||
let view_id = post_inc(&mut self.next_id);
|
let view_id = post_inc(&mut self.next_id);
|
||||||
let mut cx = ViewContext::mutable(self, view_id);
|
let mut cx = ViewContext::mutable(self, view_id);
|
||||||
let handle = if let Some(view) = build_view(&mut cx) {
|
let handle = if let Some(view) = build_view(&mut cx) {
|
||||||
let mut keymap_context = KeymapContext::default();
|
let mut keymap_context = KeymapContext::default();
|
||||||
view.update_keymap_context(&mut keymap_context, cx.app_context());
|
view.update_keymap_context(&mut keymap_context, cx.app_context());
|
||||||
self.views_metadata.insert(
|
self.views_metadata.insert(
|
||||||
(window_id, view_id),
|
(handle.id(), view_id),
|
||||||
ViewMetadata {
|
ViewMetadata {
|
||||||
type_id: TypeId::of::<T>(),
|
type_id: TypeId::of::<T>(),
|
||||||
keymap_context,
|
keymap_context,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.views.insert((window_id, view_id), Box::new(view));
|
self.views.insert((handle.id(), view_id), Box::new(view));
|
||||||
self.window
|
self.window
|
||||||
.invalidation
|
.invalidation
|
||||||
.get_or_insert_with(Default::default)
|
.get_or_insert_with(Default::default)
|
||||||
.updated
|
.updated
|
||||||
.insert(view_id);
|
.insert(view_id);
|
||||||
Some(ViewHandle::new(window_id, view_id, &self.ref_counts))
|
Some(ViewHandle::new(handle, view_id, &self.ref_counts))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -1390,7 +1383,7 @@ pub struct ChildView {
|
|||||||
|
|
||||||
impl ChildView {
|
impl ChildView {
|
||||||
pub fn new(view: &AnyViewHandle, cx: &AppContext) -> Self {
|
pub fn new(view: &AnyViewHandle, cx: &AppContext) -> Self {
|
||||||
let view_name = cx.view_ui_name(view.window_id(), view.id()).unwrap();
|
let view_name = cx.view_ui_name(view.window, view.id()).unwrap();
|
||||||
Self {
|
Self {
|
||||||
view_id: view.id(),
|
view_id: view.id(),
|
||||||
view_name,
|
view_name,
|
||||||
|
@ -1726,7 +1726,7 @@ impl ClipboardEntry {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use gpui::{AnyWindowHandle, TestAppContext, ViewHandle};
|
use gpui::{AnyWindowHandle, TestAppContext, ViewHandle, WindowHandle};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use project::FakeFs;
|
use project::FakeFs;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -1872,7 +1872,6 @@ mod tests {
|
|||||||
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||||
|
|
||||||
select_path(&panel, "root1", cx);
|
select_path(&panel, "root1", cx);
|
||||||
@ -1894,7 +1893,7 @@ mod tests {
|
|||||||
// Add a file with the root folder selected. The filename editor is placed
|
// Add a file with the root folder selected. The filename editor is placed
|
||||||
// before the first file in the root folder.
|
// before the first file in the root folder.
|
||||||
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
let panel = panel.read(cx);
|
let panel = panel.read(cx);
|
||||||
assert!(panel.filename_editor.is_focused(cx));
|
assert!(panel.filename_editor.is_focused(cx));
|
||||||
});
|
});
|
||||||
@ -2225,7 +2224,6 @@ mod tests {
|
|||||||
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||||
|
|
||||||
select_path(&panel, "root1", cx);
|
select_path(&panel, "root1", cx);
|
||||||
@ -2247,7 +2245,7 @@ mod tests {
|
|||||||
// Add a file with the root folder selected. The filename editor is placed
|
// Add a file with the root folder selected. The filename editor is placed
|
||||||
// before the first file in the root folder.
|
// before the first file in the root folder.
|
||||||
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
let panel = panel.read(cx);
|
let panel = panel.read(cx);
|
||||||
assert!(panel.filename_editor.is_focused(cx));
|
assert!(panel.filename_editor.is_focused(cx));
|
||||||
});
|
});
|
||||||
@ -2402,7 +2400,6 @@ mod tests {
|
|||||||
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||||
|
|
||||||
toggle_expand_dir(&panel, "src/test", cx);
|
toggle_expand_dir(&panel, "src/test", cx);
|
||||||
@ -2419,7 +2416,7 @@ mod tests {
|
|||||||
" third.rs"
|
" third.rs"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
ensure_single_file_is_opened(window_id, &workspace, "test/first.rs", cx);
|
ensure_single_file_is_opened(window, "test/first.rs", cx);
|
||||||
|
|
||||||
submit_deletion(window.into(), &panel, cx);
|
submit_deletion(window.into(), &panel, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -2446,9 +2443,9 @@ mod tests {
|
|||||||
" third.rs"
|
" third.rs"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
ensure_single_file_is_opened(window_id, &workspace, "test/second.rs", cx);
|
ensure_single_file_is_opened(window, "test/second.rs", cx);
|
||||||
|
|
||||||
cx.update_window(window_id, |cx| {
|
window.update(cx, |cx| {
|
||||||
let active_items = workspace
|
let active_items = workspace
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.panes()
|
.panes()
|
||||||
@ -2493,7 +2490,6 @@ mod tests {
|
|||||||
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||||
|
|
||||||
select_path(&panel, "src/", cx);
|
select_path(&panel, "src/", cx);
|
||||||
@ -2504,7 +2500,7 @@ mod tests {
|
|||||||
&["v src <== selected", " > test"]
|
&["v src <== selected", " > test"]
|
||||||
);
|
);
|
||||||
panel.update(cx, |panel, cx| panel.new_directory(&NewDirectory, cx));
|
panel.update(cx, |panel, cx| panel.new_directory(&NewDirectory, cx));
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
let panel = panel.read(cx);
|
let panel = panel.read(cx);
|
||||||
assert!(panel.filename_editor.is_focused(cx));
|
assert!(panel.filename_editor.is_focused(cx));
|
||||||
});
|
});
|
||||||
@ -2535,7 +2531,7 @@ mod tests {
|
|||||||
&["v src", " > test <== selected"]
|
&["v src", " > test <== selected"]
|
||||||
);
|
);
|
||||||
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx));
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
let panel = panel.read(cx);
|
let panel = panel.read(cx);
|
||||||
assert!(panel.filename_editor.is_focused(cx));
|
assert!(panel.filename_editor.is_focused(cx));
|
||||||
});
|
});
|
||||||
@ -2585,7 +2581,7 @@ mod tests {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
panel.update(cx, |panel, cx| panel.rename(&Rename, cx));
|
panel.update(cx, |panel, cx| panel.rename(&Rename, cx));
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
let panel = panel.read(cx);
|
let panel = panel.read(cx);
|
||||||
assert!(panel.filename_editor.is_focused(cx));
|
assert!(panel.filename_editor.is_focused(cx));
|
||||||
});
|
});
|
||||||
@ -2882,13 +2878,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_single_file_is_opened(
|
fn ensure_single_file_is_opened(
|
||||||
window_id: usize,
|
window: WindowHandle<Workspace>,
|
||||||
workspace: &ViewHandle<Workspace>,
|
|
||||||
expected_path: &str,
|
expected_path: &str,
|
||||||
cx: &mut TestAppContext,
|
cx: &mut TestAppContext,
|
||||||
) {
|
) {
|
||||||
cx.read_window(window_id, |cx| {
|
window.update_root(cx, |workspace, cx| {
|
||||||
let workspace = workspace.read(cx);
|
|
||||||
let worktrees = workspace.worktrees(cx).collect::<Vec<_>>();
|
let worktrees = workspace.worktrees(cx).collect::<Vec<_>>();
|
||||||
assert_eq!(worktrees.len(), 1);
|
assert_eq!(worktrees.len(), 1);
|
||||||
let worktree_id = WorktreeId::from_usize(worktrees[0].id());
|
let worktree_id = WorktreeId::from_usize(worktrees[0].id());
|
||||||
|
@ -1229,8 +1229,6 @@ mod tests {
|
|||||||
);
|
);
|
||||||
let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));
|
let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));
|
||||||
let window = cx.add_window(|_| EmptyView);
|
let window = cx.add_window(|_| EmptyView);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
let editor = window.add_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
let editor = window.add_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||||
|
|
||||||
let search_bar = window.add_view(cx, |cx| {
|
let search_bar = window.add_view(cx, |cx| {
|
||||||
@ -1249,12 +1247,13 @@ mod tests {
|
|||||||
search_bar.activate_current_match(cx);
|
search_bar.activate_current_match(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
!editor.is_focused(cx),
|
!editor.is_focused(cx),
|
||||||
"Initially, the editor should not be focused"
|
"Initially, the editor should not be focused"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
let initial_selections = editor.update(cx, |editor, cx| {
|
let initial_selections = editor.update(cx, |editor, cx| {
|
||||||
let initial_selections = editor.selections.display_ranges(cx);
|
let initial_selections = editor.selections.display_ranges(cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1271,7 +1270,7 @@ mod tests {
|
|||||||
cx.focus(search_bar.query_editor.as_any());
|
cx.focus(search_bar.query_editor.as_any());
|
||||||
search_bar.select_all_matches(&SelectAllMatches, cx);
|
search_bar.select_all_matches(&SelectAllMatches, cx);
|
||||||
});
|
});
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
editor.is_focused(cx),
|
editor.is_focused(cx),
|
||||||
"Should focus editor after successful SelectAllMatches"
|
"Should focus editor after successful SelectAllMatches"
|
||||||
@ -1295,7 +1294,7 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
});
|
});
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
editor.is_focused(cx),
|
editor.is_focused(cx),
|
||||||
"Should still have editor focused after SelectNextMatch"
|
"Should still have editor focused after SelectNextMatch"
|
||||||
@ -1324,7 +1323,7 @@ mod tests {
|
|||||||
cx.focus(search_bar.query_editor.as_any());
|
cx.focus(search_bar.query_editor.as_any());
|
||||||
search_bar.select_all_matches(&SelectAllMatches, cx);
|
search_bar.select_all_matches(&SelectAllMatches, cx);
|
||||||
});
|
});
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
editor.is_focused(cx),
|
editor.is_focused(cx),
|
||||||
"Should focus editor after successful SelectAllMatches"
|
"Should focus editor after successful SelectAllMatches"
|
||||||
@ -1348,7 +1347,7 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
});
|
});
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
editor.is_focused(cx),
|
editor.is_focused(cx),
|
||||||
"Should still have editor focused after SelectPrevMatch"
|
"Should still have editor focused after SelectPrevMatch"
|
||||||
@ -1384,7 +1383,7 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_all_matches(&SelectAllMatches, cx);
|
search_bar.select_all_matches(&SelectAllMatches, cx);
|
||||||
});
|
});
|
||||||
cx.read_window(window_id, |cx| {
|
window.read_with(cx, |cx| {
|
||||||
assert!(
|
assert!(
|
||||||
!editor.is_focused(cx),
|
!editor.is_focused(cx),
|
||||||
"Should not switch focus to editor if SelectAllMatches does not find any matches"
|
"Should not switch focus to editor if SelectAllMatches does not find any matches"
|
||||||
|
@ -1568,7 +1568,6 @@ pub mod tests {
|
|||||||
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
|
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
let active_item = cx.read(|cx| {
|
let active_item = cx.read(|cx| {
|
||||||
workspace
|
workspace
|
||||||
@ -1599,9 +1598,9 @@ pub mod tests {
|
|||||||
};
|
};
|
||||||
let search_view_id = search_view.id();
|
let search_view_id = search_view.id();
|
||||||
|
|
||||||
cx.spawn(
|
cx.spawn(|mut cx| async move {
|
||||||
|mut cx| async move { cx.dispatch_action(window_id, search_view_id, &ToggleFocus) },
|
cx.dispatch_action(window.into(), search_view_id, &ToggleFocus)
|
||||||
)
|
})
|
||||||
.detach();
|
.detach();
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
@ -1651,9 +1650,9 @@ pub mod tests {
|
|||||||
"Search view should be focused after mismatching query had been used in search",
|
"Search view should be focused after mismatching query had been used in search",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
cx.spawn(
|
cx.spawn(|mut cx| async move {
|
||||||
|mut cx| async move { cx.dispatch_action(window_id, search_view_id, &ToggleFocus) },
|
cx.dispatch_action(window.into(), search_view_id, &ToggleFocus)
|
||||||
)
|
})
|
||||||
.detach();
|
.detach();
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
@ -1683,9 +1682,9 @@ pub mod tests {
|
|||||||
"Search view with mismatching query should be focused after search results are available",
|
"Search view with mismatching query should be focused after search results are available",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
cx.spawn(
|
cx.spawn(|mut cx| async move {
|
||||||
|mut cx| async move { cx.dispatch_action(window_id, search_view_id, &ToggleFocus) },
|
cx.dispatch_action(window.into(), search_view_id, &ToggleFocus)
|
||||||
)
|
})
|
||||||
.detach();
|
.detach();
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
@ -1713,9 +1712,9 @@ pub mod tests {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn(
|
cx.spawn(|mut cx| async move {
|
||||||
|mut cx| async move { cx.dispatch_action(window_id, search_view_id, &ToggleFocus) },
|
cx.dispatch_action(window.into(), search_view_id, &ToggleFocus)
|
||||||
)
|
})
|
||||||
.detach();
|
.detach();
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::Vim;
|
use crate::Vim;
|
||||||
use editor::{EditorBlurred, EditorFocused, EditorReleased};
|
use editor::{EditorBlurred, EditorFocused, EditorReleased};
|
||||||
use gpui::{AppContext, BorrowWindowContext};
|
use gpui::AppContext;
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.subscribe_global(focused).detach();
|
cx.subscribe_global(focused).detach();
|
||||||
@ -10,7 +10,7 @@ pub fn init(cx: &mut AppContext) {
|
|||||||
|
|
||||||
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
||||||
if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() {
|
if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() {
|
||||||
cx.update_window(previously_active_editor.window_id(), |cx| {
|
previously_active_editor.window().update(cx, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
||||||
vim.unhook_vim_settings(previously_active_editor, cx)
|
vim.unhook_vim_settings(previously_active_editor, cx)
|
||||||
@ -19,7 +19,7 @@ fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.update_window(editor.window_id(), |cx| {
|
editor.window().update(cx, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.set_active_editor(editor.clone(), cx);
|
vim.set_active_editor(editor.clone(), cx);
|
||||||
});
|
});
|
||||||
@ -27,7 +27,7 @@ fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
||||||
cx.update_window(editor.window_id(), |cx| {
|
editor.window().update(cx, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||||
if previous_editor == editor.clone() {
|
if previous_editor == editor.clone() {
|
||||||
@ -41,7 +41,7 @@ fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
||||||
cx.update_window(editor.window_id(), |cx| {
|
editor.window().update(cx, |cx| {
|
||||||
cx.update_default_global(|vim: &mut Vim, _| {
|
cx.update_default_global(|vim: &mut Vim, _| {
|
||||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||||
if previous_editor == editor.clone() {
|
if previous_editor == editor.clone() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
elements::{Empty, Label},
|
elements::{Empty, Label},
|
||||||
AnyElement, Element, Entity, Subscription, View, ViewContext, BorrowWindowContext
|
AnyElement, Element, Entity, Subscription, View, ViewContext,
|
||||||
};
|
};
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use workspace::{item::ItemHandle, StatusItemView};
|
use workspace::{item::ItemHandle, StatusItemView};
|
||||||
@ -20,7 +20,7 @@ impl ModeIndicator {
|
|||||||
if let Some(mode_indicator) = handle.upgrade(cx) {
|
if let Some(mode_indicator) = handle.upgrade(cx) {
|
||||||
match event {
|
match event {
|
||||||
VimEvent::ModeChanged { mode } => {
|
VimEvent::ModeChanged { mode } => {
|
||||||
cx.update_window(mode_indicator.window_id(), |cx| {
|
mode_indicator.window().update(cx, |cx| {
|
||||||
mode_indicator.update(cx, move |mode_indicator, cx| {
|
mode_indicator.update(cx, move |mode_indicator, cx| {
|
||||||
mode_indicator.set_mode(mode, cx);
|
mode_indicator.set_mode(mode, cx);
|
||||||
})
|
})
|
||||||
|
@ -85,8 +85,8 @@ impl<'a> VimTestContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_state(&mut self, text: &str, mode: Mode) -> ContextHandle {
|
pub fn set_state(&mut self, text: &str, mode: Mode) -> ContextHandle {
|
||||||
let window_id = self.window.id();
|
let window = self.window;
|
||||||
self.update_window(window_id, |cx| {
|
window.update(self.cx.cx.cx, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.switch_mode(mode, false, cx);
|
vim.switch_mode(mode, false, cx);
|
||||||
})
|
})
|
||||||
|
@ -203,7 +203,7 @@ impl Dock {
|
|||||||
pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {
|
pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {
|
||||||
self.panel_entries.iter().position(|entry| {
|
self.panel_entries.iter().position(|entry| {
|
||||||
let panel = entry.panel.as_any();
|
let panel = entry.panel.as_any();
|
||||||
cx.view_ui_name(panel.window_id(), panel.id()) == Some(ui_name)
|
cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,16 +530,12 @@ impl View for PanelButtons {
|
|||||||
tooltip_action.as_ref().map(|action| action.boxed_clone());
|
tooltip_action.as_ref().map(|action| action.boxed_clone());
|
||||||
move |_, this, cx| {
|
move |_, this, cx| {
|
||||||
if let Some(tooltip_action) = &tooltip_action {
|
if let Some(tooltip_action) = &tooltip_action {
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
let view_id = this.workspace.id();
|
let view_id = this.workspace.id();
|
||||||
let tooltip_action = tooltip_action.boxed_clone();
|
let tooltip_action = tooltip_action.boxed_clone();
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
cx.dispatch_action(
|
cx.dispatch_action(window, view_id, &*tooltip_action)
|
||||||
window_id,
|
.ok();
|
||||||
view_id,
|
|
||||||
&*tooltip_action,
|
|
||||||
)
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -1917,8 +1917,8 @@ impl<V: View> Element<V> for PaneBackdrop<V> {
|
|||||||
MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down(
|
MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down(
|
||||||
gpui::platform::MouseButton::Left,
|
gpui::platform::MouseButton::Left,
|
||||||
move |_, _: &mut V, cx| {
|
move |_, _: &mut V, cx| {
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
cx.app_context().focus(window_id, Some(child_view_id))
|
cx.app_context().focus(window, Some(child_view_id))
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1250,11 +1250,11 @@ impl Workspace {
|
|||||||
_: &CloseWindow,
|
_: &CloseWindow,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
let prepare = self.prepare_to_close(false, cx);
|
let prepare = self.prepare_to_close(false, cx);
|
||||||
Some(cx.spawn(|_, mut cx| async move {
|
Some(cx.spawn(|_, mut cx| async move {
|
||||||
if prepare.await? {
|
if prepare.await? {
|
||||||
cx.remove_window(window_id);
|
cx.remove_window(window);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
@ -1266,7 +1266,7 @@ impl Workspace {
|
|||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Result<bool>> {
|
) -> Task<Result<bool>> {
|
||||||
let active_call = self.active_call().cloned();
|
let active_call = self.active_call().cloned();
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let workspace_count = cx
|
let workspace_count = cx
|
||||||
@ -1281,7 +1281,7 @@ impl Workspace {
|
|||||||
&& active_call.read_with(&cx, |call, _| call.room().is_some())
|
&& active_call.read_with(&cx, |call, _| call.room().is_some())
|
||||||
{
|
{
|
||||||
let answer = cx.prompt(
|
let answer = cx.prompt(
|
||||||
window_id,
|
window,
|
||||||
PromptLevel::Warning,
|
PromptLevel::Warning,
|
||||||
"Do you want to leave the current call?",
|
"Do you want to leave the current call?",
|
||||||
&["Close window and hang up", "Cancel"],
|
&["Close window and hang up", "Cancel"],
|
||||||
@ -1390,7 +1390,7 @@ impl Workspace {
|
|||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let window = cx.window::<Self>();
|
let window = cx.window().downcast::<Self>();
|
||||||
let is_remote = self.project.read(cx).is_remote();
|
let is_remote = self.project.read(cx).is_remote();
|
||||||
let has_worktree = self.project.read(cx).worktrees(cx).next().is_some();
|
let has_worktree = self.project.read(cx).worktrees(cx).next().is_some();
|
||||||
let has_dirty_items = self.items(cx).any(|item| item.is_dirty(cx));
|
let has_dirty_items = self.items(cx).any(|item| item.is_dirty(cx));
|
||||||
@ -3181,7 +3181,7 @@ impl Workspace {
|
|||||||
let left_visible = left_dock.is_open();
|
let left_visible = left_dock.is_open();
|
||||||
let left_active_panel = left_dock.visible_panel().and_then(|panel| {
|
let left_active_panel = left_dock.visible_panel().and_then(|panel| {
|
||||||
Some(
|
Some(
|
||||||
cx.view_ui_name(panel.as_any().window_id(), panel.id())?
|
cx.view_ui_name(panel.as_any().window(), panel.id())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -3194,7 +3194,7 @@ impl Workspace {
|
|||||||
let right_visible = right_dock.is_open();
|
let right_visible = right_dock.is_open();
|
||||||
let right_active_panel = right_dock.visible_panel().and_then(|panel| {
|
let right_active_panel = right_dock.visible_panel().and_then(|panel| {
|
||||||
Some(
|
Some(
|
||||||
cx.view_ui_name(panel.as_any().window_id(), panel.id())?
|
cx.view_ui_name(panel.as_any().window(), panel.id())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -3207,7 +3207,7 @@ impl Workspace {
|
|||||||
let bottom_visible = bottom_dock.is_open();
|
let bottom_visible = bottom_dock.is_open();
|
||||||
let bottom_active_panel = bottom_dock.visible_panel().and_then(|panel| {
|
let bottom_active_panel = bottom_dock.visible_panel().and_then(|panel| {
|
||||||
Some(
|
Some(
|
||||||
cx.view_ui_name(panel.as_any().window_id(), panel.id())?
|
cx.view_ui_name(panel.as_any().window(), panel.id())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -4000,7 +4000,7 @@ pub fn join_remote_project(
|
|||||||
workspace.downgrade()
|
workspace.downgrade()
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.activate_window(workspace.window_id());
|
cx.activate_window(workspace.window());
|
||||||
cx.platform().activate(true);
|
cx.platform().activate(true);
|
||||||
|
|
||||||
workspace.update(&mut cx, |workspace, cx| {
|
workspace.update(&mut cx, |workspace, cx| {
|
||||||
@ -4049,9 +4049,9 @@ pub fn restart(_: &Restart, cx: &mut AppContext) {
|
|||||||
// prompt in the active window before switching to a different window.
|
// prompt in the active window before switching to a different window.
|
||||||
workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
|
workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
|
||||||
|
|
||||||
if let (true, Some(window)) = (should_confirm, workspace_windows.first()) {
|
if let (true, Some(window)) = (should_confirm, workspace_windows.first().copied()) {
|
||||||
let answer = cx.prompt(
|
let answer = cx.prompt(
|
||||||
window.id(),
|
window.into(),
|
||||||
PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
"Are you sure you want to restart?",
|
"Are you sure you want to restart?",
|
||||||
&["Restart", "Cancel"],
|
&["Restart", "Cancel"],
|
||||||
|
@ -179,13 +179,12 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
|||||||
move |workspace: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
|
move |workspace: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
|
||||||
let app_state = workspace.app_state().clone();
|
let app_state = workspace.app_state().clone();
|
||||||
let markdown = app_state.languages.language_for_name("JSON");
|
let markdown = app_state.languages.language_for_name("JSON");
|
||||||
let window_id = cx.window_id();
|
let window = cx.window();
|
||||||
cx.spawn(|workspace, mut cx| async move {
|
cx.spawn(|workspace, mut cx| async move {
|
||||||
let markdown = markdown.await.log_err();
|
let markdown = markdown.await.log_err();
|
||||||
let content = to_string_pretty(
|
let content = to_string_pretty(&cx.debug_elements(window).ok_or_else(|| {
|
||||||
&cx.debug_elements(window_id)
|
anyhow!("could not debug elements for window {}", window.id())
|
||||||
.ok_or_else(|| anyhow!("could not debug elements for {window_id}"))?,
|
})?)
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
workspace
|
workspace
|
||||||
.update(&mut cx, |workspace, cx| {
|
.update(&mut cx, |workspace, cx| {
|
||||||
@ -416,9 +415,9 @@ fn quit(_: &Quit, cx: &mut gpui::AppContext) {
|
|||||||
// prompt in the active window before switching to a different window.
|
// prompt in the active window before switching to a different window.
|
||||||
workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
|
workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
|
||||||
|
|
||||||
if let (true, Some(window)) = (should_confirm, workspace_windows.first()) {
|
if let (true, Some(window)) = (should_confirm, workspace_windows.first().copied()) {
|
||||||
let answer = cx.prompt(
|
let answer = cx.prompt(
|
||||||
window.id(),
|
window.into(),
|
||||||
PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
"Are you sure you want to quit?",
|
"Are you sure you want to quit?",
|
||||||
&["Quit", "Cancel"],
|
&["Quit", "Cancel"],
|
||||||
@ -716,8 +715,8 @@ mod tests {
|
|||||||
use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor};
|
use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor};
|
||||||
use fs::{FakeFs, Fs};
|
use fs::{FakeFs, Fs};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::Empty, executor::Deterministic, Action, AnyElement, AppContext,
|
actions, elements::Empty, executor::Deterministic, Action, AnyElement, AnyWindowHandle,
|
||||||
AssetSource, Element, Entity, TestAppContext, View, ViewHandle,
|
AppContext, AssetSource, Element, Entity, TestAppContext, View, ViewHandle,
|
||||||
};
|
};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use node_runtime::NodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
@ -1317,11 +1316,10 @@ mod tests {
|
|||||||
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());
|
let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());
|
||||||
|
|
||||||
// Create a new untitled buffer
|
// Create a new untitled buffer
|
||||||
cx.dispatch_action(window_id, NewFile);
|
cx.dispatch_action(window.into(), NewFile);
|
||||||
let editor = workspace.read_with(cx, |workspace, cx| {
|
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||||
workspace
|
workspace
|
||||||
.active_item(cx)
|
.active_item(cx)
|
||||||
@ -1376,7 +1374,7 @@ mod tests {
|
|||||||
|
|
||||||
// Open the same newly-created file in another pane item. The new editor should reuse
|
// Open the same newly-created file in another pane item. The new editor should reuse
|
||||||
// the same buffer.
|
// the same buffer.
|
||||||
cx.dispatch_action(window_id, NewFile);
|
cx.dispatch_action(window.into(), NewFile);
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |workspace, cx| {
|
.update(cx, |workspace, cx| {
|
||||||
workspace.split_and_clone(
|
workspace.split_and_clone(
|
||||||
@ -1412,10 +1410,9 @@ mod tests {
|
|||||||
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
// Create a new untitled buffer
|
// Create a new untitled buffer
|
||||||
cx.dispatch_action(window_id, NewFile);
|
cx.dispatch_action(window.into(), NewFile);
|
||||||
let editor = workspace.read_with(cx, |workspace, cx| {
|
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||||
workspace
|
workspace
|
||||||
.active_item(cx)
|
.active_item(cx)
|
||||||
@ -1465,7 +1462,6 @@ mod tests {
|
|||||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||||
let workspace = window.root(cx);
|
let workspace = window.root(cx);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
||||||
let file1 = entries[0].clone();
|
let file1 = entries[0].clone();
|
||||||
@ -1487,7 +1483,7 @@ mod tests {
|
|||||||
(editor.downgrade(), buffer)
|
(editor.downgrade(), buffer)
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.dispatch_action(window_id, pane::SplitRight);
|
cx.dispatch_action(window.into(), pane::SplitRight);
|
||||||
let editor_2 = cx.update(|cx| {
|
let editor_2 = cx.update(|cx| {
|
||||||
let pane_2 = workspace.read(cx).active_pane().clone();
|
let pane_2 = workspace.read(cx).active_pane().clone();
|
||||||
assert_ne!(pane_1, pane_2);
|
assert_ne!(pane_1, pane_2);
|
||||||
@ -1497,7 +1493,7 @@ mod tests {
|
|||||||
|
|
||||||
pane2_item.downcast::<Editor>().unwrap().downgrade()
|
pane2_item.downcast::<Editor>().unwrap().downgrade()
|
||||||
});
|
});
|
||||||
cx.dispatch_action(window_id, workspace::CloseActiveItem);
|
cx.dispatch_action(window.into(), workspace::CloseActiveItem);
|
||||||
|
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
workspace.read_with(cx, |workspace, _| {
|
workspace.read_with(cx, |workspace, _| {
|
||||||
@ -1505,7 +1501,7 @@ mod tests {
|
|||||||
assert_eq!(workspace.active_pane(), &pane_1);
|
assert_eq!(workspace.active_pane(), &pane_1);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.dispatch_action(window_id, workspace::CloseActiveItem);
|
cx.dispatch_action(window.into(), workspace::CloseActiveItem);
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
window.simulate_prompt_answer(1, cx);
|
window.simulate_prompt_answer(1, cx);
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
@ -2063,11 +2059,10 @@ mod tests {
|
|||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
let window = cx.add_window(|_| TestView);
|
let window = cx.add_window(|_| TestView);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
// Test loading the keymap base at all
|
// Test loading the keymap base at all
|
||||||
assert_key_bindings_for(
|
assert_key_bindings_for(
|
||||||
window_id,
|
window.into(),
|
||||||
cx,
|
cx,
|
||||||
vec![("backspace", &A), ("k", &ActivatePreviousPane)],
|
vec![("backspace", &A), ("k", &ActivatePreviousPane)],
|
||||||
line!(),
|
line!(),
|
||||||
@ -2094,7 +2089,7 @@ mod tests {
|
|||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
assert_key_bindings_for(
|
assert_key_bindings_for(
|
||||||
window_id,
|
window.into(),
|
||||||
cx,
|
cx,
|
||||||
vec![("backspace", &B), ("k", &ActivatePreviousPane)],
|
vec![("backspace", &B), ("k", &ActivatePreviousPane)],
|
||||||
line!(),
|
line!(),
|
||||||
@ -2117,7 +2112,7 @@ mod tests {
|
|||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
assert_key_bindings_for(
|
assert_key_bindings_for(
|
||||||
window_id,
|
window.into(),
|
||||||
cx,
|
cx,
|
||||||
vec![("backspace", &B), ("[", &ActivatePrevItem)],
|
vec![("backspace", &B), ("[", &ActivatePrevItem)],
|
||||||
line!(),
|
line!(),
|
||||||
@ -2125,7 +2120,7 @@ mod tests {
|
|||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn assert_key_bindings_for<'a>(
|
fn assert_key_bindings_for<'a>(
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
cx: &TestAppContext,
|
cx: &TestAppContext,
|
||||||
actions: Vec<(&'static str, &'a dyn Action)>,
|
actions: Vec<(&'static str, &'a dyn Action)>,
|
||||||
line: u32,
|
line: u32,
|
||||||
@ -2133,7 +2128,7 @@ mod tests {
|
|||||||
for (key, action) in actions {
|
for (key, action) in actions {
|
||||||
// assert that...
|
// assert that...
|
||||||
assert!(
|
assert!(
|
||||||
cx.available_actions(window_id, 0)
|
cx.available_actions(window, 0)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.any(|(_, bound_action, b)| {
|
.any(|(_, bound_action, b)| {
|
||||||
// action names match...
|
// action names match...
|
||||||
@ -2234,11 +2229,10 @@ mod tests {
|
|||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
let window = cx.add_window(|_| TestView);
|
let window = cx.add_window(|_| TestView);
|
||||||
let window_id = window.id();
|
|
||||||
|
|
||||||
// Test loading the keymap base at all
|
// Test loading the keymap base at all
|
||||||
assert_key_bindings_for(
|
assert_key_bindings_for(
|
||||||
window_id,
|
window.into(),
|
||||||
cx,
|
cx,
|
||||||
vec![("backspace", &A), ("k", &ActivatePreviousPane)],
|
vec![("backspace", &A), ("k", &ActivatePreviousPane)],
|
||||||
line!(),
|
line!(),
|
||||||
@ -2264,7 +2258,12 @@ mod tests {
|
|||||||
|
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
assert_key_bindings_for(window_id, cx, vec![("k", &ActivatePreviousPane)], line!());
|
assert_key_bindings_for(
|
||||||
|
window.into(),
|
||||||
|
cx,
|
||||||
|
vec![("k", &ActivatePreviousPane)],
|
||||||
|
line!(),
|
||||||
|
);
|
||||||
|
|
||||||
// Test modifying the base, while retaining the users keymap
|
// Test modifying the base, while retaining the users keymap
|
||||||
fs.save(
|
fs.save(
|
||||||
@ -2282,11 +2281,11 @@ mod tests {
|
|||||||
|
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
assert_key_bindings_for(window_id, cx, vec![("[", &ActivatePrevItem)], line!());
|
assert_key_bindings_for(window.into(), cx, vec![("[", &ActivatePrevItem)], line!());
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn assert_key_bindings_for<'a>(
|
fn assert_key_bindings_for<'a>(
|
||||||
window_id: usize,
|
window: AnyWindowHandle,
|
||||||
cx: &TestAppContext,
|
cx: &TestAppContext,
|
||||||
actions: Vec<(&'static str, &'a dyn Action)>,
|
actions: Vec<(&'static str, &'a dyn Action)>,
|
||||||
line: u32,
|
line: u32,
|
||||||
@ -2294,7 +2293,7 @@ mod tests {
|
|||||||
for (key, action) in actions {
|
for (key, action) in actions {
|
||||||
// assert that...
|
// assert that...
|
||||||
assert!(
|
assert!(
|
||||||
cx.available_actions(window_id, 0)
|
cx.available_actions(window, 0)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.any(|(_, bound_action, b)| {
|
.any(|(_, bound_action, b)| {
|
||||||
// action names match...
|
// action names match...
|
||||||
|
Loading…
Reference in New Issue
Block a user