파일 목록에 탐색기 방식 선택을 적용함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
9a6dc1baa501b1c32cabb42e833f977e596170d0- 부모
- 784e0a9
변경된 파일 9개
+825-109| @@ -11,6 +11,15 @@ use std::{ | ||
| 11 | 11 | path::{Path, PathBuf}, |
| 12 | 12 | }; |
| 13 | 13 | |
| 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 | 추가: | |
| 14 | 23 | pub struct ArchiveApp { |
| 15 | 24 | pub model: Model, |
| 16 | 25 | factory: Box<dyn Factory>, |
| @@ -32,6 +41,11 @@ pub struct ArchiveApp { | ||
| 32 | 41 | dialogs: Box<dyn Dialogs>, |
| 33 | 42 | folder: String, |
| 34 | 43 | search: String, |
| 44 | 추가: list_anchor: Option<usize>, | |
| 45 | 추가: list_cursor: Option<usize>, | |
| 46 | 추가: list_offset: f32, | |
| 47 | 추가: list_focused: bool, | |
| 48 | 추가: marquee: Option<Marquee>, | |
| 35 | 49 | last_request: Option<Start>, |
| 36 | 50 | targets: Option<BTreeSet<String>>, |
| 37 | 51 | directories: BTreeSet<String>, |
| @@ -65,6 +79,11 @@ impl ArchiveApp { | ||
| 65 | 79 | dialogs: Box::new(NativeDialogs), |
| 66 | 80 | folder: String::new(), |
| 67 | 81 | search: String::new(), |
| 82 | 추가: list_anchor: None, | |
| 83 | 추가: list_cursor: None, | |
| 84 | 추가: list_offset: 0.0, | |
| 85 | 추가: list_focused: false, | |
| 86 | 추가: marquee: None, | |
| 68 | 87 | last_request: None, |
| 69 | 88 | targets: None, |
| 70 | 89 | directories: BTreeSet::new(), |
| @@ -87,6 +106,7 @@ impl ArchiveApp { | ||
| 87 | 106 | pub fn browse_folder(&mut self, folder: &str) { |
| 88 | 107 | self.folder = folder.trim_matches('/').to_owned(); |
| 89 | 108 | self.search.clear(); |
| 109 | 추가: self.clear_list_selection(); | |
| 90 | 110 | } |
| 91 | 111 | |
| 92 | 112 | pub fn show_create(&mut self, encrypted: bool) { |
| @@ -116,6 +136,7 @@ impl ArchiveApp { | ||
| 116 | 136 | self.selected_only = false; |
| 117 | 137 | self.folder.clear(); |
| 118 | 138 | self.search.clear(); |
| 139 | 추가: self.clear_list_selection(); | |
| 119 | 140 | self.targets = None; |
| 120 | 141 | self.directories.clear(); |
| 121 | 142 | self.start(Start::List { archive }); |
| @@ -185,6 +206,7 @@ impl ArchiveApp { | ||
| 185 | 206 | } |
| 186 | 207 | |
| 187 | 208 | pub fn begin_extract(&mut self) -> bool { |
| 209 | 추가: self.selected_only = !self.model.selected.is_empty(); | |
| 188 | 210 | if !self.model.can_extract() || (self.selected_only && self.model.selected.is_empty()) { |
| 189 | 211 | return false; |
| 190 | 212 | } |
| @@ -549,7 +571,14 @@ impl ArchiveApp { | ||
| 549 | 571 | ui.with_layout(Layout::right_to_left(Align::Center), |ui| { |
| 550 | 572 | theme::bounded_text( |
| 551 | 573 | 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 | 추가: ), | |
| 553 | 582 | width, |
| 554 | 583 | ); |
| 555 | 584 | }); |
| @@ -697,86 +726,187 @@ impl ArchiveApp { | ||
| 697 | 726 | .hint_text("파일 찾기"), |
| 698 | 727 | ); |
| 699 | 728 | theme::focus(&search); |
| 729 | 추가: if search.changed() { | |
| 730 | 추가: self.clear_list_selection(); | |
| 731 | 추가: } | |
| 700 | 732 | }); |
| 701 | 733 | }); |
| 702 | 734 | 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); | |
| 709 | 737 | 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); | |
| 729 | 739 | theme::column_label(ui, RichText::new("이름").strong(), name_width, Align::Min); |
| 730 | 740 | theme::column_label(ui, "크기", 96.0, Align::Max); |
| 731 | 741 | theme::column_label(ui, "암호", 64.0, Align::Min); |
| 732 | 742 | }); |
| 733 | 743 | 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 | 추가: ) | |
| 741 | 770 | }); |
| 742 | 삭제: return; | |
| 743 | 771 | } |
| 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() | |
| 745 | 776 | .id_salt("archive-rows") |
| 746 | 777 | .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) { | |
| 771 | 822 | 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 | 삭제: ); | |
| 778 | 823 | } |
| 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(); | |
| 779 | 843 | } |
| 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); | |
| 780 | 910 | theme::icon( |
| 781 | 911 | ui, |
| 782 | 912 | if row.directory { |
| @@ -786,41 +916,7 @@ impl ArchiveApp { | ||
| 786 | 916 | }, |
| 787 | 917 | 20.0, |
| 788 | 918 | ); |
| 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); | |
| 824 | 920 | theme::column_label( |
| 825 | 921 | ui, |
| 826 | 922 | if row.directory { |
| @@ -836,15 +932,161 @@ impl ArchiveApp { | ||
| 836 | 932 | if row.encrypted { |
| 837 | 933 | theme::icon(ui, Icon::Lock, 16.0); |
| 838 | 934 | } |
| 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), | |
| 845 | 967 | ); |
| 968 | 추가: ui.painter() | |
| 969 | 추가: .with_clip_rect(clip) | |
| 970 | 추가: .rect_filled(rect, 0, theme::BLUE); | |
| 846 | 971 | } |
| 847 | 972 | }); |
| 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); | |
| 848 | 1090 | } |
| 849 | 1091 | |
| 850 | 1092 | fn result_visible(&self) -> bool { |
| @@ -228,3 +228,62 @@ fn auto_destination_is_private_under_desktop_umask() { | ||
| 228 | 228 | ); |
| 229 | 229 | assert_reaped(&observed); |
| 230 | 230 | } |
| 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 | 추가: } |
| @@ -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 | 추가: } |
| @@ -903,6 +903,7 @@ mod widgets { | ||
| 903 | 903 | } |
| 904 | 904 | include!("toolbar.rs"); |
| 905 | 905 | include!("long_layout.rs"); |
| 906 | 추가: include!("explorer_selection.rs"); | |
| 906 | 907 | } |
| 907 | 908 | |
| 908 | 909 | #[cfg(feature = "ui")] |
| @@ -295,7 +295,7 @@ fn conflict_native_dialog_cancel_and_retry_preserve_selection_and_existing_files | ||
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | #[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() { | |
| 299 | 299 | let scratch = Folder::new(); |
| 300 | 300 | let factory = FakeFactory::default(); |
| 301 | 301 | let mut app = loaded(&scratch, &factory); |
| @@ -315,11 +315,12 @@ fn excluding_a_child_after_folder_selection_does_not_restore_it_during_extractio | ||
| 315 | 315 | .to_vec(); |
| 316 | 316 | app.model.selected = [0, 1, 2].into_iter().collect(); |
| 317 | 317 | app.browse_folder("docs"); |
| 318 | 추가: assert!(app.model.selected.is_empty()); | |
| 318 | 319 | let dialogs = TestDialogs::default(); |
| 319 | 320 | dialogs.0.borrow_mut().answers.push_back(Some(vec![scratch.0.clone()])); |
| 320 | 321 | app.set_dialogs(Box::new(dialogs)); |
| 321 | 322 | let ctx = egui::Context::default(); |
| 322 | 삭제: policy_click(&ctx, &mut app, "excluded.txt"); | |
| 323 | 추가: policy_click(&ctx, &mut app, "retained.txt"); | |
| 323 | 324 | assert_eq!(app.model.selected, [2].into_iter().collect()); |
| 324 | 325 | policy_click(&ctx, &mut app, "압축해제"); |
| 325 | 326 | assert!(matches!( |
| @@ -37,6 +37,8 @@ def capture(binary, variant, state, output, environment, width, height): | ||
| 37 | 37 | environment["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path={endpoint}" |
| 38 | 38 | environment.pop("DBUS_STARTER_ADDRESS", None) |
| 39 | 39 | mode = { |
| 40 | 추가: "explorer-selected": "toolbar-folder", | |
| 41 | 추가: "explorer-marquee": "toolbar-folder", | |
| 40 | 42 | "picker": "opened", |
| 41 | 43 | "selected-empty": "opened", |
| 42 | 44 | "dialog-unavailable": "toolbar-root", |
| @@ -93,12 +95,23 @@ def capture(binary, variant, state, output, environment, width, height): | ||
| 93 | 95 | command(["xdotool", "type", "--clearmodifiers", "--delay", "0", "fixture-password"], environment) |
| 94 | 96 | command(["xdotool", "key", "Tab", "Tab"], environment) |
| 95 | 97 | 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) | |
| 97 | 109 | time.sleep(0.3) |
| 98 | 110 | destination = output / f"{state}.png" |
| 99 | 111 | command(["import", "-window", window, str(destination)], environment) |
| 100 | 112 | return {"state": state, "path": str(destination.relative_to(ROOT)), "width": width, "height": height} |
| 101 | 113 | finally: |
| 114 | 추가: subprocess.run(["xdotool", "mouseup", "1"], env=environment, check=False) | |
| 102 | 115 | stop(app) |
| 103 | 116 | |
| 104 | 117 |
| @@ -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 | 추가: ] |
바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기