- fix: Crash when find occurrences in a project that has missing files.
rename FileEndType to NewlineType
This commit is contained in:
parent
4f2fb8f540
commit
89ee9d8914
2
NEWS.md
2
NEWS.md
|
@ -12,6 +12,8 @@ Red Panda C++ Version 2.8
|
|||
- fix: Error When save project units' encoding settings.
|
||||
- enhancement: Waiting for syntax parsers to finish before saving files, to prevent data lost caused by syntax parsering crash.
|
||||
- fix: Restore main window and cpu info window will set wrong font in the cpu info.
|
||||
- enhancement: Let encoding options in the statusbar more explicit.
|
||||
- fix: Crash when find occurrences in a project that has missing files.
|
||||
|
||||
Red Panda C++ Version 2.7
|
||||
|
||||
|
|
|
@ -50,12 +50,16 @@ bool CppRefacter::findOccurence(Editor *editor, const QSynedit::BufferCoord &pos
|
|||
if (!statement)
|
||||
return false;
|
||||
|
||||
if (statement->scope == StatementScope::Local) {
|
||||
doFindOccurenceInEditor(statement,editor,editor->parser());
|
||||
} else {
|
||||
std::shared_ptr<Project> project = pMainWindow->project();
|
||||
if (editor->inProject() && project) {
|
||||
doFindOccurenceInProject(statement,project,editor->parser());
|
||||
} else {
|
||||
doFindOccurenceInEditor(statement,editor,editor->parser());
|
||||
}
|
||||
}
|
||||
pMainWindow->searchResultModel()->notifySearchResultsUpdated();
|
||||
return true;
|
||||
}
|
||||
|
@ -88,10 +92,10 @@ bool CppRefacter::findOccurence(const QString &statementFullname, SearchFileScop
|
|||
if (!statement)
|
||||
return false;
|
||||
|
||||
if (scope == SearchFileScope::wholeProject) {
|
||||
doFindOccurenceInProject(statement,project,parser);
|
||||
} else if (scope == SearchFileScope::currentFile) {
|
||||
if (statement->scope == StatementScope::Local || scope == SearchFileScope::currentFile) {
|
||||
doFindOccurenceInEditor(statement, editor,parser);
|
||||
} else if (scope == SearchFileScope::wholeProject) {
|
||||
doFindOccurenceInProject(statement,project,parser);
|
||||
}
|
||||
pMainWindow->searchResultModel()->notifySearchResultsUpdated();
|
||||
return true;
|
||||
|
@ -163,6 +167,7 @@ void CppRefacter::doFindOccurenceInEditor(PStatement statement , Editor *editor,
|
|||
);
|
||||
PSearchResultTreeItem item = findOccurenceInFile(
|
||||
editor->filename(),
|
||||
editor->encodingOption(),
|
||||
statement,
|
||||
parser);
|
||||
if (item && !(item->results.isEmpty())) {
|
||||
|
@ -181,6 +186,7 @@ void CppRefacter::doFindOccurenceInProject(PStatement statement, std::shared_ptr
|
|||
if (isCFile(unit->fileName()) || isHFile(unit->fileName())) {
|
||||
PSearchResultTreeItem item = findOccurenceInFile(
|
||||
unit->fileName(),
|
||||
unit->encoding(),
|
||||
statement,
|
||||
parser);
|
||||
if (item && !(item->results.isEmpty())) {
|
||||
|
@ -192,6 +198,7 @@ void CppRefacter::doFindOccurenceInProject(PStatement statement, std::shared_ptr
|
|||
|
||||
PSearchResultTreeItem CppRefacter::findOccurenceInFile(
|
||||
const QString &filename,
|
||||
const QByteArray& fileEncoding,
|
||||
const PStatement &statement,
|
||||
const PCppParser& parser)
|
||||
{
|
||||
|
@ -203,9 +210,16 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
|
|||
if (pMainWindow->editorList()->getContentFromOpenedEditor(
|
||||
filename,buffer)){
|
||||
editor.document()->setContents(buffer);
|
||||
} else if (!fileExists(filename)){
|
||||
return parentItem;
|
||||
} else {
|
||||
QByteArray encoding;
|
||||
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
|
||||
try {
|
||||
editor.document()->loadFromFile(filename,fileEncoding,encoding);
|
||||
} catch (FileError e) {
|
||||
//don't handle it;
|
||||
return parentItem;
|
||||
}
|
||||
}
|
||||
editor.setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::CPP));
|
||||
int posY = 0;
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
void doFindOccurenceInProject(PStatement statement, std::shared_ptr<Project> project, const PCppParser& parser);
|
||||
PSearchResultTreeItem findOccurenceInFile(
|
||||
const QString& filename,
|
||||
const QByteArray& fileEncoding,
|
||||
const PStatement& statement,
|
||||
const PCppParser& parser);
|
||||
void renameSymbolInFile(
|
||||
|
|
|
@ -137,9 +137,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
mFileEncodingStatus = new LabelWithMenu();
|
||||
mFileModeStatus = new QLabel();
|
||||
|
||||
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
||||
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
||||
mFileModeStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
||||
mFileInfoStatus->setStyleSheet("margin-left:5px; margin-right:5px");
|
||||
mFileEncodingStatus->setStyleSheet("margin-left:5px; margin-right:5px");
|
||||
mFileModeStatus->setStyleSheet("margin-left:5px; margin-right:5px");
|
||||
prepareTabInfosData();
|
||||
prepareTabMessagesData();
|
||||
ui->statusbar->insertPermanentWidget(0,mFileModeStatus);
|
||||
|
@ -1323,12 +1323,10 @@ void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear)
|
|||
{
|
||||
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")
|
||||
QString msg = tr("Line: %1 Col: %2 Lines: %3")
|
||||
.arg(e->caretY())
|
||||
.arg(col)
|
||||
.arg(e->selText().length())
|
||||
.arg(e->document()->count())
|
||||
.arg(e->document()->getTextLength());
|
||||
.arg(e->document()->count());
|
||||
mFileInfoStatus->setText(msg);
|
||||
} else {
|
||||
mFileInfoStatus->setText("");
|
||||
|
@ -3350,6 +3348,12 @@ void MainWindow::buildEncodingMenu()
|
|||
ui->actionEncode_in_UTF_8_BOM->setCheckable(true);
|
||||
}
|
||||
|
||||
void MainWindow::buildNewlineMenu()
|
||||
{
|
||||
mMenuNewline = new QMenu(this);
|
||||
mMenuNewline->setTitle(tr("Newline"));
|
||||
}
|
||||
|
||||
void MainWindow::maximizeEditor()
|
||||
{
|
||||
if (ui->tabExplorer->isShrinked() && ui->tabExplorer->isShrinked()) {
|
||||
|
@ -9252,6 +9256,7 @@ void MainWindow::on_actionToggle_Readonly_triggered()
|
|||
editor->setReadOnly(!editor->readOnly());
|
||||
editor->updateCaption();
|
||||
updateEditorActions(editor);
|
||||
updateForStatusbarModeInfo(editor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -275,6 +275,7 @@ private:
|
|||
void initToolButtons();
|
||||
void buildContextMenus();
|
||||
void buildEncodingMenu();
|
||||
void buildNewlineMenu();
|
||||
void maximizeEditor();
|
||||
QStringList getBinDirsForCurrentEditor();
|
||||
QStringList getDefaultCompilerSetBinDirs();
|
||||
|
@ -778,6 +779,7 @@ private:
|
|||
LabelWithMenu *mFileEncodingStatus;
|
||||
QLabel *mFileModeStatus;
|
||||
QMenu *mMenuEncoding;
|
||||
QMenu *mMenuNewline;
|
||||
QMenu *mMenuExport;
|
||||
QMenu *mMenuEncodingList;
|
||||
QMenu *mMenuRecentFiles;
|
||||
|
|
|
@ -4046,7 +4046,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5</source>
|
||||
<translation>Linha:%1 Coluna:%2 Seleção:%3 Linhas:%4 Tamanho:%5</translation>
|
||||
<translation type="vanished">Linha:%1 Coluna:%2 Seleção:%3 Linhas:%4 Tamanho:%5</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Read Only</source>
|
||||
|
@ -4924,6 +4924,10 @@
|
|||
<source>Toggle Readonly</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Line: %1 Col: %2 Lines: %3</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NewClassDialog</name>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3893,10 +3893,6 @@
|
|||
<source>Clear History</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Read Only</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -4741,6 +4737,10 @@
|
|||
<source>Toggle Readonly</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Line: %1 Col: %2 Lines: %3</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NewClassDialog</name>
|
||||
|
|
|
@ -43,7 +43,7 @@ Document::Document(const QFont& font, const QFont& nonAsciiFont, QObject *parent
|
|||
{
|
||||
|
||||
mAppendNewLineAtEOF = true;
|
||||
mFileEndingType = FileEndingType::Windows;
|
||||
mNewlineType = NewlineType::Windows;
|
||||
mIndexOfLongestLine = -1;
|
||||
mUpdateCount = 0;
|
||||
mCharWidth = mFontMetrics.horizontalAdvance("M");
|
||||
|
@ -147,12 +147,12 @@ int Document::lengthOfLongestLine() {
|
|||
|
||||
QString Document::lineBreak() const
|
||||
{
|
||||
switch(mFileEndingType) {
|
||||
case FileEndingType::Linux:
|
||||
switch(mNewlineType) {
|
||||
case NewlineType::Unix:
|
||||
return "\n";
|
||||
case FileEndingType::Windows:
|
||||
case NewlineType::Windows:
|
||||
return "\r\n";
|
||||
case FileEndingType::Mac:
|
||||
case NewlineType::MacOld:
|
||||
return "\r";
|
||||
}
|
||||
return "\n";
|
||||
|
@ -321,7 +321,7 @@ int Document::getTextLength()
|
|||
int Result = 0;
|
||||
foreach (const PDocumentLine& line, mLines ) {
|
||||
Result += line->fString.length();
|
||||
if (mFileEndingType == FileEndingType::Windows) {
|
||||
if (mNewlineType == NewlineType::Windows) {
|
||||
Result += 2;
|
||||
} else {
|
||||
Result += 1;
|
||||
|
@ -573,11 +573,11 @@ void Document::loadFromFile(const QString& filename, const QByteArray& encoding,
|
|||
codec = QTextCodec::codecForName(ENCODING_UTF8);
|
||||
}
|
||||
if (line.endsWith("\r\n")) {
|
||||
mFileEndingType = FileEndingType::Windows;
|
||||
mNewlineType = NewlineType::Windows;
|
||||
} else if (line.endsWith("\n")) {
|
||||
mFileEndingType = FileEndingType::Linux;
|
||||
mNewlineType = NewlineType::Unix;
|
||||
} else if (line.endsWith("\r")) {
|
||||
mFileEndingType = FileEndingType::Mac;
|
||||
mNewlineType = NewlineType::MacOld;
|
||||
}
|
||||
internalClear();
|
||||
while (true) {
|
||||
|
@ -780,16 +780,16 @@ void Document::internalClear()
|
|||
}
|
||||
}
|
||||
|
||||
FileEndingType Document::getFileEndingType()
|
||||
NewlineType Document::getNewlineType()
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
return mFileEndingType;
|
||||
return mNewlineType;
|
||||
}
|
||||
|
||||
void Document::setFileEndingType(const FileEndingType &fileEndingType)
|
||||
void Document::setNewlineType(const NewlineType &fileEndingType)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
mFileEndingType = fileEndingType;
|
||||
mNewlineType = fileEndingType;
|
||||
}
|
||||
|
||||
bool Document::empty()
|
||||
|
|
|
@ -98,8 +98,8 @@ public:
|
|||
bool getAppendNewLineAtEOF();
|
||||
void setAppendNewLineAtEOF(bool appendNewLineAtEOF);
|
||||
|
||||
FileEndingType getFileEndingType();
|
||||
void setFileEndingType(const FileEndingType &fileEndingType);
|
||||
NewlineType getNewlineType();
|
||||
void setNewlineType(const NewlineType &fileEndingType);
|
||||
|
||||
bool empty();
|
||||
|
||||
|
@ -143,7 +143,7 @@ private:
|
|||
int mCharWidth;
|
||||
//int mCount;
|
||||
//int mCapacity;
|
||||
FileEndingType mFileEndingType;
|
||||
NewlineType mNewlineType;
|
||||
bool mAppendNewLineAtEOF;
|
||||
int mIndexOfLongestLine;
|
||||
int mUpdateCount;
|
||||
|
|
|
@ -32,7 +32,7 @@ SynExporter::SynExporter(const QByteArray charset):mCharset(charset)
|
|||
mForegroundColor = QGuiApplication::palette().color(QPalette::Text);
|
||||
mUseBackground = false;
|
||||
mExportAsText = false;
|
||||
mFileEndingType = FileEndingType::Windows;
|
||||
mFileEndingType = NewlineType::Windows;
|
||||
clear();
|
||||
setTitle("");
|
||||
}
|
||||
|
@ -211,12 +211,12 @@ void SynExporter::setUseBackground(bool Value)
|
|||
}
|
||||
}
|
||||
|
||||
FileEndingType SynExporter::fileEndingType() const
|
||||
NewlineType SynExporter::fileEndingType() const
|
||||
{
|
||||
return mFileEndingType;
|
||||
}
|
||||
|
||||
void SynExporter::setFileEndingType(const FileEndingType &fileEndingType)
|
||||
void SynExporter::setFileEndingType(const NewlineType &fileEndingType)
|
||||
{
|
||||
mFileEndingType = fileEndingType;
|
||||
}
|
||||
|
@ -389,11 +389,11 @@ void SynExporter::setOnFormatToken(const FormatTokenHandler &onFormatToken)
|
|||
QString SynExporter::lineBreak()
|
||||
{
|
||||
switch(mFileEndingType) {
|
||||
case FileEndingType::Linux:
|
||||
case NewlineType::Unix:
|
||||
return "\n";
|
||||
case FileEndingType::Windows:
|
||||
case NewlineType::Windows:
|
||||
return "\r\n";
|
||||
case FileEndingType::Mac:
|
||||
case NewlineType::MacOld:
|
||||
return "\r";
|
||||
}
|
||||
return "\n";
|
||||
|
|
|
@ -78,8 +78,8 @@ public:
|
|||
bool useBackground() const;
|
||||
void setUseBackground(bool Value);
|
||||
|
||||
FileEndingType fileEndingType() const;
|
||||
void setFileEndingType(const FileEndingType &fileEndingType);
|
||||
NewlineType fileEndingType() const;
|
||||
void setFileEndingType(const NewlineType &fileEndingType);
|
||||
|
||||
/**
|
||||
* @brief The clipboard format the exporter creates as native format.
|
||||
|
@ -119,7 +119,7 @@ protected:
|
|||
QMap<QChar,QString> mReplaceReserved;
|
||||
QString mTitle;
|
||||
bool mUseBackground;
|
||||
FileEndingType mFileEndingType;
|
||||
NewlineType mFileEndingType;
|
||||
|
||||
QString lineBreak();
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class QTextCodec;
|
|||
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
|
||||
#define ENCODING_ASCII "ASCII"
|
||||
|
||||
enum class FileEndingType {
|
||||
enum class NewlineType {
|
||||
Windows,
|
||||
Unix,
|
||||
MacOld
|
||||
|
|
Loading…
Reference in New Issue