diff --git a/OPTIONS.md b/OPTIONS.md index a5fd6b0cb..da06f31a1 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -265,6 +265,13 @@ These keys are also stored in `QuickLook.config`. ## QuickLook.Plugin.TextViewer.config options +### `` +- Default: `True` +- Type: `Boolean` +- Description: Show line numbers in text previews. Toggle **Show line numbers** in the **…** menu when previewing a TXT file; the choice is saved for subsequent previews and application restarts. +- Example: + - `False` to hide line numbers. + ### `` - Default: `True` - Type: `Boolean` diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.MoreMenu.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.MoreMenu.cs index 5eee34293..8bda2a218 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.MoreMenu.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.MoreMenu.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.IO; using System.Reflection; +using System.Windows; +using System.Windows.Controls; namespace QuickLook.Plugin.TextViewer; @@ -42,6 +44,26 @@ public IEnumerable GetMenuItems() { } + if (extension == ".txt" && _tvp is { } viewer) + { + var checkMark = new TextBlock + { + Text = "✓", + Visibility = viewer.ShowLineNumbers ? Visibility.Visible : Visibility.Hidden, + }; + yield return new MoreMenuItem + { + Header = TranslationHelper.Get("Editor_ShowLineNumbers", translationFile), + Icon = checkMark, + Command = new RelayCommand(() => + { + if (!ReferenceEquals(_tvp, viewer)) return; + viewer.ToggleLineNumbers(); + checkMark.Visibility = viewer.ShowLineNumbers ? Visibility.Visible : Visibility.Hidden; + }), + }; + } + var reopen = extension switch { // HTML <=> HTML TEXT diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index 0da7847f1..f58ad9481 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -72,7 +72,8 @@ static TextViewerPanel() public TextViewerPanel() { - ShowLineNumbers = true; + ShowLineNumbers = SettingHelper.Get("ShowLineNumbers", true, "QuickLook.Plugin.TextViewer"); + UpdateTextPadding(); WordWrap = true; IsReadOnly = true; @@ -89,10 +90,7 @@ public TextViewerPanel() // The default LineNumberMargin in AvalonEdit often contains a thin Line element // used as a visual separator between line numbers and the text. // If found, set its Stroke to Transparent to hide the separator visually. - TextArea.LeftMargins - .OfType() - .FirstOrDefault() - ?.Stroke = Brushes.Transparent; + TextArea.LeftMargins.OfType().FirstOrDefault()?.Stroke = Brushes.Transparent; ContextMenu = new ContextMenu(); // Add "Copy" menu item. @@ -131,6 +129,21 @@ public TextViewerPanel() SearchPanel.Install(this); } + public void ToggleLineNumbers() + { + if (_disposed) return; + ShowLineNumbers = !ShowLineNumbers; + UpdateTextPadding(); + // AvalonEdit recreates the separator when numbers are enabled again. + TextArea.LeftMargins.OfType().FirstOrDefault()?.Stroke = Brushes.Transparent; + SettingHelper.Set("ShowLineNumbers", ShowLineNumbers, "QuickLook.Plugin.TextViewer"); + } + + private void UpdateTextPadding() + { + Padding = new Thickness(ShowLineNumbers ? 0 : 6, 0, 0, 0); + } + public void Dispose() { _disposed = true; diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Translations.config b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Translations.config index 71bbc18ce..e3f8af57d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Translations.config +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Translations.config @@ -2,6 +2,7 @@ + إظهار أرقام الأسطر Consolas انسخ حدد الكل @@ -10,6 +11,7 @@ إعادة فتح كمعاينة CSV + Mostra els números de línia Consolas Copia Selecciona-ho tot @@ -18,6 +20,7 @@ Torna a obrir com a previsualització CSV + Zeilennummern anzeigen Consolas Kopieren Alles markieren @@ -26,6 +29,7 @@ Als CSV-Vorschau erneut öffnen + Show line numbers Consolas Copy Select All @@ -34,6 +38,7 @@ Reopen as CSV preview + Mostrar números de línea Consolas Copiar Seleccionar Todo @@ -42,6 +47,7 @@ Reabrir como vista previa CSV + Afficher les numéros de ligne Consolas Copie Tout sélectionner @@ -50,6 +56,7 @@ Rouvrir en aperçu CSV + Mostra numeri di riga Consolas Copia Seleziona tutto @@ -58,6 +65,7 @@ Riapri come anteprima CSV + 行番号を表示 Consolas,Meiryo UI,MS UI Gothic,MS Gothic コピー すべて選択 @@ -66,6 +74,7 @@ CSV プレビューとして再度開く + 줄 번호 표시 Consolas,Malgun Gothic,Gulim 복사 모두 선택 @@ -74,6 +83,7 @@ CSV 미리보기로 다시 열기 + Vis linjenumre Consolas Kopier Merk alt @@ -82,6 +92,7 @@ Åpne på nytt som CSV-forhåndsvisning + Regelnummers weergeven Consolas Kopiëren Alles selecteren @@ -90,6 +101,7 @@ Opnieuw openen als CSV-voorbeeld + Pokaż numery wierszy Consolas Kopiuj Zaznacz wszystko @@ -98,6 +110,7 @@ Otwórz ponownie jako podgląd CSV + Mostrar números de linha Consolas Copiar Selecionar tudo @@ -106,6 +119,7 @@ Reabrir como visualização CSV + Mostrar números de linha Consolas Copiar Selecionar tudo @@ -114,6 +128,7 @@ Reabrir como pré-visualização CSV + Afișează numerele liniilor Consolas Copiere Selectați tot @@ -122,6 +137,7 @@ Redeschideți ca previzualizare CSV + Отображать номера строк Consolas Копировать Выделить всё @@ -130,6 +146,7 @@ Переоткрыть как предварительный просмотр CSV + Satır numaralarını göster Consolas Kopyala Tümünü seç @@ -138,6 +155,7 @@ CSV önizlemesi olarak yeniden aç + Показувати номери рядків Consolas Копіювати Виділити Все @@ -146,6 +164,7 @@ Перевідкрити як попередній перегляд CSV + Hiển thị số dòng Consolas Sao chép Chọn tất cả @@ -154,6 +173,7 @@ Mở lại dưới dạng xem trước CSV + 显示行号 Consolas,Microsoft Yahei UI,Microsoft Yahei,SimSun 复制 全选 @@ -162,6 +182,7 @@ 重新作为 CSV 预览打开 + 顯示行號 Consolas,Microsoft JhengHei UI,Microsoft JhengHei,MingLiU 複製 全選 @@ -169,6 +190,7 @@ 重新作為圖像預覽開啟 + ओळ क्रमांक दाखवा Consolas,Mangal,Nirmala UI प्रतिलिपी करा सर्व निवडा @@ -176,6 +198,7 @@ प्रतिमा पूर्वावलोकन म्हणून पुन्हा उघडा + पंक्ति संख्याएँ दिखाएँ Consolas,Mangal,Nirmala UI कॉपी करें सभी चुनें @@ -183,6 +206,7 @@ छवि पूर्वावलोकन के रूप में फिर से खोलें + הצג מספרי שורות Consolas העתק בחר הכל @@ -190,6 +214,7 @@ פתח מחדש כתצוגה מקדימה של תמונה + Sorszámok megjelenítése Consolas Másolás Mindet kijelöl @@ -197,6 +222,7 @@ Újranyitás kép előnézetként + Tampilkan nomor baris Consolas Salin Pilih Semua @@ -204,6 +230,7 @@ Buka ulang sebagai pratinjau gambar + Zobraziť čísla riadkov Consolas Kopírovať Označiť všetko @@ -211,6 +238,7 @@ Znova otvoriť ako náhľad obrázka + Εμφάνιση αριθμών γραμμών Consolas Aντιγραφή Επιλογή όλων @@ -218,6 +246,7 @@ Επανανοίξτε ως προεπισκόπηση εικόνας + Visa radnummer Consolas Kopiera Markera allt