mirror of
https://github.com/ModOrganizer2/modorganizer.git
synced 2026-07-27 13:58:24 -07:00
Allow user to select app icon or mo icon for generated shortcuts
Also fixes 'x' for toolbar not disappearing when it should Issue 701
This commit is contained in:
@@ -84,18 +84,25 @@ void EditExecutablesDialog::resetInput()
|
||||
ui->appIDOverwriteEdit->clear();
|
||||
ui->overwriteAppIDBox->setChecked(false);
|
||||
ui->closeCheckBox->setChecked(false);
|
||||
ui->useAppIconCheckBox->setChecked(false);
|
||||
m_CurrentItem = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void EditExecutablesDialog::saveExecutable()
|
||||
{
|
||||
m_ExecutablesList.addExecutable(ui->titleEdit->text(), QDir::fromNativeSeparators(ui->binaryEdit->text()),
|
||||
ui->argumentsEdit->text(), QDir::fromNativeSeparators(ui->workingDirEdit->text()),
|
||||
(ui->closeCheckBox->checkState() == Qt::Checked) ? ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
|
||||
: ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
|
||||
ui->overwriteAppIDBox->isChecked() ? ui->appIDOverwriteEdit->text() : "",
|
||||
true, false);
|
||||
m_ExecutablesList.addExecutable(ui->titleEdit->text(),
|
||||
QDir::fromNativeSeparators(ui->binaryEdit->text()),
|
||||
ui->argumentsEdit->text(),
|
||||
QDir::fromNativeSeparators(ui->workingDirEdit->text()),
|
||||
(ui->closeCheckBox->checkState() == Qt::Checked) ?
|
||||
ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
|
||||
: ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
|
||||
ui->overwriteAppIDBox->isChecked() ?
|
||||
ui->appIDOverwriteEdit->text() : "",
|
||||
true,
|
||||
false,
|
||||
ui->useAppIconCheckBox->isChecked());
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +214,8 @@ bool EditExecutablesDialog::executableChanged()
|
||||
|| selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text()
|
||||
|| selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text())
|
||||
|| selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text())
|
||||
|| (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked();
|
||||
|| (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked()
|
||||
|| selectedExecutable.m_UseOwnIcon != ui->useAppIconCheckBox->isChecked();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -288,5 +296,6 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur
|
||||
} else {
|
||||
ui->appIDOverwriteEdit->clear();
|
||||
}
|
||||
ui->useAppIconCheckBox->setChecked(selectedExecutable.m_UseOwnIcon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>362</height>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -164,21 +164,28 @@ Right now the only case I know of where this needs to be overwritten is for the
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="closeCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>If checked, MO will be closed once the specified executable is run.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>If checked, MO will be closed once the specified executable is run.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close MO when started</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useAppIconCheckBox">
|
||||
<property name="text">
|
||||
<string>Use Application's Icon for shortcuts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="closeCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>If checked, MO will be closed once the specified executable is run.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>If checked, MO will be closed once the specified executable is run.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close MO when started</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="toolTip">
|
||||
@@ -240,6 +247,10 @@ Right now the only case I know of where this needs to be overwritten is for the
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>executablesListBox</zorder>
|
||||
<zorder>closeButton</zorder>
|
||||
<zorder>closeCheckBox</zorder>
|
||||
<zorder>useAppIconCheckBox</zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
+15
-15
@@ -39,7 +39,7 @@ static QDataStream &operator<<(QDataStream &out, const Executable &obj)
|
||||
<< obj.m_SteamAppID
|
||||
<< obj.m_WorkingDirectory
|
||||
<< obj.m_Custom
|
||||
<< obj.m_Toolbar;
|
||||
<< obj.m_Toolbar << obj.m_UseOwnIcon;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ static QDataStream &operator>>(QDataStream &in, Executable &obj)
|
||||
QString binaryTemp;
|
||||
int closeStyleTemp;
|
||||
in >> obj.m_Title >> binaryTemp >> obj.m_Arguments >> closeStyleTemp
|
||||
>> obj.m_SteamAppID >> obj.m_WorkingDirectory >> obj.m_Custom >> obj.m_Toolbar;
|
||||
>> obj.m_SteamAppID >> obj.m_WorkingDirectory >> obj.m_Custom >> obj.m_Toolbar >> obj.m_UseOwnIcon;
|
||||
|
||||
obj.m_CloseMO = static_cast<ExecutableInfo::CloseMOStyle>(closeStyleTemp);
|
||||
obj.m_BinaryInfo.setFile(binaryTemp);
|
||||
@@ -166,9 +166,15 @@ void ExecutablesList::position(const QString &title, bool toolbar, int pos)
|
||||
}
|
||||
|
||||
|
||||
void ExecutablesList::addExecutable(const QString &title, const QString &executableName, const QString &arguments,
|
||||
const QString &workingDirectory, ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID,
|
||||
bool custom, bool toolbar, int pos)
|
||||
void ExecutablesList::addExecutable(const QString &title,
|
||||
const QString &executableName,
|
||||
const QString &arguments,
|
||||
const QString &workingDirectory,
|
||||
ExecutableInfo::CloseMOStyle closeMO,
|
||||
const QString &steamAppID,
|
||||
bool custom,
|
||||
bool toolbar,
|
||||
bool ownicon)
|
||||
{
|
||||
QFileInfo file(executableName);
|
||||
auto existingExe = findExe(title);
|
||||
@@ -184,11 +190,7 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
|
||||
existingExe->m_Arguments = arguments;
|
||||
existingExe->m_WorkingDirectory = workingDirectory;
|
||||
existingExe->m_SteamAppID = steamAppID;
|
||||
}
|
||||
if (pos >= 0) {
|
||||
Executable temp = *existingExe;
|
||||
m_Executables.erase(existingExe);
|
||||
m_Executables.insert(m_Executables.begin() + pos, temp);
|
||||
existingExe->m_UseOwnIcon = ownicon;
|
||||
}
|
||||
} else {
|
||||
Executable newExe;
|
||||
@@ -200,11 +202,8 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
|
||||
newExe.m_SteamAppID = steamAppID;
|
||||
newExe.m_Custom = true;
|
||||
newExe.m_Toolbar = toolbar;
|
||||
if ((pos < 0) || (pos >= static_cast<int>(m_Executables.size()))) {
|
||||
m_Executables.push_back(newExe);
|
||||
} else {
|
||||
m_Executables.insert(m_Executables.begin() + pos, newExe);
|
||||
}
|
||||
newExe.m_UseOwnIcon = ownicon;
|
||||
m_Executables.push_back(newExe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +234,7 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString
|
||||
newExe.m_SteamAppID = steamAppID;
|
||||
newExe.m_Custom = false;
|
||||
newExe.m_Toolbar = false;
|
||||
newExe.m_UseOwnIcon = false;
|
||||
m_Executables.push_back(newExe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ struct Executable {
|
||||
|
||||
bool m_Custom;
|
||||
bool m_Toolbar;
|
||||
bool m_UseOwnIcon;
|
||||
};
|
||||
|
||||
|
||||
@@ -121,7 +122,7 @@ public:
|
||||
**/
|
||||
void addExecutable(const QString &title, const QString &executableName, const QString &arguments,
|
||||
const QString &workingDirectory, MOBase::ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID,
|
||||
bool custom, bool toolbar, int pos = -1);
|
||||
bool custom, bool toolbar, bool ownicon);
|
||||
|
||||
/**
|
||||
* @brief change position of an executable which is expected to exist
|
||||
|
||||
+16
-2
@@ -1626,6 +1626,7 @@ void MainWindow::on_startButton_clicked()
|
||||
|
||||
static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments,
|
||||
LPCSTR linkFileName, LPCWSTR description,
|
||||
LPCTSTR iconFileName, int iconNumber,
|
||||
LPCWSTR currentDirectory)
|
||||
{
|
||||
HRESULT result = E_INVALIDARG;
|
||||
@@ -1676,6 +1677,15 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments,
|
||||
}
|
||||
}
|
||||
|
||||
if (iconFileName != nullptr) {
|
||||
result = shellLink->SetIconLocation(iconFileName, iconNumber);
|
||||
if (!SUCCEEDED(result)) {
|
||||
qCritical("failed to load program icon: %ls %d", iconFileName, iconNumber);
|
||||
shellLink->Release();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
IPersistFile *persistFile;
|
||||
result = shellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
|
||||
if (SUCCEEDED(result)) {
|
||||
@@ -3283,16 +3293,20 @@ void MainWindow::addWindowsLink(Shortcut_Type const mapping)
|
||||
} else {
|
||||
QFileInfo const exeInfo(qApp->applicationFilePath());
|
||||
// create link
|
||||
QString executable = QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath());
|
||||
|
||||
std::wstring targetFile = ToWString(exeInfo.absoluteFilePath());
|
||||
std::wstring parameter = ToWString(QString("\"%1\" %2").arg(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()))
|
||||
std::wstring parameter = ToWString(QString("\"%1\" %2").arg(executable)
|
||||
.arg(selectedExecutable.m_Arguments));
|
||||
std::wstring description = ToWString(selectedExecutable.m_BinaryInfo.fileName());
|
||||
std::wstring iconFile = ToWString(executable);
|
||||
std::wstring currentDirectory = ToWString(QDir::toNativeSeparators(exeInfo.absolutePath()));
|
||||
|
||||
if (CreateShortcut(targetFile.c_str()
|
||||
, parameter.c_str()
|
||||
, QDir::toNativeSeparators(linkName).toUtf8().constData()
|
||||
, description.c_str()
|
||||
, (selectedExecutable.m_UseOwnIcon ? iconFile.c_str() : nullptr), 0
|
||||
, currentDirectory.c_str()) == 0) {
|
||||
ui->linkButton->menu()->actions().at(static_cast<int>(mapping))->setIcon(QIcon(":/MO/gui/remove"));
|
||||
} else {
|
||||
@@ -3530,7 +3544,7 @@ void MainWindow::addAsExecutable()
|
||||
m_OrganizerCore.executablesList()->addExecutable(name, binaryInfo.absoluteFilePath(),
|
||||
arguments, targetInfo.absolutePath(),
|
||||
ExecutableInfo::CloseMOStyle::DEFAULT_STAY, QString(),
|
||||
true, false);
|
||||
true, false, false);
|
||||
refreshExecutablesList();
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -230,6 +230,7 @@ QSettings::Status OrganizerCore::storeSettings(const QString &fileName)
|
||||
settings.setValue("workingDirectory", item.m_WorkingDirectory);
|
||||
settings.setValue("closeOnStart", item.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE);
|
||||
settings.setValue("steamAppID", item.m_SteamAppID);
|
||||
settings.setValue("ownicon", item.m_UseOwnIcon);
|
||||
}
|
||||
}
|
||||
settings.endArray();
|
||||
@@ -336,7 +337,8 @@ void OrganizerCore::updateExecutablesList(QSettings &settings)
|
||||
closeMO,
|
||||
settings.value("steamAppID", "").toString(),
|
||||
settings.value("custom", true).toBool(),
|
||||
settings.value("toolbar", false).toBool());
|
||||
settings.value("toolbar", false).toBool(),
|
||||
settings.value("ownicon", false).toBool());
|
||||
}
|
||||
|
||||
settings.endArray();
|
||||
|
||||
Reference in New Issue
Block a user