use channel::channel_buffer::ChannelBuffer; use editor::Editor; use gpui::{ actions, elements::{ChildView, Label}, AnyElement, AppContext, Element, Entity, ModelHandle, View, ViewContext, ViewHandle, }; use language::Language; use std::sync::Arc; use workspace::item::{Item, ItemHandle}; actions!(channel_view, [Deploy]); pub(crate) fn init(cx: &mut AppContext) { // TODO } pub struct ChannelView { editor: ViewHandle, channel_buffer: ModelHandle, } impl ChannelView { pub fn new( channel_buffer: ModelHandle, language: Arc, cx: &mut ViewContext, ) -> Self { let buffer = channel_buffer.read(cx).buffer(); buffer.update(cx, |buffer, cx| buffer.set_language(Some(language), cx)); let editor = cx.add_view(|cx| Editor::for_buffer(buffer, None, cx)); Self { editor, channel_buffer, } } } impl Entity for ChannelView { type Event = editor::Event; } impl View for ChannelView { fn ui_name() -> &'static str { "ChannelView" } fn render(&mut self, cx: &mut ViewContext<'_, '_, Self>) -> AnyElement { ChildView::new(self.editor.as_any(), cx).into_any() } } impl Item for ChannelView { fn tab_content( &self, _: Option, style: &theme::Tab, cx: &gpui::AppContext, ) -> AnyElement { let channel_name = self .channel_buffer .read(cx) .channel(cx) .map_or("[Deleted channel]".to_string(), |channel| { format!("#{}", channel.name) }); Label::new(channel_name, style.label.to_owned()).into_any() } }