WSL/SLF GitLab Repository

Commit 3fad42c0 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Improvements to the PreviewEditor.

Files opened from the filesystem are now read only and not marked as
"modified". A tooltip listing the major shortcuts has been added. The
regex for coordinates has been improved (it is now the same as at the
other places in Inishell).

Otherwise, re-ordering of the variables declaration for better
alignment.
parent 70ec66fa
......@@ -48,6 +48,7 @@
PreviewEdit::PreviewEdit(const bool& monospace) : QPlainTextEdit()
{
if (monospace) setMonospacedFont();
setToolTip("Supported shortcuts:\nCtrl+K \t\t\t Deletes to the end of the line\nCtrl+Z / Y \t\t Undo/Redo\nCtrl+Left / Right \t\t Move one word to the left / right\nCtrl+Tab / Shift+Tab \t Move to next / previous tab");
sidePanel = new PreviewSidePanel(this);
sidePanel->setStyleSheet("QWidget {background-color: " + colors::getQColor("syntax_background").name() + "; color: " +
colors::getQColor("sl_base01").name() + "; font-style: italic; font-size: 9pt}");
......
......@@ -40,6 +40,7 @@
#include <QStringList>
#include <QTimer>
#include <QHostInfo>
#include <QKeySequence>
#include <vector>
......@@ -151,7 +152,7 @@ SyntaxHighlighter::SyntaxHighlighter(QTextDocument *textdoc) : QSyntaxHighlighte
/* coordinates */
QTextCharFormat format_coordinate;
format_coordinate.setForeground(colors::getQColor("coordinate"));
rule.pattern = QRegularExpression(R"((latlon|xy)\s*\([-\d\s\.,;]+\))");
rule.pattern = QRegularExpression(R"((latlon|xy)\s*\(([-\d\.]+)(?:,)\s*([-\d\.]+)((?:,)\s*([-\d\.]+))?\))");
rule.format = format_coordinate;
rules_.append(rule);
......@@ -191,9 +192,10 @@ PreviewWindow::PreviewWindow(QMainWindow *parent) : QMainWindow(parent),
this->setUnifiedTitleAndToolBarOnMac(true);
file_tabs_ = new QTabWidget;
connect(file_tabs_, &QTabWidget::tabCloseRequested, this, &PreviewWindow::closeTab);
file_tabs_->setTabsClosable(true);
this->setCentralWidget(file_tabs_);
createMenu();
createMenu();
setAcceptDrops(true);
//size this window (from "outside" via a timer to have it work on macOS; works without for the logger?):
......@@ -217,10 +219,11 @@ PreviewWindow::~PreviewWindow()
*/
void PreviewWindow::addIniTab(const QString& infile)
{
const bool fromGUI = infile.isNull();
/* get currently set INI values */
QString ini_contents;
QTextStream ss(&ini_contents);
if (infile.isNull()) //load INI from GUI
if (fromGUI) //load INI from GUI
loadIniWithGui(); //extend original file's INIParser with GUI values
else
preview_ini_.parseFile(infile); //load INI from file system
......@@ -243,16 +246,18 @@ void PreviewWindow::addIniTab(const QString& infile)
this->statusBar()->hide();
}
preview_editor->setPlainText(ini_contents); //without undo history --> can't undo to empty
if (!fromGUI) preview_editor->setReadOnly(true); //INI read directly from file are RO
const QString loaded_file = infile.isNull()? getMainWindow()->getIni()->getFilename() : infile;
const QString loaded_file = fromGUI? getMainWindow()->getIni()->getFilename() : infile;
const QFileInfo file_info(loaded_file);
QString file_name(file_info.fileName());
QString file_path;
if (file_info.exists()) //avoid warning
file_path = file_info.absolutePath();
if (file_name.isEmpty()) { //pick file name if no INI is opened yet
file_name = "io_new.ini";
} else {
file_name = "GUI-"+QString::number(unsaved_ini_counter)+".ini";
unsaved_ini_counter++;
} else if (fromGUI) { //only for ini files coming from the GUI
INIParser gui_ini = getMainWindow()->getIniCopy();
(void) getMainWindow()->getControlPanel()->setIniValuesFromGui(&gui_ini);
if (getMainWindow()->getIniCopy() != gui_ini)
......
......@@ -162,21 +162,22 @@ class PreviewWindow : public QMainWindow
}
static const int paragraph_separator = 0x2029; //UNICODE paragraph separator
static const int long_spaces_for_tabs = 8; //8 spaces ~ 1 tab
static const int short_spaces_for_tabs = 4; //4 spaces ~ 1 tab
EditorKeyPressFilter *editor_key_filter_ = nullptr;
INIParser preview_ini_; //our local INIParser to do transformations on
EditorKeyPressFilter *editor_key_filter_ = nullptr;
QTabWidget *file_tabs_ = nullptr;
SyntaxHighlighter *highlighter_ = nullptr;
QLineEdit *find_text_ = nullptr;
QToolButton *close_find_bar_ = nullptr;
bool has_sorted_alphabetically_ = false;
QAction *file_save_and_load_ = nullptr;
QAction *file_load_ = nullptr;
QAction *edit_insert_missing_ = nullptr;
QAction *edit_insert_missing_mandatory_ = nullptr;
QAction *transform_reset_full_ = nullptr;
static const int paragraph_separator = 0x2029; //UNICODE paragraph separator
static const int long_spaces_for_tabs = 8; //8 spaces ~ 1 tab
static const int short_spaces_for_tabs = 4; //4 spaces ~ 1 tab
unsigned int unsaved_ini_counter = 1;
bool has_sorted_alphabetically_ = false;
private slots:
void openFile();
......
......@@ -87,8 +87,8 @@ class Atomic : public QWidget {
private:
void createContextMenu();
INIParser *ini_ = nullptr; //pointer to the main INIParser
QMenu panel_context_menu_;
INIParser *ini_ = nullptr; //pointer to the main INIParser
private slots:
void onTimerBufferedUpdatesEnabled();
......
......@@ -49,12 +49,12 @@ class Checklist : public Atomic {
QString getOrderedIniList() const;
void setChildVisibility(QListWidgetItem *item);
std::vector<QListWidgetItem *> ordered_item_list_; //order items were checked in
QListWidget *list_ = nullptr;
Group *child_container_ = nullptr;
QVBoxLayout *checklist_layout_ = nullptr;
Helptext *main_help_ = nullptr;
bool has_child_helptexts_ = false;
std::vector<QListWidgetItem *> ordered_item_list_; //order items were checked in
private slots:
void listClick(QListWidgetItem *);
......
......@@ -47,9 +47,9 @@ class Choice : public Atomic {
QString getOrderedIniList() const;
void setChildVisibility(const int &index, const Qt::CheckState &checked);
std::vector<int> ordered_item_list_; //order items were checked in
Group * checkbox_container_ = nullptr;
Group * child_container_ = nullptr;
std::vector<int> ordered_item_list_; //order items were checked in
private slots:
void changedState(int index);
......
......@@ -49,8 +49,8 @@ class Datepicker : public Atomic {
void setOptions(const QDomNode &options);
void setEmpty(const bool &is_empty);
QDateTimeEdit *datepicker_ = nullptr;
QString date_format_ = "yyyy-MM-ddThh:mm:ss"; //ISO date format is default
QDateTimeEdit *datepicker_ = nullptr;
DateKeyPressFilter *key_filter_ = nullptr;
private slots:
......
......@@ -53,14 +53,14 @@ friend class Selector;
QString getCurrentText() const;
void styleTimer();
std::vector<QDomElement> child_nodes_; //cache for child panels
QStringList item_help_texts_;
QComboBox *dropdown_ = nullptr;
Group *container_ = nullptr;
Helptext *main_help_ = nullptr;
QStringList item_help_texts_;
bool has_child_helptexts_ = false;
bool booleans_only_ = true; //XML options are all booleans
bool numeric_ini_value_ = false; //user prefers 1/0 to true/false in INI
std::vector<QDomElement> child_nodes_; //cache for child panels
private slots:
void itemChanged(int index);
......
......@@ -48,12 +48,12 @@ class FilePath : public Atomic {
};
void setOptions(const QDomNode &options);
QString extensions_; //file extension filter
input_output_mode io_mode = UNSPECIFIED;
QLineEdit *path_text_ = nullptr;
QLabel *info_text_ = nullptr;
QPushButton *open_button_ = nullptr;
bool path_only_ = false, filename_only_ = false;
QString extensions_; //file extension filter
input_output_mode io_mode = UNSPECIFIED;
private slots:
void openFile();
......
......@@ -63,16 +63,16 @@ class Number : public Atomic {
int getPrecisionOfNumber(const QString &str_number) const;
void setEmpty(const bool &is_empty);
std::vector<std::pair<QString, QString>> substitutions_; //user-set substitutions to translate to tinyexpr
KeyPressFilter *key_filter_ = nullptr;
number_mode mode_;
QAbstractSpinBox *number_element_ = nullptr;
QLineEdit *expression_element_ = nullptr;
QHBoxLayout *switcher_layout_ = nullptr;
QToolButton *switch_button_ = nullptr;
bool show_sign = false;
int default_precision_ = 2;
int precision_ = default_precision_; //current precision
std::vector<std::pair<QString, QString>> substitutions_; //user-set substitutions to translate to tinyexpr
number_mode mode_;
bool show_sign = false;
private slots:
void checkValue(const double &to_check);
......
......@@ -47,8 +47,8 @@ class Replicator : public Atomic {
void setOptions(const QDomNode &options);
int findLastItemRow() const;
Group *container_ = nullptr;
QDomNode templ_;
Group *container_ = nullptr;
QPushButton *plus_button_ = nullptr;
private slots:
......
......@@ -64,11 +64,11 @@ class Selector : public Atomic {
void removePanel(const QString &param_text);
inline QString getCurrentText() const { return textfield_? textfield_->text() : dropdown_->currentText(); }
QDomNode templ_;
std::map<QString, Group *, CaseInsensitiveCompare> container_map_;
QComboBox *dropdown_ = nullptr;
QLineEdit *textfield_ = nullptr;
Group *container_ = nullptr;
QDomNode templ_;
std::map<QString, Group *, CaseInsensitiveCompare> container_map_;
QPushButton *plus_button_ = nullptr;
SelectorKeyPressFilter *key_events_input_ = nullptr;
......
......@@ -44,11 +44,11 @@ class Textfield : public Atomic {
private:
void setOptions(const QDomNode &options);
std::vector<std::pair<QString, QString>> substitutions_; //user-set substitutions to translate to tinyexpr
QString validation_regex_;
QLineEdit *textfield_ = nullptr;
QToolButton *check_button_ = nullptr;
bool needs_prefix_for_evaluation_ = true;
QString validation_regex_;
std::vector<std::pair<QString, QString>> substitutions_; //user-set substitutions to translate to tinyexpr
private slots:
void onPropertySet() override;
......
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