>>>>> "Peter" == Peter Kümmel <[EMAIL PROTECTED]> writes:
Peter> Jean-Marc Lasgouttes wrote: >>>>>>> "Peter" == Peter Kümmel <[EMAIL PROTECTED]> writes: >> Peter> I've tried to minimize the reordering: when a file named as Peter> AAAAAAA.lyx is opened it will be not at the first place (which Peter> would be the case when I rebuild the tabbar from scratch) but Peter> on the right, only when a already existing tab is removed and a Peter> new one is added-which happens by renaming- the code doesn't Peter> work. >> Why don't you just let the tab order be the same as the bufferlist >> order? We should see exactly the same thing as we see in the View >> menu. If there are problems with this ordering, they should be >> fixed for both cases. >> >> The bufferlist is a vector, so there is no reordering going on. >> >> JMarc >> Peter> Here a patch to simplify the tabbar code. As JMarc suggested Peter> the tabbars are always build from scratch, when the buffer has Peter> changed. I have some remarks about your patch. I think the code can be further simplified. Index: src/frontends/qt4/GuiView.C =================================================================== --- src/frontends/qt4/GuiView.C (revision 16981) +++ src/frontends/qt4/GuiView.C (working copy) @@ -72,42 +72,43 @@ namespace { -int const statusbar_timer_value = 3000; + int const statusbar_timer_value = 3000; The code into namespaces is not indented in our style. (below too). + // avoid unneeded tabbar rebuild: check if something has changed + if (oldnames.size() == names.size()) { + bool equal = true; + for (size_t i = 0; i < names.size(); i++) { + if (names[i] != oldnames[i]) { + equal = false; + break; + } + } + if (equal) { + return; + } + } + oldnames = names; Can't you just test oldnames == names ? Did you check what happens if you do not do this test? Is there any noticeable flicker or slowdown? + // remove all tab bars and clear the function map + d.funcmap.clear(); + for (int i = tabbar.count()-1; i >= 0; i--) { + tabbar.removeTab(i); } Can't you just create a new tabbar? It looks strange to have to remove elements one by one (why isn't there a QTabBar::clear function?) Also, be careful about spacing (" - 1"). + // rebuild tabbar an function map from scratch + if (names.size() == 1) { + d.funcmap.insert(std::pair<int, FuncRequest> + (0, FuncRequest(LFUN_BUFFER_SWITCH, names[0]))); + } else { + for(size_t i = 0; i < names.size(); i++) { + tabbar.addTab(lyx::toqstr(onlyFilename(names[i]))); + d.funcmap.insert(std::pair<int, FuncRequest> + (i, FuncRequest(LFUN_BUFFER_SWITCH, names[i]))); } Instead of using this funcmap, you should use lyx::Action like in the menu or toolbar code. This would avoid yet another extra structure. + // set current tab + if (view()->buffer()) { + string cur_title = view()->buffer()->fileName(); + for(size_t i = 0; i < names.size(); i++) { + if (names[i] == cur_title) { + tabbar.setCurrentIndex(i); Why not do that in the previous loop? JMarc