Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions qrgui/mainWindow/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void MainWindow::connectActions()
connect(mUi->actionSave, &QAction::triggered, this, &MainWindow::tryToSave);
connect(mUi->actionSave_as, &QAction::triggered, &*mProjectManager, &ProjectManagerWrapper::suggestToSaveAs);
connect(mUi->actionSave_diagram_as_a_picture, &QAction::triggered, this, &MainWindow::saveDiagramAsAPicture);
connect(mUi->actionSave_script, &QAction::triggered, this, &MainWindow::saveScript);
connect(mUi->actionPrint, &QAction::triggered, this, &MainWindow::print);
connect(mUi->actionMakeSvg, &QAction::triggered, this, &MainWindow::makeSvg);

Expand Down Expand Up @@ -1270,15 +1271,16 @@ void MainWindow::currentTabChanged(int newIndex)
const bool isStartTab = dynamic_cast<StartWidget *>(mUi->tabs->widget(newIndex));
const bool isGesturesTab = dynamic_cast<gestures::GesturesWidget *>(mUi->tabs->widget(newIndex));
const bool isDecorativeTab = isStartTab || isGesturesTab;
const bool isCodeTab = dynamic_cast<text::QScintillaTextEdit *>(mUi->tabs->widget(newIndex));

mUi->actionSave->setEnabled(!isDecorativeTab);
mUi->actionSave->setEnabled(!isDecorativeTab && !isCodeTab);
mUi->actionSave_as->setEnabled(!isDecorativeTab);
mUi->actionSave_diagram_as_a_picture->setEnabled(isEditorTab);
mUi->actionPrint->setEnabled(!isDecorativeTab);
mUi->actionFind->setEnabled(!isDecorativeTab);
mUi->actionFind_and_replace->setEnabled(!isDecorativeTab);
mUi->actionGesturesShow->setEnabled(qReal::SettingsManager::value("gesturesEnabled").toBool());

mUi->actionSave_script->setEnabled(isCodeTab);
updateUndoRedoState();

if (isEditorTab) {
Expand Down Expand Up @@ -2377,3 +2379,20 @@ void MainWindow::endPaletteModification()
scene->update();
}
}

void MainWindow::saveScript()
{
auto * const area = dynamic_cast<text::QScintillaTextEdit *>(currentTab());
if (!area) {
mErrorReporter->addWarning(tr(""));
return;
}

auto extension = area->currentLanguage().extension;
auto code = area->text();
if (!mProjectManager->saveScriptToProject(code, extension)) {
mErrorReporter->addWarning(tr(""));
return;
}
}

1 change: 1 addition & 0 deletions qrgui/mainWindow/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ private slots:

void updatePaletteIcons();
void setTextChanged(qReal::text::QScintillaTextEdit *editor, bool changed);
void saveScript();

private:
/// Initializes a tab if it is a diagram --- sets its logical and graphical
Expand Down
9 changes: 9 additions & 0 deletions qrgui/mainWindow/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_as"/>
<addaction name="actionSave_script"/>
<addaction name="separator"/>
<addaction name="actionSave_diagram_as_a_picture"/>
<addaction name="actionPrint"/>
Expand Down Expand Up @@ -711,6 +712,14 @@
<property name="text">
<string>Save diagram as a picture...</string>
</property>
</action>
<action name="actionSave_script">
<property name="text">
<string>Save script</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionCloseProject">
<property name="text">
Expand Down
4 changes: 4 additions & 0 deletions qrgui/mainWindow/projectManager/projectManagerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ bool ProjectManagerWrapper::saveText() {
return mTextManager->saveText(false);
}

bool ProjectManagerWrapper::saveScriptToProject(const QString &code, const QString &extension) {
return ProjectManager::saveScriptToProject(code, extension) && ProjectManagerWrapper::saveText();
}

