From cb2cbf49d0918423b122f516a19f5922f9fd7d2f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 7 Jul 2022 20:08:58 +0800 Subject: [PATCH] - change: uncheck "hide unsupported files" in files view shouldn't gray out non-c files - enhancement: double clicking a non-text file in the files view, will open it with external program - enhancement: double clicking a non-text file in the project's view, will open it with external program --- NEWS.md | 6 ++++++ RedPandaIDE/editor.h | 5 ++++- RedPandaIDE/mainwindow.cpp | 26 +++++++++++++++++++++++--- RedPandaIDE/project.cpp | 11 +++++++++++ RedPandaIDE/utils.cpp | 12 ++++++++++++ RedPandaIDE/utils.h | 1 + 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9c9b3a67..cf66f53e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +Red Panda C++ Version 1.1.5 + + - change: uncheck "hide unsupported files" in files view shouldn't gray out non-c files + - enhancement: double clicking a non-text file in the files view, will open it with external program + - enhancement: double clicking a non-text file in the project's view, will open it with external program + Red Panda C++ Version 1.1.4 - enhancement: prohibit move selection up/down under column mode diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index c4493fa5..1137130f 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -147,13 +147,14 @@ public: const QByteArray& encodingOption() const noexcept; void setEncodingOption(const QByteArray& encoding) noexcept; const QByteArray& fileEncoding() const noexcept; + void convertToEncoding(const QByteArray& encoding); const QString& filename() const noexcept; + bool inProject() const noexcept; bool isNew() const noexcept; void loadFile(QString filename = ""); void saveFile(QString filename); - void convertToEncoding(const QByteArray& encoding); bool save(bool force=false, bool reparse=true); bool saveAs(const QString& name="", bool fromProject = false); void activate(); @@ -164,9 +165,11 @@ public: void updateCaption(const QString& newCaption=QString()); void applySettings(); void applyColorScheme(const QString& schemeName); + void copyToClipboard() override; void cutToClipboard() override; void copyAsHTML(); + void setCaretPosition(int line,int aChar); void setCaretPositionAndActivate(int line,int aChar); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 805e0b10..13f4f9c8 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -83,6 +83,8 @@ #include "widgets/searchdialog.h" #ifdef Q_OS_WIN +#include +#include #include #endif @@ -304,7 +306,7 @@ MainWindow::MainWindow(QWidget *parent) mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); mFileSystemModel.setNameFilters(pSystemConsts->defaultFileNameFilters()); - mFileSystemModel.setNameFilterDisables(false); + mFileSystemModel.setNameFilterDisables(true); //setFilesViewRoot(pSettings->environment().currentFolder()); for (int i=1;itreeFiles->hideColumn(i); @@ -6903,9 +6905,22 @@ void MainWindow::on_treeFiles_doubleClicked(const QModelIndex &index) QString filepath = mFileSystemModel.filePath(index); QFileInfo file(filepath); if (file.isFile()) { - if (getFileType(filepath)==FileType::Project) { + switch (getFileType(filepath)) { + case FileType::Project: openProject(filepath); - } else { + break; + case FileType::Other: + { + QMimeDatabase db; + QMimeType mimeType=db.mimeTypeForFile(file); + if (mimeType.isValid() && mimeType.name().startsWith("text/")) { + openFile(filepath); + } else { + QDesktopServices::openUrl(QUrl::fromLocalFile(file.absoluteFilePath())); + } + } + break; + default: openFile(filepath); } } @@ -7772,6 +7787,11 @@ void MainWindow::on_actionGit_Push_triggered() void MainWindow::on_actionFilesView_Hide_Non_Support_Files_toggled(bool /* arg1 */) { mFileSystemModel.setNameFilterDisables(!ui->actionFilesView_Hide_Non_Support_Files->isChecked()); + if (!mFileSystemModel.nameFilterDisables()) { + mFileSystemModel.setNameFilters(pSystemConsts->defaultFileNameFilters()); + } else { + mFileSystemModel.setNameFilters(QStringList()); + } if (pSettings->environment().hideNonSupportFilesInFileView() != ui->actionFilesView_Hide_Non_Support_Files->isChecked()) { pSettings->environment().setHideNonSupportFilesInFileView(ui->actionFilesView_Hide_Non_Support_Files->isChecked()); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 2e56f252..ab31dd16 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "customfileiconprovider.h" #include #include "settings.h" @@ -315,6 +317,15 @@ Editor *Project::openUnit(int index) PProjectUnit unit = mUnits[index]; if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) { + if (getFileType(unit->fileName())==FileType::Other) { + QMimeDatabase db; + QMimeType mimeType=db.mimeTypeForFile(unit->fileName()); + if (!mimeType.isValid() || !mimeType.name().startsWith("text/")) { + QDesktopServices::openUrl(QUrl::fromLocalFile(unit->fileName())); + } + return nullptr; + } + Editor * editor = mEditorList->getOpenedEditorByFilename(unit->fileName()); if (editor) {//already opened in the editors editor->setInProject(true); diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 1259458d..04ffe52f 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -263,6 +263,18 @@ FileType getFileType(const QString &filename) if (filename.endsWith(".rc",PATH_SENSITIVITY)) { return FileType::WindowsResourceSource; } + if (filename.endsWith(".in",PATH_SENSITIVITY)) { + return FileType::Text; + } + if (filename.endsWith(".out",PATH_SENSITIVITY)) { + return FileType::Text; + } + if (filename.endsWith(".txt",PATH_SENSITIVITY)) { + return FileType::Text; + } + if (filename.endsWith(".dat",PATH_SENSITIVITY)) { + return FileType::Text; + } return FileType::Other; } diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index cbe971af..684d267f 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -47,6 +47,7 @@ enum class FileType{ CppHeader, // c++ header (.hpp) WindowsResourceSource, // resource source (.res) Project, //Red Panda C++ Project (.dev) + Text, // text file Other // any others };