mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 19:10:24 +00:00
Add "New Window" command
This commit is contained in:
parent
c4fc3d9c7f
commit
e72f5cea22
6 changed files with 30 additions and 16 deletions
|
@ -20,7 +20,8 @@
|
|||
"cmd--": "zed::DecreaseBufferFontSize",
|
||||
"cmd-,": "zed::OpenSettings",
|
||||
"cmd-q": "zed::Quit",
|
||||
"cmd-n": "workspace::OpenNew",
|
||||
"cmd-n": "workspace::NewFile",
|
||||
"cmd-shift-N": "workspace::NewWindow",
|
||||
"cmd-o": "workspace::Open"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -216,7 +216,7 @@ pub enum Direction {
|
|||
}
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_action(Editor::open_new);
|
||||
cx.add_action(Editor::new_file);
|
||||
cx.add_action(|this: &mut Editor, action: &Scroll, cx| this.set_scroll_position(action.0, cx));
|
||||
cx.add_action(Editor::select);
|
||||
cx.add_action(Editor::cancel);
|
||||
|
@ -1002,9 +1002,9 @@ impl Editor {
|
|||
this
|
||||
}
|
||||
|
||||
pub fn open_new(
|
||||
pub fn new_file(
|
||||
workspace: &mut Workspace,
|
||||
_: &workspace::OpenNew,
|
||||
_: &workspace::NewFile,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let project = workspace.project().clone();
|
||||
|
|
|
@ -75,7 +75,8 @@ actions!(
|
|||
workspace,
|
||||
[
|
||||
Open,
|
||||
OpenNew,
|
||||
NewFile,
|
||||
NewWindow,
|
||||
Unfollow,
|
||||
Save,
|
||||
ActivatePreviousPane,
|
||||
|
@ -114,7 +115,15 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
|||
});
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &OpenNew, cx: &mut MutableAppContext| {
|
||||
move |_: &NewFile, cx: &mut MutableAppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx)
|
||||
}
|
||||
}
|
||||
});
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &NewWindow, cx: &mut MutableAppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx)
|
||||
}
|
||||
|
@ -2287,5 +2296,5 @@ fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
|
|||
(app_state.initialize_workspace)(&mut workspace, app_state, cx);
|
||||
workspace
|
||||
});
|
||||
cx.dispatch_action(window_id, vec![workspace.id()], &OpenNew);
|
||||
cx.dispatch_action(window_id, vec![workspace.id()], &NewFile);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ use std::{
|
|||
};
|
||||
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use util::{ResultExt, TryFutureExt};
|
||||
use workspace::{self, AppState, OpenNew, OpenPaths};
|
||||
use workspace::{self, AppState, NewFile, OpenPaths};
|
||||
use zed::{
|
||||
self, build_window_options,
|
||||
fs::RealFs,
|
||||
|
@ -206,7 +206,7 @@ fn main() {
|
|||
cx.platform().activate(true);
|
||||
let paths = collect_path_args();
|
||||
if paths.is_empty() {
|
||||
cx.dispatch_global_action(OpenNew);
|
||||
cx.dispatch_global_action(NewFile);
|
||||
} else {
|
||||
cx.dispatch_global_action(OpenPaths { paths });
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ fn main() {
|
|||
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
||||
.detach();
|
||||
} else {
|
||||
cx.dispatch_global_action(OpenNew);
|
||||
cx.dispatch_global_action(NewFile);
|
||||
}
|
||||
cx.spawn(|cx| async move {
|
||||
while let Some(connection) = cli_connections_rx.next().await {
|
||||
|
|
|
@ -31,7 +31,11 @@ pub fn menus() -> Vec<Menu<'static>> {
|
|||
items: vec![
|
||||
MenuItem::Action {
|
||||
name: "New",
|
||||
action: Box::new(workspace::OpenNew),
|
||||
action: Box::new(workspace::NewFile),
|
||||
},
|
||||
MenuItem::Action {
|
||||
name: "New Window",
|
||||
action: Box::new(workspace::NewWindow),
|
||||
},
|
||||
MenuItem::Separator,
|
||||
MenuItem::Action {
|
||||
|
|
|
@ -314,7 +314,7 @@ mod tests {
|
|||
};
|
||||
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use workspace::{
|
||||
open_paths, pane, Item, ItemHandle, OpenNew, Pane, SplitDirection, WorkspaceHandle,
|
||||
open_paths, pane, Item, ItemHandle, NewFile, Pane, SplitDirection, WorkspaceHandle,
|
||||
};
|
||||
|
||||
#[gpui::test]
|
||||
|
@ -376,7 +376,7 @@ mod tests {
|
|||
#[gpui::test]
|
||||
async fn test_new_empty_workspace(cx: &mut TestAppContext) {
|
||||
let app_state = init(cx);
|
||||
cx.dispatch_global_action(workspace::OpenNew);
|
||||
cx.dispatch_global_action(workspace::NewFile);
|
||||
let window_id = *cx.window_ids().first().unwrap();
|
||||
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
|
||||
let editor = workspace.update(cx, |workspace, cx| {
|
||||
|
@ -686,7 +686,7 @@ mod tests {
|
|||
let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());
|
||||
|
||||
// Create a new untitled buffer
|
||||
cx.dispatch_action(window_id, OpenNew);
|
||||
cx.dispatch_action(window_id, NewFile);
|
||||
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||
workspace
|
||||
.active_item(cx)
|
||||
|
@ -741,7 +741,7 @@ mod tests {
|
|||
|
||||
// Open the same newly-created file in another pane item. The new editor should reuse
|
||||
// the same buffer.
|
||||
cx.dispatch_action(window_id, OpenNew);
|
||||
cx.dispatch_action(window_id, NewFile);
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
|
||||
|
@ -774,7 +774,7 @@ mod tests {
|
|||
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(project, cx));
|
||||
|
||||
// Create a new untitled buffer
|
||||
cx.dispatch_action(window_id, OpenNew);
|
||||
cx.dispatch_action(window_id, NewFile);
|
||||
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||
workspace
|
||||
.active_item(cx)
|
||||
|
|
Loading…
Reference in a new issue