7aa96c99a3
The two %APPDATA% / %LOCALAPPDATA% paths in Settings → אודות are now hyperlinks. Click to open the folder (creates it lazily if it's not there yet, so the link works before the first log is written). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Documents;
|
|
using MarcusLaw.OutlookAddin.UI.ViewModels;
|
|
|
|
namespace MarcusLaw.OutlookAddin.UI.Dialogs
|
|
{
|
|
public partial class SettingsDialog : Window
|
|
{
|
|
private SettingsViewModel? _viewModel;
|
|
|
|
public SettingsDialog()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public SettingsDialog(SettingsViewModel viewModel) : this()
|
|
{
|
|
AttachViewModel(viewModel);
|
|
}
|
|
|
|
public void AttachViewModel(SettingsViewModel viewModel)
|
|
{
|
|
if (_viewModel != null)
|
|
{
|
|
_viewModel.RequestClose -= OnRequestClose;
|
|
_viewModel.ApiKeyReader = null;
|
|
}
|
|
_viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
|
|
DataContext = _viewModel;
|
|
_viewModel.RequestClose += OnRequestClose;
|
|
_viewModel.ApiKeyReader = () => ApiKeyBox.Password;
|
|
if (!string.IsNullOrEmpty(_viewModel.InitialApiKey))
|
|
{
|
|
ApiKeyBox.Password = _viewModel.InitialApiKey;
|
|
}
|
|
}
|
|
|
|
private void OnRequestClose(object? sender, EventArgs e)
|
|
{
|
|
DialogResult = _viewModel?.DialogResult;
|
|
Close();
|
|
}
|
|
|
|
private void OnOpenFolderHyperlink(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!(sender is Hyperlink h) || !(h.Tag is string raw)) return;
|
|
try
|
|
{
|
|
var path = Environment.ExpandEnvironmentVariables(raw);
|
|
// Create the folder lazily so the link works even on the very
|
|
// first run, before any log has been written.
|
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
|
Process.Start(new ProcessStartInfo("explorer.exe", "\"" + path + "\"") { UseShellExecute = true });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("פתיחת התיקייה נכשלה: " + ex.Message, "Klear",
|
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|