Avoid adding the same entry when concurrently opening it more than once

This commit is contained in:
Antonio Scandurra
2021-07-08 14:40:32 +02:00
parent f46c0a790e
commit f55718cd18
2 changed files with 83 additions and 58 deletions
+15 -1
View File
@@ -5,7 +5,7 @@ use gpui::{
elements::*,
geometry::{rect::RectF, vector::vec2f},
keymap::Binding,
AppContext, Border, Entity, MutableAppContext, Quad, View, ViewContext,
AppContext, Border, Entity, MutableAppContext, Quad, View, ViewContext, ViewHandle,
};
use postage::watch;
use std::{cmp, path::Path, sync::Arc};
@@ -382,3 +382,17 @@ impl View for Pane {
self.focus_active_item(cx);
}
}
pub trait PaneHandle {
fn add_item_view(&self, item: Box<dyn ItemViewHandle>, cx: &mut MutableAppContext);
}
impl PaneHandle for ViewHandle<Pane> {
fn add_item_view(&self, item: Box<dyn ItemViewHandle>, cx: &mut MutableAppContext) {
item.set_parent_pane(self, cx);
self.update(cx, |pane, cx| {
let item_idx = pane.add_item(item, cx);
pane.activate_item(item_idx, cx);
});
}
}