Simplified Chinese translation updated

- fix: error when syntax checking for header file
 - open the included header file when double click it
 - use QEvent::HoverXXX messages instead of QEvent::Tooltip to handle hint tips
 - fix: type hint for functions is wrong
This commit is contained in:
royqh1979 2021-08-30 13:30:42 +08:00
parent 67fba515a3
commit 692ff570e2
9 changed files with 1000 additions and 653 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ bool StdinCompiler::prepareForCompile()
QString strFileType; QString strFileType;
switch(fileType) { switch(fileType) {
case FileType::CSource: case FileType::CSource:
case FileType::CHeader:
mArguments += " -x c - "; mArguments += " -x c - ";
mArguments += getCCompileArguments(mOnlyCheckSyntax); mArguments += getCCompileArguments(mOnlyCheckSyntax);
mArguments += getCIncludeArguments(); mArguments += getCIncludeArguments();
@ -35,6 +36,7 @@ bool StdinCompiler::prepareForCompile()
mCompiler = compilerSet()->CCompiler(); mCompiler = compilerSet()->CCompiler();
break; break;
case FileType::CppSource: case FileType::CppSource:
case FileType::CppHeader:
mArguments += " -x c++ - "; mArguments += " -x c++ - ";
mArguments += getCCompileArguments(mOnlyCheckSyntax); mArguments += getCCompileArguments(mOnlyCheckSyntax);
mArguments += getCIncludeArguments(); mArguments += getCIncludeArguments();

View File

@ -104,6 +104,12 @@ Editor::Editor(QWidget *parent, const QString& filename,
} else { } else {
initParser(); initParser();
} }
if (mParser->isSystemHeaderFile(filename) || mParser->isProjectHeaderFile(filename)) {
this->setModified(false);
setReadOnly(true);
updateCaption();
}
// mCompletionPopup = std::make_shared<CodeCompletionPopup>(); // mCompletionPopup = std::make_shared<CodeCompletionPopup>();
// mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>(); // mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
mCompletionPopup = pMainWindow->completionPopup(); mCompletionPopup = pMainWindow->completionPopup();
@ -116,6 +122,8 @@ Editor::Editor(QWidget *parent, const QString& filename,
connect(this,&SynEdit::gutterClicked,this,&Editor::onGutterClicked); connect(this,&SynEdit::gutterClicked,this,&Editor::onGutterClicked);
onStatusChanged(SynStatusChange::scOpenFile); onStatusChanged(SynStatusChange::scOpenFile);
setAttribute(Qt::WA_Hover,true);
} }
Editor::~Editor() { Editor::~Editor() {
@ -557,12 +565,12 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} }
qDebug()<<token<<"-"<<attr->name()<<" - "<<line<<" : "<<aChar; // qDebug()<<token<<"-"<<attr->name()<<" - "<<line<<" : "<<aChar;
if (mParser && mCompletionPopup && (attr->name() == SYNS_AttrIdentifier)) { if (mParser && mCompletionPopup && (attr->name() == SYNS_AttrIdentifier)) {
BufferCoord p{aChar,line}; BufferCoord p{aChar,line};
BufferCoord pBeginPos,pEndPos; BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(p, pBeginPos,pEndPos, WordPurpose::wpInformation); QString s= getWordAtPosition(p, pBeginPos,pEndPos, WordPurpose::wpInformation);
qDebug()<<s; // qDebug()<<s;
PStatement statement = mParser->findStatementOf(mFilename, PStatement statement = mParser->findStatementOf(mFilename,
s , p.Line); s , p.Line);
StatementKind kind = mParser->getKindOfStatement(statement); StatementKind kind = mParser->getKindOfStatement(statement);
@ -584,8 +592,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
bool Editor::event(QEvent *event) bool Editor::event(QEvent *event)
{ {
if (event->type() == QEvent::ToolTip) { if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
BufferCoord p; BufferCoord p;
TipType reason = getTipType(helpEvent->pos(),p); TipType reason = getTipType(helpEvent->pos(),p);
PSyntaxIssue pError; PSyntaxIssue pError;
@ -634,12 +642,14 @@ bool Editor::event(QEvent *event)
return true; return true;
} }
// qDebug()<<s<<" -- "<<(int)reason;
// Don't rescan the same stuff over and over again (that's slow) // Don't rescan the same stuff over and over again (that's slow)
// if (s = fCurrentWord) and (fText.Hint<>'') then // if (s = fCurrentWord) and (fText.Hint<>'') then
s = s.trimmed(); s = s.trimmed();
if ((s == mCurrentWord) && (mCurrentTipType == reason)) { if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
QApplication* app = dynamic_cast<QApplication *>(QApplication::instance()); // QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) { // if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (helpEvent->modifiers() == Qt::ControlModifier) {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
} else { } else {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
@ -680,22 +690,69 @@ bool Editor::event(QEvent *event)
case TipType::Error: case TipType::Error:
hint = getErrorHint(pError); hint = getErrorHint(pError);
} }
// qDebug()<<"hint:"<<hint;
if (!hint.isEmpty()) { if (!hint.isEmpty()) {
QApplication* app = dynamic_cast<QApplication *>(QApplication::instance()); // QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) { // if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (helpEvent->modifiers() == Qt::ControlModifier) {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
} else { } else {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
QToolTip::showText(helpEvent->globalPos(),hint); QToolTip::showText(mapToGlobal(helpEvent->pos()),hint);
event->ignore(); event->ignore();
} else { } else {
event->ignore(); event->ignore();
} }
return true;
} else if (event->type() == QEvent::HoverLeave) {
cancelHint();
return true;
} else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease ) {
if (!mCurrentWord.isEmpty()) {
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Control) {
QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
QHoverEvent* hoverEvent=new QHoverEvent(QEvent::HoverMove,
mapFromGlobal(QCursor::pos()),
mapFromGlobal(QCursor::pos()),
Qt::ControlModifier
);
app->postEvent(this,hoverEvent);
}
}
} }
return SynEdit::event(event); return SynEdit::event(event);
} }
void Editor::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() | Qt::LeftButton) {
mLastIdCharPressed = 0;
}
// if ctrl+clicked
if ((event->modifiers() == Qt::ControlModifier)
&& (event->button() == Qt::LeftButton)) {
BufferCoord p;
if (PointToCharLine(event->pos(),p)) {
QString s = lines()->getString(p.Line - 1);
if (mParser->isIncludeLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s);
Editor * e = pMainWindow->editorList()->getEditorByFilename(filename);
if (e) {
e->setCaretPositionAndActivate(1,1);
return;
}
}
// else
// MainForm.actGotoImplDeclEditorExecute(self);
}
}
SynEdit::mouseReleaseEvent(event);
}
void Editor::copyToClipboard() void Editor::copyToClipboard()
{ {
if (pSettings->editor().copySizeLimit()) { if (pSettings->editor().copySizeLimit()) {
@ -1947,10 +2004,8 @@ QString Editor::getParserHint(const QString &s, int line)
mFilename,line); mFilename,line);
} else if (statement->line>0) { } else if (statement->line>0) {
QFileInfo fileInfo(statement->fileName); QFileInfo fileInfo(statement->fileName);
result = mParser->prettyPrintStatement(statement,mFilename, line) + " - " + result = mParser->prettyPrintStatement(statement,mFilename, line) + " - "
QString(" %1 (%2) ") + QString("%1(%2)").arg(fileInfo.fileName()).arg(line)
.arg(fileInfo.fileName())
.arg(statement->line)
+ tr("Ctrl+click for more info"); + tr("Ctrl+click for more info");
} else { // hard defines } else { // hard defines
result = mParser->prettyPrintStatement(statement, mFilename); result = mParser->prettyPrintStatement(statement, mFilename);
@ -1999,10 +2054,9 @@ QString Editor::getHintForFunction(const PStatement &statement, const PStatement
continue; continue;
if (!result.isEmpty()) if (!result.isEmpty())
result += "<BR />"; result += "<BR />";
result = mParser->prettyPrintStatement(childStatement,filename,line) + " - " + QFileInfo fileInfo(filename);
QString(" %1 (%2) ") result = mParser->prettyPrintStatement(childStatement,filename,line) + " - "
.arg(filename) + QString("%1(%2)").arg(fileInfo.fileName()).arg(line)
.arg(childStatement->line)
+ tr("Ctrl+click for more info"); + tr("Ctrl+click for more info");
} }
} }
@ -2505,6 +2559,9 @@ void Editor::updateCaption(const QString& newCaption) {
if (this->modified()) { if (this->modified()) {
caption.append("[*]"); caption.append("[*]");
} }
if (this->readOnly()) {
caption.append("["+tr("Readonly")+"]");
}
mParentPageControl->setTabText(index,caption); mParentPageControl->setTabText(index,caption);
} else { } else {
mParentPageControl->setTabText(index,newCaption); mParentPageControl->setTabText(index,newCaption);

View File

@ -243,6 +243,10 @@ protected:
// QObject interface // QObject interface
public: public:
bool event(QEvent *event) override; bool event(QEvent *event) override;
// QWidget interface
protected:
void mouseReleaseEvent(QMouseEvent *event) override;
}; };
#endif // EDITOR_H #endif // EDITOR_H

