Skip to content

Commit

Permalink
fix #121746: ask for confirmation before deleting a workspace
Browse files Browse the repository at this point in the history
and change Qt's `foreach(a, b)` to C++11's `for (a : b)`
Also improve the delete palette message
  • Loading branch information
Jojo-Schmitz authored and lasconic committed Aug 22, 2016
1 parent 7a42f74 commit 47519e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mscore/palettebox.cpp
Expand Up @@ -114,7 +114,7 @@ void PaletteBox::updateWorkspaces()
const QList<Workspace*> pl = Workspace::workspaces();
int idx = 0;
int curIdx = -1;
foreach (Workspace* p, pl) {
for (Workspace* p : pl) {
workspaceList->addItem(qApp->translate("Ms::Workspace", p->name().toUtf8()), p->path());
if (p->name() == preferences.workspace)
curIdx = idx;
Expand Down Expand Up @@ -193,8 +193,8 @@ void PaletteBox::paletteCmd(PaletteCommand cmd, int slot)
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(0,
QWidget::tr("Warning"),
QWidget::tr("Are you sure?"),
QWidget::tr("Do you really want to delete the '%1' palette?").arg(palette->name()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
Expand Down
33 changes: 22 additions & 11 deletions mscore/workspace.cpp
Expand Up @@ -68,13 +68,13 @@ void MuseScore::showWorkspaceMenu()
connect(workspaces, SIGNAL(triggered(QAction*)), SLOT(changeWorkspace(QAction*)));
}
else {
foreach(QAction* a, workspaces->actions())
for (QAction* a : workspaces->actions())
workspaces->removeAction(a);
}
menuWorkspaces->clear();

const QList<Workspace*> pl = Workspace::workspaces();
foreach (Workspace* p, pl) {
for (Workspace* p : pl) {
QAction* a = workspaces->addAction(qApp->translate("Ms::Workspace", p->name().toUtf8()));
a->setCheckable(true);
a->setData(p->path());
Expand Down Expand Up @@ -111,7 +111,7 @@ void MuseScore::createNewWorkspace()
s = s.replace( QRegExp( "[" + QRegExp::escape( "\\/:*?\"<>|" ) + "]" ), "_" ); //FAT/NTFS special chars
for (;;) {
bool notFound = true;
foreach(Workspace* p, Workspace::workspaces()) {
for (Workspace* p : Workspace::workspaces()) {
if ((qApp->translate("Ms::Workspace", p->name().toUtf8()).toLower() == s.toLower()) ||
(s.toLower() == QString("basic")) || (s.toLower() == QString("advanced"))) {
notFound = false;
Expand Down Expand Up @@ -152,14 +152,25 @@ void MuseScore::deleteWorkspace()
return;
preferences.dirty = true;
Workspace* workspace = 0;
foreach(Workspace* p, Workspace::workspaces()) {
for (Workspace* p : Workspace::workspaces()) {
if (p->name() == a->text()) { // no need for qApp->translate since "Basic" and "Advanced" are not deletable
workspace = p;
break;
}
}
if (!workspace)
return;

QMessageBox::StandardButton reply;
reply = QMessageBox::question(0,
QWidget::tr("Are you sure?"),
QWidget::tr("Do you really want to delete the '%1' workspace?").arg(workspace->name()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
if (reply != QMessageBox::Yes)
return;

Workspace::workspaces().removeOne(workspace);
QFile f(workspace->path());
f.remove();
Expand Down Expand Up @@ -209,7 +220,7 @@ void MuseScore::changeWorkspace(Workspace* p)

void Workspace::initWorkspace()
{
foreach(Workspace* p, Workspace::workspaces()) {
for (Workspace* p : Workspace::workspaces()) {
if (p->name() == preferences.workspace) {
currentWorkspace = p;
break;
Expand Down Expand Up @@ -274,7 +285,7 @@ void Workspace::write()
xml.stag("rootfiles");
xml.stag(QString("rootfile full-path=\"%1\"").arg(Xml::xmlString("workspace.xml")));
xml.etag();
foreach (ImageStoreItem* ip, imageStore) {
for (ImageStoreItem* ip : imageStore) {
if (!ip->isUsed(gscore))
continue;
QString dstPath = QString("Pictures/") + ip->hashName();
Expand All @@ -286,7 +297,7 @@ void Workspace::write()
f.addFile("META-INF/container.xml", cbuf.data());

// save images
foreach(ImageStoreItem* ip, imageStore) {
for (ImageStoreItem* ip : imageStore) {
if (!ip->isUsed(gscore))
continue;
QString dstPath = QString("Pictures/") + ip->hashName();
Expand Down Expand Up @@ -347,7 +358,7 @@ void Workspace::read()
//
// load images
//
foreach(const QString& s, images)
for (const QString& s : images)
imageStore.add(s, f.fileData(s));

if (rootfile.isEmpty()) {
Expand Down Expand Up @@ -417,15 +428,15 @@ QList<Workspace*>& Workspace::workspaces()
QStringList nameFilters;
nameFilters << "*.workspace";

foreach (const QString& s, path) {
for (const QString& s : path) {
QDir dir(s);
QStringList pl = dir.entryList(nameFilters, QDir::Files, QDir::Name);

foreach (const QString& entry, pl) {
Workspace* p = 0;
QFileInfo fi(s + "/" + entry);
QString name(fi.completeBaseName());
foreach (Workspace* w, _workspaces) {
for (Workspace* w : _workspaces) {
if (w->name() == name) {
p = w;
break;
Expand Down Expand Up @@ -461,7 +472,7 @@ Workspace* Workspace::createNewWorkspace(const QString& name)

PaletteBox* paletteBox = mscore->getPaletteBox();
QList<Palette*> pl = paletteBox->palettes();
foreach (Palette* p, pl) {
for (Palette* p : pl) {
p->setSystemPalette(false);
for (int i = 0; i < p->size(); ++i)
p->setCellReadOnly(i, false);
Expand Down

0 comments on commit 47519e5

Please sign in to comment.