noctua/src/ui/sync.rs
wfx fc73e4b76b Complete Clean Architecture migration
Phase 1-7: Full migration from src/app/ to Clean Architecture

BREAKING CHANGES:
- Removed src/app/ (old TEA-style implementation)
- Removed src/constant.rs (constants now local to modules)
- Removed deprecated canvas_to_image_coords functions

NEW STRUCTURE:
- src/ui/           - UI Layer (COSMIC interface)
- src/application/  - Application Layer (DocumentManager, Commands)
- src/domain/       - Domain Layer (Document types, Operations)
- src/infrastructure/ - Infrastructure Layer (Loaders, Cache, System)

FEATURES:
- DocumentManager as Single Source of Truth
- Command Pattern for all operations
- Model caching for render data (performance)
- Sync mechanism between DocumentManager and UI Model
- Wallpaper support (COSMIC, KDE, GNOME, feh)
- Thumbnail cache with disk persistence

IMPROVEMENTS:
- Warnings: 62 → 43 (-31%)
- Deprecated warnings: 2 → 0 (-100%)
- Code removed: src/app/ (~2000 lines), constant.rs, deprecated functions
- Better Locality of Reference (constants local to modules)
- Clean separation of concerns
- No circular dependencies

DOCUMENTATION:
- Updated AGENTS.md (100% migration status)
- Updated README.md (architecture section)
- Updated Workflow.md
- Added Migration-Plan.md with full completion summary

TESTS:
- All 41 tests passing
- Build successful (0 errors, 43 warnings)
- Release build verified

Migration Status:  100% Complete
2026-02-03 08:43:21 +01:00

76 lines
2.8 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
// src/ui/sync.rs
//
// Synchronize UI model from DocumentManager state.
use crate::application::DocumentManager;
use crate::domain::document::core::document::Renderable;
use crate::ui::model::AppModel;
/// Synchronize AppModel from DocumentManager.
///
/// Updates UI state with current document info, but does NOT copy
/// the entire document (would break Clean Architecture).
/// Only caches render-related data for performance.
pub fn sync_model_from_manager(model: &mut AppModel, manager: &mut DocumentManager) {
// Update cached render data
if let Some(doc) = manager.current_document_mut() {
// Cache image handle for rendering
if let Ok(render_output) = doc.render(1.0) {
model.current_image_handle = Some(render_output.handle);
} else {
model.current_image_handle = None;
}
// Cache dimensions
let info = doc.info();
model.current_dimensions = Some((info.width, info.height));
// Cache page info
model.current_page = Some(doc.current_page());
model.page_count = Some(doc.page_count());
} else {
// No document loaded - clear cached data
model.current_image_handle = None;
model.current_dimensions = None;
model.current_page = None;
model.page_count = None;
}
// Update navigation state
model.current_path = manager.current_path().map(|p| p.to_path_buf());
model.folder_count = manager.folder_entries().len();
model.current_index = manager.current_index();
// Update metadata
model.metadata = manager.current_metadata().cloned();
}
/// Synchronize only render data without full document info.
///
/// Useful when only the rendered image has changed (e.g., after transform).
pub fn sync_render_data(model: &mut AppModel, manager: &mut DocumentManager) {
if let Some(doc) = manager.current_document_mut() {
// Re-render at current scale to get updated image handle
if let Ok(render_output) = doc.render(model.scale as f64) {
model.current_image_handle = Some(render_output.handle);
}
// Update dimensions (may have changed after rotation)
let info = doc.info();
model.current_dimensions = Some((info.width, info.height));
// Update page info (in case page changed)
model.current_page = Some(doc.current_page());
}
}
/// Synchronize only navigation state without render data.
///
/// Useful when switching documents in a folder.
#[allow(dead_code)]
pub fn sync_navigation(model: &mut AppModel, manager: &DocumentManager) {
model.current_path = manager.current_path().map(|p| p.to_path_buf());
model.current_index = manager.current_index();
model.folder_count = manager.folder_entries().len();
}