View File

@ -349,6 +349,16 @@ void Settings::Editor::setSyntaxCheckWhenLineChanged(bool syntaxCheckWhenLineCha
mSyntaxCheckWhenLineChanged = syntaxCheckWhenLineChanged; mSyntaxCheckWhenLineChanged = syntaxCheckWhenLineChanged;
} }
bool Settings::Editor::readOnlySytemHeader() const
{
return mReadOnlySytemHeader;
}
void Settings::Editor::setReadOnlySytemHeader(bool newReadOnlySytemHeader)
{
mReadOnlySytemHeader = newReadOnlySytemHeader;
}
bool Settings::Editor::syntaxCheckWhenSave() const bool Settings::Editor::syntaxCheckWhenSave() const
{ {
return mSyntaxCheckWhenSave; return mSyntaxCheckWhenSave;
@ -722,6 +732,7 @@ void Settings::Editor::setAutoHideScrollbar(bool autoHideScrollbar)
void Settings::Editor::doSave() void Settings::Editor::doSave()
{ {
saveValue("default_encoding",mDefaultEncoding); saveValue("default_encoding",mDefaultEncoding);
saveValue("readonly_system_header",mReadOnlySytemHeader);
// indents // indents
saveValue("auto_indent", mAutoIndent); saveValue("auto_indent", mAutoIndent);
saveValue("add_indent", mAddIndent); saveValue("add_indent", mAddIndent);
@ -798,6 +809,7 @@ void Settings::Editor::doSave()
void Settings::Editor::doLoad() void Settings::Editor::doLoad()
{ {
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray(); mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
// indents // indents
mAutoIndent = boolValue("auto_indent", true); mAutoIndent = boolValue("auto_indent", true);
mAddIndent = boolValue("add_indent", true); mAddIndent = boolValue("add_indent", true);
@ -1996,7 +2008,6 @@ void Settings::CompilerSets::loadSets()
} }
clearSets(); clearSets();
findSets(); findSets();
mDefaultIndex = mList.size()-1;
pCurrentSet = defaultSet(); pCurrentSet = defaultSet();
if (!pCurrentSet) { if (!pCurrentSet) {
return; return;
@ -2433,3 +2444,155 @@ void Settings::History::doLoad()
mOpenedFiles = stringListValue("opened_files"); mOpenedFiles = stringListValue("opened_files");
mOpenedProjects =stringListValue("opened_projects"); mOpenedProjects =stringListValue("opened_projects");
} }
Settings::CodeCompletion::CodeCompletion(Settings *settings):_Base(settings, SETTING_CODE_COMPLETION)
{
}
bool Settings::CodeCompletion::showCodeIns() const
{
return mShowCodeIns;
}
void Settings::CodeCompletion::setShowCodeIns(bool newShowCodeIns)
{
mShowCodeIns = newShowCodeIns;
}
bool Settings::CodeCompletion::appendFunc() const
{
return mAppendFunc;
}
void Settings::CodeCompletion::setAppendFunc(bool newAppendFunc)
{
mAppendFunc = newAppendFunc;
}
bool Settings::CodeCompletion::ignoreCase() const
{
return mIgnoreCase;
}
void Settings::CodeCompletion::setIgnoreCase(bool newIgnoreCase)
{
mIgnoreCase = newIgnoreCase;
}
bool Settings::CodeCompletion::showKeywords() const
{
return mShowKeywords;
}
void Settings::CodeCompletion::setShowKeywords(bool newShowKeywords)
{
mShowKeywords = newShowKeywords;
}
bool Settings::CodeCompletion::sortByScope() const
{
return mSortByScope;
}
void Settings::CodeCompletion::setSortByScope(bool newSortByScope)
{
mSortByScope = newSortByScope;
}
bool Settings::CodeCompletion::recordUsage() const
{
return mRecordUsage;
}
void Settings::CodeCompletion::setRecordUsage(bool newRecordUsage)
{
mRecordUsage = newRecordUsage;
}
bool Settings::CodeCompletion::showCompletionWhileInput() const
{
return mShowCompletionWhileInput;
}
void Settings::CodeCompletion::setShowCompletionWhileInput(bool newShowCompletionWhileInput)
{
mShowCompletionWhileInput = newShowCompletionWhileInput;
}
bool Settings::CodeCompletion::parseGlobalHeaders() const
{
return mParseGlobalHeaders;
}
void Settings::CodeCompletion::setParseGlobalHeaders(bool newParseGlobalHeaders)
{
mParseGlobalHeaders = newParseGlobalHeaders;
}
bool Settings::CodeCompletion::parseLocalHeaders() const
{
return mParseLocalHeaders;
}
void Settings::CodeCompletion::setParseLocalHeaders(bool newParseLocalHeaders)
{
mParseLocalHeaders = newParseLocalHeaders;
}
bool Settings::CodeCompletion::enabled() const
{
return mEnabled;
}
void Settings::CodeCompletion::setEnabled(bool newEnabled)
{
mEnabled = newEnabled;
}
int Settings::CodeCompletion::height() const
{
return mHeight;
}
void Settings::CodeCompletion::setHeight(int newHeight)
{
mHeight = newHeight;
}
int Settings::CodeCompletion::width() const
{
return mWidth;
}
void Settings::CodeCompletion::setWidth(int newWidth)
{
mWidth = newWidth;
}
void Settings::CodeCompletion::doSave()
{
//Appearence
saveValue("width",mWidth);
saveValue("height",mHeight);
saveValue("enabled",mEnabled);
saveValue("parse_local_headers",mParseLocalHeaders);
saveValue("parse_global_headers",mParseGlobalHeaders);
saveValue("show_completion_while_input",mShowCompletionWhileInput);
saveValue("record_usage",mRecordUsage);
saveValue("sort_by_scope",mSortByScope);
saveValue("show_keywords",mShowKeywords);
saveValue("ignore_case",mIgnoreCase);
saveValue("append_func",mAppendFunc);
saveValue("show_code_ins",mShowCodeIns);
}
void Settings::CodeCompletion::doLoad()
{
//Appearence
mTheme = stringValue("theme","dark");
mInterfaceFont = stringValue("interface font","Segoe UI");
mInterfaceFontSize = intValue("interface font size",10);
mLanguage = stringValue("language", QLocale::system().name());
}

View File

@ -17,7 +17,8 @@
#define SETTING_ENVIRONMENT "Environment" #define SETTING_ENVIRONMENT "Environment"
#define SETTING_EXECUTOR "Executor" #define SETTING_EXECUTOR "Executor"
#define SETTING_DEBUGGER "Debugger" #define SETTING_DEBUGGER "Debugger"
#define SETTING_HISTORY "HISTORY" #define SETTING_HISTORY "History"
#define SETTING_CODE_COMPLETION "CodeCompletion"
#define SETTING_COMPILTER_SETS "CompilerSets" #define SETTING_COMPILTER_SETS "CompilerSets"
#define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex" #define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex"
#define SETTING_COMPILTER_SETS_COUNT "count" #define SETTING_COMPILTER_SETS_COUNT "count"
@ -261,9 +262,13 @@ public:
bool syntaxCheckWhenLineChanged() const; bool syntaxCheckWhenLineChanged() const;
void setSyntaxCheckWhenLineChanged(bool syntaxCheckWhenLineChanged); void setSyntaxCheckWhenLineChanged(bool syntaxCheckWhenLineChanged);
bool readOnlySytemHeader() const;
void setReadOnlySytemHeader(bool newReadOnlySytemHeader);
private: private:
QByteArray mDefaultEncoding; QByteArray mDefaultEncoding;
//General //General
bool mReadOnlySytemHeader;
// indents // indents
bool mAutoIndent; bool mAutoIndent;
bool mAddIndent; bool mAddIndent;
@ -371,6 +376,66 @@ public:
void doLoad() override; void doLoad() override;
}; };
class CodeCompletion: public _Base {
public:
explicit CodeCompletion(Settings *settings);
int width() const;
void setWidth(int newWidth);
int height() const;
void setHeight(int newHeight);
bool enabled() const;
void setEnabled(bool newEnabled);
bool parseLocalHeaders() const;
void setParseLocalHeaders(bool newParseLocalHeaders);
bool parseGlobalHeaders() const;
void setParseGlobalHeaders(bool newParseGlobalHeaders);
bool showCompletionWhileInput() const;
void setShowCompletionWhileInput(bool newShowCompletionWhileInput);
bool recordUsage() const;
void setRecordUsage(bool newRecordUsage);
bool sortByScope() const;
void setSortByScope(bool newSortByScope);
bool showKeywords() const;
void setShowKeywords(bool newShowKeywords);
bool ignoreCase() const;
void setIgnoreCase(bool newIgnoreCase);
bool appendFunc() const;
void setAppendFunc(bool newAppendFunc);
bool showCodeIns() const;
void setShowCodeIns(bool newShowCodeIns);
private:
int mWidth;
int mHeight;
bool mEnabled;
bool mParseLocalHeaders;
bool mParseGlobalHeaders;
bool mShowCompletionWhileInput;
bool mRecordUsage;
bool mSortByScope;
bool mShowKeywords;
bool mIgnoreCase;
bool mAppendFunc;
bool mShowCodeIns;
// _Base interface
protected:
void doSave() override;
void doLoad() override;
};
class History: public _Base { class History: public _Base {
public: public:
explicit History(Settings *settings); explicit History(Settings *settings);

View File

@ -138,27 +138,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Disassembly Coding Style</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">

View File

@ -14,6 +14,19 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="grpCompleSymbols"> <widget class="QGroupBox" name="grpCompleSymbols">
<property name="title"> <property name="title">
@ -138,19 +151,6 @@
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chkRemoveSymbolPairs"> <widget class="QCheckBox" name="chkRemoveSymbolPairs">
<property name="text"> <property name="text">
<string>Remove symbol pairs when delete chars</string> <string>Remove symbol pairs when delete chars</string>