Example #1
0
///////////////////////////////////////////////////////////////////////////////
// Saves the specified document and returns true if successful.
//
// Derived classes should HELIUM_OVERRIDE this function to actually perform saving 
// data to disk as appropriate.  The base implementation fires the appropriate
// events.  A derived class may want to call this implementation if the save
// is successful.
//
bool DocumentManager::SaveDocument( DocumentPtr document, tstring& error )
{
    // Check for "save as"
    if ( document->GetPath().empty() || !document->GetPath().IsAbsolute() )
    {
        tstring filters = document->GetPath().Extension() + TXT( "|*." ) + document->GetPath().Extension() + TXT( "|All Files|*" );
        FileDialogArgs args ( FileDialogTypes::SaveFile, TXT("Save As..."), filters, document->GetPath().Directory(), document->GetPath().Filename() );
        m_FileDialog.Invoke( args );
        if ( !args.m_Result.empty() )
        {
            document->SetPath( args.m_Result );
        }
        else
        {
            error = TXT( "Cancelled saving of document." );
            return false;
        }
    }

    if ( document->Save( error ) )
    {
        return true;
    }

    if ( error.empty() )
    {
       error = TXT( "Failed to save " ) + document->GetPath().Filename();
    }

    return false;
}