team-ljyzipelo

공개

ZIP 만들기를 폴더 선택으로 시작하는 별도 창으로 바꿈

- 압축하기를 누르면 운영체제 폴더 선택 창을 먼저 열고, 고른 폴더로 ZIP 만들기
  창을 엶. ZIP 안에는 지금처럼 그 폴더가 최상위 폴더로 들어감.
- ZIP 만들기는 메인 창 안 모달이 아니라 진행 창처럼 부모 창 가운데에 열리고
  부모 창을 따라가는 별도 창임. 따라가기 로직을 WorkWindow::builder로 합침.
  별도 창을 만들 수 없는 환경(시험)에서만 메인 창 안 모달로 그림.
- 끌어 놓기 영역과 파일/폴더 추가 버튼을 없애고, 고른 폴더 안을 메인 목록과
  같은 행 모양(entry_cells 공용)으로 보여 줌. 폴더를 두 번 누르면 들어가고
  위로 버튼으로 나옴. egui가 프레임을 다시 그릴 때 두 번 누름 정보가 사라지는
  경우가 있어 같은 폴더를 다른 프레임에서 0.4초 안에 누르면 두 번 누름으로 봄.
- 암호화 제목과 자물쇠 아이콘을 없애고 "암호로 보호하기" 체크박스만 둠.
  체크하면 아래에 암호와 암호 확인 칸이 나오고, 두 암호가 같아야 만들 수 있음.
  해제하면 입력한 암호를 지움.
- 암호는 창에서 받아 두었다가 작업자가 요청하면 바로 넘기고 지움. 그래서
  만들기 중의 "ZIP 암호 설정" 창은 더 나오지 않음. 암호 ZIP 다시 시도는
  ZIP 만들기 창을 다시 열어 암호를 받음.

시험: 새 ZIP 만들기 창 시험 3개(목록·폴더 이동·폴더째 담기, 암호 칸과 자동
전달·입력 암호 원문 일치, 다시 시도), 이전 대화 상자 흐름 시험을 새 흐름으로
바꿈. 실제 작업자 연동의 암호 ZIP 만들기 시험도 창에서 암호를 넣는 흐름으로 바꿈.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
작성자
LeeJunyoung
작성 시각
커밋
3d56b034c89716531ca0ffe7ef9ac5a1d1c0c926
부모
9cc5f60
이 시점의 파일 보기

변경된 파일 9개

