Фикс: код как ввёл пользователь + последнее выбранное хранилище
- CodeBlock: <pre> white-space:pre-wrap + TextEdit RichText, без ScrollView, implicitHeight contentHeight+20 — весь код виден целиком, как ввёл, не в одну строку; только иконка 📋
- MainWindow: vaultSwitcher теперь vaultManager.selectVault(modelData) перед openWindow, main.cpp connect windowOpened -> setCurrentVault — запуск с последним выбранным, а не добавленным; проверено на /Users/alex/Nextcloud/test и test-vault
- Tests: vault_select_test + mdparser parseBlocks
This commit is contained in:
@@ -199,6 +199,7 @@ ApplicationWindow {
|
|||||||
if (modelData === window.activeVault) {
|
if (modelData === window.activeVault) {
|
||||||
vaultSwitcher.close()
|
vaultSwitcher.close()
|
||||||
} else {
|
} else {
|
||||||
|
vaultManager.selectVault(modelData)
|
||||||
windowController.openWindow(modelData)
|
windowController.openWindow(modelData)
|
||||||
vaultSwitcher.close()
|
vaultSwitcher.close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,14 @@ Rectangle {
|
|||||||
id: codeText
|
id: codeText
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 10
|
anchors.margins: 10
|
||||||
text: root.highlightedText.length > 0 ? root.highlightedText : root.code
|
// Сохраняем форматирование как ввёл пользователь: оборачиваем в <pre> с pre-wrap
|
||||||
|
text: {
|
||||||
|
let src = root.highlightedText
|
||||||
|
if (!src || src.length === 0) {
|
||||||
|
src = root.code.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """)
|
||||||
|
}
|
||||||
|
return "<pre style=\"margin:0;white-space:pre-wrap;word-wrap:break-word;tab-size:4;\">" + src + "</pre>"
|
||||||
|
}
|
||||||
textFormat: TextEdit.RichText
|
textFormat: TextEdit.RichText
|
||||||
wrapMode: TextEdit.Wrap
|
wrapMode: TextEdit.Wrap
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
|||||||
+8
-2
@@ -70,8 +70,14 @@ int main(int argc, char *argv[])
|
|||||||
&engine, QStringLiteral("qrc:/qt/qml/Flora/qml/MainWindow.qml"));
|
&engine, QStringLiteral("qrc:/qt/qml/Flora/qml/MainWindow.qml"));
|
||||||
engine.rootContext()->setContextProperty("windowController", &windowController);
|
engine.rootContext()->setContextProperty("windowController", &windowController);
|
||||||
|
|
||||||
// Основное окно = последнее (основное) хранилище. Если хранилищ нет —
|
// При открытии любого окна — запоминаем его как последнее выбранное (для следующего запуска)
|
||||||
// откроется мастер первого запуска.
|
QObject::connect(&windowController, &WindowController::windowOpened,
|
||||||
|
&settingsStore, [&](const QString &vault){
|
||||||
|
if (!vault.isEmpty()) settingsStore.setCurrentVault(vault);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Основное окно = последнее выбранное хранилище (а не последнее добавленное).
|
||||||
|
// currentVault теперь обновляется при каждом выборе в переключателе.
|
||||||
windowController.openWindow(settingsStore.currentVault());
|
windowController.openWindow(settingsStore.currentVault());
|
||||||
|
|
||||||
// Окна создаются через QQmlComponent (WindowController), поэтому проверяем
|
// Окна создаются через QQmlComponent (WindowController), поэтому проверяем
|
||||||
|
|||||||
@@ -161,3 +161,13 @@ add_executable(flora_git_history_test git_history_test.cpp
|
|||||||
target_include_directories(flora_git_history_test PRIVATE ../src)
|
target_include_directories(flora_git_history_test PRIVATE ../src)
|
||||||
target_link_libraries(flora_git_history_test PRIVATE Qt6::Core Flora_libgit2_static)
|
target_link_libraries(flora_git_history_test PRIVATE Qt6::Core Flora_libgit2_static)
|
||||||
add_test(NAME flora_git_history_test COMMAND flora_git_history_test)
|
add_test(NAME flora_git_history_test COMMAND flora_git_history_test)
|
||||||
|
|
||||||
|
# Тест выбора хранилища (последнее выбранное, а не добавленное)
|
||||||
|
add_executable(flora_vault_select_test vault_select_test.cpp
|
||||||
|
../src/app/VaultManager.cpp
|
||||||
|
../src/core/SettingsStore.cpp
|
||||||
|
../src/git/GitManager.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(flora_vault_select_test PRIVATE ../src)
|
||||||
|
target_link_libraries(flora_vault_select_test PRIVATE Qt6::Core Flora_libgit2_static)
|
||||||
|
add_test(NAME flora_vault_select_test COMMAND flora_vault_select_test)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QDir>
|
||||||
|
#include <cstdio>
|
||||||
|
#include "core/SettingsStore.h"
|
||||||
|
#include "app/VaultManager.h"
|
||||||
|
#include "git/GitManager.h"
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
app.setOrganizationName("TestVault");
|
||||||
|
app.setApplicationName("test");
|
||||||
|
QTemporaryDir dir;
|
||||||
|
if(!dir.isValid()) return 1;
|
||||||
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, dir.path());
|
||||||
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
SettingsStore s;
|
||||||
|
GitManager g;
|
||||||
|
VaultManager vm(&s, &g);
|
||||||
|
QString v1 = dir.path() + "/vault1";
|
||||||
|
QString v2 = dir.path() + "/vault2";
|
||||||
|
if(!vm.createVault(v1).isEmpty()) return 1;
|
||||||
|
if(s.currentVault() != QDir::cleanPath(v1)) { std::fprintf(stderr,"FAIL v1 current %s\n", qPrintable(s.currentVault())); return 1; }
|
||||||
|
if(!vm.createVault(v2).isEmpty()) return 1;
|
||||||
|
if(s.currentVault() != QDir::cleanPath(v2)) return 1;
|
||||||
|
s.setCurrentVault(v1);
|
||||||
|
if(s.currentVault() != QDir::cleanPath(v1)) return 1;
|
||||||
|
{
|
||||||
|
SettingsStore s2;
|
||||||
|
if(s2.currentVault() != QDir::cleanPath(v1)) { std::fprintf(stderr,"FAIL restart current %s\n", qPrintable(s2.currentVault())); return 1; }
|
||||||
|
if(s2.vaults().size()!=2) return 1;
|
||||||
|
if(s2.vaults()[0] != QDir::cleanPath(v2)) return 1;
|
||||||
|
}
|
||||||
|
std::printf("VAULT SELECT TEST OK\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user