# HG changeset patch # User Chris Cannam # Date 1300012292 0 # Node ID acfe9390d5c671c6f9704c28f5ec9556c6bf87bb # Parent bf4bbb53e21702ccf7d812d486c003d31d7bce06 Basic implementation of annotate diff -r bf4bbb53e217 -r acfe9390d5c6 annotatedialog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/annotatedialog.cpp Sun Mar 13 10:31:32 2011 +0000 @@ -0,0 +1,75 @@ +/* -*- 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) 2011 Chris Cannam + Copyright (c) 2011 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 "annotatedialog.h" +#include "common.h" +#include "debug.h" + +#include +#include +#include +#include +#include + +AnnotateDialog::AnnotateDialog(QWidget *w, QString text) : + QDialog(w) +{ + setMinimumWidth(600); + setMinimumHeight(700); + + text.replace("\r\n", "\n"); + QStringList lines = text.split("\n"); + + QGridLayout *layout = new QGridLayout; + QTableWidget *table = new QTableWidget; + + QRegExp annotateLineRE = QRegExp("^([^:]+) ([a-z0-9]{12}) ([0-9-]+): (.*)$"); + + table->setRowCount(lines.size()); + table->setColumnCount(4); + table->horizontalHeader()->setStretchLastSection(true); + + QStringList labels; + labels << tr("User") << tr("Revision") << tr("Date") << tr("Content"); + table->setHorizontalHeaderLabels(labels); + + int row = 0; + + foreach (QString line, lines) { + if (annotateLineRE.indexIn(line) == 0) { + QStringList items = annotateLineRE.capturedTexts(); + // note items[0] is the whole match, so we want 1-4 + for (int col = 0; col+1 < items.size(); ++col) { + std::cerr << "row " << row << " col " << col << " text " + << items[col+1] << std::endl; + table->setItem(row, col, new QTableWidgetItem(items[col+1])); + } + } else { + DEBUG << "AnnotateDialog: Failed to match RE in line: " << line << " at row " << row << endl; + } + ++row; + } + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + + layout->addWidget(table, 0, 0); + layout->addWidget(bb, 1, 0); + + setLayout(layout); +} + diff -r bf4bbb53e217 -r acfe9390d5c6 annotatedialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/annotatedialog.h Sun Mar 13 10:31:32 2011 +0000 @@ -0,0 +1,31 @@ +/* -*- 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) 2011 Chris Cannam + Copyright (c) 2011 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. +*/ + +#ifndef ANNOTATE_DIALOG_H +#define ANNOTATE_DIALOG_H + +#include + +class AnnotateDialog : public QDialog +{ + Q_OBJECT + +public: + AnnotateDialog(QWidget *parent, QString output); +}; + +#endif diff -r bf4bbb53e217 -r acfe9390d5c6 easyhg.pro --- a/easyhg.pro Sat Mar 12 22:18:08 2011 +0000 +++ b/easyhg.pro Sun Mar 13 10:31:32 2011 +0000 @@ -58,7 +58,8 @@ settingsdialog.h \ clickablelabel.h \ workstatuswidget.h \ - moreinformationdialog.h + moreinformationdialog.h \ + annotatedialog.h SOURCES = main.cpp \ mainwindow.cpp \ hgtabwidget.cpp \ @@ -90,7 +91,8 @@ uncommitteditem.cpp \ settingsdialog.cpp \ workstatuswidget.cpp \ - moreinformationdialog.cpp + moreinformationdialog.cpp \ + annotatedialog.cpp macx-* { SOURCES += common_osx.mm diff -r bf4bbb53e217 -r acfe9390d5c6 filestatuswidget.cpp --- a/filestatuswidget.cpp Sat Mar 12 22:18:08 2011 +0000 +++ b/filestatuswidget.cpp Sun Mar 13 10:31:32 2011 +0000 @@ -117,13 +117,14 @@ connect(w, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); + connect(w, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(itemDoubleClicked(QListWidgetItem *))); FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s); int prevGroup = -1; foreach (FileStates::Activity a, activities) { // Skip activities which are not yet implemented - if (a == FileStates::Annotate || - a == FileStates::Ignore || + if (a == FileStates::Ignore || a == FileStates::UnIgnore) { continue; } @@ -246,6 +247,12 @@ } } +void FileStatusWidget::itemDoubleClicked(QListWidgetItem *item) +{ + QStringList files; + files << item->text(); + emit annotateFiles(files); +} void FileStatusWidget::itemSelectionChanged() { diff -r bf4bbb53e217 -r acfe9390d5c6 filestatuswidget.h --- a/filestatuswidget.h Sat Mar 12 22:18:08 2011 +0000 +++ b/filestatuswidget.h Sun Mar 13 10:31:32 2011 +0000 @@ -25,6 +25,7 @@ class QLabel; class QListWidget; +class QListWidgetItem; class QPushButton; class QFileInfo; class QCheckBox; @@ -75,6 +76,7 @@ private slots: void menuActionActivated(); void itemSelectionChanged(); + void itemDoubleClicked(QListWidgetItem *); private: QString m_localPath; diff -r bf4bbb53e217 -r acfe9390d5c6 mainwindow.cpp --- a/mainwindow.cpp Sat Mar 12 22:18:08 2011 +0000 +++ b/mainwindow.cpp Sun Mar 13 10:31:32 2011 +0000 @@ -44,6 +44,7 @@ #include "incomingdialog.h" #include "settingsdialog.h" #include "moreinformationdialog.h" +#include "annotatedialog.h" #include "version.h" #include "workstatuswidget.h" @@ -357,25 +358,12 @@ m_runner->requestAction(HgAction(ACT_QUERY_PARENTS, m_workFolderPath, params)); } -void MainWindow::hgAnnotate() -{ - QStringList params; - QString currentFile;//!!! = m_hgTabs -> getCurrentFileListLine(); - - if (!currentFile.isEmpty()) - { - params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") - - m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params)); - } -} - void MainWindow::hgAnnotateFiles(QStringList files) { QStringList params; if (!files.isEmpty()) { - params << "annotate" << "--" << files; + params << "annotate" << "-udc" << "--" << files; m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params)); } } @@ -643,7 +631,7 @@ params << "--config" << "extensions.extdiff=" << "extdiff"; params << "--program" << diff; - params << files; // may be none: whole dir + params << "--" << files; // may be none: whole dir m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params)); } @@ -1467,49 +1455,6 @@ } } -#define STDOUT_NEEDS_BIG_WINDOW 512 -#define SMALL_WND_W 500 -#define SMALL_WND_H 300 - -#define BIG_WND_W 1024 -#define BIG_WND_H 768 - - -void MainWindow::presentLongStdoutToUser(QString stdo) -{ - if (!stdo.isEmpty()) - { - QDialog dlg; - - if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW) - { - dlg.setMinimumWidth(BIG_WND_W); - dlg.setMinimumHeight(BIG_WND_H); - } - else - { - dlg.setMinimumWidth(SMALL_WND_W); - dlg.setMinimumHeight(SMALL_WND_H); - } - - QVBoxLayout *box = new QVBoxLayout; - QListWidget *list = new QListWidget; - list-> addItems(stdo.split("\n")); - QPushButton *btn = new QPushButton(tr("Ok")); - connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept())); - - box -> addWidget(list); - box -> addWidget(btn); - dlg.setLayout(box); - - dlg.exec(); - } - else - { - QMessageBox::information(this, tr("EasyMercurial"), tr("Mercurial command did not return any output.")); - } -} - void MainWindow::updateFileSystemWatcher() { bool justCreated = false; @@ -1943,9 +1888,12 @@ break; case ACT_ANNOTATE: - presentLongStdoutToUser(output); + { + AnnotateDialog dialog(this, output); + dialog.exec(); m_shouldHgStat = true; break; + } case ACT_PULL: showPullResult(output); @@ -2223,7 +2171,6 @@ connect(m_hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull())); connect(m_hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush())); - connect(m_hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate())); connect(m_hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe())); } @@ -2364,7 +2311,6 @@ m_hgUpdateAct -> setEnabled(m_localRepoActionsEnabled); m_hgCommitAct -> setEnabled(m_localRepoActionsEnabled); m_hgMergeAct -> setEnabled(m_localRepoActionsEnabled); - m_hgAnnotateAct -> setEnabled(m_localRepoActionsEnabled); m_hgServeAct -> setEnabled(m_localRepoActionsEnabled); m_hgIgnoreAct -> setEnabled(m_localRepoActionsEnabled); @@ -2540,9 +2486,6 @@ m_hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder")); //Advanced actions - //!!! needs to be modified for number - m_hgAnnotateAct = new QAction(tr("Annotate"), this); - m_hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file")); m_hgIgnoreAct = new QAction(tr("Edit .hgignore File"), this); m_hgIgnoreAct -> setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial")); diff -r bf4bbb53e217 -r acfe9390d5c6 mainwindow.h --- a/mainwindow.h Sat Mar 12 22:18:08 2011 +0000 +++ b/mainwindow.h Sun Mar 13 10:31:32 2011 +0000 @@ -86,7 +86,6 @@ void hgPull(); void hgUpdateToRev(QString); void hgMergeFrom(QString); - void hgAnnotate(); void hgResolveList(); void hgTag(QString); void hgNewBranch(); @@ -126,7 +125,6 @@ void readSettings(); void splitChangeSets(QStringList *list, QString hgLogOutput); void reportNewRemoteHeads(QString); - void presentLongStdoutToUser(QString stdo); void writeSettings(); QStringList listAllUpIpV4Addresses();