- enhancement: todo view

This commit is contained in:
royqh1979@gmail.com 2021-10-03 17:18:43 +08:00
parent 67850cfe48
commit 08d1006ae0
12 changed files with 651 additions and 304 deletions

View File

@ -4,6 +4,7 @@ Version 0.6.0
- fix: can't save code snippets modifications - fix: can't save code snippets modifications
- fix: errors in code snippet processing - fix: errors in code snippet processing
- change: auto open a new editor at start - change: auto open a new editor at start
- enhancement: todo view
Version 0.5.0 Version 0.5.0
- enhancement: support C++ using type alias; - enhancement: support C++ using type alias;

View File

@ -60,6 +60,7 @@ SOURCES += \
settingsdialog/projectprecompilewidget.cpp \ settingsdialog/projectprecompilewidget.cpp \
settingsdialog/projectversioninfowidget.cpp \ settingsdialog/projectversioninfowidget.cpp \
symbolusagemanager.cpp \ symbolusagemanager.cpp \
todoparser.cpp \
widgets/classbrowser.cpp \ widgets/classbrowser.cpp \
widgets/codecompletionlistview.cpp \ widgets/codecompletionlistview.cpp \
widgets/codecompletionpopup.cpp \ widgets/codecompletionpopup.cpp \
@ -161,6 +162,7 @@ HEADERS += \
settingsdialog/projectprecompilewidget.h \ settingsdialog/projectprecompilewidget.h \
settingsdialog/projectversioninfowidget.h \ settingsdialog/projectversioninfowidget.h \
symbolusagemanager.h \ symbolusagemanager.h \
todoparser.h \
widgets/classbrowser.h \ widgets/classbrowser.h \
widgets/codecompletionlistview.h \ widgets/codecompletionlistview.h \
widgets/codecompletionpopup.h \ widgets/codecompletionpopup.h \

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -182,6 +182,7 @@ void Editor::loadFile(const QString& filename) {
if (pSettings->editor().syntaxCheckWhenLineChanged()) { if (pSettings->editor().syntaxCheckWhenLineChanged()) {
checkSyntaxInBack(); checkSyntaxInBack();
} }
reparseTodo();
} }
mLastIdCharPressed = 0; mLastIdCharPressed = 0;
} }
@ -192,6 +193,7 @@ void Editor::saveFile(const QString &filename) {
pMainWindow->updateForEncodingInfo(); pMainWindow->updateForEncodingInfo();
if (pSettings->editor().syntaxCheckWhenSave()) if (pSettings->editor().syntaxCheckWhenSave())
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo();
} }
void Editor::convertToEncoding(const QByteArray &encoding) void Editor::convertToEncoding(const QByteArray &encoding)
@ -1279,6 +1281,7 @@ void Editor::onStatusChanged(SynStatusChanges changes)
reparse(); reparse();
if (pSettings->editor().syntaxCheckWhenLineChanged()) if (pSettings->editor().syntaxCheckWhenLineChanged())
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo();
} }
mLineCount = lines()->count(); mLineCount = lines()->count();
if (changes.testFlag(scModified)) { if (changes.testFlag(scModified)) {
@ -1899,6 +1902,11 @@ void Editor::reparse()
parseFile(mParser,mFilename,mInProject); parseFile(mParser,mFilename,mInProject);
} }
void Editor::reparseTodo()
{
pMainWindow->todoParser()->parseFile(mFilename);
}
void Editor::insertString(const QString &value, bool moveCursor) void Editor::insertString(const QString &value, bool moveCursor)
{ {
beginUpdate(); beginUpdate();
@ -3150,6 +3158,7 @@ void Editor::reformat()
setSelText(QString::fromUtf8(newContent)); setSelText(QString::fromUtf8(newContent));
reparse(); reparse();
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo();
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions();
} }

View File

@ -155,6 +155,7 @@ public:
void gotoDeclaration(const BufferCoord& pos); void gotoDeclaration(const BufferCoord& pos);
void gotoDefinition(const BufferCoord& pos); void gotoDefinition(const BufferCoord& pos);
void reparse(); void reparse();
void reparseTodo();
void insertString(const QString& value, bool moveCursor); void insertString(const QString& value, bool moveCursor);
void insertCodeSnippet(const QString& code); void insertCodeSnippet(const QString& code);

