Implement Selectable
for ListItem
and ListHeader
This commit is contained in:
parent
865baaa1a1
commit
e78538e162
8 changed files with 21 additions and 20 deletions
|
@ -11,7 +11,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
|
|
||||||
use ui::{h_stack, v_stack, HighlightedLabel, KeyBinding, ListItem};
|
use ui::{h_stack, prelude::*, v_stack, HighlightedLabel, KeyBinding, ListItem};
|
||||||
use util::{
|
use util::{
|
||||||
channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},
|
channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},
|
||||||
ResultExt,
|
ResultExt,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use text::Point;
|
use text::Point;
|
||||||
use ui::{v_stack, HighlightedLabel, ListItem};
|
use ui::{prelude::*, v_stack, HighlightedLabel, ListItem};
|
||||||
use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
|
use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme as _;
|
use ui::{prelude::*, v_stack, ContextMenu, IconElement, Label, ListItem};
|
||||||
use ui::{v_stack, ContextMenu, IconElement, Label, ListItem};
|
|
||||||
use unicase::UniCase;
|
use unicase::UniCase;
|
||||||
use util::{maybe, ResultExt, TryFutureExt};
|
use util::{maybe, ResultExt, TryFutureExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
|
@ -2845,7 +2844,7 @@ mod tests {
|
||||||
let worktree = worktree.read(cx);
|
let worktree = worktree.read(cx);
|
||||||
if let Ok(relative_path) = path.strip_prefix(worktree.root_name()) {
|
if let Ok(relative_path) = path.strip_prefix(worktree.root_name()) {
|
||||||
let entry_id = worktree.entry_for_path(relative_path).unwrap().id;
|
let entry_id = worktree.entry_for_path(relative_path).unwrap().id;
|
||||||
panel.selection = Some(Selection {
|
panel.selection = Some(crate::Selection {
|
||||||
worktree_id: worktree.id(),
|
worktree_id: worktree.id(),
|
||||||
entry_id,
|
entry_id,
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,14 +2,14 @@ use feature_flags::FeatureFlagAppExt;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render,
|
actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, SharedString, View,
|
||||||
SharedString, View, ViewContext, VisualContext, WeakView,
|
ViewContext, VisualContext, WeakView,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use settings::{update_settings_file, SettingsStore};
|
use settings::{update_settings_file, SettingsStore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme::{ActiveTheme, Theme, ThemeRegistry, ThemeSettings};
|
use theme::{Theme, ThemeRegistry, ThemeSettings};
|
||||||
use ui::ListItem;
|
use ui::{prelude::*, ListItem};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{ui::HighlightedLabel, Workspace};
|
use workspace::{ui::HighlightedLabel, Workspace};
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,10 @@ impl ListHeader {
|
||||||
self.meta = meta;
|
self.meta = meta;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn selected(mut self, selected: bool) -> Self {
|
impl Selectable for ListHeader {
|
||||||
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,11 +83,6 @@ impl ListItem {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected(mut self, selected: bool) -> Self {
|
|
||||||
self.selected = selected;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn left_child(mut self, left_content: impl IntoElement) -> Self {
|
pub fn left_child(mut self, left_content: impl IntoElement) -> Self {
|
||||||
self.left_slot = Some(left_content.into_any_element());
|
self.left_slot = Some(left_content.into_any_element());
|
||||||
self
|
self
|
||||||
|
@ -109,6 +104,13 @@ impl ListItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Selectable for ListItem {
|
||||||
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
|
self.selected = selected;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ParentElement for ListItem {
|
impl ParentElement for ListItem {
|
||||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
||||||
&mut self.children
|
&mut self.children
|
||||||
|
|
|
@ -18,7 +18,6 @@ mod disableable;
|
||||||
mod fixed;
|
mod fixed;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod selectable;
|
mod selectable;
|
||||||
mod slot;
|
|
||||||
mod styled_ext;
|
mod styled_ext;
|
||||||
mod styles;
|
mod styles;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
@ -29,6 +28,5 @@ pub use disableable::*;
|
||||||
pub use fixed::*;
|
pub use fixed::*;
|
||||||
pub use prelude::*;
|
pub use prelude::*;
|
||||||
pub use selectable::*;
|
pub use selectable::*;
|
||||||
pub use slot::*;
|
|
||||||
pub use styled_ext::*;
|
pub use styled_ext::*;
|
||||||
pub use styles::*;
|
pub use styles::*;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use super::base_keymap_setting::BaseKeymap;
|
use super::base_keymap_setting::BaseKeymap;
|
||||||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render, Task,
|
actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, Task, View,
|
||||||
View, ViewContext, VisualContext, WeakView,
|
ViewContext, VisualContext, WeakView,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use project::Fs;
|
use project::Fs;
|
||||||
use settings::{update_settings_file, Settings};
|
use settings::{update_settings_file, Settings};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ui::ListItem;
|
use ui::{prelude::*, ListItem};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{ui::HighlightedLabel, Workspace};
|
use workspace::{ui::HighlightedLabel, Workspace};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue