Re-activate the most recently-activated project search on cmd-shift-F
This commits adds the beginnings of an application state facility as a non-static place to store the most recently-activated search for each project. I also store workspace items by descending order of their entity id so that we always fetch the newest item of a given type when calling `Workspace::item_of_type`.
This commit is contained in:
parent
1ddae2adfd
commit
cb230ad574
4 changed files with 122 additions and 17 deletions
|
@ -9,7 +9,7 @@ mod status_bar;
|
|||
use anyhow::{anyhow, Result};
|
||||
use client::{Authenticate, ChannelList, Client, User, UserStore};
|
||||
use clock::ReplicaId;
|
||||
use collections::HashSet;
|
||||
use collections::BTreeMap;
|
||||
use gpui::{
|
||||
action,
|
||||
color::Color,
|
||||
|
@ -36,6 +36,7 @@ pub use status_bar::StatusItemView;
|
|||
use std::{
|
||||
any::{Any, TypeId},
|
||||
cell::RefCell,
|
||||
cmp::Reverse,
|
||||
future::Future,
|
||||
hash::{Hash, Hasher},
|
||||
path::{Path, PathBuf},
|
||||
|
@ -569,7 +570,7 @@ pub struct Workspace {
|
|||
status_bar: ViewHandle<StatusBar>,
|
||||
project: ModelHandle<Project>,
|
||||
path_openers: Arc<[Box<dyn PathOpener>]>,
|
||||
items: HashSet<Box<dyn WeakItemHandle>>,
|
||||
items: BTreeMap<Reverse<usize>, Box<dyn WeakItemHandle>>,
|
||||
_observe_current_user: Task<()>,
|
||||
}
|
||||
|
||||
|
@ -815,14 +816,14 @@ impl Workspace {
|
|||
|
||||
fn item_for_path(&self, path: &ProjectPath, cx: &AppContext) -> Option<Box<dyn ItemHandle>> {
|
||||
self.items
|
||||
.iter()
|
||||
.values()
|
||||
.filter_map(|i| i.upgrade(cx))
|
||||
.find(|i| i.project_path(cx).as_ref() == Some(path))
|
||||
}
|
||||
|
||||
pub fn item_of_type<T: Item>(&self, cx: &AppContext) -> Option<ModelHandle<T>> {
|
||||
self.items
|
||||
.iter()
|
||||
.values()
|
||||
.find_map(|i| i.upgrade(cx).and_then(|i| i.to_any().downcast()))
|
||||
}
|
||||
|
||||
|
@ -831,7 +832,7 @@ impl Workspace {
|
|||
cx: &'a AppContext,
|
||||
) -> impl 'a + Iterator<Item = ModelHandle<T>> {
|
||||
self.items
|
||||
.iter()
|
||||
.values()
|
||||
.filter_map(|i| i.upgrade(cx).and_then(|i| i.to_any().downcast()))
|
||||
}
|
||||
|
||||
|
@ -974,7 +975,8 @@ impl Workspace {
|
|||
where
|
||||
T: 'static + ItemHandle,
|
||||
{
|
||||
self.items.insert(item_handle.downgrade());
|
||||
self.items
|
||||
.insert(Reverse(item_handle.id()), item_handle.downgrade());
|
||||
pane.update(cx, |pane, cx| pane.open_item(item_handle, self, cx))
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1070,8 @@ impl Workspace {
|
|||
if let Some(item) = pane.read(cx).active_item() {
|
||||
let nav_history = new_pane.read(cx).nav_history().clone();
|
||||
if let Some(clone) = item.clone_on_split(nav_history, cx.as_mut()) {
|
||||
self.items.insert(clone.item(cx).downgrade());
|
||||
let item = clone.item(cx).downgrade();
|
||||
self.items.insert(Reverse(item.id()), item);
|
||||
new_pane.update(cx, |new_pane, cx| new_pane.add_item_view(clone, cx));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue