diff --git a/devel/0167.md b/devel/0167.md new file mode 100644 index 0000000000..8e7c30eeeb --- /dev/null +++ b/devel/0167.md @@ -0,0 +1,18 @@ +# [0167] no_name_x.tmu 文档路径变更 + +## 相关文档 +- [dddd.md](dddd.md) - 任务文档模板 + +## What + +no_name_x.tmu 文档的路径改为 `~/文档/LiiiSTEM/no_name/`(通过 Qt 的 `QStandardPaths::DocumentsLocation` 获取本地化文档目录)。 + +1. 默认格式从 `.tm` 改为 `.tmu` + +## How + +1. `src/Mogan/Research/research.cpp` 在 Qt 初始化后,调用 `QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)` 获取本地化 Documents 路径,写入 `TEXMACS_DOCUMENTS_PATH` 环境变量 +2. `src/System/Misc/tm_sys_utils.cpp` 新增 `get_documents_path()`,读取上述环境变量并回退到 `$HOME/Documents` +3. `src/System/Files/tm_file.cpp` 中的 `url_scratch` 与 `is_scratch` 使用 `get_documents_path() * "LiiiSTEM/no_name"` 作为新路径 +4. `src/Texmacs/Data/new_buffer.cpp` 中的 `make_new_buffer` 与 `propose_title` 将后缀从 `.tm` 改为 `.tmu`,并同步调整标题解析偏移 +5. `url_numbered` 内部已有 `mkdir`,`LiiiSTEM/no_name` 目录会在首次创建临时文件时自动初始化 diff --git a/src/Mogan/Research/research.cpp b/src/Mogan/Research/research.cpp index c2a170ed7a..2745d94bdc 100644 --- a/src/Mogan/Research/research.cpp +++ b/src/Mogan/Research/research.cpp @@ -49,6 +49,7 @@ void mac_fix_paths (); #include #include #include +#include #endif #ifdef MACOSX_EXTENSIONS @@ -232,6 +233,15 @@ main (int argc, char** argv) { if (headless_mode) qtmcoreapp= new QTMCoreApplication (argc, argv); else qtmapp= new QTMApplication (argc, argv); + // Set documents path for scratch files + { + QString docsDir= + QStandardPaths::writableLocation (QStandardPaths::DocumentsLocation); + if (docsDir.isEmpty ()) + docsDir= QStandardPaths::writableLocation (QStandardPaths::HomeLocation); + set_env ("TEXMACS_DOCUMENTS_PATH", from_qstring_utf8 (docsDir)); + } + // before startup login dialog init_texmacs_path (argc, argv); init_texmacs_front (); diff --git a/src/System/Files/tm_file.cpp b/src/System/Files/tm_file.cpp index b968986bef..c351515c3e 100644 --- a/src/System/Files/tm_file.cpp +++ b/src/System/Files/tm_file.cpp @@ -18,6 +18,7 @@ #include "lolly/system/subprocess.hpp" #include "scheme.hpp" #include "sys_utils.hpp" +#include "tm_sys_utils.hpp" #include "tm_timer.hpp" #include "tmfs_url.hpp" #include "tree_helper.hpp" @@ -104,13 +105,13 @@ url_numbered (url dir, string prefix, string postfix, int i) { url url_scratch (string prefix, string postfix, int i) { - url dir ("$TEXMACS_HOME_PATH/texts/scratch"); + url dir= get_documents_path () * "LiiiSTEM/no_name"; return url_numbered (dir, prefix, postfix, i); } bool is_scratch (url u) { - return head (u) == url ("$TEXMACS_HOME_PATH/texts/scratch"); + return head (u) == get_documents_path () * "LiiiSTEM/no_name"; } string diff --git a/src/System/Files/tm_file.hpp b/src/System/Files/tm_file.hpp index 1e2ce1c36a..bcf5cb31ea 100644 --- a/src/System/Files/tm_file.hpp +++ b/src/System/Files/tm_file.hpp @@ -46,9 +46,9 @@ eval_system (string which, url u1, url u2) { escape_sh (concretize (u2))); } -url url_numbered (url dir, string prefix, string postfix, int i= 1); -url url_scratch (string prefix= "no_name_", string postfix= ".tm", int i= 1); -bool is_scratch (url u); +url url_numbered (url dir, string prefix, string postfix, int i= 1); +url url_scratch (string prefix= "no_name_", string postfix= ".tmu", int i= 1); +bool is_scratch (url u); string file_format (url u); /** diff --git a/src/System/Misc/tm_sys_utils.cpp b/src/System/Misc/tm_sys_utils.cpp index bd10457bfe..67cd7d6e4a 100644 --- a/src/System/Misc/tm_sys_utils.cpp +++ b/src/System/Misc/tm_sys_utils.cpp @@ -135,6 +135,13 @@ init_texmacs_home_path () { } } +url +get_documents_path () { + string docs= get_env ("TEXMACS_DOCUMENTS_PATH"); + if (!is_empty (docs)) return url_system (docs); + return url_system (get_env ("HOME") * "/Documents"); +} + url get_tm_cache_path () { #if defined(OS_WIN) || defined(OS_MINGW) diff --git a/src/System/Misc/tm_sys_utils.hpp b/src/System/Misc/tm_sys_utils.hpp index fbef2ad535..13e2646234 100644 --- a/src/System/Misc/tm_sys_utils.hpp +++ b/src/System/Misc/tm_sys_utils.hpp @@ -29,6 +29,7 @@ string check_stderr (string s); url get_texmacs_path (); url get_texmacs_home_path (); void init_texmacs_home_path (); +url get_documents_path (); url get_tm_cache_path (); url get_tm_preference_path (); diff --git a/src/Texmacs/Data/new_buffer.cpp b/src/Texmacs/Data/new_buffer.cpp index af6b2127e4..d784fd7b9e 100644 --- a/src/Texmacs/Data/new_buffer.cpp +++ b/src/Texmacs/Data/new_buffer.cpp @@ -211,7 +211,7 @@ url make_new_buffer () { int i= 1; while (true) { - url name= url_scratch ("no_name_", ".tm", i); + url name= url_scratch ("no_name_", ".tmu", i); if (is_nil (concrete_buffer (name))) { set_buffer_tree (name, tree (DOCUMENT)); return name; @@ -232,14 +232,14 @@ buffer_has_name (url name) { string propose_title (string old_title, url u, tree doc) { string name= as_string (tail (u)); - if (starts (name, "no_name_") && ends (name, ".tm")) { + if (starts (name, "no_name_") && ends (name, ".tmu")) { string no_name= translate ("No name"); for (int i= 0; i < N (no_name); i++) if (((unsigned char) (no_name[i])) >= (unsigned char) 128) { no_name= "No name"; break; } - name= no_name * " [" * name (8, N (name) - 3) * "]"; + name= no_name * " [" * name (8, N (name) - 4) * "]"; } if ((name == "") || (name == ".")) name= as_string (tail (u * url_parent ())); if ((name == "") || (name == ".")) name= as_string (u); diff --git a/tests/Data/view_type_test.cpp b/tests/Data/view_type_test.cpp index 66a715b4c1..26d65499e8 100644 --- a/tests/Data/view_type_test.cpp +++ b/tests/Data/view_type_test.cpp @@ -27,7 +27,8 @@ private slots: void Test_view_type::test_normal_cases () { - string normal_url_1= "tmfs://view/1/default/Users/texts/scratch/no_name_5.tm"; + string normal_url_1= + "tmfs://view/1/default/Users/texts/scratch/no_name_5.tmu"; string normal_url_2= "tmfs://view/2/default/Users/jimzhou/Downloads/user_guide.tmu"; string normal_url_114514= "tmfs://view/114514/default/Users/Documents/A.tmu"; @@ -62,10 +63,11 @@ Test_view_type::test_live_cases () { void Test_view_type::test_broken_cases () { - string broken_url_1= "ntfs://view/1/default/Users/texts/scratch/no_name_5.tm"; + string broken_url_1= + "ntfs://view/1/default/Users/texts/scratch/no_name_5.tmu"; string broken_url_2= "tmfs://view//tmfs/aux/edit-strong"; string broken_url_3= - "tmfs://view//default/Users/texts/scratch/no_name_5.tm"; + "tmfs://view//default/Users/texts/scratch/no_name_5.tmu"; string broken_url_4= "tmfs://view/abc/tmfs/aux/edit-strong"; QCOMPARE (is_tmfs_view_type (broken_url_1, "default"), false); QCOMPARE (is_tmfs_view_type (broken_url_2, "aux"), false);