Commit c3bf38fe authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Use QInputDialog + fix adding file to project


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 8614644b
......@@ -22,62 +22,25 @@
#include <QClipboard>
#include <QFileInfo>
#include <QIcon>
#include <QLineEdit>
#include <QInputDialog>
#include <QMenu>
#include <QMimeDatabase>
#include <QMimeType>
#include <QPushButton>
#include <QStandardPaths>
#include <QVBoxLayout>
class AskNameDialog : public QDialog
static QString getName()
{
public:
struct Name {
Name(const QString &n, bool s)
: name{n}
, success{s}
{
}
QString name;
bool success = false;
};
AskNameDialog(QWidget *parent = nullptr)
: QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
layout->addWidget(&m_lineEdit);
QHBoxLayout *hl = new QHBoxLayout;
hl->addWidget(&m_addBtn);
hl->addWidget(&m_cancelBtn);
m_addBtn.setText(i18n("Add"));
m_cancelBtn.setText(i18n("Cancel"));
connect(&m_addBtn, &QPushButton::clicked, this, &QDialog::accept);
connect(&m_cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
layout->addLayout(hl);
}
Name askName()
{
int res = exec();
bool suc = res == QDialog::Accepted;
if (!suc || m_lineEdit.text().isEmpty()) {
return {{}, false};
}
return {m_lineEdit.text(), true};
QInputDialog dlg;
dlg.setOkButtonText(i18n("Add"));
dlg.setInputMode(QInputDialog::TextInput);
int res = dlg.exec();
bool suc = res == QDialog::Accepted;
if (!suc || dlg.textValue().isEmpty()) {
return {};
}
private:
QLineEdit m_lineEdit;
QPushButton m_addBtn;
QPushButton m_cancelBtn;
};
return dlg.textValue();
}
void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelIndex &index, const QPoint &pos, KateProjectViewTree *parent)
{
......@@ -179,17 +142,15 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
parent->edit(index);
} else if (action == fileHistory) {
showFileHistory(index.data(Qt::UserRole).toString());
} else if (action == addFile) {
AskNameDialog d;
auto name = d.askName();
if (name.success) {
parent->addFile(index, name.name);
} else if (addFile && action == addFile) {
QString name = getName();
if (!name.isEmpty()) {
parent->addFile(index, name);
}
} else if (action == addFolder) {
AskNameDialog d;
auto name = d.askName();
if (name.success) {
parent->addDirectory(index, name.name);
} else if (addFolder && action == addFolder) {
QString name = getName();
if (!name.isEmpty()) {
parent->addDirectory(index, name);
}
} else {
// One of the git actions was triggered
......
......@@ -136,7 +136,7 @@ void KateProjectViewTree::addFile(const QModelIndex &idx, const QString &fileNam
KateProjectItem *i = new KateProjectItem(KateProjectItem::File, fileName);
i->setData(fullFileName, Qt::UserRole);
item->appendRow(i);
m_project->addFile(fileName, i);
m_project->addFile(fullFileName, i);
item->sortChildren(0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment