Add action to open release notes locally (#8173)

Fixes: https://github.com/zed-industries/zed/issues/5019

zed.dev PR: https://github.com/zed-industries/zed.dev/pull/562

I've been wanting to be able to open release notes in Zed for awhile,
but was blocked on having a rendered Markdown view. Now that that is
mostly there, I think we can add this. I have not removed the `auto
update: view release notes` action, since the Markdown render view
doesn't support displaying media yet. I've opted to just add a new
action: `auto update: view release notes locally`. I'd imagine that in
the future, once the rendered view supports media, we could remove `view
release notes` and `view release notes locally` could replace it.
Clicking the toast that normally is presented on update
(https://github.com/zed-industries/zed/issues/7597) would show the notes
locally.

The action works for stable and preview as expected; for dev and
nightly, it just pulls the latest stable, for testing purposes.

I changed the way the markdown rendered view works by allowing a tab
description to be passed in.

For files that have a name, it will use `Preview <name>`:

<img width="1496" alt="SCR-20240222-byyz"
src="https://github.com/zed-industries/zed/assets/19867440/a0ef34e5-bd6d-4b0c-a684-9b09d350aec4">

For untitled files, it defaults back to `Markdown preview`:

<img width="1496" alt="SCR-20240222-byip"
src="https://github.com/zed-industries/zed/assets/19867440/2ba3f336-6198-4dce-8867-cf0e45f2c646">

Release Notes:

- Added a `zed: view release notes locally` action
([#5019](https://github.com/zed-industries/zed/issues/5019)).


https://github.com/zed-industries/zed/assets/19867440/af324f9c-e7a4-4434-adff-7fe0f8ccc7ff
This commit is contained in:
Joseph T. Lyons 2024-02-22 02:20:06 -05:00 committed by GitHub
parent f930969411
commit 38c3a93f0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 115 additions and 13 deletions

View file

@ -6,7 +6,7 @@ use gpui::{
IntoElement, ListState, ParentElement, Render, Styled, View, ViewContext, WeakView,
};
use ui::prelude::*;
use workspace::item::Item;
use workspace::item::{Item, ItemHandle};
use workspace::Workspace;
use crate::{
@ -22,6 +22,7 @@ pub struct MarkdownPreviewView {
contents: ParsedMarkdown,
selected_block: usize,
list_state: ListState,
tab_description: String,
}
impl MarkdownPreviewView {
@ -34,8 +35,9 @@ impl MarkdownPreviewView {
if let Some(editor) = workspace.active_item_as::<Editor>(cx) {
let workspace_handle = workspace.weak_handle();
let tab_description = editor.tab_description(0, cx);
let view: View<MarkdownPreviewView> =
MarkdownPreviewView::new(editor, workspace_handle, cx);
MarkdownPreviewView::new(editor, workspace_handle, tab_description, cx);
workspace.split_item(workspace::SplitDirection::Right, Box::new(view.clone()), cx);
cx.notify();
}
@ -45,6 +47,7 @@ impl MarkdownPreviewView {
pub fn new(
active_editor: View<Editor>,
workspace: WeakView<Workspace>,
tab_description: Option<SharedString>,
cx: &mut ViewContext<Workspace>,
) -> View<Self> {
cx.new_view(|cx: &mut ViewContext<Self>| {
@ -119,12 +122,17 @@ impl MarkdownPreviewView {
},
);
let tab_description = tab_description
.map(|tab_description| format!("Preview {}", tab_description))
.unwrap_or("Markdown preview".to_string());
Self {
selected_block: 0,
focus_handle: cx.focus_handle(),
workspace,
contents,
list_state,
tab_description: tab_description.into(),
}
})
}
@ -188,11 +196,13 @@ impl Item for MarkdownPreviewView {
} else {
Color::Muted
}))
.child(Label::new("Markdown preview").color(if selected {
Color::Default
} else {
Color::Muted
}))
.child(
Label::new(self.tab_description.to_string()).color(if selected {
Color::Default
} else {
Color::Muted
}),
)
.into_any()
}