Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions crates/repl/src/notebook/notebook_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use language::{Language, LanguageRegistry};
use log;
use project::{Project, ProjectEntryId, ProjectPath};
use settings::Settings as _;
use ui::{CommonAnimationExt, Tooltip, prelude::*};
use ui::{CommonAnimationExt, KeyBinding, Tooltip, prelude::*};
use workspace::item::{ItemEvent, SaveOptions, TabContentParams};
use workspace::searchable::SearchableItemHandle;
use workspace::{Item, ItemHandle, Pane, ProjectItem, ToolbarItemLocation};
Expand Down Expand Up @@ -1276,6 +1276,44 @@ impl NotebookEditor {
.size_full()
}

fn render_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.size_full()
.items_center()
.justify_center()
.gap_3()
.child(Label::new("This notebook is empty.").color(Color::Muted))
.child(
h_flex()
.gap_2()
.child(
Button::new("empty-state-add-code", "Add code cell")
.start_icon(Icon::new(IconName::Code))
.key_binding(KeyBinding::for_action_in(
&AddCodeBlock,
&self.focus_handle,
cx,
))
.on_click(
cx.listener(|this, _, window, cx| this.add_code_block(window, cx)),
),
)
.child(
Button::new("empty-state-add-markdown", "Add markdown cell")
.style(ButtonStyle::Subtle)
.start_icon(Icon::new(IconName::FileMarkdown))
.key_binding(KeyBinding::for_action_in(
&AddMarkdownBlock,
&self.focus_handle,
cx,
))
.on_click(cx.listener(|this, _, window, cx| {
this.add_markdown_block(window, cx)
})),
),
)
}

fn cell_position(&self, index: usize) -> CellPosition {
match index {
0 => CellPosition::First,
Expand Down Expand Up @@ -1475,7 +1513,16 @@ impl Render for NotebookEditor {
.w_full()
.h_full()
.gap_2()
.child(div().flex_1().h_full().child(self.cell_list(window, cx)))
.child(
div()
.flex_1()
.h_full()
.child(if self.cell_order.is_empty() {
self.render_empty_state(cx).into_any_element()
} else {
self.cell_list(window, cx).into_any_element()
}),
)
.child(self.render_notebook_controls(window, cx)),
)
.child(self.render_kernel_status_bar(window, cx))
Expand Down
Loading