- fix: info not correctly update when open an editor

This commit is contained in:
Roy Qu 2022-10-24 10:58:30 +08:00
parent aa6951c2ca
commit fcb64a69af
8 changed files with 66 additions and 32 deletions

View File

@ -1293,11 +1293,11 @@ void Editor::showEvent(QShowEvent */*event*/)
reparseTodo(); reparseTodo();
} }
pMainWindow->updateClassBrowserForEditor(this); pMainWindow->updateClassBrowserForEditor(this);
pMainWindow->updateAppTitle(); pMainWindow->updateAppTitle(this);
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions(this);
pMainWindow->updateForEncodingInfo(); pMainWindow->updateForEncodingInfo(this);
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol(this);
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo(this);
setHideTime(QDateTime::currentDateTime()); setHideTime(QDateTime::currentDateTime());
} }
@ -2550,20 +2550,21 @@ bool Editor::handleCodeCompletion(QChar key)
void Editor::initParser() void Editor::initParser()
{ {
mParser = std::make_shared<CppParser>(); mParser=nullptr;
if (mUseCppSyntax) { // mParser = std::make_shared<CppParser>();
mParser->setLanguage(ParserLanguage::CPlusPlus); // if (mUseCppSyntax) {
} else { // mParser->setLanguage(ParserLanguage::CPlusPlus);
mParser->setLanguage(ParserLanguage::C); // } else {
} // mParser->setLanguage(ParserLanguage::C);
mParser->setOnGetFileStream( // }
std::bind( // mParser->setOnGetFileStream(
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(), // std::bind(
std::placeholders::_1, std::placeholders::_2)); // &EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
resetCppParser(mParser); // std::placeholders::_1, std::placeholders::_2));
mParser->setEnabled( // resetCppParser(mParser);
pSettings->codeCompletion().enabled() && // mParser->setEnabled(
(highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)); // pSettings->codeCompletion().enabled() &&
// (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter));
} }
Editor::QuoteStatus Editor::getQuoteStatus() Editor::QuoteStatus Editor::getQuoteStatus()
@ -4427,7 +4428,7 @@ void Editor::removeBookmark(int line)
invalidateGutterLine(line); invalidateGutterLine(line);
} }
bool Editor::hasBookmark(int line) bool Editor::hasBookmark(int line) const
{ {
return mBookmarkLines.contains(line); return mBookmarkLines.contains(line);
} }

View File

@ -189,7 +189,7 @@ public:
bool hasBreakpoint(int line); bool hasBreakpoint(int line);
void addBookmark(int line); void addBookmark(int line);
void removeBookmark(int line); void removeBookmark(int line);
bool hasBookmark(int line); bool hasBookmark(int line) const;
void clearBookmarks(); void clearBookmarks();
void removeBreakpointFocus(); void removeBreakpointFocus();
void modifyBreakpointProperty(int line); void modifyBreakpointProperty(int line);

View File

@ -421,8 +421,13 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::updateForEncodingInfo(bool clear) { void MainWindow::updateForEncodingInfo(bool clear)
{
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
updateForEncodingInfo(editor,clear);
}
void MainWindow::updateForEncodingInfo(const Editor* editor, bool clear) {
if (!clear && editor!=NULL) { if (!clear && editor!=NULL) {
if (editor->encodingOption() != editor->fileEncoding()) { if (editor->encodingOption() != editor->fileEncoding()) {
mFileEncodingStatus->setText( mFileEncodingStatus->setText(
@ -448,6 +453,12 @@ void MainWindow::updateForEncodingInfo(bool clear) {
} }
} }
void MainWindow::updateStatusbarForLineCol(bool clear)
{
Editor* e = mEditorList->getEditor();
updateStatusbarForLineCol(e,clear);
}
void MainWindow::updateEditorSettings() void MainWindow::updateEditorSettings()
{ {
pIconsManager->updateEditorGuttorIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->editor().fontSize())); pIconsManager->updateEditorGuttorIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->editor().fontSize()));
@ -473,6 +484,11 @@ void MainWindow::updateEditorBreakpoints()
void MainWindow::updateEditorActions() void MainWindow::updateEditorActions()
{ {
Editor* e = mEditorList->getEditor(); Editor* e = mEditorList->getEditor();
updateEditorActions(e);
}
void MainWindow::updateEditorActions(const Editor *e)
{
if (e==nullptr) { if (e==nullptr) {
ui->actionAuto_Detect->setEnabled(false); ui->actionAuto_Detect->setEnabled(false);
ui->actionEncode_in_ANSI->setEnabled(false); ui->actionEncode_in_ANSI->setEnabled(false);
@ -587,6 +603,7 @@ void MainWindow::updateEditorActions()
updateCompilerSet(); updateCompilerSet();
} }
void MainWindow::updateProjectActions() void MainWindow::updateProjectActions()
{ {
bool hasProject = (mProject != nullptr); bool hasProject = (mProject != nullptr);
@ -950,8 +967,13 @@ void MainWindow::onFileSaved(const QString &path, bool inProject)
void MainWindow::updateAppTitle() void MainWindow::updateAppTitle()
{ {
QString appName=tr("Red Panda C++");
Editor *e = mEditorList->getEditor(); Editor *e = mEditorList->getEditor();
updateAppTitle(e);
}
void MainWindow::updateAppTitle(const Editor *e)
{
QString appName=tr("Red Panda C++");
QCoreApplication *app = QApplication::instance(); QCoreApplication *app = QApplication::instance();
if (e && !e->inProject()) { if (e && !e->inProject()) {
QString str; QString str;
@ -1206,9 +1228,8 @@ QMenuBar *MainWindow::menuBar() const
return ui->menubar; return ui->menubar;
} }
void MainWindow::updateStatusbarForLineCol(bool clear) void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear)
{ {
Editor* e = mEditorList->getEditor();
if (!clear && e!=nullptr) { if (!clear && e!=nullptr) {
int col = e->charToColumn(e->caretY(),e->caretX()); int col = e->charToColumn(e->caretY(),e->caretX());
QString msg = tr("Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5") QString msg = tr("Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5")
@ -1226,6 +1247,11 @@ void MainWindow::updateStatusbarForLineCol(bool clear)
void MainWindow::updateForStatusbarModeInfo(bool clear) void MainWindow::updateForStatusbarModeInfo(bool clear)
{ {
Editor* e = mEditorList->getEditor(); Editor* e = mEditorList->getEditor();
updateForStatusbarModeInfo(e,clear);
}
void MainWindow::updateForStatusbarModeInfo(const Editor* e, bool clear)
{
if (!clear && e!=nullptr) { if (!clear && e!=nullptr) {
QString msg; QString msg;
if (e->readOnly()) { if (e->readOnly()) {

View File

@ -108,13 +108,17 @@ public:
~MainWindow(); ~MainWindow();
void updateForEncodingInfo(bool clear=false); void updateForEncodingInfo(bool clear=false);
void updateForEncodingInfo(const Editor* editor, bool clear=false);
void updateStatusbarForLineCol(bool clear=false); void updateStatusbarForLineCol(bool clear=false);
void updateStatusbarForLineCol(const Editor* editor, bool clear=false);
void updateForStatusbarModeInfo(bool clear=false); void updateForStatusbarModeInfo(bool clear=false);
void updateForStatusbarModeInfo(const Editor* editor, bool clear=false);
void updateStatusbarMessage(const QString& s); void updateStatusbarMessage(const QString& s);
void updateEditorSettings(); void updateEditorSettings();
void updateEditorBookmarks(); void updateEditorBookmarks();
void updateEditorBreakpoints(); void updateEditorBreakpoints();
void updateEditorActions(); void updateEditorActions();
void updateEditorActions(const Editor *e);
void updateProjectActions(); void updateProjectActions();
void updateCompileActions(); void updateCompileActions();
void updateEditorColorSchemes(); void updateEditorColorSchemes();
@ -142,6 +146,7 @@ public:
void removeActiveBreakpoints(); void removeActiveBreakpoints();
void updateAppTitle(); void updateAppTitle();
void updateAppTitle(const Editor* e);
void addDebugOutput(const QString& text); void addDebugOutput(const QString& text);
void changeDebugOutputLastline(const QString& text); void changeDebugOutputLastline(const QString& text);
void updateDebugEval(const QString& value); void updateDebugEval(const QString& value);

View File

@ -816,9 +816,8 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
if (inProject) { if (inProject) {
QSet<QString> filesToReparsed = calculateFilesToBeReparsed(fileName); QSet<QString> filesToReparsed = calculateFilesToBeReparsed(fileName);
internalInvalidateFiles(filesToReparsed);
QStringList files = sortFilesByIncludeRelations(filesToReparsed); QStringList files = sortFilesByIncludeRelations(filesToReparsed);
internalInvalidateFiles(filesToReparsed);
mFilesToScanCount = files.count(); mFilesToScanCount = files.count();
mFilesScannedCount = 0; mFilesScannedCount = 0;
@ -1448,6 +1447,8 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
//rebuild file include relations //rebuild file include relations
foreach(const QString& file, files) { foreach(const QString& file, files) {
if (mPreprocessor.scannedFiles().contains(file))
continue;
//already removed in interalInvalidateFiles //already removed in interalInvalidateFiles
//mPreprocessor.removeScannedFile(file); //mPreprocessor.removeScannedFile(file);
QStringList buffer; QStringList buffer;

View File

@ -28,6 +28,7 @@
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent), ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent),
mMutex(QMutex::Recursive) mMutex(QMutex::Recursive)
{ {
mClassBrowserType = ProjectClassBrowserType::CurrentFile;
mRoot = new ClassBrowserNode(); mRoot = new ClassBrowserNode();
mRoot->parent = nullptr; mRoot->parent = nullptr;
mRoot->statement = PStatement(); mRoot->statement = PStatement();

View File

@ -1533,7 +1533,7 @@ void SynEdit::doExpandSelection(const BufferCoord &pos)
} }
} }
void SynEdit::doShrinkSelection(const BufferCoord &pos) void SynEdit::doShrinkSelection(const BufferCoord &/*pos*/)
{ {
//todo //todo
} }
@ -4658,7 +4658,7 @@ void SynEdit::setSelectionMode(SelectionMode value)
} }
} }
QString SynEdit::selText() QString SynEdit::selText() const
{ {
if (!selAvail()) { if (!selAvail()) {
return ""; return "";
@ -4800,7 +4800,7 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Select
return result; return result;
} }
QString SynEdit::lineBreak() QString SynEdit::lineBreak() const
{ {
return mDocument->lineBreak(); return mDocument->lineBreak();
} }

View File

@ -360,11 +360,11 @@ public:
SelectionMode selectionMode() const; SelectionMode selectionMode() const;
void setSelectionMode(SelectionMode value); void setSelectionMode(SelectionMode value);
QString selText(); QString selText() const;
QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const; QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const;
QString lineBreak(); QString lineBreak() const;
EditorOptions getOptions() const; EditorOptions getOptions() const;
void setOptions(const EditorOptions &Value); void setOptions(const EditorOptions &Value);