]> sigrok.org Git - pulseview.git/blobdiff - pv/toolbars/mainbar.cpp
Add a new action to save to the last .sr file, and use it for control-S saving
[pulseview.git] / pv / toolbars / mainbar.cpp
index 18790f54e4bd750be12f02fad722f23cb323672f..a2a20fb62a93aafe4956d0a6b52b4742099e7dfc 100644 (file)
@@ -90,6 +90,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
        StandardBar(session, parent, view, false),
        action_new_view_(new QAction(this)),
        action_open_(new QAction(this)),
+       action_save_(new QAction(this)),
        action_save_as_(new QAction(this)),
        action_save_selection_as_(new QAction(this)),
        action_restore_setup_(new QAction(this)),
@@ -134,10 +135,16 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
        connect(action_restore_setup_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionRestoreSetup_triggered()));
 
-       action_save_as_->setText(tr("&Save As..."));
+       action_save_->setText(tr("&Save..."));
+       action_save_->setIcon(QIcon::fromTheme("document-save-as",
+               QIcon(":/icons/document-save-as.png")));
+       action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+       connect(action_save_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionSave_triggered()));
+
+       action_save_as_->setText(tr("Save &As..."));
        action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
-       action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
        connect(action_save_as_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSaveAs_triggered()));
 
@@ -201,6 +208,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
 
        // Save button
        vector<QAction*> save_actions;
+       save_actions.push_back(action_save_);
        save_actions.push_back(action_save_as_);
        save_actions.push_back(action_save_selection_as_);
        QAction* separator_s = new QAction(this);
@@ -214,7 +222,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
                this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
 
        save_button_->setMenu(export_menu);
-       save_button_->setDefaultAction(action_save_as_);
+       save_button_->setDefaultAction(action_save_);
        save_button_->setPopupMode(QToolButton::MenuButtonPopup);
 
        // Device selector menu
@@ -298,6 +306,11 @@ QAction* MainBar::action_open() const
        return action_open_;
 }
 
+QAction* MainBar::action_save() const
+{
+       return action_save_;
+}
+
 QAction* MainBar::action_save_as() const
 {
        return action_save_as_;
@@ -595,7 +608,7 @@ void MainBar::show_session_error(const QString text, const QString info_text)
        msg.exec();
 }
 
-void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
+void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only, QString path)
 {
        using pv::dialogs::StoreProgress;
 
@@ -654,8 +667,9 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
                        tr("All Files"));
 
        // Show the file dialog
-       const QString file_name = QFileDialog::getSaveFileName(
-               this, tr("Save File"), dir, filter);
+       const QString file_name = path.isEmpty() ?
+               QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter) :
+               path;
 
        if (file_name.isEmpty())
                return;
@@ -675,8 +689,9 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
                options = dlg.options();
        }
 
-       if (!selection_only)
-               session_.set_name(QFileInfo(file_name).fileName());
+       if (!selection_only &&
+                       format == session_.device_manager().context()->output_formats()["srzip"])
+               session_.set_path(file_name);
 
        StoreProgress *dlg = new StoreProgress(file_name, format, options,
                sample_range, session_, this);
@@ -798,6 +813,11 @@ void MainBar::on_actionOpen_triggered()
        }
 }
 
+void MainBar::on_actionSave_triggered()
+{
+       export_file(session_.device_manager().context()->output_formats()["srzip"], false, session_.path());
+}
+
 void MainBar::on_actionSaveAs_triggered()
 {
        export_file(session_.device_manager().context()->output_formats()["srzip"]);