Beispiel #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, std::string& error )
{
	// Check for "save as"
	if ( document->GetPath().empty() || !document->GetPath().IsAbsolute() )
	{
		std::string filters = document->GetPath().Extension() + TXT( "|*." ) + document->GetPath().Extension() + TXT( "|All Files|*" );
		FileDialogArgs args ( FileDialogTypes::SaveFile, TXT("Save As..."), filters, FilePath( document->GetPath().Directory() ), FilePath( 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;
}
Beispiel #2
0
///////////////////////////////////////////////////////////////////////////////
// Returns true if it successfully opens a document with the specified path.
// 
bool DocumentManager::OpenDocument( const DocumentPtr& document, tstring& error )
{
    if ( !document->GetPath().empty() )
    {
        if ( FindDocument( document->GetPath() ) )
        {
            error = TXT( "The specified file (" ) + document->GetPath().Filename() + TXT( ") is already open." );
            return false;
        }

        if ( !document->IsUpToDate() )
        {
            error = TXT( "The version of '" ) + document->GetPath().Filename() + TXT( "' on your computer is out of date.  You will not be able to check it out." );
            return false;
        }
    }

    AddDocument( document );
    return true;
}