mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-10 20:29:05 +00:00
Add Zed > Preferences > Local Settings to application menu
This commit is contained in:
parent
0949ee84d8
commit
cb975f1252
2 changed files with 55 additions and 1 deletions
|
@ -16,6 +16,7 @@ pub fn menus() -> Vec<Menu<'static>> {
|
||||||
MenuItem::action("Open Key Bindings", super::OpenKeymap),
|
MenuItem::action("Open Key Bindings", super::OpenKeymap),
|
||||||
MenuItem::action("Open Default Settings", super::OpenDefaultSettings),
|
MenuItem::action("Open Default Settings", super::OpenDefaultSettings),
|
||||||
MenuItem::action("Open Default Key Bindings", super::OpenDefaultKeymap),
|
MenuItem::action("Open Default Key Bindings", super::OpenDefaultKeymap),
|
||||||
|
MenuItem::action("Open Local Settings", super::OpenLocalSettings),
|
||||||
MenuItem::action("Select Theme", theme_selector::Toggle),
|
MenuItem::action("Select Theme", theme_selector::Toggle),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -33,7 +33,11 @@ use serde_json::to_string_pretty;
|
||||||
use settings::{KeymapFileContent, SettingsStore, DEFAULT_SETTINGS_ASSET_PATH};
|
use settings::{KeymapFileContent, SettingsStore, DEFAULT_SETTINGS_ASSET_PATH};
|
||||||
use std::{borrow::Cow, str, sync::Arc};
|
use std::{borrow::Cow, str, sync::Arc};
|
||||||
use terminal_view::terminal_panel::{self, TerminalPanel};
|
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||||
use util::{channel::ReleaseChannel, paths, ResultExt};
|
use util::{
|
||||||
|
channel::ReleaseChannel,
|
||||||
|
paths::{self, LOCAL_SETTINGS_RELATIVE_PATH},
|
||||||
|
ResultExt,
|
||||||
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use welcome::BaseKeymap;
|
use welcome::BaseKeymap;
|
||||||
pub use workspace;
|
pub use workspace;
|
||||||
|
@ -66,6 +70,7 @@ actions!(
|
||||||
OpenTelemetryLog,
|
OpenTelemetryLog,
|
||||||
OpenKeymap,
|
OpenKeymap,
|
||||||
OpenSettings,
|
OpenSettings,
|
||||||
|
OpenLocalSettings,
|
||||||
OpenDefaultSettings,
|
OpenDefaultSettings,
|
||||||
OpenDefaultKeymap,
|
OpenDefaultKeymap,
|
||||||
IncreaseBufferFontSize,
|
IncreaseBufferFontSize,
|
||||||
|
@ -168,6 +173,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
cx.add_action(open_local_settings_file);
|
||||||
cx.add_action(
|
cx.add_action(
|
||||||
move |workspace: &mut Workspace, _: &OpenDefaultKeymap, cx: &mut ViewContext<Workspace>| {
|
move |workspace: &mut Workspace, _: &OpenDefaultKeymap, cx: &mut ViewContext<Workspace>| {
|
||||||
open_bundled_file(
|
open_bundled_file(
|
||||||
|
@ -555,6 +561,53 @@ pub fn handle_keymap_file_changes(
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_local_settings_file(
|
||||||
|
workspace: &mut Workspace,
|
||||||
|
_: &OpenLocalSettings,
|
||||||
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
) {
|
||||||
|
let project = workspace.project().clone();
|
||||||
|
let worktree = project
|
||||||
|
.read(cx)
|
||||||
|
.visible_worktrees(cx)
|
||||||
|
.find_map(|tree| tree.read(cx).root_entry()?.is_dir().then_some(tree));
|
||||||
|
if let Some(worktree) = worktree {
|
||||||
|
let tree_id = worktree.read(cx).id();
|
||||||
|
cx.spawn(|workspace, mut cx| async move {
|
||||||
|
let file_path = &*LOCAL_SETTINGS_RELATIVE_PATH;
|
||||||
|
|
||||||
|
if let Some(dir_path) = file_path.parent() {
|
||||||
|
if worktree.read_with(&cx, |tree, _| tree.entry_for_path(dir_path).is_none()) {
|
||||||
|
project
|
||||||
|
.update(&mut cx, |project, cx| {
|
||||||
|
project.create_entry((tree_id, dir_path), true, cx)
|
||||||
|
})
|
||||||
|
.ok_or_else(|| anyhow!("worktree was removed"))?
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if worktree.read_with(&cx, |tree, _| tree.entry_for_path(file_path).is_none()) {
|
||||||
|
project
|
||||||
|
.update(&mut cx, |project, cx| {
|
||||||
|
project.create_entry((tree_id, file_path), false, cx)
|
||||||
|
})
|
||||||
|
.ok_or_else(|| anyhow!("worktree was removed"))?
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
workspace
|
||||||
|
.update(&mut cx, |workspace, cx| {
|
||||||
|
workspace.open_path((tree_id, file_path), None, true, cx)
|
||||||
|
})?
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
anyhow::Ok(())
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||||
workspace.with_local_workspace(cx, move |workspace, cx| {
|
workspace.with_local_workspace(cx, move |workspace, cx| {
|
||||||
let app_state = workspace.app_state().clone();
|
let app_state = workspace.app_state().clone();
|
||||||
|
|
Loading…
Reference in a new issue