logic: Undoing file minimize, snippets and maximize actions

* MessageChangeFileView as single message for changing file state in the code view
* Show code view after updates at once
This commit is contained in:
Eberhard Graether
2016-01-28 12:40:29 +01:00
parent 297d5490c0
commit 38f943e8a0
20 changed files with 443 additions and 271 deletions
-9
View File
@@ -11,7 +11,6 @@
#include "utility/messaging/type/MessageActivateTokenLocations.h"
#include "utility/messaging/type/MessageActivateTokenIds.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageMoveIDECursor.h"
@@ -436,14 +435,6 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
}
}
void QtCodeArea::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && m_fileWidget->getFilePath().str().size())
{
MessageShowFile(m_fileWidget->getFilePath().str(), (m_fileWidget->getErrorMessages().size() > 0)).dispatch();
}
}
void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
{
if (m_panningValue != -1)
-1
View File
@@ -94,7 +94,6 @@ protected:
virtual void enterEvent(QEvent* event) Q_DECL_OVERRIDE;
virtual void leaveEvent(QEvent* event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void mouseDoubleClickEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
+111 -68
View File
@@ -8,8 +8,7 @@
#include "utility/file/FileSystem.h"
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageActivateFile.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/messaging/type/MessageShowSnippets.h"
#include "utility/messaging/type/MessageChangeFileView.h"
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationFile.h"
@@ -23,6 +22,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
, m_updateTitleBarFunctor(std::bind(&QtCodeFile::doUpdateTitleBar, this))
, m_parent(parent)
, m_filePath(filePath)
, m_snippetsRequested(false)
{
setObjectName("code_file");
@@ -173,7 +173,7 @@ void QtCodeFile::addCodeSnippet(
m_fileSnippet->setIsActiveFile(true);
}
clickedMaximizeButton();
setMaximized();
if (refCount != -1)
{
updateRefCount(0);
@@ -284,7 +284,7 @@ bool QtCodeFile::openCollapsedActiveSnippet() const
if (isActiveFile)
{
MessageShowSnippets(m_locationFile).dispatch();
showSnippets();
return true;
}
}
@@ -308,11 +308,74 @@ void QtCodeFile::updateContent()
void QtCodeFile::setLocationFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount)
{
m_locationFile = locationFile;
clickedMinimizeButton();
setMinimized();
updateRefCount(refCount);
}
void QtCodeFile::setMinimized()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(false);
if (m_snippets.size() || m_locationFile)
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(true);
m_minimizePlaceholder->show();
}
void QtCodeFile::setSnippets()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->show();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(true);
m_snippetButton->setEnabled(false);
m_maximizeButton->setEnabled(true);
m_minimizePlaceholder->hide();
}
void QtCodeFile::setMaximized()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->show();
}
m_minimizeButton->setEnabled(true);
if (m_snippets.size())
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(false);
m_minimizePlaceholder->hide();
}
void QtCodeFile::clickedTitleBar()
{
if (m_minimizeButton->isEnabled())
@@ -334,77 +397,57 @@ void QtCodeFile::clickedTitle()
MessageActivateFile(m_filePath).dispatch();
}
void QtCodeFile::clickedMinimizeButton()
void QtCodeFile::clickedMinimizeButton() const
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(false);
if (m_snippets.size() || m_locationFile)
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(true);
m_minimizePlaceholder->show();
MessageChangeFileView(
m_filePath,
MessageChangeFileView::FILE_MINIMIZED,
false,
false,
nullptr
).dispatch();
}
void QtCodeFile::clickedSnippetButton()
void QtCodeFile::clickedSnippetButton() const
{
if (m_locationFile)
MessageChangeFileView(
m_filePath,
MessageChangeFileView::FILE_SNIPPETS,
(m_locationFile != nullptr),
false,
m_locationFile
).dispatch();
}
void QtCodeFile::clickedMaximizeButton() const
{
MessageChangeFileView(
m_filePath,
MessageChangeFileView::FILE_MAXIMIZED,
(m_fileSnippet == nullptr),
false,
nullptr
).dispatch();
}
void QtCodeFile::showSnippets() const
{
if (m_snippetsRequested)
{
MessageShowSnippets(m_locationFile).dispatch();
return;
}
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->show();
}
m_snippetsRequested = true;
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(true);
m_snippetButton->setEnabled(false);
m_maximizeButton->setEnabled(true);
m_minimizePlaceholder->hide();
}
void QtCodeFile::clickedMaximizeButton()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->show();
}
else
{
MessageShowFile(m_filePath, (getErrorMessages().size() > 0)).dispatch();
}
m_minimizeButton->setEnabled(true);
if (m_snippets.size())
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(false);
m_minimizePlaceholder->hide();
MessageChangeFileView msg(
m_filePath,
MessageChangeFileView::FILE_SNIPPETS,
(m_locationFile != nullptr),
false,
m_locationFile
);
msg.undoRedoType = MessageBase::UNDOTYPE_IGNORE;
msg.dispatch();
}
void QtCodeFile::handleMessage(MessageWindowFocus* message)
@@ -431,7 +474,7 @@ void QtCodeFile::updateSnippets()
m_snippets.front()->setProperty("isFirst", true);
m_snippets.back()->setProperty("isLast", true);
clickedSnippetButton();
setSnippets();
}
void QtCodeFile::updateRefCount(int refCount)
+11 -3
View File
@@ -65,14 +65,20 @@ public:
void setLocationFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount);
void setMinimized();
void setSnippets();
void setMaximized();
void showSnippets() const;
public slots:
void clickedSnippetButton();
void clickedMinimizeButton() const;
void clickedSnippetButton() const;
void clickedMaximizeButton() const;
private slots:
void clickedTitleBar();
void clickedTitle();
void clickedMinimizeButton();
void clickedMaximizeButton();
private:
virtual void handleMessage(MessageWindowFocus* message);
@@ -101,7 +107,9 @@ private:
const FilePath m_filePath;
TimePoint m_modificationTime;
std::shared_ptr<TokenLocationFile> m_locationFile;
mutable bool m_snippetsRequested;
};
#endif // QT_CODE_FILE_H
+42 -6
View File
@@ -50,7 +50,7 @@ void QtCodeFileList::addCodeSnippet(
TimePoint modificationTime,
bool insert
){
QtCodeFile* file = getFile(locationFile);
QtCodeFile* file = getFile(locationFile->getFilePath());
if (insert)
{
@@ -66,7 +66,7 @@ void QtCodeFileList::addCodeSnippet(
void QtCodeFileList::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime)
{
QtCodeFile* file = getFile(locationFile);
QtCodeFile* file = getFile(locationFile->getFilePath());
file->setLocationFile(locationFile, refCount);
file->setModificationTime(modificationTime);
}
@@ -124,7 +124,7 @@ bool QtCodeFileList::scrollToFirstActiveSnippet()
{
if (!snippet->isVisible())
{
file->clickedSnippetButton();
file->showSnippets();
}
emit shouldScrollToSnippet(snippet);
@@ -158,14 +158,48 @@ void QtCodeFileList::defocusTokenIds()
updateFiles();
}
void QtCodeFileList::setFileMinimized(const FilePath path)
{
QtCodeFile* file = getFile(path);
if (file)
{
file->setMinimized();
}
}
void QtCodeFileList::setFileSnippets(const FilePath path)
{
QtCodeFile* file = getFile(path);
if (file)
{
file->setSnippets();
}
}
void QtCodeFileList::setFileMaximized(const FilePath path)
{
QtCodeFile* file = getFile(path);
if (file)
{
file->setMaximized();
}
}
void QtCodeFileList::showContents()
{
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
{
filePtr->show();
}
}
void QtCodeFileList::scrollToSnippet(QtCodeSnippet* snippet)
{
this->ensureWidgetVisibleAnimated(snippet, snippet->getFirstActiveLineRect());
}
QtCodeFile* QtCodeFileList::getFile(std::shared_ptr<TokenLocationFile> locationFile)
QtCodeFile* QtCodeFileList::getFile(const FilePath filePath)
{
FilePath filePath = locationFile->getFilePath();
QtCodeFile* file = nullptr;
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
@@ -179,11 +213,13 @@ QtCodeFile* QtCodeFileList::getFile(std::shared_ptr<TokenLocationFile> locationF
if (!file)
{
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(locationFile->getFilePath(), this);
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(filePath, this);
m_files.push_back(filePtr);
file = filePtr.get();
m_frame->layout()->addWidget(file);
file->hide();
}
return file;
+8 -1
View File
@@ -7,6 +7,7 @@
#include <QFrame>
#include <QScrollArea>
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/types.h"
@@ -60,11 +61,17 @@ public:
void focusTokenIds(const std::vector<Id>& focusedTokenIds);
void defocusTokenIds();
void setFileMinimized(const FilePath path);
void setFileSnippets(const FilePath path);
void setFileMaximized(const FilePath path);
void showContents();
private slots:
void scrollToSnippet(QtCodeSnippet* snippet);
private:
QtCodeFile* getFile(std::shared_ptr<TokenLocationFile> locationFile);
QtCodeFile* getFile(const FilePath filePath);
void updateFiles();
+6 -7
View File
@@ -5,7 +5,6 @@
#include <QPushButton>
#include "utility/messaging/type/MessageShowScope.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/text/TextAccess.h"
#include "data/location/TokenLocationFile.h"
@@ -160,11 +159,11 @@ std::string QtCodeSnippet::getCode() const
void QtCodeSnippet::contextMenuEvent(QContextMenuEvent* event)
{
QMenu menu(this);
menu.addAction(new QAction("Bar", this));
menu.addAction(new QAction("Brew Tea", this));
menu.addAction(new QAction("Translate", this));
menu.exec(event->globalPos());
// QMenu menu(this);
// menu.addAction(new QAction("Bar", this));
// menu.addAction(new QAction("Brew Tea", this));
// menu.addAction(new QAction("Translate", this));
// menu.exec(event->globalPos());
}
void QtCodeSnippet::clickedTitle()
@@ -175,7 +174,7 @@ void QtCodeSnippet::clickedTitle()
}
else
{
MessageShowFile(FilePath(m_titleString), (dynamic_cast<QtCodeFile*>(parent())->getErrorMessages().size() > 0)).dispatch();
dynamic_cast<QtCodeFile*>(parent())->clickedMaximizeButton();
}
}
+48 -15
View File
@@ -12,13 +12,15 @@
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
, m_refreshViewFunctor(std::bind(&QtCodeView::doRefreshView, this))
, m_showCodeSnippetsFunctor(std::bind(&QtCodeView::doShowCodeSnippets, this, std::placeholders::_1))
, m_showCodeSnippetsFunctor(std::bind(&QtCodeView::doShowCodeSnippets, this, std::placeholders::_1, std::placeholders::_2))
, m_addCodeSnippetsFunctor(std::bind(&QtCodeView::doAddCodeSnippets, this, std::placeholders::_1, std::placeholders::_2))
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this))
, m_doShowActiveTokenIdsFunctor(std::bind(&QtCodeView::doShowActiveTokenIds, this))
, m_setFileStateFunctor(std::bind(&QtCodeView::doSetFileState, this, std::placeholders::_1, std::placeholders::_2))
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this, std::placeholders::_1))
, m_doShowActiveTokenIdsFunctor(std::bind(&QtCodeView::doShowActiveTokenIds, this, std::placeholders::_1))
, m_focusTokenIdsFunctor(std::bind(&QtCodeView::doFocusTokenIds, this, std::placeholders::_1))
, m_defocusTokenIdsFunctor(std::bind(&QtCodeView::doDefocusTokenIds, this))
, m_showContentsFunctor(std::bind(&QtCodeView::doShowContents, this))
, m_isExpanding(false)
{
m_widget = new QtCodeFileList();
@@ -53,9 +55,9 @@ void QtCodeView::setErrorMessages(const std::vector<std::string>& errorMessages)
m_errorMessages = errorMessages;
}
void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds)
{
m_showCodeSnippetsFunctor(snippets);
m_showCodeSnippetsFunctor(snippets, activeTokenIds);
}
void QtCodeView::addCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert)
@@ -68,14 +70,19 @@ void QtCodeView::showCodeFile(const CodeSnippetParams& params)
m_showCodeFileFunctor(params);
}
void QtCodeView::showFirstActiveSnippet()
void QtCodeView::setFileState(const FilePath filePath, FileState state)
{
m_doShowFirstActiveSnippetFunctor();
m_setFileStateFunctor(filePath, state);
}
void QtCodeView::showActiveTokenIds()
void QtCodeView::showFirstActiveSnippet(const std::vector<Id>& activeTokenIds)
{
m_doShowActiveTokenIdsFunctor();
m_doShowFirstActiveSnippetFunctor(activeTokenIds);
}
void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
{
m_doShowActiveTokenIdsFunctor(activeTokenIds);
}
void QtCodeView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
@@ -88,6 +95,11 @@ void QtCodeView::defocusTokenIds()
m_defocusTokenIdsFunctor();
}
void QtCodeView::showContents()
{
m_showContentsFunctor();
}
void QtCodeView::doRefreshView()
{
setStyleSheet();
@@ -95,11 +107,11 @@ void QtCodeView::doRefreshView()
QtCodeArea::clearAnnotationColors();
}
void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds)
{
m_widget->clearCodeSnippets();
m_widget->setActiveTokenIds(m_activeTokenIds);
m_widget->setActiveTokenIds(activeTokenIds);
m_widget->setErrorMessages(m_errorMessages);
for (const CodeSnippetParams& params : snippets)
@@ -155,9 +167,25 @@ void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile, -1, params.modificationTime);
}
void QtCodeView::doShowFirstActiveSnippet()
void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
{
m_widget->setActiveTokenIds(m_activeTokenIds);
switch (state)
{
case FILE_MINIMIZED:
m_widget->setFileMinimized(filePath);
break;
case FILE_SNIPPETS:
m_widget->setFileSnippets(filePath);
break;
case FILE_MAXIMIZED:
m_widget->setFileMaximized(filePath);
break;
}
}
void QtCodeView::doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds)
{
m_widget->setActiveTokenIds(activeTokenIds);
if (!m_widget->scrollToFirstActiveSnippet())
{
@@ -166,9 +194,9 @@ void QtCodeView::doShowFirstActiveSnippet()
}
}
void QtCodeView::doShowActiveTokenIds()
void QtCodeView::doShowActiveTokenIds(const std::vector<Id>& activeTokenIds)
{
m_widget->setActiveTokenIds(m_activeTokenIds);
m_widget->setActiveTokenIds(activeTokenIds);
m_widget->showActiveTokenIds();
}
@@ -182,6 +210,11 @@ void QtCodeView::doDefocusTokenIds()
m_widget->defocusTokenIds();
}
void QtCodeView::doShowContents() const
{
m_widget->showContents();
}
void QtCodeView::setStyleSheet() const
{
utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("code/background"));
+19 -9
View File
@@ -29,39 +29,49 @@ public:
virtual void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
virtual void setErrorMessages(const std::vector<std::string>& errorMessages);
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds);
virtual void addCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert);
virtual void showCodeFile(const CodeSnippetParams& params);
virtual void showFirstActiveSnippet();
virtual void showActiveTokenIds();
virtual void setFileState(const FilePath filePath, FileState state);
virtual void showFirstActiveSnippet(const std::vector<Id>& activeTokenIds);
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds);
virtual void focusTokenIds(const std::vector<Id>& focusedTokenIds);
virtual void defocusTokenIds();
virtual void showContents();
private:
void doRefreshView();
void doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
void doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds);
void doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert);
void doShowCodeFile(const CodeSnippetParams& params);
void doShowFirstActiveSnippet();
void doShowActiveTokenIds();
void doSetFileState(const FilePath filePath, FileState state);
void doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds);
void doShowActiveTokenIds(const std::vector<Id>& activeTokenIds);
void doFocusTokenIds(const std::vector<Id>& focusedTokenIds);
void doDefocusTokenIds();
void doShowContents() const;
void setStyleSheet() const;
QtThreadedFunctor<> m_refreshViewFunctor;
QtThreadedFunctor<const std::vector<CodeSnippetParams>&> m_showCodeSnippetsFunctor;
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, const std::vector<Id>&> m_showCodeSnippetsFunctor;
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, bool> m_addCodeSnippetsFunctor;
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
QtThreadedFunctor<> m_doShowFirstActiveSnippetFunctor;
QtThreadedFunctor<> m_doShowActiveTokenIdsFunctor;
QtThreadedFunctor<const FilePath, FileState> m_setFileStateFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_doShowFirstActiveSnippetFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveTokenIdsFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_focusTokenIdsFunctor;
QtThreadedFunctor<> m_defocusTokenIdsFunctor;
QtThreadedFunctor<> m_showContentsFunctor;
QtCodeFileList* m_widget;