Merge branch 'main' into implicit-ancestry

This commit is contained in:
Antonio Scandurra 2023-05-04 14:39:58 +02:00
commit da19edc3e3
33 changed files with 746 additions and 392 deletions

View file

@ -19,6 +19,7 @@ test-support = [
]
[dependencies]
assets = { path = "../assets" }
db = { path = "../db" }
call = { path = "../call" }
client = { path = "../client" }

View file

@ -1841,12 +1841,11 @@ impl View for Pane {
});
}
fn keymap_context(&self, _: &AppContext) -> KeymapContext {
let mut keymap = Self::default_keymap_context();
fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
Self::reset_to_default_keymap_context(keymap);
if self.docked.is_some() {
keymap.add_identifier("docked");
}
keymap
}
}

View file

@ -14,9 +14,8 @@ pub mod sidebar;
mod status_bar;
mod toolbar;
pub use smallvec;
use anyhow::{anyhow, Context, Result};
use assets::Assets;
use call::ActiveCall;
use client::{
proto::{self, PeerId},
@ -38,7 +37,6 @@ use gpui::{
vector::{vec2f, Vector2F},
},
impl_actions,
keymap_matcher::KeymapContext,
platform::{
CursorStyle, MouseButton, PathPromptOptions, Platform, PromptLevel, WindowBounds,
WindowOptions,
@ -48,13 +46,14 @@ use gpui::{
WindowContext,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use language::LanguageRegistry;
use language::{LanguageRegistry, Rope};
use std::{
any::TypeId,
borrow::Cow,
cmp, env,
future::Future,
path::{Path, PathBuf},
str,
sync::Arc,
time::Duration,
};
@ -83,7 +82,7 @@ use status_bar::StatusBar;
pub use status_bar::StatusItemView;
use theme::{Theme, ThemeRegistry};
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
use util::ResultExt;
use util::{paths, ResultExt};
lazy_static! {
static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")
@ -127,6 +126,8 @@ actions!(
]
);
actions!(zed, [OpenSettings]);
#[derive(Clone, PartialEq)]
pub struct OpenPaths {
pub paths: Vec<PathBuf>,
@ -266,6 +267,17 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
.detach();
});
cx.add_action(
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
create_and_open_local_file(&paths::SETTINGS, cx, || {
Settings::initial_user_settings_content(&Assets)
.as_ref()
.into()
})
.detach_and_log_err(cx);
},
);
let client = &app_state.client;
client.add_view_request_handler(Workspace::handle_follow);
client.add_view_message_handler(Workspace::handle_unfollow);
@ -2770,10 +2782,6 @@ impl View for Workspace {
cx.focus(&self.active_pane);
}
}
fn keymap_context(&self, _: &AppContext) -> KeymapContext {
Self::default_keymap_context()
}
}
impl ViewId {
@ -2929,6 +2937,33 @@ pub fn open_new(
})
}
pub fn create_and_open_local_file(
path: &'static Path,
cx: &mut ViewContext<Workspace>,
default_content: impl 'static + Send + FnOnce() -> Rope,
) -> Task<Result<Box<dyn ItemHandle>>> {
cx.spawn(|workspace, mut cx| async move {
let fs = workspace.read_with(&cx, |workspace, _| workspace.app_state().fs.clone())?;
if !fs.is_file(path).await {
fs.create_file(path, Default::default()).await?;
fs.save(path, &default_content(), Default::default())
.await?;
}
let mut items = workspace
.update(&mut cx, |workspace, cx| {
workspace.with_local_workspace(cx, |workspace, cx| {
workspace.open_paths(vec![path.to_path_buf()], false, cx)
})
})?
.await?
.await;
let item = items.pop().flatten();
item.ok_or_else(|| anyhow!("path {path:?} is not a file"))?
})
}
pub fn join_remote_project(
project_id: u64,
follow_user_id: u64,