Skip to content

Commit

Permalink
qtedit4: escape closes preview
Browse files Browse the repository at this point in the history
When the preview panel is open (and available!) escape will close it.

Fixes #41
  • Loading branch information
diegoiast committed Jan 23, 2025
1 parent 392c857 commit 1d41821
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/plugins/help/help_plg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
#include <QSimpleUpdater.h>
#include <QUrl>

#include <iplugin.h>
#include <pluginmanager.h>

#include "CommandPaletteWidget/commandpalette.h"
#include "help_plg.h"
#include "iplugin.h"
#include <pluginmanager.h>
#include "widgets/qmdieditor.h"

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>

#endif

#if defined(__linux__)
Expand Down Expand Up @@ -378,6 +381,14 @@ void HelpPlugin::uiCleanUp() {
return;
}

auto e = dynamic_cast<qmdiEditor *>(manager->currentClient());
if (e) {
if (e->isPreviewVisible()) {
e->setPreviewVisible(false);
return;
}
}

auto w = dynamic_cast<QWidget *>(manager->currentClient());
if (w) {
w->setFocus();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/texteditor/texteditor_plg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ bool TextEditorPlugin::openFile(const QString fileName, int x, int y, int zoom)
auto shouldAutoPreview = getConfig().getAutoPreview();
auto canOpenPreview = editor->hasPreview();
editor->setPreviewEnabled(canOpenPreview);
editor->setPreview(canOpenPreview && shouldAutoPreview);
editor->setPreviewVisible(canOpenPreview && shouldAutoPreview);
editor->setHistoryModel(historyModel);
mdiServer->addClient(editor);
editor->goTo(x, y);
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/qmdieditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ void qmdiEditor::setEditorHighlighter(QString id) {

void qmdiEditor::setPreviewEnabled(bool enabled) { this->previewButton->setEnabled(enabled); }

void qmdiEditor::setPreview(bool enabled) { this->previewButton->setChecked(enabled); }
void qmdiEditor::setPreviewVisible(bool enabled) { this->previewButton->setChecked(enabled); }

bool qmdiEditor::isPreviewRequested() {
return this->previewButton->isEnabled() && this->previewButton->isChecked();
}

bool qmdiEditor::isPreviewVisible() const { return this->previewButton->isChecked(); }

void qmdiEditor::setHistoryModel(SharedHistoryModel *model) {
operationsWidget->setSearchHistory(model);
}
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/qmdieditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class qmdiEditor : public QWidget, public qmdiClient {
inline void setEditorMarkWord(bool b) { textEditor->setMarkCurrentWord(b); }

void setPreviewEnabled(bool enabled);
void setPreview(bool enabled);
void setPreviewVisible(bool enabled);
bool isPreviewRequested();
bool isPreviewVisible() const;

void setHistoryModel(SharedHistoryModel *model);

Expand Down

0 comments on commit 1d41821

Please sign in to comment.