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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,6 +28,7 @@
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent),
mMutex(QMutex::Recursive)
{
mClassBrowserType = ProjectClassBrowserType::CurrentFile;
mRoot = new ClassBrowserNode();
mRoot->parent = nullptr;
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
}
@ -4658,7 +4658,7 @@ void SynEdit::setSelectionMode(SelectionMode value)
}
}
QString SynEdit::selText()
QString SynEdit::selText() const
{
if (!selAvail()) {
return "";
@ -4800,7 +4800,7 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Select
return result;
}
QString SynEdit::lineBreak()
QString SynEdit::lineBreak() const
{
return mDocument->lineBreak();
}

View File

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