logic: Return to last scroll position in code view on undo
* fixed scrolling on undo * refactored autoscrolling in code view * save scroll position of user with MessageScrollCode
This commit is contained in:
@@ -16,12 +16,12 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
, m_addCodeSnippetsFunctor(std::bind(&QtCodeView::doAddCodeSnippets, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
|
||||
, m_setFileStateFunctor(std::bind(&QtCodeView::doSetFileState, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this, std::placeholders::_1))
|
||||
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, 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_scrollToValueFunctor(std::bind(&QtCodeView::doScrollToValue, this, std::placeholders::_1))
|
||||
{
|
||||
m_widget = new QtCodeFileList();
|
||||
setStyleSheet();
|
||||
@@ -75,9 +75,9 @@ void QtCodeView::setFileState(const FilePath filePath, FileState state)
|
||||
m_setFileStateFunctor(filePath, state);
|
||||
}
|
||||
|
||||
void QtCodeView::showFirstActiveSnippet(const std::vector<Id>& activeTokenIds)
|
||||
void QtCodeView::showFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo)
|
||||
{
|
||||
m_doShowFirstActiveSnippetFunctor(activeTokenIds);
|
||||
m_doShowFirstActiveSnippetFunctor(activeTokenIds, scrollTo);
|
||||
}
|
||||
|
||||
void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
@@ -100,6 +100,11 @@ void QtCodeView::showContents()
|
||||
m_showContentsFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::scrollToValue(int value)
|
||||
{
|
||||
m_scrollToValueFunctor(value);
|
||||
}
|
||||
|
||||
void QtCodeView::doRefreshView()
|
||||
{
|
||||
setStyleSheet();
|
||||
@@ -155,11 +160,7 @@ void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippet
|
||||
|
||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
||||
|
||||
if (m_isExpanding)
|
||||
{
|
||||
m_widget->scrollToFirstActiveSnippet();
|
||||
m_isExpanding = false;
|
||||
}
|
||||
m_widget->scrollToActiveFileIfRequested();
|
||||
}
|
||||
|
||||
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
@@ -183,15 +184,10 @@ void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeView::doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds)
|
||||
void QtCodeView::doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo)
|
||||
{
|
||||
m_widget->setActiveTokenIds(activeTokenIds);
|
||||
|
||||
if (!m_widget->scrollToFirstActiveSnippet())
|
||||
{
|
||||
m_widget->expandActiveSnippetFile();
|
||||
m_isExpanding = true;
|
||||
}
|
||||
m_widget->showFirstActiveSnippet(scrollTo);
|
||||
}
|
||||
|
||||
void QtCodeView::doShowActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
@@ -210,11 +206,16 @@ void QtCodeView::doDefocusTokenIds()
|
||||
m_widget->defocusTokenIds();
|
||||
}
|
||||
|
||||
void QtCodeView::doShowContents() const
|
||||
void QtCodeView::doShowContents()
|
||||
{
|
||||
m_widget->showContents();
|
||||
}
|
||||
|
||||
void QtCodeView::doScrollToValue(int value)
|
||||
{
|
||||
m_widget->scrollToValue(value);
|
||||
}
|
||||
|
||||
void QtCodeView::setStyleSheet() const
|
||||
{
|
||||
utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("code/background"));
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
|
||||
virtual void setFileState(const FilePath filePath, FileState state);
|
||||
|
||||
virtual void showFirstActiveSnippet(const std::vector<Id>& activeTokenIds);
|
||||
virtual void showFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo);
|
||||
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
virtual void focusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
|
||||
virtual void showContents();
|
||||
|
||||
virtual void scrollToValue(int value);
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
|
||||
@@ -52,13 +54,15 @@ private:
|
||||
|
||||
void doSetFileState(const FilePath filePath, FileState state);
|
||||
|
||||
void doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds);
|
||||
void doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo);
|
||||
void doShowActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
void doFocusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
void doDefocusTokenIds();
|
||||
|
||||
void doShowContents() const;
|
||||
void doShowContents();
|
||||
|
||||
void doScrollToValue(int value);
|
||||
|
||||
void setStyleSheet() const;
|
||||
|
||||
@@ -67,18 +71,17 @@ private:
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, bool> m_addCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
QtThreadedFunctor<const FilePath, FileState> m_setFileStateFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowFirstActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, bool> m_doShowFirstActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveTokenIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_focusTokenIdsFunctor;
|
||||
QtThreadedFunctor<> m_defocusTokenIdsFunctor;
|
||||
QtThreadedFunctor<> m_showContentsFunctor;
|
||||
QtThreadedFunctor<int> m_scrollToValueFunctor;
|
||||
|
||||
QtCodeFileList* m_widget;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<std::string> m_errorMessages;
|
||||
|
||||
bool m_isExpanding;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user