@@ -1440,16 +1440,15 @@ bool MainWindow::setProjectUI() {
14401440 this ->locationListProxyModel = new FilterChildrenProxyModel ();
14411441 this ->locationListProxyModel ->setSourceModel (this ->mapLocationModel );
14421442 this ->locationListProxyModel ->setHideEmpty (porymapConfig.mapListHideEmptyEnabled [MapListTab::Locations]);
1443-
14441443 ui->locationList ->setModel (locationListProxyModel);
1445- ui->locationList -> sortByColumn ( 0 , Qt::SortOrder::AscendingOrder );
1444+ setMapListSorted ( ui->locationList , porymapConfig. mapListLocationsSorted );
14461445
14471446 this ->layoutTreeModel = new LayoutTreeModel (editor->project );
14481447 this ->layoutListProxyModel = new FilterChildrenProxyModel ();
14491448 this ->layoutListProxyModel ->setSourceModel (this ->layoutTreeModel );
14501449 this ->layoutListProxyModel ->setHideEmpty (porymapConfig.mapListHideEmptyEnabled [MapListTab::Layouts]);
14511450 ui->layoutList ->setModel (layoutListProxyModel);
1452- ui->layoutList -> sortByColumn ( 0 , Qt::SortOrder::AscendingOrder );
1451+ setMapListSorted ( ui->layoutList , porymapConfig. mapListLayoutsSorted );
14531452
14541453 ui->mapCustomAttributesFrame ->table ()->setRestrictedKeys (project->getTopLevelMapFields ());
14551454
@@ -1503,7 +1502,7 @@ void MainWindow::clearProjectUI() {
15031502 resetMapNavigation ();
15041503}
15051504
1506- void MainWindow::scrollMapList (MapTree *list, const QString &itemName) {
1505+ void MainWindow::scrollMapList (MapTree *list, const QString &itemName, bool expandItem ) {
15071506 if (!list || itemName.isEmpty ())
15081507 return ;
15091508 auto model = static_cast <FilterChildrenProxyModel*>(list->model ());
@@ -1516,7 +1515,7 @@ void MainWindow::scrollMapList(MapTree *list, const QString &itemName) {
15161515 return ;
15171516
15181517 list->setCurrentIndex (index);
1519- list->setExpanded (index, true );
1518+ if (expandItem) list->setExpanded (index, true );
15201519 list->scrollTo (index, QAbstractItemView::PositionAtCenter);
15211520}
15221521
@@ -1537,13 +1536,13 @@ void MainWindow::scrollMapListToCurrentLayout(MapTree *list) {
15371536// - The map list was in the middle of a search
15381537// - A map/layout is being opened by interacting with the list (in which case `lockMapListAutoScroll` is true)
15391538// - The item is not in the list (e.g. a layout ID for the Groups list)
1540- void MainWindow::scrollCurrentMapListToItem (const QString &itemName) {
1539+ void MainWindow::scrollCurrentMapListToItem (const QString &itemName, bool expandItem ) {
15411540 if (this ->lockMapListAutoScroll )
15421541 return ;
15431542
15441543 auto toolbar = getCurrentMapListToolBar ();
15451544 if (toolbar && toolbar->filterText ().isEmpty ()) {
1546- scrollMapList (toolbar->list (), itemName);
1545+ scrollMapList (toolbar->list (), itemName, expandItem );
15471546 }
15481547}
15491548
@@ -1565,6 +1564,7 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
15651564 QAction* openItemAction = nullptr ;
15661565 QAction* copyListNameAction = nullptr ;
15671566 QAction* copyToolTipAction = nullptr ;
1567+ QAction* sortFoldersAction = nullptr ;
15681568
15691569 if (itemType == " map_name" ) {
15701570 // Right-clicking on a map.
@@ -1596,6 +1596,8 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
15961596 deleteFolderAction = menu.addAction (" Delete Location" );
15971597 if (itemName == this ->editor ->project ->getEmptyMapsecName ())
15981598 deleteFolderAction->setEnabled (false ); // Disallow deleting the default name
1599+ menu.addSeparator ();
1600+ sortFoldersAction = menu.addAction (list->isSortingEnabled () ? " Sort List by Value" : " Sort List Alphabetically" );
15991601 } else if (itemType == " map_layout" ) {
16001602 // Right-clicking on a map layout
16011603 openItemAction = menu.addAction (" Open Layout" );
@@ -1612,6 +1614,8 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
16121614 addToFolderAction = menu.addAction (" Add New Map with Layout" );
16131615 // menu.addSeparator();
16141616 // deleteFolderAction = menu.addAction("Delete Layout"); // TODO: No support for deleting layouts
1617+ menu.addSeparator ();
1618+ sortFoldersAction = menu.addAction (list->isSortingEnabled () ? " Sort List by Value" : " Sort List Alphabetically" );
16151619 }
16161620
16171621 if (addToFolderAction) {
@@ -1646,6 +1650,12 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
16461650 setClipboardData (selectedItem->toolTip ());
16471651 });
16481652 }
1653+ if (sortFoldersAction) {
1654+ connect (sortFoldersAction, &QAction::triggered, [this , list, itemName] {
1655+ setMapListSorted (list, !list->isSortingEnabled ());
1656+ scrollCurrentMapListToItem (itemName, false );
1657+ });
1658+ }
16491659
16501660 if (menu.actions ().length () != 0 )
16511661 menu.exec (QCursor::pos ());
@@ -1895,6 +1905,19 @@ void MainWindow::rebuildMapList_Layouts() {
18951905 ui->mapListToolBar_Layouts ->refreshFilter ();
18961906}
18971907
1908+ void MainWindow::setMapListSorted (MapTree *list, bool sort) {
1909+ if (sort == list->isSortingEnabled ())
1910+ return ;
1911+ list->setSortingEnabled (sort);
1912+ list->sortByColumn (sort ? 0 : -1 , Qt::SortOrder::AscendingOrder);
1913+
1914+ if (list == ui->locationList ) {
1915+ porymapConfig.mapListLocationsSorted = sort;
1916+ } else if (list == ui->layoutList ) {
1917+ porymapConfig.mapListLayoutsSorted = sort;
1918+ }
1919+ }
1920+
18981921QString MainWindow::getActiveItemName () {
18991922 if (this ->editor ->map ) return this ->editor ->map ->name ();
19001923 if (this ->editor ->layout ) return this ->editor ->layout ->id ;
0 commit comments