diff options
| -rw-r--r-- | src/modinfodialog.ui | 6 | ||||
| -rw-r--r-- | src/texteditor.cpp | 61 | ||||
| -rw-r--r-- | src/texteditor.h | 6 |
3 files changed, 66 insertions, 7 deletions
diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui index 7a7d82da..56c97c34 100644 --- a/src/modinfodialog.ui +++ b/src/modinfodialog.ui @@ -168,6 +168,9 @@ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
+ <property name="childrenCollapsible">
+ <bool>false</bool>
+ </property>
<widget class="QWidget" name="widget_8" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
@@ -184,6 +187,9 @@ </property>
<item>
<widget class="ImagesScrollArea" name="imagesScrollArea">
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
<widget class="ImagesThumbnails" name="imagesThumbnails">
<property name="geometry">
<rect>
diff --git a/src/texteditor.cpp b/src/texteditor.cpp index ee36c104..9bbe3ddd 100644 --- a/src/texteditor.cpp +++ b/src/texteditor.cpp @@ -5,7 +5,7 @@ TextEditor::TextEditor(QWidget* parent) : QPlainTextEdit(parent), m_toolbar(nullptr), m_lineNumbers(nullptr), m_highlighter(nullptr), - m_dirty(false) + m_dirty(false), m_loading(false) { m_toolbar = new TextEditorToolbar(*this); m_lineNumbers = new TextEditorLineNumbers(*this); @@ -59,17 +59,25 @@ void TextEditor::setDefaultStyle() void TextEditor::clear() { + QScopedValueRollback loading(m_loading, true); + m_filename.clear(); m_encoding.clear(); setPlainText(""); dirty(false); + document()->setModified(false); + + emit loaded(""); } bool TextEditor::load(const QString& filename) { - m_filename = filename; clear(); + QScopedValueRollback loading(m_loading, true); + + m_filename = filename; + const QString s = MOBase::readFileText(filename, &m_encoding); setPlainText(s); @@ -81,6 +89,8 @@ bool TextEditor::load(const QString& filename) onModified(false); } + emit loaded(m_filename); + return true; } @@ -180,8 +190,21 @@ void TextEditor::setHighlightBackgroundColor(const QColor& c) update(); } +void TextEditor::explore() +{ + if (m_filename.isEmpty()) { + return; + } + + MOBase::shell::ExploreFile(m_filename); +} + void TextEditor::onModified(bool b) { + if (m_loading) { + return; + } + dirty(b); emit modified(b); } @@ -431,15 +454,27 @@ void TextEditorLineNumbers::updateArea(const QRect &rect, int dy) } -TextEditorToolbar::TextEditorToolbar(TextEditor& editor) : - m_editor(editor), - m_save(new QAction(QIcon(":/MO/gui/save"), QObject::tr("&Save"))), - m_wordWrap(new QAction(QIcon(":/MO/gui/word-wrap"), QObject::tr("&Word wrap"))) +TextEditorToolbar::TextEditorToolbar(TextEditor& editor) + : m_editor(editor), m_save(nullptr), m_wordWrap(nullptr), m_explore(nullptr) { - QObject::connect(m_save, &QAction::triggered, [&]{ m_editor.save(); }); + m_save = new QAction( + QIcon(":/MO/gui/save"), QObject::tr("&Save"), &editor); + + m_save->setShortcutContext(Qt::WidgetWithChildrenShortcut); + m_save->setShortcut(Qt::CTRL + Qt::Key_S); + m_editor.addAction(m_save); + + m_wordWrap = new QAction( + QIcon(":/MO/gui/word-wrap"), QObject::tr("&Word wrap"), &editor); + + m_explore = new QAction( + QObject::tr("&Open in Explorer"), &editor); m_wordWrap->setCheckable(true); + + QObject::connect(m_save, &QAction::triggered, [&]{ m_editor.save(); }); QObject::connect(m_wordWrap, &QAction::triggered, [&]{ m_editor.toggleWordWrap(); }); + QObject::connect(m_explore, &QAction::triggered, [&]{ m_editor.explore(); }); auto* layout = new QHBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); @@ -453,8 +488,13 @@ TextEditorToolbar::TextEditorToolbar(TextEditor& editor) : b->setDefaultAction(m_wordWrap); layout->addWidget(b); + b = new QToolButton; + b->setDefaultAction(m_explore); + layout->addWidget(b); + QObject::connect(&m_editor, &TextEditor::modified, [&](bool b){ onTextModified(b); }); QObject::connect(&m_editor, &TextEditor::wordWrapChanged, [&](bool b){ onWordWrap(b); }); + QObject::connect(&m_editor, &TextEditor::loaded, [&](QString f){ onLoaded(f); }); } void TextEditorToolbar::onTextModified(bool b) @@ -467,6 +507,13 @@ void TextEditorToolbar::onWordWrap(bool b) m_wordWrap->setChecked(b); } +void TextEditorToolbar::onLoaded(const QString& s) +{ + const auto hasDoc = !s.isEmpty(); + + m_explore->setEnabled(hasDoc); + m_wordWrap->setEnabled(hasDoc); +} void HTMLEditor::focusOutEvent(QFocusEvent* e) { diff --git a/src/texteditor.h b/src/texteditor.h index 775565f2..798222a3 100644 --- a/src/texteditor.h +++ b/src/texteditor.h @@ -16,9 +16,11 @@ private: TextEditor& m_editor; QAction* m_save; QAction* m_wordWrap; + QAction* m_explore; void onTextModified(bool b); void onWordWrap(bool b); + void onLoaded(const QString& s); }; @@ -112,7 +114,10 @@ public: QColor highlightBackgroundColor() const; void setHighlightBackgroundColor(const QColor& c); + void explore(); + signals: + void loaded(QString filename); void modified(bool b); void wordWrapChanged(bool b); @@ -127,6 +132,7 @@ private: QString m_filename; QString m_encoding; bool m_dirty; + bool m_loading; void setDefaultStyle(); void onModified(bool b); |
