| | @@ -16,6 +16,52 @@ use std::{ |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | const 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 | +추가: } |
| 19 | 65 | const WORK_MIN_HEIGHT: f32 = 96.0; |
| 20 | 66 | const WORK_MAX_HEIGHT: f32 = 520.0; |
| 21 | 67 | const WORK_RESULT_MAX_HEIGHT: f32 = 220.0; |
| | @@ -46,6 +92,84 @@ impl Default for WorkWindow { |
| 46 | 92 | } |
| 47 | 93 | } |
| 48 | 94 | |
| 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 | +추가: |
| 49 | 173 | struct Marquee { |
| 50 | 174 | // 스크롤 중에도 시작점을 목록 좌표로 유지함. |
| 51 | 175 | origin: egui::Pos2, |
| | @@ -77,6 +201,17 @@ pub struct ArchiveApp { |
| 77 | 201 | dialogs: Box<dyn Dialogs>, |
| 78 | 202 | picker: Option<(Purpose, std::sync::mpsc::Receiver<DialogAnswer>)>, |
| 79 | 203 | 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>, |
| 80 | 215 | custom_frame: bool, |
| 81 | 216 | release_after_move: bool, |
| 82 | 217 | folder: String, |
| | @@ -119,6 +254,14 @@ impl ArchiveApp { |
| 119 | 254 | dialogs: Box::new(NativeDialogs), |
| 120 | 255 | picker: None, |
| 121 | 256 | 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, |
| 122 | 265 | custom_frame: false, |
| 123 | 266 | release_after_move: false, |
| 124 | 267 | folder: String::new(), |
| | @@ -174,6 +317,72 @@ impl ArchiveApp { |
| 174 | 317 | self.password_visible = false; |
| 175 | 318 | } |
| 176 | 319 | |
| 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 | +추가: |
| 177 | 386 | pub fn open_path(&mut self, archive: PathBuf) { |
| 178 | 387 | if self.model.busy() { |
| 179 | 388 | return; |
| | @@ -255,6 +464,8 @@ impl ArchiveApp { |
| 255 | 464 | self.sources.push(path); |
| 256 | 465 | } |
| 257 | 466 | } |
| 467 | +추가: self.create_folder.clear(); |
| 468 | +추가: self.create_listing = None; |
| 258 | 469 | self.create = true; |
| 259 | 470 | } |
| 260 | 471 | |
| | @@ -346,8 +557,14 @@ impl ArchiveApp { |
| 346 | 557 | }; |
| 347 | 558 | sources.push((path.clone(), name.to_owned())); |
| 348 | 559 | } |
| 560 | +추가: if !self.zip_password_ready() { |
| 561 | +추가: self.ui_error = Some("두 암호가 같은지 확인하세요".into()); |
| 562 | +추가: return; |
| 563 | +추가: } |
| 349 | 564 | self.targets = Some([self.zip_name.clone()].into_iter().collect()); |
| 350 | 565 | self.directories.clear(); |
| 566 | +추가: // 암호는 ZIP 만들기 창에서 받아 두었다가 작업자가 요청하면 넘김. |
| 567 | +추가: let password = self.aes256.then(|| std::mem::take(&mut self.zip_password)); |
| 351 | 568 | if self.start(Start::CreateZip { |
| 352 | 569 | sources, |
| 353 | 570 | output_file, |
| | @@ -355,6 +572,11 @@ impl ArchiveApp { |
| 355 | 572 | aes256: self.aes256, |
| 356 | 573 | }) { |
| 357 | 574 | 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; |
| 358 | 580 | } |
| 359 | 581 | } |
| 360 | 582 | |
| | @@ -500,9 +722,14 @@ impl ArchiveApp { |
| 500 | 722 | } |
| 501 | 723 | self.extract_selection(selection); |
| 502 | 724 | } |
| 503 | | -삭제: Start::CreateZip { .. } => { |
| 725 | +추가: Start::CreateZip { aes256, .. } => { |
| 504 | 726 | self.create = true; |
| 505 | | -삭제: self.begin_zip(); |
| 727 | +추가: if aes256 { |
| 728 | +추가: // 암호는 보관하지 않으므로 ZIP 만들기 창에서 다시 받음. |
| 729 | +추가: self.aes256 = true; |
| 730 | +추가: } else { |
| 731 | +추가: self.begin_zip(); |
| 732 | +추가: } |
| 506 | 733 | } |
| 507 | 734 | } |
| 508 | 735 | } |
| | @@ -551,6 +778,17 @@ impl ArchiveApp { |
| 551 | 778 | } |
| 552 | 779 | self.poll(); |
| 553 | 780 | 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 | +추가: } |
| 554 | 792 | let challenge = self.model.challenge.map(|(id, _, _)| id); |
| 555 | 793 | let new_challenge = challenge != self.password_challenge; |
| 556 | 794 | if new_challenge || challenge.is_none() { |
| | @@ -636,7 +874,7 @@ impl ArchiveApp { |
| 636 | 874 | self.open_picker(Purpose::Open); |
| 637 | 875 | } |
| 638 | 876 | if theme::tool(ui, "압축하기", theme::CREATE, idle, false).clicked() { |
| 639 | | -삭제: self.show_create(false); |
| 877 | +추가: self.choose_zip_folder(); |
| 640 | 878 | } |
| 641 | 879 | if theme::tool( |
| 642 | 880 | ui, |
| | @@ -696,9 +934,7 @@ impl ArchiveApp { |
| 696 | 934 | } |
| 697 | 935 | }); |
| 698 | 936 | self.work_window(&ctx); |
| 699 | | -삭제: if self.create && !self.model.busy() { |
| 700 | | -삭제: self.create_dialog(&ctx); |
| 701 | | -삭제: } |
| 937 | +추가: self.create_window(&ctx); |
| 702 | 938 | if self.model.challenge.is_some() { |
| 703 | 939 | self.password_dialog(&ctx, new_challenge); |
| 704 | 940 | } |
| | @@ -1049,43 +1285,26 @@ impl ArchiveApp { |
| 1049 | 1285 | if row.directory && response.double_clicked() { |
| 1050 | 1286 | open = Some(row.path.clone()); |
| 1051 | 1287 | } |
| 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()) |
| 1088 | 1306 | }, |
| 1307 | +추가: name_width, |
| 1089 | 1308 | ); |
| 1090 | 1309 | if active |
| 1091 | 1310 | && self.list_cursor == Some(index) |
| | @@ -1291,58 +1510,6 @@ impl ArchiveApp { |
| 1291 | 1510 | return; |
| 1292 | 1511 | } |
| 1293 | 1512 | 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 | | -삭제: } |
| 1346 | 1513 | let title = if self.model.busy() { |
| 1347 | 1514 | present::activity_text( |
| 1348 | 1515 | &self.model, |
| | @@ -1354,23 +1521,10 @@ impl ArchiveApp { |
| 1354 | 1521 | }; |
| 1355 | 1522 | let window_title = format!("{title} — Zipelo"); |
| 1356 | 1523 | 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); |
| 1374 | 1528 | let height = ctx.show_viewport_immediate(id, builder, |ui, class| { |
| 1375 | 1529 | if ui.ctx().input(|i| i.viewport().close_requested()) { |
| 1376 | 1530 | if self.model.busy() { |
| | @@ -1769,127 +1923,310 @@ impl ArchiveApp { |
| 1769 | 1923 | } |
| 1770 | 1924 | } |
| 1771 | 1925 | |
| 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 | +추가: }); |
| 1784 | 1967 | }); |
| 1968 | +추가: close |= self.create_area(ui); |
| 1785 | 1969 | }); |
| 1786 | | -삭제: if let Some(error) = &self.ui_error { |
| 1787 | | -삭제: Self::error_notice(ui, error); |
| 1970 | +추가: if close || modal.should_close() { |
| 1971 | +추가: self.close_create(); |
| 1788 | 1972 | } |
| 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)) |
| 1797 | 2010 | .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) |
| 1826 | 2068 | } |
| 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; |
| 1853 | 2130 | } |
| 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 | +추가: } |
| 1858 | 2138 | } |
| 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 | +추가: ); |
| 1866 | 2148 | } |
| 1867 | 2149 | }); |
| 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 | +추가: }; |
| 1886 | 2157 | } |
| 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); |
| 1889 | 2162 | } |
| 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))); |
| 1890 | 2226 | if compress { |
| 1891 | 2227 | self.open_picker(Purpose::SaveZip); |
| 1892 | 2228 | } |
| 2229 | +추가: cancel |
| 1893 | 2230 | } |
| 1894 | 2231 | |
| 1895 | 2232 | fn password_dialog(&mut self, ctx: &egui::Context, new_challenge: bool) { |