diff --git a/libgui/src/set-path-dialog.cc b/libgui/src/set-path-dialog.cc --- a/libgui/src/set-path-dialog.cc +++ b/libgui/src/set-path-dialog.cc @@ -180,6 +180,7 @@ namespace octave QItemSelectionModel *selmodel = m_path_list->selectionModel (); QModelIndexList indexlist = selmodel->selectedIndexes(); m->moveToTopPath (indexlist); + selmodel->reset (); } void set_path_dialog::moveToBottomPath (void) diff --git a/libgui/src/set-path-model.cc b/libgui/src/set-path-model.cc --- a/libgui/src/set-path-model.cc +++ b/libgui/src/set-path-model.cc @@ -208,33 +208,17 @@ namespace octave void set_path_model::moveToTopPath (const QModelIndexList& indices) { - QModelIndexList sorted_indices (indices); - std::sort (sorted_indices.begin (), sorted_indices.end ()); - - QStringList::iterator it = m_dirs.begin (); - int i = 0; - int index_top = 0; - while (it < m_dirs.end ()) + for (int i = 0; i < indices.size (); i++) { - if (index_top < indices.size () && indices[index_top].row () == i) - { - int distance = std::distance (m_dirs.begin (), it); - beginMoveRows (QModelIndex (), distance, distance, - QModelIndex (), m_dirs.size ()); - QString tmp = *it; - it = m_dirs.erase (it); - m_dirs.push_front (tmp); - endMoveRows (); - ++index_top; - } - else - ++it; + const QModelIndex& idx = indices.at (i); + + beginMoveRows (idx, idx.row (), idx.row (), idx, i); - ++i; + m_dirs.move (idx.row (), i); + + endMoveRows (); } - std::reverse (m_dirs.begin (), m_dirs.begin () + indices.size ()); - model_to_path (); }