Remove more window id usage
This commit is contained in:
+3
-11
@@ -833,7 +833,7 @@ impl AppContext {
|
||||
&mut self,
|
||||
callback: F,
|
||||
) -> Option<T> {
|
||||
self.main_window()
|
||||
self.active_window()
|
||||
.and_then(|window| window.update(self, callback))
|
||||
}
|
||||
|
||||
@@ -1093,7 +1093,7 @@ impl AppContext {
|
||||
pub fn is_action_available(&self, action: &dyn Action) -> bool {
|
||||
let mut available_in_window = false;
|
||||
let action_id = action.id();
|
||||
if let Some(window) = self.main_window() {
|
||||
if let Some(window) = self.active_window() {
|
||||
available_in_window = self
|
||||
.read_window(window, |cx| {
|
||||
if let Some(focused_view_id) = cx.focused_view_id() {
|
||||
@@ -1436,7 +1436,7 @@ impl AppContext {
|
||||
window
|
||||
}
|
||||
|
||||
pub fn main_window(&self) -> Option<AnyWindowHandle> {
|
||||
pub fn active_window(&self) -> Option<AnyWindowHandle> {
|
||||
self.platform.main_window_id().and_then(|main_window_id| {
|
||||
self.windows
|
||||
.get(&main_window_id)
|
||||
@@ -2997,10 +2997,6 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
||||
WeakViewHandle::new(self.window_handle, self.view_id)
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> usize {
|
||||
self.window_handle.id()
|
||||
}
|
||||
|
||||
pub fn window(&self) -> AnyWindowHandle {
|
||||
self.window_handle
|
||||
}
|
||||
@@ -4138,10 +4134,6 @@ impl<T: View> ViewHandle<T> {
|
||||
self.any_handle
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> usize {
|
||||
self.window.id()
|
||||
}
|
||||
|
||||
pub fn window(&self) -> AnyWindowHandle {
|
||||
self.window
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ pub(crate) fn setup_menu_handlers(foreground_platform: &dyn ForegroundPlatform,
|
||||
let cx = app.0.clone();
|
||||
move |action| {
|
||||
let mut cx = cx.borrow_mut();
|
||||
if let Some(main_window) = cx.main_window() {
|
||||
if let Some(main_window) = cx.active_window() {
|
||||
let dispatched = main_window
|
||||
.update(&mut *cx, |cx| {
|
||||
if let Some(view_id) = cx.focused_view_id() {
|
||||
|
||||
@@ -152,11 +152,11 @@ impl BorrowWindowContext for WindowContext<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_window_optional<T, F>(&self, window_id: AnyWindowHandle, f: F) -> Option<T>
|
||||
fn read_window_optional<T, F>(&self, window: AnyWindowHandle, f: F) -> Option<T>
|
||||
where
|
||||
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>(
|
||||
@@ -210,10 +210,6 @@ impl<'a> WindowContext<'a> {
|
||||
self.removed = true;
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> usize {
|
||||
self.window_handle.id()
|
||||
}
|
||||
|
||||
pub fn window(&self) -> AnyWindowHandle {
|
||||
self.window_handle
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::Project;
|
||||
use gpui::{ModelContext, ModelHandle, WeakModelHandle};
|
||||
use gpui::{AnyWindowHandle, ModelContext, ModelHandle, WeakModelHandle};
|
||||
use std::path::PathBuf;
|
||||
use terminal::{Terminal, TerminalBuilder, TerminalSettings};
|
||||
|
||||
@@ -11,7 +11,7 @@ impl Project {
|
||||
pub fn create_terminal(
|
||||
&mut self,
|
||||
working_directory: Option<PathBuf>,
|
||||
window_id: usize,
|
||||
window: AnyWindowHandle,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> anyhow::Result<ModelHandle<Terminal>> {
|
||||
if self.is_remote() {
|
||||
@@ -27,7 +27,7 @@ impl Project {
|
||||
settings.env.clone(),
|
||||
Some(settings.blinking.clone()),
|
||||
settings.alternate_scroll,
|
||||
window_id,
|
||||
window,
|
||||
)
|
||||
.map(|builder| {
|
||||
let terminal_handle = cx.add_model(|cx| builder.subscribe(cx));
|
||||
|
||||
@@ -53,7 +53,7 @@ use gpui::{
|
||||
keymap_matcher::Keystroke,
|
||||
platform::{Modifiers, MouseButton, MouseMovedEvent, TouchPhase},
|
||||
scene::{MouseDown, MouseDrag, MouseScrollWheel, MouseUp},
|
||||
AppContext, ClipboardItem, Entity, ModelContext, Task,
|
||||
AnyWindowHandle, AppContext, ClipboardItem, Entity, ModelContext, Task,
|
||||
};
|
||||
|
||||
use crate::mappings::{
|
||||
@@ -404,7 +404,7 @@ impl TerminalBuilder {
|
||||
mut env: HashMap<String, String>,
|
||||
blink_settings: Option<TerminalBlink>,
|
||||
alternate_scroll: AlternateScroll,
|
||||
window_id: usize,
|
||||
window: AnyWindowHandle,
|
||||
) -> Result<TerminalBuilder> {
|
||||
let pty_config = {
|
||||
let alac_shell = match shell.clone() {
|
||||
@@ -462,7 +462,7 @@ impl TerminalBuilder {
|
||||
let pty = match tty::new(
|
||||
&pty_config,
|
||||
TerminalSize::default().into(),
|
||||
window_id as u64,
|
||||
window.id() as u64,
|
||||
) {
|
||||
Ok(pty) => pty,
|
||||
Err(error) => {
|
||||
|
||||
@@ -255,10 +255,10 @@ impl TerminalPanel {
|
||||
.clone();
|
||||
let working_directory =
|
||||
crate::get_working_directory(workspace, cx, working_directory_strategy);
|
||||
let window_id = cx.window_id();
|
||||
let window = cx.window();
|
||||
if let Some(terminal) = workspace.project().update(cx, |project, cx| {
|
||||
project
|
||||
.create_terminal(working_directory, window_id, cx)
|
||||
.create_terminal(working_directory, window, cx)
|
||||
.log_err()
|
||||
}) {
|
||||
let terminal = Box::new(cx.add_view(|cx| {
|
||||
|
||||
@@ -112,11 +112,11 @@ impl TerminalView {
|
||||
let working_directory =
|
||||
get_working_directory(workspace, cx, strategy.working_directory.clone());
|
||||
|
||||
let window_id = cx.window_id();
|
||||
let window = cx.window();
|
||||
let terminal = workspace
|
||||
.project()
|
||||
.update(cx, |project, cx| {
|
||||
project.create_terminal(working_directory, window_id, cx)
|
||||
project.create_terminal(working_directory, window, cx)
|
||||
})
|
||||
.notify_err(workspace, cx);
|
||||
|
||||
@@ -741,7 +741,7 @@ impl Item for TerminalView {
|
||||
item_id: workspace::ItemId,
|
||||
cx: &mut ViewContext<Pane>,
|
||||
) -> Task<anyhow::Result<ViewHandle<Self>>> {
|
||||
let window_id = cx.window_id();
|
||||
let window = cx.window();
|
||||
cx.spawn(|pane, mut cx| async move {
|
||||
let cwd = TERMINAL_DB
|
||||
.get_working_directory(item_id, workspace_id)
|
||||
@@ -762,7 +762,7 @@ impl Item for TerminalView {
|
||||
});
|
||||
|
||||
let terminal = project.update(&mut cx, |project, cx| {
|
||||
project.create_terminal(cwd, window_id, cx)
|
||||
project.create_terminal(cwd, window, cx)
|
||||
})?;
|
||||
Ok(pane.update(&mut cx, |_, cx| {
|
||||
cx.add_view(|cx| TerminalView::new(terminal, workspace, workspace_id, cx))
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::{AutosaveSetting, DelayedDebouncedEditAction, WorkspaceSettings};
|
||||
use anyhow::Result;
|
||||
use client::{proto, Client};
|
||||
use gpui::geometry::vector::Vector2F;
|
||||
use gpui::AnyWindowHandle;
|
||||
use gpui::{
|
||||
fonts::HighlightStyle, AnyElement, AnyViewHandle, AppContext, ModelHandle, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle, WindowContext,
|
||||
@@ -250,7 +251,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
||||
fn workspace_deactivated(&self, cx: &mut WindowContext);
|
||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut WindowContext) -> bool;
|
||||
fn id(&self) -> usize;
|
||||
fn window_id(&self) -> usize;
|
||||
fn window(&self) -> AnyWindowHandle;
|
||||
fn as_any(&self) -> &AnyViewHandle;
|
||||
fn is_dirty(&self, cx: &AppContext) -> bool;
|
||||
fn has_conflict(&self, cx: &AppContext) -> bool;
|
||||
@@ -542,8 +543,8 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||
self.id()
|
||||
}
|
||||
|
||||
fn window_id(&self) -> usize {
|
||||
self.window_id()
|
||||
fn window(&self) -> AnyWindowHandle {
|
||||
AnyViewHandle::window(self)
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &AnyViewHandle {
|
||||
|
||||
@@ -235,7 +235,7 @@ impl From<&Box<dyn SearchableItemHandle>> for AnyViewHandle {
|
||||
|
||||
impl PartialEq for Box<dyn SearchableItemHandle> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id() == other.id() && self.window_id() == other.window_id()
|
||||
self.id() == other.id() && self.window() == other.window()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -931,11 +931,11 @@ pub fn dock_default_item_factory(
|
||||
.clone();
|
||||
let working_directory = get_working_directory(workspace, cx, strategy);
|
||||
|
||||
let window_id = cx.window_id();
|
||||
let window = cx.window();
|
||||
let terminal = workspace
|
||||
.project()
|
||||
.update(cx, |project, cx| {
|
||||
project.create_terminal(working_directory, window_id, cx)
|
||||
project.create_terminal(working_directory, window, cx)
|
||||
})
|
||||
.notify_err(workspace, cx)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user