2026-01-07 20:42:28 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2026-01-07 20:22:49 +01:00
|
|
|
// src/app/update.rs
|
|
|
|
|
//
|
|
|
|
|
// Application update loop: applies messages to the global model state.
|
|
|
|
|
|
|
|
|
|
use super::document;
|
|
|
|
|
use super::message::AppMessage;
|
|
|
|
|
use super::model::{AppModel, ToolMode, ViewMode, PAN_STEP};
|
|
|
|
|
|
|
|
|
|
/// Central update function applying messages to the model.
|
|
|
|
|
///
|
2026-01-14 17:16:25 +01:00
|
|
|
/// Panel toggle messages (ToggleContextPage) are handled directly in
|
|
|
|
|
/// `Noctua::update()` since they affect COSMIC's Core state.
|
2026-01-07 20:22:49 +01:00
|
|
|
pub fn update(model: &mut AppModel, msg: AppMessage) {
|
|
|
|
|
match msg {
|
|
|
|
|
// ===== File / navigation ==========================================================
|
|
|
|
|
AppMessage::OpenPath(path) => {
|
2026-01-08 12:18:13 +01:00
|
|
|
document::file::open_single_file(model, &path);
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppMessage::NextDocument => {
|
2026-01-08 12:18:13 +01:00
|
|
|
document::file::navigate_next(model);
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppMessage::PrevDocument => {
|
2026-01-08 12:18:13 +01:00
|
|
|
document::file::navigate_prev(model);
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== View / zoom ===============================================================
|
|
|
|
|
AppMessage::ZoomIn => zoom_in(model),
|
|
|
|
|
AppMessage::ZoomOut => zoom_out(model),
|
|
|
|
|
AppMessage::ZoomReset => {
|
|
|
|
|
model.view_mode = ViewMode::ActualSize;
|
|
|
|
|
model.reset_pan();
|
|
|
|
|
}
|
|
|
|
|
AppMessage::ZoomFit => {
|
|
|
|
|
model.view_mode = ViewMode::Fit;
|
|
|
|
|
model.reset_pan();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== Pan control (Ctrl + arrow keys) ===========================================
|
|
|
|
|
AppMessage::PanLeft => {
|
|
|
|
|
model.pan_x -= PAN_STEP;
|
|
|
|
|
}
|
|
|
|
|
AppMessage::PanRight => {
|
|
|
|
|
model.pan_x += PAN_STEP;
|
|
|
|
|
}
|
|
|
|
|
AppMessage::PanUp => {
|
|
|
|
|
model.pan_y -= PAN_STEP;
|
|
|
|
|
}
|
|
|
|
|
AppMessage::PanDown => {
|
|
|
|
|
model.pan_y += PAN_STEP;
|
|
|
|
|
}
|
|
|
|
|
AppMessage::PanReset => {
|
|
|
|
|
model.reset_pan();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 17:16:25 +01:00
|
|
|
// ===== Tool modes ================================================================
|
2026-01-07 20:22:49 +01:00
|
|
|
AppMessage::ToggleCropMode => {
|
|
|
|
|
model.tool_mode = if model.tool_mode == ToolMode::Crop {
|
|
|
|
|
ToolMode::None
|
|
|
|
|
} else {
|
|
|
|
|
ToolMode::Crop
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
AppMessage::ToggleScaleMode => {
|
|
|
|
|
model.tool_mode = if model.tool_mode == ToolMode::Scale {
|
|
|
|
|
ToolMode::None
|
|
|
|
|
} else {
|
|
|
|
|
ToolMode::Scale
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== Document transformations ==================================================
|
|
|
|
|
AppMessage::FlipHorizontal => {
|
|
|
|
|
if let Some(doc) = &mut model.document {
|
|
|
|
|
document::transform::flip_horizontal(doc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AppMessage::FlipVertical => {
|
|
|
|
|
if let Some(doc) = &mut model.document {
|
|
|
|
|
document::transform::flip_vertical(doc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AppMessage::RotateCW => {
|
|
|
|
|
if let Some(doc) = &mut model.document {
|
|
|
|
|
document::transform::rotate_cw(doc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AppMessage::RotateCCW => {
|
|
|
|
|
if let Some(doc) = &mut model.document {
|
|
|
|
|
document::transform::rotate_ccw(doc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Implement comprehensive metadata extraction for raster images with
EXIF support and display in the right panel.
New features:
- Extract basic metadata (filename, format, resolution, file size, color type)
- Parse EXIF data (camera, date, exposure, aperture, ISO, focal length, GPS)
- Display metadata in collapsible right panel (toggle with 'i' key)
- Auto-refresh metadata on document navigation
Changes by file:
Cargo.toml, Cargo.lock:
- Add kamadak-exif dependency for EXIF parsing
i18n/en/noctua.ftl:
- Add translation strings for all metadata labels
src/app/document/meta.rs:
- New module for metadata types (BasicMeta, ExifMeta, DocumentMeta)
- Extraction logic with EXIF parsing via kamadak-exif
- Helper methods for formatted display (resolution, file size, camera, GPS)
src/app/document/mod.rs:
- Re-export meta module
src/app/document/{raster,vector,portable}.rs:
- Add extract_metadata() method stubs (full impl for raster)
src/app/document/file.rs:
- Reset metadata on document change
src/app/message.rs:
- Add ToggleRightPanel and RefreshMetadata messages
src/app/model.rs:
- Add metadata: Option<DocumentMeta> field
- Add show_right_panel: bool field
src/app/update.rs:
- Handle panel toggle and metadata refresh
- Auto-refresh metadata on navigation when panel visible
src/app/view/panels.rs:
- Implement right_panel() with metadata display
- Conditional sections for basic info and EXIF data
src/app/view/canvas.rs:
- Integrate right panel into layout"
2026-01-10 11:46:07 +01:00
|
|
|
// ===== Metadata ==================================================================
|
|
|
|
|
AppMessage::RefreshMetadata => {
|
|
|
|
|
refresh_metadata(model);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 20:22:49 +01:00
|
|
|
// ===== Error handling ============================================================
|
|
|
|
|
AppMessage::ShowError(msg) => {
|
|
|
|
|
model.set_error(msg);
|
|
|
|
|
}
|
|
|
|
|
AppMessage::ClearError => {
|
|
|
|
|
model.clear_error();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 17:16:25 +01:00
|
|
|
// ===== Handled elsewhere =========================================================
|
|
|
|
|
AppMessage::ToggleContextPage(_) => {
|
|
|
|
|
// Handled in Noctua::update() directly.
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 20:22:49 +01:00
|
|
|
AppMessage::NoOp => {
|
|
|
|
|
// Intentionally do nothing.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-08 12:18:13 +01:00
|
|
|
/// Increment zoom level by 10%.
|
2026-01-07 20:22:49 +01:00
|
|
|
fn zoom_in(model: &mut AppModel) {
|
2026-01-08 12:18:13 +01:00
|
|
|
let current = current_zoom(model);
|
|
|
|
|
let new_zoom = (current * 1.1).clamp(0.05, 20.0);
|
2026-01-07 20:22:49 +01:00
|
|
|
model.view_mode = ViewMode::Custom(new_zoom);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-08 12:18:13 +01:00
|
|
|
/// Decrement zoom level by ~9% (inverse of 1.1).
|
2026-01-07 20:22:49 +01:00
|
|
|
fn zoom_out(model: &mut AppModel) {
|
2026-01-08 12:18:13 +01:00
|
|
|
let current = current_zoom(model);
|
|
|
|
|
let new_zoom = (current / 1.1).clamp(0.05, 20.0);
|
2026-01-07 20:22:49 +01:00
|
|
|
model.view_mode = ViewMode::Custom(new_zoom);
|
|
|
|
|
}
|
2026-01-08 12:18:13 +01:00
|
|
|
|
|
|
|
|
/// Extract the current effective zoom factor from the view mode.
|
|
|
|
|
fn current_zoom(model: &AppModel) -> f32 {
|
|
|
|
|
match model.view_mode {
|
|
|
|
|
ViewMode::Fit => 1.0,
|
|
|
|
|
ViewMode::ActualSize => 1.0,
|
|
|
|
|
ViewMode::Custom(z) => z,
|
|
|
|
|
}
|
|
|
|
|
}
|
Implement comprehensive metadata extraction for raster images with
EXIF support and display in the right panel.
New features:
- Extract basic metadata (filename, format, resolution, file size, color type)
- Parse EXIF data (camera, date, exposure, aperture, ISO, focal length, GPS)
- Display metadata in collapsible right panel (toggle with 'i' key)
- Auto-refresh metadata on document navigation
Changes by file:
Cargo.toml, Cargo.lock:
- Add kamadak-exif dependency for EXIF parsing
i18n/en/noctua.ftl:
- Add translation strings for all metadata labels
src/app/document/meta.rs:
- New module for metadata types (BasicMeta, ExifMeta, DocumentMeta)
- Extraction logic with EXIF parsing via kamadak-exif
- Helper methods for formatted display (resolution, file size, camera, GPS)
src/app/document/mod.rs:
- Re-export meta module
src/app/document/{raster,vector,portable}.rs:
- Add extract_metadata() method stubs (full impl for raster)
src/app/document/file.rs:
- Reset metadata on document change
src/app/message.rs:
- Add ToggleRightPanel and RefreshMetadata messages
src/app/model.rs:
- Add metadata: Option<DocumentMeta> field
- Add show_right_panel: bool field
src/app/update.rs:
- Handle panel toggle and metadata refresh
- Auto-refresh metadata on navigation when panel visible
src/app/view/panels.rs:
- Implement right_panel() with metadata display
- Conditional sections for basic info and EXIF data
src/app/view/canvas.rs:
- Integrate right panel into layout"
2026-01-10 11:46:07 +01:00
|
|
|
|
|
|
|
|
/// Refresh metadata from the current document.
|
|
|
|
|
fn refresh_metadata(model: &mut AppModel) {
|
|
|
|
|
model.metadata = model.document.as_ref().map(|doc| doc.extract_meta());
|
|
|
|
|
}
|