Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement add panel to root for DockArea #438

Closed
reyamir opened this issue Nov 27, 2024 · 4 comments
Closed

Implement add panel to root for DockArea #438

reyamir opened this issue Nov 27, 2024 · 4 comments

Comments

@reyamir
Copy link
Contributor

reyamir commented Nov 27, 2024

I've tried to implemented fn add_panel_to_root for DockArea, but the view is not reload after add panel. Do you know what I'm missing?

// DockArea
...
pub fn add_panel_to_root(&self, panel: Arc<dyn PanelView>, cx: &mut ViewContext<Self>) {
    if let DockItem::Tabs {
        items,
        active_ix,
        view,
    } = &self.items
    {
        view.update(cx, |view, cx| {
            view.add_panel(panel, cx);
            cx.notify();
        })
    }
}
...
@reyamir
Copy link
Contributor Author

reyamir commented Nov 27, 2024

I've updated my fn into this

pub fn add_panel_to_tabs(&self, panel: Arc<dyn PanelView>, cx: &mut ViewContext<Self>) {
    match self.items.clone() {
        DockItem::Tabs {
            mut items,
            mut active_ix,
            view,
        } => view.update(cx, |view, cx| {
            view.add_panel(panel.clone(), cx);
            items.push(panel);
            active_ix += 1;
            cx.notify();
        }),
        DockItem::Split { view, items, .. } => view.update(cx, |_, cx| {
            for item in items.into_iter() {
                if let DockItem::Tabs {
                    mut items,
                    mut active_ix,
                    view,
                } = item
                {
                    view.update(cx, |view, cx| {
                        view.add_panel(panel.clone(), cx);
                        items.push(panel.clone());
                        active_ix += 1;
                        cx.notify();
                    })
                }
            }
        }),
    }
}

and it worked now

@huacnlee
Copy link
Member

Do you still need my help? It looks like it's ready. I'm also going to open a branch to check the problem.

@reyamir
Copy link
Contributor Author

reyamir commented Nov 27, 2024

Ah, it seems work fine now. I will create a PR if you like, I think this fn is useful for #318 , user can create a sidebar then add new tab when user click to sidebar's component

@reyamir
Copy link
Contributor Author

reyamir commented Nov 27, 2024

Other things I wonder is do I need to push new panel to items vec here:

view.add_panel(panel, cx);
items.push(panel); <-

or just view.add_panel is enought for add new tab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants