Changeset View
Changeset View
Standalone View
Standalone View
sublime/container.cpp
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | 127 | private: | |||
---|---|---|---|---|---|
128 | Container* m_container; | 128 | Container* m_container; | ||
129 | }; | 129 | }; | ||
130 | 130 | | |||
131 | bool sortViews(const View* const lhs, const View* const rhs) | 131 | bool sortViews(const View* const lhs, const View* const rhs) | ||
132 | { | 132 | { | ||
133 | return lhs->document()->title().compare(rhs->document()->title(), Qt::CaseInsensitive) < 0; | 133 | return lhs->document()->title().compare(rhs->document()->title(), Qt::CaseInsensitive) < 0; | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | #ifdef Q_OS_MACOS | ||||
137 | // only one of these per process: | ||||
138 | static QMenu* currentDockMenu = NULL; | ||||
kfunk: `nullptr` | |||||
139 | #endif | ||||
140 | | ||||
136 | struct ContainerPrivate { | 141 | struct ContainerPrivate { | ||
137 | QBoxLayout* layout; | 142 | QBoxLayout* layout; | ||
138 | QHash<QWidget*, View*> viewForWidget; | 143 | QHash<QWidget*, View*> viewForWidget; | ||
139 | 144 | | |||
140 | ContainerTabBar *tabBar; | 145 | ContainerTabBar *tabBar; | ||
141 | QStackedWidget *stack; | 146 | QStackedWidget *stack; | ||
142 | KSqueezedTextLabel *fileNameCorner; | 147 | KSqueezedTextLabel *fileNameCorner; | ||
143 | QLabel *fileStatus; | 148 | QLabel *fileStatus; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 178 | for (int i = 0; i < views.size(); ++i) { | |||
192 | } | 197 | } | ||
193 | QAction* action = documentListMenu->addAction(visibleEntryTitle); | 198 | QAction* action = documentListMenu->addAction(visibleEntryTitle); | ||
194 | action->setData(QVariant::fromValue(view)); | 199 | action->setData(QVariant::fromValue(view)); | ||
195 | documentListActionForView[view] = action; | 200 | documentListActionForView[view] = action; | ||
196 | action->setIcon(view->document()->icon()); | 201 | action->setIcon(view->document()->icon()); | ||
197 | ///FIXME: push this code somehow into shell, such that we can access the project model for | 202 | ///FIXME: push this code somehow into shell, such that we can access the project model for | ||
198 | /// icons and also get a neat, short path like the document switcher. | 203 | /// icons and also get a neat, short path like the document switcher. | ||
199 | } | 204 | } | ||
205 | | ||||
206 | setAsDockMenu(); | ||||
207 | } | ||||
208 | | ||||
209 | void setAsDockMenu() | ||||
210 | { | ||||
211 | #ifdef Q_OS_MACOS | ||||
212 | if (documentListMenu != currentDockMenu) { | ||||
213 | documentListMenu->setAsDockMenu(); | ||||
214 | currentDockMenu = documentListMenu; | ||||
215 | } | ||||
216 | #endif | ||||
217 | } | ||||
218 | | ||||
219 | ~ContainerPrivate() | ||||
220 | { | ||||
221 | #ifdef Q_OS_MACOS | ||||
222 | if (documentListMenu == currentDockMenu) { | ||||
223 | QMenu().setAsDockMenu(); | ||||
224 | currentDockMenu = NULL; | ||||
kfunk: `nullptr` | |||||
225 | } | ||||
226 | #endif | ||||
200 | } | 227 | } | ||
201 | }; | 228 | }; | ||
202 | 229 | | |||
203 | class UnderlinedLabel: public KSqueezedTextLabel { | 230 | class UnderlinedLabel: public KSqueezedTextLabel { | ||
204 | Q_OBJECT | 231 | Q_OBJECT | ||
205 | public: | 232 | public: | ||
206 | UnderlinedLabel(QTabBar *tabBar, QWidget* parent = nullptr) | 233 | UnderlinedLabel(QTabBar *tabBar, QWidget* parent = nullptr) | ||
207 | :KSqueezedTextLabel(parent), m_tabBar(tabBar) | 234 | :KSqueezedTextLabel(parent), m_tabBar(tabBar) | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 299 | { | |||
279 | d->layout = new QBoxLayout(QBoxLayout::LeftToRight); | 306 | d->layout = new QBoxLayout(QBoxLayout::LeftToRight); | ||
280 | d->layout->setMargin(0); | 307 | d->layout->setMargin(0); | ||
281 | d->layout->setSpacing(0); | 308 | d->layout->setSpacing(0); | ||
282 | 309 | | |||
283 | d->documentListMenu = new QMenu(this); | 310 | d->documentListMenu = new QMenu(this); | ||
284 | d->documentListButton = new QToolButton(this); | 311 | d->documentListButton = new QToolButton(this); | ||
285 | d->documentListButton->setIcon(QIcon::fromTheme(QStringLiteral("format-list-unordered"))); | 312 | d->documentListButton->setIcon(QIcon::fromTheme(QStringLiteral("format-list-unordered"))); | ||
286 | d->documentListButton->setMenu(d->documentListMenu); | 313 | d->documentListButton->setMenu(d->documentListMenu); | ||
314 | #ifdef Q_OS_MACOS | ||||
315 | // for maintaining the Dock menu: | ||||
316 | setFocusPolicy(Qt::StrongFocus); | ||||
317 | #endif | ||||
287 | d->documentListButton->setPopupMode(QToolButton::InstantPopup); | 318 | d->documentListButton->setPopupMode(QToolButton::InstantPopup); | ||
288 | d->documentListButton->setAutoRaise(true); | 319 | d->documentListButton->setAutoRaise(true); | ||
289 | d->documentListButton->setToolTip(i18n("Show sorted list of opened documents")); | 320 | d->documentListButton->setToolTip(i18n("Show sorted list of opened documents")); | ||
290 | d->documentListButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | 321 | d->documentListButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | ||
291 | d->layout->addWidget(d->documentListButton); | 322 | d->layout->addWidget(d->documentListButton); | ||
292 | d->tabBar = new ContainerTabBar(this); | 323 | d->tabBar = new ContainerTabBar(this); | ||
293 | d->tabBar->setContextMenuPolicy(Qt::CustomContextMenu); | 324 | d->tabBar->setContextMenuPolicy(Qt::CustomContextMenu); | ||
294 | d->layout->addWidget(d->tabBar); | 325 | d->layout->addWidget(d->tabBar); | ||
▲ Show 20 Lines • Show All 384 Lines • ▼ Show 20 Line(s) | 706 | { | |||
679 | Q_ASSERT(widget); | 710 | Q_ASSERT(widget); | ||
680 | setCurrentWidget(widget); | 711 | setCurrentWidget(widget); | ||
681 | } | 712 | } | ||
682 | Sublime::View* Container::currentView() const | 713 | Sublime::View* Container::currentView() const | ||
683 | { | 714 | { | ||
684 | return d->viewForWidget.value(widget( d->tabBar->currentIndex() )); | 715 | return d->viewForWidget.value(widget( d->tabBar->currentIndex() )); | ||
685 | } | 716 | } | ||
686 | 717 | | |||
718 | void Container::focusInEvent(QFocusEvent* event) | ||||
719 | { | ||||
720 | d->setAsDockMenu(); | ||||
721 | QWidget::focusInEvent(event); | ||||
722 | } | ||||
723 | | ||||
687 | } | 724 | } | ||
688 | 725 | | |||
689 | #include "container.moc" | 726 | #include "container.moc" |
nullptr