mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-04 01:00:22 +00:00
Compare commits
4 Commits
stable
...
feature/re
Author | SHA1 | Date | |
---|---|---|---|
|
a21358e196 | ||
|
f711425bcf | ||
|
14c4df8427 | ||
|
9d6ad3d78a |
@@ -175,6 +175,11 @@ QString BaseInstance::instanceRoot() const
|
||||
return m_rootDir;
|
||||
}
|
||||
|
||||
void BaseInstance::setInstanceRoot(QString newRoot)
|
||||
{
|
||||
m_rootDir = std::move(newRoot);
|
||||
}
|
||||
|
||||
SettingsObjectPtr BaseInstance::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
@@ -225,11 +230,23 @@ QString BaseInstance::iconKey() const
|
||||
return m_settings->get("iconKey").toString();
|
||||
}
|
||||
|
||||
void BaseInstance::setName(QString val)
|
||||
void BaseInstance::setName(QString val, bool requestDirChange)
|
||||
{
|
||||
//FIXME: if no change, do not set. setting involves saving a file.
|
||||
if(m_settings->get("name") == val)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_settings->set("name", val);
|
||||
emit propertiesChanged(this);
|
||||
if(requestDirChange && !isRunning())
|
||||
{
|
||||
emit instanceDirChangeRequest(this);
|
||||
}
|
||||
else if(requestDirChange && isRunning())
|
||||
{
|
||||
qWarning() << "Tried to rename running instance with folder";
|
||||
}
|
||||
}
|
||||
|
||||
QString BaseInstance::name() const
|
||||
|
@@ -93,6 +93,8 @@ public:
|
||||
/// Path to the instance's root directory.
|
||||
QString instanceRoot() const;
|
||||
|
||||
void setInstanceRoot(QString newRoot);
|
||||
|
||||
/// Path to the instance's game root directory.
|
||||
virtual QString gameRoot() const
|
||||
{
|
||||
@@ -100,7 +102,7 @@ public:
|
||||
}
|
||||
|
||||
QString name() const;
|
||||
void setName(QString val);
|
||||
void setName(QString val, bool requestDirChange);
|
||||
|
||||
/// Value used for instance window titles
|
||||
QString windowTitle() const;
|
||||
@@ -245,6 +247,8 @@ signals:
|
||||
|
||||
void statusChanged(Status from, Status to);
|
||||
|
||||
void instanceDirChangeRequest(BaseInstance *inst);
|
||||
|
||||
protected slots:
|
||||
void iconUpdated(QString key);
|
||||
|
||||
|
@@ -44,7 +44,7 @@ void InstanceCopyTask::copyFinished()
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
||||
inst->setName(m_instName);
|
||||
inst->setName(m_instName, false);
|
||||
inst->setIconKey(m_instIcon);
|
||||
emitSucceeded();
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ void InstanceCreationTask::executeTask()
|
||||
auto components = inst.getComponentList();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
|
||||
inst.setName(m_instName);
|
||||
inst.setName(m_instName, false);
|
||||
inst.setIconKey(m_instIcon);
|
||||
instanceSettings->resumeSave();
|
||||
}
|
||||
|
@@ -293,7 +293,7 @@ void InstanceImportTask::processFlame()
|
||||
// nuke the original files
|
||||
FS::deletePath(jarmodsPath);
|
||||
}
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
|
||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
|
||||
{
|
||||
@@ -384,7 +384,7 @@ void InstanceImportTask::processMultiMC()
|
||||
instance.resetTimePlayed();
|
||||
|
||||
// set a new nice name
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
|
||||
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
||||
if (m_instIcon != "default")
|
||||
|
@@ -135,7 +135,7 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
||||
{
|
||||
return true;
|
||||
}
|
||||
pdata->setName(newName);
|
||||
pdata->setName(newName, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -396,6 +396,7 @@ void InstanceList::add(const QList<InstancePtr> &t)
|
||||
for(auto & ptr : t)
|
||||
{
|
||||
connect(ptr.get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
||||
connect(ptr.get(), &BaseInstance::instanceDirChangeRequest, this, &InstanceList::instanceDirUpdateRequested);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -469,6 +470,27 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::instanceDirUpdateRequested(BaseInstance *inst)
|
||||
{
|
||||
if(m_groupMap.remove(inst->id()))
|
||||
{
|
||||
saveGroupList();
|
||||
}
|
||||
|
||||
QString oldRoot = inst->instanceRoot();
|
||||
QString instID = FS::DirNameFromString(inst->name(), m_instDir);
|
||||
|
||||
QString destination = FS::PathCombine(m_instDir, instID);
|
||||
if(!QDir().rename(oldRoot, destination))
|
||||
{
|
||||
qWarning() << "Failed to move" << inst->instanceRoot() << "to" << destination;
|
||||
}
|
||||
|
||||
FS::deletePath(oldRoot);
|
||||
|
||||
loadList();
|
||||
}
|
||||
|
||||
InstancePtr InstanceList::loadInstance(const InstanceId& id)
|
||||
{
|
||||
if(!m_groupsLoaded)
|
||||
|
@@ -136,6 +136,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
void instanceDirUpdateRequested(BaseInstance *inst);
|
||||
void providerUpdated();
|
||||
void instanceDirContentsChanged(const QString &path);
|
||||
|
||||
|
@@ -66,7 +66,7 @@ void LegacyUpgradeTask::copyFinished()
|
||||
// NOTE: this scope ensures the instance is fully saved before we emitSucceeded
|
||||
{
|
||||
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
|
||||
inst.setName(m_instName);
|
||||
inst.setName(m_instName, false);
|
||||
|
||||
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
|
||||
if(preferredVersionNumber.isNull())
|
||||
|
@@ -186,7 +186,7 @@ void FtbPackInstallTask::install()
|
||||
|
||||
progress(4, 4);
|
||||
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
if(m_instIcon == "default")
|
||||
{
|
||||
m_instIcon = "ftb_logo";
|
||||
|
@@ -145,6 +145,8 @@ SET(MULTIMC_SOURCES
|
||||
# GUI - dialogs
|
||||
dialogs/AboutDialog.cpp
|
||||
dialogs/AboutDialog.h
|
||||
dialogs/CheckableInputDialog.cpp
|
||||
dialogs/CheckableInputDialog.h
|
||||
dialogs/ProfileSelectDialog.cpp
|
||||
dialogs/ProfileSelectDialog.h
|
||||
dialogs/CopyInstanceDialog.cpp
|
||||
@@ -258,6 +260,7 @@ SET(MULTIMC_UIS
|
||||
pages/modplatform/ImportPage.ui
|
||||
|
||||
# Dialogs
|
||||
dialogs/CheckableInputDialog.ui
|
||||
dialogs/CopyInstanceDialog.ui
|
||||
dialogs/NewComponentDialog.ui
|
||||
dialogs/NewInstanceDialog.ui
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QCheckBox>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
@@ -74,6 +75,7 @@
|
||||
#include "groupview/InstanceDelegate.h"
|
||||
#include "widgets/LabeledToolButton.h"
|
||||
#include "widgets/ServerStatus.h"
|
||||
#include "dialogs/CheckableInputDialog.h"
|
||||
#include "dialogs/NewInstanceDialog.h"
|
||||
#include "dialogs/ProgressDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
@@ -845,7 +847,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
||||
actionSep->setSeparator(true);
|
||||
|
||||
bool onInstance = view->indexAt(pos).isValid();
|
||||
if (onInstance)
|
||||
if (onInstance && m_selectedInstance)
|
||||
{
|
||||
actions = ui->instanceToolBar->actions();
|
||||
|
||||
@@ -1364,6 +1366,7 @@ void MainWindow::finalizeInstance(InstancePtr inst)
|
||||
});
|
||||
if(update)
|
||||
{
|
||||
loadDialog.setSkipButton(true, tr("Abort"));
|
||||
loadDialog.setSkipButton(true, tr("Abort"));
|
||||
loadDialog.execWithTask(update.get());
|
||||
}
|
||||
@@ -1691,7 +1694,15 @@ void MainWindow::on_actionRenameInstance_triggered()
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1820,6 +1831,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
||||
ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch());
|
||||
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
|
||||
ui->renameButton->setText(m_selectedInstance->name());
|
||||
ui->actionRenameInstance->setDisabled(m_selectedInstance->isRunning());
|
||||
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
||||
updateInstanceToolIcon(m_selectedInstance->iconKey());
|
||||
|
||||
|
46
application/dialogs/CheckableInputDialog.cpp
Normal file
46
application/dialogs/CheckableInputDialog.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
CheckableInputDialog::~CheckableInputDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
28
application/dialogs/CheckableInputDialog.h
Normal file
28
application/dialogs/CheckableInputDialog.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CheckableInputDialog;
|
||||
}
|
||||
|
||||
class CheckableInputDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheckableInputDialog(QWidget *parent);
|
||||
~CheckableInputDialog();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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"
|
||||
|
@@ -28,12 +28,4 @@ public:
|
||||
|
||||
void paint(QPainter *painter, 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