Skip to content

Commit

Permalink
Moved CommandDebugPopup and LocalizationDebugWindow into new Debug fo…
Browse files Browse the repository at this point in the history
…lder and kept LocalizationDebugWindow ViewModel
  • Loading branch information
CPKreu committed May 8, 2023
1 parent 0df0f41 commit 10ba953
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using Microsoft.Win32;
using Newtonsoft.Json;
using PixiEditor.Helpers;
using PixiEditor.Localization;
using PixiEditor.Models.Commands.Attributes;
using PixiEditor.Models.Commands.Attributes.Commands;
using PixiEditor.Models.Commands.Templates.Parsers;
using PixiEditor.Models.Dialogs;
using PixiEditor.Models.Enums;
using PixiEditor.Models.UserPreferences;
using PixiEditor.Views.Dialogs;
using PixiEditor.Views.Dialogs.DebugDialogs;

namespace PixiEditor.ViewModels.SubViewModels.Main;

Expand Down Expand Up @@ -198,7 +198,9 @@ public void OpenCommandDebugWindow()
[Command.Debug("PixiEditor.Debug.OpenLocalizationDebugWindow", "OPEN_LOCALIZATION_DEBUG_WINDOW", "OPEN_LOCALIZATION_DEBUG_WINDOW")]
public void OpenLocalizationDebugWindow()
{
new LocalizationDebugWindow().Show();
var window = Application.Current.Windows.OfType<LocalizationDebugWindow>().FirstOrDefault(new LocalizationDebugWindow());
window.Show();
window.Activate();
}

[Command.Internal("PixiEditor.Debug.SetLanguageFromFilePicker")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="PixiEditor.Views.Dialogs.CommandDebugPopup"
<Window x:Class="PixiEditor.Views.Dialogs.DebugDialogs.CommandDebugPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using PixiEditor.Models.Commands;
using PixiEditor.Models.Commands.Commands;
using PixiEditor.Models.Commands.Evaluators;
using PixiEditor.Models.DataHolders;

namespace PixiEditor.Views.Dialogs;
namespace PixiEditor.Views.Dialogs.DebugDialogs;

public partial class CommandDebugPopup : Window
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="PixiEditor.Views.Dialogs.LocalizationDebugWindow"
<Window x:Class="PixiEditor.Views.Dialogs.DebugDialogs.LocalizationDebugWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -64,7 +64,7 @@
<TextBox Grid.Column="1" Style="{StaticResource DarkTextBoxStyle}" TextChanged="ApiKeyChanged" Text="{Binding DataContext.ApiKey, ElementName=popup}"></TextBox>
<Button Style="{StaticResource DarkRoundButton}" Margin="5,0,0,0" Grid.Column="2" views:Translator.Key="LOG_IN" Command="{Binding DataContext.LoadApiKeyCommand, ElementName=popup}"/>
</Grid>
<Grid Visibility="{Binding DataContext.LoggedIn, ElementName=popup, Converter={BoolToVisibilityConverter}}" Margin="0,5,0,0" Height="25">
<Grid Visibility="{Binding DataContext.LoggedIn, Mode=OneWay, ElementName=popup, Converter={BoolToVisibilityConverter}}" Margin="0,5,0,0" Height="25">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
using System.Collections.ObjectModel;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PixiEditor.Helpers;
using PixiEditor.Localization;
using PixiEditor.Models.UserPreferences;

namespace PixiEditor.Views.Dialogs;
namespace PixiEditor.Views.Dialogs.DebugDialogs;

public partial class LocalizationDebugWindow : Window
{
private LocalizationDataContext dataContext;
private static LocalizationDataContext dataContext;
private bool passedStartup;

public LocalizationDebugWindow()
{
InitializeComponent();
DataContext = dataContext = new LocalizationDataContext(this);
DataContext = (dataContext ??= new LocalizationDataContext(this));
}

private void ApiKeyChanged(object sender, TextChangedEventArgs e)
{
if (!passedStartup)
{
passedStartup = true;
return;
}

dataContext.LoggedIn = false;
dataContext.StatusMessage = "NOT_LOGGED_IN";
}
Expand All @@ -44,7 +51,7 @@ private class LocalizationDataContext : NotifyableObject
{
private const int ProjectId = 400351;

private readonly LocalizationDebugWindow window;
private Dispatcher dispatcher;
private string apiKey;
private bool loggedIn;
private LocalizedString statusMessage = "NOT_LOGGED_IN";
Expand Down Expand Up @@ -90,7 +97,7 @@ public PoeLanguage SelectedLanguage

public LocalizationDataContext(LocalizationDebugWindow window)
{
this.window = window;
dispatcher = Application.Current.Dispatcher;
apiKey = PreferencesSettings.Current.GetLocalPreference<string>("POEditor_API_Key");
LoadApiKeyCommand = new RelayCommand(LoadApiKey, _ => !string.IsNullOrWhiteSpace(apiKey));
SyncLanguageCommand =
Expand All @@ -108,7 +115,7 @@ private void LoadApiKey(object parameter)
{
var result = await CheckProjectByIdAsync(ApiKey);
window.Dispatcher.Invoke(() =>
dispatcher.Invoke(() =>
{
LoggedIn = result.IsSuccess;
StatusMessage = result.Message;
Expand Down Expand Up @@ -139,7 +146,7 @@ private void LoadApiKey(object parameter)
}
finally
{
window.Dispatcher.Invoke(() => Mouse.OverrideCursor = null);
dispatcher.Invoke(() => Mouse.OverrideCursor = null);
}
});
}
Expand All @@ -154,7 +161,7 @@ private void SyncLanguage(object parameter)
{
var result = await DownloadLanguage(ApiKey, SelectedLanguage.Code);
window.Dispatcher.Invoke(() =>
dispatcher.Invoke(() =>
{
StatusMessage = result.Message;
DebugViewModel.Owner.LocalizationProvider.LoadDebugKeys(result.Output, SelectedLanguage.IsRightToLeft);
Expand All @@ -166,7 +173,7 @@ private void SyncLanguage(object parameter)
}
finally
{
window.Dispatcher.Invoke(() => Mouse.OverrideCursor = null);
dispatcher.Invoke(() => Mouse.OverrideCursor = null);
}
});
}
Expand Down

0 comments on commit 10ba953

Please sign in to comment.