Modify Std_* commands to delegate to current origin #12

Closed
opened 2026-02-05 18:27:22 +00:00 by forbes · 0 comments
Owner

Overview

Modify the existing standard FreeCAD file commands (Std_New, Std_Open, Std_Save, Std_SaveAs, etc.) to delegate to the current origin instead of directly performing local file operations.

Parent Issue

Epic: #8 Unified File Origin System

Goals

  1. Modify Std_* commands in CommandDoc.cpp to use OriginManager
  2. Maintain identical keyboard shortcuts and menu entries
  3. Ensure seamless transition - users shouldn't notice the change
  4. Handle edge cases (no origin selected, origin errors)

Detailed Design

Modified Command Pattern

Before:

void StdCmdOpen::activated(int iMsg) {
    // Directly open file dialog and load document
    QString fileName = QFileDialog::getOpenFileName(...);
    App::GetApplication().openDocument(fileName);
}

After:

void StdCmdOpen::activated(int iMsg) {
    // Delegate to current origin
    FileOrigin* origin = OriginManager::instance()->currentOrigin();
    if (origin) {
        origin->openDocument();
    } else {
        // Fallback to local (shouldn't happen, but safety)
        OriginManager::instance()->localOrigin()->openDocument();
    }
}

Commands to Modify

Command Delegation
Std_New currentOrigin()->newDocument()
Std_Open currentOrigin()->openDocument()
Std_Save originForDocument(doc)->saveDocument(doc)
Std_SaveAs currentOrigin()->saveDocumentAs(doc)
Std_Import currentOrigin()->importFile(doc)
Std_Export currentOrigin()->exportSelection(doc)
Std_Revert Origin-aware revert
Std_Close Standard close (no change needed)

Special Cases

Std_Save Behavior

Save should use the document's origin, not the current origin:

void StdCmdSave::activated(int iMsg) {
    App::Document* doc = App::GetApplication().getActiveDocument();
    if (!doc) return;
    
    // Use document's origin, not current selection
    FileOrigin* origin = OriginManager::instance()->originForDocument(doc);
    if (!origin) {
        // Document has no origin yet - use current origin for first save
        origin = OriginManager::instance()->currentOrigin();
    }
    
    origin->saveDocument(doc);
}

Std_SaveAs Behavior

