File: workspacedialog.cpp

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 214,188 kB
  • sloc: cpp: 291,198; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 244; perl: 82; pascal: 79
file content (160 lines) | stat: -rw-r--r-- 5,672 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2002-2018 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#include "workspacedialog.h"
#include "workspace.h"
#include "preferences.h"
#include "musescore.h"
#include "palettebox.h"

namespace Ms {

//---------------------------------------------------------
//   createNewWorkspace
//---------------------------------------------------------

void MuseScore::createNewWorkspace()
      {
      if (!_workspaceDialog)
            _workspaceDialog = new WorkspaceDialog();

      _workspaceDialog->editMode = false;
      _workspaceDialog->display();
      updateIcons();
      }

//---------------------------------------------------------
//   editWorkspace
//---------------------------------------------------------

void MuseScore::editWorkspace()
      {
      if (!Workspace::currentWorkspace && !Workspace::currentWorkspace->readOnly())
            return;
      if (!_workspaceDialog)
            _workspaceDialog = new WorkspaceDialog();

      _workspaceDialog->editMode = true;
      _workspaceDialog->display();
      updateIcons();
      }

//---------------------------------------------------------
//   WorkspaceDialog
//---------------------------------------------------------

WorkspaceDialog::WorkspaceDialog(QWidget* parent)
   : QDialog(parent)
      {
      setObjectName("WorkspaceDialog");
      setupUi(this);
      retranslateUi(this);
      setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
      MuseScore::restoreGeometry(this);

      connect(buttonBox, SIGNAL(accepted()), SLOT(accepted()));
      connect(buttonBox, SIGNAL(rejected()), SLOT(close()));
      }

//---------------------------------------------------------
//   display
//---------------------------------------------------------

void WorkspaceDialog::display()
      {
      mscore->getPaletteBox()->searchBox()->clear();
      if (editMode) {
            componentsCheck->setChecked(Workspace::currentWorkspace->getSaveComponents());
            toolbarsCheck->setChecked(Workspace::currentWorkspace->getSaveToolbars());
            menubarCheck->setChecked(Workspace::currentWorkspace->getSaveMenuBar());
            prefsCheck->setChecked(preferences.getUseLocalPreferences());
            nameLineEdit->setText(Workspace::currentWorkspace->name());
            setWindowTitle(tr("Edit Workspace"));
            }
      else {
            componentsCheck->setChecked(false);
            toolbarsCheck->setChecked(false);
            menubarCheck->setChecked(false);
            prefsCheck->setChecked(false);
            nameLineEdit->setText("");
            setWindowTitle(tr("Create New Workspace"));
            }
      show();
      }

//---------------------------------------------------------
//   accepted
//---------------------------------------------------------

void WorkspaceDialog::accepted()
      {
      QString s = nameLineEdit->text();
      if (s.isEmpty())
            return;
      s = s.replace( QRegExp( "[" + QRegExp::escape( "\\/:*?\"<>|" ) + "]" ), "_" ); //FAT/NTFS special chars

      for (;;) {
            if (editMode && s == Workspace::currentWorkspace->name())
                  break;
            bool notFound = true;
            for (Workspace* p : Workspace::workspaces()) {
                  if ((qApp->translate("Ms::Workspace", p->name().toUtf8()).toLower() == s.toLower())) {
                        notFound = false;
                        break;
                        }
                  }
            if (!notFound) {
                  s = QInputDialog::getText(this,
                     tr("Read Workspace Name"),
                     tr("'%1' does already exist,\nplease choose a different name:").arg(s)
                     );
                  if (s.isEmpty())
                        return;
                  s = s.replace( QRegExp( "[" + QRegExp::escape( "\\/:*?\"<>|" ) + "]" ), "_" ); //FAT/NTFS special chars
                  }
            else
                  break;
            }

      if (!editMode) {
            if (Workspace::currentWorkspace->dirty())
                  Workspace::currentWorkspace->save();
            Workspace::currentWorkspace = Workspace::createNewWorkspace(s);
            preferences.updateLocalPreferences();
            }

      Workspace::currentWorkspace->setSaveComponents(componentsCheck->isChecked());
      Workspace::currentWorkspace->setSaveToolbars(toolbarsCheck->isChecked());
      Workspace::currentWorkspace->setSaveMenuBar(menubarCheck->isChecked());
      preferences.setUseLocalPreferences(prefsCheck->isChecked());
      Workspace::currentWorkspace->save();

      if (editMode && Workspace::currentWorkspace->name() != s)
            Workspace::currentWorkspace->rename(s);

      preferences.setPreference(PREF_APP_WORKSPACE, Workspace::currentWorkspace->name());
      PaletteBox* paletteBox = mscore->getPaletteBox();
      paletteBox->updateWorkspaces();
      close();
      }

//---------------------------------------------------------
//   changeEvent
//---------------------------------------------------------

void WorkspaceDialog::changeEvent(QEvent *event)
      {
      QWidget::changeEvent(event);
      if (event->type() == QEvent::LanguageChange)
            retranslate();
      }
}