mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-14 04:32:14 +00:00
GH-336 New rename UI with optional folder rename
This commit is contained in:
@@ -145,6 +145,8 @@ SET(MULTIMC_SOURCES
|
|||||||
# GUI - dialogs
|
# GUI - dialogs
|
||||||
dialogs/AboutDialog.cpp
|
dialogs/AboutDialog.cpp
|
||||||
dialogs/AboutDialog.h
|
dialogs/AboutDialog.h
|
||||||
|
dialogs/CheckableInputDialog.cpp
|
||||||
|
dialogs/CheckableInputDialog.h
|
||||||
dialogs/ProfileSelectDialog.cpp
|
dialogs/ProfileSelectDialog.cpp
|
||||||
dialogs/ProfileSelectDialog.h
|
dialogs/ProfileSelectDialog.h
|
||||||
dialogs/CopyInstanceDialog.cpp
|
dialogs/CopyInstanceDialog.cpp
|
||||||
@@ -258,6 +260,7 @@ SET(MULTIMC_UIS
|
|||||||
pages/modplatform/ImportPage.ui
|
pages/modplatform/ImportPage.ui
|
||||||
|
|
||||||
# Dialogs
|
# Dialogs
|
||||||
|
dialogs/CheckableInputDialog.ui
|
||||||
dialogs/CopyInstanceDialog.ui
|
dialogs/CopyInstanceDialog.ui
|
||||||
dialogs/NewComponentDialog.ui
|
dialogs/NewComponentDialog.ui
|
||||||
dialogs/NewInstanceDialog.ui
|
dialogs/NewInstanceDialog.ui
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <QtWidgets/QAction>
|
#include <QtWidgets/QAction>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <QtWidgets/QButtonGroup>
|
#include <QtWidgets/QButtonGroup>
|
||||||
|
#include <QtWidgets/QCheckBox>
|
||||||
#include <QtWidgets/QHBoxLayout>
|
#include <QtWidgets/QHBoxLayout>
|
||||||
#include <QtWidgets/QHeaderView>
|
#include <QtWidgets/QHeaderView>
|
||||||
#include <QtWidgets/QMainWindow>
|
#include <QtWidgets/QMainWindow>
|
||||||
@@ -74,6 +75,7 @@
|
|||||||
#include "groupview/InstanceDelegate.h"
|
#include "groupview/InstanceDelegate.h"
|
||||||
#include "widgets/LabeledToolButton.h"
|
#include "widgets/LabeledToolButton.h"
|
||||||
#include "widgets/ServerStatus.h"
|
#include "widgets/ServerStatus.h"
|
||||||
|
#include "dialogs/CheckableInputDialog.h"
|
||||||
#include "dialogs/NewInstanceDialog.h"
|
#include "dialogs/NewInstanceDialog.h"
|
||||||
#include "dialogs/ProgressDialog.h"
|
#include "dialogs/ProgressDialog.h"
|
||||||
#include "dialogs/AboutDialog.h"
|
#include "dialogs/AboutDialog.h"
|
||||||
@@ -1364,6 +1366,7 @@ void MainWindow::finalizeInstance(InstancePtr inst)
|
|||||||
});
|
});
|
||||||
if(update)
|
if(update)
|
||||||
{
|
{
|
||||||
|
loadDialog.setSkipButton(true, tr("Abort"));
|
||||||
loadDialog.setSkipButton(true, tr("Abort"));
|
loadDialog.setSkipButton(true, tr("Abort"));
|
||||||
loadDialog.execWithTask(update.get());
|
loadDialog.execWithTask(update.get());
|
||||||
}
|
}
|
||||||
@@ -1691,7 +1694,15 @@ void MainWindow::on_actionRenameInstance_triggered()
|
|||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance)
|
||||||
{
|
{
|
||||||
view->edit(view->currentIndex());
|
CheckableInputDialog dialog(this);
|
||||||
|
dialog.setWindowTitle(tr("Rename"));
|
||||||
|
dialog.setText(tr("Enter new name for the instance:"));
|
||||||
|
dialog.setCheckboxText(tr("Rename instance folder"));
|
||||||
|
dialog.setExtraText(tr("WARNING: Renaming the instance folder may break shortcuts and automation you made!"));
|
||||||
|
if(dialog.exec() == QDialog::Accepted && !dialog.getInput().isEmpty())
|
||||||
|
{
|
||||||
|
m_selectedInstance->setName(dialog.getInput(), dialog.checkboxChecked());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
application/dialogs/CheckableInputDialog.cpp
Normal file
41
application/dialogs/CheckableInputDialog.cpp
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include "CheckableInputDialog.h"
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "ui_CheckableInputDialog.h"
|
||||||
|
|
||||||
|
CheckableInputDialog::CheckableInputDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CheckableInputDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok), &QPushButton::clicked, this, &QDialog::accept);
|
||||||
|
connect(ui->buttonBox->button(QDialogButtonBox::StandardButton::Cancel), &QPushButton::clicked, this,
|
||||||
|
&QDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableInputDialog::setText(QString text)
|
||||||
|
{
|
||||||
|
ui->label->setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableInputDialog::setExtraText(QString text)
|
||||||
|
{
|
||||||
|
ui->extraText->setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CheckableInputDialog::setCheckboxText(QString checkboxText)
|
||||||
|
{
|
||||||
|
ui->checkBox->setText(checkboxText);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckableInputDialog::checkboxChecked()
|
||||||
|
{
|
||||||
|
return ui->checkBox->checkState();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CheckableInputDialog::getInput()
|
||||||
|
{
|
||||||
|
return ui->lineEdit->text();
|
||||||
|
}
|
||||||
26
application/dialogs/CheckableInputDialog.h
Normal file
26
application/dialogs/CheckableInputDialog.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class CheckableInputDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CheckableInputDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CheckableInputDialog(QWidget *parent);
|
||||||
|
void setText(QString text);
|
||||||
|
void setExtraText(QString text);
|
||||||
|
void setCheckboxText(QString checkboxText);
|
||||||
|
|
||||||
|
bool checkboxChecked();
|
||||||
|
QString getInput();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CheckableInputDialog *ui;
|
||||||
|
|
||||||
|
};
|
||||||
94
application/dialogs/CheckableInputDialog.ui
Normal file
94
application/dialogs/CheckableInputDialog.ui
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CheckableInputDialog</class>
|
||||||
|
<widget class="QDialog" name="CheckableInputDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>186</width>
|
||||||
|
<height>112</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>CheckBox</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="extraText">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>CheckableInputDialog</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>CheckableInputDialog</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>
|
||||||
@@ -341,82 +341,4 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoReturnTextEdit: public QTextEdit
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit NoReturnTextEdit(QWidget *parent) : QTextEdit(parent)
|
|
||||||
{
|
|
||||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
|
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
|
|
||||||
}
|
|
||||||
bool event(QEvent * event) override
|
|
||||||
{
|
|
||||||
auto eventType = event->type();
|
|
||||||
if(eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease)
|
|
||||||
{
|
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
||||||
auto key = keyEvent->key();
|
|
||||||
if (key == Qt::Key_Return || key == Qt::Key_Enter)
|
|
||||||
{
|
|
||||||
emit editingDone();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(key == Qt::Key_Tab)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QTextEdit::event(event);
|
|
||||||
}
|
|
||||||
signals:
|
|
||||||
void editingDone();
|
|
||||||
};
|
|
||||||
|
|
||||||
void ListViewDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
const int iconSize = 48;
|
|
||||||
QRect textRect = option.rect;
|
|
||||||
// QStyle *style = option.widget ? option.widget->style() : QApplication::style();
|
|
||||||
textRect.adjust(0, iconSize + 5, 0, 0);
|
|
||||||
editor->setGeometry(textRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ListViewDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
auto text = index.data(Qt::EditRole).toString();
|
|
||||||
QTextEdit * realeditor = qobject_cast<NoReturnTextEdit *>(editor);
|
|
||||||
realeditor->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
|
||||||
realeditor->append(text);
|
|
||||||
realeditor->selectAll();
|
|
||||||
realeditor->document()->clearUndoRedoStacks();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ListViewDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
QTextEdit * realeditor = qobject_cast<NoReturnTextEdit *>(editor);
|
|
||||||
QString text = realeditor->toPlainText();
|
|
||||||
text.replace(QChar('\n'), QChar(' '));
|
|
||||||
text = text.trimmed();
|
|
||||||
if(text.size() != 0)
|
|
||||||
{
|
|
||||||
model->setData(index, text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget * ListViewDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
auto editor = new NoReturnTextEdit(parent);
|
|
||||||
connect(editor, &NoReturnTextEdit::editingDone, this, &ListViewDelegate::editingDone);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ListViewDelegate::editingDone()
|
|
||||||
{
|
|
||||||
NoReturnTextEdit *editor = qobject_cast<NoReturnTextEdit *>(sender());
|
|
||||||
emit commitData(editor);
|
|
||||||
emit closeEditor(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "InstanceDelegate.moc"
|
#include "InstanceDelegate.moc"
|
||||||
|
|||||||
@@ -28,12 +28,4 @@ public:
|
|||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
|
||||||
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
|
||||||
|
|
||||||
void setEditorData(QWidget * editor, const QModelIndex & index) const override;
|
|
||||||
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void editingDone();
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user