implemented edit locking (used during saves)

pull/16/head
Marc Zinnschlag 12 years ago
parent 5838929371
commit 931eb08114

@ -32,11 +32,13 @@ void CSMDoc::Document::save()
{
mSaveCount = 1;
mSaveTimer.start (500);
emit stateChanged (getState(), this);
}
void CSMDoc::Document::abortSave()
{
mSaveTimer.stop();
emit stateChanged (getState(), this);
}
void CSMDoc::Document::modificationStateChanged (bool clean)
@ -53,5 +55,6 @@ void CSMDoc::Document::saving()
mSaveCount = 0;
mSaveTimer.stop();
mUndoStack.setClean();
emit stateChanged (getState(), this);
}
}

@ -23,24 +23,26 @@ void CSVDoc::View::setupFileMenu()
QAction *save = new QAction (tr ("&Save"), this);
connect (save, SIGNAL (triggered()), this, SLOT (save()));
file->addAction (save);
mEditingActions.push_back (save);
}
void CSVDoc::View::setupEditMenu()
{
QMenu *edit = menuBar()->addMenu (tr ("&Edit"));
QAction *undo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo"));
undo->setShortcuts (QKeySequence::Undo);
edit->addAction (undo);
mUndo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo"));
mUndo->setShortcuts (QKeySequence::Undo);
edit->addAction (mUndo);
QAction *redo = mDocument->getUndoStack().createRedoAction (this, tr("&Redo"));
redo->setShortcuts (QKeySequence::Redo);
edit->addAction (redo);
mRedo= mDocument->getUndoStack().createRedoAction (this, tr("&Redo"));
mRedo->setShortcuts (QKeySequence::Redo);
edit->addAction (mRedo);
// test
QAction *test = new QAction (tr ("&Test Command"), this);
connect (test, SIGNAL (triggered()), this, SLOT (test()));
edit->addAction (test);
mEditingActions.push_back (test);
}
void CSVDoc::View::setupViewMenu()
@ -74,6 +76,17 @@ void CSVDoc::View::updateTitle()
setWindowTitle (stream.str().c_str());
}
void CSVDoc::View::updateActions()
{
bool editing = !(mDocument->getState() & CSMDoc::Document::State_Locked);
for (std::vector<QAction *>::iterator iter (mEditingActions.begin()); iter!=mEditingActions.end(); ++iter)
(*iter)->setEnabled (editing);
mUndo->setEnabled (editing & mDocument->getUndoStack().canUndo());
mRedo->setEnabled (editing & mDocument->getUndoStack().canRedo());
}
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
{
@ -105,6 +118,7 @@ void CSVDoc::View::setIndex (int viewIndex, int totalViews)
void CSVDoc::View::updateDocumentState()
{
updateTitle();
updateActions();
}
void CSVDoc::View::newView()

@ -1,6 +1,8 @@
#ifndef CSV_DOC_VIEW_H
#define CSV_DOC_VIEW_H
#include <vector>
#include <QMainWindow>
class QAction;
@ -22,6 +24,9 @@ namespace CSVDoc
CSMDoc::Document *mDocument;
int mViewIndex;
int mViewTotal;
QAction *mUndo;
QAction *mRedo;
std::vector<QAction *> mEditingActions;
// not implemented
View (const View&);
@ -41,6 +46,8 @@ namespace CSVDoc
void updateTitle();
void updateActions();
public:
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);

Loading…
Cancel
Save