Changeset View
Changeset View
Standalone View
Standalone View
addons/tabswitcher/tabswitcher.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 55 | { | |||
---|---|---|---|---|---|
68 | 68 | | |||
69 | // fill the model | 69 | // fill the model | ||
70 | setupModel(); | 70 | setupModel(); | ||
71 | 71 | | |||
72 | // register action in menu | 72 | // register action in menu | ||
73 | m_mainWindow->guiFactory()->addClient(this); | 73 | m_mainWindow->guiFactory()->addClient(this); | ||
74 | 74 | | |||
75 | // popup connections | 75 | // popup connections | ||
76 | connect(m_treeView, SIGNAL(pressed(QModelIndex)), SLOT(switchToClicked(QModelIndex))); | 76 | connect(m_treeView, &TabSwitcherTreeView::pressed, this, &TabSwitcherPluginView::switchToClicked); | ||
77 | connect(m_treeView, SIGNAL(itemActivated(QModelIndex)), SLOT(activateView(QModelIndex))); | 77 | connect(m_treeView, &TabSwitcherTreeView::itemActivated, this, &TabSwitcherPluginView::activateView); | ||
78 | 78 | | |||
79 | // track existing documents | 79 | // track existing documents | ||
80 | connect(KTextEditor::Editor::instance()->application(), SIGNAL(documentCreated(KTextEditor::Document*)), | 80 | connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated, | ||
81 | this, SLOT(registerDocument(KTextEditor::Document*))); | 81 | this, &TabSwitcherPluginView::registerDocument); | ||
82 | connect(KTextEditor::Editor::instance()->application(), SIGNAL(documentWillBeDeleted(KTextEditor::Document*)), | 82 | connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentWillBeDeleted, | ||
83 | this, SLOT(unregisterDocument(KTextEditor::Document*))); | 83 | this, &TabSwitcherPluginView::unregisterDocument);; | ||
84 | 84 | | |||
85 | // track lru activation of views to raise the respective documents in the model | 85 | // track lru activation of views to raise the respective documents in the model | ||
86 | connect(m_mainWindow, SIGNAL(viewChanged(KTextEditor::View*)), | 86 | connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &TabSwitcherPluginView::raiseView); | ||
87 | this, SLOT(raiseView(KTextEditor::View*))); | | |||
88 | } | 87 | } | ||
89 | 88 | | |||
90 | TabSwitcherPluginView::~TabSwitcherPluginView() | 89 | TabSwitcherPluginView::~TabSwitcherPluginView() | ||
91 | { | 90 | { | ||
92 | // delete popup widget | 91 | // delete popup widget | ||
93 | delete m_treeView; | 92 | delete m_treeView; | ||
94 | 93 | | |||
95 | // unregister action in menu | 94 | // unregister action in menu | ||
96 | m_mainWindow->guiFactory()->removeClient(this); | 95 | m_mainWindow->guiFactory()->removeClient(this); | ||
97 | 96 | | |||
98 | // unregister this view | 97 | // unregister this view | ||
99 | m_plugin->m_views.removeAll(this); | 98 | m_plugin->m_views.removeAll(this); | ||
100 | } | 99 | } | ||
101 | 100 | | |||
102 | void TabSwitcherPluginView::setupActions() | 101 | void TabSwitcherPluginView::setupActions() | ||
103 | { | 102 | { | ||
104 | auto aNext = actionCollection()->addAction(QStringLiteral("view_lru_document_next")); | 103 | auto aNext = actionCollection()->addAction(QStringLiteral("view_lru_document_next")); | ||
105 | aNext->setText(i18n("Last Used Views")); | 104 | aNext->setText(i18n("Last Used Views")); | ||
106 | aNext->setIcon(QIcon::fromTheme(QStringLiteral("go-next-view-page"))); | 105 | aNext->setIcon(QIcon::fromTheme(QStringLiteral("go-next-view-page"))); | ||
107 | actionCollection()->setDefaultShortcut(aNext, Qt::CTRL | Qt::Key_Tab); | 106 | actionCollection()->setDefaultShortcut(aNext, Qt::CTRL | Qt::Key_Tab); | ||
108 | aNext->setWhatsThis(i18n("Opens a list to walk through the list of last used views.")); | 107 | aNext->setWhatsThis(i18n("Opens a list to walk through the list of last used views.")); | ||
109 | aNext->setStatusTip(i18n("Walk through the list of last used views")); | 108 | aNext->setStatusTip(i18n("Walk through the list of last used views")); | ||
110 | connect(aNext, SIGNAL(triggered()), SLOT(walkForward())); | 109 | connect(aNext, &QAction::triggered, this, &TabSwitcherPluginView::walkForward); | ||
111 | 110 | | |||
112 | auto aPrev = actionCollection()->addAction(QStringLiteral("view_lru_document_prev")); | 111 | auto aPrev = actionCollection()->addAction(QStringLiteral("view_lru_document_prev")); | ||
113 | aPrev->setText(i18n("Last Used Views (Reverse)")); | 112 | aPrev->setText(i18n("Last Used Views (Reverse)")); | ||
114 | aPrev->setIcon(QIcon::fromTheme(QStringLiteral("go-previous-view-page"))); | 113 | aPrev->setIcon(QIcon::fromTheme(QStringLiteral("go-previous-view-page"))); | ||
115 | actionCollection()->setDefaultShortcut(aPrev, Qt::CTRL | Qt::SHIFT | Qt::Key_Tab); | 114 | actionCollection()->setDefaultShortcut(aPrev, Qt::CTRL | Qt::SHIFT | Qt::Key_Tab); | ||
116 | aPrev->setWhatsThis(i18n("Opens a list to walk through the list of last used views in reverse.")); | 115 | aPrev->setWhatsThis(i18n("Opens a list to walk through the list of last used views in reverse.")); | ||
117 | aPrev->setStatusTip(i18n("Walk through the list of last used views")); | 116 | aPrev->setStatusTip(i18n("Walk through the list of last used views")); | ||
118 | connect(aPrev, SIGNAL(triggered()), SLOT(walkBackward())); | 117 | connect(aPrev, &QAction::triggered, this, &TabSwitcherPluginView::walkBackward); | ||
119 | 118 | | |||
120 | // make sure action work when the popup has focus | 119 | // make sure action work when the popup has focus | ||
121 | m_treeView->addAction(aNext); | 120 | m_treeView->addAction(aNext); | ||
122 | m_treeView->addAction(aPrev); | 121 | m_treeView->addAction(aPrev); | ||
123 | } | 122 | } | ||
124 | 123 | | |||
125 | static QIcon iconForDocument(KTextEditor::Document * doc) | 124 | static QIcon iconForDocument(KTextEditor::Document * doc) | ||
126 | { | 125 | { | ||
Show All 14 Lines | 138 | { | |||
141 | m_documents.insert(document); | 140 | m_documents.insert(document); | ||
142 | 141 | | |||
143 | // add to model | 142 | // add to model | ||
144 | auto item = new QStandardItem(iconForDocument(document), document->documentName()); | 143 | auto item = new QStandardItem(iconForDocument(document), document->documentName()); | ||
145 | item->setData(QVariant::fromValue(document)); | 144 | item->setData(QVariant::fromValue(document)); | ||
146 | m_model->insertRow(0, item); | 145 | m_model->insertRow(0, item); | ||
147 | 146 | | |||
148 | // track document name changes | 147 | // track document name changes | ||
149 | connect(document, SIGNAL(documentNameChanged(KTextEditor::Document*)), | 148 | connect(document, &KTextEditor::Document::documentNameChanged, this, &TabSwitcherPluginView::updateDocumentName); | ||
150 | this, SLOT(updateDocumentName(KTextEditor::Document*))); | | |||
151 | } | 149 | } | ||
152 | 150 | | |||
153 | void TabSwitcherPluginView::unregisterDocument(KTextEditor::Document * document) | 151 | void TabSwitcherPluginView::unregisterDocument(KTextEditor::Document * document) | ||
154 | { | 152 | { | ||
155 | // remove from hash | 153 | // remove from hash | ||
156 | if (!m_documents.contains(document)) { | 154 | if (!m_documents.contains(document)) { | ||
157 | return; | 155 | return; | ||
158 | } | 156 | } | ||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |