mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:53:50 +00:00
track document modification state and display it in the top level window title bar
This commit is contained in:
parent
8e546ebd30
commit
d7c63d4c74
6 changed files with 73 additions and 5 deletions
|
@ -1,9 +1,27 @@
|
||||||
|
|
||||||
#include "document.hpp"
|
#include "document.hpp"
|
||||||
|
|
||||||
CSMDoc::Document::Document() {}
|
CSMDoc::Document::Document()
|
||||||
|
{
|
||||||
|
connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool)));
|
||||||
|
}
|
||||||
|
|
||||||
QUndoStack& CSMDoc::Document::getUndoStack()
|
QUndoStack& CSMDoc::Document::getUndoStack()
|
||||||
{
|
{
|
||||||
return mUndoStack;
|
return mUndoStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSMDoc::Document::getState() const
|
||||||
|
{
|
||||||
|
int state = 0;
|
||||||
|
|
||||||
|
if (!mUndoStack.isClean())
|
||||||
|
state |= State_Modified;
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMDoc::Document::modificationStateChanged (bool clean)
|
||||||
|
{
|
||||||
|
emit stateChanged (getState(), this);
|
||||||
|
}
|
|
@ -2,11 +2,21 @@
|
||||||
#define CSM_DOC_DOCUMENT_H
|
#define CSM_DOC_DOCUMENT_H
|
||||||
|
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Document
|
class Document : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum State
|
||||||
|
{
|
||||||
|
State_Modified = 1
|
||||||
|
};
|
||||||
|
|
||||||
QUndoStack mUndoStack;
|
QUndoStack mUndoStack;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
|
@ -18,6 +28,16 @@ namespace CSMDoc
|
||||||
Document();
|
Document();
|
||||||
|
|
||||||
QUndoStack& getUndoStack();
|
QUndoStack& getUndoStack();
|
||||||
|
|
||||||
|
int getState() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void stateChanged (int state, CSMDoc::Document *document);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void modificationStateChanged (bool clean);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,9 @@ void CSVDoc::View::updateTitle()
|
||||||
|
|
||||||
stream << "New Document ";
|
stream << "New Document ";
|
||||||
|
|
||||||
|
if (mDocument->getState() & CSMDoc::Document::State_Modified)
|
||||||
|
stream << " *";
|
||||||
|
|
||||||
if (mViewTotal>1)
|
if (mViewTotal>1)
|
||||||
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
|
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
|
||||||
|
|
||||||
|
@ -89,6 +92,11 @@ void CSVDoc::View::setIndex (int viewIndex, int totalViews)
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVDoc::View::updateDocumentState()
|
||||||
|
{
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
void CSVDoc::View::newView()
|
void CSVDoc::View::newView()
|
||||||
{
|
{
|
||||||
mViewManager.addView (mDocument);
|
mViewManager.addView (mDocument);
|
||||||
|
|
|
@ -50,6 +50,8 @@ namespace CSVDoc
|
||||||
|
|
||||||
void setIndex (int viewIndex, int totalViews);
|
void setIndex (int viewIndex, int totalViews);
|
||||||
|
|
||||||
|
void updateDocumentState();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void newView();
|
void newView();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "../../model/doc/documentmanager.hpp"
|
#include "../../model/doc/documentmanager.hpp"
|
||||||
|
#include "../../model/doc/document.hpp"
|
||||||
|
|
||||||
#include "view.hpp"
|
#include "view.hpp"
|
||||||
|
|
||||||
|
@ -42,6 +43,13 @@ CSVDoc::ViewManager::~ViewManager()
|
||||||
|
|
||||||
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
||||||
{
|
{
|
||||||
|
if (countViews (document)==0)
|
||||||
|
{
|
||||||
|
// new document
|
||||||
|
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)),
|
||||||
|
this, SLOT (documentStateChanged (int, CSMDoc::Document *)));
|
||||||
|
}
|
||||||
|
|
||||||
View *view = new View (*this, document, countViews (document)+1);
|
View *view = new View (*this, document, countViews (document)+1);
|
||||||
|
|
||||||
mViews.push_back (view);
|
mViews.push_back (view);
|
||||||
|
@ -85,3 +93,10 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *document)
|
||||||
|
{
|
||||||
|
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
||||||
|
if ((*iter)->getDocument()==document)
|
||||||
|
(*iter)->updateDocumentState();
|
||||||
|
}
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Document;
|
class Document;
|
||||||
|
@ -13,8 +15,10 @@ namespace CSVDoc
|
||||||
{
|
{
|
||||||
class View;
|
class View;
|
||||||
|
|
||||||
class ViewManager
|
class ViewManager : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
CSMDoc::DocumentManager& mDocumentManager;
|
CSMDoc::DocumentManager& mDocumentManager;
|
||||||
std::vector<View *> mViews;
|
std::vector<View *> mViews;
|
||||||
std::vector<View *> mClosed;
|
std::vector<View *> mClosed;
|
||||||
|
@ -29,7 +33,7 @@ namespace CSVDoc
|
||||||
|
|
||||||
ViewManager (CSMDoc::DocumentManager& documentManager);
|
ViewManager (CSMDoc::DocumentManager& documentManager);
|
||||||
|
|
||||||
~ViewManager();
|
virtual ~ViewManager();
|
||||||
|
|
||||||
View *addView (CSMDoc::Document *document);
|
View *addView (CSMDoc::Document *document);
|
||||||
///< The ownership of the returned view is not transferred.
|
///< The ownership of the returned view is not transferred.
|
||||||
|
@ -39,8 +43,9 @@ namespace CSVDoc
|
||||||
|
|
||||||
bool closeRequest (View *view);
|
bool closeRequest (View *view);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void documentStateChanged (int state, CSMDoc::Document *document);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue