- 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 Version 0.5.0
- enhancement: support C++ using type alias; - enhancement: support C++ using type alias;
- fix: when press shift, completion popu window will hide - fix: when press shift, completion popu window will hide
@ -24,7 +29,7 @@ Version 0.5.0
- implement: context menu for debug console - implement: context menu for debug console
- fix: errors in debug console - fix: errors in debug console
- fix: speed up the parsing process of debugger - 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 Version 0.2.1
- fix: crash when load last opens - fix: crash when load last opens

View File

@ -18,16 +18,27 @@ void CodeSnippetsManager::load()
//if config file not exists, copy it from data //if config file not exists, copy it from data
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_CODESNIPPET_FILE; QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_CODESNIPPET_FILE;
if (!fileExists(filename)) { if (!fileExists(filename)) {
QString defaultFilename = ":/config/codesnippets.json"; QString preFileName = ":/config/codesnippets.json";
if (!QFile::copy( QFile preFile(preFileName);
defaultFilename, if (!preFile.open(QFile::ReadOnly)) {
filename)) {
QMessageBox::critical(nullptr, QMessageBox::critical(nullptr,
tr("Load default code snippets failed"), tr("Load default code snippets failed"),
tr("Can't copy default code snippets '%1' to '%2'.") tr("Can't copy default code snippets '%1' to '%2'.")
.arg(defaultFilename) .arg(preFileName)
.arg(filename)); .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 //read config file
QFile file(filename); QFile file(filename);
@ -71,6 +82,7 @@ void CodeSnippetsManager::save()
tr("Save code snippets failed"), tr("Save code snippets failed"),
tr("Can't open code snippet file '%1' for write.") tr("Can't open code snippet file '%1' for write.")
.arg(filename)); .arg(filename));
return;
} }
QJsonArray array; QJsonArray array;
foreach (const PCodeSnippet& snippet,mSnippets) { foreach (const PCodeSnippet& snippet,mSnippets) {
@ -89,6 +101,7 @@ void CodeSnippetsManager::save()
tr("Save code snippets failed"), tr("Save code snippets failed"),
tr("Write to code snippet file '%1' failed.") tr("Write to code snippet file '%1' failed.")
.arg(filename)); .arg(filename));
return;
} }
} }
@ -151,7 +164,8 @@ QVariant CodeSnippetsModel::data(const QModelIndex &index, int role) const
if (!index.isValid()) { if (!index.isValid()) {
return QVariant(); return QVariant();
} }
if (role==Qt::DisplayRole) { if (role==Qt::DisplayRole
|| role == Qt::EditRole) {
int row = index.row(); int row = index.row();
PCodeSnippet snippet = mSnippets[row]; PCodeSnippet snippet = mSnippets[row];
switch(index.column()) { 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(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
} }
insertString.append(" **/"); 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 { } else {
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS); insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
insertString.append(" **/"); insertString.append(" **/");
@ -544,7 +556,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
s=TrimLeft(lineText()); s=TrimLeft(lineText());
if (s.startsWith("* ")) { if (s.startsWith("* ")) {
handled = true; handled = true;
s+=lineBreak()+"* "; s=lineBreak()+"* ";
insertString(s,false); insertString(s,false);
BufferCoord p = caretXY(); BufferCoord p = caretXY();
p.Line++; p.Line++;

View File

@ -1807,7 +1807,7 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
FolderNode* p = static_cast<FolderNode*>(index.internalPointer()); FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
if (!p) if (!p)
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole || role==Qt::EditRole) {
return p->text; return p->text;
} }
return QVariant(); 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::NoModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier); add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(SynEditorCommand::ecTab, Qt::Key_Tab, Qt::NoModifier); 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::ecShiftTab, Qt::Key_Tab, Qt::ShiftModifier);
add(SynEditorCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier); add(SynEditorCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier);

View File

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