Merge remote-tracking branch 'origin/sexy' into chat-theme-prep

This commit is contained in:
Max Brunsfeld 2021-08-20 09:50:58 -07:00
commit c7c7a197d1
8 changed files with 155 additions and 58 deletions

View file

@ -12,7 +12,7 @@ fn main() {
gpui::App::new(()).unwrap().run(|cx| {
cx.platform().activate(true);
cx.add_window(|_| TextView);
cx.add_window(Default::default(), |_| TextView);
});
}

View file

@ -12,7 +12,6 @@ use anyhow::{anyhow, Result};
use async_task::Task;
use keymap::MatchResult;
use parking_lot::{Mutex, RwLock};
use pathfinder_geometry::{rect::RectF, vector::vec2f};
use platform::Event;
use postage::{mpsc, sink::Sink as _, stream::Stream as _};
use smol::prelude::*;
@ -305,7 +304,9 @@ impl TestAppContext {
T: View,
F: FnOnce(&mut ViewContext<T>) -> T,
{
self.cx.borrow_mut().add_window(build_root_view)
self.cx
.borrow_mut()
.add_window(Default::default(), build_root_view)
}
pub fn window_ids(&self) -> Vec<usize> {
@ -973,7 +974,11 @@ impl MutableAppContext {
handle
}
pub fn add_window<T, F>(&mut self, build_root_view: F) -> (usize, ViewHandle<T>)
pub fn add_window<T, F>(
&mut self,
window_options: WindowOptions,
build_root_view: F,
) -> (usize, ViewHandle<T>)
where
T: View,
F: FnOnce(&mut ViewContext<T>) -> T,
@ -990,7 +995,7 @@ impl MutableAppContext {
invalidation: None,
},
);
self.open_platform_window(window_id);
self.open_platform_window(window_id, window_options);
root_view.update(self, |view, cx| {
view.on_focus(cx);
cx.notify();
@ -1006,15 +1011,11 @@ impl MutableAppContext {
self.remove_dropped_entities();
}
fn open_platform_window(&mut self, window_id: usize) {
let mut window = self.cx.platform.open_window(
window_id,
WindowOptions {
bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)),
title: "Zed".into(),
},
self.foreground.clone(),
);
fn open_platform_window(&mut self, window_id: usize, window_options: WindowOptions) {
let mut window =
self.cx
.platform
.open_window(window_id, window_options, self.foreground.clone());
let text_layout_cache = TextLayoutCache::new(self.cx.platform.fonts());
let presenter = Rc::new(RefCell::new(Presenter::new(
window_id,
@ -1054,6 +1055,7 @@ impl MutableAppContext {
app.update(|cx| {
let scene = presenter.borrow_mut().build_scene(
window.size(),
window.titlebar_height(),
window.scale_factor(),
cx,
);
@ -1210,7 +1212,12 @@ impl MutableAppContext {
{
let mut presenter = presenter.borrow_mut();
presenter.invalidate(invalidation, self.as_ref());
let scene = presenter.build_scene(window.size(), window.scale_factor(), self);
let scene = presenter.build_scene(
window.size(),
window.titlebar_height(),
window.scale_factor(),
self,
);
window.present_scene(scene);
}
self.presenters_and_platform_windows
@ -3120,7 +3127,7 @@ mod tests {
}
}
let (window_id, _) = cx.add_window(|cx| View::new(None, cx));
let (window_id, _) = cx.add_window(Default::default(), |cx| View::new(None, cx));
let handle_1 = cx.add_view(window_id, |cx| View::new(None, cx));
let handle_2 = cx.add_view(window_id, |cx| View::new(Some(handle_1.clone()), cx));
assert_eq!(cx.cx.views.len(), 3);
@ -3176,7 +3183,7 @@ mod tests {
}
let mouse_down_count = Arc::new(AtomicUsize::new(0));
let (window_id, _) = cx.add_window(|_| View {
let (window_id, _) = cx.add_window(Default::default(), |_| View {
mouse_down_count: mouse_down_count.clone(),
});
let presenter = cx.presenters_and_platform_windows[&window_id].0.clone();
@ -3234,7 +3241,7 @@ mod tests {
released: model_released.clone(),
});
let (window_id, _) = cx.add_window(|_| View {
let (window_id, _) = cx.add_window(Default::default(), |_| View {
released: view_released.clone(),
});
@ -3277,7 +3284,7 @@ mod tests {
type Event = usize;
}
let (window_id, handle_1) = cx.add_window(|_| View::default());
let (window_id, handle_1) = cx.add_window(Default::default(), |_| View::default());
let handle_2 = cx.add_view(window_id, |_| View::default());
let handle_2b = handle_2.clone();
let handle_3 = cx.add_model(|_| Model);
@ -3330,7 +3337,7 @@ mod tests {
type Event = ();
}
let (window_id, _) = cx.add_window(|_| View);
let (window_id, _) = cx.add_window(Default::default(), |_| View);
let observing_view = cx.add_view(window_id, |_| View);
let emitting_view = cx.add_view(window_id, |_| View);
let observing_model = cx.add_model(|_| Model);
@ -3383,7 +3390,7 @@ mod tests {
type Event = ();
}
let (_, view) = cx.add_window(|_| View::default());
let (_, view) = cx.add_window(Default::default(), |_| View::default());
let model = cx.add_model(|_| Model::default());
view.update(cx, |_, c| {
@ -3423,7 +3430,7 @@ mod tests {
type Event = ();
}
let (window_id, _) = cx.add_window(|_| View);
let (window_id, _) = cx.add_window(Default::default(), |_| View);
let observing_view = cx.add_view(window_id, |_| View);
let observing_model = cx.add_model(|_| Model);
let observed_model = cx.add_model(|_| Model);
@ -3473,7 +3480,7 @@ mod tests {
}
let events: Arc<Mutex<Vec<String>>> = Default::default();
let (window_id, view_1) = cx.add_window(|_| View {
let (window_id, view_1) = cx.add_window(Default::default(), |_| View {
events: events.clone(),
name: "view 1".to_string(),
});
@ -3583,7 +3590,7 @@ mod tests {
actions_clone.borrow_mut().push(format!("{} d", view.id));
});
let (window_id, view_1) = cx.add_window(|_| ViewA { id: 1 });
let (window_id, view_1) = cx.add_window(Default::default(), |_| ViewA { id: 1 });
let view_2 = cx.add_view(window_id, |_| ViewB { id: 2 });
let view_3 = cx.add_view(window_id, |_| ViewA { id: 3 });
let view_4 = cx.add_view(window_id, |_| ViewB { id: 4 });
@ -3663,7 +3670,7 @@ mod tests {
view_2.keymap_context.set.insert("b".into());
view_3.keymap_context.set.insert("c".into());
let (window_id, view_1) = cx.add_window(|_| view_1);
let (window_id, view_1) = cx.add_window(Default::default(), |_| view_1);
let view_2 = cx.add_view(window_id, |_| view_2);
let view_3 = cx.add_view(window_id, |_| view_3);

View file

@ -92,12 +92,15 @@ pub trait Window: WindowContext {
pub trait WindowContext {
fn size(&self) -> Vector2F;
fn scale_factor(&self) -> f32;
fn titlebar_height(&self) -> f32;
fn present_scene(&mut self, scene: Scene);
}
#[derive(Default)]
pub struct WindowOptions<'a> {
pub bounds: RectF,
pub title: Option<&'a str>,
pub titlebar_appears_transparent: bool,
}
pub struct PathPromptOptions {

View file

@ -15,6 +15,7 @@ use cocoa::{
foundation::{NSAutoreleasePool, NSInteger, NSSize, NSString},
quartzcore::AutoresizingMask,
};
use core_graphics::display::CGRect;
use ctor::ctor;
use foreign_types::ForeignType as _;
use objc::{
@ -153,11 +154,15 @@ impl Window {
let pool = NSAutoreleasePool::new(nil);
let frame = options.bounds.to_ns_rect();
let style_mask = NSWindowStyleMask::NSClosableWindowMask
let mut style_mask = NSWindowStyleMask::NSClosableWindowMask
| NSWindowStyleMask::NSMiniaturizableWindowMask
| NSWindowStyleMask::NSResizableWindowMask
| NSWindowStyleMask::NSTitledWindowMask;
if options.titlebar_appears_transparent {
style_mask |= NSWindowStyleMask::NSFullSizeContentViewWindowMask;
}
let native_window: id = msg_send![WINDOW_CLASS, alloc];
let native_window = native_window.initWithContentRect_styleMask_backing_defer_(
frame,
@ -213,6 +218,9 @@ impl Window {
if let Some(title) = options.title.as_ref() {
native_window.setTitle_(NSString::alloc(nil).init_str(title));
}
if options.titlebar_appears_transparent {
native_window.setTitlebarAppearsTransparent_(YES);
}
native_window.setAcceptsMouseMovedEvents_(YES);
native_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
@ -329,6 +337,10 @@ impl platform::WindowContext for Window {
fn present_scene(&mut self, scene: Scene) {
self.0.as_ref().borrow_mut().present_scene(scene);
}
fn titlebar_height(&self) -> f32 {
self.0.as_ref().borrow().titlebar_height()
}
}
impl platform::WindowContext for WindowState {
@ -345,6 +357,14 @@ impl platform::WindowContext for WindowState {
}
}
fn titlebar_height(&self) -> f32 {
unsafe {
let frame = NSWindow::frame(self.native_window);
let content_layout_rect: CGRect = msg_send![self.native_window, contentLayoutRect];
(frame.size.height - content_layout_rect.size.height) as f32
}
}
fn present_scene(&mut self, scene: Scene) {
self.scene_to_render = Some(scene);
unsafe {

View file

@ -164,6 +164,10 @@ impl super::WindowContext for Window {
self.scale_factor
}
fn titlebar_height(&self) -> f32 {
24.
}
fn present_scene(&mut self, scene: crate::Scene) {
self.current_scene = Some(scene);
}

View file

@ -70,13 +70,14 @@ impl Presenter {
pub fn build_scene(
&mut self,
window_size: Vector2F,
titlebar_height: f32,
scale_factor: f32,
cx: &mut MutableAppContext,
) -> Scene {
let mut scene = Scene::new(scale_factor);
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
self.layout(window_size, cx);
self.layout(window_size, titlebar_height, cx);
self.after_layout(cx);
let mut paint_cx = PaintContext {
scene: &mut scene,
@ -98,7 +99,7 @@ impl Presenter {
scene
}
fn layout(&mut self, size: Vector2F, cx: &mut MutableAppContext) {
fn layout(&mut self, size: Vector2F, titlebar_height: f32, cx: &mut MutableAppContext) {
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
let mut layout_ctx = LayoutContext {
rendered_views: &mut self.rendered_views,
@ -108,6 +109,7 @@ impl Presenter {
asset_cache: &self.asset_cache,
view_stack: Vec::new(),
app: cx,
titlebar_height,
};
layout_ctx.layout(root_view_id, SizeConstraint::strict(size));
}
@ -186,6 +188,7 @@ pub struct LayoutContext<'a> {
pub asset_cache: &'a AssetCache,
pub app: &'a mut MutableAppContext,
view_stack: Vec<usize>,
pub titlebar_height: f32,
}
impl<'a> LayoutContext<'a> {

View file

@ -2659,7 +2659,9 @@ mod tests {
fn test_selection_with_mouse(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, editor) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, editor) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
editor.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(2, 2), false, cx);
@ -2725,7 +2727,9 @@ mod tests {
fn test_canceling_pending_selection(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(2, 2), false, cx);
@ -2757,7 +2761,9 @@ mod tests {
fn test_cancel(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(3, 4), false, cx);
@ -2801,8 +2807,9 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6), cx));
let settings = settings::channel(&font_cache).unwrap().1;
let (_, editor) =
cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings.clone(), cx));
let (_, editor) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings.clone(), cx)
});
let layouts = editor.update(cx, |editor, cx| {
editor
@ -2846,7 +2853,9 @@ mod tests {
)
});
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(8, 0)..DisplayPoint::new(12, 0)], cx)
@ -2912,7 +2921,9 @@ mod tests {
fn test_move_cursor(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6), cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
buffer.update(cx, |buffer, cx| {
buffer.edit(
@ -2987,7 +2998,9 @@ mod tests {
fn test_move_cursor_multibyte(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "ⓐⓑⓒⓓⓔ\nabcde\nαβγδε\n", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
assert_eq!('ⓐ'.len_utf8(), 3);
assert_eq!('α'.len_utf8(), 2);
@ -3043,7 +3056,9 @@ mod tests {
fn test_move_cursor_different_line_lengths(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "ⓐⓑⓒⓓⓔ\nabcd\nαβγ\nabcd\nⓐⓑⓒⓓⓔ\n", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(&[empty_range(0, "ⓐⓑⓒⓓⓔ".len())], cx)
.unwrap();
@ -3072,7 +3087,9 @@ mod tests {
fn test_beginning_end_of_line(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\n def", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3215,7 +3232,9 @@ mod tests {
let buffer =
cx.add_model(|cx| Buffer::new(0, "use std::str::{foo, bar}\n\n {baz.qux()}", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3401,7 +3420,9 @@ mod tests {
let buffer =
cx.add_model(|cx| Buffer::new(0, "use one::{\n two::three::four::five\n};", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.set_wrap_width(140., cx);
@ -3461,7 +3482,9 @@ mod tests {
)
});
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
@ -3495,7 +3518,9 @@ mod tests {
)
});
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
@ -3523,7 +3548,9 @@ mod tests {
fn test_delete_line(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndef\nghi\n", cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3547,7 +3574,9 @@ mod tests {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndef\nghi\n", cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(2, 0)..DisplayPoint::new(0, 1)], cx)
.unwrap();
@ -3564,7 +3593,9 @@ mod tests {
fn test_duplicate_line(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndef\nghi\n", cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3591,7 +3622,9 @@ mod tests {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndef\nghi\n", cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3617,7 +3650,9 @@ mod tests {
fn test_move_line_up_down(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(10, 5), cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.fold_ranges(
vec![
@ -3700,7 +3735,9 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, "one two three four five six ", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let view = cx
.add_window(|cx| Editor::for_buffer(buffer.clone(), settings, cx))
.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer.clone(), settings, cx)
})
.1;
// Cut with three selections. Clipboard text is divided into three slices.
@ -3832,7 +3869,9 @@ mod tests {
fn test_select_all(cx: &mut gpui::MutableAppContext) {
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\nde\nfgh", cx));
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_all(&(), cx);
assert_eq!(
@ -3846,7 +3885,9 @@ mod tests {
fn test_select_line(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(6, 5), cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@ -3892,7 +3933,9 @@ mod tests {
fn test_split_selection_into_lines(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(9, 5), cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.fold_ranges(
vec![
@ -3957,7 +4000,9 @@ mod tests {
fn test_add_selection_above_below(cx: &mut gpui::MutableAppContext) {
let settings = settings::channel(&cx.font_cache()).unwrap().1;
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndefghi\n\njk\nlmno\n", cx));
let (_, view) = cx.add_window(|cx| Editor::for_buffer(buffer, settings, cx));
let (_, view) = cx.add_window(Default::default(), |cx| {
Editor::for_buffer(buffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(1, 3)..DisplayPoint::new(1, 3)], cx)

View file

@ -12,9 +12,14 @@ use crate::{
};
use anyhow::{anyhow, Result};
use gpui::{
elements::*, json::to_string_pretty, keymap::Binding, AnyViewHandle, AppContext, ClipboardItem,
Entity, ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task,
View, ViewContext, ViewHandle, WeakModelHandle,
elements::*,
geometry::{rect::RectF, vector::vec2f},
json::to_string_pretty,
keymap::Binding,
platform::WindowOptions,
AnyViewHandle, AppContext, ClipboardItem, Entity, ModelHandle, MutableAppContext,
PathPromptOptions, PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle,
WeakModelHandle,
};
use log::error;
pub use pane::*;
@ -93,12 +98,14 @@ fn open_paths(params: &OpenParams, cx: &mut MutableAppContext) -> Task<()> {
log::info!("open new workspace");
// Add a new workspace if necessary
let (_, workspace) = cx.add_window(|cx| Workspace::new(&params.app_state, cx));
let (_, workspace) =
cx.add_window(window_options(), |cx| Workspace::new(&params.app_state, cx));
workspace.update(cx, |workspace, cx| workspace.open_paths(&params.paths, cx))
}
fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
cx.add_window(|cx| {
cx.add_window(window_options(), |cx| {
let mut view = Workspace::new(app_state.as_ref(), cx);
view.open_new_file(&app_state, cx);
view
@ -106,13 +113,21 @@ fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
}
fn join_worktree(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
cx.add_window(|cx| {
cx.add_window(window_options(), |cx| {
let mut view = Workspace::new(app_state.as_ref(), cx);
view.join_worktree(&(), cx);
view
});
}
fn window_options() -> WindowOptions<'static> {
WindowOptions {
bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)),
title: None,
titlebar_appears_transparent: true,
}
}
pub trait Item: Entity + Sized {
type View: ItemView;