diff --git a/sublime/idealbuttonbarwidget.h b/sublime/idealbuttonbarwidget.h --- a/sublime/idealbuttonbarwidget.h +++ b/sublime/idealbuttonbarwidget.h @@ -64,6 +64,9 @@ void saveShowState(); bool lastShowState(); + void loadOrderSettings(); + void saveOrderSettings(); + private Q_SLOTS: void showWidget(bool checked); void buttonPressed(bool state); @@ -75,10 +78,14 @@ void actionEvent(QActionEvent *event) override; private: + void applyOrderToLayout(); + void takeOrderFromLayout(); + Qt::DockWidgetArea _area; IdealController *_controller; QWidget *_corner; bool _showState; + QStringList _order; }; } diff --git a/sublime/idealbuttonbarwidget.cpp b/sublime/idealbuttonbarwidget.cpp --- a/sublime/idealbuttonbarwidget.cpp +++ b/sublime/idealbuttonbarwidget.cpp @@ -177,6 +177,59 @@ return _showState; } +inline QString pureText(const QString& textWithShortcut) +{ + return QString(textWithShortcut).remove('&'); +} + +void IdealButtonBarWidget::loadOrderSettings() +{ + KConfigGroup config = KSharedConfig::openConfig()->group("UI"); + _order = config.readEntry(QStringLiteral("(%1) Order").arg(_area), QStringList()); + + applyOrderToLayout(); +} + +void IdealButtonBarWidget::saveOrderSettings() +{ + takeOrderFromLayout(); + + KConfigGroup config = KSharedConfig::openConfig()->group("UI"); + config.writeEntry(QStringLiteral("(%1) Order").arg(_area), _order); +} + +void IdealButtonBarWidget::applyOrderToLayout() +{ + QList orderedButtons; + + foreach(QAction* a, actions()) { + auto tva = dynamic_cast(a); + if (tva) { + layout()->removeWidget(tva->button()); + orderedButtons += tva->button(); + } + } + + std::sort(orderedButtons.begin(), orderedButtons.end(), + [this](const IdealToolButton* a, const IdealToolButton* b) { + return _order.lastIndexOf(pureText(a->text())) < _order.lastIndexOf(pureText(b->text())); + }); + + foreach(IdealToolButton* b, orderedButtons) { + layout()->addWidget(b); + } +} + +void IdealButtonBarWidget::takeOrderFromLayout() +{ + _order.clear(); + for (int i = 0; i < layout()->count(); ++i) { + IdealToolButton* button = dynamic_cast(layout()->itemAt(i)->widget()); + if (button) + _order += pureText(button->text()); + } +} + Qt::Orientation IdealButtonBarWidget::orientation() const { if (_area == Qt::LeftDockWidgetArea || _area == Qt::RightDockWidgetArea) @@ -256,6 +309,16 @@ connect(button, &IdealToolButton::clicked, this, &IdealButtonBarWidget::buttonPressed); connect(button, &IdealToolButton::customContextMenuRequested, action->dockWidget(), &IdealDockWidget::contextMenuRequested); + + QString newTitle = pureText(button->text()); + if (!_order.contains(newTitle)) { + if (_area == Qt::BottomDockWidgetArea) + _order.push_front(newTitle); + else + _order.push_back(newTitle); + } + applyOrderToLayout(); + if ( wasEmpty ) { emit emptyChanged(); } diff --git a/sublime/mainwindow_p.cpp b/sublime/mainwindow_p.cpp --- a/sublime/mainwindow_p.cpp +++ b/sublime/mainwindow_p.cpp @@ -522,6 +522,15 @@ void MainWindowPrivate::viewAdded(Sublime::AreaIndex *index, Sublime::View *view) { + static bool orderIsLoaded = false; + + if (!orderIsLoaded) { + orderIsLoaded = true; + idealController->leftBarWidget->loadOrderSettings(); + idealController->bottomBarWidget->loadOrderSettings(); + idealController->rightBarWidget->loadOrderSettings(); + } + if(m_leftTabbarCornerWidget) { m_leftTabbarCornerWidget->hide(); m_leftTabbarCornerWidget->setParent(nullptr); @@ -571,6 +580,15 @@ void MainWindowPrivate::aboutToRemoveView(Sublime::AreaIndex *index, Sublime::View *view) { + static bool orderIsSaved = false; + + if (!orderIsSaved) { + orderIsSaved = true; + idealController->leftBarWidget->saveOrderSettings(); + idealController->bottomBarWidget->saveOrderSettings(); + idealController->rightBarWidget->saveOrderSettings(); + } + QSplitter *splitter = m_indexSplitters[index]; if (!splitter) return;