View File

@ -130,6 +130,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->cbMemoryAddress->lineEdit(), &QLineEdit::returnPressed, connect(ui->cbMemoryAddress->lineEdit(), &QLineEdit::returnPressed,
this, &MainWindow::onDebugMemoryAddressInput); this, &MainWindow::onDebugMemoryAddressInput);
mTodoParser = std::make_shared<TodoParser>();
mSymbolUsageManager = std::make_shared<SymbolUsageManager>(); mSymbolUsageManager = std::make_shared<SymbolUsageManager>();
mSymbolUsageManager->load(); mSymbolUsageManager->load();
mCodeSnippetManager = std::make_shared<CodeSnippetsManager>(); mCodeSnippetManager = std::make_shared<CodeSnippetsManager>();
@ -140,6 +141,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->cbSearchHistory->setModel(mSearchResultListModel.get()); ui->cbSearchHistory->setModel(mSearchResultListModel.get());
ui->searchView->setModel(mSearchResultTreeModel.get()); ui->searchView->setModel(mSearchResultTreeModel.get());
ui->searchView->setItemDelegate(mSearchViewDelegate.get()); ui->searchView->setItemDelegate(mSearchViewDelegate.get());
ui->tableTODO->setModel(&mTodoModel);
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset, connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
ui->searchView,&QTreeView::expandAll); ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false); ui->replacePanel->setVisible(false);
@ -2276,6 +2278,21 @@ void MainWindow::enableDebugActions()
ui->cbMemoryAddress->setEnabled(true); ui->cbMemoryAddress->setEnabled(true);
} }
void MainWindow::onTodoParseStarted()
{
mTodoModel.clear();
}
void MainWindow::onTodoParsing(const QString &filename, int lineNo, int ch, const QString &line)
{
mTodoModel.addItem(filename,lineNo,ch,line);
}
void MainWindow::onTodoParseFinished()
{
}
void MainWindow::prepareProjectForCompile() void MainWindow::prepareProjectForCompile()
{ {
if (!mProject) if (!mProject)
@ -3875,6 +3892,11 @@ void MainWindow::on_classBrowser_doubleClicked(const QModelIndex &index)
} }
} }
const PTodoParser &MainWindow::todoParser() const
{
return mTodoParser;
}
PCodeSnippetManager &MainWindow::codeSnippetManager() PCodeSnippetManager &MainWindow::codeSnippetManager()
{ {
return mCodeSnippetManager; return mCodeSnippetManager;
@ -3884,3 +3906,34 @@ PSymbolUsageManager &MainWindow::symbolUsageManager()
{ {
return mSymbolUsageManager; return mSymbolUsageManager;
} }
void MainWindow::on_EditorTabsLeft_currentChanged(int index)
{
Editor * editor = mEditorList->getEditor();
if (editor) {
editor->reparseTodo();
}
}
void MainWindow::on_EditorTabsRight_currentChanged(int index)
{
Editor * editor = mEditorList->getEditor();
if (editor) {
editor->reparseTodo();
}
}
void MainWindow::on_tableTODO_doubleClicked(const QModelIndex &index)
{
PTodoItem item = mTodoModel.getItem(index);
if (item) {
Editor * editor = mEditorList->getOpenedEditorByFilename(item->filename);
if (editor) {
editor->setCaretPositionAndActivate(item->lineNo,item->ch+1);
}
}
}

View File

@ -13,6 +13,7 @@
#include "caretlist.h" #include "caretlist.h"
#include "symbolusagemanager.h" #include "symbolusagemanager.h"
#include "codesnippetsmanager.h" #include "codesnippetsmanager.h"
#include "todoparser.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -121,6 +122,8 @@ public:
PCodeSnippetManager &codeSnippetManager(); PCodeSnippetManager &codeSnippetManager();
const PTodoParser &todoParser() const;
public slots: public slots:
void onCompileLog(const QString& msg); void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue); void onCompileIssue(PCompileIssue issue);
@ -143,6 +146,9 @@ public slots:
void onEditorTabContextMenu(const QPoint& pos); void onEditorTabContextMenu(const QPoint& pos);
void disableDebugActions(); void disableDebugActions();
void enableDebugActions(); void enableDebugActions();
void onTodoParseStarted();
void onTodoParsing(const QString& filename, int lineNo, int ch, const QString& line);
void onTodoParseFinished();
private: private:
void prepareProjectForCompile(); void prepareProjectForCompile();
@ -357,6 +363,12 @@ private slots:
void on_classBrowser_doubleClicked(const QModelIndex &index); void on_classBrowser_doubleClicked(const QModelIndex &index);
void on_EditorTabsLeft_currentChanged(int index);
void on_EditorTabsRight_currentChanged(int index);
void on_tableTODO_doubleClicked(const QModelIndex &index);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;
@ -385,6 +397,7 @@ private:
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup; std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;
std::shared_ptr<FunctionTooltipWidget> mFunctionTip; std::shared_ptr<FunctionTooltipWidget> mFunctionTip;
TodoModel mTodoModel;
SearchResultModel mSearchResultModel; SearchResultModel mSearchResultModel;
PSearchResultListModel mSearchResultListModel; PSearchResultListModel mSearchResultListModel;
PSearchResultTreeModel mSearchResultTreeModel; PSearchResultTreeModel mSearchResultTreeModel;
@ -393,6 +406,7 @@ private:
std::shared_ptr<QHash<StatementKind, QColor>> mStatementColors; std::shared_ptr<QHash<StatementKind, QColor>> mStatementColors;
PSymbolUsageManager mSymbolUsageManager; PSymbolUsageManager mSymbolUsageManager;
PCodeSnippetManager mCodeSnippetManager; PCodeSnippetManager mCodeSnippetManager;
PTodoParser mTodoParser;
bool mCheckSyntaxInBack; bool mCheckSyntaxInBack;
bool mOpenClosingBottomPanel; bool mOpenClosingBottomPanel;

View File

@ -806,13 +806,17 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabTodo"> <widget class="QWidget" name="tabTODO">
<attribute name="title"> <attribute name="title">
<string>TODO</string> <string>TODO</string>
</attribute> </attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QTableView" name="tblTodo"/> <widget class="QTableView" name="tableTODO">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -118,6 +118,7 @@ public:
virtual bool isWordBreakChar(const QChar& ch); virtual bool isWordBreakChar(const QChar& ch);
bool enabled() const; bool enabled() const;
void setEnabled(bool value); void setEnabled(bool value);
virtual PSynHighlighterAttribute getAttribute(const QString& name) const;
protected: protected:
PSynHighlighterAttribute mCommentAttribute; PSynHighlighterAttribute mCommentAttribute;
@ -131,8 +132,6 @@ protected:
void clearAttributes(); void clearAttributes();
virtual int attributesCount() const; virtual int attributesCount() const;
virtual PSynHighlighterAttribute getAttribute(const QString& name) const;
private: private:
QMap<QString,PSynHighlighterAttribute> mAttributes; QMap<QString,PSynHighlighterAttribute> mAttributes;
bool mEnabled; bool mEnabled;

159
RedPandaIDE/todoparser.cpp Normal file
View File

@ -0,0 +1,159 @@
#include "todoparser.h"
#include "mainwindow.h"
#include "editor.h"
#include "editorlist.h"
#include "HighlighterManager.h"
#include "qsynedit/Constants.h"
TodoParser::TodoParser(QObject *parent) : QObject(parent)
{
mThread = nullptr;
}
void TodoParser::parseFile(const QString &filename)
{
QMutexLocker locker(&mMutex);
if (mThread) {
return;
}
mThread = new TodoThread(filename);
connect(mThread,&QThread::finished,
[this] {
QMutexLocker locker(&mMutex);
if (mThread) {
mThread->deleteLater();
mThread = nullptr;
}
});
connect(mThread, &TodoThread::parseStarted,
pMainWindow, &MainWindow::onTodoParseStarted);
connect(mThread, &TodoThread::todoFound,
pMainWindow, &MainWindow::onTodoParsing);
connect(mThread, &TodoThread::parseFinished,
pMainWindow, &MainWindow::onTodoParseFinished);
mThread->start();
}
bool TodoParser::parsing() const
{
return (mThread!=nullptr);
}
TodoThread::TodoThread(const QString& filename, QObject *parent): QThread(parent)
{
mFilename = filename;
}
void TodoThread::run()
{
PSynHighlighter highlighter = highlighterManager.getCppHighlighter();
emit parseStarted();
auto action = finally([this]{
emit parseFinished();
});
QStringList lines;
if (!pMainWindow->editorList()->getContentFromOpenedEditor(mFilename,lines)) {
return;
}
PSynHighlighterAttribute commentAttr = highlighter->getAttribute(SYNS_AttrComment);
highlighter->resetState();
for (int i =0;i<lines.count();i++) {
highlighter->setLine(lines[i],i);
while (!highlighter->eol()) {
PSynHighlighterAttribute attr;
attr = highlighter->getTokenAttribute();
if (attr == commentAttr) {
QString token = highlighter->getToken();
int pos = token.indexOf("TODO:",Qt::CaseInsensitive);
if (pos>=0) {
emit todoFound(
mFilename,
i+1,
pos+highlighter->getTokenPos(),
lines[i].trimmed()
);
}
}
highlighter->next();
}
}
}
TodoModel::TodoModel(QObject *parent) : QAbstractListModel(parent)
{
}
void TodoModel::addItem(const QString &filename, int lineNo, int ch, const QString &line)
{
beginInsertRows(QModelIndex(),mItems.count(),mItems.count());
PTodoItem item = std::make_shared<TodoItem>();
item->filename = filename;
item->lineNo = lineNo;
item->ch = ch;
item->line = line;
mItems.append(item);
endInsertRows();
}
void TodoModel::clear()
{
beginResetModel();
mItems.clear();
endResetModel();
}
PTodoItem TodoModel::getItem(const QModelIndex &index)
{
if (!index.isValid())
return PTodoItem();
return mItems[index.row()];
}
int TodoModel::rowCount(const QModelIndex &parent) const
{
return mItems.count();
}
QVariant TodoModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role==Qt::DisplayRole) {
PTodoItem item = mItems[index.row()];
switch(index.column()) {
case 0:
return item->filename;
case 1:
return item->lineNo;
case 2:
return item->ch;
case 3:
return item->line;
}
}
return QVariant();
}
QVariant TodoModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch(section) {
case 0:
return tr("Filename");
case 1:
return tr("Line");
case 2:
return tr("Column");
case 3:
return tr("Content");
}
}
return QVariant();
}
int TodoModel::columnCount(const QModelIndex &parent) const
{
return 4;
}

