Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Fix functionality regarding editing button + property renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger committed Mar 21, 2024
1 parent 800adf0 commit ce1fe26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ActiveDirectoryQuerier/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<!-- ROW 0 END -->
<!-- GRID ROW 1 START -->
<!-- TextBox as Console Output -->
<TextBox Grid.Row="1" Text="{Binding ConsoleViewModelOutputInQueryBuilder.ConsoleOutput}"
<TextBox Grid.Row="1" Text="{Binding ConsoleOutputInQueryBuilder.ConsoleOutput}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="10" IsReadOnly="True" TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" />
Expand All @@ -220,7 +220,7 @@
SelectedItem="{Binding SelectedQueryInActiveDirectoryInfo}"
ItemsSource="{Binding AvailableQueriesInActiveDirectoryInfo.AvailableOptions.Keys }" />
</Grid>
<TextBox Grid.Row="1" Text="{Binding ConsoleViewModelOutputInActiveDirectoryInfo.ConsoleOutput}"
<TextBox Grid.Row="1" Text="{Binding ConsoleOutputInActiveDirectoryInfo.ConsoleOutput}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="10" IsReadOnly="True" TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" />
Expand Down
45 changes: 27 additions & 18 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
private Command? _selectedCommandInQueryBuilder;
private ConsoleViewModel _consoleOutputInQueryBuilder;
private ConsoleViewModel _consoleOutputInActiveDirectoryInfo;
private ObservableCollection<Button>? _queryButtonStackPanel; // TODO: Rename to be more descriptive.

private ObservableCollection<Button>? _queryButtonStackPanel;
// [[ Other fields ]] ----------------------------------------------------------- //

private Query? _queryBeingEdited;
Expand All @@ -47,26 +47,26 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
public ObservableCollection<Button> QueryButtonStackPanel => _queryButtonStackPanel ??=
new ObservableCollection<Button>();

public ConsoleViewModel ConsoleViewModelOutputInQueryBuilder
public ConsoleViewModel ConsoleOutputInQueryBuilder
{
get => _consoleOutputInQueryBuilder;
set {
if (_consoleOutputInQueryBuilder != value)
{
_consoleOutputInQueryBuilder = value;
OnPropertyChanged(nameof(ConsoleViewModelOutputInQueryBuilder));
OnPropertyChanged(nameof(ConsoleOutputInQueryBuilder));
}
}
}

public ConsoleViewModel ConsoleViewModelOutputInActiveDirectoryInfo
public ConsoleViewModel ConsoleOutputInActiveDirectoryInfo
{
get => _consoleOutputInActiveDirectoryInfo;
set {
if (_consoleOutputInActiveDirectoryInfo != value)
{
_consoleOutputInActiveDirectoryInfo = value;
OnPropertyChanged(nameof(ConsoleViewModelOutputInActiveDirectoryInfo));
OnPropertyChanged(nameof(ConsoleOutputInActiveDirectoryInfo));
}
}
}
Expand Down Expand Up @@ -138,6 +138,7 @@ public bool IsQueryEditingEnabled
{
_isQueryEditingEnabled = value;
OnPropertyChanged(nameof(IsQueryEditingEnabled));
OnIsQueryEditingEnabledChanged();
}
}
}
Expand Down Expand Up @@ -308,7 +309,7 @@ private async void ExecuteSelectedQueryInADInfo(object _)
if (_activeDirectoryInfo.AvailableOptions.TryGetValue(SelectedQueryInActiveDirectoryInfo, out var method))
{
PSOutput result = await method.Invoke();
ConsoleViewModelOutputInActiveDirectoryInfo.Append(result.HadErrors ? result.StdErr : result.StdOut);
ConsoleOutputInActiveDirectoryInfo.Append(result.HadErrors ? result.StdErr : result.StdOut);
}
// This is an internal error to ensure that if the selected option is not found, the program will not continue.
else
Expand Down Expand Up @@ -373,7 +374,7 @@ private async void ExecuteQueryFromQueryStackPanel(object queryButton)
}

var buttonQuery = (Query)currentButton.Tag;
await ExecuteQueryAsync(ConsoleViewModelOutputInQueryBuilder, buttonQuery.Command);
await ExecuteQueryAsync(ConsoleOutputInQueryBuilder, buttonQuery.Command);
}

