- fix: old data not displayed when editing code snippets

- fix: shift-tab for unindent not work
 - fix: can't save code snippets modifications
This commit is contained in:
royqh1979@gmail.com 2021-10-03 08:25:28 +08:00
parent f2e09075fc
commit caaf07a6cc
6 changed files with 51 additions and 17 deletions

View File

@ -1,3 +1,8 @@
Version 0.6.0
- fix: old data not displayed when editing code snippets
- fix: shift-tab for unindent not work
- fix: can't save code snippets modifications
Version 0.5.0
- enhancement: support C++ using type alias;
- fix: when press shift, completion popu window will hide
@ -24,7 +29,7 @@ Version 0.5.0
- implement: context menu for debug console
- fix: errors in debug console
- fix: speed up the parsing process of debugger
- ehancement: check if debugger path contains non-ascii characters (this will prevent it from work)
- ehancement: check if debugger path contains non-ascii characters (this will prevent it from work
Version 0.2.1
- fix: crash when load last opens

View File

@ -18,16 +18,27 @@ void CodeSnippetsManager::load()
//if config file not exists, copy it from data
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_CODESNIPPET_FILE;
if (!fileExists(filename)) {
QString defaultFilename = ":/config/codesnippets.json";
if (!QFile::copy(
defaultFilename,
filename)) {
QString preFileName = ":/config/codesnippets.json";
QFile preFile(preFileName);
if (!preFile.open(QFile::ReadOnly)) {
QMessageBox::critical(nullptr,
tr("Load default code snippets failed"),
tr("Can't copy default code snippets '%1' to '%2'.")
.arg(defaultFilename)
.arg(preFileName)
.arg(filename));
return;
}
QByteArray content=preFile.readAll();
QFile file(filename);
if (!file.open(QFile::WriteOnly|QFile::Truncate)) {
QMessageBox::critical(nullptr,
tr("Load default code snippets failed"),
tr("Can't copy default code snippets '%1' to '%2'.")
.arg(preFileName)
.arg(filename));
return;
}
file.write(content);
}
//read config file
QFile file(filename);
@ -71,6 +82,7 @@ void CodeSnippetsManager::save()
tr("Save code snippets failed"),
tr("Can't open code snippet file '%1' for write.")
.arg(filename));
return;
}
QJsonArray array;
foreach (const PCodeSnippet& snippet,mSnippets) {
@ -89,6 +101,7 @@ void CodeSnippetsManager::save()
tr("Save code snippets failed"),
tr("Write to code snippet file '%1' failed.")
.arg(filename));
return;
}
}
@ -151,7 +164,8 @@ QVariant CodeSnippetsModel::data(const QModelIndex &index, int role) const
if (!index.isValid()) {
return QVariant();
}
if (role==Qt::DisplayRole) {
if (role==Qt::DisplayRole
|| role == Qt::EditRole) {
int row = index.row();
PCodeSnippet snippet = mSnippets[row];
switch(index.column()) {

View File

@ -532,6 +532,18 @@ void Editor::keyPressEvent(QKeyEvent *event)
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
}
insertString.append(" **/");
} else if (caretY()==1) { /* file header */
insertString.append(QString(" * @file %1%2%3")
.arg(USER_CODE_IN_REPL_POS_BEGIN)
.arg(mFilename)
.arg(USER_CODE_IN_REPL_POS_END));
insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
insertString.append(QString(" * @date: ") + QDateTime::currentDateTime().toString("yyyy-MM-dd hh::mm"));
insertString.append(" * ");
insertString.append(" **/");
} else {
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
insertString.append(" **/");
@ -544,7 +556,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
s=TrimLeft(lineText());
if (s.startsWith("* ")) {
handled = true;
s+=lineBreak()+"* ";
s=lineBreak()+"* ";
insertString(s,false);
BufferCoord p = caretXY();
p.Line++;

View File

@ -1807,7 +1807,7 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
if (!p)
return QVariant();
if (role == Qt::DisplayRole) {
if (role == Qt::DisplayRole || role==Qt::EditRole) {
return p->text;
}
return QVariant();

View File

@ -204,6 +204,7 @@ void SynEditKeyStrokes::resetDefaults()
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::NoModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(SynEditorCommand::ecTab, Qt::Key_Tab, Qt::NoModifier);
add(SynEditorCommand::ecShiftTab, Qt::Key_Backtab, Qt::ShiftModifier);
add(SynEditorCommand::ecShiftTab, Qt::Key_Tab, Qt::ShiftModifier);
add(SynEditorCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier);

View File

@ -472,14 +472,16 @@ void CodeCompletionPopup::getCompletionFor(const QString &fileName, const QStrin
if (mShowCodeSnippets) {
//add custom code templates
foreach (const PCodeSnippet& codeIn,mCodeSnippets) {
PStatement statement = std::make_shared<Statement>();
statement->command = codeIn->prefix;
statement->value = codeIn->code;
statement->kind = StatementKind::skUserCodeSnippet;
statement->fullName = codeIn->prefix;
statement->usageCount = 0;
statement->freqTop = 0;
mFullCompletionStatementList.append(statement);
if (!codeIn->code.isEmpty()) {
PStatement statement = std::make_shared<Statement>();
statement->command = codeIn->prefix;
statement->value = codeIn->code;
statement->kind = StatementKind::skUserCodeSnippet;
statement->fullName = codeIn->prefix;
statement->usageCount = 0;
statement->freqTop = 0;
mFullCompletionStatementList.append(statement);
}
}
}