team-ljyzipelo

공개

파일 목록에 탐색기 방식 선택을 적용함

작성자
호시노 히나타
작성 시각
커밋
9a6dc1baa501b1c32cabb42e833f977e596170d0
부모
784e0a9
이 시점의 파일 보기

변경된 파일 9개

+825-109
수정experiments/rust-ui-memory-app/src/archive_screen.rs+348-106
@@ -11,6 +11,15 @@ use std::{
1111 path::{Path, PathBuf},
1212};
1313
14추가: struct Marquee {
15추가: // 스크롤 중에도 시작점을 목록 좌표로 유지함.
16추가: origin: egui::Pos2,
17추가: base: BTreeSet<u32>,
18추가: moved: bool,
19추가: }
20추가:
21추가: const LIST_ROW: f32 = 44.0;
22추가:
1423pub struct ArchiveApp {
1524 pub model: Model,
1625 factory: Box<dyn Factory>,
@@ -32,6 +41,11 @@ pub struct ArchiveApp {
3241 dialogs: Box<dyn Dialogs>,
3342 folder: String,
3443 search: String,
44추가: list_anchor: Option<usize>,
45추가: list_cursor: Option<usize>,
46추가: list_offset: f32,
47추가: list_focused: bool,
48추가: marquee: Option<Marquee>,
3549 last_request: Option<Start>,
3650 targets: Option<BTreeSet<String>>,
3751 directories: BTreeSet<String>,
@@ -65,6 +79,11 @@ impl ArchiveApp {
6579 dialogs: Box::new(NativeDialogs),
6680 folder: String::new(),
6781 search: String::new(),
82추가: list_anchor: None,
83추가: list_cursor: None,
84추가: list_offset: 0.0,
85추가: list_focused: false,
86추가: marquee: None,
6887 last_request: None,
6988 targets: None,
7089 directories: BTreeSet::new(),
@@ -87,6 +106,7 @@ impl ArchiveApp {
87106 pub fn browse_folder(&mut self, folder: &str) {
88107 self.folder = folder.trim_matches('/').to_owned();
89108 self.search.clear();
109추가: self.clear_list_selection();
90110 }
91111
92112 pub fn show_create(&mut self, encrypted: bool) {
@@ -116,6 +136,7 @@ impl ArchiveApp {
116136 self.selected_only = false;
117137 self.folder.clear();
118138 self.search.clear();
139추가: self.clear_list_selection();
119140 self.targets = None;
120141 self.directories.clear();
121142 self.start(Start::List { archive });
@@ -185,6 +206,7 @@ impl ArchiveApp {
185206 }
186207
187208 pub fn begin_extract(&mut self) -> bool {
209추가: self.selected_only = !self.model.selected.is_empty();
188210 if !self.model.can_extract() || (self.selected_only && self.model.selected.is_empty()) {
189211 return false;
190212 }
@@ -549,7 +571,14 @@ impl ArchiveApp {
549571 ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
550572 theme::bounded_text(
551573 ui,
552삭제: &format!("선택 {}개", self.model.selected.len()),
574추가: &format!(
575추가: "선택 {}개",
576추가: browser::rows(&self.model.entries, &self.folder, &self.search)
577추가: .iter()
578추가: .filter(|row| !row.ids.is_empty()
579추가: && row.ids.is_subset(&self.model.selected))
580추가: .count()
581추가: ),
553582 width,
554583 );
555584 });
@@ -697,86 +726,187 @@ impl ArchiveApp {
697726 .hint_text("파일 찾기"),
698727 );
699728 theme::focus(&search);
729추가: if search.changed() {
730추가: self.clear_list_selection();
731추가: }
700732 });
701733 });
702734 let rows = browser::rows(&self.model.entries, &self.folder, &self.search);
703삭제: let visible = rows
704삭제: .iter()
705삭제: .flat_map(|row| row.ids.iter().copied())
706삭제: .collect::<BTreeSet<_>>();
707삭제: let mut all = !visible.is_empty() && visible.is_subset(&self.model.selected);
708삭제: let name_width = (ui.available_width() - 32.0 - 96.0 - 64.0 - 64.0).max(160.0);
735추가:
736추가: let name_width = (ui.available_width() - 16.0 - 28.0 - 96.0 - 64.0 - 40.0).max(120.0);
709737 ui.horizontal(|ui| {
710삭제: ui.add_space(16.0);
711삭제: let check = ui
712삭제: .add_enabled(
713삭제: !self.model.busy() && !visible.is_empty(),
714삭제: egui::Checkbox::without_text(&mut all),
715삭제: )
716삭제: .on_hover_text("전체 선택");
717삭제: if check.changed() {
718삭제: if all {
719삭제: self.model.selected.extend(&visible);
720삭제: } else {
721삭제: browser::remove_selection(
722삭제: &self.model.entries,
723삭제: &mut self.model.selected,
724삭제: &visible,
725삭제: );
726삭제: }
727삭제: }
728삭제: theme::focus(&check);
738추가: ui.add_space(16.0 + 28.0);
729739 theme::column_label(ui, RichText::new("이름").strong(), name_width, Align::Min);
730740 theme::column_label(ui, "크기", 96.0, Align::Max);
731741 theme::column_label(ui, "암호", 64.0, Align::Min);
732742 });
733743 ui.separator();
734삭제: if rows.is_empty() {
735삭제: ui.centered_and_justified(|ui| {
736삭제: ui.label(if self.search.is_empty() {
737삭제: "이 폴더는 비어 있습니다"
738삭제: } else {
739삭제: "일치하는 항목이 없습니다"
740삭제: });
744추가: let active = !self.model.busy()
745추가: && !self.create
746추가: && self.model.challenge.is_none()
747추가: && self.model.close == Close::Open;
748추가: let list_id = egui::Id::unique("archive-list");
749추가: let background = ui.interact(
750추가: ui.available_rect_before_wrap(),
751추가: list_id,
752추가: if active {
753추가: egui::Sense::click_and_drag()
754추가: } else {
755추가: egui::Sense::hover()
756추가: },
757추가: );
758추가: background
759추가: .widget_info(|| egui::WidgetInfo::labeled(egui::Role::ListBox, active, "파일 목록"));
760추가: if background.has_focus() {
761추가: ui.ctx().memory_mut(|memory| {
762추가: memory.set_focus_lock_filter(
763추가: list_id,
764추가: egui::EventFilter {
765추가: vertical_arrows: true,
766추가: escape: true,
767추가: ..Default::default()
768추가: },
769추가: )
741770 });
742삭제: return;
743771 }
744삭제: egui::ScrollArea::vertical()
772추가: let mut focused = None;
773추가: let mut open = None;
774추가: let mut next_offset = None;
775추가: let output = egui::ScrollArea::vertical()
745776 .id_salt("archive-rows")
746777 .auto_shrink([false, false])
747삭제: .show_rows(ui, 38.0, rows.len(), |ui, range| {
748삭제: for index in range {
749삭제: let row = &rows[index];
750삭제: let mut selected =
751삭제: !row.ids.is_empty() && row.ids.is_subset(&self.model.selected);
752삭제: let response = ui
753삭제: .horizontal(|ui| {
754삭제: ui.set_min_height(36.0);
755삭제: ui.add_space(16.0);
756삭제: let check = ui.add_enabled(
757삭제: !self.model.busy() && !row.ids.is_empty(),
758삭제: egui::Checkbox::without_text(&mut selected),
759삭제: );
760삭제: check.widget_info(|| {
761삭제: egui::WidgetInfo::selected(
762삭제: egui::Role::CheckBox,
763삭제: !self.model.busy(),
764삭제: selected,
765삭제: &row.name,
766삭제: )
767삭제: });
768삭제: theme::focus(&check);
769삭제: if check.changed() {
770삭제: if selected {
778추가: .vertical_scroll_offset(self.list_offset)
779추가: .show_viewport(ui, |ui, viewport| {
780추가: let origin = ui.max_rect().min;
781추가: let clip = ui.clip_rect();
782추가: let width = (ui.available_width() - 24.0).max(0.0);
783추가: ui.set_min_height((rows.len() as f32 * LIST_ROW).max(viewport.height()));
784추가: let point = ui.input(|i| i.pointer.interact_pos());
785추가: if active && let Some(point) = point {
786추가: let press = ui.input(|i| i.pointer.press_origin()).unwrap_or(point);
787추가: let relative = press - origin;
788추가: let in_row = relative.x >= 0.0
789추가: && relative.x <= width
790추가: && relative.y >= 0.0
791추가: && relative.y < rows.len() as f32 * LIST_ROW;
792추가: if clip.contains(press) && !in_row && ui.input(|i| i.pointer.primary_pressed())
793추가: {
794추가: background.request_focus();
795추가: let ctrl = ui.input(|i| i.modifiers.ctrl || i.modifiers.command);
796추가: self.marquee = Some(Marquee {
797추가: origin: relative.to_pos2(),
798추가: base: if ctrl {
799추가: self.model.selected.clone()
800추가: } else {
801추가: BTreeSet::new()
802추가: },
803추가: moved: false,
804추가: });
805추가: if !ctrl {
806추가: self.model.selected.clear();
807추가: self.list_anchor = None;
808추가: self.list_cursor = None;
809추가: }
810추가: }
811추가: if let Some(drag) = &mut self.marquee {
812추가: let end = (point.clamp(clip.min, clip.max) - origin).to_pos2();
813추가: drag.moved |= drag.origin.distance(end) > 3.0;
814추가: if drag.moved {
815추가: let rect = egui::Rect::from_two_pos(drag.origin, end);
816추가: self.model.selected = drag.base.clone();
817추가: if rect.left() < width && rect.right() > 0.0 {
818추가: let first = (rect.top().max(0.0) / LIST_ROW).floor() as usize;
819추가: let last = ((rect.bottom().max(0.0) / LIST_ROW).ceil() as usize)
820추가: .min(rows.len());
821추가: for row in rows.iter().take(last).skip(first) {
771822 self.model.selected.extend(&row.ids);
772삭제: } else {
773삭제: browser::remove_selection(
774삭제: &self.model.entries,
775삭제: &mut self.model.selected,
776삭제: &row.ids,
777삭제: );
778823 }
824추가: if first < last {
825추가: self.list_anchor = Some(first);
826추가: self.list_cursor = Some(last - 1);
827추가: }
828추가: }
829추가: let speed = if point.y > clip.bottom() - 24.0 {
830추가: ((point.y - clip.bottom() + 24.0) / 24.0).clamp(0.0, 3.0)
831추가: } else if point.y < clip.top() + 24.0 {
832추가: -((clip.top() + 24.0 - point.y) / 24.0).clamp(0.0, 3.0)
833추가: } else {
834추가: 0.0
835추가: };
836추가: if ui.input(|i| i.pointer.primary_down()) && speed != 0.0 {
837추가: let dt = ui.input(|i| i.stable_dt).clamp(0.001, 0.05);
838추가: next_offset = Some((viewport.min.y + speed * 500.0 * dt).clamp(
839추가: 0.0,
840추가: (rows.len() as f32 * LIST_ROW - viewport.height()).max(0.0),
841추가: ));
842추가: ui.ctx().request_repaint();
779843 }
844추가: }
845추가: }
846추가: }
847추가: let first = (viewport.min.y / LIST_ROW).floor() as usize;
848추가: let last = ((viewport.max.y / LIST_ROW).ceil() as usize + 1).min(rows.len());
849추가: for index in first.min(rows.len())..last {
850추가: let row = &rows[index];
851추가: let rect = egui::Rect::from_min_size(
852추가: origin + egui::vec2(0.0, index as f32 * LIST_ROW),
853추가: egui::vec2(width, LIST_ROW),
854추가: );
855추가: let selected = !row.ids.is_empty() && row.ids.is_subset(&self.model.selected);
856추가: let response = ui
857추가: .interact(
858추가: rect,
859추가: egui::Id::unique(("archive-row", &row.path)),
860추가: if active {
861추가: egui::Sense::click()
862추가: } else {
863추가: egui::Sense::hover()
864추가: },
865추가: )
866추가: .on_hover_text(&row.name);
867추가: response.widget_info(|| {
868추가: egui::WidgetInfo::selected(
869추가: egui::Role::ListBoxOption,
870추가: active,
871추가: selected,
872추가: &row.name,
873추가: )
874추가: });
875추가: if response.has_focus() {
876추가: focused = Some(index);
877추가: ui.ctx().memory_mut(|memory| {
878추가: memory.set_focus_lock_filter(
879추가: response.id,
880추가: egui::EventFilter {
881추가: vertical_arrows: true,
882추가: escape: true,
883추가: ..Default::default()
884추가: },
885추가: )
886추가: });
887추가: }
888추가: if selected {
889추가: ui.painter().rect_filled(rect, 0, theme::SELECTED);
890추가: }
891추가: if response.clicked() {
892추가: let modifiers = ui.input(|i| i.modifiers);
893추가: self.select_row(
894추가: &rows,
895추가: index,
896추가: modifiers.ctrl || modifiers.command,
897추가: modifiers.shift,
898추가: );
899추가: }
900추가: if row.directory && response.double_clicked() {
901추가: open = Some(row.path.clone());
902추가: }
903추가: ui.scope_builder(
904추가: egui::UiBuilder::new()
905추가: .max_rect(rect.shrink2(egui::vec2(0.0, 4.0)))
906추가: .layout(Layout::left_to_right(Align::Center)),
907추가: |ui| {
908추가: ui.style_mut().interaction.selectable_labels = false;
909추가: ui.add_space(16.0);
780910 theme::icon(
781911 ui,
782912 if row.directory {
@@ -786,41 +916,7 @@ impl ArchiveApp {
786916 },
787917 20.0,
788918 );
789삭제: let label = ui
790삭제: .allocate_ui_with_layout(
791삭제: egui::vec2((name_width - 28.0).max(0.0), 34.0),
792삭제: Layout::left_to_right(Align::Center),
793삭제: |ui| {
794삭제: ui.set_min_width((name_width - 28.0).max(0.0));
795삭제: ui.set_max_width((name_width - 28.0).max(0.0));
796삭제: ui.add_enabled(
797삭제: !self.model.busy(),
798삭제: egui::Button::new(&row.name)
799삭제: .truncate()
800삭제: .selected(selected)
801삭제: .frame(false)
802삭제: .min_size(egui::vec2(0.0, 34.0)),
803삭제: )
804삭제: },
805삭제: )
806삭제: .inner
807삭제: .on_hover_text(&row.name);
808삭제: theme::focus(&label);
809삭제: let enter =
810삭제: label.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
811삭제: if row.directory && (label.double_clicked() || enter) {
812삭제: self.browse_folder(&row.path);
813삭제: } else if !row.directory && label.clicked() {
814삭제: if selected {
815삭제: browser::remove_selection(
816삭제: &self.model.entries,
817삭제: &mut self.model.selected,
818삭제: &row.ids,
819삭제: );
820삭제: } else {
821삭제: self.model.selected.extend(&row.ids);
822삭제: }
823삭제: }
919추가: theme::bounded_text(ui, &row.name, name_width);
824920 theme::column_label(
825921 ui,
826922 if row.directory {
@@ -836,15 +932,161 @@ impl ArchiveApp {
836932 if row.encrypted {
837933 theme::icon(ui, Icon::Lock, 16.0);
838934 }
839삭제: })
840삭제: .response;
841삭제: ui.painter().hline(
842삭제: response.rect.x_range(),
843삭제: response.rect.bottom(),
844삭제: egui::Stroke::new(1.0, theme::BORDER),
935추가: },
936추가: );
937추가: if active
938추가: && self.list_cursor == Some(index)
939추가: && (response.has_focus() || background.has_focus())
940추가: {
941추가: ui.painter().rect_stroke(
942추가: rect.shrink(1.0),
943추가: 0,
944추가: egui::Stroke::new(1.0, theme::BLUE),
945추가: egui::StrokeKind::Inside,
946추가: );
947추가: }
948추가: }
949추가: if rows.is_empty() {
950추가: ui.scope_builder(egui::UiBuilder::new().max_rect(clip), |ui| {
951추가: ui.centered_and_justified(|ui| {
952추가: ui.label(if self.search.is_empty() {
953추가: "이 폴더는 비어 있습니다"
954추가: } else {
955추가: "일치하는 항목이 없습니다"
956추가: })
957추가: });
958추가: });
959추가: }
960추가: if let Some(drag) = &self.marquee
961추가: && drag.moved
962추가: && let Some(point) = point
963추가: {
964추가: let rect = egui::Rect::from_two_pos(
965추가: origin + drag.origin.to_vec2(),
966추가: point.clamp(clip.min, clip.max),
845967 );
968추가: ui.painter()
969추가: .with_clip_rect(clip)
970추가: .rect_filled(rect, 0, theme::BLUE);
846971 }
847972 });
973추가: self.list_offset = next_offset.unwrap_or(output.state.clamped_offset().y);
974추가: if ui.input(|i| i.pointer.primary_released() || !i.pointer.primary_down()) {
975추가: self.marquee = None;
976추가: }
977추가: let escape_from_list = self.list_focused
978추가: && ui.ctx().memory(|memory| memory.focused()).is_none()
979추가: && ui.input(|i| i.key_pressed(egui::Key::Escape));
980추가: self.list_focused =
981추가: active && (background.has_focus() || focused.is_some() || escape_from_list);
982추가: if self.list_focused {
983추가: if let Some(index) = focused {
984추가: self.list_cursor = Some(index);
985추가: }
986추가: let modifiers = ui.input(|i| i.modifiers);
987추가: let ctrl = modifiers.ctrl || modifiers.command;
988추가: if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
989추가: self.model.selected.clear();
990추가: self.marquee = None;
991추가: background.request_focus();
992추가: }
993추가: if ctrl && ui.input(|i| i.key_pressed(egui::Key::A)) {
994추가: self.model.selected = rows
995추가: .iter()
996추가: .flat_map(|row| row.ids.iter().copied())
997추가: .collect();
998추가: self.list_cursor = (!rows.is_empty()).then_some(0);
999추가: self.list_anchor = self.list_cursor;
1000추가: }
1001추가: if !rows.is_empty() {
1002추가: let direction = if ui.input(|i| i.key_pressed(egui::Key::ArrowDown)) {
1003추가: Some(1isize)
1004추가: } else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp)) {
1005추가: Some(-1)
1006추가: } else {
1007추가: None
1008추가: };
1009추가: if let Some(direction) = direction {
1010추가: let index = self.list_cursor.map_or(0, |index| {
1011추가: index.saturating_add_signed(direction).min(rows.len() - 1)
1012추가: });
1013추가: if ctrl && !modifiers.shift {
1014추가: self.list_cursor = Some(index);
1015추가: } else {
1016추가: self.select_row(&rows, index, ctrl, modifiers.shift);
1017추가: }
1018추가: background.request_focus();
1019추가: let top = index as f32 * LIST_ROW;
1020추가: if top < self.list_offset {
1021추가: self.list_offset = top;
1022추가: } else if top + LIST_ROW > self.list_offset + output.inner_rect.height() {
1023추가: self.list_offset = top + LIST_ROW - output.inner_rect.height();
1024추가: }
1025추가: ui.ctx().request_repaint();
1026추가: }
1027추가: if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
1028추가: let index = self
1029추가: .list_cursor
1030추가: .or(focused)
1031추가: .unwrap_or(0)
1032추가: .min(rows.len() - 1);
1033추가: if rows[index].directory {
1034추가: open = Some(rows[index].path.clone());
1035추가: }
1036추가: }
1037추가: }
1038추가: if ui.input(|i| i.key_pressed(egui::Key::Backspace)) && !self.folder.is_empty() {
1039추가: open = Some(
1040추가: self.folder
1041추가: .rsplit_once('/')
1042추가: .map_or("", |(parent, _)| parent)
1043추가: .to_owned(),
1044추가: );
1045추가: }
1046추가: }
1047추가: if let Some(folder) = open {
1048추가: self.browse_folder(&folder);
1049추가: background.request_focus();
1050추가: }
1051추가: }
1052추가:
1053추가: fn clear_list_selection(&mut self) {
1054추가: self.model.selected.clear();
1055추가: self.list_anchor = None;
1056추가: self.list_cursor = None;
1057추가: self.list_offset = 0.0;
1058추가: self.marquee = None;
1059추가: }
1060추가:
1061추가: fn select_row(&mut self, rows: &[browser::Row], index: usize, ctrl: bool, shift: bool) {
1062추가: if shift {
1063추가: let anchor = self
1064추가: .list_anchor
1065추가: .unwrap_or(self.list_cursor.unwrap_or(index))
1066추가: .min(rows.len() - 1);
1067추가: if !ctrl {
1068추가: self.model.selected.clear();
1069추가: }
1070추가: for row in &rows[anchor.min(index)..=anchor.max(index)] {
1071추가: self.model.selected.extend(&row.ids);
1072추가: }
1073추가: self.list_anchor = Some(anchor);
1074추가: } else {
1075추가: if !ctrl {
1076추가: self.model.selected.clear();
1077추가: }
1078추가: if ctrl && rows[index].ids.is_subset(&self.model.selected) {
1079추가: browser::remove_selection(
1080추가: &self.model.entries,
1081추가: &mut self.model.selected,
1082추가: &rows[index].ids,
1083추가: );
1084추가: } else {
1085추가: self.model.selected.extend(&rows[index].ids);
1086추가: }
1087추가: self.list_anchor = Some(index);
1088추가: }
1089추가: self.list_cursor = Some(index);
8481090 }
8491091
8501092 fn result_visible(&self) -> bool {
수정tests/rust-app-real-worker/selection_flows.rs+59-0
@@ -228,3 +228,62 @@ fn auto_destination_is_private_under_desktop_umask() {
228228 );
229229 assert_reaped(&observed);
230230}
231추가:
232추가: #[test]
233추가: fn explorer_folder_click_and_escape_control_actual_extraction_scope() {
234추가: let scratch = Scratch::new();
235추가: let folder = make_directory(&scratch.path("docs"));
236추가: fs::write(folder.join("child.txt"), b"selected subtree").unwrap();
237추가: let outside = scratch.path("outside.txt");
238추가: fs::write(&outside, b"outside subtree").unwrap();
239추가: let archive = scratch.path("picked.zip");
240추가: let selected_output = make_directory(&scratch.path("selected-output"));
241추가: let all_output = make_directory(&scratch.path("all-output"));
242추가: let (factory, observed) = observed_factory();
243추가: let mut screen = Screen::new(factory);
244추가: screen.app.add_sources(vec![folder, outside]);
245추가: screen.render(vec![]);
246추가: screen.set_text("zip-name", "picked.zip");
247추가: screen.click("압축하기");
248추가: screen.settle();
249추가: screen.open(&archive);
250추가: screen.click("docs");
251추가: assert!(!screen.app.model.selected.is_empty());
252추가: screen.extract(&selected_output);
253추가: assert_eq!(
254추가: fs::read(selected_output.join("docs/child.txt")).unwrap(),
255추가: b"selected subtree"
256추가: );
257추가: assert!(!selected_output.join("outside.txt").exists());
258추가: assert!(matches!(
259추가: observed.borrow().starts.last(),
260추가: Some(Start::Extract {
261추가: selection: Selection::EntryIds(_),
262추가: ..
263추가: })
264추가: ));
265추가: screen.click("확인");
266추가: screen
267추가: .context
268추가: .memory_mut(|memory| memory.request_focus(egui::Id::unique("archive-list")));
269추가: screen.render(vec![]);
270추가: screen.escape();
271추가: assert!(screen.app.model.selected.is_empty());
272추가: screen.extract(&all_output);
273추가: assert_eq!(
274추가: fs::read(all_output.join("outside.txt")).unwrap(),
275추가: b"outside subtree"
276추가: );
277추가: assert_eq!(
278추가: fs::read(all_output.join("docs/child.txt")).unwrap(),
279추가: b"selected subtree"
280추가: );
281추가: assert!(matches!(
282추가: observed.borrow().starts.last(),
283추가: Some(Start::Extract {
284추가: selection: Selection::All,
285추가: ..
286추가: })
287추가: ));
288추가: assert_reaped(&observed);
289추가: }
추가tests/rust-app-ui/explorer_selection.rs+386-0
@@ -0,0 +1,386 @@
1추가: struct Explorer {
2추가: app: ArchiveApp,
3추가: ctx: egui::Context,
4추가: factory: FakeFactory,
5추가: time: f64,
6추가: }
7추가: impl Explorer {
8추가: fn new(scratch: &Folder) -> Self {
9추가: let factory = FakeFactory::default();
10추가: let mut app = loaded(scratch, &factory);
11추가: app.model.entries = [
12추가: (0, "docs/child.txt", Kind::File),
13추가: (1, "alpha.txt", Kind::File),
14추가: (2, "beta.txt", Kind::File),
15추가: (3, "gamma.txt", Kind::File),
16추가: (4, "omega.txt", Kind::File),
17추가: (5, "docs", Kind::Directory),
18추가: ]
19추가: .map(|(id, name, kind)| Entry {
20추가: id,
21추가: name: name.into(),
22추가: kind,
23추가: bytes: Some(7),
24추가: packed: None,
25추가: encrypted: false,
26추가: })
27추가: .into();
28추가: let mut screen = Self {
29추가: app,
30추가: ctx: egui::Context::default(),
31추가: factory,
32추가: time: 0.0,
33추가: };
34추가: screen.frame(egui::Modifiers::NONE, vec![]);
35추가: screen.frame(egui::Modifiers::NONE, vec![]);
36추가: screen
37추가: }
38추가: fn frame(&mut self, modifiers: egui::Modifiers, events: Vec<egui::Event>) -> egui::FullOutput {
39추가: self.time += 0.05;
40추가: let mut events = events;
41추가: events.insert(0, egui::Event::ModifiersChanged(modifiers));
42추가: let mut output = self.ctx.run_ui(
43추가: egui::RawInput {
44추가: screen_rect: Some(egui::Rect::from_min_size(
45추가: egui::Pos2::ZERO,
46추가: egui::vec2(760.0, 540.0),
47추가: )),
48추가: time: Some(self.time),
49추가: events,
50추가: ..Default::default()
51추가: },
52추가: |ui| self.app.show(ui),
53추가: );
54추가: output.textures_delta.clear();
55추가: output
56추가: }
57추가: fn row(&mut self, path: &str) -> egui::Rect {
58추가: self.frame(egui::Modifiers::NONE, vec![]);
59추가: self.ctx
60추가: .read_response(egui::Id::unique(("archive-row", path)))
61추가: .unwrap()
62추가: .rect
63추가: }
64추가: fn body(&self) -> egui::Rect {
65추가: self.ctx
66추가: .read_response(egui::Id::unique("archive-list"))
67추가: .unwrap()
68추가: .rect
69추가: }
70추가: fn pointer(
71추가: &mut self,
72추가: point: egui::Pos2,
73추가: pressed: bool,
74추가: modifiers: egui::Modifiers,
75추가: ) -> egui::FullOutput {
76추가: self.frame(
77추가: modifiers,
78추가: vec![
79추가: egui::Event::PointerMoved(point),
80추가: egui::Event::PointerButton {
81추가: pos: point,
82추가: button: egui::PointerButton::Primary,
83추가: pressed,
84추가: modifiers,
85추가: },
86추가: ],
87추가: )
88추가: }
89추가: fn click(&mut self, path: &str, modifiers: egui::Modifiers) {
90추가: self.time += 1.0;
91추가: let point = self.row(path).center();
92추가: self.pointer(point, true, modifiers);
93추가: self.pointer(point, false, modifiers);
94추가: self.frame(egui::Modifiers::NONE, vec![]);
95추가: }
96추가: fn key(&mut self, key: egui::Key, modifiers: egui::Modifiers) {
97추가: self.frame(
98추가: modifiers,
99추가: vec![egui::Event::Key {
100추가: key,
101추가: physical_key: None,
102추가: pressed: true,
103추가: repeat: false,
104추가: modifiers,
105추가: }],
106추가: );
107추가: self.frame(
108추가: modifiers,
109추가: vec![egui::Event::Key {
110추가: key,
111추가: physical_key: None,
112추가: pressed: false,
113추가: repeat: false,
114추가: modifiers,
115추가: }],
116추가: );
117추가: }
118추가: #[track_caller]
119추가: fn selected(&self, ids: &[u32]) {
120추가: assert_eq!(self.app.model.selected, ids.iter().copied().collect());
121추가: }
122추가: }
123추가: fn explorer_ctrl() -> egui::Modifiers {
124추가: egui::Modifiers {
125추가: ctrl: true,
126추가: ..egui::Modifiers::NONE
127추가: }
128추가: }
129추가: fn explorer_shift() -> egui::Modifiers {
130추가: egui::Modifiers {
131추가: shift: true,
132추가: ..egui::Modifiers::NONE
133추가: }
134추가: }
135추가:
136추가: #[test]
137추가: fn explorer_click_ctrl_shift_and_blank_match_visible_selection_count() {
138추가: let scratch = Folder::new();
139추가: let mut s = Explorer::new(&scratch);
140추가: s.click("alpha.txt", egui::Modifiers::NONE);
141추가: s.selected(&[1]);
142추가: s.click("beta.txt", explorer_ctrl());
143추가: s.selected(&[1, 2]);
144추가: s.click("alpha.txt", explorer_ctrl());
145추가: s.selected(&[2]);
146추가: s.click("alpha.txt", egui::Modifiers::NONE);
147추가: s.click("gamma.txt", explorer_shift());
148추가: s.selected(&[1, 2, 3]);
149추가: let output = s.frame(egui::Modifiers::NONE, vec![]);
150추가: assert!(
151추가: layout_text(&output)
152추가: .iter()
153추가: .any(|(text, _, _)| text == "선택 3개")
154추가: );
155추가: s.click(
156추가: "omega.txt",
157추가: egui::Modifiers {
158추가: ctrl: true,
159추가: shift: true,
160추가: ..egui::Modifiers::NONE
161추가: },
162추가: );
163추가: s.selected(&[1, 2, 3, 4]);
164추가: s.click("docs", egui::Modifiers::NONE);
165추가: s.selected(&[0, 5]);
166추가: let output = s.frame(egui::Modifiers::NONE, vec![]);
167추가: assert!(
168추가: layout_text(&output)
169추가: .iter()
170추가: .any(|(text, _, _)| text == "선택 1개")
171추가: );
172추가: let point = egui::pos2(100.0, s.body().bottom() - 4.0);
173추가: s.pointer(point, true, explorer_ctrl());
174추가: s.pointer(point, false, explorer_ctrl());
175추가: s.selected(&[0, 5]);
176추가: s.pointer(point, true, egui::Modifiers::NONE);
177추가: s.pointer(point, false, egui::Modifiers::NONE);
178추가: s.selected(&[]);
179추가: }
180추가:
181추가: #[test]
182추가: fn explorer_keyboard_ranges_enter_backspace_and_escape_are_scoped_to_the_list() {
183추가: let scratch = Folder::new();
184추가: let mut s = Explorer::new(&scratch);
185추가: s.ctx
186추가: .memory_mut(|m| m.request_focus(egui::Id::unique("archive-list")));
187추가: s.frame(egui::Modifiers::NONE, vec![]);
188추가: s.key(egui::Key::ArrowDown, egui::Modifiers::NONE);
189추가: s.selected(&[0, 5]);
190추가: s.key(egui::Key::ArrowDown, explorer_shift());
191추가: s.selected(&[0, 1, 5]);
192추가: s.key(egui::Key::ArrowUp, explorer_shift());
193추가: s.selected(&[0, 5]);
194추가: s.key(egui::Key::ArrowDown, explorer_shift());
195추가: s.selected(&[0, 1, 5]);
196추가: s.key(egui::Key::A, explorer_ctrl());
197추가: s.selected(&[0, 1, 2, 3, 4, 5]);
198추가: s.key(egui::Key::Escape, egui::Modifiers::NONE);
199추가: s.selected(&[]);
200추가: s.key(egui::Key::ArrowUp, egui::Modifiers::NONE);
201추가: s.selected(&[0, 5]);
202추가: s.key(egui::Key::Enter, egui::Modifiers::NONE);
203추가: s.selected(&[]);
204추가: assert!(
205추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
206추가: .iter()
207추가: .any(|(text, _, _)| text == "child.txt")
208추가: );
209추가: s.key(egui::Key::Backspace, egui::Modifiers::NONE);
210추가: s.selected(&[]);
211추가: assert!(
212추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
213추가: .iter()
214추가: .any(|(text, _, _)| text == "alpha.txt")
215추가: );
216추가: s.ctx
217추가: .memory_mut(|m| m.request_focus(egui::Id::unique("archive-search")));
218추가: s.key(egui::Key::A, explorer_ctrl());
219추가: s.selected(&[]);
220추가: s.key(egui::Key::Enter, egui::Modifiers::NONE);
221추가: assert_eq!(s.factory.state.borrow().starts.len(), 1);
222추가: }
223추가:
224추가: #[test]
225추가: fn explorer_double_click_opens_only_folders_and_resets_selection() {
226추가: let scratch = Folder::new();
227추가: let mut s = Explorer::new(&scratch);
228추가: let point = s.row("alpha.txt").center();
229추가: for _ in 0..2 {
230추가: s.pointer(point, true, egui::Modifiers::NONE);
231추가: s.pointer(point, false, egui::Modifiers::NONE);
232추가: }
233추가: s.selected(&[1]);
234추가: assert_eq!(s.factory.state.borrow().starts.len(), 1);
235추가: s.time += 1.0;
236추가: let point = s.row("docs").center();
237추가: for _ in 0..2 {
238추가: s.pointer(point, true, egui::Modifiers::NONE);
239추가: s.pointer(point, false, egui::Modifiers::NONE);
240추가: }
241추가: s.selected(&[]);
242추가: assert!(
243추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
244추가: .iter()
245추가: .any(|(text, _, _)| text == "child.txt")
246추가: );
247추가: }
248추가:
249추가: #[test]
250추가: fn explorer_marquee_selects_intersections_and_ctrl_adds_with_an_opaque_blue_rectangle() {
251추가: let scratch = Folder::new();
252추가: let mut s = Explorer::new(&scratch);
253추가: s.click("docs", egui::Modifiers::NONE);
254추가: let row = s.row("alpha.txt");
255추가: let start = egui::pos2(row.right() + 8.0, s.body().bottom() - 5.0);
256추가: let end = egui::pos2(150.0, row.top() + 2.0);
257추가: s.pointer(start, true, explorer_ctrl());
258추가: let output = s.frame(explorer_ctrl(), vec![egui::Event::PointerMoved(end)]);
259추가: s.selected(&[0, 1, 2, 3, 4, 5]);
260추가: assert!(output.shapes.iter().any(|shape| matches!(&shape.shape, Shape::Rect(rect) if rect.fill == zipelo_ui_memory_app::archive_theme::BLUE && rect.rect.height() > 100.0 && rect.fill.a() == 255)));
261추가: s.pointer(end, false, explorer_ctrl());
262추가: s.selected(&[0, 1, 2, 3, 4, 5]);
263추가: let start = egui::pos2(row.right() + 8.0, s.body().bottom() - 5.0);
264추가: s.pointer(start, true, egui::Modifiers::NONE);
265추가: s.frame(egui::Modifiers::NONE, vec![egui::Event::PointerMoved(end)]);
266추가: s.pointer(end, false, egui::Modifiers::NONE);
267추가: s.selected(&[1, 2, 3, 4]);
268추가: }
269추가:
270추가: #[test]
271추가: fn explorer_marquee_autoscrolls_thousands_of_rows_without_rendering_them_all() {
272추가: let scratch = Folder::new();
273추가: let mut s = Explorer::new(&scratch);
274추가: s.app.model.entries = (0..5000)
275추가: .map(|id| Entry {
276추가: id,
277추가: name: format!("item-{id:05}.txt"),
278추가: kind: Kind::File,
279추가: bytes: Some(1),
280추가: packed: None,
281추가: encrypted: false,
282추가: })
283추가: .collect();
284추가: s.frame(egui::Modifiers::NONE, vec![]);
285추가: let row = s.row("item-00000.txt");
286추가: let start = egui::pos2(row.right() + 8.0, row.center().y);
287추가: s.pointer(start, true, egui::Modifiers::NONE);
288추가: let end = egui::pos2(100.0, s.body().bottom() + 45.0);
289추가: s.frame(egui::Modifiers::NONE, vec![egui::Event::PointerMoved(end)]);
290추가: let started = std::time::Instant::now();
291추가: let mut output = s.frame(egui::Modifiers::NONE, vec![]);
292추가: for _ in 0..40 {
293추가: output = s.frame(egui::Modifiers::NONE, vec![]);
294추가: }
295추가: assert!(started.elapsed() < std::time::Duration::from_secs(5));
296추가: assert!(
297추가: s.app.model.selected.len() > 20,
298추가: "{:?}",
299추가: s.app.model.selected
300추가: );
301추가: assert!(
302추가: layout_text(&output)
303추가: .iter()
304추가: .filter(|(text, _, _)| text.starts_with("item-"))
305추가: .count()
306추가: < 30
307추가: );
308추가: assert!(
309추가: layout_text(&output)
310추가: .iter()
311추가: .filter(|(text, _, _)| text.starts_with("item-"))
312추가: .all(|(text, _, _)| text != "item-00000.txt")
313추가: );
314추가: let first_visible = |output: &egui::FullOutput| {
315추가: layout_text(output)
316추가: .into_iter()
317추가: .filter_map(|(text, _, _)| {
318추가: text.strip_prefix("item-")
319추가: .and_then(|name| name.strip_suffix(".txt"))
320추가: .and_then(|number| number.parse::<u32>().ok())
321추가: })
322추가: .min()
323추가: .unwrap()
324추가: };
325추가: let down = first_visible(&output);
326추가: let up = egui::pos2(100.0, s.body().top() - 45.0);
327추가: s.frame(egui::Modifiers::NONE, vec![egui::Event::PointerMoved(up)]);
328추가: for _ in 0..12 {
329추가: output = s.frame(egui::Modifiers::NONE, vec![]);
330추가: }
331추가: assert!(first_visible(&output) < down);
332추가: s.pointer(up, false, egui::Modifiers::NONE);
333추가: let selected = s.app.model.selected.clone();
334추가: s.frame(egui::Modifiers::NONE, vec![egui::Event::PointerMoved(end)]);
335추가: assert_eq!(s.app.model.selected, selected);
336추가: }
337추가:
338추가: #[test]
339추가: fn explorer_selected_folder_and_empty_selection_reach_the_exact_extraction_request() {
340추가: let scratch = Folder::new();
341추가: let mut s = Explorer::new(&scratch);
342추가: s.click("docs", egui::Modifiers::NONE);
343추가: s.app.choose_destination(scratch.0.clone());
344추가: assert!(s.app.begin_extract());
345추가: assert!(
346추가: matches!(s.factory.state.borrow().starts.last(), Some(Start::Extract { selection: Selection::EntryIds(ids), .. }) if ids.iter().copied().collect::<BTreeSet<_>>() == [0,5].into_iter().collect())
347추가: );
348추가: for _ in 0..30 {
349추가: s.frame(egui::Modifiers::NONE, vec![]);
350추가: }
351추가: s.app.model.selected.clear();
352추가: assert!(s.app.begin_extract());
353추가: assert!(matches!(
354추가: s.factory.state.borrow().starts.last(),
355추가: Some(Start::Extract {
356추가: selection: Selection::All,
357추가: ..
358추가: })
359추가: ));
360추가: }
361추가:
362추가: #[test]
363추가: fn explorer_fast_forward_marquee_uses_the_original_press_position() {
364추가: let scratch = Folder::new();
365추가: let mut s = Explorer::new(&scratch);
366추가: let first = s.row("docs");
367추가: let last = s.row("beta.txt");
368추가: let start = egui::pos2(first.right() + 8.0, first.top() + 2.0);
369추가: let end = egui::pos2(100.0, last.bottom() - 1.0);
370추가: s.frame(
371추가: egui::Modifiers::NONE,
372추가: vec![
373추가: egui::Event::PointerMoved(start),
374추가: egui::Event::PointerButton {
375추가: pos: start,
376추가: button: egui::PointerButton::Primary,
377추가: pressed: true,
378추가: modifiers: egui::Modifiers::NONE,
379추가: },
380추가: egui::Event::PointerMoved(end),
381추가: ],
382추가: );
383추가: s.selected(&[0, 1, 2, 5]);
384추가: s.pointer(end, false, egui::Modifiers::NONE);
385추가: s.selected(&[0, 1, 2, 5]);
386추가: }
수정tests/rust-app-ui/presentation.rs+1-0
@@ -903,6 +903,7 @@ mod widgets {
903903 }
904904 include!("toolbar.rs");
905905 include!("long_layout.rs");
906추가: include!("explorer_selection.rs");
906907}
907908
908909#[cfg(feature = "ui")]
수정tests/rust-app-ui/toolbar.rs+3-2
@@ -295,7 +295,7 @@ fn conflict_native_dialog_cancel_and_retry_preserve_selection_and_existing_files
295295}
296296
297297#[test]
298삭제: fn excluding_a_child_after_folder_selection_does_not_restore_it_during_extraction() {
298추가: fn folder_navigation_clears_parent_selection_and_extracts_only_new_selection() {
299299 let scratch = Folder::new();
300300 let factory = FakeFactory::default();
301301 let mut app = loaded(&scratch, &factory);
@@ -315,11 +315,12 @@ fn excluding_a_child_after_folder_selection_does_not_restore_it_during_extractio
315315 .to_vec();
316316 app.model.selected = [0, 1, 2].into_iter().collect();
317317 app.browse_folder("docs");
318추가: assert!(app.model.selected.is_empty());
318319 let dialogs = TestDialogs::default();
319320 dialogs.0.borrow_mut().answers.push_back(Some(vec![scratch.0.clone()]));
320321 app.set_dialogs(Box::new(dialogs));
321322 let ctx = egui::Context::default();
322삭제: policy_click(&ctx, &mut app, "excluded.txt");
323추가: policy_click(&ctx, &mut app, "retained.txt");
323324 assert_eq!(app.model.selected, [2].into_iter().collect());
324325 policy_click(&ctx, &mut app, "압축해제");
325326 assert!(matches!(
수정tests/ui-redesign/capture.py+14-1
@@ -37,6 +37,8 @@ def capture(binary, variant, state, output, environment, width, height):
3737 environment["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path={endpoint}"
3838 environment.pop("DBUS_STARTER_ADDRESS", None)
3939 mode = {
40추가: "explorer-selected": "toolbar-folder",
41추가: "explorer-marquee": "toolbar-folder",
4042 "picker": "opened",
4143 "selected-empty": "opened",
4244 "dialog-unavailable": "toolbar-root",
@@ -93,12 +95,23 @@ def capture(binary, variant, state, output, environment, width, height):
9395 command(["xdotool", "type", "--clearmodifiers", "--delay", "0", "fixture-password"], environment)
9496 command(["xdotool", "key", "Tab", "Tab"], environment)
9597 command(["xdotool", "type", "--clearmodifiers", "--delay", "0", "different"], environment)
96삭제: command(["xdotool", "mousemove", "--window", window, "2", "2"], environment)
98추가: if state == "explorer-selected":
99추가: click(150, 235)
100추가: command(["xdotool", "keydown", "ctrl"], environment)
101추가: click(150, 323)
102추가: command(["xdotool", "keyup", "ctrl"], environment)
103추가: if state == "explorer-marquee":
104추가: command(["xdotool", "mousemove", "--window", window, str(width - 20), str(height - 80), "mousedown", "1"], environment)
105추가: time.sleep(0.2)
106추가: command(["xdotool", "mousemove", "--window", window, "250", "300"], environment)
107추가: else:
108추가: command(["xdotool", "mousemove", "--window", window, "2", "2"], environment)
97109 time.sleep(0.3)
98110 destination = output / f"{state}.png"
99111 command(["import", "-window", window, str(destination)], environment)
100112 return {"state": state, "path": str(destination.relative_to(ROOT)), "width": width, "height": height}
101113 finally:
114추가: subprocess.run(["xdotool", "mouseup", "1"], env=environment, check=False)
102115 stop(app)
103116
104117
추가tests/ui-redesign/screenshots/explorer-selection/capture.json+14-0
@@ -0,0 +1,14 @@
1추가: [
2추가: {
3추가: "state": "explorer-selected",
4추가: "path": "tests/ui-redesign/screenshots/explorer-selection/explorer-selected.png",
5추가: "width": 1060,
6추가: "height": 720
7추가: },
8추가: {
9추가: "state": "explorer-marquee",
10추가: "path": "tests/ui-redesign/screenshots/explorer-selection/explorer-marquee.png",
11추가: "width": 1060,
12추가: "height": 720
13추가: }
14추가: ]
추가tests/ui-redesign/screenshots/explorer-selection/explorer-marquee.png

바이너리 파일이라 Diff를 표시하지 않아요.

파일 내려받기
추가tests/ui-redesign/screenshots/explorer-selection/explorer-selected.png

바이너리 파일이라 Diff를 표시하지 않아요.

파일 내려받기