team-ljyzipelo

공개
2,708줄109 KB
1#[cfg(all(feature = "ui-fixture", debug_assertions))]
2#[path = "../../../tests/rust-app-ui/scenarios.rs"]
3pub mod scenarios;
4
5use crate::{
6 archive_browser as browser,
7 archive_dialog::{
8 DIALOG_UNAVAILABLE, DialogAnswer, DialogRequest, Dialogs, NativeDialogs, PendingDialog,
9 Purpose,
10 },
11 archive_present as present,
12 archive_theme::{self as theme, Icon},
13 archive_ui::*,
14 window_frame,
15};
16use eframe::egui::{self, Align, Layout, RichText};
17use std::{
18 collections::BTreeSet,
19 path::{Path, PathBuf},
20};
21
22const WORK_WIDTH: f32 = 480.0;
23const CREATE_WIDTH: f32 = 560.0;
24/// 처음 열 때의 높이. 그다음부터는 내용 높이에 맞춤.
25const CREATE_MIN_HEIGHT: f32 = 300.0;
26const CREATE_LIST_HEIGHT: f32 = 288.0;
27
28/// ZIP 만들기 창 목록의 한 행. 디스크에서 읽은 파일이나 폴더임.
29#[derive(Clone)]
30struct SourceRow {
31 name: String,
32 directory: bool,
33 bytes: Option<u64>,
34}
35
36fn source_row(path: &Path) -> SourceRow {
37 let metadata = std::fs::symlink_metadata(path).ok();
38 SourceRow {
39 name: path
40 .file_name()
41 .map(|name| name.to_string_lossy().into_owned())
42 .unwrap_or_default(),
43 // 심볼릭 링크는 따라가지 않으므로 폴더로 보이지 않음.
44 directory: metadata.as_ref().is_some_and(|m| m.is_dir()),
45 bytes: metadata.filter(|m| m.is_file()).map(|m| m.len()),
46 }
47}
48
49/// 폴더 안 항목을 메인 목록과 같은 순서(폴더 먼저, 이름순)로 읽음. 읽지 못하면 None.
50fn read_source_dir(dir: &Path) -> Option<std::rc::Rc<Vec<SourceRow>>> {
51 let mut rows = std::fs::read_dir(dir)
52 .ok()?
53 .filter_map(Result::ok)
54 .map(|entry| source_row(&entry.path()))
55 .collect::<Vec<_>>();
56 rows.sort_by(|a, b| {
57 b.directory
58 .cmp(&a.directory)
59 .then_with(|| a.name.cmp(&b.name))
60 });
61 Some(std::rc::Rc::new(rows))
62}
63
64/// 덮어쓴 뒤 버려 메모리에 암호가 남지 않게 함.
65fn wipe(value: &mut String) {
66 let mut bytes = std::mem::take(value).into_bytes();
67 bytes.fill(0);
68}
69const WORK_MIN_HEIGHT: f32 = 96.0;
70const WORK_MAX_HEIGHT: f32 = 520.0;
71const WORK_RESULT_MAX_HEIGHT: f32 = 220.0;
72
73/// 작업 진행·결과를 보여주는 자식 창의 위치 상태.
74/// 부모 창 기준 상대 위치를 기억해 두고, 부모 창이 움직이면 같은 상대 위치로 따라감.
75struct WorkWindow {
76 open: bool,
77 initial: Option<egui::Pos2>,
78 offset: Option<egui::Vec2>,
79 parent: Option<egui::Pos2>,
80 expected: Option<egui::Pos2>,
81 settle_until: f64,
82 height: f32,
83}
84
85impl Default for WorkWindow {
86 fn default() -> Self {
87 Self {
88 open: false,
89 initial: None,
90 offset: None,
91 parent: None,
92 expected: None,
93 settle_until: 0.0,
94 height: 168.0,
95 }
96 }
97}
98
99impl WorkWindow {
100 /// 부모 창 가운데에 열고, 사용자가 옮긴 상대 위치를 유지한 채 부모 창을 따라가게 함.
101 /// 앱을 쓰는 동안에만 부모 위에 두고, 처음 위치를 담은 ViewportBuilder를 돌려줌.
102 /// Wayland처럼 창 위치를 알 수 없으면 위치는 창 관리자에 맡김.
103 fn builder(
104 &mut self,
105 ctx: &egui::Context,
106 id: egui::ViewportId,
107 size: egui::Vec2,
108 title: &str,
109 decorations: bool,
110 native_dialog_open: bool,
111 ) -> egui::ViewportBuilder {
112 let (parent, parent_focused, now) = ctx.input(|i| {
113 (
114 i.viewport().outer_rect,
115 i.viewport().focused.unwrap_or(false),
116 i.time,
117 )
118 });
119 let (child, child_focused) = ctx.input(|i| {
120 i.raw.viewports.get(&id).map_or((None, false), |v| {
121 (v.outer_rect, v.focused.unwrap_or(false))
122 })
123 });
124 if !self.open {
125 // 처음 열 때 부모 창 가운데에 둠. 닫혔다 다시 열 때는 기억한 위치에 둠.
126 self.open = true;
127 self.initial = parent.map(|p| match self.offset {
128 Some(offset) => (p.min + offset).round(),
129 None => (p.center() - size / 2.0).round(),
130 });
131 self.offset = self.initial.zip(parent).map(|(c, p)| c - p.min);
132 self.parent = parent.map(|p| p.min);
133 self.expected = self.initial;
134 self.settle_until = now + 0.5;
135 }
136 if let (Some(parent), Some(child)) = (parent, child) {
137 let parent_moved = self.parent.is_some_and(|p| (p - parent.min).length() > 0.5);
138 let settled = self
139 .expected
140 .is_some_and(|e| (child.min - e).length() <= 2.0);
141 if settled || now >= self.settle_until {
142 self.settle_until = 0.0;
143 }
144 if parent_moved {
145 if let Some(offset) = self.offset {
146 let target = (parent.min + offset).round();
147 ctx.send_viewport_cmd_to(id, egui::ViewportCommand::OuterPosition(target));
148 self.expected = Some(target);
149 self.settle_until = now + 0.5;
150 }
151 } else if self.settle_until == 0.0 && !settled {
152 // 사용자가 자식 창을 옮긴 위치를 부모 기준으로 기억함.
153 self.offset = Some(child.min - parent.min);
154 self.expected = Some(child.min);
155 }
156 self.parent = Some(parent.min);
157 }
158 let mut builder = egui::ViewportBuilder::default()
159 .with_title(title)
160 .with_icon(crate::app_icon::load())
161 .with_decorations(decorations)
162 .with_inner_size(size)
163 .with_resizable(false)
164 .with_minimize_button(false)
165 .with_maximize_button(false)
166 .with_taskbar(false)
167 .with_window_level(
168 if !native_dialog_open && (parent_focused || child_focused) {
169 egui::WindowLevel::AlwaysOnTop
170 } else {
171 egui::WindowLevel::Normal
172 },
173 );
174 if let Some(position) = self.initial {
175 builder = builder.with_position(position);
176 }
177 builder
178 }
179}
180
181struct Marquee {
182 // 스크롤 중에도 시작점을 목록 좌표로 유지함.
183 origin: egui::Pos2,
184 base: BTreeSet<u32>,
185 moved: bool,
186}
187
188/// 파일 목록 한 행의 높이. 행 안의 크기 칸(theme::ROW)이 위아래 2px 여백으로 들어감.
189const LIST_ROW: f32 = 36.0;
190
191pub struct ArchiveApp {
192 pub model: Model,
193 factory: Box<dyn Factory>,
194 destination: PathBuf,
195 automatic_destination: bool,
196 owned_destination: Option<PathBuf>,
197 gzip_name: String,
198 sources: Vec<PathBuf>,
199 zip_folder: PathBuf,
200 zip_name: String,
201 password: String,
202 password_confirm: String,
203 password_visible: bool,
204 password_challenge: Option<u64>,
205 aes256: bool,
206 create: bool,
207 selected_only: bool,
208 method: Method,
209 dialogs: Box<dyn Dialogs>,
210 picker: Option<(Purpose, std::sync::mpsc::Receiver<DialogAnswer>)>,
211 work: WorkWindow,
212 create_win: WorkWindow,
213 /// ZIP 만들기 창에서 보고 있는 폴더 (고른 폴더 기준 상대 경로, 비어 있으면 최상위).
214 create_folder: String,
215 create_listing: Option<(PathBuf, Option<std::rc::Rc<Vec<SourceRow>>>)>,
216 /// 마지막으로 누른 폴더 행 (이름, 프레임 번호, 시각). 두 번 누름을 직접 판단할 때 씀.
217 create_last_click: Option<(String, u64, f64)>,
218 /// ZIP 만들기 목록에서 한 번 눌러 선택한 항목 이름. 보고 있는 폴더가 바뀌면 지움.
219 create_selected: Option<String>,
220 zip_password: String,
221 zip_password_confirm: String,
222 zip_password_visible: bool,
223 /// 암호를 지웠으면 입력창의 실행 취소 기록도 다음 그리기 전에 지움.
224 forget_password_history: Vec<&'static str>,
225 /// 작업을 시작한 뒤 작업자가 암호를 요청하면 넘길 암호. 넘기거나 작업이 끝나면 지움.
226 pending_zip_password: Option<String>,
227 custom_frame: bool,
228 release_after_move: bool,
229 folder: String,
230 search: String,
231 list_anchor: Option<usize>,
232 list_cursor: Option<usize>,
233 list_offset: f32,
234 list_focused: bool,
235 marquee: Option<Marquee>,
236 last_request: Option<Start>,
237 targets: Option<BTreeSet<String>>,
238 directories: BTreeSet<String>,
239 dismissed: bool,
240 details: bool,
241 checked_destination: bool,
242 ui_error: Option<String>,
243 initialized: bool,
244 #[cfg(all(feature = "ui-fixture", debug_assertions))]
245 scenario_marquee: Option<egui::Rect>,
246 #[cfg(all(feature = "ui-fixture", debug_assertions))]
247 scenario_sources: Option<std::rc::Rc<Vec<SourceRow>>>,
248}
249
250impl ArchiveApp {
251 pub fn new(factory: Box<dyn Factory>, startup: Option<PathBuf>, _fixture: bool) -> Self {
252 let mut app = Self {
253 model: Model::default(),
254 factory,
255 destination: PathBuf::new(),
256 automatic_destination: true,
257 owned_destination: None,
258 gzip_name: String::new(),
259 sources: Vec::new(),
260 zip_folder: present::home_directory(),
261 zip_name: String::new(),
262 password: String::new(),
263 password_confirm: String::new(),
264 password_visible: false,
265 password_challenge: None,
266 aes256: false,
267 create: false,
268 selected_only: false,
269 method: Method::Deflate,
270 dialogs: Box::new(NativeDialogs),
271 picker: None,
272 work: WorkWindow::default(),
273 create_win: WorkWindow::default(),
274 create_folder: String::new(),
275 create_listing: None,
276 create_last_click: None,
277 create_selected: None,
278 zip_password: String::new(),
279 zip_password_confirm: String::new(),
280 zip_password_visible: false,
281 forget_password_history: Vec::new(),
282 pending_zip_password: None,
283 custom_frame: false,
284 release_after_move: false,
285 folder: String::new(),
286 search: String::new(),
287 list_anchor: None,
288 list_cursor: None,
289 list_offset: 0.0,
290 list_focused: false,
291 marquee: None,
292 last_request: None,
293 targets: None,
294 directories: BTreeSet::new(),
295 dismissed: false,
296 details: false,
297 checked_destination: false,
298 ui_error: None,
299 initialized: false,
300 #[cfg(all(feature = "ui-fixture", debug_assertions))]
301 scenario_marquee: None,
302 #[cfg(all(feature = "ui-fixture", debug_assertions))]
303 scenario_sources: None,
304 };
305 if let Some(path) = startup {
306 app.open_path(path);
307 }
308 app
309 }
310
311 pub fn set_dialogs(&mut self, dialogs: Box<dyn Dialogs>) {
312 self.dialogs = dialogs;
313 }
314
315 /// 운영체제가 창 테두리를 그려 주지 않을 때(GNOME Wayland) 제목 표시줄을 직접 그림.
316 pub fn set_custom_frame(&mut self, custom: bool) {
317 self.custom_frame = custom;
318 }
319
320 pub fn browse_folder(&mut self, folder: &str) {
321 self.folder = folder.trim_matches('/').to_owned();
322 self.search.clear();
323 self.clear_list_selection();
324 }
325
326 pub fn show_create(&mut self, encrypted: bool) {
327 if !self.model.busy() {
328 self.create = true;
329 self.aes256 = encrypted;
330 self.ui_error = None;
331 }
332 }
333
334 fn clear_password(&mut self) {
335 for value in [&mut self.password, &mut self.password_confirm] {
336 let mut bytes = std::mem::take(value).into_bytes();
337 bytes.fill(0);
338 }
339 self.password_visible = false;
340 // 이 함수는 암호 요청이 없는 동안 매 프레임 불리므로, 암호 창을 쓴 뒤에만 기록을 지움.
341 if self.password_challenge.is_some() {
342 self.forget_password_history
343 .extend(["archive-password-input", "archive-password-confirm"]);
344 }
345 }
346
347 /// 지운 암호가 입력창의 실행 취소(Ctrl+Z)로 되살아나지 않게 egui가 보관하는
348 /// 입력창 상태(실행 취소 기록 포함)를 지움.
349 fn forget_password_history(&mut self, ctx: &egui::Context) {
350 if self.forget_password_history.is_empty() {
351 return;
352 }
353 let names = std::mem::take(&mut self.forget_password_history);
354 ctx.data_mut(|data| {
355 for name in names {
356 data.remove::<egui::text_edit::TextEditState>(egui::Id::unique(name));
357 }
358 });
359 }
360
361 fn clear_zip_password(&mut self) {
362 wipe(&mut self.zip_password);
363 wipe(&mut self.zip_password_confirm);
364 if let Some(mut pending) = self.pending_zip_password.take() {
365 wipe(&mut pending);
366 }
367 self.zip_password_visible = false;
368 self.forget_password_history
369 .extend(["zip-password-input", "zip-password-confirm"]);
370 }
371
372 /// 암호로 보호하지 않거나, 두 암호가 같고 1~1024바이트이면 만들 수 있음.
373 fn zip_password_ready(&self) -> bool {
374 !self.aes256
375 || (!self.zip_password.is_empty()
376 && self.zip_password.len() <= 1024
377 && self.zip_password == self.zip_password_confirm)
378 }
379
380 fn close_create(&mut self) {
381 self.create = false;
382 self.ui_error = None;
383 self.clear_zip_password();
384 self.create_win = WorkWindow::default();
385 }
386
387 /// 압축하기: 묶을 폴더를 운영체제 폴더 선택 창에서 고른 뒤 ZIP 만들기 창을 엶.
388 fn choose_zip_folder(&mut self) {
389 if self.model.busy() || self.picker.is_some() {
390 return;
391 }
392 // 이미 열린 ZIP 만들기 창의 목록과 암호 설정은 새 폴더를 실제로 고른 뒤에만 바꿈.
393 // 선택을 취소하면 그대로 남음(apply_picker의 Purpose::Folder).
394 self.open_picker(Purpose::Folder);
395 }
396
397 /// 폴더 하나를 골랐으면 그 폴더 안을 목록으로 보여 줌. 여러 항목이면 그 항목들을 보여 줌.
398 fn create_root(&self) -> Option<PathBuf> {
399 (self.sources.len() == 1 && self.sources[0].is_dir()).then(|| self.sources[0].clone())
400 }
401
402 fn create_rows(&mut self) -> Option<std::rc::Rc<Vec<SourceRow>>> {
403 #[cfg(all(feature = "ui-fixture", debug_assertions))]
404 if let Some(rows) = &self.scenario_sources {
405 return Some(rows.clone());
406 }
407 let Some(root) = self.create_root() else {
408 return Some(std::rc::Rc::new(
409 self.sources.iter().map(|path| source_row(path)).collect(),
410 ));
411 };
412 let dir = if self.create_folder.is_empty() {
413 root
414 } else {
415 root.join(&self.create_folder)
416 };
417 // 프레임마다 디스크를 읽지 않도록 보고 있는 폴더가 바뀔 때만 다시 읽음.
418 if self
419 .create_listing
420 .as_ref()
421 .is_none_or(|(path, _)| path != &dir)
422 {
423 let rows = read_source_dir(&dir);
424 self.create_listing = Some((dir, rows));
425 }
426 self.create_listing
427 .as_ref()
428 .and_then(|(_, rows)| rows.clone())
429 }
430
431 pub fn open_path(&mut self, archive: PathBuf) {
432 if self.model.busy() {
433 return;
434 }
435 self.clear_password();
436 self.destination = present::default_destination(&archive);
437 self.automatic_destination = true;
438 self.gzip_name = present::gzip_output_name(&archive);
439 self.selected_only = false;
440 self.folder.clear();
441 self.search.clear();
442 self.clear_list_selection();
443 self.targets = None;
444 self.directories.clear();
445 self.start(Start::List { archive });
446 }
447
448 fn start(&mut self, request: Start) -> bool {
449 // 파일 선택 창이 응답을 기다리는 동안에는 어느 창에서도 새 작업을 시작하지 않음.
450 if self.picker.is_some() {
451 return false;
452 }
453 self.last_request = Some(request.clone());
454 self.dismissed = false;
455 self.details = false;
456 self.checked_destination = false;
457 self.ui_error = None;
458 self.model.begin(request, self.factory.as_mut())
459 }
460
461 pub fn choose_destination(&mut self, path: PathBuf) {
462 self.destination = path;
463 self.automatic_destination = false;
464 self.ui_error = None;
465 }
466
467 pub fn add_sources(&mut self, paths: Vec<PathBuf>) {
468 if self.model.busy() {
469 return;
470 }
471 let mut validated = Vec::new();
472 for path in paths {
473 let Ok(metadata) = std::fs::symlink_metadata(&path) else {
474 self.ui_error = Some("파일이나 폴더를 찾지 못했습니다. 다시 선택하세요".into());
475 return;
476 };
477 if metadata.file_type().is_symlink() || !(metadata.is_file() || metadata.is_dir()) {
478 self.ui_error = Some("일반 파일과 폴더만 추가할 수 있습니다".into());
479 return;
480 }
481 let Ok(path) = path.canonicalize() else {
482 return;
483 };
484 if path.to_str().is_none()
485 || !path
486 .file_name()
487 .and_then(|name| name.to_str())
488 .is_some_and(valid_leaf)
489 {
490 self.ui_error = Some("파일이나 폴더의 이름을 확인하세요".into());
491 return;
492 }
493 validated.push(crate::archive_path::worker_path(&path));
494 }
495 let paths = validated;
496 if self.sources.is_empty() {
497 if let Some(first) = paths.first() {
498 self.zip_folder = first.parent().unwrap_or(Path::new("/")).to_path_buf();
499 let name = if first.is_dir() {
500 first.file_name()
501 } else {
502 first.file_stem()
503 };
504 self.zip_name = format!("{}.zip", name.unwrap_or_default().to_string_lossy());
505 }
506 }
507 for path in paths {
508 if !self.sources.contains(&path) {
509 self.sources.push(path);
510 }
511 }
512 self.create_folder.clear();
513 self.create_listing = None;
514 self.create_selected = None;
515 self.create = true;
516 }
517
518 pub fn begin_extract(&mut self) -> bool {
519 self.selected_only = !self.model.selected.is_empty();
520 let selection = if self.selected_only {
521 Selection::EntryIds(
522 browser::expand_selection(&self.model.entries, &self.model.selected)
523 .into_iter()
524 .collect(),
525 )
526 } else {
527 Selection::All
528 };
529 self.extract_selection(selection)
530 }
531
532 fn extract_selection(&mut self, selection: Selection) -> bool {
533 if !self.model.can_extract()
534 || matches!(&selection, Selection::EntryIds(ids) if ids.is_empty())
535 {
536 return false;
537 }
538 self.selected_only = matches!(&selection, Selection::EntryIds(_));
539 match present::prepare_destination(&self.destination, self.automatic_destination) {
540 Ok(true) => self.owned_destination = Some(self.destination.clone()),
541 Ok(false) => self.owned_destination = None,
542 Err(_) => {
543 self.ui_error = Some(present::FOLDER_ERROR.into());
544 return false;
545 }
546 }
547 let gzip = self
548 .model
549 .list_id
550 .as_ref()
551 .is_some_and(|id| id.format == Format::Gzip);
552 self.targets = present::target_files(
553 &self.model.entries,
554 &selection,
555 gzip.then_some(self.gzip_name.as_str()),
556 );
557 self.directories = if gzip {
558 BTreeSet::new()
559 } else {
560 present::target_directories(&self.model.entries, &selection)
561 };
562 let request = Start::Extract {
563 archive: self.model.archive.clone().unwrap(),
564 destination: self.destination.clone(),
565 selection,
566 list_id: self.model.list_id.clone().unwrap(),
567 gzip_output_name: gzip.then(|| self.gzip_name.clone()),
568 };
569 if self.start(request) {
570 true
571 } else {
572 if let Some(path) = self.owned_destination.take() {
573 present::remove_owned_empty(&path);
574 }
575 false
576 }
577 }
578
579 fn begin_zip(&mut self) {
580 if self.sources.is_empty() {
581 return;
582 }
583 if !self.zip_name.to_ascii_lowercase().ends_with(".zip") {
584 self.zip_name.push_str(".zip");
585 }
586 if !valid_leaf(&self.zip_name) {
587 self.ui_error = Some("ZIP 파일 이름을 확인하세요".into());
588 return;
589 }
590 let output_file = self.zip_folder.join(&self.zip_name);
591 if std::fs::symlink_metadata(&output_file).is_ok() {
592 self.ui_error = Some("같은 이름의 파일이 이미 있습니다. 다른 이름을 입력하세요".into());
593 return;
594 }
595 let mut sources = Vec::new();
596 for path in &self.sources {
597 let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
598 self.ui_error = Some(
599 "이름을 읽을 수 없는 파일이 있습니다. 파일 이름을 바꾼 뒤 다시 추가하세요"
600 .into(),
601 );
602 return;
603 };
604 sources.push((path.clone(), name.to_owned()));
605 }
606 if !self.zip_password_ready() {
607 self.ui_error = Some("두 암호가 같은지 확인하세요".into());
608 return;
609 }
610 self.targets = Some([self.zip_name.clone()].into_iter().collect());
611 self.directories.clear();
612 // 암호는 ZIP 만들기 창에서 받아 두었다가 작업자가 요청하면 넘김.
613 let password = self.aes256.then(|| std::mem::take(&mut self.zip_password));
614 if self.start(Start::CreateZip {
615 sources,
616 output_file,
617 method: self.method,
618 aes256: self.aes256,
619 }) {
620 self.create = false;
621 self.create_win = WorkWindow::default();
622 self.clear_zip_password();
623 self.pending_zip_password = password;
624 } else if let Some(password) = password {
625 self.zip_password = password;
626 }
627 }
628
629 fn open_picker(&mut self, purpose: Purpose) {
630 if self.model.busy() || self.picker.is_some() {
631 return;
632 }
633 let gzip = self
634 .model
635 .list_id
636 .as_ref()
637 .is_some_and(|id| id.format == Format::Gzip);
638 let purpose = match (purpose, gzip) {
639 (Purpose::Destination, true) => Purpose::SaveGzip,
640 (Purpose::Retry, true) => Purpose::RetryGzip,
641 _ => purpose,
642 };
643 let directory = match purpose {
644 Purpose::SaveZip => self.zip_folder.clone(),
645 Purpose::Destination | Purpose::SaveGzip => self
646 .model
647 .archive
648 .as_ref()
649 .and_then(|path| path.parent())
650 .map(Path::to_path_buf)
651 .unwrap_or_else(present::home_directory),
652 Purpose::Retry | Purpose::RetryGzip => self.destination.clone(),
653 _ => self
654 .sources
655 .last()
656 .and_then(|path| path.parent())
657 .map(Path::to_path_buf)
658 .unwrap_or_else(present::home_directory),
659 };
660 let request = DialogRequest {
661 purpose,
662 directory,
663 file_name: if matches!(purpose, Purpose::SaveGzip | Purpose::RetryGzip) {
664 self.gzip_name.clone()
665 } else {
666 self.zip_name.clone()
667 },
668 };
669 match self.dialogs.start(request) {
670 PendingDialog::Ready(answer) => self.apply_picker(purpose, answer),
671 PendingDialog::Waiting(receiver) => self.picker = Some((purpose, receiver)),
672 }
673 }
674
675 fn poll_picker(&mut self) {
676 let Some((purpose, receiver)) = &self.picker else {
677 return;
678 };
679 let purpose = *purpose;
680 let answer = match receiver.try_recv() {
681 Ok(answer) => answer,
682 Err(std::sync::mpsc::TryRecvError::Empty) => return,
683 Err(std::sync::mpsc::TryRecvError::Disconnected) => Err(DIALOG_UNAVAILABLE.into()),
684 };
685 self.picker = None;
686 self.apply_picker(purpose, answer);
687 }
688
689 fn apply_picker(&mut self, purpose: Purpose, answer: DialogAnswer) {
690 if answer.is_ok() && self.ui_error.as_deref() == Some(DIALOG_UNAVAILABLE) {
691 self.ui_error = None;
692 }
693 match answer {
694 Ok(Some(paths)) if !paths.is_empty() => {
695 let path = paths[0].clone();
696 match purpose {
697 Purpose::Open => {
698 if std::fs::symlink_metadata(&path)
699 .is_ok_and(|m| m.is_file() && !m.file_type().is_symlink())
700 {
701 self.open_path(path);
702 } else {
703 self.ui_error = Some("일반 압축파일을 선택하세요".into());
704 }
705 }
706 Purpose::Files => self.add_sources(paths),
707 Purpose::Folder => {
708 // 새 폴더로 처음부터 시작함. 고른 폴더가 쓸 수 없으면 기존 내용을 되돌림.
709 let previous = std::mem::take(&mut self.sources);
710 self.add_sources(paths);
711 if self.sources.is_empty() {
712 self.sources = previous;
713 } else {
714 self.aes256 = false;
715 self.clear_zip_password();
716 self.ui_error = None;
717 }
718 }
719 Purpose::Destination | Purpose::Retry => {
720 self.choose_destination(path);
721 self.selected_only = !self.model.selected.is_empty();
722 if purpose == Purpose::Retry {
723 self.retry();
724 } else {
725 self.begin_extract();
726 }
727 }
728 Purpose::SaveGzip | Purpose::RetryGzip => {
729 let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
730 self.ui_error = Some("저장할 파일 이름을 확인하세요".into());
731 return;
732 };
733 if !present::valid_output_leaf(name) {
734 self.ui_error = Some("저장할 파일 이름을 확인하세요".into());
735 return;
736 }
737 let name = name.to_owned();
738 self.choose_destination(
739 path.parent().unwrap_or(Path::new("/")).to_path_buf(),
740 );
741 self.gzip_name = name.clone();
742 self.selected_only = !self.model.selected.is_empty();
743 if purpose == Purpose::RetryGzip {
744 if let Some(Start::Extract {
745 gzip_output_name, ..
746 }) = &mut self.last_request
747 {
748 *gzip_output_name = Some(name);
749 }
750 self.retry();
751 } else {
752 self.begin_extract();
753 }
754 }
755 // 저장 위치를 고르는 사이 ZIP 만들기 창을 닫았으면 아무 작업도 시작하지 않음.
756 Purpose::SaveZip if !self.create => {}
757 Purpose::SaveZip => {
758 if let Some(name) = path.file_name().and_then(|name| name.to_str()) {
759 self.zip_name = name.to_owned();
760 self.zip_folder = path.parent().unwrap_or(Path::new("/")).to_path_buf();
761 self.begin_zip();
762 }
763 }
764 }
765 }
766 Ok(_) => {}
767 Err(error) => self.ui_error = Some(error),
768 }
769 }
770
771 fn retry(&mut self) {
772 if let Some(request) = self.last_request.clone() {
773 match request {
774 Start::List { archive } => self.open_path(archive),
775 Start::Extract {
776 selection,
777 gzip_output_name,
778 ..
779 } => {
780 if let Some(name) = gzip_output_name {
781 self.gzip_name = name;
782 }
783 self.extract_selection(selection);
784 }
785 Start::CreateZip { aes256, .. } => {
786 self.create = true;
787 if aes256 {
788 // 암호는 보관하지 않으므로 ZIP 만들기 창에서 다시 받음.
789 self.aes256 = true;
790 } else {
791 self.begin_zip();
792 }
793 }
794 }
795 }
796 }
797
798 fn on_drop(&mut self, paths: Vec<PathBuf>) {
799 if self.model.busy() || paths.is_empty() {
800 return;
801 }
802 if paths.len() == 1 && !self.create && !paths[0].is_dir() {
803 if std::fs::symlink_metadata(&paths[0])
804 .is_ok_and(|m| m.is_file() && !m.file_type().is_symlink())
805 {
806 self.open_path(paths[0].clone());
807 } else {
808 self.ui_error = Some("일반 압축파일을 선택하세요".into());
809 }
810 } else {
811 self.add_sources(paths);
812 }
813 }
814
815 fn poll(&mut self) {
816 let busy = self.model.busy();
817 let close_before = self.model.close;
818 self.model.poll();
819 if close_before == Close::Confirm && self.model.close == Close::Review {
820 // 종료 확인 창에 답하기 전에 작업이 끝났음. 사용자가 닫기를 승인하지 않았으므로
821 // 바로 닫지 않고 계속 물음(close_dialog가 작업이 끝난 문구로 바꿔 보여 줌).
822 self.model.close = Close::Confirm;
823 }
824 if busy && !self.model.busy() {
825 if let Some(path) = self.owned_destination.take() {
826 if !self.model.confirmed
827 || self
828 .model
829 .terminal
830 .as_ref()
831 .is_none_or(|t| t.outcome != Outcome::Completed)
832 {
833 present::remove_owned_empty(&path);
834 }
835 }
836 }
837 }
838
839 pub fn show(&mut self, root: &mut egui::Ui) {
840 let ctx = root.ctx().clone();
841 self.forget_password_history(&ctx);
842 if !self.initialized {
843 theme::apply(&ctx);
844 self.initialized = true;
845 }
846 self.poll();
847 self.poll_picker();
848 if self.model.challenge.is_some_and(|(_, _, encrypt)| encrypt)
849 && let Some(password) = self.pending_zip_password.take()
850 {
851 // ZIP 만들기 창에서 받은 암호를 작업자의 암호 요청에 바로 넘김.
852 self.model.password(password);
853 }
854 if !self.model.busy()
855 && let Some(mut pending) = self.pending_zip_password.take()
856 {
857 wipe(&mut pending);
858 }
859 let challenge = self.model.challenge.map(|(id, _, _)| id);
860 let new_challenge = challenge != self.password_challenge;
861 if new_challenge || challenge.is_none() {
862 self.clear_password();
863 }
864 self.password_challenge = challenge;
865 let dropped = ctx.input(|i| {
866 i.raw
867 .dropped_files
868 .iter()
869 .map(|file| file.path().to_path_buf())
870 .collect()
871 });
872 if self.picker.is_none() {
873 self.on_drop(dropped);
874 }
875 if ctx.input(|i| i.viewport().close_requested()) {
876 self.model.request_close();
877 // 실행 중인 작업이 없으면 결과 확인 안내 없이 바로 닫음.
878 self.model.acknowledge_close();
879 if self.model.close != Close::Allowed {
880 ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
881 }
882 }
883 if self.model.close == Close::Review {
884 // 작업을 취소하고 닫기로 한 뒤 정리가 끝난 경우도 안내 없이 닫음.
885 self.model.acknowledge_close();
886 }
887 if self.model.close == Close::Allowed {
888 ctx.send_viewport_cmd(egui::ViewportCommand::Close);
889 }
890 let title = self
891 .model
892 .archive
893 .as_ref()
894 .map(|path| {
895 let full = if path.is_absolute() {
896 path.clone()
897 } else {
898 std::env::current_dir().unwrap_or_default().join(path)
899 };
900 format!("{} — Zipelo", full.display())
901 })
902 .unwrap_or_else(|| "Zipelo".into());
903 let short_title = if let Some(path) = title.strip_suffix(" — Zipelo") {
904 format!(
905 "{} — Zipelo",
906 theme::window_title(root, path, ctx.content_rect().width() - 300.0)
907 )
908 } else {
909 title.clone()
910 };
911 ctx.send_viewport_cmd(egui::ViewportCommand::Title(short_title));
912 if self.custom_frame
913 && window_frame::title_bar(
914 root,
915 "main",
916 &title,
917 window_frame::Buttons {
918 minimize: true,
919 maximize: true,
920 },
921 )
922 {
923 self.release_after_move = true;
924 }
925 egui::Panel::top("archive-actions")
926 .frame(
927 theme::panel(theme::PANEL)
928 .corner_radius(0)
929 .inner_margin(egui::Margin {
930 left: 12,
931 right: 12,
932 // 버튼 안 내용은 보이는 모양 기준으로 가운데에 두므로 위아래를 같게 둠.
933 top: 4,
934 bottom: 4,
935 }),
936 )
937 .show(root, |ui| {
938 ui.horizontal(|ui| {
939 ui.spacing_mut().item_spacing.x = 2.0;
940 let idle = !self.model.busy()
941 && self.model.close == Close::Open
942 && self.picker.is_none();
943 if theme::tool(ui, "열기", theme::OPEN, idle, false)
944 .on_hover_text(&title)
945 .clicked()
946 {
947 self.open_picker(Purpose::Open);
948 }
949 if theme::tool(ui, "압축하기", theme::CREATE, idle, false).clicked() {
950 self.choose_zip_folder();
951 }
952 if theme::tool(
953 ui,
954 "압축해제",
955 theme::EXTRACT,
956 self.model.can_extract(),
957 true,
958 )
959 .clicked()
960 {
961 self.open_picker(Purpose::Destination);
962 }
963 });
964 });
965 egui::Panel::bottom("archive-status")
966 .exact_size(theme::STATUS_HEIGHT)
967 .resizable(false)
968 .frame(
969 egui::Frame::new()
970 .fill(theme::STRIPE)
971 .inner_margin(egui::Margin::symmetric(16, 0)),
972 )
973 .show(root, |ui| {
974 let rows = browser::rows(&self.model.entries, &self.folder, &self.search);
975 let selected = rows
976 .iter()
977 .filter(|row| !row.ids.is_empty() && row.ids.is_subset(&self.model.selected))
978 .count();
979 let rect = ui.max_rect();
980 let half = (rect.width() - theme::SPACE) / 2.0;
981 theme::status_text(
982 ui,
983 rect,
984 &format!("{}개 항목", rows.len()),
985 half,
986 Align::Min,
987 );
988 theme::status_text(ui, rect, &format!("선택 {selected}개"), half, Align::Max);
989 });
990 if ctx.embed_viewports() && self.work_visible() {
991 // 별도 창을 만들 수 없을 때만 쓰는 대체 배치. 목록을 가리지 않도록 하단에 둠.
992 egui::Panel::bottom("archive-work")
993 .frame(theme::panel(theme::PANEL).corner_radius(0))
994 .show(root, |ui| self.work_area(ui));
995 }
996 egui::CentralPanel::default()
997 .frame(
998 theme::panel(theme::PANEL)
999 .corner_radius(0)
1000 .inner_margin(egui::Margin::ZERO),
1001 )
1002 .show(root, |ui| {
1003 if self.model.archive.is_some() {
1004 self.archive_list(ui);
1005 } else {
1006 self.empty(ui);
1007 }
1008 });
1009 self.forget_password_history(&ctx);
1010 self.work_window(&ctx);
1011 self.create_window(&ctx);
1012 if self.model.challenge.is_some() {
1013 self.password_dialog(&ctx, new_challenge);
1014 }
1015 self.resource_dialog(&ctx);
1016 self.close_dialog(&ctx);
1017 self.picker_notice(&ctx);
1018 if self.custom_frame {
1019 window_frame::edges(&ctx, true);
1020 }
1021 if self.model.busy() {
1022 ctx.request_repaint_after(std::time::Duration::from_millis(30));
1023 }
1024 }
1025
1026 // 선택 창이 열려 있는 동안 다른 조작을 막고, 응답을 받도록 화면을 계속 갱신함.
1027 fn picker_notice(&mut self, ctx: &egui::Context) {
1028 if self.picker.is_none() {
1029 return;
1030 }
1031 egui::Modal::new(egui::Id::unique("archive-picker")).show(ctx, |ui| {
1032 ui.set_width(360.0);
1033 ui.label("파일 선택 창에서 선택을 마쳐 주세요");
1034 });
1035 ctx.request_repaint_after(std::time::Duration::from_millis(100));
1036 }
1037
1038 fn empty(&mut self, ui: &mut egui::Ui) {
1039 let hovered = ui.ctx().input(|i| !i.raw.hovered_files.is_empty());
1040 let width = (ui.available_width() * 0.60)
1041 .max(480.0)
1042 .min(ui.available_width());
1043 let y = ((ui.available_height() - theme::DROP_HEIGHT - theme::SPACE * 8.0) / 2.0).max(0.0);
1044 ui.add_space(y);
1045 ui.vertical_centered(|ui| {
1046 let drop_frame = egui::Frame::new()
1047 .fill(if hovered { theme::DROP } else { theme::PANEL })
1048 .corner_radius(theme::DROP_RADIUS)
1049 .inner_margin(egui::Margin::same(theme::DROP_PAD))
1050 .show(ui, |ui| {
1051 ui.set_width(width - 2.0 * theme::DROP_PAD as f32);
1052 ui.set_min_height(theme::DROP_HEIGHT - 2.0 * theme::DROP_PAD as f32);
1053 ui.vertical_centered(|ui| {
1054 ui.add_space(theme::PAD as f32);
1055 theme::icon(ui, Icon::Archive, 48.0);
1056 ui.add_space(theme::PAD as f32);
1057 ui.label(
1058 RichText::new(if hovered {
1059 "놓으면 엽니다"
1060 } else {
1061 "압축파일을 여기에 끌어 놓으세요"
1062 })
1063 .size(theme::FONT_LARGE)
1064 .strong(),
1065 );
1066 ui.label("또는");
1067 if theme::action(ui, "파일 열기", true, !self.model.busy()).clicked() {
1068 self.open_picker(Purpose::Open);
1069 }
1070 });
1071 });
1072 let rect = drop_frame.response.rect;
1073 if hovered {
1074 ui.painter().rect_stroke(
1075 rect,
1076 12,
1077 egui::Stroke::new(2.0, theme::BLUE),
1078 egui::StrokeKind::Inside,
1079 );
1080 } else {
1081 let stroke = egui::Stroke::new(2.0, theme::DASH);
1082 for (a, b) in [
1083 (rect.left_top(), rect.right_top()),
1084 (rect.right_top(), rect.right_bottom()),
1085 (rect.right_bottom(), rect.left_bottom()),
1086 (rect.left_bottom(), rect.left_top()),
1087 ] {
1088 let direction = (b - a).normalized();
1089 let mut distance = theme::DROP_RADIUS as f32;
1090 while distance < a.distance(b) - theme::DROP_RADIUS as f32 {
1091 ui.painter().line_segment(
1092 [
1093 a + direction * distance,
1094 a + direction
1095 * (distance + theme::SPACE)
1096 .min(a.distance(b) - theme::DROP_RADIUS as f32),
1097 ],
1098 stroke,
1099 );
1100 distance += theme::PAD as f32;
1101 }
1102 }
1103 }
1104 ui.add_space(theme::PAD as f32);
1105 ui.colored_label(
1106 theme::MUTED,
1107 "ZIP, 7z, TAR, GZ, TAR.GZ, TAR.BZ2, TAR.XZ 파일을 열 수 있습니다",
1108 );
1109 });
1110 }
1111
1112 fn archive_list(&mut self, ui: &mut egui::Ui) {
1113 // 경로 줄은 입력란 높이만 차지하고 창 너비 전체를 회색으로 채움.
1114 let path_row = egui::Frame::new()
1115 .fill(theme::STRIPE)
1116 .inner_margin(egui::Margin {
1117 left: 8,
1118 right: 12,
1119 top: 0,
1120 bottom: 0,
1121 })
1122 .show(ui, |ui| {
1123 ui.set_min_width(ui.available_width());
1124 ui.horizontal(|ui| {
1125 ui.set_height(theme::FIELD);
1126 // 간격은 아래에서 직접 넣어 위치가 흔들리지 않게 함.
1127 ui.spacing_mut().item_spacing.x = 0.0;
1128 let up = theme::flat_icon_button(
1129 ui,
1130 "위로",
1131 theme::UP,
1132 !self.folder.is_empty() && !self.model.busy(),
1133 egui::vec2(theme::FIELD, theme::FIELD),
1134 );
1135 if up.clicked() {
1136 let parent = self
1137 .folder
1138 .rsplit_once('/')
1139 .map_or("", |(parent, _)| parent)
1140 .to_owned();
1141 self.browse_folder(&parent);
1142 }
1143 ui.add_space(6.0);
1144 let path = format!("/{}", self.folder);
1145 let search_width = 240.0;
1146 let gap = 8.0;
1147 let path_width = (ui.available_width() - search_width - gap).max(0.0);
1148 // 두 입력란은 같은 높이의 칸을 받아 같은 세로 위치에 그림.
1149 let (path_rect, _) = ui.allocate_exact_size(
1150 egui::vec2(path_width, theme::FIELD),
1151 egui::Sense::hover(),
1152 );
1153 theme::field_frame(ui, path_rect, false);
1154 // 부모 배치에 영향을 주지 않는 하위 영역에 경로 글자를 그림.
1155 let mut text_ui = ui.new_child(
1156 egui::UiBuilder::new()
1157 .max_rect(path_rect.shrink2(egui::vec2(10.0, 0.0)))
1158 .layout(Layout::left_to_right(Align::Center)),
1159 );
1160 theme::bounded_text(&mut text_ui, &path, (path_width - 20.0).max(0.0));
1161 ui.add_space(gap);
1162 let (search_rect, _) = ui.allocate_exact_size(
1163 egui::vec2(search_width, theme::FIELD),
1164 egui::Sense::hover(),
1165 );
1166 let search_id = egui::Id::unique("archive-search");
1167 let focused = ui.memory(|m| m.has_focus(search_id));
1168 theme::field_frame(ui, search_rect, focused);
1169 let icon = egui::Rect::from_center_size(
1170 egui::pos2(search_rect.left() + 20.0, search_rect.center().y),
1171 egui::vec2(16.0, 16.0),
1172 );
1173 theme::svg_icon(ui.painter(), icon, theme::SEARCH, theme::MUTED);
1174 let search = ui.put(
1175 egui::Rect::from_min_max(
1176 egui::pos2(icon.right() + 8.0, search_rect.top() + 1.0),
1177 egui::pos2(search_rect.right() - 8.0, search_rect.bottom() - 1.0),
1178 ),
1179 egui::TextEdit::singleline(&mut self.search)
1180 .id(search_id)
1181 .frame(egui::Frame::NONE)
1182 .margin(egui::Margin::ZERO)
1183 .align(egui::Align2::LEFT_CENTER)
1184 .hint_text("파일 검색"),
1185 );
1186 if search.changed() {
1187 self.clear_list_selection();
1188 }
1189 });
1190 })
1191 .response
1192 .rect;
1193 // 경로 줄 아래 한 줄이 목록과의 경계이자 입력란의 아래 테두리 역할을 함.
1194 ui.painter().hline(
1195 path_row.x_range(),
1196 path_row.bottom() - 0.5,
1197 egui::Stroke::new(1.0, theme::BORDER),
1198 );
1199 let rows = browser::rows(&self.model.entries, &self.folder, &self.search);
1200
1201 // 열 제목 줄 없이 바로 목록을 보여 줌. 이름과 크기는 내용으로 구분됨.
1202 let name_width = (ui.available_width() - 16.0 - 28.0 - 96.0 - 40.0).max(120.0);
1203 let active = !self.model.busy()
1204 && !self.create
1205 && self.model.challenge.is_none()
1206 && self.model.close == Close::Open;
1207 let list_id = egui::Id::unique("archive-list");
1208 let background = ui.interact(
1209 ui.available_rect_before_wrap(),
1210 list_id,
1211 if active {
1212 egui::Sense::click_and_drag()
1213 } else {
1214 egui::Sense::hover()
1215 },
1216 );
1217 background
1218 .widget_info(|| egui::WidgetInfo::labeled(egui::Role::ListBox, active, "파일 목록"));
1219 if background.has_focus() {
1220 ui.ctx().memory_mut(|memory| {
1221 memory.set_focus_lock_filter(
1222 list_id,
1223 egui::EventFilter {
1224 vertical_arrows: true,
1225 escape: true,
1226 ..Default::default()
1227 },
1228 )
1229 });
1230 }
1231 let mut focused = None;
1232 let mut open = None;
1233 let mut next_offset = None;
1234 let output = egui::ScrollArea::vertical()
1235 .id_salt("archive-rows")
1236 .auto_shrink([false, false])
1237 .vertical_scroll_offset(self.list_offset)
1238 .show_viewport(ui, |ui, viewport| {
1239 let origin = ui.max_rect().min;
1240 let clip = ui.clip_rect();
1241 // 행을 누르는 영역은 오른쪽 24px을 비워 둠. 목록이 길어도 그 빈 곳에서
1242 // 끌어서 선택을 시작할 수 있음. 행 배경(선택, 마우스 올림)은 너비를 꽉 채움.
1243 let full_width = ui.available_width();
1244 let width = (full_width - 24.0).max(0.0);
1245 ui.set_min_height((rows.len() as f32 * LIST_ROW).max(viewport.height()));
1246 let point = ui.input(|i| i.pointer.interact_pos());
1247 if active && let Some(point) = point {
1248 let press = ui.input(|i| i.pointer.press_origin()).unwrap_or(point);
1249 let relative = press - origin;
1250 let in_row = relative.x >= 0.0
1251 && relative.x <= width
1252 && relative.y >= 0.0
1253 && relative.y < rows.len() as f32 * LIST_ROW;
1254 if clip.contains(press) && !in_row && ui.input(|i| i.pointer.primary_pressed())
1255 {
1256 background.request_focus();
1257 let ctrl = ui.input(|i| i.modifiers.ctrl || i.modifiers.command);
1258 self.marquee = Some(Marquee {
1259 origin: relative.to_pos2(),
1260 base: if ctrl {
1261 self.model.selected.clone()
1262 } else {
1263 BTreeSet::new()
1264 },
1265 moved: false,
1266 });
1267 if !ctrl {
1268 self.model.selected.clear();
1269 self.list_anchor = None;
1270 self.list_cursor = None;
1271 }
1272 }
1273 if let Some(drag) = &mut self.marquee {
1274 let end = (point.clamp(clip.min, clip.max) - origin).to_pos2();
1275 drag.moved |= drag.origin.distance(end) > 3.0;
1276 if drag.moved {
1277 let rect = egui::Rect::from_two_pos(drag.origin, end);
1278 self.model.selected = drag.base.clone();
1279 if rect.left() < width && rect.right() > 0.0 {
1280 let first = (rect.top().max(0.0) / LIST_ROW).floor() as usize;
1281 let last = ((rect.bottom().max(0.0) / LIST_ROW).ceil() as usize)
1282 .min(rows.len());
1283 for row in rows.iter().take(last).skip(first) {
1284 self.model.selected.extend(&row.ids);
1285 }
1286 if first < last {
1287 self.list_anchor = Some(first);
1288 self.list_cursor = Some(last - 1);
1289 }
1290 }
1291 let speed = if point.y > clip.bottom() - 24.0 {
1292 ((point.y - clip.bottom() + 24.0) / 24.0).clamp(0.0, 3.0)
1293 } else if point.y < clip.top() + 24.0 {
1294 -((clip.top() + 24.0 - point.y) / 24.0).clamp(0.0, 3.0)
1295 } else {
1296 0.0
1297 };
1298 if ui.input(|i| i.pointer.primary_down()) && speed != 0.0 {
1299 let dt = ui.input(|i| i.stable_dt).clamp(0.001, 0.05);
1300 next_offset = Some((viewport.min.y + speed * 500.0 * dt).clamp(
1301 0.0,
1302 (rows.len() as f32 * LIST_ROW - viewport.height()).max(0.0),
1303 ));
1304 ui.ctx().request_repaint();
1305 }
1306 }
1307 }
1308 }
1309 let first = (viewport.min.y / LIST_ROW).floor() as usize;
1310 let last = ((viewport.max.y / LIST_ROW).ceil() as usize + 1).min(rows.len());
1311 for index in first.min(rows.len())..last {
1312 let row = &rows[index];
1313 let rect = egui::Rect::from_min_size(
1314 origin + egui::vec2(0.0, index as f32 * LIST_ROW),
1315 egui::vec2(width, LIST_ROW),
1316 );
1317 let selected = !row.ids.is_empty() && row.ids.is_subset(&self.model.selected);
1318 let response = ui
1319 .interact(
1320 rect,
1321 egui::Id::unique(("archive-row", &row.path)),
1322 if active {
1323 egui::Sense::click()
1324 } else {
1325 egui::Sense::hover()
1326 },
1327 )
1328 .on_hover_text(&row.name);
1329 theme::pointer(&response);
1330 response.widget_info(|| {
1331 egui::WidgetInfo::selected(
1332 egui::Role::ListBoxOption,
1333 active,
1334 selected,
1335 &row.name,
1336 )
1337 });
1338 if response.has_focus() {
1339 focused = Some(index);
1340 ui.ctx().memory_mut(|memory| {
1341 memory.set_focus_lock_filter(
1342 response.id,
1343 egui::EventFilter {
1344 vertical_arrows: true,
1345 escape: true,
1346 ..Default::default()
1347 },
1348 )
1349 });
1350 }
1351 theme::row_background(
1352 ui,
1353 egui::Rect::from_min_size(rect.min, egui::vec2(full_width, LIST_ROW)),
1354 selected,
1355 response.hovered(),
1356 );
1357 if response.clicked() {
1358 background.request_focus();
1359 let modifiers = ui.input(|i| i.modifiers);
1360 self.select_row(
1361 &rows,
1362 index,
1363 modifiers.ctrl || modifiers.command,
1364 modifiers.shift,
1365 );
1366 }
1367 if row.directory && response.double_clicked() {
1368 open = Some(row.path.clone());
1369 }
1370 // 암호가 걸린 항목은 이름 앞에 *를 붙이고, 툴팁은 실제 이름을 보여 줌.
1371 let name = if row.encrypted {
1372 format!("*{}", row.name)
1373 } else {
1374 row.name.clone()
1375 };
1376 Self::entry_cells(
1377 ui,
1378 rect,
1379 row.directory,
1380 &name,
1381 &row.name,
1382 if row.directory {
1383 "0 B".into()
1384 } else {
1385 row.bytes
1386 .map(present::bytes_text)
1387 .unwrap_or_else(|| "—".into())
1388 },
1389 name_width,
1390 );
1391 if active
1392 && self.list_cursor == Some(index)
1393 && (response.has_focus() || background.has_focus())
1394 {
1395 ui.painter().rect_stroke(
1396 egui::Rect::from_min_size(rect.min, egui::vec2(full_width, LIST_ROW))
1397 .shrink(1.0),
1398 0,
1399 egui::Stroke::new(1.0, theme::BLUE),
1400 egui::StrokeKind::Inside,
1401 );
1402 }
1403 }
1404 if rows.is_empty() {
1405 ui.scope_builder(egui::UiBuilder::new().max_rect(clip), |ui| {
1406 ui.centered_and_justified(|ui| {
1407 ui.label(if self.search.is_empty() {
1408 "이 폴더는 비어 있습니다"
1409 } else {
1410 "일치하는 항목이 없습니다"
1411 })
1412 });
1413 });
1414 }
1415 #[cfg(all(feature = "ui-fixture", debug_assertions))]
1416 if let Some(rect) = self.scenario_marquee {
1417 ui.painter().with_clip_rect(clip).rect(
1418 rect.translate(origin.to_vec2()),
1419 0,
1420 theme::BLUE.gamma_multiply(0.16),
1421 egui::Stroke::new(1.0, theme::BLUE),
1422 egui::StrokeKind::Inside,
1423 );
1424 }
1425 if let Some(drag) = &self.marquee
1426 && drag.moved
1427 && let Some(point) = point
1428 {
1429 let rect = egui::Rect::from_two_pos(
1430 origin + drag.origin.to_vec2(),
1431 point.clamp(clip.min, clip.max),
1432 );
1433 ui.painter().with_clip_rect(clip).rect(
1434 rect,
1435 0,
1436 theme::BLUE.gamma_multiply(0.16),
1437 egui::Stroke::new(1.0, theme::BLUE),
1438 egui::StrokeKind::Inside,
1439 );
1440 }
1441 });
1442 self.list_offset = next_offset.unwrap_or(output.state.clamped_offset().y);
1443 if ui.input(|i| i.pointer.primary_released() || !i.pointer.primary_down()) {
1444 self.marquee = None;
1445 }
1446 let escape_from_list = self.list_focused
1447 && ui.ctx().memory(|memory| memory.focused()).is_none()
1448 && ui.input(|i| i.key_pressed(egui::Key::Escape));
1449 self.list_focused =
1450 active && (background.has_focus() || focused.is_some() || escape_from_list);
1451 if self.list_focused {
1452 if let Some(index) = focused {
1453 self.list_cursor = Some(index);
1454 }
1455 let modifiers = ui.input(|i| i.modifiers);
1456 let ctrl = modifiers.ctrl || modifiers.command;
1457 if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
1458 self.model.selected.clear();
1459 self.marquee = None;
1460 background.request_focus();
1461 }
1462 if ctrl && ui.input(|i| i.key_pressed(egui::Key::A)) {
1463 self.model.selected = rows
1464 .iter()
1465 .flat_map(|row| row.ids.iter().copied())
1466 .collect();
1467 self.list_cursor = (!rows.is_empty()).then_some(0);
1468 self.list_anchor = self.list_cursor;
1469 }
1470 if !rows.is_empty() {
1471 let direction = if ui.input(|i| i.key_pressed(egui::Key::ArrowDown)) {
1472 Some(1isize)
1473 } else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp)) {
1474 Some(-1)
1475 } else {
1476 None
1477 };
1478 if let Some(direction) = direction {
1479 let index = self.list_cursor.map_or(0, |index| {
1480 index.saturating_add_signed(direction).min(rows.len() - 1)
1481 });
1482 if ctrl && !modifiers.shift {
1483 self.list_cursor = Some(index);
1484 } else {
1485 self.select_row(&rows, index, ctrl, modifiers.shift);
1486 }
1487 background.request_focus();
1488 let top = index as f32 * LIST_ROW;
1489 if top < self.list_offset {
1490 self.list_offset = top;
1491 } else if top + LIST_ROW > self.list_offset + output.inner_rect.height() {
1492 self.list_offset = top + LIST_ROW - output.inner_rect.height();
1493 }
1494 ui.ctx().request_repaint();
1495 }
1496 if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
1497 let index = self
1498 .list_cursor
1499 .or(focused)
1500 .unwrap_or(0)
1501 .min(rows.len() - 1);
1502 if rows[index].directory {
1503 open = Some(rows[index].path.clone());
1504 }
1505 }
1506 }
1507 if ui.input(|i| i.key_pressed(egui::Key::Backspace)) && !self.folder.is_empty() {
1508 open = Some(
1509 self.folder
1510 .rsplit_once('/')
1511 .map_or("", |(parent, _)| parent)
1512 .to_owned(),
1513 );
1514 }
1515 }
1516 if let Some(folder) = open {
1517 self.browse_folder(&folder);
1518 background.request_focus();
1519 }
1520 }
1521
1522 fn clear_list_selection(&mut self) {
1523 self.model.selected.clear();
1524 self.list_anchor = None;
1525 self.list_cursor = None;
1526 self.list_offset = 0.0;
1527 self.marquee = None;
1528 }
1529
1530 fn select_row(&mut self, rows: &[browser::Row], index: usize, ctrl: bool, shift: bool) {
1531 if shift {
1532 let anchor = self
1533 .list_anchor
1534 .unwrap_or(self.list_cursor.unwrap_or(index))
1535 .min(rows.len() - 1);
1536 if !ctrl {
1537 self.model.selected.clear();
1538 }
1539 for row in &rows[anchor.min(index)..=anchor.max(index)] {
1540 self.model.selected.extend(&row.ids);
1541 }
1542 self.list_anchor = Some(anchor);
1543 } else {
1544 if !ctrl {
1545 self.model.selected.clear();
1546 }
1547 if ctrl && rows[index].ids.is_subset(&self.model.selected) {
1548 // 폴더 이동 시 선택을 지우므로 현재 행의 ID만 제거함.
1549 self.model
1550 .selected
1551 .retain(|id| !rows[index].ids.contains(id));
1552 } else {
1553 self.model.selected.extend(&rows[index].ids);
1554 }
1555 self.list_anchor = Some(index);
1556 }
1557 self.list_cursor = Some(index);
1558 }
1559
1560 fn result_visible(&self) -> bool {
1561 !self.dismissed
1562 && !self.model.busy()
1563 && self.last_request.as_ref().is_some_and(|request| {
1564 !matches!(request, Start::List { .. })
1565 || self.model.error.is_some()
1566 || self
1567 .model
1568 .terminal
1569 .as_ref()
1570 .is_some_and(|t| t.outcome != Outcome::Completed)
1571 })
1572 }
1573
1574 fn error_notice(ui: &mut egui::Ui, error: &str) {
1575 let response = theme::panel(theme::ERROR_BG)
1576 .show(ui, |ui| {
1577 ui.horizontal_wrapped(|ui| {
1578 theme::icon(ui, Icon::Error, 24.0);
1579 ui.colored_label(theme::ERROR, error);
1580 });
1581 })
1582 .response;
1583 response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Alert, true, error));
1584 }
1585
1586 fn work_visible(&self) -> bool {
1587 self.model.busy() || self.result_visible() || (self.ui_error.is_some() && !self.create)
1588 }
1589
1590 /// 메인 창 가운데에 모달(암호 입력, 종료 확인, 파일 선택 안내)이나 같은 자리에 뜨는
1591 /// ZIP 만들기 창이 떠 있는지. 닫기가 정해진 뒤(Allowed)에도 결과 창을 다시 띄우지 않음.
1592 /// 모달이 늘어도 진행·결과 창 숨김 규칙은 이 한 곳만 보면 되도록 모음.
1593 fn main_modal_open(&self) -> bool {
1594 (self.create && !self.model.busy())
1595 || self.picker.is_some()
1596 || self.model.challenge.is_some()
1597 || self.model.resource.is_some()
1598 || self.model.close != Close::Open
1599 }
1600
1601 fn work_window(&mut self, ctx: &egui::Context) {
1602 if !self.work_visible() {
1603 self.work = WorkWindow::default();
1604 return;
1605 }
1606 if ctx.embed_viewports() {
1607 // 별도 창을 만들 수 없는 환경(시험 등)은 show()에서 하단에 그림.
1608 return;
1609 }
1610 if self.main_modal_open() {
1611 // 메인 창 가운데에 뜨는 모달을 항상 위에 뜨는 진행·결과 창이 가리지 않게
1612 // 그동안 창을 닫음. 부모 기준 위치는 기억해 두고 다시 엶.
1613 self.work.open = false;
1614 return;
1615 }
1616 let id = egui::ViewportId::from_hash_of("archive-work");
1617 let title = if self.model.busy() {
1618 present::activity_text(
1619 &self.model,
1620 matches!(self.last_request, Some(Start::CreateZip { .. })),
1621 )
1622 .to_owned()
1623 } else {
1624 "작업 결과".to_owned()
1625 };
1626 let window_title = format!("{title} — Zipelo");
1627 let custom_frame = self.custom_frame;
1628 let size = egui::vec2(WORK_WIDTH, self.work.height);
1629 let builder = self.work.builder(
1630 ctx,
1631 id,
1632 size,
1633 &window_title,
1634 !custom_frame,
1635 self.picker.is_some(),
1636 );
1637 let height = ctx.show_viewport_immediate(id, builder, |ui, class| {
1638 if ui.ctx().input(|i| i.viewport().close_requested()) {
1639 if self.model.busy() {
1640 ui.ctx()
1641 .send_viewport_cmd(egui::ViewportCommand::CancelClose);
1642 } else {
1643 self.dismissed = true;
1644 self.ui_error = None;
1645 self.model.input_error = None;
1646 }
1647 }
1648 if class == egui::ViewportClass::EmbeddedWindow {
1649 ui.set_width(WORK_WIDTH);
1650 self.work_area(ui);
1651 return None;
1652 }
1653 let mut chrome = 0.0;
1654 if custom_frame {
1655 window_frame::title_bar(
1656 ui,
1657 "work",
1658 &window_title,
1659 window_frame::Buttons {
1660 minimize: false,
1661 maximize: false,
1662 },
1663 );
1664 window_frame::edges(ui.ctx(), false);
1665 chrome = window_frame::TITLE_HEIGHT;
1666 }
1667 let margin = theme::PAD as f32;
1668 egui::CentralPanel::default()
1669 .frame(theme::panel(theme::PANEL).corner_radius(0))
1670 .show(ui, |ui| {
1671 let content = ui.vertical(|ui| self.work_area(ui)).response.rect;
1672 Some(content.height() + 2.0 * margin + chrome)
1673 })
1674 .inner
1675 });
1676 if let Some(height) = height {
1677 let height = height.clamp(WORK_MIN_HEIGHT, WORK_MAX_HEIGHT).ceil();
1678 if (height - self.work.height).abs() > 1.0 {
1679 self.work.height = height;
1680 }
1681 }
1682 }
1683
1684 fn work_area(&mut self, ui: &mut egui::Ui) {
1685 // 선택 창 안내 모달은 메인 창만 막으므로, 별도 진행 창의 버튼은 여기서 막음.
1686 let enabled = self.picker.is_none();
1687 ui.add_enabled_ui(enabled, |ui| self.work_contents(ui));
1688 }
1689
1690 fn work_contents(&mut self, ui: &mut egui::Ui) {
1691 if self.model.busy() {
1692 self.progress(ui);
1693 } else if self.result_visible() {
1694 self.result(ui);
1695 }
1696 if !self.create
1697 && let Some(error) = &self.ui_error
1698 {
1699 Self::error_notice(ui, error);
1700 if error == present::FOLDER_ERROR
1701 && theme::action(ui, "폴더 바꾸기", false, true).clicked()
1702 {
1703 self.open_picker(Purpose::Destination);
1704 }
1705 }
1706 if let Some(error) = &self.model.input_error {
1707 ui.colored_label(
1708 theme::ERROR,
1709 if error.starts_with("암호는") {
1710 error.as_str()
1711 } else {
1712 if matches!(self.last_request, Some(Start::CreateZip { .. })) {
1713 "저장 위치와 추가한 항목을 확인하세요"
1714 } else {
1715 "풀 위치와 선택한 항목을 확인하세요"
1716 }
1717 },
1718 );
1719 }
1720 }
1721
1722 fn progress(&mut self, ui: &mut egui::Ui) {
1723 if self.model.resource.is_some() {
1724 ui.horizontal(|ui| {
1725 ui.label("사용자 허용을 기다리고 있습니다");
1726 self.cancel_action(ui, false);
1727 });
1728 return;
1729 }
1730 let creating = matches!(self.last_request, Some(Start::CreateZip { .. }));
1731 let cancelling = self.model.cancellation_requested() || self.model.cancel.is_some();
1732 let title = present::activity_text(&self.model, creating);
1733 ui.strong(title);
1734 if let Some((stage, done, total, count)) = self.model.progress {
1735 // 원본을 읽는 단계에서는 아직 처리한 항목이 없으므로 개수를 표시하지 않음.
1736 let processed = if stage == Stage::Read {
1737 String::new()
1738 } else {
1739 format!("{count}개 처리함, ")
1740 };
1741 if let Some(total) = total.filter(|n| *n > 0) {
1742 ui.scope(|ui| {
1743 ui.visuals_mut().extreme_bg_color = theme::BORDER;
1744 ui.add(
1745 egui::ProgressBar::new((done as f64 / total as f64).clamp(0.0, 1.0) as f32)
1746 .fill(theme::BLUE)
1747 .desired_height(theme::SPACE * 2.0),
1748 );
1749 });
1750 ui.horizontal(|ui| {
1751 ui.label(format!(
1752 "{:.0}% / {processed}{} / {}",
1753 (done as f64 / total as f64).clamp(0.0, 1.0) * 100.0,
1754 present::bytes_text(done),
1755 present::bytes_text(total)
1756 ));
1757 self.cancel_action(ui, cancelling);
1758 });
1759 } else {
1760 theme::indeterminate(ui);
1761 ui.horizontal(|ui| {
1762 ui.label(format!("{processed}{}", present::bytes_text(done)));
1763 self.cancel_action(ui, cancelling);
1764 });
1765 }
1766 } else {
1767 theme::indeterminate(ui);
1768 ui.horizontal(|ui| {
1769 ui.label("작업을 진행하고 있습니다");
1770 self.cancel_action(ui, cancelling);
1771 });
1772 }
1773 }
1774
1775 fn cancel_action(&mut self, ui: &mut egui::Ui, cancelling: bool) {
1776 ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
1777 if theme::action(ui, "취소", false, !cancelling).clicked() {
1778 self.clear_password();
1779 self.model.cancel();
1780 }
1781 });
1782 }
1783
1784 fn result(&mut self, ui: &mut egui::Ui) {
1785 let t = self.model.terminal.clone();
1786 let listing = matches!(self.last_request, Some(Start::List { .. }));
1787 let creating = matches!(self.last_request, Some(Start::CreateZip { .. }));
1788 let warnings = if listing {
1789 Vec::new()
1790 } else {
1791 present::publication_warnings(
1792 t.as_ref(),
1793 self.model.confirmed,
1794 self.targets.as_ref(),
1795 &self.directories,
1796 &self.model.outputs,
1797 )
1798 };
1799 let success = self.model.confirmed
1800 && self.model.error.is_none()
1801 && t.as_ref().is_some_and(|t| t.outcome == Outcome::Completed)
1802 && warnings.is_empty();
1803 let durability_warning = t
1804 .as_ref()
1805 .filter(|_| self.model.confirmed && !listing)
1806 .and_then(|t| present::durability_warning(t.durability));
1807 let durability_in_details = success
1808 && t.as_ref()
1809 .is_some_and(|t| t.durability == Durability::Unconfirmed);
1810 let cancelled =
1811 self.model.confirmed && t.as_ref().is_some_and(|t| t.outcome == Outcome::Cancelled);
1812 let title = if success {
1813 if creating {
1814 "ZIP 파일을 만들었습니다"
1815 } else {
1816 "압축을 풀었습니다"
1817 }
1818 } else if cancelled {
1819 "작업을 취소했습니다"
1820 } else if listing {
1821 "압축파일을 열지 못했습니다"
1822 } else if creating {
1823 "ZIP 파일을 만들지 못했습니다"
1824 } else {
1825 "압축을 풀지 못했습니다"
1826 };
1827 let fill = if success {
1828 theme::SUCCESS_BG
1829 } else if cancelled {
1830 theme::STRIPE
1831 } else {
1832 theme::ERROR_BG
1833 };
1834 let mut choose = false;
1835 let mut retry = false;
1836 let mut expand = false;
1837 let mut reopen = false;
1838 let mut folder = false;
1839 theme::panel(fill).show(ui, |ui| {
1840 ui.horizontal(|ui| {
1841 theme::icon(
1842 ui,
1843 if success {
1844 Icon::Success
1845 } else if cancelled {
1846 Icon::Warning
1847 } else {
1848 Icon::Error
1849 },
1850 24.0,
1851 );
1852 ui.strong(title);
1853 });
1854 let max_height = WORK_RESULT_MAX_HEIGHT;
1855 egui::ScrollArea::vertical()
1856 .id_salt("result-message")
1857 .max_height(max_height)
1858 .show(ui, |ui| {
1859 if success {
1860 let path = match self.last_request.as_ref() {
1861 Some(Start::CreateZip { output_file, .. }) => {
1862 output_file.display().to_string()
1863 }
1864 _ => format!("{} 폴더에 저장했습니다.", self.destination.display()),
1865 };
1866 theme::bounded_text(ui, &path, ui.available_width());
1867 } else if let Some(code) = t.as_ref().and_then(|t| t.error) {
1868 ui.label(if creating && code == ErrorCode::SourceChanged {
1869 "묶을 파일이 바뀌었습니다. 파일을 확인한 뒤 다시 만드세요".to_owned()
1870 } else {
1871 present::operation_text(present::error_text(code), creating)
1872 });
1873 } else if let Some(error) = &self.model.error {
1874 ui.label(present::operation_text(
1875 present::client_error_text(error),
1876 creating,
1877 ));
1878 }
1879 for warning in warnings
1880 .iter()
1881 .copied()
1882 .chain(durability_warning.filter(|_| !durability_in_details))
1883 {
1884 ui.horizontal_wrapped(|ui| {
1885 theme::icon(ui, Icon::Warning, 20.0);
1886 ui.colored_label(
1887 theme::WARNING,
1888 present::operation_text(warning, creating),
1889 );
1890 });
1891 }
1892 if !success
1893 && !listing
1894 && present::definitely_unsaved(
1895 t.as_ref(),
1896 self.model.confirmed,
1897 &self.model.outputs,
1898 )
1899 {
1900 ui.label(if creating {
1901 "ZIP 파일을 만들지 않았습니다"
1902 } else {
1903 "아무 파일도 풀지 않았습니다"
1904 });
1905 }
1906 if t.as_ref().is_some_and(|t| {
1907 t.error == Some(ErrorCode::Limit)
1908 && (t.created_count > 0
1909 || t.retained_partial_count > 0
1910 || t.publication != Publication::None)
1911 }) {
1912 ui.label(format!(
1913 "{}개 파일이 저장되었거나 일부 남아 있습니다. 저장 위치를 확인하세요.",
1914 t.as_ref().unwrap().created_count
1915 ));
1916 theme::bounded_text(
1917 ui,
1918 &self.destination.display().to_string(),
1919 ui.available_width(),
1920 );
1921 }
1922 if self.details {
1923 theme::panel(theme::STRIPE).show(ui, |ui| {
1924 if durability_in_details {
1925 if let Some(warning) = durability_warning {
1926 ui.label(present::operation_text(warning, creating));
1927 }
1928 }
1929 if let Some(t) = &t {
1930 for line in terminal_lines(t) {
1931 ui.label(line);
1932 }
1933 }
1934 if let Some(error) = &self.model.error {
1935 ui.label(error);
1936 }
1937 for (name, state) in &self.model.outputs {
1938 theme::bounded_text(
1939 ui,
1940 &format!("{name}: {}", disposition_label(*state)),
1941 ui.available_width(),
1942 );
1943 }
1944 });
1945 }
1946 });
1947 let conflict = t
1948 .as_ref()
1949 .is_some_and(|t| t.error == Some(ErrorCode::Conflict))
1950 && !creating;
1951 let uncertain = warnings.contains(&present::UNCERTAIN);
1952 if conflict && uncertain {
1953 let response = ui.checkbox(
1954 &mut self.checked_destination,
1955 "기존 풀 위치 폴더를 확인했습니다",
1956 );
1957 theme::pointer(&response);
1958 theme::focus(&response);
1959 }
1960 ui.horizontal(|ui| {
1961 if theme::action(
1962 ui,
1963 if self.details {
1964 "자세히 닫기"
1965 } else {
1966 "자세히 보기"
1967 },
1968 false,
1969 true,
1970 )
1971 .clicked()
1972 {
1973 self.details = !self.details;
1974 }
1975 let action = if success {
1976 Some(("폴더 열기", true))
1977 } else if conflict {
1978 Some((
1979 if self
1980 .model
1981 .list_id
1982 .as_ref()
1983 .is_some_and(|id| id.format == Format::Gzip)
1984 {
1985 "다른 이름으로 저장"
1986 } else {
1987 "다른 폴더에 풀기"
1988 },
1989 !uncertain || self.checked_destination,
1990 ))
1991 } else if t
1992 .as_ref()
1993 .is_some_and(|t| t.error == Some(ErrorCode::SourceChanged))
1994 {
1995 Some((
1996 if creating {
1997 "다시 만들기"
1998 } else {
1999 "압축파일 다시 열기"
2000 },
2001 true,
2002 ))
2003 } else if self.model.can_retry_expanded() {
2004 None
2005 } else if t
2006 .as_ref()
2007 .is_some_and(|t| t.error == Some(ErrorCode::Limit))
2008 {
2009 None
2010 } else if !cancelled && (!uncertain || listing) {
2011 Some(("다시 시도", true))
2012 } else {
2013 None
2014 };
2015 let (confirm, primary) = theme::action_pair(ui, "확인", action);
2016 if confirm {
2017 self.dismissed = true;
2018 self.ui_error = None;
2019 self.model.input_error = None;
2020 }
2021 if primary {
2022 match action.map(|(label, _)| label) {
2023 Some("폴더 열기") => folder = true,
2024 Some("다른 폴더에 풀기" | "다른 이름으로 저장") => {
2025 choose = true
2026 }
2027 Some("압축파일 다시 열기") => reopen = true,
2028 Some("다시 시도" | "다시 만들기") => retry = true,
2029 _ => {}
2030 }
2031 }
2032 });
2033 if self.model.can_retry_expanded() {
2034 ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
2035 expand = theme::action(ui, "한도를 늘려 다시 시도", true, true).clicked();
2036 });
2037 }
2038 });
2039 if choose {
2040 self.open_picker(Purpose::Retry);
2041 }
2042 if retry {
2043 self.retry();
2044 }
2045 if expand {
2046 let ready = if matches!(self.last_request, Some(Start::Extract { .. })) {
2047 match present::prepare_destination(&self.destination, self.automatic_destination) {
2048 Ok(created) => {
2049 self.owned_destination = created.then(|| self.destination.clone());
2050 true
2051 }
2052 Err(_) => {
2053 self.ui_error = Some(present::FOLDER_ERROR.into());
2054 false
2055 }
2056 }
2057 } else {
2058 true
2059 };
2060 if ready && self.model.retry_expanded(self.factory.as_mut()) {
2061 self.dismissed = false;
2062 self.details = false;
2063 self.ui_error = None;
2064 }
2065 }
2066 if reopen {
2067 if let Some(path) = self.model.archive.clone() {
2068 self.open_path(path);
2069 }
2070 }
2071 if folder {
2072 let path = match self.last_request.as_ref() {
2073 Some(Start::CreateZip { output_file, .. }) => {
2074 output_file.parent().unwrap_or(Path::new("/"))
2075 }
2076 _ => self.destination.as_path(),
2077 };
2078 match present::folder_command(path).spawn() {
2079 Ok(mut child) => {
2080 std::thread::spawn(move || {
2081 let _ = child.wait();
2082 });
2083 }
2084 Err(_) => {
2085 self.ui_error = Some(
2086 "폴더를 열지 못했습니다. 파일 탐색기에서 저장 위치를 확인하세요".into(),
2087 )
2088 }
2089 }
2090 }
2091 }
2092
2093 /// 파일 목록 한 행의 아이콘, 이름, 크기 칸. 메인 목록과 ZIP 만들기 창이 같이 씀.
2094 fn entry_cells(
2095 ui: &mut egui::Ui,
2096 rect: egui::Rect,
2097 directory: bool,
2098 name: &str,
2099 hover: &str,
2100 size: String,
2101 name_width: f32,
2102 ) {
2103 ui.scope_builder(
2104 egui::UiBuilder::new()
2105 .max_rect(rect.shrink2(egui::vec2(0.0, 2.0)))
2106 .layout(Layout::left_to_right(Align::Center)),
2107 |ui| {
2108 ui.style_mut().interaction.selectable_labels = false;
2109 ui.add_space(16.0);
2110 theme::icon(ui, if directory { Icon::Folder } else { Icon::File }, 20.0);
2111 theme::bounded_text_hover(ui, name, hover, name_width);
2112 theme::column_label(ui, size, 96.0, Align::Max);
2113 },
2114 );
2115 }
2116
2117 /// ZIP 만들기를 진행 창처럼 부모 창을 따라가는 별도 창으로 띄움.
2118 /// 별도 창을 만들 수 없는 환경(시험 등)에서는 메인 창 안의 모달로 띄움.
2119 fn create_window(&mut self, ctx: &egui::Context) {
2120 if !self.create || self.model.busy() {
2121 self.create_win = WorkWindow::default();
2122 return;
2123 }
2124 if ctx.embed_viewports() {
2125 let mut close = false;
2126 let modal = egui::Modal::new(egui::Id::unique("create-zip")).show(ctx, |ui| {
2127 ui.set_width((ctx.content_rect().width() - 64.0).min(CREATE_WIDTH));
2128 ui.horizontal(|ui| {
2129 ui.heading("ZIP 만들기");
2130 ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
2131 let button = theme::icon_button(ui, "닫기", theme::CLOSE, true);
2132 close = button.clicked();
2133 });
2134 });
2135 close |= self.create_area(ui);
2136 ui.add_space(theme::SPACE);
2137 close |= self.create_actions(ui);
2138 });
2139 if close || modal.should_close() {
2140 self.close_create();
2141 }
2142 return;
2143 }
2144 let id = egui::ViewportId::from_hash_of("archive-create");
2145 let title = "ZIP 만들기 — Zipelo";
2146 let custom_frame = self.custom_frame;
2147 if !self.create_win.open {
2148 self.create_win.height = self.create_win.height.max(CREATE_MIN_HEIGHT);
2149 }
2150 let size = egui::vec2(CREATE_WIDTH, self.create_win.height);
2151 let builder =
2152 self.create_win
2153 .builder(ctx, id, size, title, !custom_frame, self.picker.is_some());
2154 let mut close = false;
2155 let height = ctx.show_viewport_immediate(id, builder, |ui, class| {
2156 if ui.ctx().input(|i| i.viewport().close_requested()) {
2157 close = true;
2158 }
2159 if class == egui::ViewportClass::EmbeddedWindow {
2160 ui.set_width(CREATE_WIDTH);
2161 close |= self.create_area(ui);
2162 close |= self.create_actions(ui);
2163 return None;
2164 }
2165 let mut chrome = 0.0;
2166 if custom_frame {
2167 window_frame::title_bar(
2168 ui,
2169 "create",
2170 title,
2171 window_frame::Buttons {
2172 minimize: false,
2173 maximize: false,
2174 },
2175 );
2176 window_frame::edges(ui.ctx(), false);
2177 chrome = window_frame::TITLE_HEIGHT;
2178 }
2179 // 버튼은 창 오른쪽 아래에 여백을 두고 고정함. 위 내용이 바뀌어도 자리가 같음.
2180 let actions = egui::Panel::bottom(egui::Id::unique("create-actions"))
2181 .resizable(false)
2182 .show_separator_line(false)
2183 .frame(
2184 egui::Frame::new()
2185 .fill(theme::PANEL)
2186 .inner_margin(egui::Margin {
2187 left: theme::PAD,
2188 right: theme::PAD,
2189 top: 0,
2190 bottom: theme::PAD,
2191 }),
2192 )
2193 .show(ui, |ui| close |= self.create_actions(ui))
2194 .response
2195 .rect
2196 .height();
2197 let margin = theme::PAD as f32;
2198 egui::CentralPanel::default()
2199 .frame(theme::panel(theme::PANEL).corner_radius(0))
2200 .show(ui, |ui| {
2201 let content = ui
2202 .vertical(|ui| close |= self.create_area(ui))
2203 .response
2204 .rect;
2205 Some(content.height() + 2.0 * margin + chrome + actions)
2206 })
2207 .inner
2208 });
2209 if let Some(height) = height {
2210 let height = height.clamp(CREATE_MIN_HEIGHT, 900.0).ceil();
2211 if (height - self.create_win.height).abs() > 1.0 {
2212 self.create_win.height = height;
2213 }
2214 }
2215 if close {
2216 self.close_create();
2217 }
2218 }
2219
2220 /// ZIP 만들기 내용. 닫기를 눌렀으면 true를 돌려줌.
2221 fn create_area(&mut self, ui: &mut egui::Ui) -> bool {
2222 // 저장 위치 선택 창이 응답을 기다리는 동안에는 버튼을 막음.
2223 let enabled = self.picker.is_none();
2224 ui.add_enabled_ui(enabled, |ui| self.create_contents(ui))
2225 .inner
2226 }
2227
2228 fn create_contents(&mut self, ui: &mut egui::Ui) -> bool {
2229 let rows = self.create_rows();
2230 let root = self.create_root();
2231
2232 // 경로 줄: 메인 화면처럼 위로 버튼과 현재 폴더 경로.
2233 ui.horizontal(|ui| {
2234 ui.set_height(theme::FIELD);
2235 ui.spacing_mut().item_spacing.x = 0.0;
2236 let up = theme::flat_icon_button(
2237 ui,
2238 "위로",
2239 theme::UP,
2240 !self.create_folder.is_empty(),
2241 egui::vec2(theme::FIELD, theme::FIELD),
2242 );
2243 if up.clicked() {
2244 self.create_folder = self
2245 .create_folder
2246 .rsplit_once('/')
2247 .map_or("", |(parent, _)| parent)
2248 .to_owned();
2249 self.create_selected = None;
2250 }
2251 ui.add_space(6.0);
2252 let path = match &root {
2253 Some(root) => {
2254 let name = root.file_name().unwrap_or_default().to_string_lossy();
2255 if self.create_folder.is_empty() {
2256 format!("/{name}")
2257 } else {
2258 format!("/{name}/{}", self.create_folder)
2259 }
2260 }
2261 None => "/".to_owned(),
2262 };
2263 let (rect, _) = ui.allocate_exact_size(
2264 egui::vec2(ui.available_width(), theme::FIELD),
2265 egui::Sense::hover(),
2266 );
2267 theme::boxed_field(ui, rect);
2268 theme::field_text(ui, rect, &path);
2269 });
2270 ui.add_space(theme::SPACE);
2271
2272 // 파일 목록: 메인 화면 목록과 같은 행 모양. 폴더를 두 번 누르면 들어감.
2273 let mut enter = None;
2274 egui::Frame::new()
2275 .stroke(egui::Stroke::new(1.0, theme::BORDER))
2276 .show(ui, |ui| {
2277 ui.set_min_size(egui::vec2(ui.available_width(), CREATE_LIST_HEIGHT));
2278 ui.set_max_height(CREATE_LIST_HEIGHT);
2279 let message = match &rows {
2280 None => Some("폴더를 읽지 못했습니다"),
2281 Some(rows) if rows.is_empty() => Some("이 폴더는 비어 있습니다"),
2282 Some(_) => None,
2283 };
2284 if let Some(message) = message {
2285 ui.centered_and_justified(|ui| ui.label(message));
2286 return;
2287 }
2288 let rows = rows.unwrap();
2289 let name_width = (ui.available_width() - 16.0 - 28.0 - 96.0 - 24.0).max(80.0);
2290 egui::ScrollArea::vertical()
2291 .id_salt("create-rows")
2292 .auto_shrink([false, false])
2293 .max_height(CREATE_LIST_HEIGHT)
2294 .show_rows(ui, LIST_ROW, rows.len(), |ui, range| {
2295 for row in &rows[range] {
2296 let (rect, response) = ui.allocate_exact_size(
2297 egui::vec2(ui.available_width(), LIST_ROW),
2298 egui::Sense::click(),
2299 );
2300 let response = response.on_hover_text(&row.name);
2301 theme::pointer(&response);
2302 response.widget_info(|| {
2303 egui::WidgetInfo::labeled(
2304 egui::Role::ListBoxOption,
2305 true,
2306 &row.name,
2307 )
2308 });
2309 if response.clicked() {
2310 self.create_selected = Some(row.name.clone());
2311 }
2312 theme::row_background(
2313 ui,
2314 rect,
2315 self.create_selected.as_deref() == Some(row.name.as_str()),
2316 response.hovered(),
2317 );
2318 if row.directory && root.is_some() && response.clicked() {
2319 // egui가 한 프레임을 다시 그리면 두 번 누름 정보가 사라질 수 있어
2320 // 같은 폴더를 다른 프레임에서 0.4초 안에 다시 누르면 두 번 누름으로 봄.
2321 let frame = ui.ctx().cumulative_frame_nr();
2322 let time = ui.input(|i| i.time);
2323 match &self.create_last_click {
2324 Some((name, last_frame, last_time))
2325 if name == &row.name
2326 && *last_frame != frame
2327 && time - last_time < 0.4 =>
2328 {
2329 enter = Some(row.name.clone());
2330 self.create_last_click = None;
2331 }
2332 Some((name, last_frame, _))
2333 if name == &row.name && *last_frame == frame => {}
2334 _ => {
2335 self.create_last_click =
2336 Some((row.name.clone(), frame, time));
2337 }
2338 }
2339 }
2340 Self::entry_cells(
2341 ui,
2342 rect,
2343 row.directory,
2344 &row.name,
2345 &row.name,
2346 row.bytes.map(present::bytes_text).unwrap_or_default(),
2347 name_width,
2348 );
2349 }
2350 });
2351 });
2352 if let Some(name) = enter {
2353 self.create_folder = if self.create_folder.is_empty() {
2354 name
2355 } else {
2356 format!("{}/{name}", self.create_folder)
2357 };
2358 self.create_selected = None;
2359 }
2360 ui.add_space(theme::SPACE);
2361
2362 if let Some(error) = &self.ui_error {
2363 Self::error_notice(ui, error);
2364 }
2365
2366 // 암호: 체크하면 바로 아래에 암호와 암호 확인 칸을 보여 줌.
2367 let check = ui.checkbox(&mut self.aes256, "암호로 보호하기");
2368 theme::pointer(&check);
2369 theme::focus(&check);
2370 if self.aes256 {
2371 let label_width = 72.0;
2372 ui.horizontal(|ui| {
2373 ui.add_sized([label_width, theme::FIELD], egui::Label::new("암호"));
2374 let toggle = if self.zip_password_visible {
2375 "숨기기"
2376 } else {
2377 "보기"
2378 };
2379 let toggle_width = 72.0;
2380 let edit = ui.add_sized(
2381 [
2382 (ui.available_width() - toggle_width - theme::SPACE).max(80.0),
2383 theme::FIELD,
2384 ],
2385 egui::TextEdit::singleline(&mut self.zip_password)
2386 .password(!self.zip_password_visible)
2387 .id(egui::Id::unique("zip-password-input"))
2388 .char_limit(1024)
2389 .align(egui::Align2::LEFT_CENTER),
2390 );
2391 theme::focus(&edit);
2392 if theme::action(ui, toggle, false, true).clicked() {
2393 self.zip_password_visible = !self.zip_password_visible;
2394 }
2395 });
2396 ui.horizontal(|ui| {
2397 ui.add_sized([label_width, theme::FIELD], egui::Label::new("암호 확인"));
2398 let edit = ui.add_sized(
2399 [
2400 (ui.available_width() - 72.0 - theme::SPACE).max(80.0),
2401 theme::FIELD,
2402 ],
2403 egui::TextEdit::singleline(&mut self.zip_password_confirm)
2404 .password(!self.zip_password_visible)
2405 .id(egui::Id::unique("zip-password-confirm"))
2406 .char_limit(1024)
2407 .align(egui::Align2::LEFT_CENTER),
2408 );
2409 theme::focus(&edit);
2410 });
2411 if self.zip_password.len() > 1024 {
2412 ui.colored_label(theme::ERROR, "암호는 UTF-8 1~1024바이트로 입력하세요");
2413 } else if !self.zip_password_confirm.is_empty()
2414 && self.zip_password != self.zip_password_confirm
2415 {
2416 ui.colored_label(theme::ERROR, "두 암호가 같지 않습니다");
2417 }
2418 ui.label(RichText::new("암호를 잊으면 파일을 열 수 없습니다.").color(theme::MUTED));
2419 } else if check.changed()
2420 || !self.zip_password.is_empty()
2421 || !self.zip_password_confirm.is_empty()
2422 {
2423 // 체크를 해제하면 입력한 암호와 그 실행 취소 기록을 남겨 두지 않음.
2424 // 입력했다가 모두 지운 경우도 기록에는 남아 있으므로 해제한 순간 함께 지움.
2425 self.clear_zip_password();
2426 }
2427 false
2428 }
2429
2430 /// 취소와 압축하기 버튼. 취소를 눌렀으면 true.
2431 fn create_actions(&mut self, ui: &mut egui::Ui) -> bool {
2432 let ready = !self.sources.is_empty() && self.zip_password_ready();
2433 let enabled = self.picker.is_none();
2434 let (cancel, compress) = ui
2435 .add_enabled_ui(enabled, |ui| {
2436 theme::action_pair(ui, "취소", Some(("압축하기", ready)))
2437 })
2438 .inner;
2439 if compress {
2440 self.open_picker(Purpose::SaveZip);
2441 }
2442 cancel
2443 }
2444
2445 fn resource_dialog(&mut self, ctx: &egui::Context) {
2446 let Some(question) = self.model.resource.clone() else {
2447 return;
2448 };
2449 let Some(job) = self.model.job_id() else {
2450 return;
2451 };
2452 let mut allow = false;
2453 let mut cancel = false;
2454 let modal = egui::Modal::new(egui::Id::unique(("archive-resource", job, question.id)))
2455 .show(ctx, |ui| {
2456 ui.set_width((ctx.content_rect().width() - 64.0).min(460.0));
2457 ui.heading(if question.scope.ratio {
2458 "압축률이 매우 높습니다"
2459 } else {
2460 "큰 작업을 허용할까요?"
2461 });
2462 ui.label(match question.action {
2463 ActionKind::List => "압축파일 목록 열기",
2464 ActionKind::Extract => "압축 해제",
2465 ActionKind::CreateZip => "ZIP 만들기",
2466 });
2467 if question.scope.ratio {
2468 ui.label("작은 압축파일도 많은 저장 공간을 사용할 수 있습니다.");
2469 }
2470 if question.scope.output {
2471 ui.label(format!(
2472 "총량 한도: {}에서 {}로",
2473 present::bytes_text(question.soft_limits.output),
2474 present::bytes_text(question.ceiling.output)
2475 ));
2476 }
2477 if question.scope.entries {
2478 ui.label(format!(
2479 "항목 한도: {}개에서 {}개로",
2480 question.soft_limits.entries, question.ceiling.entries
2481 ));
2482 }
2483 let mut u = question.usage;
2484 let estimated = self.model.estimated_usage();
2485 u.estimated_bytes = u.estimated_bytes.or(estimated.estimated_bytes);
2486 u.estimated_entries = u.estimated_entries.or(estimated.estimated_entries);
2487 let bytes = |value: Option<u64>| {
2488 value
2489 .map(present::bytes_text)
2490 .unwrap_or_else(|| "미확인".into())
2491 };
2492 let entries = |value: Option<u32>| {
2493 value
2494 .map(|n| format!("{n}개"))
2495 .unwrap_or_else(|| "미확인".into())
2496 };
2497 ui.label(format!(
2498 "예상 총량: {} / 실제 총량: {}",
2499 bytes(u.estimated_bytes),
2500 bytes(u.actual_bytes)
2501 ));
2502 ui.label(format!(
2503 "예상 항목: {} / 실제 항목: {}",
2504 entries(u.estimated_entries),
2505 entries(u.actual_entries)
2506 ));
2507 if question.scope.ratio {
2508 ui.label(format!(
2509 "압축 크기: {} / 풀린 크기: {}",
2510 bytes(u.compressed_bytes),
2511 bytes(u.ratio_output_bytes)
2512 ));
2513 }
2514 ui.label(format!(
2515 "확인한 저장 볼륨의 여유 공간: {}",
2516 bytes(u.available_bytes)
2517 ));
2518 ui.label(format!(
2519 "이 작업의 상한: {} / {}개",
2520 present::bytes_text(question.ceiling.output),
2521 question.ceiling.entries
2522 ));
2523 ui.label("이 작업에만 적용합니다. 공간 부족이나 자원 상한에 도달하면 중단합니다.");
2524 ui.horizontal(|ui| {
2525 cancel = theme::action(ui, "취소", false, true).clicked();
2526 allow = theme::action(ui, "이 작업 허용", true, true).clicked();
2527 });
2528 });
2529 if cancel || modal.should_close() {
2530 self.clear_password();
2531 self.model.cancel();
2532 } else if allow {
2533 self.model.resource_reply(job, question.id, true);
2534 }
2535 }
2536
2537 fn password_dialog(&mut self, ctx: &egui::Context, new_challenge: bool) {
2538 let (_, attempt, encrypt) = self.model.challenge.unwrap();
2539 let mut submit = false;
2540 let mut cancel = false;
2541 let password_enter = ctx.memory(|memory| memory.focused()).is_some_and(|id| {
2542 id == egui::Id::unique("archive-password-input")
2543 || id == egui::Id::unique("archive-password-confirm")
2544 }) && ctx.input(|input| input.key_pressed(egui::Key::Enter));
2545 let modal = egui::Modal::new(egui::Id::unique("archive-password")).show(ctx, |ui| {
2546 ui.set_width((ctx.content_rect().width() - 64.0).min(420.0));
2547 ui.heading(if encrypt {
2548 "ZIP 암호 설정"
2549 } else {
2550 "암호가 필요합니다"
2551 });
2552 if encrypt {
2553 ui.label("암호를 잊으면 파일을 열 수 없습니다.");
2554 } else if let Some(path) = &self.model.archive {
2555 ui.label(format!(
2556 "{}은 암호로 보호되어 있습니다.",
2557 present::middle_text(
2558 &path.file_name().unwrap_or_default().to_string_lossy(),
2559 24
2560 )
2561 ));
2562 }
2563 ui.horizontal(|ui| {
2564 ui.label("암호");
2565 let edit = ui.add(
2566 egui::TextEdit::singleline(&mut self.password)
2567 .password(!self.password_visible)
2568 .id(egui::Id::unique("archive-password-input"))
2569 .char_limit(1024)
2570 .desired_width(232.0),
2571 );
2572 theme::focus(&edit);
2573 if new_challenge {
2574 edit.request_focus();
2575 }
2576 if theme::action(
2577 ui,
2578 if self.password_visible {
2579 "숨기기"
2580 } else {
2581 "보기"
2582 },
2583 false,
2584 true,
2585 )
2586 .clicked()
2587 {
2588 self.password_visible = !self.password_visible;
2589 }
2590 });
2591 if encrypt {
2592 ui.horizontal(|ui| {
2593 ui.label("암호 확인");
2594 let edit = ui.add(
2595 egui::TextEdit::singleline(&mut self.password_confirm)
2596 .password(!self.password_visible)
2597 .id(egui::Id::unique("archive-password-confirm"))
2598 .char_limit(1024)
2599 .desired_width(232.0),
2600 );
2601 theme::focus(&edit);
2602 });
2603 if self.password != self.password_confirm {
2604 ui.colored_label(theme::ERROR, "두 암호가 같지 않습니다");
2605 }
2606 } else if attempt > 1 {
2607 ui.colored_label(theme::ERROR, "암호가 맞지 않습니다. 다시 입력하세요");
2608 }
2609 if self.password.len() > 1024 {
2610 ui.colored_label(theme::ERROR, "암호는 UTF-8 1~1024바이트로 입력하세요");
2611 }
2612 let valid = !self.password.is_empty()
2613 && self.password.len() <= 1024
2614 && (!encrypt || self.password == self.password_confirm);
2615 let actions = theme::action_pair(ui, "취소", Some(("확인", valid)));
2616 cancel = actions.0;
2617 submit = actions.1 || (valid && password_enter);
2618 });
2619 if modal.should_close() || cancel {
2620 self.clear_password();
2621 self.model.cancel();
2622 } else if submit {
2623 let password = std::mem::take(&mut self.password);
2624 self.clear_password();
2625 self.model.password(password);
2626 }
2627 }
2628
2629 fn close_dialog(&mut self, ctx: &egui::Context) {
2630 // Review(결과 확인 후 닫기)는 show()에서 바로 확인 처리하므로 그리지 않음.
2631 if matches!(
2632 self.model.close,
2633 Close::Open | Close::Allowed | Close::Review
2634 ) {
2635 return;
2636 }
2637 egui::Modal::new(egui::Id::unique("archive-close")).show(ctx, |ui| {
2638 ui.set_width(420.0);
2639 match self.model.close {
2640 Close::Confirm => {
2641 // 답하기 전에 작업이 끝났으면 취소할 작업이 없으므로 닫을지만 물음.
2642 let busy = self.model.busy();
2643 let (heading, text, keep, close) = if busy {
2644 (
2645 "작업 중 닫기",
2646 "작업을 취소하고 닫을까요?",
2647 "계속 작업",
2648 "취소하고 닫기",
2649 )
2650 } else {
2651 (
2652 "닫기",
2653 "작업이 끝났습니다. 창을 닫을까요?",
2654 "열어 두기",
2655 "닫기",
2656 )
2657 };
2658 ui.heading(heading);
2659 ui.label(text);
2660 ui.horizontal(|ui| {
2661 if theme::action(ui, keep, false, true).clicked() {
2662 self.model.keep_open();
2663 }
2664 if theme::action(ui, close, true, true).clicked() {
2665 self.clear_password();
2666 self.model.confirm_close();
2667 }
2668 });
2669 }
2670 Close::Waiting => {
2671 ui.heading("종료 확인 중");
2672 ui.label("마무리하는 중입니다. 잠시만 기다려 주세요");
2673 if theme::action(ui, "닫기 취소", false, true).clicked() {
2674 self.model.keep_open();
2675 }
2676 }
2677 _ => {}
2678 }
2679 });
2680 }
2681}
2682
2683impl eframe::App for ArchiveApp {
2684 fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) {
2685 self.show(root);
2686 }
2687
2688 fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
2689 // 운영체제가 창 이동을 맡으면 버튼 놓기가 오지 않으므로 대신 넣어 눌림 상태를 풀어 줌.
2690 if std::mem::take(&mut self.release_after_move) {
2691 let pos = ctx.input(|i| i.pointer.latest_pos()).unwrap_or_default();
2692 raw_input.events.insert(
2693 0,
2694 egui::Event::PointerButton {
2695 pos,
2696 button: egui::PointerButton::Primary,
2697 pressed: false,
2698 modifiers: ctx.input(|i| i.modifiers),
2699 },
2700 );
2701 }
2702 }
2703}
2704impl Drop for ArchiveApp {
2705 fn drop(&mut self) {
2706 self.clear_password();
2707 }
2708}