Skip to content

Commit

Permalink
fix #311405 Save new workspaces by translatable name if it possible, …
Browse files Browse the repository at this point in the history
…otherwise by name
  • Loading branch information
Eism authored and vpereverzev committed Oct 9, 2020
1 parent 6339f82 commit 186bf15
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mscore/prefsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ void PreferenceDialog::apply()

if(uiStyleThemeChanged) {
WorkspacesManager::retranslateAll();
preferences.setPreference(PREF_APP_WORKSPACE, WorkspacesManager::currentWorkspace()->translatableName());
preferences.setPreference(PREF_APP_WORKSPACE, WorkspacesManager::currentWorkspace()->id());
WorkspacesManager::currentWorkspace()->save();
emit mscore->workspacesChanged();
}
Expand Down
21 changes: 16 additions & 5 deletions mscore/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void MuseScore::changeWorkspace(Workspace* p, bool first)

connect(getPaletteWorkspace(), &PaletteWorkspace::userPaletteChanged, WorkspacesManager::currentWorkspace(), QOverload<>::of(&Workspace::setDirty), Qt::UniqueConnection);

preferences.setPreference(PREF_APP_WORKSPACE, p->translatableName());
preferences.setPreference(PREF_APP_WORKSPACE, p->id());
emit mscore->workspacesChanged();
}

Expand Down Expand Up @@ -272,10 +272,16 @@ bool WorkspacesManager::isDefaultEditedWorkspace(Workspace* workspace)
void WorkspacesManager::initCurrentWorkspace()
{
initWorkspaces();
m_currentWorkspace = findByName(preferences.getString(PREF_APP_WORKSPACE));

QString workspaceName = preferences.getString(PREF_APP_WORKSPACE);
m_currentWorkspace = findByName(workspaceName);
Q_ASSERT(!workspaces().empty());
if (m_currentWorkspace == 0)
m_currentWorkspace = workspaces().at(0);
if (!m_currentWorkspace) {
m_currentWorkspace = findByTranslatableName(workspaceName);
if (!m_currentWorkspace) {
m_currentWorkspace = workspaces().at(0);
}
}
}

void WorkspacesManager::remove(Workspace* workspace)
Expand Down Expand Up @@ -317,6 +323,11 @@ Workspace::Workspace()
connect(&_saveTimer, &QTimer::timeout, this, &Workspace::ensureWorkspaceSaved);
}

QString Workspace::id() const
{
return !_translatableName.isEmpty() ? _translatableName : _name;
}

//---------------------------------------------------------
// makeUserWorkspacePath
/// Returns path for the workspace with the given \p name
Expand Down Expand Up @@ -1094,7 +1105,7 @@ void Workspace::ensureWorkspaceSaved()
Q_ASSERT(!_readOnly);

WorkspacesManager::refreshWorkspaces();
preferences.setPreference(PREF_APP_WORKSPACE, translatableName());
preferences.setPreference(PREF_APP_WORKSPACE, id());
emit mscore->workspacesChanged();
}
else
Expand Down
1 change: 1 addition & 0 deletions mscore/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Workspace : public QObject {
Workspace(const QString& n, const QString& p, bool d, bool r)
: _name(n), _path(p), _dirty(d), _readOnly(r) {}

QString id() const;
QString path() const { return _path; }
void setPath(const QString& s) { _path = s; }
QString name() const { return _name; }
Expand Down
2 changes: 1 addition & 1 deletion mscore/workspacecombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void WorkspaceComboBox::updateWorkspaces()
int curIdx = -1;
for (Workspace* p : pl) {
addItem(qApp->translate("Ms::Workspace", p->name().toUtf8()), p->path());
if (p->name() == preferences.getString(PREF_APP_WORKSPACE))
if (p->id() == preferences.getString(PREF_APP_WORKSPACE))
curIdx = idx;
++idx;
}
Expand Down
4 changes: 2 additions & 2 deletions mscore/workspacedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ void WorkspaceDialog::accepted()
mscore->changeWorkspace(newWorkspace);
preferences.updateLocalPreferences();
}
preferences.setPreference(PREF_APP_WORKSPACE, WorkspacesManager::currentWorkspace()->translatableName());

preferences.setPreference(PREF_APP_WORKSPACE, WorkspacesManager::currentWorkspace()->id());
emit mscore->workspacesChanged();
close();
}
Expand Down

0 comments on commit 186bf15

Please sign in to comment.