- fix: crash when create new file

- implement: two editor view
This commit is contained in:
royqh1979@gmail.com 2021-10-13 11:32:59 +08:00
parent 47f754ca0f
commit 59390203e3
10 changed files with 137 additions and 32 deletions

View File

@ -1,3 +1,7 @@
Version 0.6.6
- fix: crash when create new file
- implement: two editor view
Version 0.6.5 Version 0.6.5
- implement: export as rtf / export as html - implement: export as rtf / export as html
- fix: the contents copied/exported are not correctly syntax colored - fix: the contents copied/exported are not correctly syntax colored

View File

@ -382,6 +382,28 @@ bool Editor::isNew() const noexcept {
QTabWidget* Editor::pageControl() noexcept{ QTabWidget* Editor::pageControl() noexcept{
return mParentPageControl; return mParentPageControl;
} }
static int findWidgetInPageControl(QTabWidget* pageControl, QWidget* child) {
for (int i=0;i<pageControl->count();i++) {
if (pageControl->widget(i)==child)
return i;
}
return -1;
}
void Editor::setPageControl(QTabWidget *newPageControl)
{
if (mParentPageControl==newPageControl)
return;
if (mParentPageControl!=nullptr) {
int index = findWidgetInPageControl(mParentPageControl,this);
if (index>=0)
mParentPageControl->removeTab(index);
}
mParentPageControl= newPageControl;
if (newPageControl!=nullptr) {
mParentPageControl->addTab(this,"");
updateCaption();
}
}
void Editor::undoSymbolCompletion(int pos) void Editor::undoSymbolCompletion(int pos)
{ {

View File

@ -124,6 +124,7 @@ public:
void activate(); void activate();
QTabWidget* pageControl() noexcept; QTabWidget* pageControl() noexcept;
void setPageControl(QTabWidget* newPageControl);
void updateCaption(const QString& newCaption=QString()); void updateCaption(const QString& newCaption=QString());
void applySettings(); void applySettings();

View File

@ -24,8 +24,8 @@ EditorList::EditorList(QTabWidget* leftPageWidget,
Editor* EditorList::newEditor(const QString& filename, const QByteArray& encoding, Editor* EditorList::newEditor(const QString& filename, const QByteArray& encoding,
bool inProject, bool newFile, bool inProject, bool newFile,
QTabWidget* page) { QTabWidget* page) {
QTabWidget * parentPageControl = NULL; QTabWidget * parentPageControl = nullptr;
if (page == NULL) if (page == nullptr)
parentPageControl = getNewEditorPageControl(); parentPageControl = getNewEditorPageControl();
else else
parentPageControl = page; parentPageControl = page;
@ -38,13 +38,25 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin
} }
QTabWidget* EditorList::getNewEditorPageControl() const { QTabWidget* EditorList::getNewEditorPageControl() const {
//todo: return widget depends on layout return getFocusedPageControl();
return mLeftPageWidget;
} }
QTabWidget* EditorList::getFocusedPageControl() const { QTabWidget* EditorList::getFocusedPageControl() const {
//todo: //todo:
switch(mLayout) {
case LayoutShowType::lstLeft:
return mLeftPageWidget; return mLeftPageWidget;
case LayoutShowType::lstRight:
return mRightPageWidget;
case LayoutShowType::lstBoth: {
Editor* editor = dynamic_cast<Editor*>(mRightPageWidget->currentWidget());
if (editor && editor->hasFocus())
return mRightPageWidget;
return mLeftPageWidget;
}
default:
return nullptr;
}
} }
void EditorList::showLayout(LayoutShowType layout) void EditorList::showLayout(LayoutShowType layout)
@ -55,7 +67,6 @@ void EditorList::showLayout(LayoutShowType layout)
// Apply widths if layout does not change // Apply widths if layout does not change
switch(mLayout) { switch(mLayout) {
case LayoutShowType::lstLeft: case LayoutShowType::lstLeft:
case LayoutShowType::lstNone:
mLeftPageWidget->setVisible(true); mLeftPageWidget->setVisible(true);
mRightPageWidget->setVisible(false); mRightPageWidget->setVisible(false);
break; break;
@ -71,16 +82,18 @@ void EditorList::showLayout(LayoutShowType layout)
Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const { Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const {
QTabWidget* selectedWidget; QTabWidget* selectedWidget;
if (tabsWidget == NULL) { if (tabsWidget == nullptr) {
selectedWidget = getFocusedPageControl(); // todo: get focused widget selectedWidget = getFocusedPageControl();
} else { } else {
selectedWidget = tabsWidget; selectedWidget = tabsWidget;
} }
if (!selectedWidget)
return nullptr;
if (index == -1) { if (index == -1) {
index = selectedWidget->currentIndex(); index = selectedWidget->currentIndex();
} }
if (index<0 || index >= selectedWidget->count()) { if (index<0 || index >= selectedWidget->count()) {
return NULL; return nullptr;
} }
return (Editor*)selectedWidget->widget(index); return (Editor*)selectedWidget->widget(index);
} }
@ -133,6 +146,25 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
return true; return true;
} }
bool EditorList::swapEditor(Editor *editor)
{
Q_ASSERT(editor!=nullptr);
beginUpdate();
auto action = finally([this](){
endUpdate();
});
//remember old index
QTabWidget* fromPageControl = editor->pageControl();
if (fromPageControl == mLeftPageWidget) {
editor->setPageControl(mRightPageWidget);
} else {
editor->setPageControl(mLeftPageWidget);
}
updateLayout();
editor->activate();
return true;
}
void EditorList::beginUpdate() { void EditorList::beginUpdate() {
if (mUpdateCount==0) { if (mUpdateCount==0) {
mPanel->setUpdatesEnabled(false); mPanel->setUpdatesEnabled(false);
@ -241,7 +273,6 @@ bool EditorList::closeAll(bool force) {
return false; return false;
} }
} }
return true; return true;
} }
@ -305,10 +336,6 @@ bool EditorList::getContentFromOpenedEditor(const QString &filename, QStringList
void EditorList::getVisibleEditors(Editor *&left, Editor *&right) void EditorList::getVisibleEditors(Editor *&left, Editor *&right)
{ {
switch(mLayout) { switch(mLayout) {
case LayoutShowType::lstNone:
left = nullptr;
right = nullptr;
break;
case LayoutShowType::lstLeft: case LayoutShowType::lstLeft:
left = getEditor(-1,mLeftPageWidget); left = getEditor(-1,mLeftPageWidget);
right = nullptr; right = nullptr;
@ -326,11 +353,9 @@ void EditorList::getVisibleEditors(Editor *&left, Editor *&right)
void EditorList::updateLayout() void EditorList::updateLayout()
{ {
if (mLeftPageWidget->count() ==0 && mRightPageWidget->count() == 0) if (mRightPageWidget->count() == 0)
showLayout(LayoutShowType::lstNone);
else if (mLeftPageWidget->count() > 0 && mRightPageWidget->count() == 0)
showLayout(LayoutShowType::lstLeft); showLayout(LayoutShowType::lstLeft);
else if (mLeftPageWidget->count() ==0 && mRightPageWidget->count() > 0) else if (mLeftPageWidget->count() ==0)
showLayout(LayoutShowType::lstRight); showLayout(LayoutShowType::lstRight);
else else
showLayout(LayoutShowType::lstBoth); showLayout(LayoutShowType::lstBoth);

View File

@ -11,7 +11,6 @@ class EditorList
{ {
public: public:
enum class LayoutShowType{ enum class LayoutShowType{
lstNone,
lstLeft, lstLeft,
lstRight, lstRight,
lstBoth lstBoth
@ -24,12 +23,14 @@ public:
Editor* newEditor(const QString& filename, const QByteArray& encoding, Editor* newEditor(const QString& filename, const QByteArray& encoding,
bool inProject, bool newFile, bool inProject, bool newFile,
QTabWidget* page=NULL); QTabWidget* page=nullptr);
Editor* getEditor(int index=-1, QTabWidget* tabsWidget=NULL) const; Editor* getEditor(int index=-1, QTabWidget* tabsWidget=nullptr) const;
bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false); bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false);
bool swapEditor(Editor* editor);
bool closeAll(bool force = false); bool closeAll(bool force = false);
void forceCloseEditor(Editor* editor); void forceCloseEditor(Editor* editor);

View File

@ -1654,14 +1654,14 @@ void MainWindow::buildContextMenus()
connect(ui->EditorTabsLeft->tabBar(), connect(ui->EditorTabsLeft->tabBar(),
&QWidget::customContextMenuRequested, &QWidget::customContextMenuRequested,
this, this,
&MainWindow::onEditorTabContextMenu &MainWindow::onEditorLeftTabContextMenu
); );
ui->EditorTabsRight->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); ui->EditorTabsRight->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsRight->tabBar(), connect(ui->EditorTabsRight->tabBar(),
&QWidget::customContextMenuRequested, &QWidget::customContextMenuRequested,
this, this,
&MainWindow::onEditorTabContextMenu &MainWindow::onEditorRightTabContextMenu
); );
//context menu signal for Compile Issue view //context menu signal for Compile Issue view
@ -2278,21 +2278,38 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
} }
void MainWindow::onEditorTabContextMenu(const QPoint &pos) void MainWindow::onEditorRightTabContextMenu(const QPoint &pos)
{ {
int index = ui->EditorTabsLeft->tabBar()->tabAt(pos); onEditorTabContextMenu(ui->EditorTabsRight,pos);
}
void MainWindow::onEditorLeftTabContextMenu(const QPoint &pos)
{
onEditorTabContextMenu(ui->EditorTabsLeft,pos);
}
void MainWindow::onEditorTabContextMenu(QTabWidget* tabWidget, const QPoint &pos)
{
int index = tabWidget->tabBar()->tabAt(pos);
if (index<0) if (index<0)
return; return;
ui->EditorTabsLeft->setCurrentIndex(index); tabWidget->setCurrentIndex(index);
QMenu menu(this); QMenu menu(this);
QTabBar* tabBar = ui->EditorTabsLeft->tabBar(); QTabBar* tabBar = tabWidget->tabBar();
menu.addAction(ui->actionClose); menu.addAction(ui->actionClose);
menu.addAction(ui->actionClose_All); menu.addAction(ui->actionClose_All);
menu.addSeparator(); menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder); menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal); menu.addAction(ui->actionOpen_Terminal);
menu.addSeparator(); menu.addSeparator();
menu.addAction(ui->actionMove_To_Other_View);
menu.addSeparator();
menu.addAction(ui->actionFile_Properties); menu.addAction(ui->actionFile_Properties);
ui->actionMove_To_Other_View->setEnabled(
tabWidget==ui->EditorTabsRight
|| tabWidget->count()>1
);
menu.exec(tabBar->mapToGlobal(pos)); menu.exec(tabBar->mapToGlobal(pos));
} }
@ -2529,6 +2546,12 @@ void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
mEditorList->closeEditor(editor); mEditorList->closeEditor(editor);
} }
void MainWindow::on_EditorTabsRight_tabCloseRequested(int index)
{
Editor* editor = mEditorList->getEditor(index,ui->EditorTabsRight);
mEditorList->closeEditor(editor);
}
void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionOpen_triggered()
{ {
try { try {
@ -3507,6 +3530,11 @@ void MainWindow::on_EditorTabsLeft_tabBarDoubleClicked(int index)
maximizeEditor(); maximizeEditor();
} }
void MainWindow::on_EditorTabsRight_tabBarDoubleClicked(int index)
{
maximizeEditor();
}
void MainWindow::on_actionClose_triggered() void MainWindow::on_actionClose_triggered()
{ {
@ -3979,7 +4007,7 @@ PSymbolUsageManager &MainWindow::symbolUsageManager()
void MainWindow::on_EditorTabsLeft_currentChanged(int index) void MainWindow::on_EditorTabsLeft_currentChanged(int index)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft);
if (editor) { if (editor) {
editor->reparseTodo(); editor->reparseTodo();
} }
@ -3988,7 +4016,7 @@ void MainWindow::on_EditorTabsLeft_currentChanged(int index)
void MainWindow::on_EditorTabsRight_currentChanged(int index) void MainWindow::on_EditorTabsRight_currentChanged(int index)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsRight);
if (editor) { if (editor) {
editor->reparseTodo(); editor->reparseTodo();
} }
@ -4215,3 +4243,12 @@ void MainWindow::on_actionExport_As_HTML_triggered()
} }
} }
void MainWindow::on_actionMove_To_Other_View_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor) {
mEditorList->swapEditor(editor);
}
}

