aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/TextEdit.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-02-04 06:02:49 +0000
committersaturneric <[email protected]>2023-02-04 06:02:49 +0000
commit8c2e8e37505058bb2448ba65021f616ca658927b (patch)
tree919b0124932a5ee7dce940595c46f087f2d763cc /src/ui/widgets/TextEdit.cpp
parentfix: solve some issues (diff)
downloadGpgFrontend-8c2e8e37505058bb2448ba65021f616ca658927b.tar.gz
GpgFrontend-8c2e8e37505058bb2448ba65021f616ca658927b.zip
fix: solve open file issue in menu bar
1. add flush policy for logger 2. seperate the name of each logger 3. replace the old open file logic with the new one when click the button on the menu bar
Diffstat (limited to 'src/ui/widgets/TextEdit.cpp')
-rw-r--r--src/ui/widgets/TextEdit.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index c4754b3b..d8c4605d 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -79,7 +79,7 @@ void TextEdit::SlotNewFileTab() const {
page->SlotGoPath();
}
-void TextEdit::SlotOpenFile(QString& path) {
+void TextEdit::SlotOpenFile(const QString& path) {
QFile file(path);
SPDLOG_INFO("path: {}", path.toStdString());
auto result = file.open(QIODevice::ReadOnly | QIODevice::Text);
@@ -112,35 +112,7 @@ void TextEdit::SlotOpen() {
QFileDialog::getOpenFileNames(this, _("Open file"), QDir::currentPath());
for (const auto& file_name : file_names) {
if (!file_name.isEmpty()) {
- QFile file(file_name);
-
- if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- auto* page = new PlainTextEditorPage(file_name);
-
- QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- page->GetTextPage()->setPlainText(in.readAll());
- page->SetFilePath(file_name);
- QTextDocument* document = page->GetTextPage()->document();
- document->setModified(false);
-
- tab_widget_->addTab(page, stripped_name(file_name));
- tab_widget_->setCurrentIndex(tab_widget_->count() - 1);
- QApplication::restoreOverrideCursor();
- page->GetTextPage()->setFocus();
- connect(page->GetTextPage()->document(),
- &QTextDocument::modificationChanged, this,
- &TextEdit::SlotShowModified);
- // enableAction(true)
- file.close();
- } else {
- QMessageBox::warning(
- this, _("Warning"),
- (boost::format(_("Cannot read file %1%:\n%2%.")) %
- file_name.toStdString() % file.errorString().toStdString())
- .str()
- .c_str());
- }
+ SlotOpenFile(file_name);
}
}
}