chore(clippy): tab.rs
This commit is contained in:
parent
bd592e3e4e
commit
f1a9befec1
1 changed files with 272 additions and 309 deletions
581
src/tab.rs
581
src/tab.rs
|
|
@ -83,8 +83,8 @@ const MAX_SEARCH_RESULTS: usize = 200;
|
||||||
const THUMBNAIL_SIZE: u32 = (ICON_SIZE_GRID as u32) * (ICON_SCALE_MAX as u32);
|
const THUMBNAIL_SIZE: u32 = (ICON_SIZE_GRID as u32) * (ICON_SCALE_MAX as u32);
|
||||||
|
|
||||||
//TODO: adjust for locales?
|
//TODO: adjust for locales?
|
||||||
const DATE_TIME_FORMAT: &'static str = "%b %-d, %-Y, %-I:%M %p";
|
const DATE_TIME_FORMAT: &str = "%b %-d, %-Y, %-I:%M %p";
|
||||||
const TIME_FORMAT: &'static str = "%-I:%M %p";
|
const TIME_FORMAT: &str = "%-I:%M %p";
|
||||||
static SPECIAL_DIRS: Lazy<HashMap<PathBuf, &'static str>> = Lazy::new(|| {
|
static SPECIAL_DIRS: Lazy<HashMap<PathBuf, &'static str>> = Lazy::new(|| {
|
||||||
let mut special_dirs = HashMap::new();
|
let mut special_dirs = HashMap::new();
|
||||||
if let Some(dir) = dirs::document_dir() {
|
if let Some(dir) = dirs::document_dir() {
|
||||||
|
|
@ -293,7 +293,7 @@ enum PermissionOwner {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_permissions_owner(metadata: &Metadata, owner: PermissionOwner) -> String {
|
fn format_permissions_owner(metadata: &Metadata, owner: PermissionOwner) -> String {
|
||||||
return match owner {
|
match owner {
|
||||||
PermissionOwner::Owner => get_user_by_uid(metadata.uid())
|
PermissionOwner::Owner => get_user_by_uid(metadata.uid())
|
||||||
.and_then(|user| user.name().to_str().map(ToOwned::to_owned))
|
.and_then(|user| user.name().to_str().map(ToOwned::to_owned))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
|
@ -301,7 +301,7 @@ fn format_permissions_owner(metadata: &Metadata, owner: PermissionOwner) -> Stri
|
||||||
.and_then(|group| group.name().to_str().map(ToOwned::to_owned))
|
.and_then(|group| group.name().to_str().map(ToOwned::to_owned))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
PermissionOwner::Other => String::from(""),
|
PermissionOwner::Other => String::from(""),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_permissions(metadata: &Metadata, owner: PermissionOwner) -> String {
|
fn format_permissions(metadata: &Metadata, owner: PermissionOwner) -> String {
|
||||||
|
|
@ -570,11 +570,7 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
|
||||||
_ => LANGUAGE_SORTER.compare(&a.display_name, &b.display_name),
|
_ => LANGUAGE_SORTER.compare(&a.display_name, &b.display_name),
|
||||||
});
|
});
|
||||||
items.iter_mut().for_each(|item| {
|
items.iter_mut().for_each(|item| {
|
||||||
if hidden_files
|
if hidden_files.iter().any(|hidden| &item.name == hidden) {
|
||||||
.iter()
|
|
||||||
.find(|hidden| &&item.name == hidden)
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
item.hidden = true;
|
item.hidden = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -591,7 +587,7 @@ pub fn scan_search<F: Fn(&Path, &str, Metadata) -> bool + Sync>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern = regex::escape(&term);
|
let pattern = regex::escape(term);
|
||||||
let regex = match regex::RegexBuilder::new(&pattern)
|
let regex = match regex::RegexBuilder::new(&pattern)
|
||||||
.case_insensitive(true)
|
.case_insensitive(true)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -741,12 +737,7 @@ pub fn scan_trash(sizes: IconSizes) -> Vec<Item> {
|
||||||
|
|
||||||
fn uri_to_path(uri: String) -> Option<PathBuf> {
|
fn uri_to_path(uri: String) -> Option<PathBuf> {
|
||||||
//TODO support for external drive or cloud?
|
//TODO support for external drive or cloud?
|
||||||
if uri.starts_with("file://") {
|
uri.strip_prefix("file://").map(PathBuf::from)
|
||||||
let path_str = &uri[7..];
|
|
||||||
Some(PathBuf::from(path_str))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
|
pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
|
||||||
|
|
@ -768,28 +759,27 @@ pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
|
||||||
Ok(last_visit) => last_visit,
|
Ok(last_visit) => last_visit,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
let path_buf = PathBuf::from(path);
|
let path_exist = path.exists();
|
||||||
let path_exist = path_buf.exists();
|
|
||||||
|
|
||||||
if path_exist {
|
if path_exist {
|
||||||
let file_name = path_buf.file_name();
|
let file_name = path.file_name();
|
||||||
|
|
||||||
if let Some(name) = file_name {
|
if let Some(name) = file_name {
|
||||||
let name = name.to_string_lossy().to_string();
|
let name = name.to_string_lossy().to_string();
|
||||||
|
|
||||||
let metadata = match path_buf.metadata() {
|
let metadata = match path.metadata() {
|
||||||
Ok(ok) => ok,
|
Ok(ok) => ok,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"failed to read metadata for entry at {:?}: {}",
|
"failed to read metadata for entry at {:?}: {}",
|
||||||
path_buf.clone(),
|
path,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let item = item_from_entry(path_buf, name, metadata, sizes);
|
let item = item_from_entry(path, name, metadata, sizes);
|
||||||
recents.push((
|
recents.push((
|
||||||
item,
|
item,
|
||||||
if last_edit.le(&last_visit) {
|
if last_edit.le(&last_visit) {
|
||||||
|
|
@ -800,7 +790,7 @@ pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("recent file path not exist: {:?}", path_buf);
|
log::warn!("recent file path not exist: {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -941,9 +931,9 @@ impl std::fmt::Display for Location {
|
||||||
impl Location {
|
impl Location {
|
||||||
pub fn path_opt(&self) -> Option<&PathBuf> {
|
pub fn path_opt(&self) -> Option<&PathBuf> {
|
||||||
match self {
|
match self {
|
||||||
Self::Desktop(path, ..) => Some(&path),
|
Self::Desktop(path, ..) => Some(path),
|
||||||
Self::Path(path) => Some(&path),
|
Self::Path(path) => Some(path),
|
||||||
Self::Search(path, ..) => Some(&path),
|
Self::Search(path, ..) => Some(path),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1195,7 +1185,7 @@ impl ItemThumbnail {
|
||||||
&& check_size("svg", 8 * 1000 * 1000)
|
&& check_size("svg", 8 * 1000 * 1000)
|
||||||
{
|
{
|
||||||
// Try built-in svg thumbnailer
|
// Try built-in svg thumbnailer
|
||||||
match fs::read(&path) {
|
match fs::read(path) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
//TODO: validate SVG data
|
//TODO: validate SVG data
|
||||||
return ItemThumbnail::Svg(widget::svg::Handle::from_memory(data));
|
return ItemThumbnail::Svg(widget::svg::Handle::from_memory(data));
|
||||||
|
|
@ -1206,7 +1196,7 @@ impl ItemThumbnail {
|
||||||
}
|
}
|
||||||
} else if mime.type_() == mime::IMAGE && check_size("image", 64 * 1000 * 1000) {
|
} else if mime.type_() == mime::IMAGE && check_size("image", 64 * 1000 * 1000) {
|
||||||
// Try built-in image thumbnailer
|
// Try built-in image thumbnailer
|
||||||
match image::ImageReader::open(&path).and_then(|img| img.with_guessed_format()) {
|
match image::ImageReader::open(path).and_then(|img| img.with_guessed_format()) {
|
||||||
Ok(reader) => match reader.decode() {
|
Ok(reader) => match reader.decode() {
|
||||||
Ok(image) => {
|
Ok(image) => {
|
||||||
let thumbnail =
|
let thumbnail =
|
||||||
|
|
@ -1261,7 +1251,7 @@ impl ItemThumbnail {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(mut command) = thumbnailer.command(&path, file.path(), thumbnail_size) else {
|
let Some(mut command) = thumbnailer.command(path, file.path(), thumbnail_size) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
match command.status() {
|
match command.status() {
|
||||||
|
|
@ -1338,7 +1328,7 @@ impl Item {
|
||||||
self.mime.type_() == mime::IMAGE || self.mime.type_() == mime::TEXT
|
self.mime.type_() == mime::IMAGE || self.mime.type_() == mime::TEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview<'a>(&'a self, sizes: IconSizes) -> Element<'a, Message> {
|
fn preview(&self, sizes: IconSizes) -> Element<'_, Message> {
|
||||||
let spacing = cosmic::theme::active().cosmic().spacing;
|
let spacing = cosmic::theme::active().cosmic().spacing;
|
||||||
// This loads the image only if thumbnailing worked
|
// This loads the image only if thumbnailing worked
|
||||||
let icon = widget::icon::icon(self.icon_handle_grid.clone())
|
let icon = widget::icon::icon(self.icon_handle_grid.clone())
|
||||||
|
|
@ -1513,15 +1503,12 @@ impl Item {
|
||||||
//TODO: other metadata types
|
//TODO: other metadata types
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match self
|
if let ItemThumbnail::Image(_, Some((width, height))) = self
|
||||||
.thumbnail_opt
|
.thumbnail_opt
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(&ItemThumbnail::NotImage)
|
.unwrap_or(&ItemThumbnail::NotImage)
|
||||||
{
|
{
|
||||||
ItemThumbnail::Image(_, Some((width, height))) => {
|
details = details.push(widget::text::body(format!("{}x{}", width, height)));
|
||||||
details = details.push(widget::text::body(format!("{}x{}", width, height)));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
column = column.push(details);
|
column = column.push(details);
|
||||||
|
|
||||||
|
|
@ -1543,7 +1530,7 @@ impl Item {
|
||||||
column.into()
|
column.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_view<'a>(&'a self, heading: String, sizes: IconSizes) -> Element<'a, Message> {
|
pub fn replace_view(&self, heading: String, sizes: IconSizes) -> Element<'_, Message> {
|
||||||
let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing;
|
let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing;
|
||||||
|
|
||||||
let mut row = widget::row().spacing(space_xxxs);
|
let mut row = widget::row().spacing(space_xxxs);
|
||||||
|
|
@ -1727,18 +1714,14 @@ fn parse_hidden_file(path: &PathBuf) -> Vec<String> {
|
||||||
Err(_) => return Vec::new(),
|
Err(_) => return Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let reader = BufReader::new(file);
|
BufReader::new(file)
|
||||||
let mut paths: Vec<String> = Vec::new();
|
.lines()
|
||||||
|
.map_while(Result::ok)
|
||||||
for line in reader.lines() {
|
.flat_map(|line| {
|
||||||
if let Ok(line) = line {
|
let line = line.trim();
|
||||||
if !line.is_empty() {
|
(!line.is_empty()).then_some(line.to_owned())
|
||||||
paths.push(line.trim().to_string());
|
})
|
||||||
}
|
.collect()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
paths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
|
|
@ -2021,15 +2004,11 @@ impl Tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
first = Some(match first {
|
first = Some(match first {
|
||||||
Some((first_row, first_col)) => {
|
Some((first_row, first_col)) => match row.cmp(&first_row) {
|
||||||
if row < first_row {
|
Ordering::Less => (row, col),
|
||||||
(row, col)
|
Ordering::Equal => (row, col.min(first_row)),
|
||||||
} else if row == first_row {
|
Ordering::Greater => (first_row, first_col),
|
||||||
(row, col.min(first_row))
|
},
|
||||||
} else {
|
|
||||||
(first_row, first_col)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => (row, col),
|
None => (row, col),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -2050,15 +2029,11 @@ impl Tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
last = Some(match last {
|
last = Some(match last {
|
||||||
Some((last_row, last_col)) => {
|
Some((last_row, last_col)) => match row.cmp(&last_row) {
|
||||||
if row > last_row {
|
Ordering::Greater => (row, col),
|
||||||
(row, col)
|
Ordering::Equal => (row, col.max(last_row)),
|
||||||
} else if row == last_row {
|
Ordering::Less => (last_row, last_col),
|
||||||
(row, col.max(last_row))
|
},
|
||||||
} else {
|
|
||||||
(last_row, last_col)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => (row, col),
|
None => (row, col),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -2133,12 +2108,10 @@ impl Tab {
|
||||||
if let Some(location) = &clicked_item.location_opt {
|
if let Some(location) = &clicked_item.location_opt {
|
||||||
if clicked_item.metadata.is_dir() {
|
if clicked_item.metadata.is_dir() {
|
||||||
cd = Some(location.clone());
|
cd = Some(location.clone());
|
||||||
|
} else if let Some(path) = location.path_opt() {
|
||||||
|
commands.push(Command::OpenFile(path.to_path_buf()));
|
||||||
} else {
|
} else {
|
||||||
if let Some(path) = location.path_opt() {
|
log::warn!("no path for item {:?}", clicked_item);
|
||||||
commands.push(Command::OpenFile(path.to_path_buf()));
|
|
||||||
} else {
|
|
||||||
log::warn!("no path for item {:?}", clicked_item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("no location for item {:?}", clicked_item);
|
log::warn!("no location for item {:?}", clicked_item);
|
||||||
|
|
@ -2214,7 +2187,7 @@ impl Tab {
|
||||||
let max = indices
|
let max = indices
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&offset| offset == max)
|
.position(|&offset| offset == max)
|
||||||
.unwrap_or_else(|| indices.len());
|
.unwrap_or(indices.len());
|
||||||
let min_real = min.min(max);
|
let min_real = min.min(max);
|
||||||
let max_real = max.max(min);
|
let max_real = max.max(min);
|
||||||
|
|
||||||
|
|
@ -2351,8 +2324,8 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Drag(rect_opt) => match rect_opt {
|
Message::Drag(rect_opt) => {
|
||||||
Some(rect) => {
|
if let Some(rect) = rect_opt {
|
||||||
self.context_menu = None;
|
self.context_menu = None;
|
||||||
self.location_context_menu_index = None;
|
self.location_context_menu_index = None;
|
||||||
self.select_rect(rect, mod_ctrl, mod_shift);
|
self.select_rect(rect, mod_ctrl, mod_shift);
|
||||||
|
|
@ -2363,8 +2336,7 @@ impl Tab {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
}
|
||||||
},
|
|
||||||
Message::EditLocation(edit_location) => {
|
Message::EditLocation(edit_location) => {
|
||||||
if self.edit_location.is_none() && edit_location.is_some() {
|
if self.edit_location.is_none() && edit_location.is_some() {
|
||||||
commands.push(Command::Iced(
|
commands.push(Command::Iced(
|
||||||
|
|
@ -2415,19 +2387,17 @@ impl Tab {
|
||||||
}
|
}
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for (index, item) in indices {
|
for (index, item) in indices {
|
||||||
if self.select_focus == None {
|
if self.select_focus.is_none() {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if self.select_focus == Some(index) {
|
if self.select_focus == Some(index) {
|
||||||
found = true;
|
found = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if found {
|
if found && item.can_gallery() {
|
||||||
if item.can_gallery() {
|
pos_opt = item.pos_opt.get();
|
||||||
pos_opt = item.pos_opt.get();
|
if pos_opt.is_some() {
|
||||||
if pos_opt.is_some() {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2674,11 +2644,8 @@ impl Tab {
|
||||||
if item.metadata.is_dir() {
|
if item.metadata.is_dir() {
|
||||||
//TODO: allow opening multiple tabs?
|
//TODO: allow opening multiple tabs?
|
||||||
cd = Some(location.clone());
|
cd = Some(location.clone());
|
||||||
} else {
|
} else if let Some(path) = location.path_opt() {
|
||||||
if let Some(path) = location.path_opt() {
|
commands.push(Command::OpenFile(path.to_path_buf()));
|
||||||
commands
|
|
||||||
.push(Command::OpenFile(path.to_path_buf()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//TODO: open properties?
|
//TODO: open properties?
|
||||||
|
|
@ -3018,11 +2985,10 @@ impl Tab {
|
||||||
}
|
}
|
||||||
} else if location != self.location {
|
} else if location != self.location {
|
||||||
if location.path_opt().map_or(true, |path| path.is_dir()) {
|
if location.path_opt().map_or(true, |path| path.is_dir()) {
|
||||||
let prev_path = if let Some(path) = self.location.path_opt() {
|
let prev_path = self
|
||||||
Some(vec![path.to_path_buf()])
|
.location
|
||||||
} else {
|
.path_opt()
|
||||||
None
|
.map(|path| vec![path.to_path_buf()]);
|
||||||
};
|
|
||||||
self.change_location(&location, history_i_opt);
|
self.change_location(&location, history_i_opt);
|
||||||
commands.push(Command::ChangeLocation(self.title(), location, prev_path));
|
commands.push(Command::ChangeLocation(self.title(), location, prev_path));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3149,7 +3115,7 @@ impl Tab {
|
||||||
let location1 = location.clone();
|
let location1 = location.clone();
|
||||||
let location2 = location.clone();
|
let location2 = location.clone();
|
||||||
let location3 = location.clone();
|
let location3 = location.clone();
|
||||||
let is_dnd_hovered = self.dnd_hovered.as_ref().map(|(l, _)| l) == Some(&location);
|
let is_dnd_hovered = self.dnd_hovered.as_ref().map(|(l, _)| l) == Some(location);
|
||||||
let mut container = widget::container(
|
let mut container = widget::container(
|
||||||
DndDestination::for_data::<ClipboardPaste>(element, move |data, action| {
|
DndDestination::for_data::<ClipboardPaste>(element, move |data, action| {
|
||||||
if let Some(mut data) = data {
|
if let Some(mut data) = data {
|
||||||
|
|
@ -3342,11 +3308,11 @@ impl Tab {
|
||||||
.min_bounds()
|
.min_bounds()
|
||||||
.width
|
.width
|
||||||
}
|
}
|
||||||
fn text_width_body<'a>(content: &'a str) -> f32 {
|
fn text_width_body(content: &str) -> f32 {
|
||||||
//TODO: should libcosmic set the font when using widget::text::body?
|
//TODO: should libcosmic set the font when using widget::text::body?
|
||||||
text_width(content, font::default(), 14.0, 20.0)
|
text_width(content, font::default(), 14.0, 20.0)
|
||||||
}
|
}
|
||||||
fn text_width_heading<'a>(content: &'a str) -> f32 {
|
fn text_width_heading(content: &str) -> f32 {
|
||||||
text_width(content, font::semibold(), 14.0, 20.0)
|
text_width(content, font::semibold(), 14.0, 20.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3411,9 +3377,9 @@ impl Tab {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
//TODO: make it possible to resize with the mouse
|
//TODO: make it possible to resize with the mouse
|
||||||
return mouse_area::MouseArea::new(row)
|
mouse_area::MouseArea::new(row)
|
||||||
.on_press(move |_point_opt| Message::ToggleSort(msg))
|
.on_press(move |_point_opt| Message::ToggleSort(msg))
|
||||||
.into();
|
.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
let heading_row = widget::row::with_children(vec![
|
let heading_row = widget::row::with_children(vec![
|
||||||
|
|
@ -3495,7 +3461,7 @@ impl Tab {
|
||||||
let excess_str = "...";
|
let excess_str = "...";
|
||||||
let excess_width = text_width_body(excess_str);
|
let excess_width = text_width_body(excess_str);
|
||||||
for (index, ancestor) in path.ancestors().enumerate() {
|
for (index, ancestor) in path.ancestors().enumerate() {
|
||||||
let (name, found_home) = folder_name(&ancestor);
|
let (name, found_home) = folder_name(ancestor);
|
||||||
let (name_width, name_text) = if children.is_empty() {
|
let (name_width, name_text) = if children.is_empty() {
|
||||||
(
|
(
|
||||||
text_width_heading(&name),
|
text_width_heading(&name),
|
||||||
|
|
@ -3677,8 +3643,7 @@ impl Tab {
|
||||||
let (width, height) = match self.size_opt.get() {
|
let (width, height) = match self.size_opt.get() {
|
||||||
Some(size) => (
|
Some(size) => (
|
||||||
(size.width.floor() as usize)
|
(size.width.floor() as usize)
|
||||||
.checked_sub(2 * (space_m as usize))
|
.saturating_sub(2 * (space_m as usize))
|
||||||
.unwrap_or(0)
|
|
||||||
.max(item_width),
|
.max(item_width),
|
||||||
(size.height.floor() as usize).max(item_height),
|
(size.height.floor() as usize).max(item_height),
|
||||||
),
|
),
|
||||||
|
|
@ -3686,19 +3651,18 @@ impl Tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (cols, column_spacing) = {
|
let (cols, column_spacing) = {
|
||||||
let width_m1 = width.checked_sub(item_width).unwrap_or(0);
|
let width_m1 = width.saturating_sub(item_width);
|
||||||
let cols_m1 = width_m1 / (item_width + space_xxs as usize);
|
let cols_m1 = width_m1 / (item_width + space_xxs as usize);
|
||||||
let cols = cols_m1 + 1;
|
let cols = cols_m1 + 1;
|
||||||
let spacing = width_m1
|
let spacing = width_m1
|
||||||
.checked_div(cols_m1)
|
.checked_div(cols_m1)
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
.checked_sub(item_width)
|
.saturating_sub(item_width);
|
||||||
.unwrap_or(0);
|
|
||||||
(cols, spacing as u16)
|
(cols, spacing as u16)
|
||||||
};
|
};
|
||||||
|
|
||||||
let rows = {
|
let rows = {
|
||||||
let height_m1 = height.checked_sub(item_height).unwrap_or(0);
|
let height_m1 = height.saturating_sub(item_height);
|
||||||
let rows_m1 = height_m1 / (item_height + space_xxs as usize);
|
let rows_m1 = height_m1 / (item_height + space_xxs as usize);
|
||||||
rows_m1 + 1
|
rows_m1 + 1
|
||||||
};
|
};
|
||||||
|
|
@ -3869,7 +3833,7 @@ impl Tab {
|
||||||
height: s.height - top_deduct as f32,
|
height: s.height - top_deduct as f32,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let spacer_height = height.checked_sub(max_bottom + top_deduct).unwrap_or(0);
|
let spacer_height = height.saturating_sub(max_bottom + top_deduct);
|
||||||
if spacer_height > 0 {
|
if spacer_height > 0 {
|
||||||
children.push(
|
children.push(
|
||||||
widget::container(Space::with_height(Length::Fixed(spacer_height as f32)))
|
widget::container(Space::with_height(Length::Fixed(spacer_height as f32)))
|
||||||
|
|
@ -4318,7 +4282,7 @@ impl Tab {
|
||||||
items
|
items
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|item| item.selected)
|
.filter(|item| item.selected)
|
||||||
.filter_map(|item| item.path_opt().map(|x| x.clone()))
|
.filter_map(|item| item.path_opt().cloned())
|
||||||
.collect::<Vec<PathBuf>>()
|
.collect::<Vec<PathBuf>>()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
@ -4360,7 +4324,7 @@ impl Tab {
|
||||||
|
|
||||||
if let Some(point) = self.context_menu {
|
if let Some(point) = self.context_menu {
|
||||||
popover = popover
|
popover = popover
|
||||||
.popup(menu::context_menu(&self, &key_binds))
|
.popup(menu::context_menu(self, key_binds))
|
||||||
.position(widget::popover::Position::Point(point));
|
.position(widget::popover::Position::Point(point));
|
||||||
}
|
}
|
||||||
let mut tab_column = widget::column::with_capacity(3);
|
let mut tab_column = widget::column::with_capacity(3);
|
||||||
|
|
@ -4541,8 +4505,7 @@ impl Tab {
|
||||||
// Load directory size for selected items
|
// Load directory size for selected items
|
||||||
if let Some(item) = items
|
if let Some(item) = items
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|item| item.selected)
|
.find(|item| item.selected)
|
||||||
.next()
|
|
||||||
.or(self.parent_item_opt.as_ref())
|
.or(self.parent_item_opt.as_ref())
|
||||||
{
|
{
|
||||||
// Item must have a path
|
// Item must have a path
|
||||||
|
|
@ -4611,7 +4574,7 @@ impl Tab {
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
let term = term.clone();
|
let term = term.clone();
|
||||||
let show_hidden = *show_hidden;
|
let show_hidden = *show_hidden;
|
||||||
let start = start.clone();
|
let start = *start;
|
||||||
subscriptions.push(Subscription::run_with_id(
|
subscriptions.push(Subscription::run_with_id(
|
||||||
location.clone(),
|
location.clone(),
|
||||||
stream::channel(2, move |mut output| async move {
|
stream::channel(2, move |mut output| async move {
|
||||||
|
|
@ -4721,6 +4684,200 @@ pub fn respond_to_scroll_direction(delta: ScrollDelta, modifiers: Modifiers) ->
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ArcElementWrapper<M>(pub Arc<Mutex<Element<'static, M>>>);
|
||||||
|
|
||||||
|
impl<M> Widget<M, cosmic::Theme, cosmic::Renderer> for ArcElementWrapper<M> {
|
||||||
|
fn size(&self) -> Size<Length> {
|
||||||
|
self.0.lock().unwrap().as_widget().size()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> Size<Length> {
|
||||||
|
self.0.lock().unwrap().as_widget().size_hint()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout(
|
||||||
|
&self,
|
||||||
|
tree: &mut tree::Tree,
|
||||||
|
renderer: &cosmic::Renderer,
|
||||||
|
limits: &cosmic::iced_core::layout::Limits,
|
||||||
|
) -> cosmic::iced_core::layout::Node {
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_widget_mut()
|
||||||
|
.layout(tree, renderer, limits)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(
|
||||||
|
&self,
|
||||||
|
tree: &tree::Tree,
|
||||||
|
renderer: &mut cosmic::Renderer,
|
||||||
|
theme: &cosmic::Theme,
|
||||||
|
style: &cosmic::iced_core::renderer::Style,
|
||||||
|
layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
cursor: cosmic::iced_core::mouse::Cursor,
|
||||||
|
viewport: &Rectangle,
|
||||||
|
) {
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_widget()
|
||||||
|
.draw(tree, renderer, theme, style, layout, cursor, viewport)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tag(&self) -> tree::Tag {
|
||||||
|
self.0.lock().unwrap().as_widget().tag()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn state(&self) -> tree::State {
|
||||||
|
self.0.lock().unwrap().as_widget().state()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn children(&self) -> Vec<tree::Tree> {
|
||||||
|
self.0.lock().unwrap().as_widget().children()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn diff(&mut self, tree: &mut tree::Tree) {
|
||||||
|
self.0.lock().unwrap().as_widget_mut().diff(tree)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn operate(
|
||||||
|
&self,
|
||||||
|
state: &mut tree::Tree,
|
||||||
|
layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
renderer: &cosmic::Renderer,
|
||||||
|
operation: &mut dyn widget::Operation,
|
||||||
|
) {
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_widget()
|
||||||
|
.operate(state, layout, renderer, operation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_event(
|
||||||
|
&mut self,
|
||||||
|
_state: &mut tree::Tree,
|
||||||
|
_event: cosmic::iced::Event,
|
||||||
|
_layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
_cursor: cosmic::iced_core::mouse::Cursor,
|
||||||
|
_renderer: &cosmic::Renderer,
|
||||||
|
_clipboard: &mut dyn cosmic::iced_core::Clipboard,
|
||||||
|
_shell: &mut cosmic::iced_core::Shell<'_, M>,
|
||||||
|
_viewport: &Rectangle,
|
||||||
|
) -> event::Status {
|
||||||
|
self.0.lock().unwrap().as_widget_mut().on_event(
|
||||||
|
_state, _event, _layout, _cursor, _renderer, _clipboard, _shell, _viewport,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mouse_interaction(
|
||||||
|
&self,
|
||||||
|
_state: &tree::Tree,
|
||||||
|
_layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
_cursor: cosmic::iced_core::mouse::Cursor,
|
||||||
|
_viewport: &Rectangle,
|
||||||
|
_renderer: &cosmic::Renderer,
|
||||||
|
) -> cosmic::iced_core::mouse::Interaction {
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_widget()
|
||||||
|
.mouse_interaction(_state, _layout, _cursor, _viewport, _renderer)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn overlay<'a>(
|
||||||
|
&'a mut self,
|
||||||
|
_state: &'a mut tree::Tree,
|
||||||
|
_layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
_renderer: &cosmic::Renderer,
|
||||||
|
_translation: cosmic::iced_core::Vector,
|
||||||
|
) -> Option<cosmic::iced_core::overlay::Element<'a, M, cosmic::Theme, cosmic::Renderer>> {
|
||||||
|
// TODO
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> Option<Id> {
|
||||||
|
self.0.lock().unwrap().as_widget().id()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_id(&mut self, _id: Id) {
|
||||||
|
self.0.lock().unwrap().as_widget_mut().set_id(_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn drag_destinations(
|
||||||
|
&self,
|
||||||
|
_state: &tree::Tree,
|
||||||
|
_layout: cosmic::iced_core::Layout<'_>,
|
||||||
|
renderer: &cosmic::Renderer,
|
||||||
|
_dnd_rectangles: &mut cosmic::iced_core::clipboard::DndDestinationRectangles,
|
||||||
|
) {
|
||||||
|
self.0.lock().unwrap().as_widget().drag_destinations(
|
||||||
|
_state,
|
||||||
|
_layout,
|
||||||
|
renderer,
|
||||||
|
_dnd_rectangles,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Message: 'static> From<ArcElementWrapper<Message>> for Element<'static, Message> {
|
||||||
|
fn from(wrapper: ArcElementWrapper<Message>) -> Self {
|
||||||
|
Element::new(wrapper)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn text_editor_class(
|
||||||
|
theme: &cosmic::Theme,
|
||||||
|
status: cosmic::widget::text_editor::Status,
|
||||||
|
) -> cosmic::iced_widget::text_editor::Style {
|
||||||
|
let cosmic = theme.cosmic();
|
||||||
|
let container = theme.current_container();
|
||||||
|
|
||||||
|
let mut background: cosmic::iced::Color = container.component.base.into();
|
||||||
|
background.a = 0.25;
|
||||||
|
let selection = cosmic.accent.base.into();
|
||||||
|
let value = cosmic.palette.neutral_9.into();
|
||||||
|
let mut placeholder = cosmic.palette.neutral_9;
|
||||||
|
placeholder.alpha = 0.7;
|
||||||
|
let placeholder = placeholder.into();
|
||||||
|
let icon = cosmic.background.on.into();
|
||||||
|
|
||||||
|
match status {
|
||||||
|
cosmic::iced_widget::text_editor::Status::Active
|
||||||
|
| cosmic::iced_widget::text_editor::Status::Disabled => {
|
||||||
|
cosmic::iced_widget::text_editor::Style {
|
||||||
|
background: background.into(),
|
||||||
|
border: cosmic::iced::Border {
|
||||||
|
radius: cosmic.corner_radii.radius_m.into(),
|
||||||
|
width: 2.0,
|
||||||
|
color: container.component.divider.into(),
|
||||||
|
},
|
||||||
|
icon,
|
||||||
|
placeholder,
|
||||||
|
value,
|
||||||
|
selection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cosmic::iced_widget::text_editor::Status::Hovered
|
||||||
|
| cosmic::iced_widget::text_editor::Status::Focused => {
|
||||||
|
cosmic::iced_widget::text_editor::Style {
|
||||||
|
background: background.into(),
|
||||||
|
border: cosmic::iced::Border {
|
||||||
|
radius: cosmic.corner_radii.radius_m.into(),
|
||||||
|
width: 2.0,
|
||||||
|
color: cosmic::iced::Color::from(cosmic.accent.base),
|
||||||
|
},
|
||||||
|
icon,
|
||||||
|
placeholder,
|
||||||
|
value,
|
||||||
|
selection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{fs, io, path::PathBuf};
|
use std::{fs, io, path::PathBuf};
|
||||||
|
|
@ -4758,7 +4915,7 @@ mod tests {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.expect("tab should be populated with items");
|
.expect("tab should be populated with items");
|
||||||
|
|
||||||
for (i, (&expected, actual)) in expected_selected.into_iter().zip(items).enumerate() {
|
for (i, (&expected, actual)) in expected_selected.iter().zip(items).enumerate() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected,
|
expected,
|
||||||
actual.selected,
|
actual.selected,
|
||||||
|
|
@ -4971,7 +5128,7 @@ mod tests {
|
||||||
fn tab_scroll_up_with_ctrl_modifier_zooms() -> io::Result<()> {
|
fn tab_scroll_up_with_ctrl_modifier_zooms() -> io::Result<()> {
|
||||||
let message_maybe =
|
let message_maybe =
|
||||||
respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: 1.0 }, Modifiers::CTRL);
|
respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: 1.0 }, Modifiers::CTRL);
|
||||||
assert!(!message_maybe.is_none());
|
assert!(message_maybe.is_some());
|
||||||
assert!(matches!(message_maybe.unwrap(), Message::ZoomIn));
|
assert!(matches!(message_maybe.unwrap(), Message::ZoomIn));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -4988,7 +5145,7 @@ mod tests {
|
||||||
fn tab_scroll_down_with_ctrl_modifier_zooms() -> io::Result<()> {
|
fn tab_scroll_down_with_ctrl_modifier_zooms() -> io::Result<()> {
|
||||||
let message_maybe =
|
let message_maybe =
|
||||||
respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: -1.0 }, Modifiers::CTRL);
|
respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: -1.0 }, Modifiers::CTRL);
|
||||||
assert!(!message_maybe.is_none());
|
assert!(message_maybe.is_some());
|
||||||
assert!(matches!(message_maybe.unwrap(), Message::ZoomOut));
|
assert!(matches!(message_maybe.unwrap(), Message::ZoomOut));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -5047,7 +5204,7 @@ mod tests {
|
||||||
// Create files with names 255 characters long that only contain a single number
|
// Create files with names 255 characters long that only contain a single number
|
||||||
// Example: 0000...0 for 255 characters
|
// Example: 0000...0 for 255 characters
|
||||||
// https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
|
// https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
|
||||||
let mut base_nums: Vec<_> = ('0'..'9').collect();
|
let mut base_nums: Vec<_> = ('0'..='9').collect();
|
||||||
fastrand::shuffle(&mut base_nums);
|
fastrand::shuffle(&mut base_nums);
|
||||||
debug!("Shuffled numbers for paths: {base_nums:?}");
|
debug!("Shuffled numbers for paths: {base_nums:?}");
|
||||||
let paths: Vec<_> = base_nums
|
let paths: Vec<_> = base_nums
|
||||||
|
|
@ -5066,197 +5223,3 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ArcElementWrapper<M>(pub Arc<Mutex<Element<'static, M>>>);
|
|
||||||
|
|
||||||
impl<M> Widget<M, cosmic::Theme, cosmic::Renderer> for ArcElementWrapper<M> {
|
|
||||||
fn size(&self) -> Size<Length> {
|
|
||||||
self.0.lock().unwrap().as_widget().size()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> Size<Length> {
|
|
||||||
self.0.lock().unwrap().as_widget().size_hint()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout(
|
|
||||||
&self,
|
|
||||||
tree: &mut tree::Tree,
|
|
||||||
renderer: &cosmic::Renderer,
|
|
||||||
limits: &cosmic::iced_core::layout::Limits,
|
|
||||||
) -> cosmic::iced_core::layout::Node {
|
|
||||||
self.0
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.as_widget_mut()
|
|
||||||
.layout(tree, renderer, limits)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(
|
|
||||||
&self,
|
|
||||||
tree: &tree::Tree,
|
|
||||||
renderer: &mut cosmic::Renderer,
|
|
||||||
theme: &cosmic::Theme,
|
|
||||||
style: &cosmic::iced_core::renderer::Style,
|
|
||||||
layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
cursor: cosmic::iced_core::mouse::Cursor,
|
|
||||||
viewport: &Rectangle,
|
|
||||||
) {
|
|
||||||
self.0
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.as_widget()
|
|
||||||
.draw(tree, renderer, theme, style, layout, cursor, viewport)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tag(&self) -> tree::Tag {
|
|
||||||
self.0.lock().unwrap().as_widget().tag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn state(&self) -> tree::State {
|
|
||||||
self.0.lock().unwrap().as_widget().state()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn children(&self) -> Vec<tree::Tree> {
|
|
||||||
self.0.lock().unwrap().as_widget().children()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn diff(&mut self, tree: &mut tree::Tree) {
|
|
||||||
self.0.lock().unwrap().as_widget_mut().diff(tree)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn operate(
|
|
||||||
&self,
|
|
||||||
state: &mut tree::Tree,
|
|
||||||
layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
renderer: &cosmic::Renderer,
|
|
||||||
operation: &mut dyn widget::Operation,
|
|
||||||
) {
|
|
||||||
self.0
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.as_widget()
|
|
||||||
.operate(state, layout, renderer, operation)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_event(
|
|
||||||
&mut self,
|
|
||||||
_state: &mut tree::Tree,
|
|
||||||
_event: cosmic::iced::Event,
|
|
||||||
_layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
_cursor: cosmic::iced_core::mouse::Cursor,
|
|
||||||
_renderer: &cosmic::Renderer,
|
|
||||||
_clipboard: &mut dyn cosmic::iced_core::Clipboard,
|
|
||||||
_shell: &mut cosmic::iced_core::Shell<'_, M>,
|
|
||||||
_viewport: &Rectangle,
|
|
||||||
) -> event::Status {
|
|
||||||
self.0.lock().unwrap().as_widget_mut().on_event(
|
|
||||||
_state, _event, _layout, _cursor, _renderer, _clipboard, _shell, _viewport,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mouse_interaction(
|
|
||||||
&self,
|
|
||||||
_state: &tree::Tree,
|
|
||||||
_layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
_cursor: cosmic::iced_core::mouse::Cursor,
|
|
||||||
_viewport: &Rectangle,
|
|
||||||
_renderer: &cosmic::Renderer,
|
|
||||||
) -> cosmic::iced_core::mouse::Interaction {
|
|
||||||
self.0
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.as_widget()
|
|
||||||
.mouse_interaction(_state, _layout, _cursor, _viewport, _renderer)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn overlay<'a>(
|
|
||||||
&'a mut self,
|
|
||||||
_state: &'a mut tree::Tree,
|
|
||||||
_layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
_renderer: &cosmic::Renderer,
|
|
||||||
_translation: cosmic::iced_core::Vector,
|
|
||||||
) -> Option<cosmic::iced_core::overlay::Element<'a, M, cosmic::Theme, cosmic::Renderer>> {
|
|
||||||
// TODO
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn id(&self) -> Option<Id> {
|
|
||||||
self.0.lock().unwrap().as_widget().id()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_id(&mut self, _id: Id) {
|
|
||||||
self.0.lock().unwrap().as_widget_mut().set_id(_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn drag_destinations(
|
|
||||||
&self,
|
|
||||||
_state: &tree::Tree,
|
|
||||||
_layout: cosmic::iced_core::Layout<'_>,
|
|
||||||
renderer: &cosmic::Renderer,
|
|
||||||
_dnd_rectangles: &mut cosmic::iced_core::clipboard::DndDestinationRectangles,
|
|
||||||
) {
|
|
||||||
self.0.lock().unwrap().as_widget().drag_destinations(
|
|
||||||
_state,
|
|
||||||
_layout,
|
|
||||||
renderer,
|
|
||||||
_dnd_rectangles,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Message: 'static> From<ArcElementWrapper<Message>> for Element<'static, Message> {
|
|
||||||
fn from(wrapper: ArcElementWrapper<Message>) -> Self {
|
|
||||||
Element::new(wrapper)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn text_editor_class(
|
|
||||||
theme: &cosmic::Theme,
|
|
||||||
status: cosmic::widget::text_editor::Status,
|
|
||||||
) -> cosmic::iced_widget::text_editor::Style {
|
|
||||||
let cosmic = theme.cosmic();
|
|
||||||
let container = theme.current_container();
|
|
||||||
|
|
||||||
let mut background: cosmic::iced::Color = container.component.base.into();
|
|
||||||
background.a = 0.25;
|
|
||||||
let selection = cosmic.accent.base.into();
|
|
||||||
let value = cosmic.palette.neutral_9.into();
|
|
||||||
let mut placeholder = cosmic.palette.neutral_9;
|
|
||||||
placeholder.alpha = 0.7;
|
|
||||||
let placeholder = placeholder.into();
|
|
||||||
let icon = cosmic.background.on.into();
|
|
||||||
|
|
||||||
match status {
|
|
||||||
cosmic::iced_widget::text_editor::Status::Active
|
|
||||||
| cosmic::iced_widget::text_editor::Status::Disabled => {
|
|
||||||
cosmic::iced_widget::text_editor::Style {
|
|
||||||
background: background.into(),
|
|
||||||
border: cosmic::iced::Border {
|
|
||||||
radius: cosmic.corner_radii.radius_m.into(),
|
|
||||||
width: 2.0,
|
|
||||||
color: container.component.divider.into(),
|
|
||||||
},
|
|
||||||
icon,
|
|
||||||
placeholder,
|
|
||||||
value,
|
|
||||||
selection,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cosmic::iced_widget::text_editor::Status::Hovered
|
|
||||||
| cosmic::iced_widget::text_editor::Status::Focused => {
|
|
||||||
cosmic::iced_widget::text_editor::Style {
|
|
||||||
background: background.into(),
|
|
||||||
border: cosmic::iced::Border {
|
|
||||||
radius: cosmic.corner_radii.radius_m.into(),
|
|
||||||
width: 2.0,
|
|
||||||
color: cosmic::iced::Color::from(cosmic.accent.base),
|
|
||||||
},
|
|
||||||
icon,
|
|
||||||
placeholder,
|
|
||||||
value,
|
|
||||||
selection,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue