diff --git a/src/plugins/git/changeselectiondialog.cpp b/src/plugins/git/changeselectiondialog.cpp index 8dc3dba6c6fe3a490d98765b6ceb01e7802ca4d2..84d904125d93e3bd87acb8155566570ed8b537fe 100644 --- a/src/plugins/git/changeselectiondialog.cpp +++ b/src/plugins/git/changeselectiondialog.cpp @@ -31,6 +31,7 @@ #include "logchangedialog.h" #include "gitplugin.h" #include "gitclient.h" +#include "ui_changeselectiondialog.h" #include <QProcess> #include <QFormLayout> @@ -47,86 +48,48 @@ namespace Internal { ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Core::Id id, QWidget *parent) : QDialog(parent) + , m_ui(new Ui::ChangeSelectionDialog) , m_process(0) - , m_workingDirEdit(new QLineEdit(workingDirectory, this)) - , m_changeNumberEdit(new QLineEdit(this)) - , m_selectDirButton(new QPushButton(tr("Browse &Directory..."), this)) - , m_selectFromHistoryButton(new QPushButton(tr("Browse &History..."), this)) - , m_showButton(new QPushButton(tr("&Show"), this)) - , m_cherryPickButton(new QPushButton(tr("Cherry &Pick"), this)) - , m_revertButton(new QPushButton(tr("&Revert"), this)) - , m_checkoutButton(new QPushButton(tr("Check&out"), this)) - , m_closeButton(new QPushButton(tr("&Close"), this)) - , m_detailsText(new QPlainTextEdit(this)) , m_command(NoCommand) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - bool ok; - m_gitBinaryPath = GitPlugin::instance()->gitClient()->gitBinaryPath(&ok); - if (!ok) - return; - - QGridLayout* layout = new QGridLayout(this); - layout->addWidget(new QLabel(tr("Working directory:"), this), 0, 0 , 1, 1); - layout->addWidget(m_workingDirEdit, 0, 1, 1, 1); - layout->addWidget(m_selectDirButton, 0, 2, 1, 1); - layout->addWidget(new QLabel(tr("Change:"), this),1, 0, 1, 1); - layout->addWidget(m_changeNumberEdit, 1, 1, 1, 1); - layout->addWidget(m_selectFromHistoryButton, 1, 2, 1, 1); - layout->addWidget(m_detailsText, 2, 0, 1, 3); - - QHBoxLayout* buttonsLine = new QHBoxLayout(); - buttonsLine->addWidget(m_closeButton); - buttonsLine->addStretch(); - buttonsLine->addWidget(m_checkoutButton); - buttonsLine->addWidget(m_revertButton); - buttonsLine->addWidget(m_cherryPickButton); - buttonsLine->addWidget(m_showButton); - - layout->addLayout(buttonsLine, 3, 0 ,1 ,3); - - m_changeNumberEdit->setFocus(Qt::ActiveWindowFocusReason); - m_changeNumberEdit->setText(QLatin1String("HEAD")); - m_changeNumberEdit->selectAll(); - - setWindowTitle(tr("Select a Git Commit")); - setMinimumSize(QSize(550, 350)); - + m_gitBinaryPath = GitPlugin::instance()->gitClient()->gitBinaryPath(); + m_ui->setupUi(this); + m_ui->workingDirectoryEdit->setText(workingDirectory); m_gitEnvironment = GitPlugin::instance()->gitClient()->processEnvironment(); - connect(m_changeNumberEdit, SIGNAL(textChanged(QString)), - this, SLOT(recalculateDetails())); - connect(m_workingDirEdit, SIGNAL(textChanged(QString)), - this, SLOT(recalculateDetails())); - connect(m_selectFromHistoryButton, SIGNAL(clicked()), - this, SLOT(selectCommitFromRecentHistory())); - connect(m_selectDirButton, SIGNAL(clicked()), this, SLOT(chooseWorkingDirectory())); - - connect(m_showButton, SIGNAL(clicked()), this, SLOT(acceptShow())); - connect(m_cherryPickButton, SIGNAL(clicked()), this, SLOT(acceptCherryPick())); - connect(m_revertButton, SIGNAL(clicked()), this, SLOT(acceptRevert())); - connect(m_checkoutButton, SIGNAL(clicked()), this, SLOT(acceptCheckout())); - connect(m_closeButton, SIGNAL(clicked()), this, SLOT(reject())); + m_ui->changeNumberEdit->setFocus(); + m_ui->changeNumberEdit->selectAll(); + + connect(m_ui->changeNumberEdit, SIGNAL(textChanged(QString)), this, SLOT(recalculateDetails())); + connect(m_ui->workingDirectoryEdit, SIGNAL(textChanged(QString)), this, SLOT(recalculateDetails())); + connect(m_ui->selectDirectoryButton, SIGNAL(clicked()), this, SLOT(chooseWorkingDirectory())); + connect(m_ui->selectFromHistoryButton, SIGNAL(clicked()), this, SLOT(selectCommitFromRecentHistory())); + connect(m_ui->showButton, SIGNAL(clicked()), this, SLOT(acceptShow())); + connect(m_ui->cherryPickButton, SIGNAL(clicked()), this, SLOT(acceptCherryPick())); + connect(m_ui->revertButton, SIGNAL(clicked()), this, SLOT(acceptRevert())); + connect(m_ui->checkoutButton, SIGNAL(clicked()), this, SLOT(acceptCheckout())); QByteArray idName = id.name(); if (idName == "Git.Revert") - m_revertButton->setDefault(true); + m_ui->revertButton->setDefault(true); else if (idName == "Git.CherryPick") - m_cherryPickButton->setDefault(true); + m_ui->cherryPickButton->setDefault(true); else if (idName == "Git.Checkout") - m_checkoutButton->setDefault(true); + m_ui->checkoutButton->setDefault(true); else - m_showButton->setDefault(true); + m_ui->showButton->setDefault(true); recalculateDetails(); } ChangeSelectionDialog::~ChangeSelectionDialog() { + delete m_ui; delete m_process; } QString ChangeSelectionDialog::change() const { - return m_changeNumberEdit->text(); + return m_ui->changeNumberEdit->text(); } void ChangeSelectionDialog::selectCommitFromRecentHistory() @@ -150,27 +113,27 @@ void ChangeSelectionDialog::selectCommitFromRecentHistory() if (dialog.commitIndex() > 0) commit += QLatin1Char('~') + QString::number(dialog.commitIndex()); - m_changeNumberEdit->setText(commit); + m_ui->changeNumberEdit->setText(commit); } void ChangeSelectionDialog::chooseWorkingDirectory() { QString folder = QFileDialog::getExistingDirectory(this, tr("Select Git Directory"), - m_workingDirEdit->text()); + m_ui->workingDirectoryEdit->text()); if (folder.isEmpty()) return; - m_workingDirEdit->setText(folder); + m_ui->workingDirectoryEdit->setText(folder); } QString ChangeSelectionDialog::workingDirectory() const { - if (m_workingDirEdit->text().isEmpty() || !QDir(m_workingDirEdit->text()).exists()) + const QString workingDir = m_ui->workingDirectoryEdit->text(); + if (workingDir.isEmpty() || !QDir(workingDir).exists()) return QString(); - return GitPlugin::instance()->gitClient()-> - findRepositoryForDirectory(m_workingDirEdit->text()); + return GitPlugin::instance()->gitClient()->findRepositoryForDirectory(workingDir); } ChangeCommand ChangeSelectionDialog::command() const @@ -205,25 +168,25 @@ void ChangeSelectionDialog::acceptShow() //! Set commit message in details void ChangeSelectionDialog::setDetails(int exitCode) { - QPalette palette = m_changeNumberEdit->palette(); + QPalette palette = m_ui->changeNumberEdit->palette(); if (exitCode == 0) { - m_detailsText->setPlainText(QString::fromUtf8(m_process->readAllStandardOutput())); + m_ui->detailsText->setPlainText(QString::fromUtf8(m_process->readAllStandardOutput())); palette.setColor(QPalette::Text, Qt::black); - m_changeNumberEdit->setPalette(palette); + m_ui->changeNumberEdit->setPalette(palette); enableButtons(true); } else { - m_detailsText->setPlainText(tr("Error: Unknown reference")); + m_ui->detailsText->setPlainText(tr("Error: Unknown reference")); palette.setColor(QPalette::Text, Qt::red); - m_changeNumberEdit->setPalette(palette); + m_ui->changeNumberEdit->setPalette(palette); } } void ChangeSelectionDialog::enableButtons(bool b) { - m_showButton->setEnabled(b); - m_cherryPickButton->setEnabled(b); - m_revertButton->setEnabled(b); - m_checkoutButton->setEnabled(b); + m_ui->showButton->setEnabled(b); + m_ui->cherryPickButton->setEnabled(b); + m_ui->revertButton->setEnabled(b); + m_ui->checkoutButton->setEnabled(b); } void ChangeSelectionDialog::recalculateDetails() @@ -236,20 +199,20 @@ void ChangeSelectionDialog::recalculateDetails() } enableButtons(false); - QString workingDir = workingDirectory(); - QPalette palette = m_workingDirEdit->palette(); + const QString workingDir = workingDirectory(); + QPalette palette = m_ui->workingDirectoryEdit->palette(); if (workingDir.isEmpty()) { - m_detailsText->setPlainText(tr("Error: Bad working directory.")); + m_ui->detailsText->setPlainText(tr("Error: Bad working directory.")); palette.setColor(QPalette::Text, Qt::red); - m_workingDirEdit->setPalette(palette); + m_ui->workingDirectoryEdit->setPalette(palette); return; } else { palette.setColor(QPalette::Text, Qt::black); - m_workingDirEdit->setPalette(palette); + m_ui->workingDirectoryEdit->setPalette(palette); } QStringList args; - args << QLatin1String("log") << QLatin1String("-n1") << m_changeNumberEdit->text(); + args << QLatin1String("log") << QLatin1String("-n1") << m_ui->changeNumberEdit->text(); m_process = new QProcess(this); m_process->setWorkingDirectory(workingDir); @@ -260,9 +223,9 @@ void ChangeSelectionDialog::recalculateDetails() m_process->start(m_gitBinaryPath, args); m_process->closeWriteChannel(); if (!m_process->waitForStarted()) - m_detailsText->setPlainText(tr("Error: Could not start Git.")); + m_ui->detailsText->setPlainText(tr("Error: Could not start Git.")); else - m_detailsText->setPlainText(tr("Fetching commit data...")); + m_ui->detailsText->setPlainText(tr("Fetching commit data...")); } } // Internal diff --git a/src/plugins/git/changeselectiondialog.h b/src/plugins/git/changeselectiondialog.h index 9035ec7c19d2eb61294dbf97a2cc8f742a26f261..6af4f73af032c5ab13c300b0b366575568d91bde 100644 --- a/src/plugins/git/changeselectiondialog.h +++ b/src/plugins/git/changeselectiondialog.h @@ -54,6 +54,8 @@ enum ChangeCommand { Show }; +namespace Ui { class ChangeSelectionDialog; } + class ChangeSelectionDialog : public QDialog { Q_OBJECT @@ -79,21 +81,11 @@ private slots: private: void enableButtons(bool b); + Ui::ChangeSelectionDialog *m_ui; + QProcess *m_process; QString m_gitBinaryPath; QProcessEnvironment m_gitEnvironment; - - QLineEdit *m_workingDirEdit; - QLineEdit *m_changeNumberEdit; - QPushButton *m_selectDirButton; - QPushButton *m_selectFromHistoryButton; - QPushButton *m_showButton; - QPushButton *m_cherryPickButton; - QPushButton *m_revertButton; - QPushButton *m_checkoutButton; - QPushButton *m_closeButton; - QPlainTextEdit *m_detailsText; - ChangeCommand m_command; }; diff --git a/src/plugins/git/changeselectiondialog.ui b/src/plugins/git/changeselectiondialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..5fd084858c25fe2aa918472a64970fd9c5d637c7 --- /dev/null +++ b/src/plugins/git/changeselectiondialog.ui @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Git::Internal::ChangeSelectionDialog</class> + <widget class="QDialog" name="Git::Internal::ChangeSelectionDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>550</width> + <height>350</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout"> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="workingDirectoryLabel"> + <property name="text"> + <string>Working directory:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="workingDirectoryEdit"/> + </item> + <item row="0" column="2"> + <widget class="QPushButton" name="selectDirectoryButton"> + <property name="text"> + <string>Browse &Directory...</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="changeLabel"> + <property name="text"> + <string>Change:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="changeNumberEdit"> + <property name="text"> + <string>HEAD</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="selectFromHistoryButton"> + <property name="text"> + <string>Browse &History...</string> + </property> + </widget> + </item> + <item row="2" column="0" colspan="3"> + <widget class="QPlainTextEdit" name="detailsText"> + <property name="undoRedoEnabled"> + <bool>false</bool> + </property> + <property name="lineWrapMode"> + <enum>QPlainTextEdit::NoWrap</enum> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="3" column="0" colspan="3"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="closeButton"> + <property name="text"> + <string>&Close</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="checkoutButton"> + <property name="text"> + <string>Check&out</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="revertButton"> + <property name="text"> + <string>&Revert</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cherryPickButton"> + <property name="text"> + <string>Cherry &Pick</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="showButton"> + <property name="text"> + <string>&Show</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>closeButton</sender> + <signal>clicked()</signal> + <receiver>Git::Internal::ChangeSelectionDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>52</x> + <y>324</y> + </hint> + <hint type="destinationlabel"> + <x>112</x> + <y>312</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/plugins/git/git.pro b/src/plugins/git/git.pro index 96af92c5fe0acaada013fc11477931717fa369ba..775b7c00956c7b6cedd97ea9eacb794aea268224 100644 --- a/src/plugins/git/git.pro +++ b/src/plugins/git/git.pro @@ -50,7 +50,8 @@ SOURCES += gitplugin.cpp \ branchcheckoutdialog.cpp \ githighlighters.cpp -FORMS += settingspage.ui \ +FORMS += changeselectiondialog.ui \ + settingspage.ui \ gitsubmitpanel.ui \ branchdialog.ui \ stashdialog.ui \ diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index 1c626ff198f646c4d1d07d6b7700825683f7c9c5..154a08b5554ed6d01982c34c959c93eeb921a299 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -29,6 +29,7 @@ QtcPlugin { "branchmodel.h", "changeselectiondialog.cpp", "changeselectiondialog.h", + "changeselectiondialog.ui", "clonewizard.cpp", "clonewizard.h", "clonewizardpage.cpp",