Added missing sort-by-group action
authorTsu Jan <tsujan2000@gmail.com>
Sun, 27 Jan 2019 03:43:38 +0000 (07:13 +0330)
committerAlf Gaida <agaida@siduction.org>
Tue, 5 Feb 2019 19:11:09 +0000 (19:11 +0000)
This is related to https://github.com/lxqt/pcmanfm-qt/issues/886 and will be followed by a pcmanfm-qt patch, which should be applied immediately after it (otherwie, a crash will happen).

Gbp-Pq: Name sort-by-group-action.patch

src/foldermenu.cpp
src/foldermenu.h

index 1a87dd04ca92345a045f2b00e7fe31186184cd66..86675d59c8c9a0d8d61b1a606843c1e7a904ba53 100644 (file)
@@ -142,13 +142,14 @@ void FolderMenu::onCustomActionTrigerred() {
     }
 }
 
-void FolderMenu::addSortMenuItem(QString title, int id) {
+void FolderMenu::addSortMenuItem(const QString &title, int id) {
     QAction* action = new QAction(title, this);
+    action->setData(QVariant(id));
     sortMenu_->addAction(action);
     action->setCheckable(true);
+    action->setChecked(id == view_->model()->sortColumn());
     sortActionGroup_->addAction(action);
     connect(action, &QAction::triggered, this, &FolderMenu::onSortActionTriggered);
-    sortActions_[id] = action;
 }
 
 void FolderMenu::createSortMenu() {
@@ -158,19 +159,12 @@ void FolderMenu::createSortMenu() {
     sortActionGroup_ = new QActionGroup(sortMenu_);
     sortActionGroup_->setExclusive(true);
 
-    std::memset(sortActions_, 0, sizeof(sortActions_));
-
     addSortMenuItem(tr("By File Name"), FolderModel::ColumnFileName);
     addSortMenuItem(tr("By Modification Time"), FolderModel::ColumnFileMTime);
     addSortMenuItem(tr("By File Size"), FolderModel::ColumnFileSize);
     addSortMenuItem(tr("By File Type"), FolderModel::ColumnFileType);
     addSortMenuItem(tr("By File Owner"), FolderModel::ColumnFileOwner);
-
-    int col = model->sortColumn();
-
-    if(col >= 0 && col < FolderModel::NumOfColumns) {
-        sortActions_[col]->setChecked(true);;
-    }
+    addSortMenuItem(tr("By File Group"), FolderModel::ColumnFileGroup);
 
     sortMenu_->addSeparator();
 
@@ -237,12 +231,16 @@ void FolderMenu::onInvertSelectionActionTriggered() {
 void FolderMenu::onSortActionTriggered(bool /*checked*/) {
     ProxyFolderModel* model = view_->model();
 
-    if(model) {
+    if(model && sortActionGroup_) {
         QAction* action = static_cast<QAction*>(sender());
 
-        for(int col = 0; col < FolderModel::NumOfColumns; ++col) {
-            if(action == sortActions_[col]) {
-                model->sort(col, model->sortOrder());
+        const auto actions = sortActionGroup_->actions();
+        for(auto a : actions) {
+            if(a == action) {
+                int col = a->data().toInt();
+                if(col >= 0 && col < FolderModel::NumOfColumns) {
+                    model->sort(col, model->sortOrder());
+                }
                 break;
             }
         }
index d533c1de6e889182716758e3678d81f5c6f21048..eb7ec4cbc1c09a8da4f619e39249cd9a1e8b9558 100644 (file)
@@ -104,7 +104,7 @@ protected Q_SLOTS:
 
 private:
     void createSortMenu();
-    void addSortMenuItem(QString title, int id);
+    void addSortMenuItem(const QString &title, int id);
 
 private:
     FolderView* view_;
@@ -118,7 +118,6 @@ private:
     QAction* sortAction_;
     QActionGroup* sortActionGroup_;
     QMenu* sortMenu_;
-    QAction* sortActions_[FolderModel::NumOfColumns];
     QAction* actionAscending_;
     QAction* actionDescending_;
     QAction* showHiddenAction_;