diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index b95fa59f..28cd3dec 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1,6 +1,7 @@ #include "editor.h" #include +#include #include using namespace std; @@ -31,7 +32,12 @@ Editor::Editor(QObject *parent, const QString& filename, else mFileEncoding = mEncodingType; } + mTextEdit->setProperty("editor",QVariant::fromValue((intptr_t)this)); +} +Editor::~Editor() { + int index = mParentPageControl->indexOf(mTextEdit); + mParentPageControl->removeTab(index); } void Editor::loadFile() { diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 07e8baa3..9e10aa58 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -15,6 +15,8 @@ public: bool inProject, bool isNew, QTabWidget* parentPageControl); + ~Editor(); + FileEncodingType encodingType() const; void setFileEncodingType(FileEncodingType type); FileEncodingType fileEncoding() const; diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 4ba8ef78..55d26dfa 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -1,5 +1,6 @@ #include "editorlist.h" #include "editor.h" +#include EditorList::EditorList(QTabWidget* leftPageWidget, QTabWidget* rightPageWidget, @@ -31,3 +32,25 @@ QTabWidget* EditorList::GetNewEditorPageControl() { return mLeftPageWidget; } +Editor* EditorList::GetEditor(int index, QTabWidget* tabsWidget) const { + QTabWidget* selectedWidget; + if (tabsWidget == NULL) { + selectedWidget = mLeftPageWidget; // todo: get focused widget + } else { + selectedWidget = tabsWidget; + } + QWidget* textEdit; + if (index == -1) { + textEdit = selectedWidget->currentWidget(); + } else { + textEdit =selectedWidget->widget(index); + } + QVariant pop = textEdit->property("editor"); + Editor *editor = (Editor*)pop.value(); + return editor; +} + +bool EditorList::CloseEditor(Editor* editor, bool transferFocus, bool force) { + delete editor; + return true; +} diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index 361f1506..45f5eaad 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -26,6 +26,10 @@ public: bool inProject, bool newFile, QTabWidget* page=NULL); + Editor* GetEditor(int index=-1, QTabWidget* tabsWidget=NULL) const; + + bool CloseEditor(Editor* editor, bool transferFocus=true, bool force=false); + private: QTabWidget* GetNewEditorPageControl(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index dd276798..89bc5fbd 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent) ui->EditorPanelSplitter, ui->EditorPanel); setupActions(); + ui->EditorTabsRight->setVisible(false); } MainWindow::~MainWindow() @@ -28,3 +29,9 @@ void MainWindow::on_actionNew_triggered() { mEditorList->NewEditor("",etAuto,false,true); } + +void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index) +{ + Editor* editor = mEditorList->GetEditor(index,ui->EditorTabsLeft); + mEditorList->CloseEditor(editor); +} diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 88000c78..edb5fa59 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -20,6 +20,8 @@ public: private slots: void on_actionNew_triggered(); + void on_EditorTabsLeft_tabCloseRequested(int index); + private: void setupActions(); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 712e901c..6a581784 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -15,6 +15,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -28,6 +40,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -62,6 +86,21 @@ + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -71,8 +110,18 @@ -1 + + true + + + + + true + + + true + -