logic: Refactored undo redo stack

* Store MessageActivateTokens instead of original view messages
* Renamed FeatureController to ActivationController
* Remove all non-activation messages from undo redo stack after reindexing project
* Added MessageShowReference to undo redo stack
* Added MessageScrollGraph for restoring graph view scroll position
* Fixed MessageGraphNodeMove not saved for bundles
* Refactored tokenIds and nodeNames in SearchMatch and MessageActivateTokens
* Refactored SearchController
* Fixed file expansion on undoing/redoing after switching code view mode
* Fixed redundant graph animation due to present qualifier nodes
* Fixed no restoring of graph node expansion when showing overview in between
This commit is contained in:
Eberhard Graether
2017-03-16 23:24:33 +01:00
parent aa49fffca6
commit 630009a2ba
44 changed files with 516 additions and 400 deletions
+9 -9
View File
@@ -250,7 +250,7 @@ bool QtCodeFile::isCollapsed() const
return m_isCollapsed;
}
void QtCodeFile::requestContent()
void QtCodeFile::requestContent(bool isFirstInList)
{
if (!isCollapsed() || m_contentRequested)
{
@@ -260,15 +260,15 @@ void QtCodeFile::requestContent()
m_contentRequested = true;
MessageChangeFileView msg(
m_filePath,
m_isWholeFile ? MessageChangeFileView::FILE_MAXIMIZED : MessageChangeFileView::FILE_SNIPPETS,
isCollapsed(),
m_navigator->hasErrors()
);
MessageChangeFileView::FileState state =
isFirstInList ? MessageChangeFileView::FILE_DEFAULT_FOR_MODE : MessageChangeFileView::FILE_SNIPPETS;
msg.setIsReplayed(true);
msg.dispatch();
if (m_isWholeFile)
{
state = MessageChangeFileView::FILE_MAXIMIZED;
}
MessageChangeFileView(m_filePath, state, isCollapsed(), m_navigator->hasErrors()).dispatch();
}
void QtCodeFile::updateContent()
+1 -1
View File
@@ -43,7 +43,7 @@ public:
bool isCollapsed() const;
void requestContent();
void requestContent(bool isFirstInList = false);
void updateContent();
void setWholeFile(bool isWholeFile, int refCount);
+2 -2
View File
@@ -101,9 +101,9 @@ void QtCodeFileList::addCodeSnippet(
file->setModificationTime(params.modificationTime);
}
void QtCodeFileList::requestFileContent(const FilePath& filePath)
void QtCodeFileList::requestFileContent(const FilePath& filePath, bool isFirstInList)
{
getFile(filePath)->requestContent();
getFile(filePath)->requestContent(isFirstInList);
}
bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop)
+1 -1
View File
@@ -35,7 +35,7 @@ public:
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
virtual void requestFileContent(const FilePath& filePath);
void requestFileContent(const FilePath& filePath, bool isFirstInList = false);
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop);
virtual void updateFiles();
+3 -6
View File
@@ -142,15 +142,12 @@ void QtCodeFileSingle::requestFileContent(const FilePath& filePath)
m_contentRequested = true;
MessageChangeFileView msg(
MessageChangeFileView(
filePath,
MessageChangeFileView::FILE_MAXIMIZED,
MessageChangeFileView::FILE_DEFAULT_FOR_MODE,
true,
m_navigator->hasErrors()
);
msg.setIsReplayed(true);
msg.dispatch();
).dispatch();
}
bool QtCodeFileSingle::requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop)
+1 -1
View File
@@ -33,7 +33,7 @@ public:
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false) override;
virtual void requestFileContent(const FilePath& filePath) override;
void requestFileContent(const FilePath& filePath);
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) override;
virtual void updateFiles() override;
@@ -22,7 +22,6 @@ public:
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false) = 0;
virtual void requestFileContent(const FilePath& filePath) = 0;
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) = 0;
virtual void updateFiles() = 0;
+30 -19
View File
@@ -10,7 +10,6 @@
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageCodeViewExpandedInitialFiles.h"
#include "utility/messaging/type/MessageScrollCode.h"
#include "utility/messaging/type/MessageShowReference.h"
#include "utility/ResourcePaths.h"
#include "data/location/TokenLocation.h"
@@ -321,6 +320,11 @@ size_t QtCodeNavigator::getFatalErrorCountForFile(const FilePath& filePath) cons
return fatalErrorCount;
}
bool QtCodeNavigator::isInListMode() const
{
return m_mode == MODE_LIST;
}
void QtCodeNavigator::showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
{
@@ -442,7 +446,7 @@ void QtCodeNavigator::setupFiles()
{
if (filePathsToExpand.find(ref.filePath) == filePathsToExpand.end())
{
m_list->requestFileContent(ref.filePath);
m_list->requestFileContent(ref.filePath, filePathsToExpand.size() == 0);
filePathsToExpand.insert(ref.filePath);
if (filePathsToExpand.size() >= 3)
@@ -626,10 +630,7 @@ void QtCodeNavigator::requestScroll(const FilePath& filePath, uint lineNumber, I
}
}
if (m_scrollRequest.filePath.empty())
{
m_scrollRequest = req;
}
m_scrollRequest = req;
m_singleHasNewFile = false;
}
@@ -755,19 +756,7 @@ void QtCodeNavigator::setMode(Mode mode)
void QtCodeNavigator::showCurrentReference(bool fromUI)
{
const Reference& ref = m_references[m_refIndex - 1];
setCurrentActiveLocationIds(std::vector<Id>(1, ref.locationId));
updateFiles();
requestScroll(ref.filePath, 0, ref.locationId, fromUI, false);
emit scrollRequest();
updateRefLabel();
if (fromUI)
{
MessageShowReference(m_refIndex - 1, ref.tokenId, ref.locationId).dispatch();
}
MessageShowReference(m_refIndex, ref.tokenId, ref.locationId, fromUI).dispatch();
}
void QtCodeNavigator::updateRefLabel()
@@ -817,6 +806,28 @@ void QtCodeNavigator::handleMessage(MessageFinishedParsing* message)
);
}
void QtCodeNavigator::handleMessage(MessageShowReference* message)
{
m_refIndex = message->refIndex;
m_onQtThread(
[=]()
{
if (m_refIndex > 0)
{
const Reference& ref = m_references[m_refIndex - 1];
setCurrentActiveLocationIds(std::vector<Id>(1, ref.locationId));
updateFiles();
requestScroll(ref.filePath, 0, ref.locationId, message->animated, false);
emit scrollRequest();
}
updateRefLabel();
}
);
}
void QtCodeNavigator::handleMessage(MessageSwitchColorScheme* message)
{
m_onQtThread(
+5
View File
@@ -11,6 +11,7 @@
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageCodeReference.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/messaging/type/MessageShowReference.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "utility/messaging/type/MessageWindowFocus.h"
@@ -23,6 +24,7 @@ class QtCodeNavigator
: public QWidget
, public MessageListener<MessageCodeReference>
, public MessageListener<MessageFinishedParsing>
, public MessageListener<MessageShowReference>
, public MessageListener<MessageSwitchColorScheme>
, public MessageListener<MessageWindowFocus>
{
@@ -62,6 +64,8 @@ public:
bool hasErrors() const;
size_t getFatalErrorCountForFile(const FilePath& filePath) const;
bool isInListMode() const;
void showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
@@ -147,6 +151,7 @@ private:
void handleMessage(MessageCodeReference* message);
void handleMessage(MessageFinishedParsing* message);
void handleMessage(MessageShowReference* message);
void handleMessage(MessageSwitchColorScheme* message);
void handleMessage(MessageWindowFocus* message);
+5
View File
@@ -175,6 +175,11 @@ void QtCodeView::scrollToDefinition(bool ignoreActiveReference)
);
}
bool QtCodeView::isInListMode() const
{
return m_widget->isInListMode();
}
void QtCodeView::doShowCodeSnippets(
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles)
{
+2
View File
@@ -52,6 +52,8 @@ public:
virtual void scrollToLine(const FilePath filePath, unsigned int line);
virtual void scrollToDefinition(bool ignoreActiveReference);
virtual bool isInListMode() const;
private:
void doShowCodeSnippets(
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles);
+30 -3
View File
@@ -14,6 +14,7 @@
#include "component/view/GraphViewStyle.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageDeactivateEdge.h"
#include "utility/messaging/type/MessageScrollGraph.h"
#include "utility/ResourcePaths.h"
#include "qt/graphics/QtGraphicsView.h"
@@ -40,6 +41,7 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout)
, m_focusInFunctor(std::bind(&QtGraphView::doFocusIn, this, std::placeholders::_1))
, m_focusOutFunctor(std::bind(&QtGraphView::doFocusOut, this, std::placeholders::_1))
, m_scrollToTop(false)
, m_restoreScroll(false)
, m_isIndexedList(false)
{
}
@@ -77,6 +79,9 @@ void QtGraphView::initView()
m_scrollSpeedChangeListenerHorizontal.setScrollBar(view->horizontalScrollBar());
m_scrollSpeedChangeListenerVertical.setScrollBar(view->verticalScrollBar());
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrolled(int)));
connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrolled(int)));
doRefreshView();
}
@@ -114,6 +119,12 @@ Vec2i QtGraphView::getViewSize() const
return Vec2i(view->width() / zoomFactor - 60, view->height() / zoomFactor - 60);
}
void QtGraphView::scrollToValues(int xValue, int yValue)
{
m_restoreScroll = true;
m_scrollValues = Vec2i(xValue, yValue);
}
void QtGraphView::updateScrollBars()
{
QGraphicsView* view = getView();
@@ -121,7 +132,12 @@ void QtGraphView::updateScrollBars()
QScrollBar* hb = view->horizontalScrollBar();
QScrollBar* vb = view->verticalScrollBar();
if (m_scrollToTop)
if (m_restoreScroll)
{
hb->setValue(m_scrollValues.x());
vb->setValue(m_scrollValues.y());
}
else if (m_scrollToTop)
{
vb->setValue(vb->minimum());
}
@@ -201,6 +217,13 @@ void QtGraphView::pressedCharacterKey(QChar c)
}
}
void QtGraphView::scrolled(int)
{
QGraphicsView* view = getView();
MessageScrollGraph(view->horizontalScrollBar()->value(), view->verticalScrollBar()->value()).dispatch();
}
void QtGraphView::switchToNewGraphData()
{
m_oldGraph = m_graph;
@@ -223,9 +246,12 @@ void QtGraphView::switchToNewGraphData()
doResize();
if (m_scrollToTop)
if (m_scrollToTop || m_restoreScroll)
{
updateScrollBars();
m_scrollToTop = false;
m_restoreScroll = false;
}
// Manually hover the item below the mouse cursor.
@@ -568,7 +594,8 @@ void QtGraphView::compareNodesRecursive(
dynamic_cast<QtGraphNodeAccess*>((*it).get())->getAccessKind() ==
dynamic_cast<QtGraphNodeAccess*>((*it2).get())->getAccessKind()) ||
((*it)->isExpandToggleNode() && (*it2)->isExpandToggleNode()) ||
((*it)->isBundleNode() && (*it2)->isBundleNode() && (*it)->getTokenId() == (*it2)->getTokenId()))
((*it)->isBundleNode() && (*it2)->isBundleNode() && (*it)->getTokenId() == (*it2)->getTokenId()) ||
((*it)->isQualifierNode() && (*it2)->isQualifierNode() && (*it)->getTokenId() == (*it2)->getTokenId()))
{
remainingNodes->push_back(std::pair<QtGraphNode*, QtGraphNode*>((*it).get(), (*it2).get()));
compareNodesRecursive(
+5
View File
@@ -48,11 +48,14 @@ public:
virtual Vec2i getViewSize() const;
virtual void scrollToValues(int xValue, int yValue);
private slots:
void updateScrollBars();
void finishedTransition();
void clickedInEmptySpace();
void pressedCharacterKey(QChar c);
void scrolled(int);
private:
void switchToNewGraphData();
@@ -114,6 +117,8 @@ private:
std::shared_ptr<QtGraphNode> m_activeNode;
bool m_scrollToTop;
bool m_restoreScroll;
Vec2i m_scrollValues;
bool m_isIndexedList;
std::shared_ptr<QSequentialAnimationGroup> m_transition;
@@ -85,8 +85,10 @@ void QtGraphNodeData::onClick()
return;
}
FilePath path = getFilePath();
MessageActivateNodes message;
message.addNode(m_data->getId(), m_data->getType(), m_data->getNameHierarchy());
message.addNode(m_data->getId(), path.empty() ? m_data->getNameHierarchy() : path.str());
message.dispatch();
}
@@ -75,7 +75,7 @@ bool QtGraphNodeQualifier::setPosition(const Vec2i& pos)
void QtGraphNodeQualifier::onClick()
{
MessageActivateNodes msg;
msg.addNode(m_qualifierName);
msg.addNode(0, m_qualifierName);
msg.dispatch();
}