Fix inconsistent behaviour when working with edited workspaces
* Introduce visible workspaces that are workspaces to be shown in GUI * Introduce method `findByTranslatableName` to be used when seeking `sourceWorkspace`
This commit is contained in:
parent
88d6c46df2
commit
3f1ee5df27
4 changed files with 29 additions and 22 deletions
|
@ -523,7 +523,7 @@ void MuseScore::preferencesChanged(bool fromWorkspace)
|
|||
|
||||
// change workspace
|
||||
if (!fromWorkspace && preferences.getString(PREF_APP_WORKSPACE) != WorkspacesManager::currentWorkspace()->name()) {
|
||||
Workspace* workspace = WorkspacesManager::find(preferences.getString(PREF_APP_WORKSPACE));
|
||||
Workspace* workspace = WorkspacesManager::findByName(preferences.getString(PREF_APP_WORKSPACE));
|
||||
|
||||
if (workspace)
|
||||
mscore->changeWorkspace(workspace);
|
||||
|
@ -888,7 +888,7 @@ bool MuseScore::uninstallExtension(QString extensionId)
|
|||
//If current worksapce is alive, do nothing
|
||||
//Select first available workspace in the list otherwise
|
||||
bool curWorkspaceDisappeared = false;
|
||||
if (WorkspacesManager::find(curWorkspaceName))
|
||||
if (WorkspacesManager::findByName(curWorkspaceName))
|
||||
curWorkspaceDisappeared = true;
|
||||
|
||||
if (curWorkspaceDisappeared)
|
||||
|
@ -7681,7 +7681,7 @@ int main(int argc, char* av[])
|
|||
setMscoreLocale(sw->language());
|
||||
Workspace::writeGlobalToolBar();
|
||||
Workspace::writeGlobalGUIState();
|
||||
Workspace* targetWorkspace = WorkspacesManager::find(sw->workspace());
|
||||
Workspace* targetWorkspace = WorkspacesManager::findByName(sw->workspace());
|
||||
if (targetWorkspace)
|
||||
mscore->changeWorkspace(targetWorkspace, true);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace Ms {
|
|||
bool WorkspacesManager::isWorkspacesListDirty = true;
|
||||
Workspace* WorkspacesManager::m_currentWorkspace = nullptr;
|
||||
QList<Workspace*> WorkspacesManager::m_workspaces {};
|
||||
QList<Workspace*> WorkspacesManager::m_visibleWorkspaces {};
|
||||
|
||||
QList<QPair<QAction*, QString>> Workspace::actionToStringList {};
|
||||
QList<QPair<QMenu* , QString>> Workspace::menuToStringList {};
|
||||
|
@ -154,7 +155,7 @@ void MuseScore::deleteWorkspace()
|
|||
if (!a)
|
||||
return;
|
||||
|
||||
Workspace* workspace = WorkspacesManager::find(a->text());
|
||||
Workspace* workspace = WorkspacesManager::findByName(a->text());
|
||||
if (!workspace)
|
||||
return;
|
||||
|
||||
|
@ -257,7 +258,7 @@ void MuseScore::updateIcons()
|
|||
void WorkspacesManager::initCurrentWorkspace()
|
||||
{
|
||||
initWorkspaces();
|
||||
m_currentWorkspace = find(preferences.getString(PREF_APP_WORKSPACE));
|
||||
m_currentWorkspace = findByName(preferences.getString(PREF_APP_WORKSPACE));
|
||||
Q_ASSERT(!workspaces().empty());
|
||||
if (m_currentWorkspace == 0)
|
||||
m_currentWorkspace = workspaces().at(0);
|
||||
|
@ -1104,10 +1105,6 @@ static QStringList findWorkspaceFiles()
|
|||
return workspaces;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// workspaces
|
||||
//---------------------------------------------------------
|
||||
|
||||
void WorkspacesManager::initWorkspaces()
|
||||
{
|
||||
if (!isWorkspacesListDirty)
|
||||
|
@ -1156,16 +1153,16 @@ void WorkspacesManager::initWorkspaces()
|
|||
m_workspaces.removeOne(old);
|
||||
|
||||
// Delete default workspaces if there are corresponding user-edited ones
|
||||
m_visibleWorkspaces = m_workspaces;
|
||||
for (Workspace* ew : editedWorkpaces) {
|
||||
const QString uneditedName = defaultWorkspaceTranslatableName(ew->translatableName());
|
||||
if (uneditedName.isEmpty())
|
||||
continue;
|
||||
|
||||
for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) {
|
||||
for (auto it = m_visibleWorkspaces.begin(); it != m_visibleWorkspaces.end(); ++it) {
|
||||
Workspace* w = *it;
|
||||
if (w->translatableName() == uneditedName) {
|
||||
m_workspaces.erase(it);
|
||||
delete w;
|
||||
m_visibleWorkspaces.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1208,12 +1205,11 @@ const Workspace* Workspace::sourceWorkspace() const
|
|||
if (translatableName() == sourceName || name() == sourceName)
|
||||
return this;
|
||||
|
||||
for (const Workspace* w : WorkspacesManager::workspaces()) {
|
||||
if (w->translatableName() == sourceName || w->name() == sourceName)
|
||||
return w;
|
||||
}
|
||||
|
||||
return WorkspacesManager::workspaces()[0];
|
||||
Workspace* sourceWorkspace = WorkspacesManager::findByName(sourceName);
|
||||
if (!sourceWorkspace)
|
||||
sourceWorkspace = WorkspacesManager::findByTranslatableName(sourceName);
|
||||
|
||||
return !!sourceWorkspace ? sourceWorkspace : WorkspacesManager::workspaces()[0];
|
||||
}
|
||||
|
||||
void WorkspacesManager::retranslate(QList<Workspace*>& workspacesList)
|
||||
|
|
|
@ -126,7 +126,7 @@ class WorkspacesManager {
|
|||
static void retranslate(QList<Workspace*>& workspacesList);
|
||||
static void retranslateAll();
|
||||
|
||||
static Workspace* find(const QString& name) {
|
||||
static Workspace* findByName(const QString& name) {
|
||||
for (auto w : m_workspaces) {
|
||||
if (w->name() == name)
|
||||
return w;
|
||||
|
@ -134,8 +134,16 @@ class WorkspacesManager {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static Workspace* findByTranslatableName(const QString& name) {
|
||||
for (auto w : m_workspaces) {
|
||||
if (w->translatableName() == name)
|
||||
return w;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void remove(const QString& name) {
|
||||
m_workspaces.removeOne(find(name));
|
||||
m_workspaces.removeOne(findByName(name));
|
||||
}
|
||||
|
||||
static const QList<Workspace*>& workspaces() {
|
||||
|
@ -144,6 +152,8 @@ class WorkspacesManager {
|
|||
return m_workspaces;
|
||||
}
|
||||
|
||||
static const QList<Workspace*>& visibleWorkspaces() { return m_visibleWorkspaces; }
|
||||
|
||||
//replace with `const Workspace*` in future
|
||||
static Workspace* currentWorkspace() { return m_currentWorkspace; }
|
||||
static void setCurrentWorkspace(Workspace* currWorkspace) { m_currentWorkspace = currWorkspace; }
|
||||
|
@ -152,6 +162,7 @@ class WorkspacesManager {
|
|||
|
||||
private:
|
||||
static QList<Workspace*> m_workspaces;
|
||||
static QList<Workspace*> m_visibleWorkspaces;
|
||||
static Workspace* m_currentWorkspace;
|
||||
static bool isWorkspacesListDirty;
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ void WorkspaceComboBox::updateWorkspaces()
|
|||
return;
|
||||
|
||||
clear();
|
||||
const QList<Workspace*> pl = WorkspacesManager::workspaces();
|
||||
const QList<Workspace*> pl = WorkspacesManager::visibleWorkspaces();
|
||||
int idx = 0;
|
||||
int curIdx = -1;
|
||||
for (Workspace* p : pl) {
|
||||
|
@ -103,7 +103,7 @@ void WorkspaceComboBox::workspaceSelected(int idx)
|
|||
if (idx < 0)
|
||||
return;
|
||||
|
||||
Workspace* w = WorkspacesManager::workspaces().at(idx);
|
||||
Workspace* w = WorkspacesManager::visibleWorkspaces().at(idx);
|
||||
if (w != WorkspacesManager::currentWorkspace()) {
|
||||
blockUpdateWorkspaces = true;
|
||||
_mscore->changeWorkspace(w);
|
||||
|
|
Loading…
Reference in a new issue