private void DeleteQueryFromQueryStackPanel(object queryButton)
Expand Down Expand Up @@ -402,6 +403,7 @@ private void DeleteQueryFromQueryStackPanel(object queryButton)
}
}

// TODO: Continue refactoring starting here...
private void CreateNewQueryFile(object _)
{
// Saves/creates a new save file for the queries
Expand All @@ -410,7 +412,6 @@ private void CreateNewQueryFile(object _)
if (saveFileDialog.ShowDialog() == true)
{
QueryButtonStackPanel.Clear();
// File.WriteAllText(saveFileDialog.FileName, string.Empty);
_queryManager.QueryFileSaveLocation = saveFileDialog.FileName;
}
}
Expand Down Expand Up @@ -523,11 +524,11 @@ private async void OutputExecutionResultsToTextFileAsync(object _)
Query buttonQuery;

buttonQuery = (Query)currentButton!.Tag;
await ExecuteQueryAsync(ConsoleViewModelOutputInQueryBuilder, buttonQuery.Command);
await ExecuteQueryAsync(ConsoleOutputInQueryBuilder, buttonQuery.Command);
}
else
{
await ExecuteQueryAsync(ConsoleViewModelOutputInQueryBuilder);
await ExecuteQueryAsync(ConsoleOutputInQueryBuilder);
}

// Filepath
Expand All @@ -545,7 +546,7 @@ private async void OutputExecutionResultsToTextFileAsync(object _)
{
// Open document
string filePath = saveFileDialog.FileName;
await File.WriteAllTextAsync(filePath, ConsoleViewModelOutputInQueryBuilder.ConsoleOutput);
await File.WriteAllTextAsync(filePath, ConsoleOutputInQueryBuilder.ConsoleOutput);
}
}

Expand All @@ -557,15 +558,15 @@ private async void OutputExecutionResultsToCsvFileAsync(object _)
Query buttonQuery;

buttonQuery = (Query)currentButton!.Tag;
await ExecuteQueryAsync(ConsoleViewModelOutputInQueryBuilder, buttonQuery.Command);
await ExecuteQueryAsync(ConsoleOutputInQueryBuilder, buttonQuery.Command);
}
else
{
await ExecuteQueryAsync(ConsoleViewModelOutputInQueryBuilder);
await ExecuteQueryAsync(ConsoleOutputInQueryBuilder);
}

var csv = new StringBuilder();
string[] output = ConsoleViewModelOutputInQueryBuilder.ConsoleOutput.Split(' ', '\n');
string[] output = ConsoleOutputInQueryBuilder.ConsoleOutput.Split(' ', '\n');

for (int i = 0; i < output.Length - 2; i++)
{
Expand Down Expand Up @@ -593,7 +594,7 @@ private async void OutputExecutionResultsToCsvFileAsync(object _)

private void ExportConsoleOutputToFile(object _)
{
if (ConsoleViewModelOutputInQueryBuilder.ConsoleOutput.Length == 0)
if (ConsoleOutputInQueryBuilder.ConsoleOutput.Length == 0)
{
MessageBox.Show("The console is empty.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
return;
Expand All @@ -606,7 +607,7 @@ private void ExportConsoleOutputToFile(object _)
if (result == true)
{
string filename = saveFileDialog.FileName;
ConsoleViewModelOutputInQueryBuilder.ExportToTextFile(filename);
ConsoleOutputInQueryBuilder.ExportToTextFile(filename);
}
}

Expand Down Expand Up @@ -720,7 +721,7 @@ private void SaveCurrentQuery(object commandParameter)
}
}
}

private void ClearQueryBuilder(object _)
{
if (SelectedCommandInQueryBuilder is null && DynamicallyAvailableADCommandParameterComboBoxes.Count == 0)
Expand Down Expand Up @@ -749,6 +750,14 @@ private void ClearQueryBuilder(object _)
DynamicallyAvailableADCommandParameterValueTextBoxes.Clear();
}
}

private void OnIsQueryEditingEnabledChanged()
{
if (!IsQueryEditingEnabled)
{
_queryBeingEdited = null;
}
}

private Button CreateQueryButtonInStackPanel(Query? query = null)
{
Expand Down

0 comments on commit ce1fe26

Please sign in to comment.