75
RedPandaIDE/todoparser.h Normal file
View File

@ -0,0 +1,75 @@
#ifndef TODOPARSER_H
#define TODOPARSER_H
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QAbstractListModel>
struct TodoItem {
QString filename;
int lineNo;
int ch;
QString line;
};
using PTodoItem = std::shared_ptr<TodoItem>;
class TodoModel : public QAbstractListModel {
Q_OBJECT
public:
explicit TodoModel(QObject* parent=nullptr);
void addItem(const QString& filename, int lineNo,
int ch, const QString& line);
void clear();
PTodoItem getItem(const QModelIndex& index);
private:
QList<PTodoItem> mItems;
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
// QAbstractItemModel interface
public:
int columnCount(const QModelIndex &parent) const override;
};
class TodoThread: public QThread
{
Q_OBJECT
public:
explicit TodoThread(const QString& filename, QObject* parent = nullptr);
signals:
void parseStarted();
void todoFound(const QString& filename, int lineNo, int ch, const QString& line);
void parseFinished();
private:
QString mFilename;
// QThread interface
protected:
void run() override;
};
using PTodoThread = std::shared_ptr<TodoThread>;
class TodoParser : public QObject
{
Q_OBJECT
public:
explicit TodoParser(QObject *parent = nullptr);
void parseFile(const QString& filename);
bool parsing() const;
signals:
private:
TodoThread* mThread;
QRecursiveMutex mMutex;
};
using PTodoParser = std::shared_ptr<TodoParser>;
#endif // TODOPARSER_H