Skip to content
Snippets Groups Projects
Commit f9b97ec4 authored by Eike Ziller's avatar Eike Ziller
Browse files

Fix updating of lock icon and tool tip in editor tool bar


Since the IEditor changed signal removal it was not updating them at
all, and before that it was only updating them in one of the editor
views in case of splits.

Change-Id: I8c604b64d03f6ea243e67fab52692b5b17795c32
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent d3d3ae70
No related branches found
No related tags found
No related merge requests found
...@@ -207,7 +207,7 @@ EditorToolBar::~EditorToolBar() ...@@ -207,7 +207,7 @@ EditorToolBar::~EditorToolBar()
void EditorToolBar::removeToolbarForEditor(IEditor *editor) void EditorToolBar::removeToolbarForEditor(IEditor *editor)
{ {
QTC_ASSERT(editor, return); QTC_ASSERT(editor, return);
disconnect(editor->document(), SIGNAL(changed()), this, SLOT(checkEditorStatus())); disconnect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
QWidget *toolBar = editor->toolBar(); QWidget *toolBar = editor->toolBar();
if (toolBar != 0) { if (toolBar != 0) {
...@@ -245,13 +245,13 @@ void EditorToolBar::closeEditor() ...@@ -245,13 +245,13 @@ void EditorToolBar::closeEditor()
void EditorToolBar::addEditor(IEditor *editor) void EditorToolBar::addEditor(IEditor *editor)
{ {
QTC_ASSERT(editor, return); QTC_ASSERT(editor, return);
connect(editor->document(), SIGNAL(changed()), this, SLOT(checkEditorStatus())); connect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
QWidget *toolBar = editor->toolBar(); QWidget *toolBar = editor->toolBar();
if (toolBar && !d->m_isStandalone) if (toolBar && !d->m_isStandalone)
addCenterToolBar(toolBar); addCenterToolBar(toolBar);
updateEditorStatus(editor); updateDocumentStatus(editor->document());
} }
void EditorToolBar::addCenterToolBar(QWidget *toolBar) void EditorToolBar::addCenterToolBar(QWidget *toolBar)
...@@ -298,7 +298,7 @@ void EditorToolBar::setCurrentEditor(IEditor *editor) ...@@ -298,7 +298,7 @@ void EditorToolBar::setCurrentEditor(IEditor *editor)
if (!d->m_isStandalone) if (!d->m_isStandalone)
updateToolBar(editor ? editor->toolBar() : 0); updateToolBar(editor ? editor->toolBar() : 0);
updateEditorStatus(editor); updateDocumentStatus(document);
} }
void EditorToolBar::updateEditorListSelection(IEditor *newSelection) void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
...@@ -354,20 +354,22 @@ void EditorToolBar::updateActionShortcuts() ...@@ -354,20 +354,22 @@ void EditorToolBar::updateActionShortcuts()
d->m_closeSplitButton->setToolTip(ActionManager::command(Constants::REMOVE_CURRENT_SPLIT)->stringWithAppendedShortcut(tr("Remove Split"))); d->m_closeSplitButton->setToolTip(ActionManager::command(Constants::REMOVE_CURRENT_SPLIT)->stringWithAppendedShortcut(tr("Remove Split")));
} }
void EditorToolBar::checkEditorStatus() void EditorToolBar::checkDocumentStatus()
{ {
IEditor *editor = qobject_cast<IEditor *>(sender()); IDocument *document = qobject_cast<IDocument *>(sender());
IEditor *current = EditorManager::currentEditor(); QTC_ASSERT(document, return);
DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow(
d->m_editorList->currentIndex());
if (current == editor) if (entry && entry->document && entry->document == document)
updateEditorStatus(editor); updateDocumentStatus(document);
} }
void EditorToolBar::updateEditorStatus(IEditor *editor) void EditorToolBar::updateDocumentStatus(IDocument *document)
{ {
d->m_closeEditorButton->setEnabled(editor != 0); d->m_closeEditorButton->setEnabled(document != 0);
if (!editor || !editor->document()) { if (!document) {
d->m_lockButton->setIcon(QIcon()); d->m_lockButton->setIcon(QIcon());
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(QString()); d->m_lockButton->setToolTip(QString());
...@@ -375,13 +377,13 @@ void EditorToolBar::updateEditorStatus(IEditor *editor) ...@@ -375,13 +377,13 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
return; return;
} }
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(editor->document())); d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(document));
if (editor->document()->filePath().isEmpty()) { if (document->filePath().isEmpty()) {
d->m_lockButton->setIcon(QIcon()); d->m_lockButton->setIcon(QIcon());
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(QString()); d->m_lockButton->setToolTip(QString());
} else if (editor->document()->isFileReadOnly()) { } else if (document->isFileReadOnly()) {
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon())); d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon()));
d->m_lockButton->setEnabled(true); d->m_lockButton->setEnabled(true);
d->m_lockButton->setToolTip(tr("Make Writable")); d->m_lockButton->setToolTip(tr("Make Writable"));
...@@ -390,13 +392,10 @@ void EditorToolBar::updateEditorStatus(IEditor *editor) ...@@ -390,13 +392,10 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(tr("File is writable")); d->m_lockButton->setToolTip(tr("File is writable"));
} }
IEditor *current = EditorManager::currentEditor(); d->m_editorList->setToolTip(
if (editor == current) document->filePath().isEmpty()
d->m_editorList->setToolTip( ? document->displayName()
current->document()->filePath().isEmpty() : QDir::toNativeSeparators(document->filePath()));
? current->document()->displayName()
: QDir::toNativeSeparators(editor->document()->filePath())
);
} }
void EditorToolBar::setNavigationVisible(bool isVisible) void EditorToolBar::setNavigationVisible(bool isVisible)
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
namespace Core { namespace Core {
class IEditor; class IEditor;
class IDocument;
struct EditorToolBarPrivate; struct EditorToolBarPrivate;
...@@ -81,7 +82,7 @@ public: ...@@ -81,7 +82,7 @@ public:
void setCloseSplitIcon(const QIcon &icon); void setCloseSplitIcon(const QIcon &icon);
public slots: public slots:
void updateEditorStatus(IEditor *editor); void updateDocumentStatus(Core::IDocument *document);
signals: signals:
void closeClicked(); void closeClicked();
...@@ -99,7 +100,7 @@ private slots: ...@@ -99,7 +100,7 @@ private slots:
void listContextMenu(QPoint); void listContextMenu(QPoint);
void makeEditorWritable(); void makeEditorWritable();
void checkEditorStatus(); void checkDocumentStatus();
void closeEditor(); void closeEditor();
void updateActionShortcuts(); void updateActionShortcuts();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment