Ejemplo n.º 1
0
bool CodeDocument::loadFromStream (InputStream& stream)
{
    replaceAllContent (stream.readEntireStreamAsString());
    setSavePoint();
    clearUndoHistory();
    return true;
}
Ejemplo n.º 2
0
void CodeDocument::setDisableUndo(bool shouldBeDisabled)
{
	if (shouldBeDisabled)
		clearUndoHistory();

	undoDisabled = shouldBeDisabled;
}
Ejemplo n.º 3
0
bool MainWindow::loadProject( QString fileName )
{
	try
	{
		QDir d = QFileInfo( fileName ).absoluteDir();
		QString projectDir = QDir::cleanPath( d.absolutePath() );

		QFile file( fileName );
		if ( !file.open( QIODevice::ReadOnly ) )
			throw std::runtime_error( "cant open project file" );

		QDomDocument doc;
		if ( !doc.setContent( &file ) ) 
			throw std::runtime_error( "cant load project file" );

		QDomElement root = doc.documentElement();
		if ( root.tagName() != "project" )
			throw std::runtime_error( "invalid project format" );

		clearUndoHistory();
		project.load( root, projectDir );
		invalidateAll();

		spriteView->load(root);
		graphicsView->load( root );
	}
	catch (...)
	{
		return false;		
	}

	return true;
}
Ejemplo n.º 4
0
bool UndoManager::redo()
{
    const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];

    if (commandSet == 0)
        return false;

    reentrancyCheck = true;
    bool failed = false;

    for (int i = 0; i < commandSet->size(); ++i)
    {
        if (! commandSet->getUnchecked(i)->perform())
        {
            jassertfalse;
            failed = true;
            break;
        }
    }

    reentrancyCheck = false;

    if (failed)
        clearUndoHistory();
    else
        ++nextIndex;

    beginNewTransaction();

    sendChangeMessage();
    return true;
}
Ejemplo n.º 5
0
bool UndoManager::undo()
{
    const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];

    if (commandSet == nullptr)
        return false;

    bool failed = false;

    {
        const ScopedValueSetter<bool> setter (reentrancyCheck, true);

        for (int i = commandSet->size(); --i >= 0;)
        {
            if (! commandSet->getUnchecked(i)->undo())
            {
                jassertfalse;
                failed = true;
                break;
            }
        }
    }

    if (failed)
        clearUndoHistory();
    else
        --nextIndex;

    beginNewTransaction();

    sendChangeMessage();
    return true;
}
Ejemplo n.º 6
0
bool CodeDocument::loadFromStream (InputStream& stream)
{
    remove (0, getNumCharacters(), false);
    insert (stream.readEntireStreamAsString(), 0, false);
    setSavePoint();
    clearUndoHistory();
    return true;
}
Ejemplo n.º 7
0
void MainWindow::newProject()
{
	clearUndoHistory();
	project.newProject();
	invalidateAll();
	spriteView->setCurrentIndex(spriteModel->getRootIndex());
	graphicsView->newProject(); // reset guide lines
}
Ejemplo n.º 8
0
bool UndoManager::redo()
{
    if (auto* s = getNextSet())
    {
        const ScopedValueSetter<bool> setter (reentrancyCheck, true);

        if (s->perform())
            ++nextIndex;
        else
            clearUndoHistory();

        beginNewTransaction();
        sendChangeMessage();
        return true;
    }

    return false;
}
Ejemplo n.º 9
0
bool UndoManager::undo()
{
    if (const ActionSet* const s = getCurrentSet())
    {
        const ScopedValueSetter<bool> setter (reentrancyCheck, true);

        if (s->undo())
            --nextIndex;
        else
            clearUndoHistory();

        beginNewTransaction();
        sendChangeMessage();
        return true;
    }

    return false;
}
Ejemplo n.º 10
0
void CommandManager::slotCmdFinished()
{
	if( !m_current_command )
	{
		return;
	}

	if( m_current_command->storeInUndoList() )
	{
		if( m_current_command->isUndoable() )
		{
			int maxindex = m_undo_vec.size()-1;
			if( m_undo_pos != maxindex )
			{
				// todo: clear undo vec from current position upwards
				int num_remove_cmds = maxindex - m_undo_pos;
				for( ; num_remove_cmds > 0; --num_remove_cmds )
				{
					m_undo_vec.pop_back();
				}
			}
			// put current cmd into undo stack
			m_undo_vec.push_back( m_current_command );
			m_undo_pos = m_undo_vec.size()-1;
		}
		else
		{
			clearUndoHistory();
		}

		if( m_current_command->isRepeatable() )
		{
			m_previous_command = m_current_command;
		}
		else
		{
			m_previous_command.reset();
		}
	}
	m_current_command.reset();
}
Ejemplo n.º 11
0
bool MainWindow::saveProject( QString fileName )
{
	if ( fileName.isEmpty() )
		return false;

	try
	{
		QDir d = QFileInfo( fileName ).absoluteDir();
		QString projectDir = QDir::cleanPath( d.absolutePath() );

		QDomDocument doc;
		QDomProcessingInstruction xmlHeaderPI = doc.createProcessingInstruction( "xml", "version=\"1.0\" " );
		doc.appendChild( xmlHeaderPI );

		QDomElement root = doc.createElement( "project" );
		root.setAttribute( "version", 1 );
		doc.appendChild( root );

		project.save( root, projectDir );
		spriteView->save(root);
		graphicsView->save( root );

		QFile outFile( fileName );
		if ( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
			throw std::runtime_error( "cant open project file" );

		QTextStream stream( &outFile );
		stream << doc.toString();

		clearUndoHistory();
	}
	catch ( ... )
	{
		return false;
	}

	return true;
}
Ejemplo n.º 12
0
UndoManager::~UndoManager()
{
    clearUndoHistory();
}