diff --git a/git/checkoutdialog.cpp b/git/checkoutdialog.cpp index 67043d8..30500e0 100644 --- a/git/checkoutdialog.cpp +++ b/git/checkoutdialog.cpp @@ -1,274 +1,274 @@ /****************************************************************************** * Copyright (C) 2010 by Sebastian Doerner * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ******************************************************************************/ #include "checkoutdialog.h" #include "gitwrapper.h" #include #include #include #include #include #include #include #include #include #include #include #include CheckoutDialog::CheckoutDialog(QWidget* parent): QDialog(parent, Qt::Dialog), m_userEditedNewBranchName(false) { //branch/tag selection this->setWindowTitle(xi18nc("@title:window", "Git Checkout")); m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; this->setLayout(mainLayout); mainLayout->addWidget(mainWidget); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); this->connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); okButton->setText(i18nc("@action:button", "Checkout")); QWidget *boxWidget = new QWidget(this); QVBoxLayout *boxLayout = new QVBoxLayout(boxWidget); mainLayout->addWidget(boxWidget); m_branchSelectGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(m_branchSelectGroupBox); boxLayout->addWidget(m_branchSelectGroupBox); QGridLayout * gridLayout = new QGridLayout(m_branchSelectGroupBox); m_branchSelectGroupBox->setLayout(gridLayout); m_branchRadioButton = new QRadioButton(i18nc("@option:radio Git Checkout","Branch:"), m_branchSelectGroupBox); m_branchRadioButton->setChecked(true); gridLayout->addWidget(m_branchRadioButton,0,0); m_branchRadioButton->setFocus(); m_branchComboBox = new QComboBox(m_branchSelectGroupBox); gridLayout->addWidget(m_branchComboBox,0,1); QRadioButton * tagRadioButton = new QRadioButton(i18nc("@option:radio Git Checkout", "Tag:"), m_branchSelectGroupBox); gridLayout->addWidget(tagRadioButton,1,0); m_tagComboBox = new QComboBox(m_branchSelectGroupBox); m_tagComboBox->setEnabled(false); gridLayout->addWidget(m_tagComboBox,1,1); //options QGroupBox * optionsGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(optionsGroupBox); boxLayout->addWidget(optionsGroupBox); optionsGroupBox->setTitle(i18nc("@title:group", "Options")); QGridLayout * optionsGridLayout = new QGridLayout(optionsGroupBox); optionsGroupBox->setLayout(optionsGridLayout); m_newBranchCheckBox = new QCheckBox(i18nc("@option:check", "Create New Branch: "), optionsGroupBox); m_newBranchCheckBox->setToolTip(i18nc("@info:tooltip", "Create a new branch based on a selected branch or tag.")); optionsGridLayout->addWidget(m_newBranchCheckBox, 0,0); mainLayout->addWidget(m_buttonBox); m_newBranchName = new QLineEdit(optionsGroupBox); m_newBranchName->setMinimumWidth(150); m_newBranchName->setClearButtonEnabled(true); optionsGridLayout->addWidget(m_newBranchName, 0, 1); //initialize alternate color scheme for errors m_errorColors = m_newBranchName->palette(); m_errorColors.setColor(QPalette::Normal, QPalette::Base, Qt::red); m_errorColors.setColor(QPalette::Inactive, QPalette::Base, Qt::red); m_forceCheckBox = new QCheckBox(i18nc("@option:check", "Force"), optionsGroupBox); m_forceCheckBox->setToolTip(i18nc("@info:tooltip", "Discard local changes.")); optionsGridLayout->addWidget(m_forceCheckBox, 1,0); //get branch names GitWrapper * gitWrapper = GitWrapper::instance(); int currentBranchIndex; const QStringList branches = gitWrapper->branches(¤tBranchIndex); m_branchComboBox->addItems(branches); if (currentBranchIndex == -1) { m_branchComboBox->insertItem(0, "(no branch)"); m_branchComboBox->setCurrentIndex(0); } else { m_branchComboBox->setCurrentIndex(currentBranchIndex); } setDefaultNewBranchName(m_branchComboBox->currentText()); //keep local branches to prevent creating an equally named new branch foreach (const QString& b, branches) { if (!b.startsWith(QLatin1String("remotes/"))) { //you CAN create local branches called "remotes/...", but since no sane person //would do that, we save the effort of another call to "git branch" m_branchNames.insert(b); } } //get tag names const QStringList tags = gitWrapper->tags(); m_tagComboBox->addItems(tags); m_tagComboBox->setCurrentIndex(m_tagComboBox->count()-1); if (m_tagComboBox->count() == 0){ tagRadioButton->setEnabled(false); const QString tooltip = i18nc("@info:tooltip", "There are no tags in this repository."); tagRadioButton->setToolTip(tooltip); m_tagComboBox->setToolTip(tooltip); } //signals connect(m_branchRadioButton, SIGNAL(toggled(bool)), this, SLOT(branchRadioButtonToggled(bool))); connect(m_branchComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setDefaultNewBranchName(QString))); connect(m_branchComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setOkButtonState())); connect(m_tagComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setDefaultNewBranchName(QString))); connect(m_newBranchCheckBox, SIGNAL(stateChanged(int)), this, SLOT(newBranchCheckBoxStateToggled(int))); connect(m_newBranchName, SIGNAL(textChanged(QString)), this, SLOT(setOkButtonState())); connect(m_newBranchName, SIGNAL(textEdited(QString)), this, SLOT(noteUserEditedNewBranchName())); //set initial widget states newBranchCheckBoxStateToggled(Qt::Unchecked); } QString CheckoutDialog::checkoutIdentifier() const { QString identifier = m_branchComboBox->isEnabled() ? m_branchComboBox->currentText() : m_tagComboBox->currentText(); if (identifier.length()==0 || identifier.at(0)=='(') { identifier = ""; } return identifier; } bool CheckoutDialog::force() const { return m_forceCheckBox->isChecked(); } QString CheckoutDialog::newBranchName() const { if (m_newBranchCheckBox->isChecked()) { return m_newBranchName->text().trimmed(); } else { return QString(); } } void CheckoutDialog::branchRadioButtonToggled(bool checked) { m_branchComboBox->setEnabled(checked); m_tagComboBox->setEnabled(!checked); setDefaultNewBranchName(checked ? m_branchComboBox->currentText() : m_tagComboBox->currentText()); setOkButtonState(); } void CheckoutDialog::newBranchCheckBoxStateToggled(int state) { m_newBranchName->setEnabled(state == Qt::Checked); m_branchSelectGroupBox->setTitle( state == Qt::Checked ? i18nc("@title:group", "Branch Base") : i18nc("@title:group", "Checkout")); if (state == Qt::Checked) { m_newBranchName->setFocus(Qt::TabFocusReason); } setOkButtonState(); } void CheckoutDialog::setOkButtonState() { //default to enabled bool enableButton = true; bool newNameError = false; QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); //------------disable on these conditions---------------// if (m_newBranchCheckBox->isChecked()) { const QString newBranchName = m_newBranchName->text().trimmed(); if (newBranchName.isEmpty()){ enableButton = false; newNameError = true; const QString tt = i18nc("@info:tooltip", "You must enter a valid name for the new branch first."); m_newBranchName->setToolTip(tt); - okButton->setToolTip(tt)); + okButton->setToolTip(tt); } if (m_branchNames.contains(newBranchName)) { enableButton = false; newNameError = true; const QString tt = i18nc("@info:tooltip", "A branch with the name '%1' already exists.", newBranchName); m_newBranchName->setToolTip(tt); - okButton->setToolTip(tt)); + okButton->setToolTip(tt); } if (newBranchName.contains(QRegExp("\\s"))) { enableButton = false; newNameError = true; const QString tt = i18nc("@info:tooltip", "Branch names may not contain any whitespace."); m_newBranchName->setToolTip(tt); - okButton->setToolTip(tt)); + okButton->setToolTip(tt); } } //if we create a new branch and no valid branch is selected we create one based on the currently checked out version else if (m_branchRadioButton->isChecked() && m_branchComboBox->currentText().at(0) == '('){ enableButton = false; okButton->setToolTip(i18nc("@info:tooltip", "You must select a valid branch first.")); } //------------------------------------------------------// setLineEditErrorModeActive(newNameError); okButton->setEnabled(enableButton); if (!newNameError) { m_newBranchName->setToolTip(QString()); } if (enableButton) { okButton->setToolTip(QString()); } } void CheckoutDialog::setDefaultNewBranchName(const QString& baseBranchName) { if (!m_userEditedNewBranchName) { if (baseBranchName.startsWith('(')) { m_newBranchName->setText(""); } else { m_newBranchName->setText(i18nc("@item:intext Prepended to the current branch name " "to get the default name for a newly created branch", "branch") + '_' + baseBranchName); } } } void CheckoutDialog::noteUserEditedNewBranchName() { m_userEditedNewBranchName = true; } void CheckoutDialog::setLineEditErrorModeActive(bool active) { m_newBranchName->setPalette(active ? m_errorColors : QPalette()); } diff --git a/git/commitdialog.cpp b/git/commitdialog.cpp index 59d9635..9ea90de 100644 --- a/git/commitdialog.cpp +++ b/git/commitdialog.cpp @@ -1,149 +1,149 @@ /****************************************************************************** * Copyright (C) 2010 by Sebastian Doerner * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ******************************************************************************/ #include "commitdialog.h" #include "fileviewgitpluginsettings.h" #include "gitwrapper.h" #include #include #include #include #include #include #include #include #include CommitDialog::CommitDialog (QWidget* parent ): QDialog (parent, Qt::Dialog), m_localCodec(QTextCodec::codecForLocale()) { this->setWindowTitle(xi18nc("@title:window", "Git Commit")); - QDialogButtonBox *m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; this->setLayout(mainLayout); mainLayout->addWidget(mainWidget); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); this->connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); okButton->setText(i18nc("@action:button", "Commit")); QWidget* boxWidget = new QWidget(this); QVBoxLayout* boxLayout = new QVBoxLayout(boxWidget); mainLayout->addWidget(boxWidget); QGroupBox* messageGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(messageGroupBox); boxLayout->addWidget(messageGroupBox); messageGroupBox->setTitle(i18nc("@title:group", "Commit message")); mainLayout->addWidget(m_buttonBox); QVBoxLayout * messageVBox = new QVBoxLayout(messageGroupBox); messageGroupBox->setLayout(messageVBox); m_commitMessageTextEdit = new KTextEdit(messageGroupBox); m_commitMessageTextEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); m_commitMessageTextEdit->setLineWrapColumnOrWidth(72); messageVBox->addWidget(m_commitMessageTextEdit); setOkButtonState(); connect(m_commitMessageTextEdit, SIGNAL(textChanged()), this, SLOT(setOkButtonState())); QHBoxLayout* messageHBox = new QHBoxLayout(); messageVBox->addLayout(messageHBox); m_amendCheckBox = new QCheckBox(i18nc("@option:check", "Amend last commit"), messageGroupBox); messageHBox->addWidget(m_amendCheckBox); //read last commit message m_alternativeMessage = GitWrapper::instance()->lastCommitMessage(); if (m_alternativeMessage.isNull()) { m_amendCheckBox->setEnabled(false); m_amendCheckBox->setToolTip(i18nc("@info:tooltip", "There is nothing to amend.")); } else { connect(m_amendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(amendCheckBoxStateChanged())); } QPushButton * signOffButton = new QPushButton( i18nc("@action:button Add Signed-Off line to the message widget", "Sign off"),messageGroupBox); signOffButton->setToolTip(i18nc("@info:tooltip", "Add Signed-off-by line at the end of the commit message.")); messageHBox->addStretch(); messageHBox->addWidget(signOffButton); //restore dialog size FileViewGitPluginSettings* settings = FileViewGitPluginSettings::self(); this->resize(QSize(settings->commitDialogWidth(), settings->commitDialogHeight())); connect(this, SIGNAL(finished()), this, SLOT(saveDialogSize())); connect(signOffButton, SIGNAL(clicked(bool)), this, SLOT(signOffButtonClicked())); } void CommitDialog::signOffButtonClicked() { if (m_userName.isNull()) { GitWrapper * gitWrapper= GitWrapper::instance(); m_userName = gitWrapper->userName(); m_userEmail = gitWrapper->userEmail(); } //append Signed-off line QString lastline = m_commitMessageTextEdit->document()->lastBlock().text(); bool noNewLine = lastline.startsWith(QLatin1String("Signed-off")) || lastline.isEmpty(); m_commitMessageTextEdit->append(QString(noNewLine ? "" : "\n") + "Signed-off-by: " + m_userName + " <" + m_userEmail + '>'); } QByteArray CommitDialog::commitMessage() const { return m_localCodec->fromUnicode(m_commitMessageTextEdit->toPlainText()); } bool CommitDialog::amend() const { return m_amendCheckBox->isChecked(); } void CommitDialog::amendCheckBoxStateChanged() { QString tmp = m_commitMessageTextEdit->toPlainText(); m_commitMessageTextEdit->setText(m_alternativeMessage); m_alternativeMessage = tmp; } void CommitDialog::saveDialogSize() { FileViewGitPluginSettings* settings = FileViewGitPluginSettings::self(); settings->setCommitDialogHeight(this->height()); settings->setCommitDialogWidth(this->width()); settings->writeConfig(); } void CommitDialog::setOkButtonState() { bool enable = !m_commitMessageTextEdit->toPlainText().isEmpty(); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setEnabled(enable); - this->setButtonToolTip(QDialog::Ok, enable ? + okButton->setToolTip(enable ? "" : i18nc("@info:tooltip", "You must enter a commit message first.")); } diff --git a/git/pulldialog.cpp b/git/pulldialog.cpp index 5f6af06..19586d7 100644 --- a/git/pulldialog.cpp +++ b/git/pulldialog.cpp @@ -1,114 +1,114 @@ /****************************************************************************** * Copyright (C) 2010 by Sebastian Doerner * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ******************************************************************************/ #include "pulldialog.h" #include "gitwrapper.h" #include #include #include #include #include #include #include #include #include PullDialog::PullDialog(QWidget* parent): QDialog(parent, Qt::Dialog) { this->setWindowTitle(xi18nc("@title:window", "Git Pull")); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; this->setLayout(mainLayout); mainLayout->addWidget(mainWidget); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); this->connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); okButton->setText(i18nc("@action:button", "Pull")); QWidget * boxWidget = new QWidget(this); QVBoxLayout * boxLayout = new QVBoxLayout(boxWidget); mainLayout->addWidget(boxWidget); QGroupBox * sourceGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(sourceGroupBox); boxLayout->addWidget(sourceGroupBox); sourceGroupBox->setTitle(i18nc("@title:group The source to pull from", "Source")); QHBoxLayout * sourceHBox = new QHBoxLayout(sourceGroupBox); sourceGroupBox->setLayout(sourceHBox); mainLayout->addWidget(m_buttonBox); QLabel * remoteLabel = new QLabel(i18nc("@label:listbox a git remote", "Remote:"), sourceGroupBox); sourceHBox->addWidget(remoteLabel); m_remoteComboBox = new QComboBox(sourceGroupBox); sourceHBox->addWidget(m_remoteComboBox); QLabel * remoteBranchLabel = new QLabel(i18nc("@label:listbox", "Remote branch:"), sourceGroupBox); sourceHBox->addWidget(remoteBranchLabel); m_remoteBranchComboBox = new QComboBox(sourceGroupBox); sourceHBox->addWidget(m_remoteBranchComboBox); //populate UI GitWrapper * gitWrapper = GitWrapper::instance(); //get sources m_remoteComboBox->addItems(gitWrapper->pullRemotes()); //get branch names int currentBranchIndex; QStringList branches = gitWrapper->branches(¤tBranchIndex); foreach (const QString& branch, branches) { if (branch.startsWith(QLatin1String("remotes/"))) { const QString remote = branch.section('/', 1, 1); const QString name = branch.section('/', 2); m_remoteBranches[remote] << name; } } remoteSelectionChanged(m_remoteComboBox->currentText()); //Signals connect(m_remoteComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(remoteSelectionChanged(QString))); } QString PullDialog::source() const { return m_remoteComboBox->currentText(); } QString PullDialog::remoteBranch() const { return m_remoteBranchComboBox->currentText(); } void PullDialog::remoteSelectionChanged(const QString& newRemote) { m_remoteBranchComboBox->clear(); m_remoteBranchComboBox->addItems(m_remoteBranches.value(newRemote)); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setEnabled(m_remoteBranchComboBox->count() > 0); } diff --git a/git/pushdialog.cpp b/git/pushdialog.cpp index 0272c62..2021670 100644 --- a/git/pushdialog.cpp +++ b/git/pushdialog.cpp @@ -1,169 +1,169 @@ /****************************************************************************** * Copyright (C) 2010 by Sebastian Doerner * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ******************************************************************************/ #include "pushdialog.h" #include "gitwrapper.h" #include #include #include #include #include #include #include #include #include #include PushDialog::PushDialog (QWidget* parent ): QDialog (parent, Qt::Dialog) { this->setWindowTitle(xi18nc("@title:window", "Git Push")); - QDialogButtonBox *m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; this->setLayout(mainLayout); mainLayout->addWidget(mainWidget); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); this->connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); okButton->setText(i18nc("@action:button", "Push")); QWidget * boxWidget = new QWidget(this); QVBoxLayout * boxLayout = new QVBoxLayout(boxWidget); mainLayout->addWidget(boxWidget); //Destination QGroupBox * destinationGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(destinationGroupBox); boxLayout->addWidget(destinationGroupBox); destinationGroupBox->setTitle(i18nc("@title:group The remote host", "Destination")); QHBoxLayout * destinationHBox = new QHBoxLayout(destinationGroupBox); destinationGroupBox->setLayout(destinationHBox); QLabel * remoteLabel = new QLabel(i18nc("@label:listbox a git remote", "Remote:"), destinationGroupBox); destinationHBox->addWidget(remoteLabel); m_remoteComboBox = new QComboBox(destinationGroupBox); destinationHBox->addWidget(m_remoteComboBox); destinationHBox->addStretch(); //Branches QGroupBox* branchesGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(branchesGroupBox); boxLayout->addWidget(branchesGroupBox); branchesGroupBox->setTitle(i18nc("@title:group", "Branches")); QHBoxLayout * branchesHBox = new QHBoxLayout(branchesGroupBox); branchesGroupBox->setLayout(branchesHBox); QLabel * localBranchLabel = new QLabel(i18nc("@label:listbox", "Local Branch:"), branchesGroupBox); branchesHBox->addWidget(localBranchLabel); m_localBranchComboBox = new QComboBox(branchesGroupBox); branchesHBox->addWidget(m_localBranchComboBox); branchesHBox->addStretch(); QLabel * remoteBranchLabel = new QLabel(i18nc("@label:listbox", "Remote Branch:"), branchesGroupBox); branchesHBox->addWidget(remoteBranchLabel); m_remoteBranchComboBox = new QComboBox(branchesGroupBox); branchesHBox->addWidget(m_remoteBranchComboBox); QGroupBox* optionsGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(optionsGroupBox); boxLayout->addWidget(optionsGroupBox); optionsGroupBox->setTitle(i18nc("@title:group", "Options")); QHBoxLayout * optionsHBox = new QHBoxLayout(optionsGroupBox); optionsGroupBox->setLayout(optionsHBox); m_forceCheckBox = new QCheckBox(i18nc("@option:check", "Force"), optionsGroupBox); m_forceCheckBox->setToolTip(i18nc("@info:tooltip", "Proceed even if the remote branch is not an ancestor of the local branch.")); optionsHBox->addWidget(m_forceCheckBox); mainLayout->addWidget(m_buttonBox); //populate UI GitWrapper * gitWrapper = GitWrapper::instance(); //get destinations QStringList remotes = gitWrapper->pushRemotes(); m_remoteComboBox->addItems(remotes); //get branch names int currentBranchIndex; QStringList branches = gitWrapper->branches(¤tBranchIndex); foreach (const QString& branch, branches) { if (branch.startsWith(QLatin1String("remotes/"))) { const QString remote = branch.section('/', 1, 1); const QString name = branch.section('/', 2); m_remoteBranches[remote] << name; } else { m_localBranchComboBox->addItem(branch); } } m_localBranchComboBox->setCurrentText(branches.at(currentBranchIndex)); remoteSelectionChanged(m_remoteComboBox->currentText()); //Signals connect(m_remoteComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(remoteSelectionChanged(QString))); connect(m_localBranchComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(localBranchSelectionChanged(QString))); } QString PushDialog::destination() const { return m_remoteComboBox->currentText(); } QString PushDialog::localBranch() const { return m_localBranchComboBox->currentText(); } QString PushDialog::remoteBranch() const { return m_remoteBranchComboBox->currentText(); } bool PushDialog::force() const { return m_forceCheckBox->isChecked(); } void PushDialog::remoteSelectionChanged(const QString& newRemote) { m_remoteBranchComboBox->clear(); m_remoteBranchComboBox->addItems(m_remoteBranches.value(newRemote)); localBranchSelectionChanged(m_localBranchComboBox->currentText()); } void PushDialog::localBranchSelectionChanged(const QString& newLocalBranch) { //select matching remote branch if possible const int index = m_remoteBranchComboBox->findText(newLocalBranch); if (index != -1) { m_remoteBranchComboBox->setCurrentIndex(index); } QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setEnabled(m_remoteBranchComboBox->count() > 0); } diff --git a/git/tagdialog.cpp b/git/tagdialog.cpp index 6b90ee8..142d7b6 100644 --- a/git/tagdialog.cpp +++ b/git/tagdialog.cpp @@ -1,159 +1,159 @@ /****************************************************************************** * Copyright (C) 2010 by Johannes Steffen * * Copyright (C) 2010 by Sebastian Doerner * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ******************************************************************************/ #include "tagdialog.h" #include "gitwrapper.h" #include #include #include #include #include #include #include #include #include #include #include #include #include TagDialog::TagDialog (QWidget* parent ): QDialog (parent, Qt::Dialog), m_localCodec(QTextCodec::codecForLocale()) { this->setWindowTitle(xi18nc("@title:window", "Git Create Tag")); - QDialogButtonBox *m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; this->setLayout(mainLayout); mainLayout->addWidget(mainWidget); QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); this->connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); okButton->setText(i18nc("@action:button", "Create Tag")); QWidget* boxWidget = new QWidget(this); QVBoxLayout* boxLayout = new QVBoxLayout(boxWidget); mainLayout->addWidget(boxWidget); QGroupBox* tagInformationGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(tagInformationGroupBox); boxLayout->addWidget(tagInformationGroupBox); tagInformationGroupBox->setTitle(i18nc("@title:group", "Tag Information")); QVBoxLayout * tagInformationLayout = new QVBoxLayout(tagInformationGroupBox); tagInformationGroupBox->setLayout(tagInformationLayout); QLabel* nameLabel = new QLabel(i18nc("@label:textbox", "Tag Name:"), tagInformationGroupBox); tagInformationLayout->addWidget(nameLabel); m_tagNameTextEdit = new QLineEdit(tagInformationGroupBox); tagInformationLayout->addWidget(m_tagNameTextEdit); setOkButtonState(); connect(m_tagNameTextEdit, SIGNAL(textChanged(QString)), this, SLOT(setOkButtonState())); QLabel* messageLabel = new QLabel(i18nc("@label:textbox", "Tag Message:"), tagInformationGroupBox); tagInformationLayout->addWidget(messageLabel); m_tagMessageTextEdit = new KTextEdit(tagInformationGroupBox); m_tagMessageTextEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); m_tagMessageTextEdit->setLineWrapColumnOrWidth(72); tagInformationLayout->addWidget(m_tagMessageTextEdit); QGroupBox* attachToGroupBox = new QGroupBox(boxWidget); mainLayout->addWidget(attachToGroupBox); boxLayout->addWidget(attachToGroupBox); attachToGroupBox->setTitle(i18nc("@title:group", "Attach to")); mainLayout->addWidget(m_buttonBox); QHBoxLayout* attachToLayout = new QHBoxLayout(); attachToGroupBox->setLayout(attachToLayout); QLabel* branchLabel = new QLabel(i18nc("@label:listbox", "Branch:"), attachToGroupBox); attachToLayout->addWidget(branchLabel); m_branchComboBox = new QComboBox(attachToGroupBox); attachToLayout->addWidget(m_branchComboBox); attachToLayout->addStretch(); this->resize(QSize(300,200)); //initialize alternate color scheme for errors m_errorColors = m_tagNameTextEdit->palette(); m_errorColors.setColor(QPalette::Normal, QPalette::Base, Qt::red); m_errorColors.setColor(QPalette::Inactive, QPalette::Base, Qt::red); //get branch & tag names GitWrapper * gitWrapper = GitWrapper::instance(); int currentIndex; const QStringList branches = gitWrapper->branches(¤tIndex); m_branchComboBox->addItems(branches); m_branchComboBox->setCurrentIndex(currentIndex); gitWrapper->tagSet(m_tagNames); } QByteArray TagDialog::tagMessage() const { return m_localCodec->fromUnicode(m_tagMessageTextEdit->toPlainText()); } QString TagDialog::tagName() const { return m_tagNameTextEdit->text().trimmed(); } QString TagDialog::baseBranch() const { return m_branchComboBox->currentText(); } void TagDialog::setOkButtonState() { const QString tagName = m_tagNameTextEdit->text().trimmed(); QString toolTip; if (tagName.isEmpty()) { toolTip = i18nc("@info:tooltip", "You must enter a tag name first."); } else if (tagName.contains(QRegExp("\\s"))) { toolTip = i18nc("@info:tooltip", "Tag names may not contain any whitespace."); } else if (m_tagNames.contains(tagName)) { toolTip = i18nc("@info:tooltip", "A tag named '%1' already exists.", tagName); } QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok); okButton->setEnabled(toolTip.isEmpty()); setLineEditErrorModeActive(!toolTip.isEmpty()); m_tagNameTextEdit->setToolTip(toolTip); - okButton->setToolTip(toolTip)); + okButton->setToolTip(toolTip); } void TagDialog::setLineEditErrorModeActive(bool active) { m_tagNameTextEdit->setPalette(active ? m_errorColors : QPalette()); }