SaveAs should offer choice of origin (handled in #17 Mixed Origin Workflows), but initially just use current origin:

void StdCmdSaveAs::activated(int iMsg) {
    App::Document* doc = App::GetApplication().getActiveDocument();
    if (!doc) return;
    
    FileOrigin* origin = OriginManager::instance()->currentOrigin();
    origin->saveDocumentAs(doc);
    
    // Update document's origin association
    OriginManager::instance()->setDocumentOrigin(doc, origin);
}

Error Handling

void StdCmdOpen::activated(int iMsg) {
    FileOrigin* origin = OriginManager::instance()->currentOrigin();
    
    // Check connection for remote origins
    if (origin->requiresAuthentication() && 
        origin->connectionState() != ConnectionState::Connected) {
        QMessageBox::warning(nullptr, tr("Not Connected"),
            tr("Please connect to %1 before opening files.")
                .arg(origin->name()));
        return;
    }
    
    origin->openDocument();
}

Menu and Toolbar

No changes needed - commands keep their existing:

  • Menu entries (File → New, Open, Save, etc.)
  • Toolbar buttons
  • Keyboard shortcuts (Ctrl+N, Ctrl+O, Ctrl+S, etc.)

The behavior changes dynamically based on current origin.

Implementation Tasks

  • Add #include "OriginManager.h" to CommandDoc.cpp
  • Modify StdCmdNew::activated()
  • Modify StdCmdOpen::activated()
  • Modify StdCmdSave::activated() with document origin logic
  • Modify StdCmdSaveAs::activated()
  • Modify StdCmdImport::activated()
  • Modify StdCmdExport::activated()
  • Review StdCmdRevert for origin-aware behavior
  • Add error handling for disconnected origins
  • Test all commands with Local origin
  • Test all commands with Silo origin

Files to Modify

  • src/Gui/CommandDoc.cpp

Acceptance Criteria

  • All modified commands delegate to OriginManager
  • Keyboard shortcuts work unchanged
  • Menu entries work unchanged
  • Save uses document's origin
  • SaveAs uses current origin
  • Error handling for disconnected origins
  • No regressions when Local origin is selected
  • Silo origin operations work correctly

Dependencies

  • #9 Origin abstraction layer
  • #10 Local filesystem origin
  • #11 Silo origin adapter

Blocking

  • #13 Origin selector widget (UI depends on commands working)
## Overview Modify the existing standard FreeCAD file commands (`Std_New`, `Std_Open`, `Std_Save`, `Std_SaveAs`, etc.) to delegate to the current origin instead of directly performing local file operations. ## Parent Issue Epic: #8 Unified File Origin System ## Goals 1. Modify `Std_*` commands in `CommandDoc.cpp` to use `OriginManager` 2. Maintain identical keyboard shortcuts and menu entries 3. Ensure seamless transition - users shouldn't notice the change 4. Handle edge cases (no origin selected, origin errors) ## Detailed Design ### Modified Command Pattern Before: ```cpp void StdCmdOpen::activated(int iMsg) { // Directly open file dialog and load document QString fileName = QFileDialog::getOpenFileName(...); App::GetApplication().openDocument(fileName); } ``` After: ```cpp void StdCmdOpen::activated(int iMsg) { // Delegate to current origin FileOrigin* origin = OriginManager::instance()->currentOrigin(); if (origin) { origin->openDocument(); } else { // Fallback to local (shouldn't happen, but safety) OriginManager::instance()->localOrigin()->openDocument(); } } ``` ### Commands to Modify | Command | Delegation | |---------|-----------| | `Std_New` | `currentOrigin()->newDocument()` | | `Std_Open` | `currentOrigin()->openDocument()` | | `Std_Save` | `originForDocument(doc)->saveDocument(doc)` | | `Std_SaveAs` | `currentOrigin()->saveDocumentAs(doc)` | | `Std_Import` | `currentOrigin()->importFile(doc)` | | `Std_Export` | `currentOrigin()->exportSelection(doc)` | | `Std_Revert` | Origin-aware revert | | `Std_Close` | Standard close (no change needed) | ### Special Cases #### Std_Save Behavior Save should use the **document's origin**, not the current origin: ```cpp void StdCmdSave::activated(int iMsg) { App::Document* doc = App::GetApplication().getActiveDocument(); if (!doc) return; // Use document's origin, not current selection FileOrigin* origin = OriginManager::instance()->originForDocument(doc); if (!origin) { // Document has no origin yet - use current origin for first save origin = OriginManager::instance()->currentOrigin(); } origin->saveDocument(doc); } ``` #### Std_SaveAs Behavior SaveAs should offer choice of origin (handled in #17 Mixed Origin Workflows), but initially just use current origin: ```cpp void StdCmdSaveAs::activated(int iMsg) { App::Document* doc = App::GetApplication().getActiveDocument(); if (!doc) return; FileOrigin* origin = OriginManager::instance()->currentOrigin(); origin->saveDocumentAs(doc); // Update document's origin association OriginManager::instance()->setDocumentOrigin(doc, origin); } ``` #### Error Handling ```cpp void StdCmdOpen::activated(int iMsg) { FileOrigin* origin = OriginManager::instance()->currentOrigin(); // Check connection for remote origins if (origin->requiresAuthentication() && origin->connectionState() != ConnectionState::Connected) { QMessageBox::warning(nullptr, tr("Not Connected"), tr("Please connect to %1 before opening files.") .arg(origin->name())); return; } origin->openDocument(); } ``` ### Menu and Toolbar No changes needed - commands keep their existing: - Menu entries (File → New, Open, Save, etc.) - Toolbar buttons - Keyboard shortcuts (Ctrl+N, Ctrl+O, Ctrl+S, etc.) The behavior changes dynamically based on current origin. ## Implementation Tasks - [ ] Add `#include "OriginManager.h"` to `CommandDoc.cpp` - [ ] Modify `StdCmdNew::activated()` - [ ] Modify `StdCmdOpen::activated()` - [ ] Modify `StdCmdSave::activated()` with document origin logic - [ ] Modify `StdCmdSaveAs::activated()` - [ ] Modify `StdCmdImport::activated()` - [ ] Modify `StdCmdExport::activated()` - [ ] Review `StdCmdRevert` for origin-aware behavior - [ ] Add error handling for disconnected origins - [ ] Test all commands with Local origin - [ ] Test all commands with Silo origin ## Files to Modify - `src/Gui/CommandDoc.cpp` ## Acceptance Criteria - [ ] All modified commands delegate to OriginManager - [ ] Keyboard shortcuts work unchanged - [ ] Menu entries work unchanged - [ ] Save uses document's origin - [ ] SaveAs uses current origin - [ ] Error handling for disconnected origins - [ ] No regressions when Local origin is selected - [ ] Silo origin operations work correctly ## Dependencies - #9 Origin abstraction layer - #10 Local filesystem origin - #11 Silo origin adapter ## Blocking - #13 Origin selector widget (UI depends on commands working)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#12