diff --git a/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj b/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj index 861a675..905f922 100644 --- a/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj +++ b/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj @@ -8,7 +8,7 @@ true - + diff --git a/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs index 6766ed2..0296d68 100644 --- a/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs @@ -1,23 +1,38 @@ namespace CrossWikiEditor.Core.ViewModels; -public sealed partial class AddOrEditProfileViewModel(IFileDialogService fileDialogService, +public sealed partial class AddOrEditProfileViewModel : ViewModelBase +{ + private readonly IFileDialogService _fileDialogService; + private readonly IProfileRepository _profileRepository; + private readonly int _id; + + public AddOrEditProfileViewModel( + IFileDialogService fileDialogService, IProfileRepository profileRepository, int id) - : ViewModelBase -{ - public bool IsEdit => id != -1; + { + _fileDialogService = fileDialogService; + _profileRepository = profileRepository; + _id = id; + Username = string.Empty; + Password = string.Empty; + DefaultSettingsPath = string.Empty; + Notes = string.Empty; + } + + public bool IsEdit => _id != -1; - [ObservableProperty] private string _username = string.Empty; - [ObservableProperty] private string _password = string.Empty; - [ObservableProperty] private string _defaultSettingsPath = string.Empty; - [ObservableProperty] private bool _shouldSavePassword; - [ObservableProperty] private bool _shouldSelectDefaultSettings; - [ObservableProperty] private string _notes = string.Empty; + [ObservableProperty] public partial string Username { get; set; } + [ObservableProperty] public partial string Password { get; set; } + [ObservableProperty] public partial string DefaultSettingsPath { get; set; } + [ObservableProperty] public partial bool ShouldSavePassword { get; set; } + [ObservableProperty] public partial bool ShouldSelectDefaultSettings { get; set; } + [ObservableProperty] public partial string Notes { get; set; } [RelayCommand] private async Task Browse() { - string[]? result = await fileDialogService.OpenFilePickerAsync("Select settings file", false, ["*.xml"]); + string[]? result = await _fileDialogService.OpenFilePickerAsync("Select settings file", false, ["*.xml"]); if (result?.Length == 1) { DefaultSettingsPath = result[0]; @@ -56,12 +71,12 @@ private void Save(IDialog dialog) if (IsEdit) { - profile.Id = id; - profileRepository.Update(profile); + profile.Id = _id; + _profileRepository.Update(profile); } else { - profileRepository.Insert(profile); + _profileRepository.Insert(profile); } dialog.Close(true); diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs index 20f8408..ec6529d 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs @@ -19,25 +19,35 @@ public MoreViewModel( _dialogService = dialogService; _settingsService = settingsService; _moreOptions = _settingsService.GetCurrentSettings().MoreOptions; + IsAppendOrPrependEnabled = false; + IsAppend = true; + AppendOrPrependContent = string.Empty; + FileType = FileTaskType.None; + SourceFile = string.Empty; + ReplaceFileOrComment = string.Empty; + CategoryType = CategoryTaskType.None; + SourceCategory = string.Empty; + ReplaceCategory = string.Empty; PopulateProperties(); } - [ObservableProperty] private bool _isAppendOrPrependEnabled = false; - [ObservableProperty] private bool _isAppend = true; - [ObservableProperty] private string _appendOrPrependContent = string.Empty; - [ObservableProperty] private int _appendOrPrependNewLines = 0; - [ObservableProperty] private bool _shouldSortMetadataAfterAppendOrPrepend; - [ObservableProperty] private FileTaskType _fileType = FileTaskType.None; - [ObservableProperty] private string _sourceFile = string.Empty; - [ObservableProperty] private string _replaceFileOrComment = string.Empty; - [ObservableProperty] private bool _skipIfNoFileChanged; + [ObservableProperty] public partial bool IsAppendOrPrependEnabled { get; set; } + [ObservableProperty] public partial bool IsAppend { get; set; } + [ObservableProperty] public partial string AppendOrPrependContent { get; set; } + [ObservableProperty] public partial int AppendOrPrependNewLines { get; set; } + [ObservableProperty] public partial bool ShouldSortMetadataAfterAppendOrPrepend { get; set; } - [ObservableProperty] private CategoryTaskType _categoryType = CategoryTaskType.None; - [ObservableProperty] private string _sourceCategory = string.Empty; - [ObservableProperty] private string _replaceCategory = string.Empty; - [ObservableProperty] private bool _skipIfNoCategoryChanged; - [ObservableProperty] private bool _removeSortkey; + [ObservableProperty] public partial FileTaskType FileType { get; set; } + [ObservableProperty] public partial string SourceFile { get; set; } + [ObservableProperty] public partial string ReplaceFileOrComment { get; set; } + [ObservableProperty] public partial bool SkipIfNoFileChanged { get; set; } + + [ObservableProperty] public partial CategoryTaskType CategoryType { get; set; } + [ObservableProperty] public partial string SourceCategory { get; set; } + [ObservableProperty] public partial string ReplaceCategory { get; set; } + [ObservableProperty] public partial bool SkipIfNoCategoryChanged { get; set; } + [ObservableProperty] public partial bool RemoveSortkey { get; set; } partial void OnIsAppendOrPrependEnabledChanged(bool value) => _moreOptions.IsAppendPrependEnabled = value; partial void OnIsAppendChanged(bool value) => _moreOptions.IsAppend = value; diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs index 27a8816..dfdbb1c 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs @@ -21,19 +21,20 @@ public OptionsViewModel( _dialogService = dialogService; _settingsService = settingsService; _generalOptions = _settingsService.GetCurrentSettings().GeneralOptions; + NormalFindAndReplaceRules = []; PopulateProperties(); PropertyChanged += OptionsViewModel_PropertyChanged; } - [ObservableProperty] private bool _autoTag; - [ObservableProperty] private bool _applyGeneralFixes; - [ObservableProperty] private bool _unicodifyWholePage; - [ObservableProperty] private bool _findAndReplace; - [ObservableProperty] private bool _skipIfNoReplacement; - [ObservableProperty] private bool _skipIfOnlyMinorReplacementMade; - [ObservableProperty] private bool _regexTypoFixing; - [ObservableProperty] private bool _skipIfNoTypoFixed; - [ObservableProperty] private NormalFindAndReplaceRules _normalFindAndReplaceRules = []; + [ObservableProperty] public partial bool AutoTag { get;set; } + [ObservableProperty] public partial bool ApplyGeneralFixes { get; set; } + [ObservableProperty] public partial bool UnicodifyWholePage { get; set; } + [ObservableProperty] public partial bool FindAndReplace { get; set; } + [ObservableProperty] public partial bool SkipIfNoReplacement { get; set; } + [ObservableProperty] public partial bool SkipIfOnlyMinorReplacementMade { get; set; } + [ObservableProperty] public partial bool RegexTypoFixing { get; set; } + [ObservableProperty] public partial bool SkipIfNoTypoFixed { get; set; } + [ObservableProperty] public partial NormalFindAndReplaceRules NormalFindAndReplaceRules { get; set; } [RelayCommand] private async Task OpenNormalFindAndReplaceDialog() diff --git a/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs index c7f10b2..a18848d 100644 --- a/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs @@ -2,45 +2,70 @@ namespace CrossWikiEditor.Core.ViewModels; -public sealed partial class DatabaseScannerViewModel(ISettingsService settingsService, - IWikiClientCache wikiClientCache, - IFileDialogService fileDialogService) : ViewModelBase +public sealed partial class DatabaseScannerViewModel : ViewModelBase { private Task? _scannerTask; private Task? _updateUiTask; private CancellationTokenSource _scannerCancellationTokenSource = new(); private readonly ConcurrentQueue _titlesQueue = new(); + private readonly ISettingsService _settingsService; + private readonly IWikiClientCache _wikiClientCache; + private readonly IFileDialogService _fileDialogService; public EventHandler? _convertedTextChanged; - [ObservableProperty] private ObservableCollection _subjectNamespaces = []; - [ObservableProperty] private ObservableCollection _talkNamespaces = []; - [ObservableProperty] private ObservableCollection _pages = []; - - [ObservableProperty] private bool _isTitleContainsEnabled; - [ObservableProperty] private bool _isTitleNotContainsEnabled; - [ObservableProperty] private string _titleContains = string.Empty; - [ObservableProperty] private string _titleNotContains = string.Empty; - [ObservableProperty] private bool _isTitleContainsRegex; - [ObservableProperty] private bool _isTitleContainsCaseSensitive; - - [ObservableProperty] private bool _isAllTalkChecked; - [ObservableProperty] private bool _isAllSubjectChecked; - [ObservableProperty] private string _databaseFile = string.Empty; - [ObservableProperty] private string _siteName = string.Empty; - [ObservableProperty] private string _base = string.Empty; - [ObservableProperty] private string _generator = string.Empty; - [ObservableProperty] private string _case = string.Empty; - - [ObservableProperty] private bool _isSearchDateChecked; - [ObservableProperty] private DateTimeOffset _selectedStartDate; - [ObservableProperty] private DateTimeOffset _selectedEndDate; - [ObservableProperty] private DateTimeOffset _minStartYear = new(new DateTime(2000, 1, 1)); - [ObservableProperty] private DateTimeOffset _minEndYear = new(new DateTime(2000, 1, 1)); - - [ObservableProperty] private string _convertedText = string.Empty; - [ObservableProperty] private bool _isAlphabetisedHeading; - [ObservableProperty] private int _numberOfPagesOnEachSection = 25; - [ObservableProperty] private bool _isNumericList; + public DatabaseScannerViewModel( + ISettingsService settingsService, + IWikiClientCache wikiClientCache, + IFileDialogService fileDialogService) + { + _settingsService = settingsService; + _wikiClientCache = wikiClientCache; + _fileDialogService = fileDialogService; + SubjectNamespaces = []; + TalkNamespaces = []; + Pages = []; + TitleContains = string.Empty; + TitleNotContains = string.Empty; + DatabaseFile = string.Empty; + SiteName = string.Empty; + Base = string.Empty; + Generator = string.Empty; + Case = string.Empty; + MinStartYear = new(new DateTime(2000, 1, 1)); + MinEndYear = new(new DateTime(2000, 1, 1)); + ConvertedText = string.Empty; + NumberOfPagesOnEachSection = 25; + } + + [ObservableProperty] public partial ObservableCollection SubjectNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection TalkNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection Pages { get; set; } + + [ObservableProperty] public partial bool IsTitleContainsEnabled { get; set;} + [ObservableProperty] public partial bool IsTitleNotContainsEnabled { get; set; } + [ObservableProperty] public partial string TitleContains {get;set;} + [ObservableProperty] public partial string TitleNotContains { get; set; } + [ObservableProperty] public partial bool IsTitleContainsRegex {get;set;} + [ObservableProperty] public partial bool IsTitleContainsCaseSensitive { get; set; } + + [ObservableProperty] public partial bool IsAllTalkChecked { get; set; } + [ObservableProperty] public partial bool IsAllSubjectChecked { get; set; } + [ObservableProperty] public partial string DatabaseFile { get; set; } + [ObservableProperty] public partial string SiteName { get; set; } + [ObservableProperty] public partial string Base { get; set; } + [ObservableProperty] public partial string Generator { get; set; } + [ObservableProperty] public partial string Case { get; set; } + + [ObservableProperty] public partial bool IsSearchDateChecked { get; set; } + [ObservableProperty] public partial DateTimeOffset SelectedStartDate { get; set; } + [ObservableProperty] public partial DateTimeOffset SelectedEndDate { get; set; } + [ObservableProperty] public partial DateTimeOffset MinStartYear { get; set; } + [ObservableProperty] public partial DateTimeOffset MinEndYear { get; set; } + + [ObservableProperty] public partial string ConvertedText { get; set; } + [ObservableProperty] public partial bool IsAlphabetisedHeading { get; set; } + [ObservableProperty] public partial int NumberOfPagesOnEachSection { get; set; } + [ObservableProperty] public partial bool IsNumericList { get; set; } partial void OnIsAllTalkCheckedChanged(bool value) { @@ -59,7 +84,7 @@ partial void OnIsAllSubjectCheckedChanged(bool value) [RelayCommand] public async Task BrowseCommand() { - string[]? result = await fileDialogService.OpenFilePickerAsync("Open Database dump", false); + string[]? result = await _fileDialogService.OpenFilePickerAsync("Open Database dump", false); if (result is not { Length: 1 }) { return; @@ -80,7 +105,7 @@ private void Start() _updateUiTask = Task.Run(async () => { - WikiSite wikiSite = await wikiClientCache.GetWikiSite(settingsService.CurrentApiUrl); + WikiSite wikiSite = await _wikiClientCache.GetWikiSite(_settingsService.CurrentApiUrl); while (_scannerTask != null) { UpdateUi(wikiSite); diff --git a/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs index b2e8a35..a21b152 100644 --- a/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs @@ -1,9 +1,24 @@ namespace CrossWikiEditor.Core.ViewModels; -public partial class FilterViewModel(List subjectNamespaces, List talkNamespaces, - TextFileListProvider textFileListProvider) - : ViewModelBase +public partial class FilterViewModel : ViewModelBase { + private readonly TextFileListProvider _textFileListProvider; + + public FilterViewModel( + List subjectNamespaces, + List talkNamespaces, + TextFileListProvider textFileListProvider) + { + _textFileListProvider = textFileListProvider; + SubjectNamespaces = subjectNamespaces.ToObservableCollection(); + TalkNamespaces = talkNamespaces.ToObservableCollection(); + Pages = []; + SetOperations = new[] { Models.SetOperations.SymmetricDifference, Models.SetOperations.Intersection }.ToObservableCollection(); + RemoveTitlesContaining = string.Empty; + KeepTitlesContaining = string.Empty; + SelectedSetOperations = Models.SetOperations.SymmetricDifference; + } + [RelayCommand] private void Save(IDialog dialog) { @@ -29,11 +44,11 @@ private void Close(IDialog dialog) [RelayCommand] private async Task OpenFile() { - await textFileListProvider.GetAdditionalParams(); + await _textFileListProvider.GetAdditionalParams(); - if (textFileListProvider.CanMake) + if (_textFileListProvider.CanMake) { - Result> result = await textFileListProvider.MakeList(); + Result> result = await _textFileListProvider.MakeList(); if (result is { IsSuccessful: true, Value: not null }) { Pages = result.Value.ToObservableCollection(); @@ -61,20 +76,16 @@ partial void OnIsAllSubjectCheckedChanged(bool value) .ToObservableCollection(); } - [ObservableProperty] private ObservableCollection _subjectNamespaces = subjectNamespaces.ToObservableCollection(); - [ObservableProperty] private ObservableCollection _talkNamespaces = talkNamespaces.ToObservableCollection(); - [ObservableProperty] private ObservableCollection _pages = []; - - [ObservableProperty] - private ObservableCollection _setOperations = - new[] { Models.SetOperations.SymmetricDifference, Models.SetOperations.Intersection }.ToObservableCollection(); - - [ObservableProperty] private bool _isAllTalkChecked; - [ObservableProperty] private bool _isAllSubjectChecked; - [ObservableProperty] private bool _useRegex; - [ObservableProperty] private bool _sortAlphabetically; - [ObservableProperty] private bool _removeDuplicates; - [ObservableProperty] private string _removeTitlesContaining = string.Empty; - [ObservableProperty] private string _keepTitlesContaining = string.Empty; - [ObservableProperty] private SetOperations _selectedSetOperations = Models.SetOperations.SymmetricDifference; + [ObservableProperty] public partial ObservableCollection SubjectNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection TalkNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection Pages { get; set; } + [ObservableProperty] public partial ObservableCollection SetOperations { get; set; } + [ObservableProperty] public partial bool IsAllTalkChecked { get; set; } + [ObservableProperty] public partial bool IsAllSubjectChecked { get; set; } + [ObservableProperty] public partial bool UseRegex { get; set; } + [ObservableProperty] public partial bool SortAlphabetically { get; set; } + [ObservableProperty] public partial bool RemoveDuplicates { get; set; } + [ObservableProperty] public partial string RemoveTitlesContaining { get; set; } + [ObservableProperty] public partial string KeepTitlesContaining { get; set; } + [ObservableProperty] public partial SetOperations SelectedSetOperations { get; set; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs index cc9e883..4027371 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs @@ -4,8 +4,9 @@ public sealed partial class EditBoxViewModel : ViewModelBase { public EditBoxViewModel(IMessengerWrapper messenger) { + Content = string.Empty; messenger.Register(this, (recipient, message) => Content = message.NewContent); } - [ObservableProperty] private string _content = string.Empty; + [ObservableProperty] public partial string Content { get; set; } } \ No newline at end of file