work save

This commit is contained in:
royqh1979@gmail.com 2021-08-23 17:27:17 +08:00
parent 5bcb19805e
commit 60a4e8c468
13 changed files with 172 additions and 25 deletions

View File

@ -90,11 +90,19 @@ Editor::Editor(QWidget *parent, const QString& filename,
setUseCodeFolding(false);
}
if (inProject) {
//todo:
} else {
initParser();
}
applySettings();
applyColorScheme(pSettings->editor().colorScheme());
connect(this,&SynEdit::statusChanged,this,&Editor::onStatusChanged);
connect(this,&SynEdit::gutterClicked,this,&Editor::onGutterClicked);
onStatusChanged(SynStatusChange::scOpenFile);
}
Editor::~Editor() {
@ -300,6 +308,7 @@ void Editor::focusInEvent(QFocusEvent *event)
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->updateClassBrowserForEditor(this);
}
void Editor::focusOutEvent(QFocusEvent *event)
@ -645,8 +654,7 @@ void Editor::onModificationChanged(bool) {
void Editor::onStatusChanged(SynStatusChanges changes)
{
if (!changes.testFlag(SynStatusChange::scOpenFile)
&& !changes.testFlag(SynStatusChange::scReadOnly)
if (!changes.testFlag(SynStatusChange::scReadOnly)
&& !changes.testFlag(SynStatusChange::scInsertMode)
&& (lines()->count()!=mLineCount)
&& (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) {
@ -1185,6 +1193,11 @@ void Editor::reparse()
parseFile(mParser,mFilename,mInProject);
}
const PCppParser &Editor::parser() const
{
return mParser;
}
int Editor::gutterClickedLine() const
{
return mGutterClickedLine;

View File

@ -115,6 +115,8 @@ public:
void removeBreakpointFocus();
void setActiveBreakpointFocus(int Line, bool setFocus=true);
const PCppParser &parser() const;
signals:

View File

@ -35,7 +35,8 @@ MainWindow::MainWindow(QWidget *parent)
mMessageControlChanged(false),
mTabMessagesTogglingState(false),
mCheckSyntaxInBack(false),
mSearchDialog(nullptr)
mSearchDialog(nullptr),
mQuitting(false)
{
ui->setupUi(this);
// status bar
@ -117,6 +118,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false);
//class browser
ui->classBrowser->setModel(&mClassBrowserModel);
}
MainWindow::~MainWindow()
@ -385,6 +389,35 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
}
}
void MainWindow::updateClassBrowserForEditor(Editor *editor)
{
if (!editor) {
mClassBrowserModel.setParser(nullptr);
mClassBrowserModel.setCurrentFile("");
return;
}
if (mQuitting)
return;
// if not devCodeCompletion.Enabled then
// Exit;
if ((mClassBrowserModel.currentFile() == editor->filename())
&& (mClassBrowserModel.parser() == editor->parser()))
return;
mClassBrowserModel.beginUpdate();
{
auto action = finally([this] {
mClassBrowserModel.endUpdate();
});
mClassBrowserModel.setParser(editor->parser());
// if e.InProject then begin
// ClassBrowser.StatementsType := devClassBrowsing.StatementsType;
// end else
// ClassBrowser.StatementsType := cbstFile;
mClassBrowserModel.setCurrentFile(editor->filename());
}
}
QPlainTextEdit *MainWindow::txtLocals()
{
return ui->txtLocals;

View File

@ -4,6 +4,7 @@
#include <QMainWindow>
#include "common.h"
#include "widgets/searchresultview.h"
#include "widgets/classbrowser.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -73,6 +74,8 @@ public:
void rebuildOpenedFileHisotryMenu();
void updateClassBrowserForEditor(Editor* editor);
QPlainTextEdit* txtLocals();
CPUDialog *cpuDialog() const;
@ -85,6 +88,8 @@ public:
SearchResultModel* searchResultModel();
protected:
void openFiles(const QStringList& files);
void openFile(const QString& filename);
@ -220,11 +225,13 @@ private:
CPUDialog *mCPUDialog;
SearchDialog *mSearchDialog;
QList<QAction *> mRecentFileActions;
bool mQuitting;
SearchResultModel mSearchResultModel;
PSearchResultListModel mSearchResultListModel;
PSearchResultTreeModel mSearchResultTreeModel;
PSearchResultTreeViewDelegate mSearchViewDelegate;
ClassBrowserModel mClassBrowserModel;
bool mMessageControlChanged;
bool mTabMessagesTogglingState;

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -131,6 +131,33 @@
<attribute name="title">
<string>Structure</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="classBrowser">
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabFiles">
<attribute name="title">

View File

@ -971,6 +971,7 @@ PStatement CppParser::addStatement(PStatement parent, const QString &fileName, c
result->fullName = getFullStatementName(newCommand, parent);
result->usageCount = 0;
result->freqTop = 0;
mStatementList.add(result);
if (result->kind == StatementKind::skNamespace) {
PStatementList namespaceList = mNamespaces.value(result->fullName,PStatementList());
if (!namespaceList) {
@ -1293,7 +1294,7 @@ bool CppParser::checkForPreprocessor()
{
// return (mIndex < mTokenizer.tokenCount())
// && ( "#" == mTokenizer[mIndex]->text);
return ("#" == mTokenizer[mIndex]->text);
return (mTokenizer[mIndex]->text.startsWith('#'));
}
bool CppParser::checkForScope()
@ -2316,7 +2317,7 @@ bool CppParser::handleStatement()
false);
addSoloScopeLevel(block,mTokenizer[mIndex]->line);
mIndex++;
} else if (mTokenizer[mIndex]->text[1] == '}') {
} else if (mTokenizer[mIndex]->text[0] == '}') {
removeScopeLevel(mTokenizer[mIndex]->line);
mIndex++;
} else if (checkForPreprocessor()) {
@ -2859,9 +2860,9 @@ void CppParser::internalParse(const QString &fileName)
if (!isCfile(fileName) && !isHfile(fileName)) // support only known C/C++ files
return;
QStringList tempStream;
QStringList buffer;
if (mOnGetFileStream) {
mOnGetFileStream(fileName,tempStream);
mOnGetFileStream(fileName,buffer);
}
// Preprocess the file...
@ -2876,8 +2877,10 @@ void CppParser::internalParse(const QString &fileName)
// mPreprocessor.setProjectIncludePaths(mProjectIncludePaths);
// mPreprocessor.setScannedFileList(mScannedFiles);
mPreprocessor.setScanOptions(mParseGlobalHeaders, mParseLocalHeaders);
mPreprocessor.preprocess(fileName, tempStream);
mPreprocessor.preprocess(fileName, buffer);
#ifdef QT_DEBUG
StringsToFile(mPreprocessor.result(),"f:\\preprocess.txt");
#endif
// with TStringList.Create do try
// Text:=fPreprocessor.Result;
// SaveToFile('f:\\Preprocess.txt');
@ -2903,11 +2906,16 @@ void CppParser::internalParse(const QString &fileName)
if (!handleStatement())
break;
}
//mTokenizer.DumpTokens('f:\tokens.txt');
#ifdef QT_DEBUG
mTokenizer.dumpTokens("f:\\tokens.txt");
mPreprocessor.dumpDefinesTo("f:\\defines.txt");
mPreprocessor.dumpIncludesListTo("f:\\includes.txt");
mStatementList.dump("f:\\stats.txt");
//Statements.DumpTo('f:\stats.txt');
//Statements.DumpWithScope('f:\\statements.txt');
//fPreprocessor.DumpDefinesTo('f:\defines.txt');
//fPreprocessor.DumpIncludesListTo('f:\\includes.txt');
#endif
}
}

View File

@ -888,6 +888,8 @@ QStringList CppPreprocessor::removeComments(const QStringList &text)
s+=ch;
}
}
default:
s+=ch;
}
if (stopProcess)
break;

