WSL/SLF GitLab Repository

Commit c36ab4e7 authored by Michael Reisecker's avatar Michael Reisecker
Browse files

Add Preview Editor menu entry to open an existing INI file

parent 13c71bec
......@@ -212,13 +212,17 @@ PreviewWindow::~PreviewWindow()
/**
* @brief Display the current INI file in a new tab.
* @param[in] infile Optional file name to load instead of the GUI values.
*/
void PreviewWindow::addIniTab()
void PreviewWindow::addIniTab(const QString& infile)
{
/* get currently set INI values */
QString ini_contents;
QTextStream ss(&ini_contents);
loadIniWithGui(); //extend original file's INIParser with GUI values
if (infile.isNull()) //load INI from GUI
loadIniWithGui(); //extend original file's INIParser with GUI values
else
preview_ini_.parseFile(infile); //load INI from file system
/* text box for the current INI */
const bool setMonospace = (getSetting("user::preview::mono_font", "value") == "TRUE");
......@@ -332,6 +336,11 @@ void PreviewWindow::createMenu()
{
/* FILE menu */
QMenu *menu_file = this->menuBar()->addMenu(tr("&File"));
auto *file_open = new QAction(getIcon("document-open"), tr("&Open..."), menu_file);
file_open->setShortcut( QKeySequence::Open );
menu_file->addAction(file_open);
connect(file_open, &QAction::triggered, this, &PreviewWindow::openFile);
menu_file->addSeparator();
auto *file_save = new QAction(getIcon("document-save"), tr("&Save"), menu_file);
file_save->setShortcut( QKeySequence::Save );
menu_file->addAction(file_save);
......@@ -1111,6 +1120,25 @@ QString PreviewWindow::trimComment(const QString &comment) const
}
}
/**
* @brief Menu item to open an existing INI file in the Preview Editor.
*/
void PreviewWindow::openFile()
{
QString start_path( getSetting("auto::history::last_preview_ini", "path") );
if (start_path.isEmpty())
start_path = QDir::currentPath();
const QString path = QFileDialog::getOpenFileName(this, tr("Open INI file in preview"), start_path,
"INI files (*.ini);;All files (*)", nullptr,
QFileDialog::DontUseNativeDialog | QFileDialog::DontConfirmOverwrite);
if (path.isNull()) //cancelled
return;
addIniTab(path);
setSetting("auto::history::last_preview_ini", "path", QFileInfo( path ).absoluteDir().path());
}
/**
* @brief Menu item to save an INI file to the file system.
*/
......
......@@ -76,7 +76,7 @@ class PreviewWindow : public QMainWindow
PreviewWindow& operator =(PreviewWindow const&) = delete;
PreviewWindow(PreviewWindow&&) = delete;
PreviewWindow& operator=(PreviewWindow&&) = delete;
void addIniTab();
void addIniTab(const QString& infile = QString());
int count() const { return file_tabs_->count(); }
protected:
......@@ -177,6 +177,7 @@ class PreviewWindow : public QMainWindow
QAction *transform_reset_full_ = nullptr;
private slots:
void openFile();
void saveFile();
void saveFileAs();
void saveFileAndLoadIntoGui();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment