Added branch on commit
Refactored CommitDialog FossilOrigin-Name: 34efdbe98a491079ce2a2ae97c701ed5af118a4c
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "ui_CommitDialog.h"
|
||||
#include "MainWindow.h" // Ugly. I know.
|
||||
|
||||
CommitDialog::CommitDialog(QWidget *parent, const QString &title, QStringList &files, const QStringList *history, bool singleLineEntry, const QString *checkBoxText, bool *checkBoxValue) :
|
||||
CommitDialog::CommitDialog(QWidget *parent, const QString &title, QStringList &files, const QStringList *history, bool stashMode) :
|
||||
QDialog(parent, Qt::Sheet),
|
||||
ui(new Ui::CommitDialog)
|
||||
{
|
||||
@@ -15,16 +15,13 @@ CommitDialog::CommitDialog(QWidget *parent, const QString &title, QStringList &f
|
||||
setWindowTitle(title);
|
||||
|
||||
// Activate the appropriate control based on mode
|
||||
ui->plainTextEdit->setVisible(!singleLineEntry);
|
||||
ui->lineEdit->setVisible(singleLineEntry);
|
||||
ui->plainTextEdit->setVisible(!stashMode);
|
||||
ui->lineEdit->setVisible(stashMode);
|
||||
|
||||
// Activate the checkbox if we have some text
|
||||
ui->checkBox->setVisible(checkBoxText!=0);
|
||||
if(checkBoxText && checkBoxValue)
|
||||
{
|
||||
ui->checkBox->setText(*checkBoxText);
|
||||
ui->checkBox->setCheckState(*checkBoxValue ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
ui->chkRevertFiles->setVisible(stashMode);
|
||||
|
||||
ui->widgetBranchOptions->setVisible(!stashMode);
|
||||
|
||||
// Activate the combo if we have history
|
||||
ui->comboBox->setVisible(history!=0);
|
||||
@@ -77,16 +74,12 @@ CommitDialog::~CommitDialog()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CommitDialog::run(QWidget *parent, const QString &title, QStringList &files, QString &commitMsg, const QStringList *history, bool singleLineEntry, const QString *checkBoxText, bool *checkBoxValue)
|
||||
bool CommitDialog::runCommit(QWidget* parent, QStringList& files, QString& commitMsg, const QStringList& commitMsgHistory, QString &branchName, bool &privateBranch)
|
||||
{
|
||||
CommitDialog dlg(parent, title, files, history, singleLineEntry, checkBoxText, checkBoxValue);
|
||||
CommitDialog dlg(parent, tr("Commit Changes"), files, &commitMsgHistory, false);
|
||||
int res = dlg.exec();
|
||||
|
||||
if(singleLineEntry)
|
||||
commitMsg = dlg.ui->lineEdit->text();
|
||||
else
|
||||
commitMsg = dlg.ui->plainTextEdit->toPlainText();
|
||||
|
||||
commitMsg = dlg.ui->plainTextEdit->toPlainText();
|
||||
|
||||
if(res!=QDialog::Accepted)
|
||||
return false;
|
||||
@@ -100,26 +93,38 @@ bool CommitDialog::run(QWidget *parent, const QString &title, QStringList &files
|
||||
files.append(si->text());
|
||||
}
|
||||
|
||||
if(checkBoxText)
|
||||
branchName.clear();
|
||||
if(dlg.ui->chkNewBranch->isChecked())
|
||||
{
|
||||
Q_ASSERT(checkBoxValue);
|
||||
*checkBoxValue = dlg.ui->checkBox->checkState() == Qt::Checked;
|
||||
branchName = dlg.ui->lineBranchName->text().trimmed();
|
||||
privateBranch = dlg.ui->chkPrivateBranch->isChecked();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CommitDialog::runCommit(QWidget* parent, QStringList& files, QString& commitMsg, const QStringList& commitMsgHistory)
|
||||
bool CommitDialog::runStashNew(QWidget* parent, QStringList& stashedFiles, QString& stashName, bool& revertFiles)
|
||||
{
|
||||
return run(parent, tr("Commit Changes"), files, commitMsg, &commitMsgHistory, false, 0, 0);
|
||||
}
|
||||
CommitDialog dlg(parent, tr("Stash Changes"), stashedFiles, NULL, true);
|
||||
int res = dlg.exec();
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CommitDialog::runStashNew(QWidget* parent, QStringList& stashedFiles, QString& stashName, bool& checkBoxValue)
|
||||
{
|
||||
QString checkbox_text = tr("Revert stashed files");
|
||||
return run(parent, tr("Stash Changes"), stashedFiles, stashName, 0, true, &checkbox_text, &checkBoxValue);
|
||||
stashName = dlg.ui->lineEdit->text();
|
||||
|
||||
if(res!=QDialog::Accepted)
|
||||
return false;
|
||||
|
||||
stashedFiles.clear();
|
||||
for(int i=0; i<dlg.itemModel.rowCount(); ++i)
|
||||
{
|
||||
QStandardItem *si = dlg.itemModel.item(i);
|
||||
if(si->checkState()!=Qt::Checked)
|
||||
continue;
|
||||
stashedFiles.append(si->text());
|
||||
}
|
||||
|
||||
revertFiles = dlg.ui->chkRevertFiles->checkState() == Qt::Checked;
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -155,3 +160,10 @@ void CommitDialog::on_listView_clicked(const QModelIndex &)
|
||||
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(num_selected>0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void CommitDialog::on_chkNewBranch_toggled(bool checked)
|
||||
{
|
||||
ui->chkPrivateBranch->setEnabled(checked);
|
||||
ui->lineBranchName->setEnabled(checked);
|
||||
}
|
||||
|
@@ -13,19 +13,17 @@ class CommitDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CommitDialog(QWidget *parent, const QString &title, QStringList &files, const QStringList *history=0, bool singleLineEntry=false, const QString *checkBoxText=0, bool *checkBoxValue=0);
|
||||
explicit CommitDialog(QWidget *parent, const QString &title, QStringList &files, const QStringList *history, bool stashMode);
|
||||
~CommitDialog();
|
||||
|
||||
static bool runStashNew(QWidget* parent, QStringList& stashedFiles, QString& stashName, bool &checkBoxValue);
|
||||
static bool runCommit(QWidget* parent, QStringList& files, QString& commitMsg, const QStringList &commitMsgHistory);
|
||||
|
||||
private:
|
||||
static bool run(QWidget *parent, const QString &title, QStringList &files, QString &commitMsg, const QStringList *history, bool singleLineEntry, const QString *checkBoxText, bool *checkBoxValue);
|
||||
static bool runStashNew(QWidget* parent, QStringList& stashedFiles, QString& stashName, bool &revertFiles);
|
||||
static bool runCommit(QWidget* parent, QStringList& files, QString& commitMsg, const QStringList &commitMsgHistory, QString& branchName, bool& privateBranch);
|
||||
|
||||
private slots:
|
||||
void on_comboBox_activated(int index);
|
||||
void on_listView_doubleClicked(const QModelIndex &index);
|
||||
void on_listView_clicked(const QModelIndex &index);
|
||||
void on_chkNewBranch_toggled(bool checked);
|
||||
|
||||
private:
|
||||
Ui::CommitDialog *ui;
|
||||
|
@@ -227,7 +227,7 @@ bool Fossil::commitFiles(const QStringList& fileList, const QString& comment, co
|
||||
// Commit to new branch
|
||||
if(!newBranchName.isEmpty())
|
||||
{
|
||||
params << "--branch" << newBranchName;
|
||||
params << "--branch" << newBranchName.trimmed();
|
||||
|
||||
// Private branches are not synced with remotes
|
||||
if(isPrivateBranch)
|
||||
|
@@ -1358,7 +1358,9 @@ void MainWindow::on_actionCommit_triggered()
|
||||
QStringList commit_msgs = settings.GetValue(FUEL_SETTING_COMMIT_MSG).toStringList();
|
||||
|
||||
QString msg;
|
||||
bool aborted = !CommitDialog::runCommit(this, commit_files, msg, commit_msgs);
|
||||
QString branch_name="";
|
||||
bool private_branch = false;
|
||||
bool aborted = !CommitDialog::runCommit(this, commit_files, msg, commit_msgs, branch_name, private_branch);
|
||||
|
||||
// Aborted or not we always keep the commit messages.
|
||||
// (This has saved me way too many times on TortoiseSVN)
|
||||
@@ -1388,10 +1390,6 @@ void MainWindow::on_actionCommit_triggered()
|
||||
if(commit_files.size() != all_modified_files.size())
|
||||
files = commit_files;
|
||||
|
||||
// FIXME: add UI
|
||||
QString branch_name="";
|
||||
bool private_branch = false;
|
||||
|
||||
fossil().commitFiles(files, msg, branch_name, private_branch);
|
||||
refresh();
|
||||
}
|
||||
|
Reference in New Issue
Block a user