]> sigrok.org Git - pulseview.git/commitdiff
Add a new action to save to the last .sr file, and use it for control-S saving
authorValentin Ochs <redacted>
Sat, 13 Jun 2020 17:23:49 +0000 (19:23 +0200)
committerSoeren Apel <redacted>
Thu, 25 Jun 2020 19:05:42 +0000 (21:05 +0200)
pv/session.cpp
pv/session.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

index ea3fe07b4e312c8bece64035967edf4e6e5c692f..840773d1aa7115bd4dcc7594496c776231bcdd15 100644 (file)
@@ -176,6 +176,17 @@ void Session::set_name(QString name)
        name_changed();
 }
 
        name_changed();
 }
 
+QString Session::path() const
+{
+       return path_;
+}
+
+void Session::set_path(QString path)
+{
+       path_ = path;
+       set_name(QFileInfo(path).fileName());
+}
+
 const vector< shared_ptr<views::ViewBase> > Session::views() const
 {
        return views_;
 const vector< shared_ptr<views::ViewBase> > Session::views() const
 {
        return views_;
@@ -444,6 +455,8 @@ void Session::restore_settings(QSettings &settings)
                settings.endGroup();
        }
 
                settings.endGroup();
        }
 
+
+       QString path;
        if ((device_type == "sessionfile") || (device_type == "inputfile")) {
                if (device_type == "sessionfile") {
                        settings.beginGroup("device");
        if ((device_type == "sessionfile") || (device_type == "inputfile")) {
                if (device_type == "sessionfile") {
                        settings.beginGroup("device");
@@ -451,6 +464,7 @@ void Session::restore_settings(QSettings &settings)
                        settings.endGroup();
 
                        if (QFileInfo(filename).isReadable()) {
                        settings.endGroup();
 
                        if (QFileInfo(filename).isReadable()) {
+                       path = filename;
                                device = make_shared<devices::SessionFile>(device_manager_.context(),
                                        filename.toStdString());
                        }
                                device = make_shared<devices::SessionFile>(device_manager_.context(),
                                        filename.toStdString());
                        }
@@ -472,6 +486,9 @@ void Session::restore_settings(QSettings &settings)
 
                        set_name(QString::fromStdString(
                                dynamic_pointer_cast<devices::File>(device)->display_name(device_manager_)));
 
                        set_name(QString::fromStdString(
                                dynamic_pointer_cast<devices::File>(device)->display_name(device_manager_)));
+
+                       if (!path.isEmpty())
+                               set_path(path);
                }
        }
 
                }
        }
 
@@ -709,7 +726,7 @@ void Session::load_file(QString file_name, QString setup_file_name,
        start_capture([&, errorMessage](QString infoMessage) {
                MainWindow::show_session_error(errorMessage, infoMessage); });
 
        start_capture([&, errorMessage](QString infoMessage) {
                MainWindow::show_session_error(errorMessage, infoMessage); });
 
-       set_name(QFileInfo(file_name).fileName());
+       set_path(file_name);
 }
 
 Session::capture_state Session::get_capture_state() const
 }
 
 Session::capture_state Session::get_capture_state() const
index cfc69d4aa94e4fbdda0fb4d8806058a0ecaa491c..871dcba85f334eecb7be37f93a6e1c0271adf625 100644 (file)
@@ -141,6 +141,9 @@ public:
        QString name() const;
        void set_name(QString name);
 
        QString name() const;
        void set_name(QString name);
 
+       QString path() const;
+       void set_path(QString path);
+
        const vector< shared_ptr<views::ViewBase> > views() const;
 
        shared_ptr<views::ViewBase> main_view() const;
        const vector< shared_ptr<views::ViewBase> > views() const;
 
        shared_ptr<views::ViewBase> main_view() const;
@@ -270,7 +273,7 @@ private:
 
        DeviceManager &device_manager_;
        shared_ptr<devices::Device> device_;
 
        DeviceManager &device_manager_;
        shared_ptr<devices::Device> device_;
-       QString default_name_, name_;
+       QString default_name_, name_, path_;
 
        vector< shared_ptr<views::ViewBase> > views_;
        shared_ptr<pv::views::ViewBase> main_view_;
 
        vector< shared_ptr<views::ViewBase> > views_;
        shared_ptr<pv::views::ViewBase> main_view_;
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)),
        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)),
        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()));
 
        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_->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()));
 
        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 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);
        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);
                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
        save_button_->setPopupMode(QToolButton::MenuButtonPopup);
 
        // Device selector menu
@@ -298,6 +306,11 @@ QAction* MainBar::action_open() const
        return action_open_;
 }
 
        return action_open_;
 }
 
+QAction* MainBar::action_save() const
+{
+       return action_save_;
+}
+
 QAction* MainBar::action_save_as() const
 {
        return action_save_as_;
 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();
 }
 
        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;
 
 {
        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
                        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;
 
        if (file_name.isEmpty())
                return;
@@ -675,8 +689,9 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
                options = dlg.options();
        }
 
                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);
 
        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"]);
 void MainBar::on_actionSaveAs_triggered()
 {
        export_file(session_.device_manager().context()->output_formats()["srzip"]);
index 04c344c5351088e8e636e50159adb1c536d3dc08..fca6acabcd7e5045aa519419f085a1a6673c4343 100644 (file)
@@ -96,6 +96,7 @@ public:
 
        QAction* action_new_view() const;
        QAction* action_open() const;
 
        QAction* action_new_view() const;
        QAction* action_open() const;
+       QAction* action_save() const;
        QAction* action_save_as() const;
        QAction* action_save_selection_as() const;
        QAction* action_restore_setup() const;
        QAction* action_save_as() const;
        QAction* action_save_selection_as() const;
        QAction* action_restore_setup() const;
@@ -120,7 +121,8 @@ private Q_SLOTS:
        void show_session_error(const QString text, const QString info_text);
 
        void export_file(shared_ptr<sigrok::OutputFormat> format,
        void show_session_error(const QString text, const QString info_text);
 
        void export_file(shared_ptr<sigrok::OutputFormat> format,
-               bool selection_only = false);
+               bool selection_only = false,
+               QString path = QString{});
        void import_file(shared_ptr<sigrok::InputFormat> format);
 
        void on_device_selected();
        void import_file(shared_ptr<sigrok::InputFormat> format);
 
        void on_device_selected();
@@ -134,6 +136,7 @@ private Q_SLOTS:
        void on_actionNewView_triggered(QAction* action = nullptr);
 
        void on_actionOpen_triggered();
        void on_actionNewView_triggered(QAction* action = nullptr);
 
        void on_actionOpen_triggered();
+       void on_actionSave_triggered();
        void on_actionSaveAs_triggered();
        void on_actionSaveSelectionAs_triggered();
 
        void on_actionSaveAs_triggered();
        void on_actionSaveSelectionAs_triggered();
 
@@ -156,6 +159,7 @@ Q_SIGNALS:
 private:
        QAction *const action_new_view_;
        QAction *const action_open_;
 private:
        QAction *const action_new_view_;
        QAction *const action_open_;
+       QAction *const action_save_;
        QAction *const action_save_as_;
        QAction *const action_save_selection_as_;
        QAction *const action_restore_setup_;
        QAction *const action_save_as_;
        QAction *const action_save_selection_as_;
        QAction *const action_restore_setup_;