Skip to content

Commit

Permalink
Merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 9, 2024
2 parents a912c67 + 6739bb0 commit a6e4890
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 346 deletions.
10 changes: 10 additions & 0 deletions src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using Wpf.Ui;

using IThemeService = Corathing.Contracts.Services.IThemeService;
using ThemeService = Corathing.Organizer.Services.ThemeService;

namespace Corathing.Organizer;

/// <summary>
Expand Down Expand Up @@ -147,6 +152,11 @@ private static IServiceProvider ConfigureServices(string[] args)
var configuration = BuildConfiguration(args);
serviceCollection.AddSingleton<IConfiguration>(configuration);

// Wpf.Ui Service
// TODO: This should be implmented with IDialogService (Corathing.Contracts.Services)
// RoadMap 3, Content Presenter (Binding using Context)
serviceCollection.AddSingleton<IContentDialogService, ContentDialogService>();

// Register services
serviceCollection.AddSingleton<IApplicationService, ApplicationService>();
serviceCollection.AddSingleton<ISecretService, ModelVersionSecretService>();
Expand Down
126 changes: 126 additions & 0 deletions src/Apps/Corathing.Organizer/Behaviors/DoubleClickTextBlockBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows;

using Microsoft.Xaml.Behaviors;
using System.Windows.Controls;
using ControlzEx.Behaviors;
using Corathing.Dashboards.WPF.Controls;

namespace Corathing.Organizer.Behaviors;

public class DoubleClickTextBoxBehavior : Behavior<TextBox>
{
#region Public Properties

/// <summary>
/// The edit mode property
/// </summary>
public static readonly DependencyProperty EditModeProperty = DependencyProperty.Register(
nameof(EditMode),
typeof(bool),
typeof(DoubleClickTextBoxBehavior),
new PropertyMetadata(false));

/// <summary>
/// Gets or sets a value indicating whether the dashboard is in [edit mode].
/// </summary>
/// <value><c>true</c> if [edit mode]; otherwise, <c>false</c>.</value>
public bool EditMode
{
get => (bool)GetValue(EditModeProperty);
set => SetValue(EditModeProperty, value);
}


public Style TextBoxNoEditStyle
{
get => (Style)GetValue(TextBoxNoEditStyleProperty);
set => SetValue(TextBoxNoEditStyleProperty, value);
}

public static readonly DependencyProperty TextBoxNoEditStyleProperty = DependencyProperty.Register(
nameof(TextBoxNoEditStyle),
typeof(Style),
typeof(DoubleClickTextBoxBehavior),
new PropertyMetadata(null));

public Style TextBoxEditingStyle
{
get => (Style)GetValue(TextBoxEditingStyleProperty);
set => SetValue(TextBoxEditingStyleProperty, value);
}

public static readonly DependencyProperty TextBoxEditingStyleProperty = DependencyProperty.Register(
nameof(TextBoxEditingStyle),
typeof(Style),
typeof(DoubleClickTextBoxBehavior),
new PropertyMetadata(null));

#endregion

protected override void OnAttached()
{
AssociatedObject.Focusable = false;
AssociatedObject.Cursor = Cursors.Arrow;

AssociatedObject.Style = TextBoxNoEditStyle;
AssociatedObject.MouseDoubleClick += AssociatedObjectOnMouseDoubleClick;
AssociatedObject.LostFocus += AssociatedObjectOnLostFocus;
AssociatedObject.KeyDown += AssociatedObject_KeyDown;
}

private void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return && e.Key == Key.Enter)
{
RaiseLostFocus();
}
}

private void RaiseLostFocus()
{
AssociatedObject.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}

protected override void OnDetaching()
{
base.OnDetaching();

AssociatedObject.MouseDoubleClick -= AssociatedObjectOnMouseDoubleClick;
AssociatedObject.LostFocus -= AssociatedObjectOnLostFocus;
AssociatedObject.KeyDown -= AssociatedObject_KeyDown;
}

private void AssociatedObjectOnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (!EditMode)
return;

if (e.ChangedButton != MouseButton.Left)
return;

if (AssociatedObject.Focusable)
return;//fix an issue of selecting all text on double click

e.Handled = true;
AssociatedObject.Style = TextBoxEditingStyle;
AssociatedObject.Cursor = Cursors.IBeam;
AssociatedObject.Focusable = true;
AssociatedObject.Focus();
AssociatedObject.CaretIndex = AssociatedObject.Text.Length;
AssociatedObject.SelectionStart = AssociatedObject.Text.Length;
}

private void AssociatedObjectOnLostFocus(object sender, RoutedEventArgs e)
{
AssociatedObject.Style = TextBoxNoEditStyle;
AssociatedObject.Cursor = Cursors.Arrow;
AssociatedObject.Focusable = false;
}
}
20 changes: 0 additions & 20 deletions src/Apps/Corathing.Organizer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ public partial class MainWindow : MetroWindow
public MainWindow()
{
InitializeComponent();

MouseDown += Window_MouseDown;
MouseDoubleClick += Window_MouseDoubleClick;
}

