view hgtabwidget.cpp @ 115:78374cefa10f

* Add useful state message to file status page. Also add shouldBeFast() method to HgAction; use it to avoid showing progress bar for fast actions
author Chris Cannam
date Fri, 26 Nov 2010 21:48:25 +0000
parents 1721c580c10e
children 807c79350bf1
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    EasyMercurial

    Based on HgExplorer by Jari Korhonen
    Copyright (c) 2010 Jari Korhonen
    Copyright (c) 2010 Chris Cannam
    Copyright (c) 2010 Queen Mary, University of London
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/

#include "hgtabwidget.h"
#include "common.h"
#include "logparser.h"
#include "changeset.h"
#include "changesetitem.h"
#include "grapher.h"
#include "panner.h"
#include "panned.h"
#include "filestatuswidget.h"

#include <QClipboard>
#include <QContextMenuEvent>
#include <QApplication>

#include <iostream>

HgTabWidget::HgTabWidget(QWidget *parent,
                         QString remoteRepo,
                         QString workFolderPath) :
QTabWidget(parent)
{
    // Work page
    fileStatusWidget = new FileStatusWidget;
    fileStatusWidget->setLocalPath(workFolderPath);
    fileStatusWidget->setRemoteURL(remoteRepo);
    connect(fileStatusWidget, SIGNAL(selectionChanged()),
            this, SIGNAL(selectionChanged()));
    addTab(fileStatusWidget, tr("My work"));

    // History graph page
    historyGraphPageWidget = new QWidget;
    Panned *panned = new Panned;
    Panner *panner = new Panner;
    historyGraphWidget = panned;
    historyGraphPanner = panner;
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(historyGraphWidget, 0, 0);
    layout->addWidget(historyGraphPanner, 0, 1);
    panner->setMaximumWidth(80);
    panner->connectToPanned(panned);
    historyGraphPageWidget->setLayout(layout);
    addTab(historyGraphPageWidget, tr("History"));
}

void HgTabWidget::clearSelections()
{
    fileStatusWidget->clearSelections();
}

bool HgTabWidget::canCommit() const
{
    if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
    return fileStatusWidget->haveChangesToCommit();
}

bool HgTabWidget::canRevert() const
{
    return fileStatusWidget->haveChangesToCommit() ||
        !fileStatusWidget->getSelectedRevertableFiles().empty();
}

bool HgTabWidget::canAdd() const
{
    if (fileStatusWidget->getSelectedAddableFiles().empty()) return false;
    if (!fileStatusWidget->getSelectedCommittableFiles().empty()) return false;
    if (!fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
    return true;
}

bool HgTabWidget::canRemove() const
{
    if (fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
    if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
    return true;
}

bool HgTabWidget::canDoDiff() const
{
    return canCommit();
}

QStringList HgTabWidget::getAllSelectedFiles() const
{
    return fileStatusWidget->getAllSelectedFiles();
}

QStringList HgTabWidget::getAllCommittableFiles() const
{
    return fileStatusWidget->getAllCommittableFiles();
}

QStringList HgTabWidget::getSelectedCommittableFiles() const
{
    return fileStatusWidget->getSelectedCommittableFiles();
}

QStringList HgTabWidget::getAllRevertableFiles() const
{
    return fileStatusWidget->getAllRevertableFiles();
}

QStringList HgTabWidget::getSelectedRevertableFiles() const
{
    return fileStatusWidget->getSelectedRevertableFiles();
}

QStringList HgTabWidget::getSelectedAddableFiles() const
{
    return fileStatusWidget->getSelectedAddableFiles();
}

QStringList HgTabWidget::getAllRemovableFiles() const
{
    return fileStatusWidget->getAllRemovableFiles();
}

QStringList HgTabWidget::getSelectedRemovableFiles() const
{
    return fileStatusWidget->getSelectedRemovableFiles();
}

void HgTabWidget::updateWorkFolderFileList(QString fileList)
{
    fileStates.parseStates(fileList);
    fileStatusWidget->setFileStates(fileStates);
}

void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList)
{
    //!!!
    Panned *panned = static_cast<Panned *>(historyGraphWidget);
    Panner *panner = static_cast<Panner *>(historyGraphPanner);
    QGraphicsScene *scene = new QGraphicsScene();
    Changesets csets = parseChangeSets(hgLogList);
    if (csets.empty()) return;
    Grapher g(scene);
    try {
        g.layout(csets);
    } catch (std::string s) {
        std::cerr << "Internal error: Layout failed: " << s << std::endl;
    }
    QGraphicsScene *oldScene = panned->scene();
    panned->setScene(scene);
    panner->setScene(scene);
    if (oldScene) delete oldScene;
    ChangesetItem *tipItem = g.getItemFor(csets[0]);
    if (tipItem) tipItem->ensureVisible();
    //!!! track lifecycle of those Changesets
}

Changesets HgTabWidget::parseChangeSets(QString changeSetsStr)
{
    Changesets csets = Changeset::parseChangesets(changeSetsStr);
    for (int i = 0; i+1 < csets.size(); ++i) {
        Changeset *cs = csets[i];
        if (cs->parents().empty()) {
            QStringList list;
            list.push_back(csets[i+1]->id());
            cs->setParents(list);
        }
    }
    return csets;
}

void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
{
    fileStatusWidget->setLocalPath(workFolderPath);
    fileStatusWidget->setRemoteURL(remoteRepoPath);
}

void HgTabWidget::setState(QString state)
{
    fileStatusWidget->setState(state);
}