diff -u -r vym-1.8.1/branchobj.cpp vym-1.8.1-sort/branchobj.cpp --- vym-1.8.1/branchobj.cpp 2006-06-01 10:51:56.000000000 -0400 +++ vym-1.8.1-sort/branchobj.cpp 2007-08-27 09:35:56.000000000 -0400 @@ -1198,6 +1198,26 @@ return branch.at(i); } +void BranchObj::sortChildren() +{ + int childCount=branch.count(); + int curChildIndex; + bool madeChanges=false; + do + { + madeChanges=false; + for(curChildIndex=1;curChildIndexheading->text().compare(curChild->heading->text())>0) + { + this->moveBranchUp(curChild); + madeChanges=true; + } + } + }while(madeChanges); +} + BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos) { // Find current parent and diff -u -r vym-1.8.1/branchobj.h vym-1.8.1-sort/branchobj.h --- vym-1.8.1/branchobj.h 2006-05-31 08:27:38.000000000 -0400 +++ vym-1.8.1-sort/branchobj.h 2007-08-27 08:14:34.000000000 -0400 @@ -108,6 +108,7 @@ virtual BranchObj* moveBranchUp(BranchObj*); virtual bool canMoveBranchDown(); virtual BranchObj* moveBranchDown(BranchObj*); + virtual void sortChildren(); virtual BranchObj* moveBranchTo (BranchObj*, int); virtual void alignRelativeTo(const QPoint ); virtual void reposition(); diff -u -r vym-1.8.1/main.cpp vym-1.8.1-sort/main.cpp --- vym-1.8.1/main.cpp 2006-04-24 07:31:15.000000000 -0400 +++ vym-1.8.1-sort/main.cpp 2007-08-27 07:33:38.000000000 -0400 @@ -41,6 +41,7 @@ QAction *actionEditPaste; QAction *actionEditMoveUp; QAction *actionEditMoveDown; +QAction *actionEditSortChildren; QAction *actionEditToggleScroll; QAction *actionEditOpenURL; QAction *actionEditOpenURLTab; diff -u -r vym-1.8.1/mainwindow.cpp vym-1.8.1-sort/mainwindow.cpp --- vym-1.8.1/mainwindow.cpp 2006-07-13 04:40:58.000000000 -0400 +++ vym-1.8.1-sort/mainwindow.cpp 2007-08-27 09:49:46.000000000 -0400 @@ -55,6 +55,7 @@ extern QAction *actionEditPaste; extern QAction *actionEditMoveUp; extern QAction *actionEditMoveDown; +extern QAction *actionEditSortChildren; extern QAction *actionEditToggleScroll; extern QAction* actionEditOpenURL; extern QAction* actionEditOpenURLTab; @@ -519,6 +520,11 @@ a->addTo( menu ); actionEditMoveDown=a; + a = new QAction( tr( "Sort children" ), QPixmap(iconPath+"sortchildren.png" ), tr( "Sort children" ), 0, this, "editSortChildren" ); + connect( a, SIGNAL( activated() ), this, SLOT( editSortChildren() ) ); + a->setEnabled (true); + a->addTo( tb ); + actionEditSortChildren=a; a = new QAction( tr( "Scroll branch" ), QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" ); connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) ); @@ -2374,6 +2380,12 @@ currentMapEditor()->moveBranchDown(); } +void Main::editSortChildren() +{ + if (currentMapEditor()) + currentMapEditor()->sortChildren(); +} + void Main::editToggleScroll() { if (currentMapEditor()) diff -u -r vym-1.8.1/mainwindow.h vym-1.8.1-sort/mainwindow.h --- vym-1.8.1/mainwindow.h 2006-05-15 03:32:10.000000000 -0400 +++ vym-1.8.1-sort/mainwindow.h 2007-08-27 07:36:04.000000000 -0400 @@ -106,6 +106,7 @@ void editMapInfo(); void editMoveUp(); void editMoveDown(); + void editSortChildren(); void editToggleScroll(); void editUnScrollAll(); void editHeading(); diff -u -r vym-1.8.1/mapeditor.cpp vym-1.8.1-sort/mapeditor.cpp --- vym-1.8.1/mapeditor.cpp 2006-05-31 08:27:38.000000000 -0400 +++ vym-1.8.1-sort/mapeditor.cpp 2007-08-27 08:17:11.000000000 -0400 @@ -58,6 +58,7 @@ extern QAction *actionEditPaste; extern QAction *actionEditMoveUp; extern QAction *actionEditMoveDown; +extern QAction *actionEditSortChildren; extern QAction *actionEditToggleScroll; extern QAction *actionEditOpenURL; extern QAction *actionEditOpenURLTab; @@ -1466,6 +1467,25 @@ } } +void MapEditor::sortChildren() +{ + // Finish open lineEdits + if (lineedit) finishedLineEdit(); + + BranchObj* bo; + if (typeid(*selection) == typeid(BranchObj) ) + { + bo=(BranchObj*)selection; + if(bo->countBranches()>1) + { + bo->sortChildren(); + saveState("sortChildren ()",bo,QString("Sorted children of %1").arg(getName(bo))); + mapCenter->reposition(); + ensureSelectionVisible(); + } + } +} + void MapEditor::editHeading() { // Finish open lineEdits diff -u -r vym-1.8.1/mapeditor.h vym-1.8.1-sort/mapeditor.h --- vym-1.8.1/mapeditor.h 2006-04-11 10:34:14.000000000 -0400 +++ vym-1.8.1-sort/mapeditor.h 2007-08-27 07:43:11.000000000 -0400 @@ -92,6 +92,7 @@ void move(const int &,const int&); void moveBranchUp(); void moveBranchDown(); + void sortChildren(); void editHeading(); // Start editing heading private: void setHeading(const QString &); // Just set the heading for selection