View File

@ -279,6 +279,7 @@ QString CppTokenizer::getWord(bool bSkipParenthesis, bool bSkipArray, bool bSkip
QString result;
// We found a word...
if (!currentWord.isEmpty()) {
result = currentWord;
// Skip whitespace
skipToNextToken();

View File

@ -88,7 +88,7 @@ int StatementModel::deleteMember(StatementMap &map, PStatement statement)
void StatementModel::dumpStatementMap(StatementMap &map, QTextStream &out, int level)
{
QString indent(' ',level);
QString indent(level,' ');
for (PStatement statement:map.values()) {
out<<indent<<QString("%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12")
.arg(statement->command).arg(int(statement->kind))

View File

@ -4551,7 +4551,7 @@ int SynEdit::InsertTextByColumnMode(const QString &Value, bool AddToUndoList)
TempString = mLines->getString(mCaretY - 1);
Len = stringColumns(TempString,0);
if (Len < InsertCol) {
TempString = TempString + QChar(' ', InsertCol - Len - 1) + Str;
TempString = TempString + QString(InsertCol - Len - 1,' ') + Str;
} else {
int insertPos = charToColumn(TempString,InsertCol);
TempString.insert(insertPos-1,Str);

View File

@ -7,6 +7,7 @@
#include <QString>
#include <QRect>
#include <QStringList>
#include <memory>
class QByteArray;
class QTextStream;

View File

@ -1,5 +1,6 @@
#include "classbrowser.h"
#include "../utils.h"
#include <QDebug>
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent)
{
@ -33,7 +34,7 @@ QModelIndex ClassBrowserModel::index(int row, int column, const QModelIndex &par
QModelIndex ClassBrowserModel::parent(const QModelIndex &child) const
{
if (child.isValid()) {
if (!child.isValid()) {
return QModelIndex();
}
ClassBrowserNode *childNode = static_cast<ClassBrowserNode *>(child.internalPointer());
@ -46,6 +47,21 @@ QModelIndex ClassBrowserModel::parent(const QModelIndex &child) const
return createIndex(row,0,parentNode);
}
bool ClassBrowserModel::hasChildren(const QModelIndex &parent) const
{
ClassBrowserNode *parentNode;
if (!parent.isValid()) { // top level
return mRoot->children.count();
} else {
parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
if (parentNode->childrenFetched)
return parentNode->children.count();
if (parentNode->statement)
return !parentNode->statement->children.isEmpty();
return false;
}
}
int ClassBrowserModel::rowCount(const QModelIndex &parent) const
{
ClassBrowserNode *parentNode;
@ -71,8 +87,11 @@ void ClassBrowserModel::fetchMore(const QModelIndex &parent)
ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
if (!parentNode->childrenFetched) {
parentNode->childrenFetched = true;
if (parentNode->statement && !parentNode->statement->children.isEmpty())
if (parentNode->statement && !parentNode->statement->children.isEmpty()) {
filterChildren(parentNode, parentNode->statement->children);
beginInsertRows(parent,0,parentNode->children.count());
endInsertRows();
}
}
}
@ -109,12 +128,12 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
return QVariant();
}
const PCppParser &ClassBrowserModel::cppParser() const
const PCppParser &ClassBrowserModel::parser() const
{
return mParser;
}
void ClassBrowserModel::setCppParser(const PCppParser &newCppParser)
void ClassBrowserModel::setParser(const PCppParser &newCppParser)
{
if (mParser) {
disconnect(mParser.get(),
@ -128,8 +147,6 @@ void ClassBrowserModel::setCppParser(const PCppParser &newCppParser)
&CppParser::onEndParsing,
this,
&ClassBrowserModel::fillStatements);
if (!mParser->parsing())
fillStatements();
}
}
@ -144,10 +161,12 @@ void ClassBrowserModel::clear()
void ClassBrowserModel::fillStatements()
{
QMutexLocker locker(&mMutex);
if (mUpdateCount!=0)
return;
mUpdating = true;
{
QMutexLocker locker(&mMutex);
if (mUpdateCount!=0 || mUpdating)
return;
mUpdating = true;
}
beginResetModel();
clear();
{
@ -305,4 +324,29 @@ PStatement ClassBrowserModel::createDummy(PStatement statement)
return result;
}
const QString &ClassBrowserModel::currentFile() const
{
return mCurrentFile;
}
void ClassBrowserModel::setCurrentFile(const QString &newCurrentFile)
{
mCurrentFile = newCurrentFile;
}
void ClassBrowserModel::beginUpdate()
{
mUpdateCount++;
}
void ClassBrowserModel::endUpdate()
{
mUpdateCount--;
if (mUpdateCount == 0) {
if (!mParser->parsing()) {
this->fillStatements();
}
}
}

View File

@ -23,14 +23,20 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
bool hasChildren(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
bool canFetchMore(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
const PCppParser &cppParser() const;
void setCppParser(const PCppParser &newCppParser);
const PCppParser &parser() const;
void setParser(const PCppParser &newCppParser);
void clear();
const QString &currentFile() const;
void setCurrentFile(const QString &newCurrentFile);
void beginUpdate();
void endUpdate();
public slots:
void fillStatements();
private:
@ -49,6 +55,9 @@ private:
QString mCurrentFile;
bool mShowInheritedMembers;
// QAbstractItemModel interface
public:
};
#endif // CLASSBROWSER_H