private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
if (WindowState == WindowState.Normal)
WindowState = WindowState.Maximized;
else
WindowState = WindowState.Normal;
}
}

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
}
}
4 changes: 2 additions & 2 deletions src/Apps/Corathing.Organizer/Models/ProjectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public ObservableCollection<WorkflowContext> Workflows
return;
OnPropertyChanging(nameof(Workflows));
_workflows = value;
var itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(_workflows);
itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
//var itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(_workflows);
//itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
OnPropertyChanged(nameof(Workflows));
}
}
Expand Down
86 changes: 36 additions & 50 deletions src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Corathing.Organizer.Views;
using Microsoft.Extensions.DependencyInjection;

using Wpf.Ui;

using static MaterialDesignThemes.Wpf.Theme.ToolBar;

namespace Corathing.Organizer.ViewModels;
Expand All @@ -34,39 +36,16 @@ namespace Corathing.Organizer.ViewModels;
/// </summary>
/// <seealso cref="Infrastructure.ViewModelBase" />
/// <seealso cref="WpfDashboardControl.Dashboards.IDashboardConfigurationHandler" />
public partial class DashboardViewModel : ObservableObject, IDashboardConfigurationHandler
public partial class DashboardViewModel : ObservableObject
{
#region Private Fields

[ObservableProperty]
private ObservableCollection<ProjectContext>? _projects;

/// <summary>
/// Gets or sets the dashboards.
/// </summary>
/// <value>The dashboards.</value>
private ObservableCollection<WorkflowContext>? _workflows;
public ObservableCollection<WorkflowContext> Workflows
{
get => _workflows;
set
{
if (EqualityComparer<ObservableCollection<WorkflowContext>?>.Default.Equals(_workflows, value))
return;
OnPropertyChanging(nameof(Workflows));
_workflows = value;
var itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(_workflows);
itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
OnPropertyChanged(nameof(Workflows));
}
}

[ObservableProperty]
private ProjectContext _selectedProject;

[ObservableProperty]
private WorkflowContext _selectedWorkflow;

[ObservableProperty]
private ObservableCollection<MenuItemViewModel> _addWidgetMenuItemViewModels;

Expand Down Expand Up @@ -101,22 +80,14 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
}
}

/// <summary>
/// Gets the command add widget.
/// </summary>
/// <value>The command add widget.</value>
public ICommand CommandAddWidget => new RelayCommand<WidgetGenerator>(o =>
{
var widgetGeneratorToAdd = (WidgetGenerator)o;

SelectedWorkflow.Widgets.Add(widgetGeneratorToAdd.CreateWidget());
EditMode = true;
});

[RelayCommand]
public void AddWidget(WidgetGenerator generator)
{
SelectedWorkflow.Widgets.Add(generator.CreateWidget());
if (SelectedProject == null)
return;
if (SelectedProject.SelectedWorkflow == null)
return;
SelectedProject.SelectedWorkflow.Widgets.Add(generator.CreateWidget());
}

[RelayCommand]
Expand All @@ -126,7 +97,7 @@ public void AddWorkflow()
}

[RelayCommand]
public void OpenOrganizerSettings()
public async void OpenOrganizerSettings()
{
var window = new BaseWindow();
window.Content = new OrganizerSettingsView();
Expand All @@ -151,6 +122,33 @@ public void ToggleEditDashboard()
EditMode = !EditMode;
}

[RelayCommand]
public void MouseDoubleClick(object e)
{
Console.WriteLine(e);
//private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
//{
// if (sender is not MainWindow)
// return;

// if (e.ChangedButton == MouseButton.Left)
// {
// if (WindowState == WindowState.Normal)
// WindowState = WindowState.Maximized;
// else
// WindowState = WindowState.Normal;
// }
//}

//private void Window_MouseDown(object sender, MouseButtonEventArgs e)
//{
// if (e.ChangedButton == MouseButton.Left)
// this.DragMove();
//}
}



/// <summary>
/// Gets the command configure widget.
/// </summary>
Expand Down Expand Up @@ -225,18 +223,6 @@ public void DashboardConfigurationComplete(DashboardConfigurationType type, bool
//}
}

/// <summary>
/// Dashboards the name valid.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>DashboardNameValidResponse.</returns>
public DashboardNameValidResponse DashboardNameValid(string name)
{
return Workflows.Any(dashboard => dashboard.Title == name)
? new DashboardNameValidResponse(false, $"That Dashboard Name [{name}] already exists.")
: new DashboardNameValidResponse(true);
}

/// <summary>
/// Starts this instance.
/// </summary>
Expand Down
Loading

0 comments on commit a6e4890

Please sign in to comment.