Disable events when project becomes read-only
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
77e913b5a4
commit
38313abc48
2 changed files with 67 additions and 36 deletions
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
|
|
||||||
pub struct EventHandler {
|
pub struct EventHandler {
|
||||||
child: ElementBox,
|
child: ElementBox,
|
||||||
|
capture: Option<Box<dyn FnMut(&Event, RectF, &mut EventContext) -> bool>>,
|
||||||
mouse_down: Option<Box<dyn FnMut(&mut EventContext) -> bool>>,
|
mouse_down: Option<Box<dyn FnMut(&mut EventContext) -> bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ impl EventHandler {
|
||||||
pub fn new(child: ElementBox) -> Self {
|
pub fn new(child: ElementBox) -> Self {
|
||||||
Self {
|
Self {
|
||||||
child,
|
child,
|
||||||
|
capture: None,
|
||||||
mouse_down: None,
|
mouse_down: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +28,14 @@ impl EventHandler {
|
||||||
self.mouse_down = Some(Box::new(callback));
|
self.mouse_down = Some(Box::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn capture<F>(mut self, callback: F) -> Self
|
||||||
|
where
|
||||||
|
F: 'static + FnMut(&Event, RectF, &mut EventContext) -> bool,
|
||||||
|
{
|
||||||
|
self.capture = Some(Box::new(callback));
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element for EventHandler {
|
impl Element for EventHandler {
|
||||||
|
@ -59,6 +69,12 @@ impl Element for EventHandler {
|
||||||
_: &mut Self::PaintState,
|
_: &mut Self::PaintState,
|
||||||
cx: &mut EventContext,
|
cx: &mut EventContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
if let Some(capture) = self.capture.as_mut() {
|
||||||
|
if capture(event, bounds, cx) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.child.dispatch_event(event, cx) {
|
if self.child.dispatch_event(event, cx) {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1308,13 +1308,17 @@ impl Workspace {
|
||||||
if self.project.read(cx).is_read_only() {
|
if self.project.read(cx).is_read_only() {
|
||||||
let theme = &self.settings.borrow().theme;
|
let theme = &self.settings.borrow().theme;
|
||||||
Some(
|
Some(
|
||||||
Label::new(
|
EventHandler::new(
|
||||||
"Your connection to the remote project has been lost.".to_string(),
|
Label::new(
|
||||||
theme.workspace.disconnected_overlay.text.clone(),
|
"Your connection to the remote project has been lost.".to_string(),
|
||||||
|
theme.workspace.disconnected_overlay.text.clone(),
|
||||||
|
)
|
||||||
|
.aligned()
|
||||||
|
.contained()
|
||||||
|
.with_style(theme.workspace.disconnected_overlay.container)
|
||||||
|
.boxed(),
|
||||||
)
|
)
|
||||||
.aligned()
|
.capture(|_, _, _| true)
|
||||||
.contained()
|
|
||||||
.with_style(theme.workspace.disconnected_overlay.container)
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1335,40 +1339,51 @@ impl View for Workspace {
|
||||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
let settings = self.settings.borrow();
|
let settings = self.settings.borrow();
|
||||||
let theme = &settings.theme;
|
let theme = &settings.theme;
|
||||||
Flex::column()
|
Stack::new()
|
||||||
.with_child(self.render_titlebar(&theme, cx))
|
|
||||||
.with_child(
|
.with_child(
|
||||||
Stack::new()
|
Flex::column()
|
||||||
.with_child({
|
.with_child(self.render_titlebar(&theme, cx))
|
||||||
let mut content = Flex::row();
|
.with_child(
|
||||||
content.add_child(self.left_sidebar.render(&settings, cx));
|
Stack::new()
|
||||||
if let Some(element) = self.left_sidebar.render_active_item(&settings, cx) {
|
.with_child({
|
||||||
content.add_child(Flexible::new(0.8, false, element).boxed());
|
let mut content = Flex::row();
|
||||||
}
|
content.add_child(self.left_sidebar.render(&settings, cx));
|
||||||
content.add_child(
|
if let Some(element) =
|
||||||
Flex::column()
|
self.left_sidebar.render_active_item(&settings, cx)
|
||||||
.with_child(
|
{
|
||||||
Flexible::new(1., true, self.center.render(&settings.theme))
|
content.add_child(Flexible::new(0.8, false, element).boxed());
|
||||||
|
}
|
||||||
|
content.add_child(
|
||||||
|
Flex::column()
|
||||||
|
.with_child(
|
||||||
|
Flexible::new(
|
||||||
|
1.,
|
||||||
|
true,
|
||||||
|
self.center.render(&settings.theme),
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child(ChildView::new(&self.status_bar).boxed())
|
||||||
|
.flexible(1., true)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
);
|
||||||
.with_child(ChildView::new(&self.status_bar).boxed())
|
if let Some(element) =
|
||||||
.flexible(1., true)
|
self.right_sidebar.render_active_item(&settings, cx)
|
||||||
.boxed(),
|
{
|
||||||
);
|
content.add_child(Flexible::new(0.8, false, element).boxed());
|
||||||
if let Some(element) = self.right_sidebar.render_active_item(&settings, cx)
|
}
|
||||||
{
|
content.add_child(self.right_sidebar.render(&settings, cx));
|
||||||
content.add_child(Flexible::new(0.8, false, element).boxed());
|
content.boxed()
|
||||||
}
|
})
|
||||||
content.add_child(self.right_sidebar.render(&settings, cx));
|
.with_children(self.modal.as_ref().map(|m| ChildView::new(m).boxed()))
|
||||||
content.boxed()
|
.flexible(1.0, true)
|
||||||
})
|
.boxed(),
|
||||||
.with_children(self.modal.as_ref().map(|m| ChildView::new(m).boxed()))
|
)
|
||||||
.with_children(self.render_disconnected_overlay(cx))
|
.contained()
|
||||||
.flexible(1.0, true)
|
.with_background_color(settings.theme.workspace.background)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.contained()
|
.with_children(self.render_disconnected_overlay(cx))
|
||||||
.with_background_color(settings.theme.workspace.background)
|
|
||||||
.named("workspace")
|
.named("workspace")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue