* can close now
This commit is contained in:
parent
a42654dea8
commit
950aaadc73
|
@ -1,6 +1,7 @@
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QVariant>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -31,7 +32,12 @@ Editor::Editor(QObject *parent, const QString& filename,
|
||||||
else
|
else
|
||||||
mFileEncoding = mEncodingType;
|
mFileEncoding = mEncodingType;
|
||||||
}
|
}
|
||||||
|
mTextEdit->setProperty("editor",QVariant::fromValue<intptr_t>((intptr_t)this));
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor::~Editor() {
|
||||||
|
int index = mParentPageControl->indexOf(mTextEdit);
|
||||||
|
mParentPageControl->removeTab(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::loadFile() {
|
void Editor::loadFile() {
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
bool inProject, bool isNew,
|
bool inProject, bool isNew,
|
||||||
QTabWidget* parentPageControl);
|
QTabWidget* parentPageControl);
|
||||||
|
|
||||||
|
~Editor();
|
||||||
|
|
||||||
FileEncodingType encodingType() const;
|
FileEncodingType encodingType() const;
|
||||||
void setFileEncodingType(FileEncodingType type);
|
void setFileEncodingType(FileEncodingType type);
|
||||||
FileEncodingType fileEncoding() const;
|
FileEncodingType fileEncoding() const;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "editorlist.h"
|
#include "editorlist.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
EditorList::EditorList(QTabWidget* leftPageWidget,
|
EditorList::EditorList(QTabWidget* leftPageWidget,
|
||||||
QTabWidget* rightPageWidget,
|
QTabWidget* rightPageWidget,
|
||||||
|
@ -31,3 +32,25 @@ QTabWidget* EditorList::GetNewEditorPageControl() {
|
||||||
return mLeftPageWidget;
|
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<intptr_t>();
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorList::CloseEditor(Editor* editor, bool transferFocus, bool force) {
|
||||||
|
delete editor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ public:
|
||||||
bool inProject, bool newFile,
|
bool inProject, bool newFile,
|
||||||
QTabWidget* page=NULL);
|
QTabWidget* page=NULL);
|
||||||
|
|
||||||
|
Editor* GetEditor(int index=-1, QTabWidget* tabsWidget=NULL) const;
|
||||||
|
|
||||||
|
bool CloseEditor(Editor* editor, bool transferFocus=true, bool force=false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget* GetNewEditorPageControl();
|
QTabWidget* GetNewEditorPageControl();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->EditorPanelSplitter,
|
ui->EditorPanelSplitter,
|
||||||
ui->EditorPanel);
|
ui->EditorPanel);
|
||||||
setupActions();
|
setupActions();
|
||||||
|
ui->EditorTabsRight->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -28,3 +29,9 @@ void MainWindow::on_actionNew_triggered()
|
||||||
{
|
{
|
||||||
mEditorList->NewEditor("",etAuto,false,true);
|
mEditorList->NewEditor("",etAuto,false,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
|
||||||
|
{
|
||||||
|
Editor* editor = mEditorList->GetEditor(index,ui->EditorTabsLeft);
|
||||||
|
mEditorList->CloseEditor(editor);
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionNew_triggered();
|
void on_actionNew_triggered();
|
||||||
|
|
||||||
|
void on_EditorTabsLeft_tabCloseRequested(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupActions();
|
void setupActions();
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,18 @@
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QSplitter" name="splitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -28,6 +40,18 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter_2">
|
<widget class="QSplitter" name="splitter_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -62,6 +86,21 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="EditorPanelSplitter">
|
<widget class="QSplitter" name="EditorPanelSplitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -71,8 +110,18 @@
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>-1</number>
|
<number>-1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tabsClosable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QTabWidget" name="EditorTabsRight">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="tabsClosable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QTabWidget" name="EditorTabsRight"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
Loading…
Reference in New Issue