bool ProjectManagerWrapper::suggestToSaveAs()
{
if (mTextManager->saveText(true)) {
Expand Down
1 change: 1 addition & 0 deletions qrgui/mainWindow/projectManager/projectManagerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public slots:

void refreshWindowTitleAccordingToSaveFile();
bool saveText();
bool saveScriptToProject(const QString &code, const QString &extension) override;

bool askQuestion(const QString &title, const QString &question) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public slots:
/// Similarly @see save(), if specified project-file, similarly @see suggestToSaveAs() o/w
virtual bool saveOrSuggestToSaveAs() = 0;

virtual bool saveScriptToProject(const QString &code, const QString &extension) = 0;

public:
/// Returns true if some .qrs project is currently opened in system. Otherwise returns false.
virtual bool somethingOpened() const = 0;
Expand Down
20 changes: 20 additions & 0 deletions qrgui/systemFacade/components/projectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ bool ProjectManager::import(const QString &fileName)

bool ProjectManager::saveFileExists(const QString &fileName) const
{
qDebug() << __PRETTY_FUNCTION__ << "saveFileExists";
if (!QFile::exists(fileName)) {
fileNotFoundMessage(fileName);
return false;
Expand Down Expand Up @@ -304,6 +305,7 @@ bool ProjectManager::saveTo(const QString &fileName)

bool ProjectManager::save()
{
qDebug() << __PRETTY_FUNCTION__ << "SAVE";
// Do not change the method to saveAll - in the current implementation, an empty project in the repository is
// created to initialize the file name with an empty string, which allows the internal state of the file
// name = "" Attempt to save the project in this case result in
Expand All @@ -316,6 +318,24 @@ bool ProjectManager::save()
return false;
}

bool ProjectManager::saveScriptToProject(const QString &script, const QString &extension)
{
if (!script.isEmpty()) {
auto& repo = mModels.mutableLogicalRepoApi();
repo.setMetaInformation("activeCode", script);
repo.setMetaInformation("activeCodeLanguageExtension", extension);
if (!mModels.repoControlApi().saveAll()) {
QLOG_INFO() << "";
return false;
}

return true;
}

QLOG_INFO() << "";
return false;
}

bool ProjectManager::restoreIncorrectlyTerminated()
{
return mAutosaver.checkTempFile();
Expand Down
1 change: 1 addition & 0 deletions qrgui/systemFacade/components/projectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public slots:
bool saveAs(const QString &fileName) override;
bool suggestToSaveAs() override;
bool saveOrSuggestToSaveAs() override;
bool saveScriptToProject(const QString &code, const QString &extension) override;

void setUnsavedIndicator(bool isUnsaved) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ProjectManagementInterfaceMock : public qReal::ProjectManagementInterface
MOCK_METHOD0(openEmptyWithSuggestToSaveChanges, bool());
MOCK_METHOD1(open, bool(const QString &fileName));
MOCK_METHOD0(suggestToSaveChangesOrCancel, bool());
MOCK_METHOD2(saveScriptToProject, bool(const QString &code, const QString &extension));
MOCK_METHOD1(setUnsavedIndicator, void(bool isUnsaved));
};

Expand Down
20 changes: 13 additions & 7 deletions qrtranslations/fr/qrgui_mainWindow_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<translation>&amp;Fichier</translation>
</message>
<message>
<location line="+16"/>
<location line="+17"/>
<source>&amp;View</source>
<translation>&amp;Affichage</translation>
</message>
Expand Down Expand Up @@ -258,11 +258,12 @@
</message>
<message>
<location line="+3"/>
<location line="+181"/>
<source>Ctrl+S</source>
<translation>Ctrl+S</translation>
</message>
<message>
<location line="+5"/>
<location line="-176"/>
<source>Save as...</source>
<translation>Enregistrer sous...</translation>
</message>
Expand Down Expand Up @@ -415,6 +416,11 @@
</message>
<message>
<location line="+5"/>
<source>Save script</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+8"/>
<source>Close project</source>
<translation>Fermer le projet</translation>
</message>
Expand Down Expand Up @@ -708,7 +714,7 @@
<context>
<name>qReal::MainWindow</name>
<message>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+620"/>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+621"/>
<source>Could not save file, try to save it to another place</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -717,7 +723,7 @@
<translation type="vanished">À propo de QReal</translation>
</message>
<message>
<location line="-425"/>
<location line="-426"/>
<source>Restore default settings</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -729,7 +735,7 @@ WARNING: The settings will be restored after application restart</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+673"/>
<location line="+674"/>
<location line="+11"/>
<source>Error</source>
<translation>Erreur</translation>
Expand Down Expand Up @@ -837,7 +843,7 @@ WARNING: The settings will be restored after application restart</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+202"/>
<location line="+203"/>
<source>Gestures Show</source>
<translation>Afficher les gestes</translation>
</message>
Expand Down Expand Up @@ -915,7 +921,7 @@ WARNING: The settings will be restored after application restart</source>
<translation>[modifié]</translation>
</message>
<message>
<location line="+90"/>
<location line="+94"/>
<source>Select file to save current metamodel to</source>
<translation>Choisir un fichier pour enregister le metamodèle courant</translation>
</message>
Expand Down
8 changes: 4 additions & 4 deletions qrtranslations/fr/qrgui_system_facade_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="+242"/>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="+243"/>
<source>Can`t open project file</source>
<translation type="unfinished">Le fichier du projet ne peut pas être ouvert</translation>
</message>
Expand Down Expand Up @@ -90,7 +90,7 @@
<translation type="vanished">Ouvrir un projet existant</translation>
</message>
<message>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="-166"/>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="-167"/>
<source>Open project</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -111,7 +111,7 @@
<translation>Choisir le fichier avec la sauvegarde pour importer</translation>
</message>
<message>
<location line="+34"/>
<location line="+35"/>
<source>There are missing plugins</source>
<translation>Manque d&apos;extensions</translation>
</message>
Expand All @@ -132,7 +132,7 @@
<translation>Le fichier du projet ne peut pas être ouvert</translation>
</message>
<message>
<location line="+79"/>
<location line="+98"/>
<source>Select file to save current model to</source>
<translation>Choisissez le ficher pour enregister le modèle</translation>
</message>
Expand Down
20 changes: 13 additions & 7 deletions qrtranslations/ru/qrgui_mainWindow_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<translation>Ф&amp;айл</translation>
</message>
<message>
<location line="+16"/>
<location line="+17"/>
<source>&amp;View</source>
<translation>&amp;Вид</translation>
</message>
Expand Down Expand Up @@ -258,11 +258,12 @@
</message>
<message>
<location line="+3"/>
<location line="+181"/>
<source>Ctrl+S</source>
<translation>Ctrl+S</translation>
</message>
<message>
<location line="+5"/>
<location line="-176"/>
<source>Save as...</source>
<translation>Сохранить как...</translation>
</message>
Expand Down Expand Up @@ -415,6 +416,11 @@
</message>
<message>
<location line="+5"/>
<source>Save script</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+8"/>
<source>Close project</source>
<translation>Закрыть проект</translation>
</message>
Expand Down Expand Up @@ -735,7 +741,7 @@
<translation type="vanished">О QReal</translation>
</message>
<message>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+869"/>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+870"/>
<location line="+11"/>
<source>Error</source>
<translation>Ошибка</translation>
Expand Down Expand Up @@ -788,7 +794,7 @@
<translation>Создать диаграмму</translation>
</message>
<message>
<location line="-1047"/>
<location line="-1048"/>
<source>Restore default settings</source>
<translation>Восстановить настройки по-умолчанию</translation>
</message>
Expand All @@ -802,7 +808,7 @@ WARNING: The settings will be restored after application restart</source>
ВНИМАНИЕ: Настройки будут сброшены после перезапуска приложения</translation>
</message>
<message>
<location line="+424"/>
<location line="+425"/>
<source>Could not save file, try to save it to another place</source>
<translation>Не удалось сохранить файл, попробуйте сохранить его в другое место</translation>
</message>
Expand Down Expand Up @@ -862,7 +868,7 @@ WARNING: The settings will be restored after application restart</source>
<translation>Показать/спрятать панель ошибок</translation>
</message>
<message>
<location line="+202"/>
<location line="+203"/>
<source>Gestures Show</source>
<translation>Жесты мышью</translation>
</message>
Expand Down Expand Up @@ -1029,7 +1035,7 @@ WARNING: The settings will be restored after application restart</source>
<translation> [изменён]</translation>
</message>
<message>
<location line="+90"/>
<location line="+94"/>
<source>Select file to save current metamodel to</source>
<translation>Выберите файл для сохранения метамодели</translation>
</message>
Expand Down
8 changes: 4 additions & 4 deletions qrtranslations/ru/qrgui_system_facade_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="+242"/>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="+243"/>
<source>Can`t open project file</source>
<translation>Не могу открыть проект</translation>
</message>
Expand Down Expand Up @@ -90,7 +90,7 @@
<translation type="vanished">Открыть проект</translation>
</message>
<message>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="-166"/>
<location filename="../../qrgui/systemFacade/components/projectManager.cpp" line="-167"/>
<source>Open project</source>
<translation>Открыть проект</translation>
</message>
Expand All @@ -111,7 +111,7 @@
<translation>Выберите файл для импорта</translation>
</message>
<message>
<location line="+34"/>
<location line="+35"/>
<source>There are missing plugins</source>
<translation>Не хватает плагинов</translation>
</message>
Expand All @@ -133,7 +133,7 @@
<translation>Не могу открыть проект</translation>
</message>
<message>
<location line="+79"/>
<location line="+98"/>
<source>Select file to save current model to</source>
<translation>Выберите файл для сохранения модели</translation>
</message>
Expand Down