zed2.rs

  1#![allow(unused_variables, dead_code, unused_mut)]
  2// todo!() this is to make transition easier.
  3
  4mod assets;
  5pub mod languages;
  6mod only_instance;
  7mod open_listener;
  8
  9pub use assets::*;
 10use gpui::{
 11    point, px, AppContext, AsyncWindowContext, Task, TitlebarOptions, WeakView, WindowBounds,
 12    WindowKind, WindowOptions,
 13};
 14pub use only_instance::*;
 15pub use open_listener::*;
 16
 17use anyhow::Result;
 18use project_panel::ProjectPanel;
 19use std::sync::Arc;
 20use uuid::Uuid;
 21use workspace::{dock::PanelHandle as _, AppState, Workspace};
 22
 23pub fn build_window_options(
 24    bounds: Option<WindowBounds>,
 25    display_uuid: Option<Uuid>,
 26    cx: &mut AppContext,
 27) -> WindowOptions {
 28    let bounds = bounds.unwrap_or(WindowBounds::Maximized);
 29    let display = display_uuid.and_then(|uuid| {
 30        cx.displays()
 31            .into_iter()
 32            .find(|display| display.uuid().ok() == Some(uuid))
 33    });
 34
 35    WindowOptions {
 36        bounds,
 37        titlebar: Some(TitlebarOptions {
 38            title: None,
 39            appears_transparent: true,
 40            traffic_light_position: Some(point(px(8.), px(8.))),
 41        }),
 42        center: false,
 43        focus: false,
 44        show: false,
 45        kind: WindowKind::Normal,
 46        is_movable: true,
 47        display_id: display.map(|display| display.id()),
 48    }
 49}
 50
 51pub fn initialize_workspace(
 52    workspace_handle: WeakView<Workspace>,
 53    was_deserialized: bool,
 54    app_state: Arc<AppState>,
 55    cx: AsyncWindowContext,
 56) -> Task<Result<()>> {
 57    cx.spawn(|mut cx| async move {
 58        workspace_handle.update(&mut cx, |workspace, cx| {
 59            let workspace_handle = cx.view();
 60            cx.subscribe(&workspace_handle, {
 61                move |workspace, _, event, cx| {
 62                    if let workspace::Event::PaneAdded(pane) = event {
 63                        pane.update(cx, |pane, cx| {
 64                            pane.toolbar().update(cx, |toolbar, cx| {
 65                                // todo!()
 66                                //     let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
 67                                //     toolbar.add_item(breadcrumbs, cx);
 68                                //     let buffer_search_bar = cx.add_view(BufferSearchBar::new);
 69                                //     toolbar.add_item(buffer_search_bar.clone(), cx);
 70                                //     let quick_action_bar = cx.add_view(|_| {
 71                                //         QuickActionBar::new(buffer_search_bar, workspace)
 72                                //     });
 73                                //     toolbar.add_item(quick_action_bar, cx);
 74                                //     let diagnostic_editor_controls =
 75                                //         cx.add_view(|_| diagnostics2::ToolbarControls::new());
 76                                //     toolbar.add_item(diagnostic_editor_controls, cx);
 77                                //     let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
 78                                //     toolbar.add_item(project_search_bar, cx);
 79                                //     let submit_feedback_button =
 80                                //         cx.add_view(|_| SubmitFeedbackButton::new());
 81                                //     toolbar.add_item(submit_feedback_button, cx);
 82                                //     let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new());
 83                                //     toolbar.add_item(feedback_info_text, cx);
 84                                //     let lsp_log_item =
 85                                //         cx.add_view(|_| language_tools::LspLogToolbarItemView::new());
 86                                //     toolbar.add_item(lsp_log_item, cx);
 87                                //     let syntax_tree_item = cx
 88                                //         .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new());
 89                                //     toolbar.add_item(syntax_tree_item, cx);
 90                            })
 91                        });
 92                    }
 93                }
 94            })
 95            .detach();
 96
 97            //     cx.emit(workspace2::Event::PaneAdded(
 98            //         workspace.active_pane().clone(),
 99            //     ));
100
101            //     let collab_titlebar_item =
102            //         cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx));
103            //     workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
104
105            //     let copilot =
106            //         cx.add_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx));
107            //     let diagnostic_summary =
108            //         cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx));
109            //     let activity_indicator = activity_indicator::ActivityIndicator::new(
110            //         workspace,
111            //         app_state.languages.clone(),
112            //         cx,
113            //     );
114            //     let active_buffer_language =
115            //         cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace));
116            //     let vim_mode_indicator = cx.add_view(|cx| vim::ModeIndicator::new(cx));
117            //     let feedback_button = cx.add_view(|_| {
118            //         feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)
119            //     });
120            //     let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
121            workspace.status_bar().update(cx, |status_bar, cx| {
122                // status_bar.add_left_item(diagnostic_summary, cx);
123                // status_bar.add_left_item(activity_indicator, cx);
124
125                // status_bar.add_right_item(feedback_button, cx);
126                // status_bar.add_right_item(copilot, cx);
127                // status_bar.add_right_item(active_buffer_language, cx);
128                // status_bar.add_right_item(vim_mode_indicator, cx);
129                // status_bar.add_right_item(cursor_position, cx);
130            });
131
132            //     auto_update::notify_of_any_new_update(cx.weak_handle(), cx);
133
134            //     vim::observe_keystrokes(cx);
135
136            //     cx.on_window_should_close(|workspace, cx| {
137            //         if let Some(task) = workspace.close(&Default::default(), cx) {
138            //             task.detach_and_log_err(cx);
139            //         }
140            //         false
141            //     });
142        })?;
143
144        let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
145        // let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone());
146        // let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone());
147        // let channels_panel =
148        //     collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
149        // let chat_panel =
150        //     collab_ui::chat_panel::ChatPanel::load(workspace_handle.clone(), cx.clone());
151        // let notification_panel = collab_ui::notification_panel::NotificationPanel::load(
152        //     workspace_handle.clone(),
153        //     cx.clone(),
154        // );
155        let (
156            project_panel,
157            //     terminal_panel,
158            //     assistant_panel,
159            //     channels_panel,
160            //     chat_panel,
161            //     notification_panel,
162        ) = futures::try_join!(
163            project_panel,
164            //     terminal_panel,
165            //     assistant_panel,
166            //     channels_panel,
167            //     chat_panel,
168            //     notification_panel,
169        )?;
170
171        workspace_handle.update(&mut cx, |workspace, cx| {
172            let project_panel_position = project_panel.position(cx);
173            workspace.add_panel(project_panel, cx);
174            //     workspace.add_panel(terminal_panel, cx);
175            //     workspace.add_panel(assistant_panel, cx);
176            //     workspace.add_panel(channels_panel, cx);
177            //     workspace.add_panel(chat_panel, cx);
178            //     workspace.add_panel(notification_panel, cx);
179
180            //     if !was_deserialized
181            //         && workspace
182            //             .project()
183            //             .read(cx)
184            //             .visible_worktrees(cx)
185            //             .any(|tree| {
186            //                 tree.read(cx)
187            //                     .root_entry()
188            //                     .map_or(false, |entry| entry.is_dir())
189            //             })
190            //     {
191            workspace.toggle_dock(project_panel_position, cx);
192            //     }
193            // cx.focus_self();
194        })?;
195        Ok(())
196    })
197}