View File

@ -155,7 +155,9 @@ public slots:
void onMemoryExamineReady(const QStringList& value); void onMemoryExamineReady(const QStringList& value);
void onLocalsReady(const QStringList& value); void onLocalsReady(const QStringList& value);
void onEditorContextMenu(const QPoint& pos); void onEditorContextMenu(const QPoint& pos);
void onEditorTabContextMenu(const QPoint& pos); void onEditorRightTabContextMenu(const QPoint& pos);
void onEditorLeftTabContextMenu(const QPoint& pos);
void onEditorTabContextMenu(QTabWidget* tabWidget, const QPoint& pos);
void disableDebugActions(); void disableDebugActions();
void enableDebugActions(); void enableDebugActions();
void onTodoParseStarted(); void onTodoParseStarted();
@ -203,6 +205,7 @@ private slots:
void on_actionNew_triggered(); void on_actionNew_triggered();
void on_EditorTabsLeft_tabCloseRequested(int index); void on_EditorTabsLeft_tabCloseRequested(int index);
void on_EditorTabsRight_tabCloseRequested(int index);
void on_actionOpen_triggered(); void on_actionOpen_triggered();
@ -315,6 +318,7 @@ private slots:
void on_splitterMessages_splitterMoved(int pos, int index); void on_splitterMessages_splitterMoved(int pos, int index);
void on_EditorTabsLeft_tabBarDoubleClicked(int index); void on_EditorTabsLeft_tabBarDoubleClicked(int index);
void on_EditorTabsRight_tabBarDoubleClicked(int index);
void on_actionClose_triggered(); void on_actionClose_triggered();
@ -377,7 +381,6 @@ private slots:
void on_classBrowser_doubleClicked(const QModelIndex &index); void on_classBrowser_doubleClicked(const QModelIndex &index);
void on_EditorTabsLeft_currentChanged(int index); void on_EditorTabsLeft_currentChanged(int index);
void on_EditorTabsRight_currentChanged(int index); void on_EditorTabsRight_currentChanged(int index);
void on_tableTODO_doubleClicked(const QModelIndex &index); void on_tableTODO_doubleClicked(const QModelIndex &index);
@ -396,6 +399,8 @@ private slots:
void on_actionExport_As_HTML_triggered(); void on_actionExport_As_HTML_triggered();
void on_actionMove_To_Other_View_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -1832,6 +1832,14 @@
<string>Export As HTML</string> <string>Export As HTML</string>
</property> </property>
</action> </action>
<action name="actionMove_To_Other_View">
<property name="text">
<string>Move To Other View</string>
</property>
<property name="shortcut">
<string>Ctrl+M</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -670,6 +670,8 @@ void SynEditTextPainter::PaintFoldAttributes()
LastNonBlank = vLine - 1; LastNonBlank = vLine - 1;
while (LastNonBlank + 1 < edit->mLines->count() && edit->mLines->getString(LastNonBlank).isEmpty()) while (LastNonBlank + 1 < edit->mLines->count() && edit->mLines->getString(LastNonBlank).isEmpty())
LastNonBlank++; LastNonBlank++;
if (LastNonBlank>=edit->lines()->count())
continue;
LineIndent = edit->getLineIndent(edit->mLines->getString(LastNonBlank)); LineIndent = edit->getLineIndent(edit->mLines->getString(LastNonBlank));
int braceLevel = edit->mLines->ranges(LastNonBlank).braceLevel; int braceLevel = edit->mLines->ranges(LastNonBlank).braceLevel;
int indentLevel = braceLevel ; int indentLevel = braceLevel ;

View File

@ -3,7 +3,7 @@
#include <QStringList> #include <QStringList>
#define DEVCPP_VERSION "0.6.5" #define DEVCPP_VERSION "0.6.6"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define APP_SETTSINGS_FILENAME "redpandacpp.ini" #define APP_SETTSINGS_FILENAME "redpandacpp.ini"