Просмотр исходного кода

LibCore: Add some extensions that are text/plain

C++ source/header files, GML, IPC, CMake and various Serenity config
files.
Maciej 3 лет назад
Родитель
Сommit
273b69f947
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      Userland/Libraries/LibCore/MimeData.cpp

+ 15 - 0
Userland/Libraries/LibCore/MimeData.cpp

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <AK/LexicalPath.h>
 #include <AK/StringBuilder.h>
 #include <LibCore/MimeData.h>
 
@@ -86,6 +87,20 @@ String guess_mime_type_based_on_filename(StringView path)
         return "text/html";
     if (path.ends_with(".csv", CaseSensitivity::CaseInsensitive))
         return "text/csv";
+    // FIXME: Share this, TextEditor and HackStudio language detection somehow.
+    auto basename = LexicalPath::basename(path);
+    if (path.ends_with(".cpp", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".c", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".hpp", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".h", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".gml", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".ini", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".ipc", CaseSensitivity::CaseInsensitive)
+        || path.ends_with(".txt", CaseSensitivity::CaseInsensitive)
+        || basename == "CMakeLists.txt"
+        || basename == ".history"
+        || basename == ".shellrc")
+        return "text/plain";
     return "application/octet-stream";
 }