- fix: Encoding info in the status bar not correctly updated when save a new file

This commit is contained in:
Roy Qu 2022-10-26 09:33:45 +08:00
parent 6bf443d3d8
commit da2a7549f1
5 changed files with 31 additions and 30 deletions

View File

@ -31,7 +31,7 @@ Red Panda C++ Version 2.0
- enhancement: when add file in the project view, auto select basename in the filename dialog - enhancement: when add file in the project view, auto select basename in the filename dialog
- change: Don't generate localized filename when new header/add file in the project view - change: Don't generate localized filename when new header/add file in the project view
- fix: Restore project's original compiler set if user choose 'No' in the confirm project compiler set change dialog. - fix: Restore project's original compiler set if user choose 'No' in the confirm project compiler set change dialog.
- fix: Encoding info in the status bar not correctly updated when save a new file
Red Panda C++ Version 1.5 Red Panda C++ Version 1.5

View File

@ -205,7 +205,7 @@ void Editor::loadFile(QString filename) {
} }
//this->setModified(false); //this->setModified(false);
updateCaption(); updateCaption();
pMainWindow->updateForEncodingInfo(); pMainWindow->updateForEncodingInfo(this);
switch(getFileType(mFilename)) { switch(getFileType(mFilename)) {
case FileType::CppSource: case FileType::CppSource:
mUseCppSyntax = true; mUseCppSyntax = true;
@ -389,8 +389,9 @@ bool Editor::saveAs(const QString &name, bool fromProject){
if (!shouldOpenInReadonly()) { if (!shouldOpenInReadonly()) {
setReadOnly(false); setReadOnly(false);
updateCaption();
} }
pMainWindow->updateForEncodingInfo(this);
updateCaption();
emit renamed(oldName, newName , firstSave); emit renamed(oldName, newName , firstSave);
return true; return true;
@ -413,7 +414,7 @@ void Editor::setEncodingOption(const QByteArray& encoding) noexcept{
if (!isNew()) if (!isNew())
loadFile(); loadFile();
else else
pMainWindow->updateForEncodingInfo(); pMainWindow->updateForEncodingInfo(this);
if (mProject) { if (mProject) {
PProjectUnit unit = mProject->findUnit(this); PProjectUnit unit = mProject->findUnit(this);
if (unit) { if (unit) {
@ -1320,9 +1321,9 @@ void Editor::hideEvent(QHideEvent */*event*/)
this, this,
&QSynedit::SynEdit::invalidate); &QSynedit::SynEdit::invalidate);
} }
pMainWindow->updateForEncodingInfo(); pMainWindow->updateForEncodingInfo(nullptr);
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol(nullptr);
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo(nullptr);
setHideTime(QDateTime::currentDateTime()); setHideTime(QDateTime::currentDateTime());
} }

View File

@ -159,7 +159,7 @@ Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const {
} }
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) { bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
if (editor == NULL) if (editor == nullptr)
return false; return false;
if (force) { if (force) {
editor->save(true,false); editor->save(true,false);

View File

@ -429,7 +429,7 @@ void MainWindow::updateForEncodingInfo(bool clear)
} }
void MainWindow::updateForEncodingInfo(const Editor* editor, bool clear) { void MainWindow::updateForEncodingInfo(const Editor* editor, bool clear) {
if (!clear && editor!=NULL) { if (!clear && editor!=nullptr) {
if (editor->encodingOption() != editor->fileEncoding()) { if (editor->encodingOption() != editor->fileEncoding()) {
mFileEncodingStatus->setText( mFileEncodingStatus->setText(
QString("%1(%2)") QString("%1(%2)")
@ -1778,7 +1778,7 @@ bool MainWindow::compile(bool rebuild)
updateAppTitle(); updateAppTitle();
} else { } else {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
clearIssues(); clearIssues();
if (editor->modified() || editor->isNew()) { if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false)) if (!editor->save(false,false))
@ -1902,7 +1902,7 @@ void MainWindow::runExecutable(RunType runType)
binDirs); binDirs);
} else { } else {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
if (editor->modified() || editor->isNew()) { if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false)) if (!editor->save(false,false))
return; return;
@ -4997,7 +4997,7 @@ bool MainWindow::event(QEvent *event)
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL) { if (editor) {
try { try {
editor->save(); editor->save();
// if (editor->inProject() && (mProject)) // if (editor->inProject() && (mProject))
@ -5011,7 +5011,7 @@ void MainWindow::on_actionSave_triggered()
void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionSaveAs_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL) { if (editor) {
try { try {
editor->saveAs(); editor->saveAs();
} catch(FileError e) { } catch(FileError e) {
@ -5334,7 +5334,7 @@ void MainWindow::on_actionRun_triggered()
void MainWindow::on_actionUndo_triggered() void MainWindow::on_actionUndo_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->undo(); editor->undo();
} }
} }
@ -5342,7 +5342,7 @@ void MainWindow::on_actionUndo_triggered()
void MainWindow::on_actionRedo_triggered() void MainWindow::on_actionRedo_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->redo(); editor->redo();
} }
} }
@ -5350,7 +5350,7 @@ void MainWindow::on_actionRedo_triggered()
void MainWindow::on_actionCut_triggered() void MainWindow::on_actionCut_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->cutToClipboard(); editor->cutToClipboard();
} }
} }
@ -5358,7 +5358,7 @@ void MainWindow::on_actionCut_triggered()
void MainWindow::on_actionSelectAll_triggered() void MainWindow::on_actionSelectAll_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->selectAll(); editor->selectAll();
} }
} }
@ -5366,7 +5366,7 @@ void MainWindow::on_actionSelectAll_triggered()
void MainWindow::on_actionCopy_triggered() void MainWindow::on_actionCopy_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->copyToClipboard(); editor->copyToClipboard();
} }
} }
@ -5379,7 +5379,7 @@ void MainWindow::on_actionPaste_triggered()
return; return;
if (data->hasText()) { if (data->hasText()) {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->pasteFromClipboard(); editor->pasteFromClipboard();
editor->activate(); editor->activate();
} }
@ -5399,7 +5399,7 @@ void MainWindow::on_actionPaste_triggered()
void MainWindow::on_actionIndent_triggered() void MainWindow::on_actionIndent_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->tab(); editor->tab();
} }
} }
@ -5407,7 +5407,7 @@ void MainWindow::on_actionIndent_triggered()
void MainWindow::on_actionUnIndent_triggered() void MainWindow::on_actionUnIndent_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->shifttab(); editor->shifttab();
} }
} }
@ -5415,7 +5415,7 @@ void MainWindow::on_actionUnIndent_triggered()
void MainWindow::on_actionToggleComment_triggered() void MainWindow::on_actionToggleComment_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->toggleComment(); editor->toggleComment();
} }
} }
@ -5423,7 +5423,7 @@ void MainWindow::on_actionToggleComment_triggered()
void MainWindow::on_actionUnfoldAll_triggered() void MainWindow::on_actionUnfoldAll_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->unCollpaseAll(); editor->unCollpaseAll();
} }
} }
@ -5431,7 +5431,7 @@ void MainWindow::on_actionUnfoldAll_triggered()
void MainWindow::on_actionFoldAll_triggered() void MainWindow::on_actionFoldAll_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->collapseAll(); editor->collapseAll();
} }
} }
@ -8352,7 +8352,7 @@ void MainWindow::on_actionFilesView_Hide_Non_Support_Files_toggled(bool /* arg1
void MainWindow::on_actionToggle_Block_Comment_triggered() void MainWindow::on_actionToggle_Block_Comment_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->toggleBlockComment(); editor->toggleBlockComment();
} }
} }
@ -8361,7 +8361,7 @@ void MainWindow::on_actionToggle_Block_Comment_triggered()
void MainWindow::on_actionMatch_Bracket_triggered() void MainWindow::on_actionMatch_Bracket_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->matchBracket(); editor->matchBracket();
} }
} }
@ -8475,7 +8475,7 @@ void MainWindow::on_txtProblemCaseInput_cursorPositionChanged()
void MainWindow::on_actionMove_Selection_Up_triggered() void MainWindow::on_actionMove_Selection_Up_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->moveSelUp(); editor->moveSelUp();
} }
} }
@ -8484,7 +8484,7 @@ void MainWindow::on_actionMove_Selection_Up_triggered()
void MainWindow::on_actionMove_Selection_Down_triggered() void MainWindow::on_actionMove_Selection_Down_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor) {
editor->moveSelDown(); editor->moveSelDown();
} }
} }

View File

@ -123,7 +123,7 @@ void FileAssociationModel::saveAssociations()
); );
} }
if (!ok) { if (!ok) {
QMessageBox::critical(NULL, QMessageBox::critical(nullptr,
tr("Register File Association Error"), tr("Register File Association Error"),
tr("Don't have privilege to register file types!")); tr("Don't have privilege to register file types!"));
return; return;
@ -142,7 +142,7 @@ void FileAssociationModel::saveAssociations()
ok = unregisterFileType(fileType); ok = unregisterFileType(fileType);
} }
if (!ok) { if (!ok) {
QMessageBox::critical(NULL, QMessageBox::critical(nullptr,
tr("Register File Type Error"), tr("Register File Type Error"),
tr("Don't have privilege to register file types!")); tr("Don't have privilege to register file types!"));
return; return;