ui/logic/data: refreshing only source files that have been updated
This change adds the refresh component that allows for refreshing the source code via UI or shortcut. If automatic refreshing is activated via the UI, the code is refreshed anytime the window gets focus. The contents of all the updated source files get removed from Storage, before reparsing them. File dependencies are not respected yet.
This commit is contained in:
@@ -15,6 +15,8 @@ add_files(
|
||||
qt/element/QtCodeSnippet.h
|
||||
qt/element/QtMainWindow.cpp
|
||||
qt/element/QtMainWindow.h
|
||||
qt/element/QtRefreshBar.cpp
|
||||
qt/element/QtRefreshBar.h
|
||||
qt/element/QtSearchBar.cpp
|
||||
qt/element/QtSearchBar.h
|
||||
qt/element/QtSmartSearchBox.cpp
|
||||
@@ -56,6 +58,8 @@ add_files(
|
||||
qt/view/QtGraphView.h
|
||||
qt/view/QtMainView.cpp
|
||||
qt/view/QtMainView.h
|
||||
qt/view/QtRefreshView.cpp
|
||||
qt/view/QtRefreshView.h
|
||||
qt/view/QtSearchView.cpp
|
||||
qt/view/QtSearchView.h
|
||||
qt/view/QtStatusBarView.cpp
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageSaveProject.h"
|
||||
#include "utility/messaging/type/MessageUndo.h"
|
||||
#include "utility/messaging/type/MessageWindowFocus.h"
|
||||
|
||||
QtMainWindow::QtMainWindow()
|
||||
{
|
||||
@@ -208,6 +209,16 @@ void QtMainWindow::saveLayout()
|
||||
}
|
||||
}
|
||||
|
||||
bool QtMainWindow::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowActivate)
|
||||
{
|
||||
MessageWindowFocus().dispatch();
|
||||
}
|
||||
|
||||
return QMainWindow::event(event);
|
||||
}
|
||||
|
||||
void QtMainWindow::setupProjectMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Project"), this);
|
||||
|
||||
@@ -26,6 +26,9 @@ public:
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event);
|
||||
|
||||
public slots:
|
||||
void about();
|
||||
void newProject();
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "qt/element/QtRefreshBar.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "utility/messaging/type/MessageAutoRefreshChanged.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
|
||||
QtRefreshBar::QtRefreshBar()
|
||||
{
|
||||
setObjectName("refresh_bar");
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
||||
m_refreshButton = new QPushButton(this);
|
||||
m_refreshButton->setObjectName("refresh_button");
|
||||
m_refreshButton->setToolTip("refresh");
|
||||
m_refreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_refreshButton->setIcon(QIcon("data/gui/refresh_view/images/refresh.png"));
|
||||
m_refreshButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
||||
layout->addWidget(m_refreshButton);
|
||||
|
||||
m_autoRefreshButton = new QPushButton(this);
|
||||
m_autoRefreshButton->setObjectName("auto_refresh_button");
|
||||
m_autoRefreshButton->setCheckable(true);
|
||||
m_autoRefreshButton->setToolTip("automatic refresh on window focus");
|
||||
m_autoRefreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_autoRefreshButton->setIcon(QIcon("data/gui/refresh_view/images/auto_refresh.png"));
|
||||
m_autoRefreshButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
||||
layout->addWidget(m_autoRefreshButton);
|
||||
|
||||
connect(m_refreshButton, SIGNAL(clicked()), this, SLOT(refreshClicked()));
|
||||
connect(m_autoRefreshButton, SIGNAL(clicked()), this, SLOT(autoRefreshClicked()));
|
||||
}
|
||||
|
||||
QtRefreshBar::~QtRefreshBar()
|
||||
{
|
||||
}
|
||||
|
||||
QSize QtRefreshBar::sizeHint() const
|
||||
{
|
||||
return QSize(150, 100);
|
||||
}
|
||||
|
||||
void QtRefreshBar::refreshClicked()
|
||||
{
|
||||
MessageRefresh().dispatch();
|
||||
}
|
||||
|
||||
void QtRefreshBar::autoRefreshClicked()
|
||||
{
|
||||
MessageAutoRefreshChanged(m_autoRefreshButton->isChecked()).dispatch();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef QT_REFRESH_BAR_H
|
||||
#define QT_REFRESH_BAR_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
class QPushButton;
|
||||
|
||||
class QtRefreshBar
|
||||
: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtRefreshBar();
|
||||
virtual ~QtRefreshBar();
|
||||
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
private slots:
|
||||
void refreshClicked();
|
||||
void autoRefreshClicked();
|
||||
|
||||
private:
|
||||
QPushButton* m_refreshButton;
|
||||
QPushButton* m_autoRefreshButton;
|
||||
};
|
||||
|
||||
#endif // QT_REFRESH_BAR_H
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef QT_SEARCH_BOX_H
|
||||
#define QT_SEARCH_BOX_H
|
||||
#ifndef QT_SEARCH_BAR_H
|
||||
#define QT_SEARCH_BAR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -35,4 +35,4 @@ private:
|
||||
// QPushButton* m_caseSensitiveButton;
|
||||
};
|
||||
|
||||
#endif // QT_SEARCH_BOX_H
|
||||
#endif // QT_SEARCH_BAR_H
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "qt/view/QtRefreshView.h"
|
||||
|
||||
#include "component/controller/RefreshController.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
QtRefreshView::QtRefreshView(ViewLayout* viewLayout)
|
||||
: RefreshView(viewLayout)
|
||||
, m_refreshViewFunctor(std::bind(&QtRefreshView::doRefreshView, this))
|
||||
{
|
||||
m_widget = std::make_shared<QtRefreshBar>();
|
||||
setStyleSheet();
|
||||
}
|
||||
|
||||
QtRefreshView::~QtRefreshView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtRefreshView::createWidgetWrapper()
|
||||
{
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(m_widget));
|
||||
}
|
||||
|
||||
void QtRefreshView::initView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtRefreshView::refreshView()
|
||||
{
|
||||
m_refreshViewFunctor();
|
||||
}
|
||||
|
||||
void QtRefreshView::doRefreshView()
|
||||
{
|
||||
setStyleSheet();
|
||||
}
|
||||
|
||||
void QtRefreshView::setStyleSheet()
|
||||
{
|
||||
std::string css = TextAccess::createFromFile("data/gui/refresh_view/refresh_view.css")->getText();
|
||||
|
||||
m_widget->setStyleSheet(css.c_str());
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef QT_REFRESH_VIEW_H
|
||||
#define QT_REFRESH_VIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "component/view/RefreshView.h"
|
||||
#include "qt/element/QtRefreshBar.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
class QtRefreshView
|
||||
: public RefreshView
|
||||
{
|
||||
public:
|
||||
QtRefreshView(ViewLayout* viewLayout);
|
||||
~QtRefreshView();
|
||||
|
||||
// View implementation
|
||||
virtual void createWidgetWrapper();
|
||||
virtual void initView();
|
||||
virtual void refreshView();
|
||||
|
||||
// RefreshView implementation
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
|
||||
void setStyleSheet();
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
|
||||
std::shared_ptr<QtRefreshBar> m_widget;
|
||||
};
|
||||
|
||||
# endif // QT_REFRESH_VIEW_H
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "qt/view/QtCodeView.h"
|
||||
#include "qt/view/QtGraphView.h"
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/view/QtRefreshView.h"
|
||||
#include "qt/view/QtSearchView.h"
|
||||
#include "qt/view/QtStatusBarView.h"
|
||||
#include "qt/view/QtUndoRedoView.h"
|
||||
@@ -30,6 +31,11 @@ std::shared_ptr<GraphView> QtViewFactory::createGraphView(ViewLayout* viewLayout
|
||||
return View::create<QtGraphView>(viewLayout);
|
||||
}
|
||||
|
||||
std::shared_ptr<RefreshView> QtViewFactory::createRefreshView(ViewLayout* viewLayout) const
|
||||
{
|
||||
return View::create<QtRefreshView>(viewLayout);
|
||||
}
|
||||
|
||||
std::shared_ptr<SearchView> QtViewFactory::createSearchView(ViewLayout* viewLayout) const
|
||||
{
|
||||
return View::create<QtSearchView>(viewLayout);
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
virtual std::shared_ptr<MainView> createMainView() const;
|
||||
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<RefreshView> createRefreshView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<StatusBarView> createStatusBarView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<UndoRedoView> createUndoRedoView(ViewLayout* viewLayout) const;
|
||||
|
||||
Reference in New Issue
Block a user