diff --git a/IDE-todo.xlsx b/IDE-todo.xlsx
index 6c95383a..09998711 100644
Binary files a/IDE-todo.xlsx and b/IDE-todo.xlsx differ
diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts
index a38afff8..2c6e8b89 100644
--- a/RedPandaIDE/RedPandaIDE_zh_CN.ts
+++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts
@@ -1,3 +1,85 @@
-
+
+
+ Editor
+
+
+
+ 无标题
+
+
+
+ MainWindow
+
+
+
+ 小熊猫C++
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 文件
+
+
+
+
+
+
+
+
+
+ 新建
+
+
+
+
+ 打开...
+
+
+
+
+ 保存
+
+
+
+
+ 另存为...
+
+
+
+
+ 另存为
+
+
+
+
+ 全部保存
+
+
+
+ QObject
+
+
+
+ 保存
+
+
+
+
+ 保存修改后的内容到"%s"?
+
+
+
diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp
index f3bd8d39..cebd69f6 100644
--- a/RedPandaIDE/editor.cpp
+++ b/RedPandaIDE/editor.cpp
@@ -1,32 +1,35 @@
#include "editor.h"
#include
+#include
#include
#include
+#include
#include
#include "settings.h"
#include "mainwindow.h"
+#include
using namespace std;
-Editor::Editor(QObject *parent, const QString& filename,
+Editor::Editor(QWidget *parent, const QString& filename,
const QByteArray& encoding,
bool inProject, bool isNew,
QTabWidget* parentPageControl):
- QObject(parent),
+ QsciScintilla(parent),
mFilename(filename),
mEncodingOption(encoding),
mInProject(inProject),
mIsNew(isNew),
mParentPageControl(parentPageControl)
{
- mTextEdit = new QsciScintilla();
if (mFilename.isEmpty()) {
mFilename = tr("untitled") + "1";
}
QFileInfo fileInfo(mFilename);
- mParentPageControl->addTab(mTextEdit,fileInfo.fileName());
+ if (mParentPageControl!=NULL)
+ mParentPageControl->addTab(this,fileInfo.fileName());
if (!isNew) {
loadFile();
} else {
@@ -35,12 +38,24 @@ Editor::Editor(QObject *parent, const QString& filename,
else
mFileEncoding = mEncodingOption;
}
- mTextEdit->setProperty("editor",QVariant::fromValue((intptr_t)this));
+
+ //
+ QsciLexerCPP *lexer = new QsciLexerCPP();
+ lexer->setHighlightEscapeSequences(true);
+ this->setLexer(lexer);
+ this->setAutoIndent(pSettings->value(EDITOR_AUTO_INDENT).toBool());
+
}
Editor::~Editor() {
- int index = mParentPageControl->indexOf(mTextEdit);
- mParentPageControl->removeTab(index);
+ if (mParentPageControl!=NULL) {
+ int index = mParentPageControl->indexOf(this);
+ mParentPageControl->removeTab(index);
+ }
+ this->setParent(0);
+
+ delete this->lexer();
+ this->setLexer(NULL);
}
void Editor::loadFile() {
@@ -53,14 +68,14 @@ void Editor::loadFile() {
mFileEncoding = mEncodingOption;
}
if (mFileEncoding == ENCODING_UTF8) {
- mTextEdit->setText(QString::fromUtf8(ba));
+ this->setText(QString::fromUtf8(ba));
} else if (mFileEncoding == ENCODING_UTF8_BOM) {
- mTextEdit->setText(QString::fromUtf8(ba.mid(3)));
+ this->setText(QString::fromUtf8(ba.mid(3)));
} else if (mFileEncoding == ENCODING_ASCII) {
- mTextEdit->setText(QString::fromLatin1(ba));
+ this->setText(QString::fromLatin1(ba));
}else {
QTextCodec*codec = QTextCodec::codecForName(mFileEncoding);
- mTextEdit->setText(codec->toUnicode(ba));
+ this->setText(codec->toUnicode(ba));
}
}
@@ -69,7 +84,7 @@ void Editor::saveFile(const QString &filename) {
mFileEncoding = mEncodingOption;
}
if (mEncodingOption == ENCODING_AUTO_DETECT && mFileEncoding == ENCODING_ASCII) {
- if (!isTextAllAscii(mTextEdit->text())) {
+ if (!isTextAllAscii(this->text())) {
mFileEncoding = pSettings->value(EDITOR_DEFAULT_ENCODING).toByteArray();
}
pMainWindow->updateStatusBarForEncoding();
@@ -78,18 +93,18 @@ void Editor::saveFile(const QString &filename) {
QFile file(filename);
QByteArray ba;
if (mFileEncoding == ENCODING_UTF8) {
- ba = mTextEdit->text().toUtf8();
+ ba = this->text().toUtf8();
} else if (mFileEncoding == ENCODING_UTF8_BOM) {
ba.resize(3);
ba[0]=0xEF;
ba[1]=0xBB;
ba[2]=0xBF;
- ba.append(mTextEdit->text().toUtf8());
+ ba.append(this->text().toUtf8());
} else if (mFileEncoding == ENCODING_ASCII) {
- ba = mTextEdit->text().toLatin1();
+ ba = this->text().toLatin1();
} else {
QTextCodec* codec = QTextCodec::codecForName(mFileEncoding);
- ba = codec->fromUnicode(mTextEdit->text());
+ ba = codec->fromUnicode(this->text());
}
file.write(ba);
file.close();
@@ -118,6 +133,17 @@ bool Editor::inProject() const {
bool Editor::isNew() const {
return mIsNew;
}
-QsciScintilla* Editor::textEdit() {
- return mTextEdit;
+
+QTabWidget* Editor::pageControl() {
+ return mParentPageControl;
+}
+
+void Editor::wheelEvent(QWheelEvent *event) {
+ if ( (event->modifiers() & Qt::ControlModifier)!=0) {
+ if (event->angleDelta().y()>0) {
+ this->zoomIn();
+ } else {
+ this->zoomOut();
+ }
+ }
}
diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h
index 4e79575c..74a40146 100644
--- a/RedPandaIDE/editor.h
+++ b/RedPandaIDE/editor.h
@@ -6,14 +6,13 @@
#include
#include
-class Editor : public QObject
+class Editor : public QsciScintilla
{
Q_OBJECT
public:
- explicit Editor(QObject *parent, const QString& filename,
+ explicit Editor(QWidget *parent, const QString& filename,
const QByteArray& encoding,
- bool inProject, bool isNew,
- QTabWidget* parentPageControl);
+ bool inProject, bool isNew,QTabWidget* parentPageControl);
~Editor();
@@ -28,7 +27,6 @@ public:
void saveFile(const QString& filename);
bool save(bool force=false, bool reparse=true);
- QsciScintilla* textEdit();
QTabWidget* pageControl();
signals:
@@ -39,7 +37,11 @@ private:
QTabWidget* mParentPageControl;
bool mInProject;
bool mIsNew;
- QsciScintilla* mTextEdit;
+
+
+ // QWidget interface
+protected:
+ void wheelEvent(QWheelEvent *event) override;
};
#endif // EDITOR_H
diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp
index 09e5b858..bff62a7d 100644
--- a/RedPandaIDE/editorlist.cpp
+++ b/RedPandaIDE/editorlist.cpp
@@ -13,7 +13,6 @@ EditorList::UpdateLocker::~UpdateLocker() {
mEditorList->endUpdate();
}
-}
EditorList::EditorList(QTabWidget* leftPageWidget,
QTabWidget* rightPageWidget,
QSplitter* splitter,
@@ -62,10 +61,7 @@ Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const {
if (index<0 || index >= selectedWidget->count()) {
return NULL;
}
- QWidget* textEdit = selectedWidget->widget(index);
- QVariant pop = textEdit->property("editor");
- Editor *editor = (Editor*)pop.value();
- return editor;
+ return (Editor*)selectedWidget->widget(index);
}
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
@@ -74,7 +70,7 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
return false;
if (force) {
editor->save(true,false);
- } else if ( (editor->textEdit()->isModified()) && (!editor->textEdit()->text().isEmpty())) {
+ } else if ( (editor->isModified()) && (!editor->text().isEmpty())) {
// ask user if he wants to save
QMessageBox::StandardButton reply;
reply = QMessageBox::question(pMainWindow,QObject::tr("Save"),QObject::tr("Save changes to %s?"),
@@ -88,7 +84,9 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
}
}
- if (transferFocus && editor-)
+ if (transferFocus && (editor->pageControl()->currentWidget()==editor)) {
+ //todo: activate & focus the previous editor
+ }
delete editor;
return true;
@@ -111,5 +109,16 @@ void EditorList::endUpdate() {
bool EditorList::closeAll(bool force) {
UpdateLocker locker(this);
+ while (mLeftPageWidget->count()>0) {
+ if (!closeEditor(getEditor(0,mLeftPageWidget),false,force)) {
+ return false;
+ }
+ }
+ while (mRightPageWidget->count()>0) {
+ if (!closeEditor(getEditor(0,mRightPageWidget),false,force)) {
+ return false;
+ }
+ }
+ return true;
}
diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp
index eb9dfaaf..8c5a7e3c 100644
--- a/RedPandaIDE/mainwindow.cpp
+++ b/RedPandaIDE/mainwindow.cpp
@@ -3,6 +3,7 @@
#include "editorlist.h"
#include "editor.h"
+#include
#include
MainWindow* pMainWindow;
@@ -63,3 +64,14 @@ void MainWindow::on_actionOpen_triggered()
editor->save();
}
}
+
+void MainWindow::closeEvent(QCloseEvent *event) {
+ if (!mEditorList->closeAll(true)) {
+ event->ignore();
+ return ;
+ }
+
+ delete mEditorList;
+ event->accept();
+ return;
+}
diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h
index 23ac53c3..72125d42 100644
--- a/RedPandaIDE/mainwindow.h
+++ b/RedPandaIDE/mainwindow.h
@@ -20,6 +20,7 @@ public:
void updateStatusBarForEncoding();
+
private slots:
void on_actionNew_triggered();
@@ -35,6 +36,10 @@ private:
EditorList* mEditorList;
QLabel* mFileInfoStatus;
QLabel* mFileEncodingStatus;
+
+ // QWidget interface
+protected:
+ void closeEvent(QCloseEvent *event) override;
};
extern MainWindow* pMainWindow;
diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp
index 26811f5f..f5c2449d 100644
--- a/RedPandaIDE/settings.cpp
+++ b/RedPandaIDE/settings.cpp
@@ -9,6 +9,7 @@ Settings::Settings():
// default values for editors
setDefault(EDITOR_DEFAULT_ENCODING, QTextCodec::codecForLocale()->name());
+ setDefault(EDITOR_AUTO_INDENT,true);
}
diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h
index 9c5e63b4..f0fc62e4 100644
--- a/RedPandaIDE/settings.h
+++ b/RedPandaIDE/settings.h
@@ -4,6 +4,8 @@
#include
#define EDITOR_DEFAULT_ENCODING "editor/default_encoding"
+#define EDITOR_AUTO_INDENT "editor/default_auto_indent"
+
class Settings
{