forked from qt-creator/qt-creator
make ctrl-tab navigation view specific
This commit is contained in:
@@ -133,10 +133,6 @@ EditorManagerPlaceHolder* EditorManagerPlaceHolder::current()
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
//struct EditorHistoryItem {
|
|
||||||
// IFile *file;
|
|
||||||
// QPointer<Internal::EditorView> view;
|
|
||||||
//};
|
|
||||||
|
|
||||||
struct EditorManagerPrivate {
|
struct EditorManagerPrivate {
|
||||||
explicit EditorManagerPrivate(ICore *core, QWidget *parent);
|
explicit EditorManagerPrivate(ICore *core, QWidget *parent);
|
||||||
@@ -167,8 +163,6 @@ struct EditorManagerPrivate {
|
|||||||
QAction *m_removeAllSplitsAction;
|
QAction *m_removeAllSplitsAction;
|
||||||
QAction *m_gotoOtherSplitAction;
|
QAction *m_gotoOtherSplitAction;
|
||||||
|
|
||||||
QList<IEditor *> m_editorHistory;
|
|
||||||
|
|
||||||
Internal::OpenEditorsWindow *m_windowPopup;
|
Internal::OpenEditorsWindow *m_windowPopup;
|
||||||
Core::BaseView *m_openEditorsView;
|
Core::BaseView *m_openEditorsView;
|
||||||
Internal::EditorClosingCoreListener *m_coreListener;
|
Internal::EditorClosingCoreListener *m_coreListener;
|
||||||
@@ -196,8 +190,8 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
|
|||||||
m_closeCurrentEditorAction(new QAction(EditorManager::tr("Close"), parent)),
|
m_closeCurrentEditorAction(new QAction(EditorManager::tr("Close"), parent)),
|
||||||
m_closeAllEditorsAction(new QAction(EditorManager::tr("Close All"), parent)),
|
m_closeAllEditorsAction(new QAction(EditorManager::tr("Close All"), parent)),
|
||||||
m_closeOtherEditorsAction(new QAction(EditorManager::tr("Close Others"), parent)),
|
m_closeOtherEditorsAction(new QAction(EditorManager::tr("Close Others"), parent)),
|
||||||
m_gotoNextDocHistoryAction(new QAction(EditorManager::tr("Next Document in History"), parent)),
|
m_gotoNextDocHistoryAction(new QAction(EditorManager::tr("Next Open Document in History"), parent)),
|
||||||
m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Document in History"), parent)),
|
m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Open Document in History"), parent)),
|
||||||
m_goBackAction(new QAction(QIcon(QLatin1String(":/help/images/previous.png")), EditorManager::tr("Go Back"), parent)),
|
m_goBackAction(new QAction(QIcon(QLatin1String(":/help/images/previous.png")), EditorManager::tr("Go Back"), parent)),
|
||||||
m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)),
|
m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)),
|
||||||
m_openInExternalEditorAction(new QAction(EditorManager::tr("Open in External Editor"), parent)),
|
m_openInExternalEditorAction(new QAction(EditorManager::tr("Open in External Editor"), parent)),
|
||||||
@@ -455,15 +449,6 @@ QString EditorManager::defaultExternalEditor() const
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::updateEditorHistory()
|
|
||||||
{
|
|
||||||
IEditor *editor = currentEditor();
|
|
||||||
if (!editor)
|
|
||||||
return;
|
|
||||||
m_d->m_editorHistory.removeAll(editor);
|
|
||||||
m_d->m_editorHistory.prepend(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorManager::removeEditor(IEditor *editor)
|
void EditorManager::removeEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
bool isDuplicate = m_d->m_editorModel->isDuplicate(editor);
|
bool isDuplicate = m_d->m_editorModel->isDuplicate(editor);
|
||||||
@@ -471,9 +456,7 @@ void EditorManager::removeEditor(IEditor *editor)
|
|||||||
if (!isDuplicate) {
|
if (!isDuplicate) {
|
||||||
m_d->m_core->fileManager()->removeFile(editor->file());
|
m_d->m_core->fileManager()->removeFile(editor->file());
|
||||||
}
|
}
|
||||||
m_d->m_editorHistory.removeAll(editor);
|
|
||||||
m_d->m_core->removeContextObject(editor);
|
m_d->m_core->removeContextObject(editor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::handleContextChange(Core::IContext *context)
|
void EditorManager::handleContextChange(Core::IContext *context)
|
||||||
@@ -502,9 +485,9 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto
|
|||||||
if (editor) {
|
if (editor) {
|
||||||
if (SplitterOrView *splitterOrView = m_d->m_splitter->findView(editor))
|
if (SplitterOrView *splitterOrView = m_d->m_splitter->findView(editor))
|
||||||
splitterOrView->view()->setCurrentEditor(editor);
|
splitterOrView->view()->setCurrentEditor(editor);
|
||||||
|
m_d->m_view->updateEditorHistory(editor); // the global view should have a complete history
|
||||||
}
|
}
|
||||||
updateActions();
|
updateActions();
|
||||||
updateEditorHistory();
|
|
||||||
emit currentEditorChanged(editor);
|
emit currentEditorChanged(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,6 +516,8 @@ Core::Internal::SplitterOrView *EditorManager::currentView() const
|
|||||||
view = m_d->m_currentEditor?
|
view = m_d->m_currentEditor?
|
||||||
m_d->m_splitter->findView(m_d->m_currentEditor):
|
m_d->m_splitter->findView(m_d->m_currentEditor):
|
||||||
m_d->m_splitter->findFirstView();
|
m_d->m_splitter->findFirstView();
|
||||||
|
if (!view)
|
||||||
|
return m_d->m_splitter;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,7 +601,6 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
|
|||||||
else
|
else
|
||||||
setCurrentView(newCurrent);
|
setCurrentView(newCurrent);
|
||||||
}
|
}
|
||||||
updateEditorHistory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor*>
|
QList<IEditor*>
|
||||||
@@ -840,7 +824,7 @@ void EditorManager::closeDuplicate(Core::IEditor *editor)
|
|||||||
|
|
||||||
Core::IEditor *EditorManager::pickUnusedEditor() const
|
Core::IEditor *EditorManager::pickUnusedEditor() const
|
||||||
{
|
{
|
||||||
foreach (IEditor *editor, m_d->m_editorHistory) {
|
foreach (IEditor *editor, openedEditors()) {
|
||||||
SplitterOrView *view = m_d->m_splitter->findView(editor);
|
SplitterOrView *view = m_d->m_splitter->findView(editor);
|
||||||
if (!view || view->editor() != editor)
|
if (!view || view->editor() != editor)
|
||||||
return editor;
|
return editor;
|
||||||
@@ -848,7 +832,6 @@ Core::IEditor *EditorManager::pickUnusedEditor() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Core::IEditor *EditorManager::activateEditor(const QModelIndex &index, Internal::EditorView *view, OpenEditorFlags flags)
|
Core::IEditor *EditorManager::activateEditor(const QModelIndex &index, Internal::EditorView *view, OpenEditorFlags flags)
|
||||||
{
|
{
|
||||||
IEditor *editor = index.data(Qt::UserRole).value<IEditor*>();
|
IEditor *editor = index.data(Qt::UserRole).value<IEditor*>();
|
||||||
@@ -863,7 +846,11 @@ Core::IEditor *EditorManager::activateEditor(const QModelIndex &index, Internal:
|
|||||||
|
|
||||||
Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core::IEditor *editor)
|
Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
Q_ASSERT(view && editor) ;
|
Q_ASSERT(view && editor);
|
||||||
|
|
||||||
|
if (view->currentEditor() && view->currentEditor()->file() == editor->file())
|
||||||
|
editor = view->currentEditor();
|
||||||
|
|
||||||
if (!view->hasEditor(editor)) {
|
if (!view->hasEditor(editor)) {
|
||||||
bool duplicateSupported = editor->duplicateSupported();
|
bool duplicateSupported = editor->duplicateSupported();
|
||||||
if (SplitterOrView *sourceView = m_d->m_splitter->findView(editor)) {
|
if (SplitterOrView *sourceView = m_d->m_splitter->findView(editor)) {
|
||||||
@@ -1043,10 +1030,6 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
|
|||||||
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
|
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_d->m_editorHistory.removeAll(editor);
|
|
||||||
m_d->m_editorHistory.prepend(editor);
|
|
||||||
|
|
||||||
emit editorOpened(editor);
|
emit editorOpened(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1142,7 +1125,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
|
|||||||
|
|
||||||
const QList<IEditor *> editors = editorsForFileName(fileName);
|
const QList<IEditor *> editors = editorsForFileName(fileName);
|
||||||
if (!editors.isEmpty()) {
|
if (!editors.isEmpty()) {
|
||||||
return activateEditor(editors.first(), flags);
|
return activateEditor(view, editors.first(), flags);
|
||||||
}
|
}
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
IEditor *editor = createEditor(editorKind, fileName);
|
IEditor *editor = createEditor(editorKind, fileName);
|
||||||
@@ -1422,7 +1405,8 @@ void EditorManager::gotoNextDocHistory()
|
|||||||
if (dialog->isVisible()) {
|
if (dialog->isVisible()) {
|
||||||
dialog->selectNextEditor();
|
dialog->selectNextEditor();
|
||||||
} else {
|
} else {
|
||||||
dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor, m_d->m_editorModel);
|
EditorView *view = currentView()->view();
|
||||||
|
dialog->setEditors(m_d->m_view, view, m_d->m_editorModel);
|
||||||
dialog->selectNextEditor();
|
dialog->selectNextEditor();
|
||||||
showWindowPopup();
|
showWindowPopup();
|
||||||
}
|
}
|
||||||
@@ -1434,7 +1418,8 @@ void EditorManager::gotoPreviousDocHistory()
|
|||||||
if (dialog->isVisible()) {
|
if (dialog->isVisible()) {
|
||||||
dialog->selectPreviousEditor();
|
dialog->selectPreviousEditor();
|
||||||
} else {
|
} else {
|
||||||
dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor, m_d->m_editorModel);
|
EditorView *view = currentView()->view();
|
||||||
|
dialog->setEditors(m_d->m_view, view, m_d->m_editorModel);
|
||||||
dialog->selectPreviousEditor();
|
dialog->selectPreviousEditor();
|
||||||
showWindowPopup();
|
showWindowPopup();
|
||||||
}
|
}
|
||||||
@@ -1489,8 +1474,8 @@ void EditorManager::updateActions()
|
|||||||
m_d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
|
m_d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
|
||||||
m_d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others")));
|
m_d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others")));
|
||||||
|
|
||||||
m_d->m_gotoNextDocHistoryAction->setEnabled(m_d->m_editorHistory.count() > 0);
|
m_d->m_gotoNextDocHistoryAction->setEnabled(m_d->m_editorModel->rowCount() != 0);
|
||||||
m_d->m_gotoPreviousDocHistoryAction->setEnabled(m_d->m_editorHistory.count() > 0);
|
m_d->m_gotoPreviousDocHistoryAction->setEnabled(m_d->m_editorModel->rowCount() != 0);
|
||||||
EditorView *view = currentEditorView();
|
EditorView *view = currentEditorView();
|
||||||
m_d->m_goBackAction->setEnabled(view->canGoBack());
|
m_d->m_goBackAction->setEnabled(view->canGoBack());
|
||||||
m_d->m_goForwardAction->setEnabled(view->canGoForward());
|
m_d->m_goForwardAction->setEnabled(view->canGoForward());
|
||||||
@@ -1513,11 +1498,6 @@ OpenEditorsModel *EditorManager::openedEditorsModel() const
|
|||||||
return m_d->m_editorModel;
|
return m_d->m_editorModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor*> EditorManager::editorHistory() const
|
|
||||||
{
|
|
||||||
return m_d->m_editorHistory;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
|
void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
|
||||||
{
|
{
|
||||||
currentView()->view()->addCurrentPositionToNavigationHistory(editor, saveState);
|
currentView()->view()->addCurrentPositionToNavigationHistory(editor, saveState);
|
||||||
@@ -1874,7 +1854,6 @@ void EditorManager::split(Qt::Orientation orientation)
|
|||||||
: m_d->m_splitter->findFirstView();
|
: m_d->m_splitter->findFirstView();
|
||||||
if (view && !view->splitter()) {
|
if (view && !view->splitter()) {
|
||||||
view->split(orientation);
|
view->split(orientation);
|
||||||
updateEditorHistory();
|
|
||||||
}
|
}
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
|
#include <QtCore/QPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QSettings;
|
class QSettings;
|
||||||
@@ -72,6 +73,8 @@ class SplitterOrView;
|
|||||||
|
|
||||||
class EditorClosingCoreListener;
|
class EditorClosingCoreListener;
|
||||||
class OpenEditorsViewFactory;
|
class OpenEditorsViewFactory;
|
||||||
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
|
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
|
||||||
@@ -126,17 +129,17 @@ public:
|
|||||||
|
|
||||||
IEditor *currentEditor() const;
|
IEditor *currentEditor() const;
|
||||||
IEditor *activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
|
IEditor *activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
|
||||||
|
IEditor *activateEditor(const QModelIndex &index, Internal::EditorView *view = 0, OpenEditorFlags = 0);
|
||||||
|
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
|
||||||
|
|
||||||
QList<IEditor*> openedEditors() const;
|
QList<IEditor*> openedEditors() const;
|
||||||
|
|
||||||
OpenEditorsModel *openedEditorsModel() const;
|
OpenEditorsModel *openedEditorsModel() const;
|
||||||
IEditor *activateEditor(const QModelIndex &index, Internal::EditorView *view = 0, OpenEditorFlags = 0);
|
|
||||||
void closeEditor(const QModelIndex &index);
|
void closeEditor(const QModelIndex &index);
|
||||||
void closeOtherEditors(IEditor *editor);
|
void closeOtherEditors(IEditor *editor);
|
||||||
|
|
||||||
QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
|
QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
|
||||||
//QList<EditorGroup *> editorGroups() const;
|
//QList<EditorGroup *> editorGroups() const;
|
||||||
QList<IEditor*> editorHistory() const;
|
|
||||||
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
||||||
|
|
||||||
bool saveEditor(IEditor *editor);
|
bool saveEditor(IEditor *editor);
|
||||||
@@ -210,7 +213,6 @@ private slots:
|
|||||||
void gotoNextDocHistory();
|
void gotoNextDocHistory();
|
||||||
void gotoPreviousDocHistory();
|
void gotoPreviousDocHistory();
|
||||||
void handleContextChange(Core::IContext *context);
|
void handleContextChange(Core::IContext *context);
|
||||||
void updateEditorHistory();
|
|
||||||
void updateActions();
|
void updateActions();
|
||||||
void revertToSaved();
|
void revertToSaved();
|
||||||
void makeCurrentEditorWritable();
|
void makeCurrentEditorWritable();
|
||||||
@@ -239,11 +241,11 @@ private:
|
|||||||
void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
|
void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
|
||||||
void setCurrentView(Core::Internal::SplitterOrView *view);
|
void setCurrentView(Core::Internal::SplitterOrView *view);
|
||||||
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
|
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
|
||||||
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
|
|
||||||
IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
|
IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
|
||||||
const QString &editorKind = QString(),
|
const QString &editorKind = QString(),
|
||||||
OpenEditorFlags flags = 0);
|
OpenEditorFlags flags = 0);
|
||||||
Core::Internal::SplitterOrView *currentView() const;
|
Core::Internal::SplitterOrView *currentView() const;
|
||||||
|
|
||||||
void closeEditor(Core::IEditor *editor);
|
void closeEditor(Core::IEditor *editor);
|
||||||
void closeDuplicate(Core::IEditor *editor);
|
void closeDuplicate(Core::IEditor *editor);
|
||||||
void closeView(Core::Internal::EditorView *view);
|
void closeView(Core::Internal::EditorView *view);
|
||||||
|
|||||||
@@ -323,6 +323,7 @@ void EditorView::setCurrentEditor(IEditor *editor)
|
|||||||
m_editorList->setCurrentIndex(m_model->indexOf(editor).row());
|
m_editorList->setCurrentIndex(m_model->indexOf(editor).row());
|
||||||
updateEditorStatus(editor);
|
updateEditorStatus(editor);
|
||||||
updateToolBar(editor);
|
updateToolBar(editor);
|
||||||
|
updateEditorHistory(editor);
|
||||||
|
|
||||||
// FIXME: this keeps the editor hidden if switching from A to B and back
|
// FIXME: this keeps the editor hidden if switching from A to B and back
|
||||||
if (editor != m_editorForInfoWidget) {
|
if (editor != m_editorForInfoWidget) {
|
||||||
@@ -413,6 +414,35 @@ void EditorView::listContextMenu(QPoint pos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorView::updateEditorHistory(IEditor *editor)
|
||||||
|
{
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
IFile *file = editor->file();
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString fileName = file->fileName();
|
||||||
|
QByteArray state = editor->saveState();
|
||||||
|
|
||||||
|
EditLocation location;
|
||||||
|
location.file = file;
|
||||||
|
location.fileName = file->fileName();
|
||||||
|
location.kind = editor->kind();
|
||||||
|
location.state = QVariant(state);
|
||||||
|
|
||||||
|
for(int i = 0; i < m_editorHistory.size(); ++i) {
|
||||||
|
if (m_editorHistory.at(i).file == 0
|
||||||
|
|| m_editorHistory.at(i).file == file
|
||||||
|
){
|
||||||
|
m_editorHistory.removeAt(i--);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_editorHistory.prepend(location);
|
||||||
|
}
|
||||||
|
|
||||||
void EditorView::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
|
void EditorView::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
|
||||||
{
|
{
|
||||||
if (editor && editor != currentEditor()) {
|
if (editor && editor != currentEditor()) {
|
||||||
@@ -436,29 +466,32 @@ void EditorView::addCurrentPositionToNavigationHistory(IEditor *editor, const QB
|
|||||||
state = saveState;
|
state = saveState;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditLocation *location = new EditLocation;
|
EditLocation location;
|
||||||
location->file = file;
|
location.file = file;
|
||||||
location->fileName = file->fileName();
|
location.fileName = file->fileName();
|
||||||
location->kind = editor->kind();
|
location.kind = editor->kind();
|
||||||
location->state = QVariant(state);
|
location.state = QVariant(state);
|
||||||
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
|
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
|
||||||
m_navigationHistory.insert(m_currentNavigationHistoryPosition, location);
|
m_navigationHistory.insert(m_currentNavigationHistoryPosition, location);
|
||||||
++m_currentNavigationHistoryPosition;
|
++m_currentNavigationHistoryPosition;
|
||||||
|
|
||||||
while (m_navigationHistory.size() >= 30) {
|
while (m_navigationHistory.size() >= 30) {
|
||||||
if (m_currentNavigationHistoryPosition > 15) {
|
if (m_currentNavigationHistoryPosition > 15) {
|
||||||
delete m_navigationHistory.takeFirst();
|
m_navigationHistory.takeFirst();
|
||||||
--m_currentNavigationHistoryPosition;
|
--m_currentNavigationHistoryPosition;
|
||||||
} else {
|
} else {
|
||||||
delete m_navigationHistory.takeLast();
|
m_navigationHistory.takeLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorView::copyNavigationHistoryFrom(EditorView* other)
|
void EditorView::copyNavigationHistoryFrom(EditorView* other)
|
||||||
{
|
{
|
||||||
|
if (!other)
|
||||||
|
return;
|
||||||
m_currentNavigationHistoryPosition = other->m_currentNavigationHistoryPosition;
|
m_currentNavigationHistoryPosition = other->m_currentNavigationHistoryPosition;
|
||||||
m_navigationHistory = other->m_navigationHistory;
|
m_navigationHistory = other->m_navigationHistory;
|
||||||
|
m_editorHistory = other->m_editorHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorView::updateCurrentPositionInNavigationHistory()
|
void EditorView::updateCurrentPositionInNavigationHistory()
|
||||||
@@ -470,10 +503,10 @@ void EditorView::updateCurrentPositionInNavigationHistory()
|
|||||||
IFile *file = editor->file();
|
IFile *file = editor->file();
|
||||||
EditLocation *location;
|
EditLocation *location;
|
||||||
if (m_currentNavigationHistoryPosition < m_navigationHistory.size()) {
|
if (m_currentNavigationHistoryPosition < m_navigationHistory.size()) {
|
||||||
location = m_navigationHistory[m_currentNavigationHistoryPosition];
|
location = &m_navigationHistory[m_currentNavigationHistoryPosition];
|
||||||
} else {
|
} else {
|
||||||
location = new EditLocation;
|
m_navigationHistory.append(EditLocation());
|
||||||
m_navigationHistory.append(location);
|
location = &m_navigationHistory[m_navigationHistory.size()-1];
|
||||||
}
|
}
|
||||||
location->file = file;
|
location->file = file;
|
||||||
location->fileName = file->fileName();
|
location->fileName = file->fileName();
|
||||||
@@ -487,18 +520,18 @@ void EditorView::goBackInNavigationHistory()
|
|||||||
updateCurrentPositionInNavigationHistory();
|
updateCurrentPositionInNavigationHistory();
|
||||||
while (m_currentNavigationHistoryPosition > 0) {
|
while (m_currentNavigationHistoryPosition > 0) {
|
||||||
--m_currentNavigationHistoryPosition;
|
--m_currentNavigationHistoryPosition;
|
||||||
EditLocation *location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
|
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
|
||||||
IEditor *editor;
|
IEditor *editor;
|
||||||
if (location->file) {
|
if (location.file) {
|
||||||
editor = em->activateEditor(this, location->file, EditorManager::IgnoreNavigationHistory);
|
editor = em->activateEditor(this, location.file, EditorManager::IgnoreNavigationHistory);
|
||||||
} else {
|
} else {
|
||||||
editor = em->openEditor(this, location->fileName, location->kind, EditorManager::IgnoreNavigationHistory);
|
editor = em->openEditor(this, location.fileName, location.kind, EditorManager::IgnoreNavigationHistory);
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
delete m_navigationHistory.takeAt(m_currentNavigationHistoryPosition);
|
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor->restoreState(location->state.toByteArray());
|
editor->restoreState(location.state.toByteArray());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,19 +543,19 @@ void EditorView::goForwardInNavigationHistory()
|
|||||||
if (m_currentNavigationHistoryPosition >= m_navigationHistory.size()-1)
|
if (m_currentNavigationHistoryPosition >= m_navigationHistory.size()-1)
|
||||||
return;
|
return;
|
||||||
++m_currentNavigationHistoryPosition;
|
++m_currentNavigationHistoryPosition;
|
||||||
EditLocation *location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
|
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
|
||||||
IEditor *editor;
|
IEditor *editor;
|
||||||
if (location->file) {
|
if (location.file) {
|
||||||
editor = em->activateEditor(this, location->file, EditorManager::IgnoreNavigationHistory);
|
editor = em->activateEditor(this, location.file, EditorManager::IgnoreNavigationHistory);
|
||||||
} else {
|
} else {
|
||||||
editor = em->openEditor(this, location->fileName, location->kind, EditorManager::IgnoreNavigationHistory);
|
editor = em->openEditor(this, location.fileName, location.kind, EditorManager::IgnoreNavigationHistory);
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
//TODO
|
//TODO
|
||||||
qDebug() << Q_FUNC_INFO << "can't open file" << location->fileName;
|
qDebug() << Q_FUNC_INFO << "can't open file" << location.fileName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor->restoreState(location->state.toByteArray());
|
editor->restoreState(location.state.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -131,22 +131,22 @@ private:
|
|||||||
QList<IEditor *> m_editors;
|
QList<IEditor *> m_editors;
|
||||||
QMap<QWidget *, IEditor *> m_widgetEditorMap;
|
QMap<QWidget *, IEditor *> m_widgetEditorMap;
|
||||||
|
|
||||||
QList<EditLocation *> m_navigationHistory;
|
QList<EditLocation> m_navigationHistory;
|
||||||
void clearNavigationHistory() {
|
QList<EditLocation> m_editorHistory;
|
||||||
qDeleteAll(m_navigationHistory);
|
|
||||||
m_navigationHistory.clear();
|
|
||||||
}
|
|
||||||
int m_currentNavigationHistoryPosition;
|
int m_currentNavigationHistoryPosition;
|
||||||
void updateCurrentPositionInNavigationHistory();
|
void updateCurrentPositionInNavigationHistory();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
|
inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
|
||||||
inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
|
inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
|
||||||
void goBackInNavigationHistory();
|
void goBackInNavigationHistory();
|
||||||
void goForwardInNavigationHistory();
|
void goForwardInNavigationHistory();
|
||||||
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
||||||
|
inline QList<EditLocation> editorHistory() const { return m_editorHistory; }
|
||||||
|
|
||||||
void copyNavigationHistoryFrom(EditorView* other);
|
void copyNavigationHistoryFrom(EditorView* other);
|
||||||
|
void updateEditorHistory(IEditor *editor);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SplitterOrView : public QWidget
|
class SplitterOrView : public QWidget
|
||||||
|
|||||||
@@ -281,6 +281,14 @@ QModelIndex OpenEditorsModel::indexOf(IEditor *editor) const
|
|||||||
return createIndex(idx, 0);
|
return createIndex(idx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString OpenEditorsModel::displayNameForFile(IFile *file) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_editors.count(); ++i)
|
||||||
|
if (m_editors.at(i).editor && m_editors.at(i).editor->file() == file)
|
||||||
|
return m_editors.at(i).editor->displayName();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::itemChanged()
|
void OpenEditorsModel::itemChanged()
|
||||||
{
|
{
|
||||||
emitDataChanged(qobject_cast<IEditor*>(sender()));
|
emitDataChanged(qobject_cast<IEditor*>(sender()));
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class IEditor;
|
class IEditor;
|
||||||
|
class IFile;
|
||||||
|
|
||||||
class CORE_EXPORT OpenEditorsModel : public QAbstractItemModel
|
class CORE_EXPORT OpenEditorsModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
@@ -81,6 +82,8 @@ public:
|
|||||||
void makeOriginal(IEditor *duplicate);
|
void makeOriginal(IEditor *duplicate);
|
||||||
QModelIndex indexOf(IEditor *editor) const;
|
QModelIndex indexOf(IEditor *editor) const;
|
||||||
|
|
||||||
|
QString displayNameForFile(IFile *file) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itemChanged();
|
void itemChanged();
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
#include <QtGui/QHeaderView>
|
#include <QtGui/QHeaderView>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Core::IEditor *)
|
Q_DECLARE_METATYPE(Core::Internal::EditorView*)
|
||||||
|
Q_DECLARE_METATYPE(Core::IFile *)
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
@@ -188,41 +189,68 @@ void OpenEditorsWindow::centerOnItem(int selectedIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsWindow::setEditors(const QList<IEditor *>&editors, IEditor *current, OpenEditorsModel *model)
|
void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenEditorsModel *model)
|
||||||
{
|
{
|
||||||
static const QIcon lockedIcon(QLatin1String(":/core/images/locked.png"));
|
static const QIcon lockedIcon(QLatin1String(":/core/images/locked.png"));
|
||||||
static const QIcon emptyIcon(QLatin1String(":/core/images/empty14.png"));
|
static const QIcon emptyIcon(QLatin1String(":/core/images/empty14.png"));
|
||||||
|
|
||||||
m_editorList->clear();
|
m_editorList->clear();
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
QList<IEditor *> doneList;
|
QSet<IFile*> filesDone;
|
||||||
QList<IFile *>doneFileList;
|
foreach (const EditLocation &hi, view->editorHistory()) {
|
||||||
foreach (IEditor *editor, editors) {
|
if (hi.file == 0 || filesDone.contains(hi.file))
|
||||||
if (doneList.contains(editor))
|
|
||||||
continue;
|
continue;
|
||||||
doneList += editor;
|
filesDone.insert(hi.file.data());
|
||||||
if (!editor->widget()->isVisible() && doneFileList.contains(editor->file()))
|
|
||||||
continue;
|
|
||||||
doneFileList += editor->file();
|
|
||||||
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
|
|
||||||
QString title = editor->displayName();
|
QString title = model->displayNameForFile(hi.file);
|
||||||
if (editor->file()->isModified())
|
if (hi.file && hi.file->isModified())
|
||||||
title += tr("*");
|
title += tr("*");
|
||||||
item->setIcon(0, editor->file()->isReadOnly() ? lockedIcon : emptyIcon);
|
item->setIcon(0, hi.file->isReadOnly() ? lockedIcon : emptyIcon);
|
||||||
item->setText(0, title);
|
item->setText(0, title);
|
||||||
item->setToolTip(0, editor->file()->fileName());
|
item->setToolTip(0, hi.file->fileName());
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(editor));
|
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.file.data()));
|
||||||
|
item->setData(0, Qt::UserRole+1, QVariant::fromValue(view));
|
||||||
item->setTextAlignment(0, Qt::AlignLeft);
|
item->setTextAlignment(0, Qt::AlignLeft);
|
||||||
|
|
||||||
m_editorList->addTopLevelItem(item);
|
m_editorList->addTopLevelItem(item);
|
||||||
|
|
||||||
if (editor == current)
|
if (first){
|
||||||
m_editorList->setCurrentItem(item);
|
m_editorList->setCurrentItem(item);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add missing editors from the main view
|
||||||
|
if (mainView != view) {
|
||||||
|
foreach (const EditLocation &hi, mainView->editorHistory()) {
|
||||||
|
if (hi.file == 0 || filesDone.contains(hi.file))
|
||||||
|
continue;
|
||||||
|
filesDone.insert(hi.file.data());
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
|
|
||||||
|
QString title = model->displayNameForFile(hi.file);
|
||||||
|
if (hi.file && hi.file->isModified())
|
||||||
|
title += tr("*");
|
||||||
|
item->setIcon(0, hi.file->isReadOnly() ? lockedIcon : emptyIcon);
|
||||||
|
item->setText(0, title);
|
||||||
|
item->setToolTip(0, hi.file->fileName());
|
||||||
|
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.file.data()));
|
||||||
|
item->setData(0, Qt::UserRole+1, QVariant::fromValue(view));
|
||||||
|
item->setTextAlignment(0, Qt::AlignLeft);
|
||||||
|
|
||||||
|
m_editorList->addTopLevelItem(item);
|
||||||
|
|
||||||
|
if (first){
|
||||||
|
m_editorList->setCurrentItem(item);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add purely restored editors which are not initialised yet
|
// add purely restored editors which are not initialised yet
|
||||||
foreach (OpenEditorsModel::Entry entry, model->entries()) {
|
foreach (OpenEditorsModel::Entry entry, model->entries()) {
|
||||||
if (entry.editor)
|
if (entry.editor)
|
||||||
@@ -232,7 +260,7 @@ void OpenEditorsWindow::setEditors(const QList<IEditor *>&editors, IEditor *curr
|
|||||||
item->setIcon(0, emptyIcon);
|
item->setIcon(0, emptyIcon);
|
||||||
item->setText(0, title);
|
item->setText(0, title);
|
||||||
item->setToolTip(0, entry.fileName());
|
item->setToolTip(0, entry.fileName());
|
||||||
item->setData(0, Qt::UserRole+1, QVariant::fromValue(entry.kind()));
|
item->setData(0, Qt::UserRole+2, QVariant::fromValue(entry.kind()));
|
||||||
item->setTextAlignment(0, Qt::AlignLeft);
|
item->setTextAlignment(0, Qt::AlignLeft);
|
||||||
|
|
||||||
m_editorList->addTopLevelItem(item);
|
m_editorList->addTopLevelItem(item);
|
||||||
@@ -244,10 +272,12 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
|
|||||||
{
|
{
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
if (IEditor *editor = item->data(0, Qt::UserRole).value<IEditor*>())
|
if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) {
|
||||||
EditorManager::instance()->activateEditor(editor);
|
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
|
||||||
else
|
EditorManager::instance()->activateEditor(view, file);
|
||||||
EditorManager::instance()->openEditor(item->toolTip(0), item->data(0, Qt::UserRole+1).toByteArray());
|
} else {
|
||||||
|
EditorManager::instance()->openEditor(item->toolTip(0), item->data(0, Qt::UserRole+2).toByteArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsWindow::editorClicked(QTreeWidgetItem *item)
|
void OpenEditorsWindow::editorClicked(QTreeWidgetItem *item)
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ class OpenEditorsModel;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class EditorHistoryItem;
|
||||||
|
class EditorView;
|
||||||
|
|
||||||
class OpenEditorsWindow : public QWidget
|
class OpenEditorsWindow : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -54,7 +57,7 @@ public:
|
|||||||
OpenEditorsWindow(QWidget *parent = 0);
|
OpenEditorsWindow(QWidget *parent = 0);
|
||||||
~OpenEditorsWindow() {}
|
~OpenEditorsWindow() {}
|
||||||
|
|
||||||
void setEditors(const QList<IEditor *>&editors, IEditor *current, OpenEditorsModel *model);
|
void setEditors(EditorView *mainView, EditorView *view, OpenEditorsModel *model);
|
||||||
|
|
||||||
bool event(QEvent *e);
|
bool event(QEvent *e);
|
||||||
bool eventFilter(QObject *src, QEvent *e);
|
bool eventFilter(QObject *src, QEvent *e);
|
||||||
|
|||||||
@@ -256,11 +256,6 @@ QList<Core::IEditor*> EditorManagerPrototype::openedEditors() const
|
|||||||
return callee()->openedEditors();
|
return callee()->openedEditors();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Core::IEditor*> EditorManagerPrototype::editorHistory() const
|
|
||||||
{
|
|
||||||
return callee()->editorHistory();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Core::IEditor*> EditorManagerPrototype::editorsForFiles(QList<Core::IFile*> files) const
|
QList<Core::IEditor*> EditorManagerPrototype::editorsForFiles(QList<Core::IFile*> files) const
|
||||||
{
|
{
|
||||||
return callee()->editorsForFiles(files);
|
return callee()->editorsForFiles(files);
|
||||||
|
|||||||
@@ -165,7 +165,6 @@ class EditorManagerPrototype : public QObject, public QScriptable
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Core::IEditor* currentEditor READ currentEditor WRITE activateEditor DESIGNABLE false SCRIPTABLE true STORED false)
|
Q_PROPERTY(Core::IEditor* currentEditor READ currentEditor WRITE activateEditor DESIGNABLE false SCRIPTABLE true STORED false)
|
||||||
Q_PROPERTY(QList<Core::IEditor*> openedEditors READ openedEditors DESIGNABLE false SCRIPTABLE true STORED false)
|
Q_PROPERTY(QList<Core::IEditor*> openedEditors READ openedEditors DESIGNABLE false SCRIPTABLE true STORED false)
|
||||||
Q_PROPERTY(QList<Core::IEditor*> editorHistory READ editorHistory DESIGNABLE false SCRIPTABLE true STORED false)
|
|
||||||
public:
|
public:
|
||||||
typedef Core::EditorManager EditorManager;
|
typedef Core::EditorManager EditorManager;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user