* new changes
This commit is contained in:
parent
783c6ea2d8
commit
c5a3c820c5
Binary file not shown.
|
@ -95,7 +95,7 @@ void Editor::saveFile(const QString &filename) {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Editor::save() {
|
bool Editor::save(bool force, bool reparse) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,10 @@ public:
|
||||||
|
|
||||||
void loadFile();
|
void loadFile();
|
||||||
void saveFile(const QString& filename);
|
void saveFile(const QString& filename);
|
||||||
bool save();
|
bool save(bool force=false, bool reparse=true);
|
||||||
|
|
||||||
QsciScintilla* textEdit();
|
QsciScintilla* textEdit();
|
||||||
|
QTabWidget* pageControl();
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
#include "editorlist.h"
|
#include "editorlist.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <mainwindow.h>
|
||||||
|
#include <iconv.h>
|
||||||
|
|
||||||
|
EditorList::UpdateLocker::UpdateLocker(EditorList* editorList): mEditorList(editorList){
|
||||||
|
mEditorList->beginUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorList::UpdateLocker::~UpdateLocker() {
|
||||||
|
mEditorList->endUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
EditorList::EditorList(QTabWidget* leftPageWidget,
|
EditorList::EditorList(QTabWidget* leftPageWidget,
|
||||||
QTabWidget* rightPageWidget,
|
QTabWidget* rightPageWidget,
|
||||||
QSplitter* splitter,
|
QSplitter* splitter,
|
||||||
|
@ -27,30 +39,77 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin
|
||||||
//UpdateLayout;
|
//UpdateLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabWidget* EditorList::getNewEditorPageControl() {
|
QTabWidget* EditorList::getNewEditorPageControl() const {
|
||||||
//todo: return widget depends on layout
|
//todo: return widget depends on layout
|
||||||
return mLeftPageWidget;
|
return mLeftPageWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTabWidget* EditorList::getFocusedPageControl() const {
|
||||||
|
//todo:
|
||||||
|
return mLeftPageWidget;
|
||||||
|
}
|
||||||
|
|
||||||
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 == NULL) {
|
||||||
selectedWidget = mLeftPageWidget; // todo: get focused widget
|
selectedWidget = getFocusedPageControl(); // todo: get focused widget
|
||||||
} else {
|
} else {
|
||||||
selectedWidget = tabsWidget;
|
selectedWidget = tabsWidget;
|
||||||
}
|
}
|
||||||
QWidget* textEdit;
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
textEdit = selectedWidget->currentWidget();
|
index = selectedWidget->currentIndex();
|
||||||
} else {
|
|
||||||
textEdit =selectedWidget->widget(index);
|
|
||||||
}
|
}
|
||||||
|
if (index<0 || index >= selectedWidget->count()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
QWidget* textEdit = selectedWidget->widget(index);
|
||||||
QVariant pop = textEdit->property("editor");
|
QVariant pop = textEdit->property("editor");
|
||||||
Editor *editor = (Editor*)pop.value<intptr_t>();
|
Editor *editor = (Editor*)pop.value<intptr_t>();
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
|
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
|
||||||
|
UpdateLocker locker(this); // use RAII to correctly pause/resume update of the panel widget
|
||||||
|
if (editor == NULL)
|
||||||
|
return false;
|
||||||
|
if (force) {
|
||||||
|
editor->save(true,false);
|
||||||
|
} else if ( (editor->textEdit()->isModified()) && (!editor->textEdit()->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?"),
|
||||||
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
|
||||||
|
if (reply == QMessageBox::Cancel) {
|
||||||
|
return false;
|
||||||
|
} else if (reply == QMessageBox::Yes) {
|
||||||
|
if (!editor->save(false,false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transferFocus && editor-)
|
||||||
|
|
||||||
delete editor;
|
delete editor;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorList::beginUpdate() {
|
||||||
|
if (mUpdateCount==0) {
|
||||||
|
mPanel->setUpdatesEnabled(false);
|
||||||
|
}
|
||||||
|
mUpdateCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorList::endUpdate() {
|
||||||
|
mUpdateCount--;
|
||||||
|
if (mUpdateCount==0) {
|
||||||
|
mPanel->setUpdatesEnabled(true);
|
||||||
|
mPanel->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorList::closeAll(bool force) {
|
||||||
|
UpdateLocker locker(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,14 @@ public:
|
||||||
lstBoth
|
lstBoth
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UpdateLocker {
|
||||||
|
public:
|
||||||
|
UpdateLocker(EditorList* editorList);
|
||||||
|
~UpdateLocker();
|
||||||
|
private:
|
||||||
|
EditorList* mEditorList;
|
||||||
|
};
|
||||||
|
|
||||||
explicit EditorList(QTabWidget* leftPageWidget,
|
explicit EditorList(QTabWidget* leftPageWidget,
|
||||||
QTabWidget* rightPageWidget,
|
QTabWidget* rightPageWidget,
|
||||||
QSplitter* splitter,
|
QSplitter* splitter,
|
||||||
|
@ -30,8 +38,14 @@ public:
|
||||||
|
|
||||||
bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false);
|
bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false);
|
||||||
|
|
||||||
|
bool closeAll(bool force = false);
|
||||||
|
|
||||||
|
void beginUpdate();
|
||||||
|
void endUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget* getNewEditorPageControl();
|
QTabWidget* getNewEditorPageControl() const;
|
||||||
|
QTabWidget* getFocusedPageControl() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -47,7 +47,6 @@ void MainWindow::setupActions() {
|
||||||
void MainWindow::on_actionNew_triggered()
|
void MainWindow::on_actionNew_triggered()
|
||||||
{
|
{
|
||||||
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
|
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
|
||||||
editor->textEdit()->setFocus();
|
|
||||||
updateStatusBarForEncoding();
|
updateStatusBarForEncoding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue