- enhancement: add "auto reformat when saving codes" in "Options" / "Editor" / "Misc" (off by default)
- enhancement: use "todo" and "fixme" as the keyword for TODO comments
This commit is contained in:
parent
b958cdc00c
commit
cab0c8ca24
2
NEWS.md
2
NEWS.md
|
@ -22,6 +22,8 @@ Red Panda C++ Version 2.0
|
||||||
- fix: compiler settings not correctly handled when create makefile
|
- fix: compiler settings not correctly handled when create makefile
|
||||||
- enhancement: auto locate current open file in the project view panel
|
- enhancement: auto locate current open file in the project view panel
|
||||||
- enhancement: when closing project, prevent all editors that belongs to the project check syntax and parse todos.
|
- enhancement: when closing project, prevent all editors that belongs to the project check syntax and parse todos.
|
||||||
|
- enhancement: add "auto reformat when saving codes" in "Options" / "Editor" / "Misc" (off by default)
|
||||||
|
- enhancement: use "todo" and "fixme" as the keyword for TODO comments
|
||||||
|
|
||||||
Red Panda C++ Version 1.5
|
Red Panda C++ Version 1.5
|
||||||
|
|
||||||
|
|
|
@ -251,13 +251,9 @@ bool Editor::save(bool force, bool doReparse) {
|
||||||
//is this file writable;
|
//is this file writable;
|
||||||
pMainWindow->fileSystemWatcher()->removePath(mFilename);
|
pMainWindow->fileSystemWatcher()->removePath(mFilename);
|
||||||
try {
|
try {
|
||||||
// QFileInfo info(mFilename);
|
if (pSettings->editor().autoFormatWhenSaved()) {
|
||||||
// if (!force && !info.isWritable()) {
|
reformat(false);
|
||||||
// QMessageBox::critical(pMainWindow,tr("Error"),
|
}
|
||||||
// tr("File %1 is not writable!").arg(mFilename));
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// qDebug()<<"saving "<<mFilename;
|
|
||||||
saveFile(mFilename);
|
saveFile(mFilename);
|
||||||
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
||||||
setModified(false);
|
setModified(false);
|
||||||
|
@ -342,6 +338,10 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
if (pSettings->codeCompletion().enabled() && mParser) {
|
if (pSettings->codeCompletion().enabled() && mParser) {
|
||||||
mParser->invalidateFile(mFilename);
|
mParser->invalidateFile(mFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSettings->editor().autoFormatWhenSaved()) {
|
||||||
|
reformat(false);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mFilename = newName;
|
mFilename = newName;
|
||||||
saveFile(mFilename);
|
saveFile(mFilename);
|
||||||
|
@ -387,7 +387,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
pMainWindow->checkSyntaxInBack(this);
|
pMainWindow->checkSyntaxInBack(this);
|
||||||
reparseTodo();
|
reparseTodo();
|
||||||
|
|
||||||
|
|
||||||
if (!shouldOpenInReadonly()) {
|
if (!shouldOpenInReadonly()) {
|
||||||
setReadOnly(false);
|
setReadOnly(false);
|
||||||
updateCaption();
|
updateCaption();
|
||||||
|
@ -4303,7 +4302,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::reformat()
|
void Editor::reformat(bool doReparse)
|
||||||
{
|
{
|
||||||
if (readOnly())
|
if (readOnly())
|
||||||
return;
|
return;
|
||||||
|
@ -4349,10 +4348,14 @@ void Editor::reformat()
|
||||||
setTopLine(oldTopLine);
|
setTopLine(oldTopLine);
|
||||||
setOptions(oldOptions);
|
setOptions(oldOptions);
|
||||||
endUndoBlock();
|
endUndoBlock();
|
||||||
reparse(true);
|
|
||||||
checkSyntaxInBack();
|
if (doReparse && !pMainWindow->isQuitting() && !pMainWindow->isClosingAll()
|
||||||
reparseTodo();
|
&& !(inProject() && pMainWindow->closingProject())) {
|
||||||
pMainWindow->updateEditorActions();
|
reparse(true);
|
||||||
|
checkSyntaxInBack();
|
||||||
|
reparseTodo();
|
||||||
|
pMainWindow->updateEditorActions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::checkSyntaxInBack()
|
void Editor::checkSyntaxInBack()
|
||||||
|
|
|
@ -195,7 +195,7 @@ public:
|
||||||
void modifyBreakpointProperty(int line);
|
void modifyBreakpointProperty(int line);
|
||||||
void setActiveBreakpointFocus(int Line, bool setFocus=true);
|
void setActiveBreakpointFocus(int Line, bool setFocus=true);
|
||||||
QString getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoord& p);
|
QString getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoord& p);
|
||||||
void reformat();
|
void reformat(bool doReparse=true);
|
||||||
void checkSyntaxInBack();
|
void checkSyntaxInBack();
|
||||||
void gotoDeclaration(const QSynedit::BufferCoord& pos);
|
void gotoDeclaration(const QSynedit::BufferCoord& pos);
|
||||||
void gotoDefinition(const QSynedit::BufferCoord& pos);
|
void gotoDefinition(const QSynedit::BufferCoord& pos);
|
||||||
|
|
|
@ -655,6 +655,16 @@ void Settings::Editor::setUndoMemoryUsage(int newUndoMemoryUsage)
|
||||||
mUndoMemoryUsage = newUndoMemoryUsage;
|
mUndoMemoryUsage = newUndoMemoryUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Settings::Editor::autoFormatWhenSaved() const
|
||||||
|
{
|
||||||
|
return mAutoFormatWhenSaved;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::Editor::setAutoFormatWhenSaved(bool newAutoFormatWhenSaved)
|
||||||
|
{
|
||||||
|
mAutoFormatWhenSaved = newAutoFormatWhenSaved;
|
||||||
|
}
|
||||||
|
|
||||||
bool Settings::Editor::highlightCurrentWord() const
|
bool Settings::Editor::highlightCurrentWord() const
|
||||||
{
|
{
|
||||||
return mHighlightCurrentWord;
|
return mHighlightCurrentWord;
|
||||||
|
@ -1235,6 +1245,7 @@ void Settings::Editor::doSave()
|
||||||
saveValue("auto_detect_file_encoding",mAutoDetectFileEncoding);
|
saveValue("auto_detect_file_encoding",mAutoDetectFileEncoding);
|
||||||
saveValue("undo_limit",mUndoLimit);
|
saveValue("undo_limit",mUndoLimit);
|
||||||
saveValue("undo_memory_usage", mUndoMemoryUsage);
|
saveValue("undo_memory_usage", mUndoMemoryUsage);
|
||||||
|
saveValue("auto_format_when_saved", mAutoFormatWhenSaved);
|
||||||
|
|
||||||
//tooltips
|
//tooltips
|
||||||
saveValue("enable_tooltips",mEnableTooltips);
|
saveValue("enable_tooltips",mEnableTooltips);
|
||||||
|
@ -1377,6 +1388,7 @@ void Settings::Editor::doLoad()
|
||||||
mAutoDetectFileEncoding = boolValue("auto_detect_file_encoding",true);
|
mAutoDetectFileEncoding = boolValue("auto_detect_file_encoding",true);
|
||||||
mUndoLimit = intValue("undo_limit",0);
|
mUndoLimit = intValue("undo_limit",0);
|
||||||
mUndoMemoryUsage = intValue("undo_memory_usage", 10);
|
mUndoMemoryUsage = intValue("undo_memory_usage", 10);
|
||||||
|
mAutoFormatWhenSaved = boolValue("auto_format_when_saved", false);
|
||||||
|
|
||||||
//tooltips
|
//tooltips
|
||||||
mEnableTooltips = boolValue("enable_tooltips",true);
|
mEnableTooltips = boolValue("enable_tooltips",true);
|
||||||
|
|
|
@ -370,6 +370,9 @@ public:
|
||||||
int undoMemoryUsage() const;
|
int undoMemoryUsage() const;
|
||||||
void setUndoMemoryUsage(int newUndoMemoryUsage);
|
void setUndoMemoryUsage(int newUndoMemoryUsage);
|
||||||
|
|
||||||
|
bool autoFormatWhenSaved() const;
|
||||||
|
void setAutoFormatWhenSaved(bool newAutoFormatWhenSaved);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//General
|
//General
|
||||||
// indents
|
// indents
|
||||||
|
@ -478,6 +481,7 @@ public:
|
||||||
bool mDefaultFileCpp;
|
bool mDefaultFileCpp;
|
||||||
int mUndoLimit;
|
int mUndoLimit;
|
||||||
int mUndoMemoryUsage;
|
int mUndoMemoryUsage;
|
||||||
|
bool mAutoFormatWhenSaved;
|
||||||
|
|
||||||
|
|
||||||
//hints tooltip
|
//hints tooltip
|
||||||
|
|
|
@ -66,6 +66,7 @@ void EditorMiscWidget::doLoad()
|
||||||
}
|
}
|
||||||
ui->spinMaxUndo->setValue(pSettings->editor().undoLimit());
|
ui->spinMaxUndo->setValue(pSettings->editor().undoLimit());
|
||||||
ui->spinMaxUndoMemory->setValue(pSettings->editor().undoMemoryUsage());
|
ui->spinMaxUndoMemory->setValue(pSettings->editor().undoMemoryUsage());
|
||||||
|
ui->chkAutoReformat->setChecked(pSettings->editor().autoFormatWhenSaved());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorMiscWidget::doSave()
|
void EditorMiscWidget::doSave()
|
||||||
|
@ -82,6 +83,8 @@ void EditorMiscWidget::doSave()
|
||||||
}
|
}
|
||||||
pSettings->editor().setUndoLimit(ui->spinMaxUndo->value());
|
pSettings->editor().setUndoLimit(ui->spinMaxUndo->value());
|
||||||
pSettings->editor().setUndoMemoryUsage(ui->spinMaxUndoMemory->value());
|
pSettings->editor().setUndoMemoryUsage(ui->spinMaxUndoMemory->value());
|
||||||
|
pSettings->editor().setAutoFormatWhenSaved(ui->chkAutoReformat->isChecked());
|
||||||
|
|
||||||
pSettings->editor().save();
|
pSettings->editor().save();
|
||||||
pMainWindow->updateEditorSettings();
|
pMainWindow->updateEditorSettings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>515</width>
|
<width>515</width>
|
||||||
<height>315</height>
|
<height>408</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -35,6 +35,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="chkAutoReformat">
|
||||||
|
<property name="text">
|
||||||
|
<string>Auto reformat code before saving files</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<widget class="QWidget" name="widget" native="true">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "editorlist.h"
|
#include "editorlist.h"
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
|
||||||
|
static QRegularExpression todoReg("\\b(todo|fixme)\\b", QRegularExpression::CaseInsensitiveOption);
|
||||||
TodoParser::TodoParser(QObject *parent) : QObject(parent),
|
TodoParser::TodoParser(QObject *parent) : QObject(parent),
|
||||||
mMutex(QMutex::Recursive)
|
mMutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +135,7 @@ void TodoThread::doParseFile(const QString &filename, QSynedit::PHighlighter hig
|
||||||
attr = highlighter->getTokenAttribute();
|
attr = highlighter->getTokenAttribute();
|
||||||
if (attr == commentAttr) {
|
if (attr == commentAttr) {
|
||||||
QString token = highlighter->getToken();
|
QString token = highlighter->getToken();
|
||||||
int pos = token.indexOf("TODO:",0,Qt::CaseInsensitive);
|
int pos = token.indexOf(todoReg);
|
||||||
if (pos>=0) {
|
if (pos>=0) {
|
||||||
emit todoFound(
|
emit todoFound(
|
||||||
filename,
|
filename,
|
||||||
|
|
|
@ -1431,6 +1431,10 @@
|
||||||
<source>MB</source>
|
<source>MB</source>
|
||||||
<translation type="unfinished">MB</translation>
|
<translation type="unfinished">MB</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Auto reformat code before saving files</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>EditorSnippetWidget</name>
|
<name>EditorSnippetWidget</name>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1328,6 +1328,10 @@
|
||||||
<source>MB</source>
|
<source>MB</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Auto reformat code before saving files</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>EditorSnippetWidget</name>
|
<name>EditorSnippetWidget</name>
|
||||||
|
|
Loading…
Reference in New Issue