+875-293
수정experiments/rust-ui-memory-app/src/archive_screen.rs+555-218
@@ -16,6 +16,52 @@ use std::{
1616};
1717
1818const WORK_WIDTH: f32 = 480.0;
19추가: const CREATE_WIDTH: f32 = 560.0;
20추가: /// 처음 열 때의 높이. 그다음부터는 내용 높이에 맞춤.
21추가: const CREATE_MIN_HEIGHT: f32 = 300.0;
22추가: const CREATE_LIST_HEIGHT: f32 = 288.0;
23추가:
24추가: /// ZIP 만들기 창 목록의 한 행. 디스크에서 읽은 파일이나 폴더임.
25추가: #[derive(Clone)]
26추가: struct SourceRow {
27추가: name: String,
28추가: directory: bool,
29추가: bytes: Option<u64>,
30추가: }
31추가:
32추가: fn source_row(path: &Path) -> SourceRow {
33추가: let metadata = std::fs::symlink_metadata(path).ok();
34추가: SourceRow {
35추가: name: path
36추가: .file_name()
37추가: .map(|name| name.to_string_lossy().into_owned())
38추가: .unwrap_or_default(),
39추가: // 심볼릭 링크는 따라가지 않으므로 폴더로 보이지 않음.
40추가: directory: metadata.as_ref().is_some_and(|m| m.is_dir()),
41추가: bytes: metadata.filter(|m| m.is_file()).map(|m| m.len()),
42추가: }
43추가: }
44추가:
45추가: /// 폴더 안 항목을 메인 목록과 같은 순서(폴더 먼저, 이름순)로 읽음. 읽지 못하면 None.
46추가: fn read_source_dir(dir: &Path) -> Option<std::rc::Rc<Vec<SourceRow>>> {
47추가: let mut rows = std::fs::read_dir(dir)
48추가: .ok()?
49추가: .filter_map(Result::ok)
50추가: .map(|entry| source_row(&entry.path()))
51추가: .collect::<Vec<_>>();
52추가: rows.sort_by(|a, b| {
53추가: b.directory
54추가: .cmp(&a.directory)
55추가: .then_with(|| a.name.cmp(&b.name))
56추가: });
57추가: Some(std::rc::Rc::new(rows))
58추가: }
59추가:
60추가: /// 덮어쓴 뒤 버려 메모리에 암호가 남지 않게 함.
61추가: fn wipe(value: &mut String) {
62추가: let mut bytes = std::mem::take(value).into_bytes();
63추가: bytes.fill(0);
64추가: }
1965const WORK_MIN_HEIGHT: f32 = 96.0;
2066const WORK_MAX_HEIGHT: f32 = 520.0;
2167const WORK_RESULT_MAX_HEIGHT: f32 = 220.0;
@@ -46,6 +92,84 @@ impl Default for WorkWindow {
4692 }
4793}
4894
95추가: impl WorkWindow {
96추가: /// 부모 창 가운데에 열고, 사용자가 옮긴 상대 위치를 유지한 채 부모 창을 따라가게 함.
97추가: /// 앱을 쓰는 동안에만 부모 위에 두고, 처음 위치를 담은 ViewportBuilder를 돌려줌.
98추가: /// Wayland처럼 창 위치를 알 수 없으면 위치는 창 관리자에 맡김.
99추가: fn builder(
100추가: &mut self,
101추가: ctx: &egui::Context,
102추가: id: egui::ViewportId,
103추가: size: egui::Vec2,
104추가: title: &str,
105추가: decorations: bool,
106추가: ) -> egui::ViewportBuilder {
107추가: let (parent, parent_focused, now) = ctx.input(|i| {
108추가: (
109추가: i.viewport().outer_rect,
110추가: i.viewport().focused.unwrap_or(false),
111추가: i.time,
112추가: )
113추가: });
114추가: let (child, child_focused) = ctx.input(|i| {
115추가: i.raw.viewports.get(&id).map_or((None, false), |v| {
116추가: (v.outer_rect, v.focused.unwrap_or(false))
117추가: })
118추가: });
119추가: if !self.open {
120추가: // 처음 열 때 부모 창 가운데에 둠. 닫혔다 다시 열 때는 기억한 위치에 둠.
121추가: self.open = true;
122추가: self.initial = parent.map(|p| match self.offset {
123추가: Some(offset) => (p.min + offset).round(),
124추가: None => (p.center() - size / 2.0).round(),
125추가: });
126추가: self.offset = self.initial.zip(parent).map(|(c, p)| c - p.min);
127추가: self.parent = parent.map(|p| p.min);
128추가: self.expected = self.initial;
129추가: self.settle_until = now + 0.5;
130추가: }
131추가: if let (Some(parent), Some(child)) = (parent, child) {
132추가: let parent_moved = self.parent.is_some_and(|p| (p - parent.min).length() > 0.5);
133추가: let settled = self
134추가: .expected
135추가: .is_some_and(|e| (child.min - e).length() <= 2.0);
136추가: if settled || now >= self.settle_until {
137추가: self.settle_until = 0.0;
138추가: }
139추가: if parent_moved {
140추가: if let Some(offset) = self.offset {
141추가: let target = (parent.min + offset).round();
142추가: ctx.send_viewport_cmd_to(id, egui::ViewportCommand::OuterPosition(target));
143추가: self.expected = Some(target);
144추가: self.settle_until = now + 0.5;
145추가: }
146추가: } else if self.settle_until == 0.0 && !settled {
147추가: // 사용자가 자식 창을 옮긴 위치를 부모 기준으로 기억함.
148추가: self.offset = Some(child.min - parent.min);
149추가: self.expected = Some(child.min);
150추가: }
151추가: self.parent = Some(parent.min);
152추가: }
153추가: let mut builder = egui::ViewportBuilder::default()
154추가: .with_title(title)
155추가: .with_decorations(decorations)
156추가: .with_inner_size(size)
157추가: .with_resizable(false)
158추가: .with_minimize_button(false)
159추가: .with_maximize_button(false)
160추가: .with_taskbar(false)
161추가: .with_window_level(if parent_focused || child_focused {
162추가: egui::WindowLevel::AlwaysOnTop
163추가: } else {
164추가: egui::WindowLevel::Normal
165추가: });
166추가: if let Some(position) = self.initial {
167추가: builder = builder.with_position(position);
168추가: }
169추가: builder
170추가: }
171추가: }
172추가:
49173struct Marquee {
50174 // 스크롤 중에도 시작점을 목록 좌표로 유지함.
51175 origin: egui::Pos2,
@@ -77,6 +201,17 @@ pub struct ArchiveApp {
77201 dialogs: Box<dyn Dialogs>,
78202 picker: Option<(Purpose, std::sync::mpsc::Receiver<DialogAnswer>)>,
79203 work: WorkWindow,
204추가: create_win: WorkWindow,
205추가: /// ZIP 만들기 창에서 보고 있는 폴더 (고른 폴더 기준 상대 경로, 비어 있으면 최상위).
206추가: create_folder: String,
207추가: create_listing: Option<(PathBuf, Option<std::rc::Rc<Vec<SourceRow>>>)>,
208추가: /// 마지막으로 누른 폴더 행 (이름, 프레임 번호, 시각). 두 번 누름을 직접 판단할 때 씀.
209추가: create_last_click: Option<(String, u64, f64)>,
210추가: zip_password: String,
211추가: zip_password_confirm: String,
212추가: zip_password_visible: bool,
213추가: /// 작업을 시작한 뒤 작업자가 암호를 요청하면 넘길 암호. 넘기거나 작업이 끝나면 지움.
214추가: pending_zip_password: Option<String>,
80215 custom_frame: bool,
81216 release_after_move: bool,
82217 folder: String,
@@ -119,6 +254,14 @@ impl ArchiveApp {
119254 dialogs: Box::new(NativeDialogs),
120255 picker: None,
121256 work: WorkWindow::default(),
257추가: create_win: WorkWindow::default(),
258추가: create_folder: String::new(),
259추가: create_listing: None,
260추가: create_last_click: None,
261추가: zip_password: String::new(),
262추가: zip_password_confirm: String::new(),
263추가: zip_password_visible: false,
264추가: pending_zip_password: None,
122265 custom_frame: false,
123266 release_after_move: false,
124267 folder: String::new(),
@@ -174,6 +317,72 @@ impl ArchiveApp {
174317 self.password_visible = false;
175318 }
176319
320추가: fn clear_zip_password(&mut self) {
321추가: wipe(&mut self.zip_password);
322추가: wipe(&mut self.zip_password_confirm);
323추가: if let Some(mut pending) = self.pending_zip_password.take() {
324추가: wipe(&mut pending);
325추가: }
326추가: self.zip_password_visible = false;
327추가: }
328추가:
329추가: /// 암호로 보호하지 않거나, 두 암호가 같고 1~1024바이트이면 만들 수 있음.
330추가: fn zip_password_ready(&self) -> bool {
331추가: !self.aes256
332추가: || (!self.zip_password.is_empty()
333추가: && self.zip_password.len() <= 1024
334추가: && self.zip_password == self.zip_password_confirm)
335추가: }
336추가:
337추가: fn close_create(&mut self) {
338추가: self.create = false;
339추가: self.ui_error = None;
340추가: self.clear_zip_password();
341추가: self.create_win = WorkWindow::default();
342추가: }
343추가:
344추가: /// 압축하기: 묶을 폴더를 운영체제 폴더 선택 창에서 고른 뒤 ZIP 만들기 창을 엶.
345추가: fn choose_zip_folder(&mut self) {
346추가: if self.model.busy() || self.picker.is_some() {
347추가: return;
348추가: }
349추가: self.sources.clear();
350추가: self.aes256 = false;
351추가: self.clear_zip_password();
352추가: self.ui_error = None;
353추가: self.open_picker(Purpose::Folder);
354추가: }
355추가:
356추가: /// 폴더 하나를 골랐으면 그 폴더 안을 목록으로 보여 줌. 여러 항목이면 그 항목들을 보여 줌.
357추가: fn create_root(&self) -> Option<PathBuf> {
358추가: (self.sources.len() == 1 && self.sources[0].is_dir()).then(|| self.sources[0].clone())
359추가: }
360추가:
361추가: fn create_rows(&mut self) -> Option<std::rc::Rc<Vec<SourceRow>>> {
362추가: let Some(root) = self.create_root() else {
363추가: return Some(std::rc::Rc::new(
364추가: self.sources.iter().map(|path| source_row(path)).collect(),
365추가: ));
366추가: };
367추가: let dir = if self.create_folder.is_empty() {
368추가: root
369추가: } else {
370추가: root.join(&self.create_folder)
371추가: };
372추가: // 프레임마다 디스크를 읽지 않도록 보고 있는 폴더가 바뀔 때만 다시 읽음.
373추가: if self
374추가: .create_listing
375추가: .as_ref()
376추가: .is_none_or(|(path, _)| path != &dir)
377추가: {
378추가: let rows = read_source_dir(&dir);
379추가: self.create_listing = Some((dir, rows));
380추가: }
381추가: self.create_listing
382추가: .as_ref()
383추가: .and_then(|(_, rows)| rows.clone())
384추가: }
385추가:
177386 pub fn open_path(&mut self, archive: PathBuf) {
178387 if self.model.busy() {
179388 return;
@@ -255,6 +464,8 @@ impl ArchiveApp {
255464 self.sources.push(path);
256465 }
257466 }
467추가: self.create_folder.clear();
468추가: self.create_listing = None;
258469 self.create = true;
259470 }
260471
@@ -346,8 +557,14 @@ impl ArchiveApp {
346557 };
347558 sources.push((path.clone(), name.to_owned()));
348559 }
560추가: if !self.zip_password_ready() {
561추가: self.ui_error = Some("두 암호가 같은지 확인하세요".into());
562추가: return;
563추가: }
349564 self.targets = Some([self.zip_name.clone()].into_iter().collect());
350565 self.directories.clear();
566추가: // 암호는 ZIP 만들기 창에서 받아 두었다가 작업자가 요청하면 넘김.
567추가: let password = self.aes256.then(|| std::mem::take(&mut self.zip_password));
351568 if self.start(Start::CreateZip {
352569 sources,
353570 output_file,
@@ -355,6 +572,11 @@ impl ArchiveApp {
355572 aes256: self.aes256,
356573 }) {
357574 self.create = false;
575추가: self.create_win = WorkWindow::default();
576추가: self.clear_zip_password();
577추가: self.pending_zip_password = password;
578추가: } else if let Some(password) = password {
579추가: self.zip_password = password;
358580 }
359581 }
360582
@@ -500,9 +722,14 @@ impl ArchiveApp {
500722 }
501723 self.extract_selection(selection);
502724 }
503삭제: Start::CreateZip { .. } => {
725추가: Start::CreateZip { aes256, .. } => {
504726 self.create = true;
505삭제: self.begin_zip();
727추가: if aes256 {
728추가: // 암호는 보관하지 않으므로 ZIP 만들기 창에서 다시 받음.
729추가: self.aes256 = true;
730추가: } else {
731추가: self.begin_zip();
732추가: }
506733 }
507734 }
508735 }
@@ -551,6 +778,17 @@ impl ArchiveApp {
551778 }
552779 self.poll();
553780 self.poll_picker();
781추가: if self.model.challenge.is_some_and(|(_, _, encrypt)| encrypt)
782추가: && let Some(password) = self.pending_zip_password.take()
783추가: {
784추가: // ZIP 만들기 창에서 받은 암호를 작업자의 암호 요청에 바로 넘김.
785추가: self.model.password(password);
786추가: }
787추가: if !self.model.busy()
788추가: && let Some(mut pending) = self.pending_zip_password.take()
789추가: {
790추가: wipe(&mut pending);
791추가: }
554792 let challenge = self.model.challenge.map(|(id, _, _)| id);
555793 let new_challenge = challenge != self.password_challenge;
556794 if new_challenge || challenge.is_none() {
@@ -636,7 +874,7 @@ impl ArchiveApp {
636874 self.open_picker(Purpose::Open);
637875 }
638876 if theme::tool(ui, "압축하기", theme::CREATE, idle, false).clicked() {
639삭제: self.show_create(false);
877추가: self.choose_zip_folder();
640878 }
641879 if theme::tool(
642880 ui,
@@ -696,9 +934,7 @@ impl ArchiveApp {
696934 }
697935 });
698936 self.work_window(&ctx);
699삭제: if self.create && !self.model.busy() {
700삭제: self.create_dialog(&ctx);
701삭제: }
937추가: self.create_window(&ctx);
702938 if self.model.challenge.is_some() {
703939 self.password_dialog(&ctx, new_challenge);
704940 }
@@ -1049,43 +1285,26 @@ impl ArchiveApp {
10491285 if row.directory && response.double_clicked() {
10501286 open = Some(row.path.clone());
10511287 }
1052삭제: ui.scope_builder(
1053삭제: egui::UiBuilder::new()
1054삭제: .max_rect(rect.shrink2(egui::vec2(0.0, 2.0)))
1055삭제: .layout(Layout::left_to_right(Align::Center)),
1056삭제: |ui| {
1057삭제: ui.style_mut().interaction.selectable_labels = false;
1058삭제: ui.add_space(16.0);
1059삭제: theme::icon(
1060삭제: ui,
1061삭제: if row.directory {
1062삭제: Icon::Folder
1063삭제: } else {
1064삭제: Icon::File
1065삭제: },
1066삭제: 20.0,
1067삭제: );
1068삭제: // 암호가 걸린 항목은 이름 앞에 *를 붙여 표시함.
1069삭제: let name = if row.encrypted {
1070삭제: format!("*{}", row.name)
1071삭제: } else {
1072삭제: row.name.clone()
1073삭제: };
1074삭제: // 툴팁은 표시용 *를 빼고 실제 이름을 보여 줌.
1075삭제: theme::bounded_text_hover(ui, &name, &row.name, name_width);
1076삭제: theme::column_label(
1077삭제: ui,
1078삭제: if row.directory {
1079삭제: "0 B".into()
1080삭제: } else {
1081삭제: row.bytes
1082삭제: .map(present::bytes_text)
1083삭제: .unwrap_or_else(|| "—".into())
1084삭제: },
1085삭제: 96.0,
1086삭제: Align::Max,
1087삭제: );
1288추가: // 암호가 걸린 항목은 이름 앞에 *를 붙이고, 툴팁은 실제 이름을 보여 줌.
1289추가: let name = if row.encrypted {
1290추가: format!("*{}", row.name)
1291추가: } else {
1292추가: row.name.clone()
1293추가: };
1294추가: Self::entry_cells(
1295추가: ui,
1296추가: rect,
1297추가: row.directory,
1298추가: &name,
1299추가: &row.name,
1300추가: if row.directory {
1301추가: "0 B".into()
1302추가: } else {
1303추가: row.bytes
1304추가: .map(present::bytes_text)
1305추가: .unwrap_or_else(|| "—".into())
10881306 },
1307추가: name_width,
10891308 );
10901309 if active
10911310 && self.list_cursor == Some(index)
@@ -1291,58 +1510,6 @@ impl ArchiveApp {
12911510 return;
12921511 }
12931512 let id = egui::ViewportId::from_hash_of("archive-work");
1294삭제: let (parent, parent_focused, now) = ctx.input(|i| {
1295삭제: (
1296삭제: i.viewport().outer_rect,
1297삭제: i.viewport().focused.unwrap_or(false),
1298삭제: i.time,
1299삭제: )
1300삭제: });
1301삭제: let (child, child_focused) = ctx.input(|i| {
1302삭제: i.raw.viewports.get(&id).map_or((None, false), |v| {
1303삭제: (v.outer_rect, v.focused.unwrap_or(false))
1304삭제: })
1305삭제: });
1306삭제: let size = egui::vec2(WORK_WIDTH, self.work.height);
1307삭제: if !self.work.open {
1308삭제: // 처음 열 때 부모 창 가운데에 둠. 암호 입력 뒤 다시 열 때는 기억한 위치에 둠.
1309삭제: // Wayland처럼 위치를 알 수 없으면 창 관리자에 맡김.
1310삭제: self.work.open = true;
1311삭제: self.work.initial = parent.map(|p| match self.work.offset {
1312삭제: Some(offset) => (p.min + offset).round(),
1313삭제: None => (p.center() - size / 2.0).round(),
1314삭제: });
1315삭제: self.work.offset = self.work.initial.zip(parent).map(|(c, p)| c - p.min);
1316삭제: self.work.parent = parent.map(|p| p.min);
1317삭제: self.work.expected = self.work.initial;
1318삭제: self.work.settle_until = now + 0.5;
1319삭제: }
1320삭제: if let (Some(parent), Some(child)) = (parent, child) {
1321삭제: let parent_moved = self
1322삭제: .work
1323삭제: .parent
1324삭제: .is_some_and(|p| (p - parent.min).length() > 0.5);
1325삭제: let settled = self
1326삭제: .work
1327삭제: .expected
1328삭제: .is_some_and(|e| (child.min - e).length() <= 2.0);
1329삭제: if settled || now >= self.work.settle_until {
1330삭제: self.work.settle_until = 0.0;
1331삭제: }
1332삭제: if parent_moved {
1333삭제: if let Some(offset) = self.work.offset {
1334삭제: let target = (parent.min + offset).round();
1335삭제: ctx.send_viewport_cmd_to(id, egui::ViewportCommand::OuterPosition(target));
1336삭제: self.work.expected = Some(target);
1337삭제: self.work.settle_until = now + 0.5;
1338삭제: }
1339삭제: } else if self.work.settle_until == 0.0 && !settled {
1340삭제: // 사용자가 자식 창을 옮긴 위치를 부모 기준으로 기억함.
1341삭제: self.work.offset = Some(child.min - parent.min);
1342삭제: self.work.expected = Some(child.min);
1343삭제: }
1344삭제: self.work.parent = Some(parent.min);
1345삭제: }
13461513 let title = if self.model.busy() {
13471514 present::activity_text(
13481515 &self.model,
@@ -1354,23 +1521,10 @@ impl ArchiveApp {
13541521 };
13551522 let window_title = format!("{title} — Zipelo");
13561523 let custom_frame = self.custom_frame;
1357삭제: let mut builder = egui::ViewportBuilder::default()
1358삭제: .with_title(window_title.clone())
1359삭제: .with_decorations(!custom_frame)
1360삭제: .with_inner_size(size)
1361삭제: .with_resizable(false)
1362삭제: .with_minimize_button(false)
1363삭제: .with_maximize_button(false)
1364삭제: .with_taskbar(false)
1365삭제: // 앱을 쓰는 동안에만 부모 창 위에 유지함.
1366삭제: .with_window_level(if parent_focused || child_focused {
1367삭제: egui::WindowLevel::AlwaysOnTop
1368삭제: } else {
1369삭제: egui::WindowLevel::Normal
1370삭제: });
1371삭제: if let Some(position) = self.work.initial {
1372삭제: builder = builder.with_position(position);
1373삭제: }
1524추가: let size = egui::vec2(WORK_WIDTH, self.work.height);
1525추가: let builder = self
1526추가: .work
1527추가: .builder(ctx, id, size, &window_title, !custom_frame);
13741528 let height = ctx.show_viewport_immediate(id, builder, |ui, class| {
13751529 if ui.ctx().input(|i| i.viewport().close_requested()) {
13761530 if self.model.busy() {
@@ -1769,127 +1923,310 @@ impl ArchiveApp {
17691923 }
17701924 }
17711925
1772삭제: fn create_dialog(&mut self, ctx: &egui::Context) {
1773삭제: let mut compress = false;
1774삭제: let mut pick = None;
1775삭제: let mut cancel = false;
1776삭제: let modal = egui::Modal::new(egui::Id::unique("create-zip")).show(ctx, |ui| {
1777삭제: ui.set_width((ctx.content_rect().width() - 64.0).min(600.0));
1778삭제: ui.horizontal(|ui| {
1779삭제: ui.heading("ZIP 만들기");
1780삭제: ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
1781삭제: let close = theme::icon_button(ui, "닫기", theme::CLOSE, true);
1782삭제: theme::focus(&close);
1783삭제: cancel = close.clicked();
1926추가: /// 파일 목록 한 행의 아이콘, 이름, 크기 칸. 메인 목록과 ZIP 만들기 창이 같이 씀.
1927추가: fn entry_cells(
1928추가: ui: &mut egui::Ui,
1929추가: rect: egui::Rect,
1930추가: directory: bool,
1931추가: name: &str,
1932추가: hover: &str,
1933추가: size: String,
1934추가: name_width: f32,
1935추가: ) {
1936추가: ui.scope_builder(
1937추가: egui::UiBuilder::new()
1938추가: .max_rect(rect.shrink2(egui::vec2(0.0, 2.0)))
1939추가: .layout(Layout::left_to_right(Align::Center)),
1940추가: |ui| {
1941추가: ui.style_mut().interaction.selectable_labels = false;
1942추가: ui.add_space(16.0);
1943추가: theme::icon(ui, if directory { Icon::Folder } else { Icon::File }, 20.0);
1944추가: theme::bounded_text_hover(ui, name, hover, name_width);
1945추가: theme::column_label(ui, size, 96.0, Align::Max);
1946추가: },
1947추가: );
1948추가: }
1949추가:
1950추가: /// ZIP 만들기를 진행 창처럼 부모 창을 따라가는 별도 창으로 띄움.
1951추가: /// 별도 창을 만들 수 없는 환경(시험 등)에서는 메인 창 안의 모달로 띄움.
1952추가: fn create_window(&mut self, ctx: &egui::Context) {
1953추가: if !self.create || self.model.busy() {
1954추가: self.create_win = WorkWindow::default();
1955추가: return;
1956추가: }
1957추가: if ctx.embed_viewports() {
1958추가: let mut close = false;
1959추가: let modal = egui::Modal::new(egui::Id::unique("create-zip")).show(ctx, |ui| {
1960추가: ui.set_width((ctx.content_rect().width() - 64.0).min(CREATE_WIDTH));
1961추가: ui.horizontal(|ui| {
1962추가: ui.heading("ZIP 만들기");
1963추가: ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
1964추가: let button = theme::icon_button(ui, "닫기", theme::CLOSE, true);
1965추가: close = button.clicked();
1966추가: });
17841967 });
1968추가: close |= self.create_area(ui);
17851969 });
1786삭제: if let Some(error) = &self.ui_error {
1787삭제: Self::error_notice(ui, error);
1970추가: if close || modal.should_close() {
1971추가: self.close_create();
17881972 }
1789삭제: egui::ScrollArea::vertical()
1790삭제: .id_salt("create-fields")
1791삭제: .max_height(
1792삭제: (ctx.content_rect().height()
1793삭제: - 180.0
1794삭제: - if self.ui_error.is_some() { 96.0 } else { 0.0 })
1795삭제: .max(120.0),
1796삭제: )
1973추가: return;
1974추가: }
1975추가: let id = egui::ViewportId::from_hash_of("archive-create");
1976추가: let title = "ZIP 만들기 — Zipelo";
1977추가: let custom_frame = self.custom_frame;
1978추가: if !self.create_win.open {
1979추가: self.create_win.height = self.create_win.height.max(CREATE_MIN_HEIGHT);
1980추가: }
1981추가: let size = egui::vec2(CREATE_WIDTH, self.create_win.height);
1982추가: let builder = self.create_win.builder(ctx, id, size, title, !custom_frame);
1983추가: let mut close = false;
1984추가: let height = ctx.show_viewport_immediate(id, builder, |ui, class| {
1985추가: if ui.ctx().input(|i| i.viewport().close_requested()) {
1986추가: close = true;
1987추가: }
1988추가: if class == egui::ViewportClass::EmbeddedWindow {
1989추가: ui.set_width(CREATE_WIDTH);
1990추가: close |= self.create_area(ui);
1991추가: return None;
1992추가: }
1993추가: let mut chrome = 0.0;
1994추가: if custom_frame {
1995추가: window_frame::title_bar(
1996추가: ui,
1997추가: "create",
1998추가: title,
1999추가: window_frame::Buttons {
2000추가: minimize: false,
2001추가: maximize: false,
2002추가: },
2003추가: );
2004추가: window_frame::edges(ui.ctx(), false);
2005추가: chrome = window_frame::TITLE_HEIGHT;
2006추가: }
2007추가: let margin = theme::PAD as f32;
2008추가: egui::CentralPanel::default()
2009추가: .frame(theme::panel(theme::PANEL).corner_radius(0))
17972010 .show(ui, |ui| {
1798삭제: ui.add_space(16.0);
1799삭제: let frame = theme::panel(theme::STRIPE)
1800삭제: .stroke(egui::Stroke::new(1.0, theme::DASH))
1801삭제: .inner_margin(egui::Margin::same(24));
1802삭제: let area = frame
1803삭제: .show(ui, |ui| {
1804삭제: ui.set_min_size(egui::vec2(ui.available_width(), 144.0));
1805삭제: ui.vertical_centered(|ui| {
1806삭제: theme::icon(ui, Icon::File, 44.0);
1807삭제: ui.add_space(16.0);
1808삭제: ui.label(
1809삭제: RichText::new("파일이나 폴더를 여기에 끌어 놓으세요")
1810삭제: .size(theme::FONT_BODY),
1811삭제: );
1812삭제: });
1813삭제: })
1814삭제: .response;
1815삭제: let drop = ui.interact(
1816삭제: area.rect,
1817삭제: egui::Id::unique("zip-source-drop"),
1818삭제: egui::Sense::click(),
1819삭제: );
1820삭제: theme::focus(&drop);
1821삭제: drop.widget_info(|| {
1822삭제: egui::WidgetInfo::labeled(egui::Role::Button, true, "파일 추가")
1823삭제: });
1824삭제: if drop.clicked() {
1825삭제: pick = Some(Purpose::Files);
2011추가: let content = ui
2012추가: .vertical(|ui| close |= self.create_area(ui))
2013추가: .response
2014추가: .rect;
2015추가: Some(content.height() + 2.0 * margin + chrome)
2016추가: })
2017추가: .inner
2018추가: });
2019추가: if let Some(height) = height {
2020추가: let height = height.clamp(CREATE_MIN_HEIGHT, 900.0).ceil();
2021추가: if (height - self.create_win.height).abs() > 1.0 {
2022추가: self.create_win.height = height;
2023추가: }
2024추가: }
2025추가: if close {
2026추가: self.close_create();
2027추가: }
2028추가: }
2029추가:
2030추가: /// ZIP 만들기 내용. 닫기를 눌렀으면 true를 돌려줌.
2031추가: fn create_area(&mut self, ui: &mut egui::Ui) -> bool {
2032추가: // 저장 위치 선택 창이 응답을 기다리는 동안에는 버튼을 막음.
2033추가: let enabled = self.picker.is_none();
2034추가: ui.add_enabled_ui(enabled, |ui| self.create_contents(ui))
2035추가: .inner
2036추가: }
2037추가:
2038추가: fn create_contents(&mut self, ui: &mut egui::Ui) -> bool {
2039추가: let rows = self.create_rows();
2040추가: let root = self.create_root();
2041추가:
2042추가: // 경로 줄: 메인 화면처럼 위로 버튼과 현재 폴더 경로.
2043추가: ui.horizontal(|ui| {
2044추가: ui.set_height(theme::FIELD);
2045추가: ui.spacing_mut().item_spacing.x = 0.0;
2046추가: let up = theme::flat_icon_button(
2047추가: ui,
2048추가: "위로",
2049추가: theme::UP,
2050추가: !self.create_folder.is_empty(),
2051추가: egui::vec2(theme::FIELD, theme::FIELD),
2052추가: );
2053추가: if up.clicked() {
2054추가: self.create_folder = self
2055추가: .create_folder
2056추가: .rsplit_once('/')
2057추가: .map_or("", |(parent, _)| parent)
2058추가: .to_owned();
2059추가: }
2060추가: ui.add_space(6.0);
2061추가: let path = match &root {
2062추가: Some(root) => {
2063추가: let name = root.file_name().unwrap_or_default().to_string_lossy();
2064추가: if self.create_folder.is_empty() {
2065추가: format!("/{name}")
2066추가: } else {
2067추가: format!("/{name}/{}", self.create_folder)
18262068 }
1827삭제: egui::ScrollArea::vertical()
1828삭제: .id_salt("zip-sources")
1829삭제: .max_height(86.0)
1830삭제: .show(ui, |ui| {
1831삭제: let mut remove = None;
1832삭제: for (index, path) in self.sources.iter().enumerate() {
1833삭제: ui.horizontal(|ui| {
1834삭제: theme::icon(
1835삭제: ui,
1836삭제: if path.is_dir() {
1837삭제: Icon::Folder
1838삭제: } else {
1839삭제: Icon::File
1840삭제: },
1841삭제: 20.0,
1842삭제: );
1843삭제: let name =
1844삭제: path.file_name().unwrap_or_default().to_string_lossy();
1845삭제: theme::bounded_text(
1846삭제: ui,
1847삭제: &name,
1848삭제: (ui.available_width() - 72.0).max(0.0),
1849삭제: )
1850삭제: .on_hover_text(path.display().to_string());
1851삭제: if ui.button("빼기").clicked() {
1852삭제: remove = Some(index);
2069추가: }
2070추가: None => "/".to_owned(),
2071추가: };
2072추가: let (rect, _) = ui.allocate_exact_size(
2073추가: egui::vec2(ui.available_width(), theme::FIELD),
2074추가: egui::Sense::hover(),
2075추가: );
2076추가: theme::boxed_field(ui, rect);
2077추가: theme::field_text(ui, rect, &path);
2078추가: });
2079추가: ui.add_space(theme::SPACE);
2080추가:
2081추가: // 파일 목록: 메인 화면 목록과 같은 행 모양. 폴더를 두 번 누르면 들어감.
2082추가: let mut enter = None;
2083추가: egui::Frame::new()
2084추가: .stroke(egui::Stroke::new(1.0, theme::BORDER))
2085추가: .show(ui, |ui| {
2086추가: ui.set_min_size(egui::vec2(ui.available_width(), CREATE_LIST_HEIGHT));
2087추가: ui.set_max_height(CREATE_LIST_HEIGHT);
2088추가: let message = match &rows {
2089추가: None => Some("폴더를 읽지 못했습니다"),
2090추가: Some(rows) if rows.is_empty() => Some("이 폴더는 비어 있습니다"),
2091추가: Some(_) => None,
2092추가: };
2093추가: if let Some(message) = message {
2094추가: ui.centered_and_justified(|ui| ui.label(message));
2095추가: return;
2096추가: }
2097추가: let rows = rows.unwrap();
2098추가: let name_width = (ui.available_width() - 16.0 - 28.0 - 96.0 - 24.0).max(80.0);
2099추가: egui::ScrollArea::vertical()
2100추가: .id_salt("create-rows")
2101추가: .auto_shrink([false, false])
2102추가: .max_height(CREATE_LIST_HEIGHT)
2103추가: .show_rows(ui, LIST_ROW, rows.len(), |ui, range| {
2104추가: for row in &rows[range] {
2105추가: let (rect, response) = ui.allocate_exact_size(
2106추가: egui::vec2(ui.available_width(), LIST_ROW),
2107추가: egui::Sense::click(),
2108추가: );
2109추가: let response = response.on_hover_text(&row.name);
2110추가: response.widget_info(|| {
2111추가: egui::WidgetInfo::labeled(
2112추가: egui::Role::ListBoxOption,
2113추가: true,
2114추가: &row.name,
2115추가: )
2116추가: });
2117추가: if row.directory && root.is_some() && response.clicked() {
2118추가: // egui가 한 프레임을 다시 그리면 두 번 누름 정보가 사라질 수 있어
2119추가: // 같은 폴더를 다른 프레임에서 0.4초 안에 다시 누르면 두 번 누름으로 봄.
2120추가: let frame = ui.ctx().cumulative_frame_nr();
2121추가: let time = ui.input(|i| i.time);
2122추가: match &self.create_last_click {
2123추가: Some((name, last_frame, last_time))
2124추가: if name == &row.name
2125추가: && *last_frame != frame
2126추가: && time - last_time < 0.4 =>
2127추가: {
2128추가: enter = Some(row.name.clone());
2129추가: self.create_last_click = None;
18532130 }
1854삭제: });
1855삭제: }
1856삭제: if let Some(index) = remove {
1857삭제: self.sources.remove(index);
2131추가: Some((name, last_frame, _))
2132추가: if name == &row.name && *last_frame == frame => {}
2133추가: _ => {
2134추가: self.create_last_click =
2135추가: Some((row.name.clone(), frame, time));
2136추가: }
2137추가: }
18582138 }
1859삭제: });
1860삭제: ui.horizontal(|ui| {
1861삭제: if theme::action(ui, "파일 추가", false, true).clicked() {
1862삭제: pick = Some(Purpose::Files);
1863삭제: }
1864삭제: if theme::action(ui, "폴더 추가", false, true).clicked() {
1865삭제: pick = Some(Purpose::Folder);
2139추가: Self::entry_cells(
2140추가: ui,
2141추가: rect,
2142추가: row.directory,
2143추가: &row.name,
2144추가: &row.name,
2145추가: row.bytes.map(present::bytes_text).unwrap_or_default(),
2146추가: name_width,
2147추가: );
18662148 }
18672149 });
1868삭제: ui.add_space(16.0);
1869삭제: ui.horizontal(|ui| {
1870삭제: theme::icon(ui, Icon::Lock, 24.0);
1871삭제: ui.strong("암호화");
1872삭제: });
1873삭제: let check = ui.checkbox(&mut self.aes256, "암호로 보호하기");
1874삭제: theme::focus(&check);
1875삭제: ui.add_space(16.0);
1876삭제: });
1877삭제: let (dismiss, confirm) =
1878삭제: theme::action_pair(ui, "취소", Some(("압축하기", !self.sources.is_empty())));
1879삭제: cancel |= dismiss;
1880삭제: compress = confirm;
1881삭제: });
1882삭제: if cancel || modal.should_close() {
1883삭제: self.create = false;
1884삭제: self.ui_error = None;
1885삭제: return;
2150추가: });
2151추가: if let Some(name) = enter {
2152추가: self.create_folder = if self.create_folder.is_empty() {
2153추가: name
2154추가: } else {
2155추가: format!("{}/{name}", self.create_folder)
2156추가: };
18862157 }
1887삭제: if let Some(purpose) = pick {
1888삭제: self.open_picker(purpose);
2158추가: ui.add_space(theme::SPACE);
2159추가:
2160추가: if let Some(error) = &self.ui_error {
2161추가: Self::error_notice(ui, error);
18892162 }
2163추가:
2164추가: // 암호: 체크하면 바로 아래에 암호와 암호 확인 칸을 보여 줌.
2165추가: let check = ui.checkbox(&mut self.aes256, "암호로 보호하기");
2166추가: theme::focus(&check);
2167추가: if self.aes256 {
2168추가: let label_width = 72.0;
2169추가: ui.horizontal(|ui| {
2170추가: ui.add_sized([label_width, theme::FIELD], egui::Label::new("암호"));
2171추가: let toggle = if self.zip_password_visible {
2172추가: "숨기기"
2173추가: } else {
2174추가: "보기"
2175추가: };
2176추가: let toggle_width = 72.0;
2177추가: let edit = ui.add_sized(
2178추가: [
2179추가: (ui.available_width() - toggle_width - theme::SPACE).max(80.0),
2180추가: theme::FIELD,
2181추가: ],
2182추가: egui::TextEdit::singleline(&mut self.zip_password)
2183추가: .password(!self.zip_password_visible)
2184추가: .id(egui::Id::unique("zip-password-input"))
2185추가: .char_limit(1024)
2186추가: .align(egui::Align2::LEFT_CENTER),
2187추가: );
2188추가: theme::focus(&edit);
2189추가: if theme::action(ui, toggle, false, true).clicked() {
2190추가: self.zip_password_visible = !self.zip_password_visible;
2191추가: }
2192추가: });
2193추가: ui.horizontal(|ui| {
2194추가: ui.add_sized([label_width, theme::FIELD], egui::Label::new("암호 확인"));
2195추가: let edit = ui.add_sized(
2196추가: [
2197추가: (ui.available_width() - 72.0 - theme::SPACE).max(80.0),
2198추가: theme::FIELD,
2199추가: ],
2200추가: egui::TextEdit::singleline(&mut self.zip_password_confirm)
2201추가: .password(!self.zip_password_visible)
2202추가: .id(egui::Id::unique("zip-password-confirm"))
2203추가: .char_limit(1024)
2204추가: .align(egui::Align2::LEFT_CENTER),
2205추가: );
2206추가: theme::focus(&edit);
2207추가: });
2208추가: if self.zip_password.len() > 1024 {
2209추가: ui.colored_label(theme::ERROR, "암호는 UTF-8 1~1024바이트로 입력하세요");
2210추가: } else if !self.zip_password_confirm.is_empty()
2211추가: && self.zip_password != self.zip_password_confirm
2212추가: {
2213추가: ui.colored_label(theme::ERROR, "두 암호가 같지 않습니다");
2214추가: }
2215추가: ui.label(RichText::new("암호를 잊으면 파일을 열 수 없습니다.").color(theme::MUTED));
2216추가: } else if !self.zip_password.is_empty() || !self.zip_password_confirm.is_empty() {
2217추가: // 체크를 해제하면 입력한 암호를 남겨 두지 않음.
2218추가: wipe(&mut self.zip_password);
2219추가: wipe(&mut self.zip_password_confirm);
2220추가: self.zip_password_visible = false;
2221추가: }
2222추가: ui.add_space(theme::SPACE);
2223추가:
2224추가: let ready = !self.sources.is_empty() && self.zip_password_ready();
2225추가: let (cancel, compress) = theme::action_pair(ui, "취소", Some(("압축하기", ready)));
18902226 if compress {
18912227 self.open_picker(Purpose::SaveZip);
18922228 }
2229추가: cancel
18932230 }
18942231
18952232 fn password_dialog(&mut self, ctx: &egui::Context, new_challenge: bool) {
수정experiments/rust-ui-memory-app/src/archive_theme.rs+22-0
@@ -175,6 +175,28 @@ pub fn field_frame(ui: &egui::Ui, rect: egui::Rect, focused: bool) {
175175 painter.vline(rect.right() - 0.5, rect.y_range(), stroke);
176176}
177177
178추가: /// 네 변 테두리가 모두 있는 입력란 모양 (주변에 구분선이 없는 곳에서 씀).
179추가: pub fn boxed_field(ui: &egui::Ui, rect: egui::Rect) {
180추가: ui.painter().rect(
181추가: rect,
182추가: 0,
183추가: PANEL,
184추가: Stroke::new(1.0, BORDER),
185추가: egui::StrokeKind::Inside,
186추가: );
187추가: }
188추가:
189추가: /// 입력란 안에 경로처럼 한 줄 글자를 그림. 넘치면 줄이고 전체 글자는 툴팁으로 보여 줌.
190추가: /// 부모 배치에 영향을 주지 않는 하위 영역을 써서 옆 칸의 위치가 흔들리지 않게 함.
191추가: pub fn field_text(ui: &mut egui::Ui, rect: egui::Rect, text: &str) {
192추가: let mut child = ui.new_child(
193추가: egui::UiBuilder::new()
194추가: .max_rect(rect.shrink2(egui::vec2(10.0, 0.0)))
195추가: .layout(egui::Layout::left_to_right(egui::Align::Center)),
196추가: );
197추가: bounded_text(&mut child, text, (rect.width() - 20.0).max(0.0));
198추가: }
199추가:
178200/// 상태 줄 글자를 칸의 세로 가운데에 그림. 넘치면 줄이고 전체 글자는 툴팁으로 보여 줌.
179201pub fn status_text(
180202 ui: &mut egui::Ui,
수정tests/rust-app-real-worker/password_flows.rs+60-52
@@ -79,13 +79,34 @@ impl Screen {
7979 assert_eq!(self.app.model.terminal.as_ref().unwrap().outcome, expected);
8080 assert!(self.app.model.challenge.is_none());
8181 }
82삭제: fn start_encrypted_zip(&mut self, source: &Path, archive: &Path) {
82추가: /// ZIP 만들기 창에서 암호로 보호하기를 켜고 두 칸에 암호를 넣은 뒤 압축하기를 누름.
83추가: /// 작업이 시작됐는지 돌려줌.
84추가: fn start_encrypted_zip(&mut self, source: &Path, archive: &Path, password: &str) -> bool {
8385 self.app.add_sources(vec![source.to_path_buf()]);
8486 self.render(vec![]);
8587 self.set_text("zip-name", archive.file_name().unwrap().to_str().unwrap());
8688 self.click("암호로 보호하기");
89추가: self.set_text("zip-password-input", password);
90추가: self.set_text("zip-password-confirm", password);
91추가: if !password.is_empty() {
92추가: // 입력한 암호는 화면에 그대로 보이지 않음.
93추가: assert!(!self.render(vec![]).iter().any(|(value, _)| value.contains(password)));
94추가: }
8795 self.click("압축하기");
88삭제: assert!(self.app.model.busy(), "{}", self.app.model.status());
96추가: self.app.model.busy()
97추가: }
98추가: /// 별도 암호 입력 창 없이 작업이 끝나는지 확인함.
99추가: fn finish_without_password_prompt(&mut self, expected: Outcome) {
100추가: let deadline = Instant::now() + Duration::from_secs(10);
101추가: while self.app.model.busy() {
102추가: let shown = self.render(vec![]);
103추가: assert!(!shown.iter().any(|(value, _)| value == "ZIP 암호 설정"));
104추가: assert!(Instant::now() < deadline);
105추가: std::thread::sleep(Duration::from_millis(2));
106추가: }
107추가: assert!(self.app.model.confirmed, "{}", self.app.model.status());
108추가: assert_eq!(self.app.model.terminal.as_ref().unwrap().outcome, expected);
109추가: assert!(self.app.model.challenge.is_none());
89110 }
90111}
91112#[test]
@@ -206,11 +227,9 @@ fn cold_start_creates_aes_zip_then_reopens_and_extracts_with_password() {
206227 let (factory, observed) = observed_factory();
207228 let mut screen = Screen::new(factory);
208229 assert!(!screen.app.model.encryption);
209삭제: screen.start_encrypted_zip(&source, &archive);
210삭제: screen.password_request(1, true);
211삭제: assert!(!archive.exists());
212삭제: screen.password_answer(FIXTURE_PASSWORD);
213삭제: screen.finish_password_job(Outcome::Completed);
230추가: // 암호는 ZIP 만들기 창에서 받고, 작업자가 요청하면 별도 창 없이 넘김.
231추가: assert!(screen.start_encrypted_zip(&source, &archive, FIXTURE_PASSWORD));
232추가: screen.finish_without_password_prompt(Outcome::Completed);
214233 let bytes = fs::read(&archive).unwrap();
215234 assert_eq!(&bytes[..4], b"PK\x03\x04");
216235 assert_eq!(u16::from_le_bytes(bytes[6..8].try_into().unwrap()) & 1, 1);
@@ -226,17 +245,23 @@ fn cold_start_creates_aes_zip_then_reopens_and_extracts_with_password() {
226245 assert_reaped(&observed);
227246}
228247#[test]
229삭제: fn cancel_password_creation_does_not_create_an_archive() {
248추가: fn cancel_encrypted_creation_window_starts_no_worker_or_archive() {
230249 let scratch = Scratch::new();
231250 let source = scratch.path("private.txt");
232251 fs::write(&source, b"preserve").unwrap();
233252 let archive = scratch.path("cancelled.zip");
234253 let (factory, observed) = observed_factory();
235254 let mut screen = Screen::new(factory);
236삭제: screen.start_encrypted_zip(&source, &archive);
237삭제: screen.password_request(1, true);
238삭제: screen.escape();
239삭제: screen.finish_password_job(Outcome::Cancelled);
255추가: screen.app.add_sources(vec![source.clone()]);
256추가: screen.render(vec![]);
257추가: screen.click("암호로 보호하기");
258추가: screen.set_text("zip-password-input", FIXTURE_PASSWORD);
259추가: screen.set_text("zip-password-confirm", FIXTURE_PASSWORD);
260추가: screen.click("취소");
261추가: let shown = screen.render(vec![]);
262추가: assert!(!shown.iter().any(|(value, _)| value == "ZIP 만들기"));
263추가: assert!(!screen.app.model.busy());
264추가: assert!(observed.borrow().jobs.is_empty());
240265 assert!(!archive.exists());
241266 assert_eq!(fs::read(source).unwrap(), b"preserve");
242267 assert_eq!(fs::read_dir(&scratch.0).unwrap().count(), 1);
@@ -267,20 +292,17 @@ fn oversized_utf8_password_stays_in_dialog_then_accepts_valid_input() {
267292 assert_reaped(&observed);
268293}
269294
270삭제: fn invalid_password_then_cancel(invalid: &str, close: bool) {
295추가: fn invalid_zip_password_never_starts_a_worker(invalid: &str, close: bool) {
271296 let scratch = Scratch::new();
272297 let source = scratch.path("private.txt");
273298 fs::write(&source, b"preserve").unwrap();
274299 let archive = scratch.path("cancelled.zip");
275300 let (factory, observed) = observed_factory();
276301 let mut screen = Screen::new(factory);
277삭제: screen.start_encrypted_zip(&source, &archive);
278삭제: let challenge = screen.password_request(1, true);
279삭제: screen.password_answer(invalid);
280삭제: assert_eq!(screen.app.model.challenge, Some((challenge, 1, true)));
281삭제: if invalid.is_empty() {
282삭제: assert!(screen.app.model.input_error.is_none());
283삭제: } else {
302추가: // 빈 암호나 1024바이트를 넘는 암호로는 압축하기를 누를 수 없음.
303추가: assert!(!screen.start_encrypted_zip(&source, &archive, invalid));
304추가: assert!(observed.borrow().jobs.is_empty());
305추가: if !invalid.is_empty() {
284306 assert!(
285307 screen
286308 .render(vec![])
@@ -289,52 +311,38 @@ fn invalid_password_then_cancel(invalid: &str, close: bool) {
289311 );
290312 }
291313 if close {
314추가: // 작업이 없으므로 확인만 거치면 닫을 수 있음.
292315 screen.app.model.request_close();
293삭제: screen.app.model.confirm_close();
294삭제: assert_eq!(screen.app.model.close, Close::Waiting);
295삭제: assert!(!screen.app.model.confirmed);
316추가: assert_eq!(screen.app.model.close, Close::Review);
317추가: screen.app.model.acknowledge_close();
318추가: assert_eq!(screen.app.model.close, Close::Allowed);
296319 } else {
297삭제: screen.escape();
320추가: screen.click("취소");
321추가: assert!(
322추가: !screen
323추가: .render(vec![])
324추가: .iter()
325추가: .any(|(value, _)| value == "ZIP 만들기")
326추가: );
298327 }
299삭제: screen.finish_password_job(Outcome::Cancelled);
300삭제: assert_eq!(screen.app.model.status(), "작업 취소됨");
301삭제: assert_eq!(
302삭제: screen.app.model.terminal.as_ref().unwrap().publication,
303삭제: Publication::None
304삭제: );
305삭제: assert_eq!(screen.app.model.terminal.as_ref().unwrap().created_count, 0);
306삭제: assert_eq!(
307삭제: screen
308삭제: .app
309삭제: .model
310삭제: .terminal
311삭제: .as_ref()
312삭제: .unwrap()
313삭제: .retained_partial_count,
314삭제: 0
315삭제: );
316328 assert!(!archive.exists());
317329 assert_eq!(fs::read(&source).unwrap(), b"preserve");
318330 assert_eq!(fs::read_dir(&scratch.0).unwrap().count(), 1);
319331 assert_reaped(&observed);
320삭제: if close {
321삭제: assert_eq!(screen.app.model.close, Close::Review);
322삭제: screen.app.model.acknowledge_close();
323삭제: assert_eq!(screen.app.model.close, Close::Allowed);
324삭제: } else {
332추가: if !close {
325333 screen.open(&encrypted_fixture(&scratch, "aes2-store.zip"));
326334 assert_reaped(&observed);
327335 }
328336}
329337#[test]
330삭제: fn empty_password_then_cancel_confirms_worker_exit() {
331삭제: invalid_password_then_cancel("", false);
338추가: fn empty_zip_password_never_starts_a_worker() {
339추가: invalid_zip_password_never_starts_a_worker("", false);
332340}
333341#[test]
334삭제: fn oversized_password_then_cancel_confirms_worker_exit() {
335삭제: invalid_password_then_cancel(&"가".repeat(342), false);
342추가: fn oversized_zip_password_never_starts_a_worker() {
343추가: invalid_zip_password_never_starts_a_worker(&"가".repeat(342), false);
336344}
337345#[test]
338삭제: fn invalid_password_then_close_confirms_worker_exit() {
339삭제: invalid_password_then_cancel("", true);
346추가: fn invalid_zip_password_then_close_allows_closing() {
347추가: invalid_zip_password_never_starts_a_worker("", true);
340348}
추가tests/rust-app-ui/create_window.rs+192-0
@@ -0,0 +1,192 @@
1추가: // ZIP 만들기 창: 폴더 선택으로 시작하고, 메인 목록과 같은 모양으로 폴더 안을 보여 주며,
2추가: // 암호는 창 안에서 받아 작업자 요청에 자동으로 넘기는지 확인함.
3추가:
4추가: fn create_double_click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) {
5추가: policy_render(ctx, app, vec![]);
6추가: let point = policy_render(ctx, app, vec![])
7추가: .iter()
8추가: .rev()
9추가: .find(|(text, _)| text == label)
10추가: .unwrap_or_else(|| panic!("항목 없음: {label}"))
11추가: .1;
12추가: for _ in 0..2 {
13추가: for pressed in [true, false] {
14추가: policy_render(
15추가: ctx,
16추가: app,
17추가: vec![
18추가: egui::Event::PointerMoved(point),
19추가: egui::Event::PointerButton {
20추가: pos: point,
21추가: button: egui::PointerButton::Primary,
22추가: pressed,
23추가: modifiers: egui::Modifiers::NONE,
24추가: },
25추가: ],
26추가: );
27추가: }
28추가: }
29추가: }
30추가:
31추가: /// photos/a.txt, photos/trip/sea.jpg 폴더를 만들고 압축하기의 폴더 선택 응답으로 씀.
32추가: fn create_from_folder(scratch: &Folder, factory: &FakeFactory) -> (ArchiveApp, egui::Context) {
33추가: let folder = scratch.0.join("photos");
34추가: fs::create_dir_all(folder.join("trip")).unwrap();
35추가: fs::write(folder.join("a.txt"), b"abc").unwrap();
36추가: fs::write(folder.join("trip/sea.jpg"), b"sea").unwrap();
37추가: let mut app = loaded(scratch, factory);
38추가: let dialogs = TestDialogs::default();
39추가: dialogs.0.borrow_mut().answers.push_back(Some(vec![folder]));
40추가: app.set_dialogs(Box::new(dialogs));
41추가: let ctx = egui::Context::default();
42추가: policy_click(&ctx, &mut app, "압축하기");
43추가: (app, ctx)
44추가: }
45추가:
46추가: #[test]
47추가: fn create_window_lists_chosen_folder_and_browses_into_subfolders() {
48추가: let scratch = Folder::new();
49추가: let factory = FakeFactory::default();
50추가: let (mut app, ctx) = create_from_folder(&scratch, &factory);
51추가: let shown = policy_render(&ctx, &mut app, vec![]);
52추가: for expected in ["ZIP 만들기", "/photos", "trip", "a.txt", "암호로 보호하기", "취소"] {
53추가: assert!(
54추가: shown.iter().any(|(text, _)| text == expected),
55추가: "{expected}: {shown:?}"
56추가: );
57추가: }
58추가: // 끌어 놓기 영역, 파일/폴더 추가 버튼, 암호화 제목은 없음.
59추가: for removed in [
60추가: "파일이나 폴더를 여기에 끌어 놓으세요",
61추가: "파일 추가",
62추가: "폴더 추가",
63추가: "빼기",
64추가: "암호화",
65추가: ] {
66추가: assert!(!shown.iter().any(|(text, _)| text == removed), "{removed}");
67추가: }
68추가: // 폴더가 파일보다 먼저 나옴 (메인 목록과 같은 순서).
69추가: let y = |label: &str| shown.iter().find(|(text, _)| text == label).unwrap().1.y;
70추가: assert!(y("trip") < y("a.txt"));
71추가:
72추가: // 한 번 누르면 들어가지 않음.
73추가: policy_click(&ctx, &mut app, "trip");
74추가: for _ in 0..30 {
75추가: policy_render(&ctx, &mut app, vec![]);
76추가: }
77추가: let shown = policy_render(&ctx, &mut app, vec![]);
78추가: assert!(shown.iter().any(|(text, _)| text == "a.txt"));
79추가: assert!(!shown.iter().any(|(text, _)| text == "/photos/trip"));
80추가:
81추가: create_double_click(&ctx, &mut app, "trip");
82추가: let shown = policy_render(&ctx, &mut app, vec![]);
83추가: assert!(shown.iter().any(|(text, _)| text == "/photos/trip"));
84추가: assert!(shown.iter().any(|(text, _)| text == "sea.jpg"));
85추가: assert!(!shown.iter().any(|(text, _)| text == "a.txt"));
86추가:
87추가: // ZIP 안에는 고른 폴더가 최상위 폴더로 들어감.
88추가: policy_click(&ctx, &mut app, "압축하기");
89추가: match factory.state.borrow().starts.last() {
90추가: Some(Start::CreateZip {
91추가: sources, aes256, ..
92추가: }) => {
93추가: assert_eq!(sources.len(), 1);
94추가: assert_eq!(sources[0].1, "photos");
95추가: assert!(!aes256);
96추가: }
97추가: other => panic!("ZIP 만들기 요청이 필요함: {other:?}"),
98추가: }
99추가: }
100추가:
101추가: #[test]
102추가: fn create_password_rows_follow_checkbox_and_answer_worker_without_prompt() {
103추가: let scratch = Folder::new();
104추가: let factory = FakeFactory::default();
105추가: let (mut app, ctx) = create_from_folder(&scratch, &factory);
106추가: let shown = policy_render(&ctx, &mut app, vec![]);
107추가: assert!(!shown.iter().any(|(text, _)| text == "암호 확인"));
108추가:
109추가: policy_click(&ctx, &mut app, "암호로 보호하기");
110추가: let shown = policy_render(&ctx, &mut app, vec![]);
111추가: assert!(shown.iter().any(|(text, _)| text == "암호"));
112추가: assert!(shown.iter().any(|(text, _)| text == "암호 확인"));
113추가:
114추가: // 다른 두 암호는 알리고 시작하지 않음.
115추가: text(&ctx, &mut app, "zip-password-input", "first-secret");
116추가: text(&ctx, &mut app, "zip-password-confirm", "other-secret");
117추가: let shown = policy_render(&ctx, &mut app, vec![]);
118추가: assert!(shown.iter().any(|(text, _)| text == "두 암호가 같지 않습니다"));
119추가: policy_click(&ctx, &mut app, "압축하기");
120추가: assert_eq!(factory.state.borrow().starts.len(), 1);
121추가:
122추가: // 체크를 해제하면 암호 칸이 사라지고 입력한 암호도 남기지 않음.
123추가: policy_click(&ctx, &mut app, "암호로 보호하기");
124추가: let shown = policy_render(&ctx, &mut app, vec![]);
125추가: assert!(!shown.iter().any(|(text, _)| text == "암호 확인"));
126추가: policy_click(&ctx, &mut app, "암호로 보호하기");
127추가: policy_click(&ctx, &mut app, "압축하기");
128추가: assert_eq!(factory.state.borrow().starts.len(), 1, "지운 암호로 시작함");
129추가:
130추가: text(&ctx, &mut app, "zip-password-input", "fixture-secret");
131추가: text(&ctx, &mut app, "zip-password-confirm", "fixture-secret");
132추가: factory.state.borrow_mut().manual = true;
133추가: policy_click(&ctx, &mut app, "압축하기");
134추가: assert!(matches!(
135추가: factory.state.borrow().starts.last(),
136추가: Some(Start::CreateZip { aes256: true, .. })
137추가: ));
138추가: {
139추가: let mut worker = factory.state.borrow_mut();
140추가: worker.frame(Event::Accepted { encryption: true });
141추가: worker.frame(Event::PasswordRequired {
142추가: challenge_id: 17,
143추가: attempt: 1,
144추가: encrypt: true,
145추가: });
146추가: }
147추가: // 작업자가 암호를 요청하면 별도 암호 창 없이 ZIP 만들기 창의 암호를 넘김.
148추가: for _ in 0..12 {
149추가: let shown = policy_render(&ctx, &mut app, vec![]);
150추가: assert!(!shown.iter().any(|(text, _)| text == "ZIP 암호 설정"));
151추가: }
152추가: assert!(app.model.challenge.is_none());
153추가: assert!(factory.state.borrow().password_seen);
154추가: assert_eq!(factory.state.borrow().password, b"fixture-secret");
155추가: }
156추가:
157추가: #[test]
158추가: fn retry_of_encrypted_creation_reopens_create_window_for_password() {
159추가: let scratch = Folder::new();
160추가: let factory = FakeFactory::default();
161추가: let (mut app, ctx) = create_from_folder(&scratch, &factory);
162추가: policy_click(&ctx, &mut app, "암호로 보호하기");
163추가: text(&ctx, &mut app, "zip-password-input", "fixture-secret");
164추가: text(&ctx, &mut app, "zip-password-confirm", "fixture-secret");
165추가: factory.state.borrow_mut().manual = true;
166추가: policy_click(&ctx, &mut app, "압축하기");
167추가: let starts = factory.state.borrow().starts.len();
168추가: {
169추가: let mut worker = factory.state.borrow_mut();
170추가: worker.frame(Event::Accepted { encryption: true });
171추가: worker.finish(Outcome::Failed, Publication::None);
172추가: for event in &mut worker.queue {
173추가: if let HostEvent::Frame {
174추가: event: Event::Terminal(t),
175추가: ..
176추가: } = event
177추가: {
178추가: t.error = Some(ErrorCode::Io);
179추가: }
180추가: }
181추가: }
182추가: for _ in 0..12 {
183추가: policy_render(&ctx, &mut app, vec![]);
184추가: }
185추가: policy_click(&ctx, &mut app, "다시 시도");
186추가: let shown = policy_render(&ctx, &mut app, vec![]);
187추가: // 암호는 보관하지 않으므로 ZIP 만들기 창을 다시 열어 암호를 받음.
188추가: assert!(shown.iter().any(|(text, _)| text == "ZIP 만들기"));
189추가: assert!(shown.iter().any(|(text, _)| text == "암호 확인"));
190추가: assert!(!shown.iter().any(|(text, _)| text == "ZIP 암호 설정"));
191추가: assert_eq!(factory.state.borrow().starts.len(), starts);
192추가: }
수정tests/rust-app-ui/fake.rs+3-0
@@ -6,6 +6,8 @@ pub struct State {
66 pub requests: Vec<(u64, &'static str)>,
77 pub starts: Vec<Start>,
88 pub password_seen: bool,
9추가: /// 마지막으로 받은 암호 원문. 화면에서 입력한 암호가 그대로 전달됐는지 확인할 때 씀.
10추가: pub password: Vec<u8>,
911 pub job: u64,
1012 sequence: u64,
1113 pub queue: VecDeque<HostEvent>,
@@ -176,6 +178,7 @@ impl Connection for FakeConnection {
176178 assert_eq!(challenge_id, 17);
177179 assert!(!secret.as_bytes().is_empty());
178180 s.password_seen = true;
181추가: s.password = secret.as_bytes().to_vec();
179182 s.requests.push((request.sequence, "password"));
180183 if !s.manual {
181184 s.complete_action();
수정tests/rust-app-ui/long_layout.rs+2-2
@@ -170,7 +170,7 @@ fn narrow_deep_folder_path_is_elided_without_displacing_search() {
170170}
171171
172172#[test]
173삭제: fn narrow_create_sources_keep_remove_and_footer_actions_visible() {
173추가: fn narrow_create_sources_keep_names_and_footer_actions_visible() {
174174 let scratch = Folder::new();
175175 let factory = FakeFactory::default();
176176 let mut app = loaded(&scratch, &factory);
@@ -188,7 +188,7 @@ fn narrow_create_sources_keep_remove_and_footer_actions_visible() {
188188 text.iter()
189189 .any(|(text, _, elided)| text == &name && *elided)
190190 );
191삭제: for expected in ["빼기", "취소", "압축하기"] {
191추가: for expected in ["취소", "압축하기"] {
192192 assert!(
193193 text.iter()
194194 .any(|(text, rect, _)| text == expected && rect.bottom() <= 540.0)
수정tests/rust-app-ui/presentation.rs+1-0
@@ -911,6 +911,7 @@ mod widgets {
911911 include!("explorer_selection.rs");
912912 include!("window_frame.rs");
913913 include!("work_window.rs");
914추가: include!("create_window.rs");
914915}
915916
916917#[cfg(feature = "ui")]
수정tests/rust-app-ui/regressions.rs+10-0
@@ -375,6 +375,16 @@ fn renders_every_flow_with_actual_egui_widgets() {
375375 let ctx = egui::Context::default();
376376 let f = FakeFactory::default();
377377 let mut app = ArchiveApp::new(Box::new(f.clone()), None, true);
378추가: // 압축하기는 운영체제 폴더 선택 창을 여므로 시험 응답으로 바꿈.
379추가: let folder = std::env::temp_dir().join(format!("zipelo-ui-create-{}", std::process::id()));
380추가: std::fs::create_dir_all(&folder).unwrap();
381추가: let dialogs = dialogs::TestDialogs::default();
382추가: dialogs
383추가: .0
384추가: .borrow_mut()
385추가: .answers
386추가: .push_back(Some(vec![folder.clone()]));
387추가: app.set_dialogs(Box::new(dialogs));
378388 let render = |app: &mut ArchiveApp, events: Vec<egui::Event>, width: f32| {
379389 let mut output = ctx.run_ui(
380390 egui::RawInput {
수정tests/rust-app-ui/toolbar.rs+30-21
@@ -57,11 +57,10 @@ fn native_dialog_cancellation_never_starts_a_job() {
5757 policy_click(&ctx, &mut app, "열기");
5858 policy_click(&ctx, &mut app, "압축해제");
5959 assert_eq!(factory.state.borrow().starts.len(), 1);
60추가: // 압축하기는 폴더 선택 창을 먼저 열고, 취소하면 ZIP 만들기 창을 열지 않음.
6061 policy_click(&ctx, &mut app, "압축하기");
61삭제: policy_click(&ctx, &mut app, "파일 추가");
62삭제: policy_click(&ctx, &mut app, "폴더 추가");
6362 let shown = policy_render(&ctx, &mut app, vec![]);
64삭제: assert!(shown.iter().any(|(text, _)| text == "ZIP 만들기"));
63추가: assert!(!shown.iter().any(|(text, _)| text == "ZIP 만들기"));
6564 assert_eq!(factory.state.borrow().starts.len(), 1);
6665 let source = scratch.0.join("source.txt");
6766 fs::write(&source, b"source").unwrap();
@@ -81,7 +80,6 @@ fn native_dialog_cancellation_never_starts_a_job() {
8180 [
8281 Purpose::Open,
8382 Purpose::Destination,
84삭제: Purpose::Files,
8583 Purpose::Folder,
8684 Purpose::SaveZip
8785 ]
@@ -90,7 +88,7 @@ fn native_dialog_cancellation_never_starts_a_job() {
9088
9189#[test]
9290fn toolbar_and_modal_keyboard_do_not_submit_from_secondary_controls() {
93삭제: for label in ["취소", "파일 추가", "폴더 추가"] {
91추가: for label in ["취소", "암호로 보호하기"] {
9492 let scratch = Folder::new();
9593 let factory = FakeFactory::default();
9694 let mut app = loaded(&scratch, &factory);
@@ -159,14 +157,30 @@ fn toolbar_has_three_actions_and_zip_password_option_remains_available() {
159157 assert!(shown.iter().any(|(text, _)| text == label), "{label}");
160158 }
161159 assert!(!shown.iter().any(|(text, _)| text == "암호화"));
160추가: // 압축하기 → 폴더 선택 → ZIP 만들기 창. 암호 칸은 체크해야 나타남.
161추가: let folder = scratch.0.join("protected");
162추가: fs::create_dir(&folder).unwrap();
163추가: fs::write(folder.join("note.txt"), b"protected").unwrap();
164추가: let dialogs = TestDialogs::default();
165추가: dialogs
166추가: .0
167추가: .borrow_mut()
168추가: .answers
169추가: .push_back(Some(vec![folder.clone()]));
170추가: app.set_dialogs(Box::new(dialogs.clone()));
162171 policy_click(&ctx, &mut app, "압축하기");
163172 let shown = policy_render(&ctx, &mut app, vec![]);
164173 assert!(shown.iter().any(|(text, _)| text == "ZIP 만들기"));
165174 assert!(shown.iter().any(|(text, _)| text == "암호로 보호하기"));
166삭제: let source = scratch.0.join("protected.txt");
167삭제: fs::write(&source, b"protected").unwrap();
168삭제: app.add_sources(vec![source]);
175추가: assert!(!shown.iter().any(|(text, _)| text == "암호 확인"));
169176 policy_click(&ctx, &mut app, "암호로 보호하기");
177추가: let shown = policy_render(&ctx, &mut app, vec![]);
178추가: assert!(shown.iter().any(|(text, _)| text == "암호 확인"));
179추가: // 두 암호가 같아야 만들 수 있음.
180추가: policy_click(&ctx, &mut app, "압축하기");
181추가: assert_eq!(factory.state.borrow().starts.len(), 1);
182추가: text(&ctx, &mut app, "zip-password-input", "fixture-secret");
183추가: text(&ctx, &mut app, "zip-password-confirm", "fixture-secret");
170184 policy_click(&ctx, &mut app, "압축하기");
171185 assert!(matches!(
172186 factory.state.borrow().starts.last(),
@@ -361,7 +375,6 @@ fn dialog_failures_show_alerts_while_cancelled_dialogs_remain_silent() {
361375 for failed in [false, true] {
362376 for purpose in [
363377 Purpose::Open,
364삭제: Purpose::Files,
365378 Purpose::Folder,
366379 Purpose::Destination,
367380 Purpose::SaveZip,
@@ -382,18 +395,14 @@ fn dialog_failures_show_alerts_while_cancelled_dialogs_remain_silent() {
382395 let ctx = egui::Context::default();
383396 let label = match purpose {
384397 Purpose::Open => "열기",
385삭제: Purpose::Files | Purpose::Folder | Purpose::SaveZip => {
386삭제: policy_click(&ctx, &mut app, "압축하기");
387삭제: if purpose == Purpose::SaveZip {
388삭제: let source = scratch.0.join("source.txt");
389삭제: fs::write(&source, b"preserve").unwrap();
390삭제: app.add_sources(vec![source]);
391삭제: }
392삭제: match purpose {
393삭제: Purpose::Files => "파일 추가",
394삭제: Purpose::Folder => "폴더 추가",
395삭제: _ => "압축하기",
396삭제: }
398추가: // 도구 막대의 압축하기가 폴더 선택 창을 엶.
399추가: Purpose::Folder => "압축하기",
400추가: Purpose::SaveZip => {
401추가: let source = scratch.0.join("source.txt");
402추가: fs::write(&source, b"preserve").unwrap();
403추가: app.add_sources(vec![source]);
404추가: // ZIP 만들기 창의 압축하기가 저장 위치 선택 창을 엶.
405추가: "압축하기"
397406 }
398407 _ => "압축해제",
399408 };