From f6fc78eaea6ac7c145aaff166bdd2aa2c5541c46 Mon Sep 17 00:00:00 2001
From: Radovan Zivkovic <pivonroll@gmail.com>
Date: Fri, 14 Jun 2013 00:03:27 +0200
Subject: [PATCH] Dialog that prompts to add files to VCS is now resizable.

Change-Id: I8b440c76255b0cd2b952539ad4945443e293a661
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
---
 src/plugins/coreplugin/coreplugin.pro         |  9 +-
 src/plugins/coreplugin/coreplugin.qbs         |  3 +
 .../coreplugin/dialogs/addtovcsdialog.cpp     | 62 +++++++++++++
 .../coreplugin/dialogs/addtovcsdialog.h       | 58 ++++++++++++
 .../coreplugin/dialogs/addtovcsdialog.ui      | 93 +++++++++++++++++++
 src/plugins/coreplugin/vcsmanager.cpp         | 11 +--
 6 files changed, 227 insertions(+), 9 deletions(-)
 create mode 100644 src/plugins/coreplugin/dialogs/addtovcsdialog.cpp
 create mode 100644 src/plugins/coreplugin/dialogs/addtovcsdialog.h
 create mode 100644 src/plugins/coreplugin/dialogs/addtovcsdialog.ui

diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro
index 25640dd63a4..d8466a9975e 100644
--- a/src/plugins/coreplugin/coreplugin.pro
+++ b/src/plugins/coreplugin/coreplugin.pro
@@ -98,7 +98,8 @@ SOURCES += mainwindow.cpp \
     textdocument.cpp \
     documentmanager.cpp \
     removefiledialog.cpp \
-    iversioncontrol.cpp
+    iversioncontrol.cpp \
+    dialogs/addtovcsdialog.cpp
 
 HEADERS += mainwindow.h \
     editmode.h \
@@ -194,7 +195,8 @@ HEADERS += mainwindow.h \
     idocumentfactory.h \
     textdocument.h \
     documentmanager.h \
-    removefiledialog.h
+    removefiledialog.h \
+    dialogs/addtovcsdialog.h
 
 FORMS += dialogs/newdialog.ui \
     actionmanager/commandmappings.ui \
@@ -206,7 +208,8 @@ FORMS += dialogs/newdialog.ui \
     variablechooser.ui \
     mimetypesettingspage.ui \
     mimetypemagicdialog.ui \
-    removefiledialog.ui
+    removefiledialog.ui \
+    dialogs/addtovcsdialog.ui
 
 RESOURCES += core.qrc \
     fancyactionbar.qrc
diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs
index 7b4abefae00..5edc0d519dc 100644
--- a/src/plugins/coreplugin/coreplugin.qbs
+++ b/src/plugins/coreplugin/coreplugin.qbs
@@ -171,6 +171,9 @@ QtcPlugin {
         "actionmanager/commandmappings.ui",
         "actionmanager/commandsfile.cpp",
         "actionmanager/commandsfile.h",
+        "dialogs/addtovcsdialog.cpp",
+        "dialogs/addtovcsdialog.h",
+        "dialogs/addtovcsdialog.ui",
         "dialogs/externaltoolconfig.cpp",
         "dialogs/externaltoolconfig.h",
         "dialogs/externaltoolconfig.ui",
diff --git a/src/plugins/coreplugin/dialogs/addtovcsdialog.cpp b/src/plugins/coreplugin/dialogs/addtovcsdialog.cpp
new file mode 100644
index 00000000000..c1e3758dba1
--- /dev/null
+++ b/src/plugins/coreplugin/dialogs/addtovcsdialog.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+#include "addtovcsdialog.h"
+#include "ui_addtovcsdialog.h"
+
+#include <QListWidgetItem>
+
+namespace Core {
+namespace Internal {
+
+AddToVcsDialog::AddToVcsDialog(QWidget *parent, const QString &title,
+                               const QStringList &files, const QString &vcsDisplayName) :
+    QDialog(parent),
+    ui(new Ui::AddToVcsDialog)
+{
+    ui->setupUi(this);
+    QString addTo = files.size() == 1
+            ? tr("Add the file to version control (%1)").arg(vcsDisplayName)
+            : tr("Add the files to version control (%1)").arg(vcsDisplayName);
+
+    ui->addFilesLabel->setText(addTo);
+    setWindowTitle(title);
+
+    foreach (const QString &file, files) {
+        QListWidgetItem *item = new QListWidgetItem(file);
+        ui->filesListWidget->addItem(item);
+    }
+}
+
+AddToVcsDialog::~AddToVcsDialog()
+{
+    delete ui;
+}
+
+} // namespace Internal
+} // namespace Core
diff --git a/src/plugins/coreplugin/dialogs/addtovcsdialog.h b/src/plugins/coreplugin/dialogs/addtovcsdialog.h
new file mode 100644
index 00000000000..67928099f08
--- /dev/null
+++ b/src/plugins/coreplugin/dialogs/addtovcsdialog.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef ADDTOVCSDIALOG_H
+#define ADDTOVCSDIALOG_H
+
+#include <QDialog>
+
+namespace Core {
+namespace Internal {
+
+namespace Ui {
+class AddToVcsDialog;
+}
+
+class AddToVcsDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit AddToVcsDialog(QWidget *parent, const QString &title,
+                            const QStringList &files, const QString &vcsDisplayName);
+    ~AddToVcsDialog();
+
+private:
+    Ui::AddToVcsDialog *ui;
+};
+
+
+} // namespace Internal
+} // namespace Core
+#endif // ADDTOVCSDIALOG_H
diff --git a/src/plugins/coreplugin/dialogs/addtovcsdialog.ui b/src/plugins/coreplugin/dialogs/addtovcsdialog.ui
new file mode 100644
index 00000000000..17493a3f69e
--- /dev/null
+++ b/src/plugins/coreplugin/dialogs/addtovcsdialog.ui
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Core::Internal::AddToVcsDialog</class>
+ <widget class="QDialog" name="Core::Internal::AddToVcsDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>363</width>
+    <height>433</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>200</width>
+    <height>200</height>
+   </size>
+  </property>
+  <property name="baseSize">
+   <size>
+    <width>300</width>
+    <height>500</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="addFilesLabel">
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QListWidget" name="filesListWidget">
+     <property name="selectionMode">
+      <enum>QAbstractItemView::NoSelection</enum>
+     </property>
+     <property name="selectionBehavior">
+      <enum>QAbstractItemView::SelectRows</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::No|QDialogButtonBox::Yes</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>Core::Internal::AddToVcsDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>Core::Internal::AddToVcsDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/src/plugins/coreplugin/vcsmanager.cpp b/src/plugins/coreplugin/vcsmanager.cpp
index 00a5334d8aa..0fe9543f4b7 100644
--- a/src/plugins/coreplugin/vcsmanager.cpp
+++ b/src/plugins/coreplugin/vcsmanager.cpp
@@ -36,8 +36,9 @@
 #include "idocument.h"
 #include "infobar.h"
 
-#include <vcsbase/vcsbaseconstants.h>
+#include "addtovcsdialog.h"
 
+#include <vcsbase/vcsbaseconstants.h>
 #include <extensionsystem/pluginmanager.h>
 #include <utils/qtcassert.h>
 
@@ -403,11 +404,9 @@ void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNa
     if (!vc || !vc->supportsOperation(Core::IVersionControl::AddOperation))
         return;
 
-    QMessageBox::StandardButton button =
-           QMessageBox::question(Core::ICore::mainWindow(), VcsManager::msgAddToVcsTitle(),
-                                 VcsManager::msgPromptToAddToVcs(fileNames, vc),
-                                 QMessageBox::Yes | QMessageBox::No);
-    if (button == QMessageBox::Yes) {
+    Internal::AddToVcsDialog dlg(Core::ICore::mainWindow(), VcsManager::msgAddToVcsTitle(),
+                                 fileNames, vc->displayName());
+    if (dlg.exec() == QDialog::Accepted) {
         QStringList notAddedToVc;
         foreach (const QString &file, fileNames) {
             if (!vc->vcsAdd(file))
-- 
GitLab