~ubuntu-branches/debian/sid/tortoisehg/sid

« back to all changes in this revision

Viewing changes to tortoisehg/hgqt/reporegistry.py

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2012-02-20 22:03:12 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20120220220312-11yhqpn8suxvwyg4
Tags: 2.3-1
* Imported Upstream version 2.3 (Closes: #660387, #658140).
* Update dependency on Merurual (2.1, 2.2).

Show diffs side-by-side

added added

removed removed

Lines of Context:
360
360
                idx = m.index(it.row(), 0, idx)
361
361
                self.tview.expand(idx)
362
362
 
363
 
    def addRepo(self, root):
364
 
        'workbench has opened a new repowidget, ensure it is in the registry'
 
363
    def addRepo(self, root, groupname=None):
 
364
        """
 
365
        Add a repo to the repo registry, optionally specifying the parent repository group
 
366
 
 
367
        The main use of this method is when the workbench has opened a new repowidget
 
368
        """
365
369
        m = self.tview.model()
366
370
        it = m.getRepoItem(root, lookForSubrepos=True)
367
371
        if it == None:
368
 
            m.addRepo(None, root, -1)
 
372
            group = None
 
373
            if groupname:
 
374
                # Get the group index of the RepoGroup corresponding to the target group name
 
375
                for it in m.rootItem.childs:
 
376
                    if groupname == it.name:
 
377
                        rootidx = self.tview.rootIndex()
 
378
                        group = m.index(it.row(), 0, rootidx)
 
379
                        break
 
380
            m.addRepo(group, root, -1)
369
381
            self.updateSettingsFile()
370
382
 
371
383
    def setActiveTabRepo(self, root):
431
443
             ("copypath", _("Copy path"), '',
432
444
                _("Copy the root path of the repository to the clipboard"),
433
445
                self.copyPath),
 
446
             ("sortbyname", _("Sort by name"), '',
 
447
                _("Sort the group by short name"), self.sortbyname),
 
448
             ("sortbypath", _("Sort by path"), '',
 
449
                _("Sort the group by full path"), self.sortbypath),
 
450
             ("sortbyhgsub", _("Sort by .hgsub"), '',
 
451
                _("Order the subrepos as in .hgsub"), self.sortbyhgsub),
434
452
             ]
435
453
        return a
436
454
 
455
473
        menulist = selitem.internalPointer().menulist()
456
474
        if not menulist:
457
475
            return
458
 
        self.contextmenu.clear()
459
 
        for act in menulist:
460
 
            if act:
461
 
                self.contextmenu.addAction(self._actions[act])
462
 
            else:
463
 
                self.contextmenu.addSeparator()
 
476
        self.addtomenu(self.contextmenu, menulist)
464
477
        self.selitem = selitem
465
478
        self.contextmenu.exec_(point)
466
479
 
 
480
    def addtomenu(self, menu, actlist):
 
481
        menu.clear()
 
482
        for act in actlist:
 
483
            if isinstance(act, basestring) and act in self._actions:
 
484
                menu.addAction(self._actions[act])
 
485
            elif isinstance(act, tuple) and len(act) == 2:
 
486
                submenu = menu.addMenu(act[0])
 
487
                self.addtomenu(submenu, act[1])
 
488
            else:
 
489
                menu.addSeparator()
 
490
 
467
491
    #
468
492
    ## Menu action handlers
469
493
    #
472
496
        root = self.selitem.internalPointer().rootpath()
473
497
        d = clone.CloneDialog(args=[root, root + '-clone'], parent=self)
474
498
        d.finished.connect(d.deleteLater)
475
 
        d.clonedRepository.connect(self.open)
 
499
        d.clonedRepository.connect(self.openClone)
476
500
        d.show()
477
501
 
478
502
    def explore(self):
513
537
 
514
538
            root = os.path.normcase(os.path.normpath(root))
515
539
 
516
 
            if sroot != root and root == paths.find_root(os.path.dirname(path)):
 
540
            if not os.path.isdir(sroot):
 
541
                qtlib.WarningMsgBox(_('Cannot add subrepository'),
 
542
                    _('"%s" is not a folder' % sroot),
 
543
                    parent=self)
 
544
                return
 
545
            elif sroot == root:
 
546
                qtlib.WarningMsgBox(_('Cannot add subrepository'),
 
547
                    _('A repository cannot be added as a subrepo of itself'),
 
548
                    parent=self)
 
549
                return
 
550
            elif root != paths.find_root(os.path.dirname(path)):
 
551
                qtlib.WarningMsgBox(_('Cannot add subrepository'),
 
552
                    _('The selected folder:<br><br>%s<br><br>'
 
553
                    'is not inside the target repository.<br><br>'
 
554
                    'This may be allowed but is greatly discouraged.<br>'
 
555
                    'If you want to add a non trivial subrepository mapping '
 
556
                    'you must manually edit the <i>.hgsub</i> file') % root, parent=self)
 
557
                return
 
558
            else:
517
559
                # The selected path is the root of a repository that is inside
518
560
                # the selected repository
