GUI: Have separate setting for editor app path and params.
Currently combined editor application path + params is a bit problematic (at least in Windows). We really don't know where the app path ends and parameters start. So proper quoting is not always possible. And application path and command line parameters are clearly different settings anyway. So make them separate settings. It has bunch of other positive sides too. Like one can now browse new path for the application without loosing the parameters. When starting Cppcheck version with these new settings user is warned that loading settings had problems and asked to check and fix the settings.
This commit is contained in:
parent
f34e9e6623
commit
1f7d9145b0
|
@ -10,7 +10,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>569</width>
|
||||
<height>300</height>
|
||||
<height>303</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -54,13 +54,23 @@ kate -l(line) (file)</string>
|
|||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Command to execute:</string>
|
||||
<string>Executable:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>mPath</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Parameters:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>mParameters</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -71,6 +81,9 @@ kate -l(line) (file)</string>
|
|||
<item>
|
||||
<widget class="QLineEdit" name="mPath"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mParameters"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -114,8 +127,9 @@ kate -l(line) (file)</string>
|
|||
<tabstops>
|
||||
<tabstop>mName</tabstop>
|
||||
<tabstop>mPath</tabstop>
|
||||
<tabstop>mButtonBrowse</tabstop>
|
||||
<tabstop>mParameters</tabstop>
|
||||
<tabstop>mButtons</tabstop>
|
||||
<tabstop>mButtonBrowse</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
ApplicationDialog::ApplicationDialog(const QString &name,
|
||||
const QString &path,
|
||||
const QString ¶ms,
|
||||
const QString &title,
|
||||
QWidget *parent) :
|
||||
QDialog(parent)
|
||||
|
@ -38,6 +39,7 @@ ApplicationDialog::ApplicationDialog(const QString &name,
|
|||
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
mUI.mPath->setText(path);
|
||||
mUI.mName->setText(name);
|
||||
mUI.mParameters->setText(params);
|
||||
setWindowTitle(title);
|
||||
}
|
||||
|
||||
|
@ -88,13 +90,19 @@ QString ApplicationDialog::GetPath()
|
|||
return mUI.mPath->text();
|
||||
}
|
||||
|
||||
QString ApplicationDialog::GetParams()
|
||||
{
|
||||
return mUI.mParameters->text();
|
||||
}
|
||||
|
||||
void ApplicationDialog::Ok()
|
||||
{
|
||||
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty())
|
||||
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty() ||
|
||||
mUI.mParameters->text().isEmpty())
|
||||
{
|
||||
QMessageBox msg(QMessageBox::Warning,
|
||||
tr("Cppcheck"),
|
||||
tr("You must specify a name and a path for the application!"),
|
||||
tr("You must specify a name, a path and parameters for the application!"),
|
||||
QMessageBox::Ok,
|
||||
this);
|
||||
|
||||
|
|
|
@ -44,11 +44,13 @@ public:
|
|||
*
|
||||
* @param name Default name for the application to start
|
||||
* @param path Path for the application
|
||||
* @param params Params for the application
|
||||
* @param title Title for the dialog
|
||||
* @param parent Parent widget
|
||||
*/
|
||||
ApplicationDialog(const QString &name,
|
||||
const QString &path,
|
||||
const QString ¶ms,
|
||||
const QString &title,
|
||||
QWidget *parent = 0);
|
||||
virtual ~ApplicationDialog();
|
||||
|
@ -64,10 +66,18 @@ public:
|
|||
|
||||
/**
|
||||
* @brief Get modified path
|
||||
* This also contains all parameters user wants to specify.
|
||||
* This contains the full path to the application executable.
|
||||
* @return Modified path
|
||||
*/
|
||||
QString GetPath();
|
||||
|
||||
/**
|
||||
* @brief Get modified parameters
|
||||
* This contains the parameters given to the application.
|
||||
* @return Modified path
|
||||
*/
|
||||
QString GetParams();
|
||||
|
||||
protected slots:
|
||||
void Ok();
|
||||
|
||||
|
|
|
@ -38,28 +38,39 @@ ApplicationList::~ApplicationList()
|
|||
Clear();
|
||||
}
|
||||
|
||||
void ApplicationList::LoadSettings(QSettings *programSettings)
|
||||
bool ApplicationList::LoadSettings(QSettings *programSettings)
|
||||
{
|
||||
|
||||
QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, QStringList()).toStringList();
|
||||
QStringList paths = programSettings->value(SETTINGS_APPLICATION_PATHS, QStringList()).toStringList();
|
||||
QStringList params = programSettings->value(SETTINGS_APPLICATION_PARAMS, QStringList()).toStringList();
|
||||
int defapp = programSettings->value(SETTINGS_APPLICATION_DEFAULT, -1).toInt();
|
||||
|
||||
if (names.empty() && paths.empty())
|
||||
// Params will be empty first time starting with the new setting.
|
||||
// Return false and inform user about problem with application settings.
|
||||
bool succeeded = true;
|
||||
if (params.empty())
|
||||
{
|
||||
for (int i = 0; i < paths.length(); i++)
|
||||
params << "";
|
||||
succeeded = false;
|
||||
}
|
||||
|
||||
if (names.empty() && paths.empty() && params.empty())
|
||||
{
|
||||
do
|
||||
{
|
||||
// use as default for gnome environments
|
||||
if (QFileInfo("/usr/bin/gedit").isExecutable())
|
||||
{
|
||||
AddApplication("gedit", "/usr/bin/gedit +(line) (file)");
|
||||
AddApplication("gedit", "/usr/bin/gedit", "+(line) (file)");
|
||||
defapp = 0;
|
||||
break;
|
||||
}
|
||||
// use as default for kde environments
|
||||
if (QFileInfo("/usr/bin/kate").isExecutable())
|
||||
{
|
||||
AddApplication("kate", "/usr/bin/kate -l(line) (file)");
|
||||
AddApplication("kate", "/usr/bin/kate", "-l(line) (file)");
|
||||
defapp = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -75,7 +86,7 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
|
|||
if (names.size() > 0 && (names.size() == paths.size()))
|
||||
{
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
AddApplication(names[i], paths[i]);
|
||||
AddApplication(names[i], paths[i], params[i]);
|
||||
|
||||
if (defapp == -1)
|
||||
mDefaultApplicationIndex = 0;
|
||||
|
@ -84,21 +95,25 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
|
|||
else
|
||||
mDefaultApplicationIndex = 0;
|
||||
}
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
void ApplicationList::SaveSettings(QSettings *programSettings)
|
||||
{
|
||||
QStringList names;
|
||||
QStringList paths;
|
||||
QStringList params;
|
||||
|
||||
for (int i = 0; i < GetApplicationCount(); i++)
|
||||
{
|
||||
names << GetApplicationName(i);
|
||||
paths << GetApplicationPath(i);
|
||||
params << GetApplicationParameters(i);
|
||||
}
|
||||
|
||||
programSettings->setValue(SETTINGS_APPLICATION_NAMES, names);
|
||||
programSettings->setValue(SETTINGS_APPLICATION_PATHS, paths);
|
||||
programSettings->setValue(SETTINGS_APPLICATION_PARAMS, params);
|
||||
programSettings->setValue(SETTINGS_APPLICATION_DEFAULT, mDefaultApplicationIndex);
|
||||
|
||||
}
|
||||
|
@ -126,21 +141,34 @@ QString ApplicationList::GetApplicationPath(const int index) const
|
|||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ApplicationList::GetApplicationParameters(const int index) const
|
||||
{
|
||||
if (index >= 0 && index < mApplications.size())
|
||||
{
|
||||
return mApplications[index].Parameters;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ApplicationList::SetApplication(const int index,
|
||||
const QString &name,
|
||||
const QString &path)
|
||||
const QString &path,
|
||||
const QString ¶meters)
|
||||
{
|
||||
if (index >= 0 && index < mApplications.size())
|
||||
{
|
||||
mApplications[index].Name = name;
|
||||
mApplications[index].Path = path;
|
||||
mApplications[index].Parameters = parameters;
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationList::AddApplication(const QString &name, const QString &path)
|
||||
void ApplicationList::AddApplication(const QString &name,
|
||||
const QString &path,
|
||||
const QString ¶meters)
|
||||
{
|
||||
if (name.isEmpty() || path.isEmpty())
|
||||
{
|
||||
|
@ -150,6 +178,7 @@ void ApplicationList::AddApplication(const QString &name, const QString &path)
|
|||
ApplicationType type;
|
||||
type.Name = name;
|
||||
type.Path = path;
|
||||
type.Parameters = parameters;
|
||||
mApplications << type;
|
||||
}
|
||||
|
||||
|
@ -176,7 +205,8 @@ void ApplicationList::Copy(const ApplicationList *list)
|
|||
Clear();
|
||||
for (int i = 0; i < list->GetApplicationCount(); i++)
|
||||
{
|
||||
AddApplication(list->GetApplicationName(i), list->GetApplicationPath(i));
|
||||
AddApplication(list->GetApplicationName(i), list->GetApplicationPath(i),
|
||||
list->GetApplicationParameters(i));
|
||||
}
|
||||
mDefaultApplicationIndex = list->GetDefaultApplication();
|
||||
}
|
||||
|
@ -193,7 +223,7 @@ bool ApplicationList::FindDefaultWindowsEditor()
|
|||
const QString notepadppPath = appPath + "\\Notepad++\\notepad++.exe";
|
||||
if (QFileInfo(notepadppPath).isExecutable())
|
||||
{
|
||||
AddApplication("Notepad++", "\"" + notepadppPath + "\" -n(line) (file)");
|
||||
AddApplication("Notepad++", "\"" + notepadppPath + "\"", "-n(line) (file)");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -201,7 +231,7 @@ bool ApplicationList::FindDefaultWindowsEditor()
|
|||
const QString notepadPath = windowsPath + "\\system32\\notepad.exe";
|
||||
if (QFileInfo(notepadPath).isExecutable())
|
||||
{
|
||||
AddApplication("Notepad", notepadPath + " (file)");
|
||||
AddApplication("Notepad", notepadPath, "(file)");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -62,10 +62,16 @@ public:
|
|||
QString Name;
|
||||
|
||||
/**
|
||||
* @brief Application's path and commandline arguments
|
||||
* @brief Application's path
|
||||
*
|
||||
*/
|
||||
QString Path;
|
||||
|
||||
/**
|
||||
* @brief Application's parameters
|
||||
*
|
||||
*/
|
||||
QString Parameters;
|
||||
} ApplicationType;
|
||||
|
||||
ApplicationList(QObject *parent = 0);
|
||||
|
@ -75,8 +81,11 @@ public:
|
|||
* @brief Load all applications
|
||||
*
|
||||
* @param programSettings QSettings to load application list from
|
||||
* @return true if loading succeeded, false if there is problem with
|
||||
* application list. Most probably because of older version settings need
|
||||
* to be upgraded.
|
||||
*/
|
||||
void LoadSettings(QSettings *programSettings);
|
||||
bool LoadSettings(QSettings *programSettings);
|
||||
|
||||
/**
|
||||
* @brief Save all applications
|
||||
|
@ -106,6 +115,14 @@ public:
|
|||
*/
|
||||
QString GetApplicationPath(const int index) const;
|
||||
|
||||
/**
|
||||
* @brief Get Application's parameters
|
||||
*
|
||||
* @param index of the application whose parameters to get
|
||||
* @return Application's parameters
|
||||
*/
|
||||
QString GetApplicationParameters(const int index) const;
|
||||
|
||||
/**
|
||||
* @brief Return the default application.
|
||||
* @return Index of the default application.
|
||||
|
@ -121,17 +138,20 @@ public:
|
|||
* @param index Index of the application to modify
|
||||
* @param name New name for the application
|
||||
* @param path New path for the application
|
||||
* @param parameters New parameters for the application
|
||||
*/
|
||||
void SetApplication(const int index, const QString &name,
|
||||
const QString &path);
|
||||
const QString &path, const QString ¶meters);
|
||||
|
||||
/**
|
||||
* @brief Add a new application
|
||||
*
|
||||
* @param name Name of the application
|
||||
* @param path Path to the application
|
||||
* @param parameters Parameters for the application
|
||||
*/
|
||||
void AddApplication(const QString &name, const QString &path);
|
||||
void AddApplication(const QString &name, const QString &path,
|
||||
const QString ¶meters);
|
||||
|
||||
/**
|
||||
* @brief Remove an application from the list
|
||||
|
|
|
@ -77,6 +77,7 @@ ShowTypes;
|
|||
#define SETTINGS_SAVE_FULL_PATH "Save full path"
|
||||
#define SETTINGS_APPLICATION_NAMES "Application names"
|
||||
#define SETTINGS_APPLICATION_PATHS "Application paths"
|
||||
#define SETTINGS_APPLICATION_PARAMS "Application parameters"
|
||||
#define SETTINGS_APPLICATION_DEFAULT "Default Application"
|
||||
#define SETTINGS_LANGUAGE "Application language"
|
||||
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
|
||||
|
|
|
@ -153,9 +153,24 @@ void MainWindow::LoadSettings()
|
|||
mUI.mToolBarMain->setVisible(mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool());
|
||||
mUI.mToolBarView->setVisible(mSettings->value(SETTINGS_TOOLBARS_VIEW_SHOW, true).toBool());
|
||||
|
||||
mApplications->LoadSettings(mSettings);
|
||||
|
||||
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, mTranslation->SuggestLanguage()).toString());
|
||||
|
||||
bool succeeded = mApplications->LoadSettings(mSettings);
|
||||
if (!succeeded)
|
||||
{
|
||||
QString msg = tr("There was a problem with loading the editor application settings.\n\n"
|
||||
"This is probably because the settings were changed between the Cppcheck versions. "
|
||||
"Please check (and fix) the editor application settings, otherwise the editor "
|
||||
"program might not start correctly.");
|
||||
QMessageBox msgBox(QMessageBox::Warning,
|
||||
tr("Cppcheck"),
|
||||
msg,
|
||||
QMessageBox::Ok,
|
||||
this);
|
||||
msgBox.exec();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::SaveSettings()
|
||||
|
|
|
@ -659,7 +659,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
|
|||
|
||||
QVariantMap data = target->data().toMap();
|
||||
|
||||
QString program = mApplications->GetApplicationPath(application);
|
||||
QString params = mApplications->GetApplicationParameters(application);
|
||||
|
||||
//Replace (file) with filename
|
||||
QString file = data["file"].toString();
|
||||
|
@ -697,19 +697,21 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
|
|||
file.append("\"");
|
||||
}
|
||||
|
||||
program.replace("(file)", file, Qt::CaseInsensitive);
|
||||
params.replace("(file)", file, Qt::CaseInsensitive);
|
||||
|
||||
QVariant line = data["line"];
|
||||
program.replace("(line)", QString("%1").arg(line.toInt()), Qt::CaseInsensitive);
|
||||
params.replace("(line)", QString("%1").arg(line.toInt()), Qt::CaseInsensitive);
|
||||
|
||||
program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
|
||||
program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
|
||||
params.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
|
||||
params.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
|
||||
|
||||
bool success = QProcess::startDetached(program);
|
||||
const QString program = mApplications->GetApplicationPath(application);
|
||||
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
|
||||
|
||||
bool success = QProcess::startDetached(cmdLine);
|
||||
if (!success)
|
||||
{
|
||||
QString app = mApplications->GetApplicationName(application);
|
||||
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(app);
|
||||
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
|
||||
|
||||
QMessageBox msgbox(this);
|
||||
msgbox.setWindowTitle("Cppcheck");
|
||||
|
|
|
@ -198,11 +198,12 @@ void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
|
|||
|
||||
void SettingsDialog::AddApplication()
|
||||
{
|
||||
ApplicationDialog dialog("", "", tr("Add a new application"), this);
|
||||
ApplicationDialog dialog("", "", "", tr("Add a new application"), this);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
mTempApplications->AddApplication(dialog.GetName(), dialog.GetPath());
|
||||
mTempApplications->AddApplication(dialog.GetName(), dialog.GetPath(),
|
||||
dialog.GetParams());
|
||||
mUI.mListWidget->addItem(dialog.GetName());
|
||||
}
|
||||
}
|
||||
|
@ -236,11 +237,14 @@ void SettingsDialog::EditApplication()
|
|||
|
||||
ApplicationDialog dialog(mTempApplications->GetApplicationName(row),
|
||||
mTempApplications->GetApplicationPath(row),
|
||||
mTempApplications->GetApplicationParameters(row),
|
||||
tr("Modify an application"), this);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
mTempApplications->SetApplication(row, dialog.GetName(), dialog.GetPath());
|
||||
mTempApplications->SetApplication(row, dialog.GetName(),
|
||||
dialog.GetPath(),
|
||||
dialog.GetParams());
|
||||
item->setText(dialog.GetName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue