diff --git a/NEWS.md b/NEWS.md
index 8640ba59..c4468f68 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@ Version 0.7.0
- fix: Backspace still works in readonly mode
- fix: save as file dialog's operation mode is not correct
- enhancement: fill indents in the editor (Turned off by default)
+ - enhancement: new file template
+ - fix: when an editor is created, its caret will be displayed even it doesn't have focus
Version 0.6.8
- enhancement: add link to cppreference in the help menu
diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro
index 0a0b54fe..c0df9c68 100644
--- a/RedPandaIDE/RedPandaIDE.pro
+++ b/RedPandaIDE/RedPandaIDE.pro
@@ -19,7 +19,6 @@ SOURCES += \
caretlist.cpp \
codeformatter.cpp \
codesnippetsmanager.cpp \
- codetemplate.cpp \
colorscheme.cpp \
compiler/projectcompiler.cpp \
platform.cpp \
@@ -133,7 +132,6 @@ HEADERS += \
caretlist.h \
codeformatter.h \
codesnippetsmanager.h \
- codetemplate.h \
colorscheme.h \
compiler/compiler.h \
compiler/compilermanager.h \
diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts
index c3f7a47d..f53f4cf4 100644
--- a/RedPandaIDE/RedPandaIDE_zh_CN.ts
+++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts
@@ -273,69 +273,89 @@
CodeSnippetsManager
-
-
+
+
载入缺省代码模板失败
-
-
+
+
无法将缺省代码模板'%1'复制到'%2'。
-
-
+
+
读取代码模板失败
-
+
无法读入代码模板文件'%1'
-
+
读取代码模板文件'%1'失败:%2
-
-
+
+
保存代码模板失败
-
+
-
+
写入代码片段文件'%1'失败。
+
+
+
+ 载入新文件模板失败
+
+
+
+
+ 无法读取新文件模板文件'%1'。
+
+
+
+
+ 保存新文件模板失败
+
+
+
+
+ 无法写入新文件模板文件'%1'。
+
CodeSnippetsModel
-
+
名称
-
+
代码补全前缀
-
+
描述
-
+
菜单节
@@ -931,76 +951,76 @@ Are you really want to continue?
失败
-
-
-
-
-
-
-
+
+
+
+
+
+
+
错误
-
+
无法写入文件"%1"
-
+
另存为
-
+
要复制的内容超过了行数限制!
-
+
要复制的内容超过了字符数限制!
-
+
要剪切的内容超过了行数限制!
-
+
要剪切的内容超过了字符数限制!
-
+
打印文档
-
-
-
+
+
+
Ctrl+单击以获取更多信息
-
-
+
+
未找到符号'%1'!
-
+
断点条件
-
+
输入当前断点的生效条件:
-
+
只读
@@ -1506,15 +1526,25 @@ Are you really want to continue?
表单
-
+
+
+ 代码模板
+
+
+
添加
-
+
删除
+
+
+
+ 新文件模板
+
EditorSymbolCompletionWidget
diff --git a/RedPandaIDE/codesnippetsmanager.cpp b/RedPandaIDE/codesnippetsmanager.cpp
index 989cc790..eecaecdc 100644
--- a/RedPandaIDE/codesnippetsmanager.cpp
+++ b/RedPandaIDE/codesnippetsmanager.cpp
@@ -14,6 +14,18 @@ CodeSnippetsManager::CodeSnippetsManager(QObject *parent) : QObject(parent)
}
void CodeSnippetsManager::load()
+{
+ loadSnippets();
+ loadNewFileTemplate();
+}
+
+void CodeSnippetsManager::save()
+{
+ saveSnippets();
+ saveNewFileTemplate();
+}
+
+void CodeSnippetsManager::loadSnippets()
{
//if config file not exists, copy it from data
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_CODESNIPPET_FILE;
@@ -75,7 +87,7 @@ void CodeSnippetsManager::load()
}
}
-void CodeSnippetsManager::save()
+void CodeSnippetsManager::saveSnippets()
{
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_CODESNIPPET_FILE;
QFile file(filename);
@@ -107,6 +119,38 @@ void CodeSnippetsManager::save()
}
}
+void CodeSnippetsManager::loadNewFileTemplate()
+{
+ QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_NEWFILETEMPLATES_FILE;
+ QFile file(filename);
+ if (!file.exists()) {
+ mNewFileTemplate = "";
+ return;
+ }
+ if (!file.open(QFile::ReadOnly)) {
+ QMessageBox::critical(nullptr,
+ tr("Load new file template failed"),
+ tr("Can't open new file template file '%1' for read.")
+ .arg(filename));
+ return;
+ }
+ mNewFileTemplate=QString::fromUtf8(file.readAll());
+}
+
+void CodeSnippetsManager::saveNewFileTemplate()
+{
+ QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_NEWFILETEMPLATES_FILE;
+ QFile file(filename);
+ if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
+ QMessageBox::critical(nullptr,
+ tr("Save new file template failed"),
+ tr("Can't open new file template file '%1' for write.")
+ .arg(filename));
+ return;
+ }
+ file.write(mNewFileTemplate.toUtf8());
+}
+
const QList &CodeSnippetsManager::snippets() const
{
return mSnippets;
@@ -117,6 +161,16 @@ void CodeSnippetsManager::setSnippets(const QList &newSnippets)
mSnippets = newSnippets;
}
+const QString &CodeSnippetsManager::newFileTemplate() const
+{
+ return mNewFileTemplate;
+}
+
+void CodeSnippetsManager::setNewFileTemplate(const QString &newNewFileTemplate)
+{
+ mNewFileTemplate = newNewFileTemplate;
+}
+
void CodeSnippetsModel::addSnippet(const QString &caption, const QString &prefix, const QString &code, const QString &description, int menuSection)
{
beginInsertRows(QModelIndex(),mSnippets.count(),mSnippets.count());
diff --git a/RedPandaIDE/codesnippetsmanager.h b/RedPandaIDE/codesnippetsmanager.h
index cc9321a9..bad5222a 100644
--- a/RedPandaIDE/codesnippetsmanager.h
+++ b/RedPandaIDE/codesnippetsmanager.h
@@ -41,14 +41,25 @@ public:
void load();
void save();
+
const QList &snippets() const;
void setSnippets(const QList &newSnippets);
+ const QString &newFileTemplate() const;
+ void setNewFileTemplate(const QString &newNewFileTemplate);
+
signals:
+private:
+ void loadSnippets();
+ void saveSnippets();
+ void loadNewFileTemplate();
+ void saveNewFileTemplate();
+
private:
QList mSnippets;
+ QString mNewFileTemplate;
};
using PCodeSnippetManager = std::shared_ptr;
diff --git a/RedPandaIDE/codetemplate.cpp b/RedPandaIDE/codetemplate.cpp
deleted file mode 100644
index 10ac53a3..00000000
--- a/RedPandaIDE/codetemplate.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "codetemplate.h"
-
-CodeTemplate::CodeTemplate()
-{
-
-}
diff --git a/RedPandaIDE/codetemplate.h b/RedPandaIDE/codetemplate.h
deleted file mode 100644
index 48f85d36..00000000
--- a/RedPandaIDE/codetemplate.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef CODETEMPLATE_H
-#define CODETEMPLATE_H
-
-
-class CodeTemplate
-{
-public:
- CodeTemplate();
-};
-
-#endif // CODETEMPLATE_H
diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp
index 10c33532..d3660f39 100644
--- a/RedPandaIDE/editor.cpp
+++ b/RedPandaIDE/editor.cpp
@@ -97,6 +97,9 @@ Editor::Editor(QWidget *parent, const QString& filename,
else
mFileEncoding = mEncodingOption;
highlighter=highlighterManager.getCppHighlighter();
+ if (parentPageControl!=nullptr) {
+ insertCodeSnippet(pMainWindow->codeSnippetManager()->newFileTemplate());
+ }
}
if (highlighter) {
diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp
index 9a772402..0f10775a 100644
--- a/RedPandaIDE/qsynedit/SynEdit.cpp
+++ b/RedPandaIDE/qsynedit/SynEdit.cpp
@@ -129,7 +129,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
synFontChanged();
- showCaret();
+ hideCaret();
connect(horizontalScrollBar(),&QScrollBar::valueChanged,
this, &SynEdit::onScrolled);
diff --git a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp
index b291436e..49979374 100644
--- a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp
+++ b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp
@@ -38,6 +38,8 @@ EditorSnippetWidget::EditorSnippetWidget(const QString& name, const QString& gro
mUpdatingCode = false;
}
});
+ connect(ui->editFileTemplate,&Editor::changed,
+ this, &SettingsWidget::setSettingsChanged);
}
EditorSnippetWidget::~EditorSnippetWidget()
@@ -48,11 +50,13 @@ EditorSnippetWidget::~EditorSnippetWidget()
void EditorSnippetWidget::doLoad()
{
mModel.updateSnippets(pMainWindow->codeSnippetManager()->snippets());
+ ui->editFileTemplate->lines()->setText(pMainWindow->codeSnippetManager()->newFileTemplate());
}
void EditorSnippetWidget::doSave()
{
pMainWindow->codeSnippetManager()->setSnippets(mModel.snippets());
+ pMainWindow->codeSnippetManager()->setNewFileTemplate(ui->editFileTemplate->text());
pMainWindow->codeSnippetManager()->save();
}
diff --git a/RedPandaIDE/settingsdialog/editorsnippetwidget.ui b/RedPandaIDE/settingsdialog/editorsnippetwidget.ui
index 476a72d9..ab970058 100644
--- a/RedPandaIDE/settingsdialog/editorsnippetwidget.ui
+++ b/RedPandaIDE/settingsdialog/editorsnippetwidget.ui
@@ -15,105 +15,136 @@
-
-
-
- Qt::Vertical
+
+
+ 0
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
+
+
+ Code Snippets
+
+
-
-
-
- true
+
+
+ Qt::Vertical
-
- QAbstractItemView::SingleSelection
-
-
- QAbstractItemView::SelectRows
-
-
- Qt::ElideNone
-
-
- true
-
-
-
- -
-
-
-
- 0
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ true
+
+
+ QAbstractItemView::SingleSelection
+
+
+ QAbstractItemView::SelectRows
+
+
+ Qt::ElideNone
+
+
+ true
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Add
+
+
+
+ :/icons/images/newlook24/002-add.png:/icons/images/newlook24/002-add.png
+
+
+
+ -
+
+
+ Remove
+
+
+
+ :/icons/images/newlook24/008-close.png:/icons/images/newlook24/008-close.png
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 159
+
+
+
+
+
+
+
+
+
+
+
+ QFrame::StyledPanel
-
- 0
+
+ QFrame::Raised
-
- 0
-
-
- 0
-
- -
-
-
- Add
-
-
-
- :/icons/images/newlook24/002-add.png:/icons/images/newlook24/002-add.png
-
-
-
- -
-
-
- Remove
-
-
-
- :/icons/images/newlook24/008-close.png:/icons/images/newlook24/008-close.png
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 159
-
-
-
-
-
+
-
-
- QFrame::StyledPanel
-
-
- QFrame::Raised
-
+
+
+ New File Template
+
+
+ -
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+
diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h
index 324224fd..134407f5 100644
--- a/RedPandaIDE/systemconsts.h
+++ b/RedPandaIDE/systemconsts.h
@@ -43,6 +43,7 @@
#define DEV_LASTOPENS_FILE "lastopens.ini"
#define DEV_SYMBOLUSAGE_FILE "symbolusage.json"
#define DEV_CODESNIPPET_FILE "codesnippets.json"
+#define DEV_NEWFILETEMPLATES_FILE "newfiletemplate.txt"
#define DEV_AUTOLINK_FILE "autolink.json"
#define DEV_SHORTCUT_FILE "shortcuts.json"
#define DEV_TOOLS_FILE "tools.json"