519
561
 
549
591
                            fsub.close()
550
592
                        except:
551
593
                            qtlib.WarningMsgBox(
552
 
                                _('Failed to add repository'),
 
594
                                _('Failed to add subrepository'),
553
595
                                _('Cannot open the .hgsub file in:<br><br>%s') \
554
596
                                % root, parent=self)
 
597
                            return
555
598
 
556
599
                    # Make sure that the selected subrepo (or one of its
557
600
                    # subrepos!) is not already on the .hgsub file
581
624
                        fsub = repo.wopener('.hgsub', 'w')
582
625
                        fsub.write(linesep.join(lines))
583
626
                        fsub.close()
584
 
 
585
627
                        if not hasHgsub:
586
 
                            commands.add(ui.ui(), repo, '.hgsub')
587
 
 
 
628
                            commands.add(ui.ui(), repo, repo.wjoin('.hgsub'))
588
629
                        qtlib.InfoMsgBox(
589
630
                            _('Subrepo added to .hgsub file'),
590
631
                            _('The selected subrepo:<br><br><i>%s</i><br><br>'
591
 
                            'has been added to the .hgsub file.<br><br>'
 
632
                            'has been added to the .hgsub file of the repository:<br><br><i>%s</i><br><br>'
592
633
                            'Remember that in order to finish adding the '
593
 
                            'subrepo<br><i>you must still commit</i> the '
594
 
                            '.hgsub file changes.') \
595
 
                            % root, parent=self)
 
634
                            'subrepo <i>you must still <u>commit</u></i> the '
 
635
                            'changes to the .hgsub file in order to confirm '
 
636
                            'the addition of the subrepo.') \
 
637
                            % (srelroot, root), parent=self)
596
638
                    except:
597
639
                        qtlib.WarningMsgBox(
598
640
                            _('Failed to add repository'),
616
658
    def openAll(self):
617
659
        for root in self.selitem.internalPointer().childRoots():
618
660
            self.openRepo.emit(hglib.tounicode(root), False)
619
 
    def open(self, root=None):
 
661
 
 
662
    def openClone(self, root=None, sourceroot=None):
 
663
        m = self.tview.model()
 
664
        src = m.getRepoItem(hglib.fromunicode(sourceroot))
 
665
        if src:
 
666
            groupname = src.parent().name
 
667
        else:
 
668
            groupname = None
 
669
        self.open(root, groupname)
 
670
 
 
671
    def open(self, root=None, groupname=None):
620
672
        'open context menu action, open repowidget unconditionally'
621
673
        if not root:
622
674
            root = self.selitem.internalPointer().rootpath()
628
680
            else:
629
681
                repotype = 'unknown'
630
682
        if repotype == 'hg':
 
683
            if groupname:
 
684
                self.addRepo(hglib.tounicode(root), groupname)
631
685
            self.openRepo.emit(hglib.tounicode(root), False)
632
686
        else:
633
687
            qtlib.WarningMsgBox(
637
691
 
638
692
    def copyPath(self):
639
693
        clip = QApplication.clipboard()
640
 
        clip.setText(self.selitem.internalPointer().rootpath())
 
694
        clip.setText(hglib.tounicode(self.selitem.internalPointer().rootpath()))
641
695
 
642
696
    def startRename(self):
643
697
        self.tview.edit(self.tview.currentIndex())
657
711
        if root is not None:
658
712
            self.removeRepo.emit(hglib.tounicode(root))
659
713
 
 
714
    def sortbyname(self):
 
715
        childs = self.selitem.internalPointer().childs
 
716
        self.tview.model().sortchilds(childs, lambda x: x.shortname())
 
717
 
 
718
    def sortbypath(self):
 
719
        childs = self.selitem.internalPointer().childs
 
720
        self.tview.model().sortchilds(childs, lambda x: util.normpath(x.rootpath()))
 
721
 
 
722
    def sortbyhgsub(self):
 
723
        ip = self.selitem.internalPointer()
 
724
        repo = hg.repository(ui.ui(), ip.rootpath())
 
725
        ctx = repo['.']
 
726
        wfile = '.hgsub'
 
727
        if wfile not in ctx:
 
728
            return self.sortbypath()
 
729
        data = ctx[wfile].data().strip()
 
730
        data = data.split('\n')
 
731
        getsubpath = lambda x: x.split('=')[0].strip()
 
732
        abspath = lambda x: util.normpath(repo.wjoin(x))
 
733
        hgsuborder = [abspath(getsubpath(x)) for x in data]
 
734
        def keyfunc(x):
 
735
            try:
 
736
                return hgsuborder.index(util.normpath(x.rootpath()))
 
737
            except:
 
738
                # If an item is not found, place it at the top
 
739
                return 0
 
740
        self.tview.model().sortchilds(ip.childs, keyfunc)
 
741
 
660
742
    @pyqtSlot(QString, QString)
661
743
    def shortNameChanged(self, uroot, uname):
662
744
        it = self.tview.model().getRepoItem(hglib.fromunicode(uroot))