Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saveas feature #795

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/boardeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ BoardEditor::BoardEditor(ProjectEditor& projectEditor, Project& project)
// connect some actions which are created with the Qt Designer
connect(mUi->actionProjectSave, &QAction::triggered, &mProjectEditor,
&ProjectEditor::saveProject);
connect(mUi->actionProjectSaveAs, &QAction::triggered,
[this]() { mProjectEditor.saveProjectAs(this); });
connect(mUi->actionQuit, &QAction::triggered, this, &BoardEditor::close);
connect(mUi->actionOpenWebsite, &QAction::triggered,
[]() { QDesktopServices::openUrl(QUrl("https://librepcb.org")); });
Expand Down
10 changes: 10 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/boardeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<string>&amp;File</string>
</property>
<addaction name="actionProjectSave"/>
<addaction name="actionProjectSaveAs"/>
<addaction name="actionExportLppz"/>
<addaction name="actionExportAsPdf"/>
<addaction name="actionExportAsSvg"/>
Expand Down Expand Up @@ -304,6 +305,15 @@
<string notr="true">Ctrl+S</string>
</property>
</action>
<action name="actionProjectSaveAs">
<property name="icon">
<iconset>
<normaloff>:/img/actions/save.png</normaloff>:/img/actions/save.png</iconset>
</property>
<property name="text">
<string>&amp;Save Project</string>
</property>
</action>
<action name="actionProjectClose">
<property name="icon">
<iconset>
Expand Down
40 changes: 40 additions & 0 deletions libs/librepcb/projecteditor/projecteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,46 @@ bool ProjectEditor::saveProject() noexcept {
}
}

bool ProjectEditor::saveProjectAs(QWidget* parent) noexcept {
try {
qDebug() << "Saving project as...";

FilePath defaultDirectory = mProject.getPath().getParentDir(); // can throw
QString directoryName = FileDialog::getSaveFileName(
parent, tr("Save project as *"), defaultDirectory.toStr(), "*");
if (directoryName.isEmpty()) return false;

// Copy project directory to 'directoryName' directory
// create file system
FilePath chosenDir = FilePath(directoryName);
std::shared_ptr<TransactionalFileSystem> fs = TransactionalFileSystem::openRW(
chosenDir);
TransactionalDirectory transdir(fs);

// Create a new project
Project* project = Project::create(
std::unique_ptr<TransactionalDirectory>(new TransactionalDirectory(fs)),
directoryName);

// Save project to its own transactional directory, and then copies it to the
// newly created transactional directory
mProject.save();
mProject.getDirectory().copyTo(transdir);

project->save();
fs->save();

// Do not clean the undo stack for saving as copy, could be useful?

qDebug() << "Project successfully saved";
return true;
} catch (Exception& exc) {
QMessageBox::critical(0, tr("Error while saving the project"),
exc.getMsg());
return false;
}
}

bool ProjectEditor::autosaveProject() noexcept {
if (mUndoStack->isClean())
return false; // do not save if there are no changes
Expand Down
11 changes: 11 additions & 0 deletions libs/librepcb/projecteditor/projecteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ public slots:
*/
bool saveProject() noexcept;

/**
* @brief Save the whole project as a copy to the harddisc
*
* @note The whole save procedere is described in @ref doc_project_save.
*
* @param parent parent widget of the dialog (optional)
*
* @return true on success, false on failure
*/
bool saveProjectAs(QWidget* parent = nullptr) noexcept;

/**
* @brief Make a automatic backup of the project (save to temporary files)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ SchematicEditor::SchematicEditor(ProjectEditor& projectEditor, Project& project)
&SchematicEditor::addSchematic);
connect(mUi->actionSave_Project, &QAction::triggered, &mProjectEditor,
&ProjectEditor::saveProject);
connect(mUi->actionSave_Project_As, &QAction::triggered,
[this]() { mProjectEditor.saveProjectAs(this); });
connect(mUi->actionQuit, &QAction::triggered, this, &SchematicEditor::close);
connect(mUi->actionOpenWebsite, &QAction::triggered,
[]() { QDesktopServices::openUrl(QUrl("https://librepcb.org")); });
Expand Down
10 changes: 10 additions & 0 deletions libs/librepcb/projecteditor/schematiceditor/schematiceditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</property>
<addaction name="actionNew_Schematic_Page"/>
<addaction name="actionSave_Project"/>
<addaction name="actionSave_Project_As"/>
<addaction name="actionExportLppz"/>
<addaction name="actionPDF_Export"/>
<addaction name="actionExportAsSvg"/>
Expand Down Expand Up @@ -296,6 +297,15 @@
<string notr="true">Ctrl+S</string>
</property>
</action>
<action name="actionSave_Project_As">
<property name="icon">
<iconset>
<normaloff>:/img/actions/save.png</normaloff>:/img/actions/save.png</iconset>
</property>
<property name="text">
<string>&amp;Save Project As</string>
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset>
Expand Down