mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile tree - Prevent dragging while renaming
Profile tree - Prevent hotkeys while renaming
This commit is contained in:
parent
9602934342
commit
84b394fc51
@ -132,7 +132,7 @@ public class SimpleContextDragBehavior : Behavior<Control>
|
||||
private async void AssociatedObject_PointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties;
|
||||
if (!properties.IsLeftButtonPressed)
|
||||
if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox)
|
||||
return;
|
||||
|
||||
if (_triggerEvent is null)
|
||||
|
||||
@ -34,6 +34,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
private ObservableAsPropertyHelper<bool>? _focusNone;
|
||||
private ObservableAsPropertyHelper<bool>? _focusFolder;
|
||||
private ObservableAsPropertyHelper<bool>? _focusSelection;
|
||||
private ObservableAsPropertyHelper<bool>? _keyBindingsEnabled;
|
||||
|
||||
public MenuBarViewModel(ILogger logger, IProfileEditorService profileEditorService, IProfileService profileService, ISettingsService settingsService, IWindowService windowService)
|
||||
{
|
||||
@ -57,6 +58,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
_focusNone = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.None).ToProperty(this, vm => vm.FocusNone).DisposeWith(d);
|
||||
_focusFolder = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Folder).ToProperty(this, vm => vm.FocusFolder).DisposeWith(d);
|
||||
_focusSelection = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Selection).ToProperty(this, vm => vm.FocusSelection).DisposeWith(d);
|
||||
_keyBindingsEnabled = profileEditorService.SuspendedKeybindings.Select(s => !s).ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
});
|
||||
|
||||
AddFolder = ReactiveCommand.Create(ExecuteAddFolder);
|
||||
@ -71,8 +73,8 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
ToggleSuspendedEditing = ReactiveCommand.Create(ExecuteToggleSuspendedEditing);
|
||||
OpenUri = ReactiveCommand.Create<string>(s => Process.Start(new ProcessStartInfo(s) {UseShellExecute = true, Verb = "open"}));
|
||||
ToggleBooleanSetting = ReactiveCommand.Create<PluginSetting<bool>>(ExecuteToggleBooleanSetting);
|
||||
CycleFocusMode = ReactiveCommand.Create(ExecuteCycleFocusMode);
|
||||
ChangeFocusMode = ReactiveCommand.Create<ProfileEditorFocusMode>(ExecuteChangeFocusMode);
|
||||
CycleFocusMode = ReactiveCommand.Create(ExecuteCycleFocusMode, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> AddFolder { get; }
|
||||
@ -87,9 +89,9 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
public ReactiveCommand<PluginSetting<bool>, Unit> ToggleBooleanSetting { get; }
|
||||
public ReactiveCommand<string, Unit> OpenUri { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspendedEditing { get; }
|
||||
public ReactiveCommand<Unit, Unit> CycleFocusMode { get; }
|
||||
public ReactiveCommand<ProfileEditorFocusMode, Unit> ChangeFocusMode { get; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> CycleFocusMode { get; }
|
||||
|
||||
public ProfileConfiguration? ProfileConfiguration => _profileConfiguration?.Value;
|
||||
public RenderProfileElement? ProfileElement => _profileElement?.Value;
|
||||
public bool IsSuspended => _isSuspended?.Value ?? false;
|
||||
@ -97,6 +99,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
public bool FocusNone => _focusNone?.Value ?? false;
|
||||
public bool FocusFolder => _focusFolder?.Value ?? false;
|
||||
public bool FocusSelection => _focusSelection?.Value ?? false;
|
||||
public bool KeyBindingsEnabled => _keyBindingsEnabled?.Value ?? false;
|
||||
|
||||
public PluginSetting<bool> AutoSuspend => _settingsService.GetSetting("ProfileEditor.AutoSuspend", true);
|
||||
public PluginSetting<bool> ShowDataModelValues => _settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
|
||||
|
||||
@ -17,14 +17,13 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
private readonly ISettingsService _settingsService;
|
||||
private ObservableAsPropertyHelper<TimeSpan>? _currentTime;
|
||||
private ObservableAsPropertyHelper<string?>? _formattedCurrentTime;
|
||||
private DateTime _lastUpdate;
|
||||
private ObservableAsPropertyHelper<bool>? _keyBindingsEnabled;
|
||||
private ObservableAsPropertyHelper<bool>? _playing;
|
||||
private RenderProfileElement? _profileElement;
|
||||
private bool _repeating;
|
||||
private bool _repeatSegment;
|
||||
private bool _repeatTimeline;
|
||||
private ReactiveCommand<Unit, Unit>? _togglePlay;
|
||||
private ReactiveCommand<Unit, Unit>? _playFromStart;
|
||||
private DateTime _lastUpdate;
|
||||
|
||||
public PlaybackViewModel(IProfileEditorService profileEditorService, ISettingsService settingsService)
|
||||
{
|
||||
@ -38,15 +37,16 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
_currentTime = _profileEditorService.Time.ToProperty(this, vm => vm.CurrentTime).DisposeWith(d);
|
||||
_formattedCurrentTime = _profileEditorService.Time.Select(t => $"{Math.Floor(t.TotalSeconds):00}.{t.Milliseconds:000}").ToProperty(this, vm => vm.FormattedCurrentTime).DisposeWith(d);
|
||||
_playing = _profileEditorService.Playing.ToProperty(this, vm => vm.Playing).DisposeWith(d);
|
||||
_keyBindingsEnabled = _profileEditorService.SuspendedKeybindings.Select(s => !s).ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
|
||||
_lastUpdate = DateTime.MinValue;
|
||||
DispatcherTimer updateTimer = new(TimeSpan.FromMilliseconds(60.0 / 1000), DispatcherPriority.Render, Update);
|
||||
updateTimer.Start();
|
||||
Disposable.Create(() => updateTimer.Stop()).DisposeWith(d);
|
||||
|
||||
PlayFromStart = ReactiveCommand.Create(ExecutePlayFromStart, _profileEditorService.SuspendedKeybindings.Select(s => !s)).DisposeWith(d);
|
||||
TogglePlay = ReactiveCommand.Create(ExecuteTogglePlay, _profileEditorService.SuspendedKeybindings.Select(s => !s)).DisposeWith(d);
|
||||
});
|
||||
|
||||
PlayFromStart = ReactiveCommand.Create(ExecutePlayFromStart, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
TogglePlay = ReactiveCommand.Create(ExecuteTogglePlay, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
GoToStart = ReactiveCommand.Create(ExecuteGoToStart);
|
||||
GoToEnd = ReactiveCommand.Create(ExecuteGoToEnd);
|
||||
GoToPreviousFrame = ReactiveCommand.Create(ExecuteGoToPreviousFrame);
|
||||
@ -57,7 +57,8 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
public TimeSpan CurrentTime => _currentTime?.Value ?? TimeSpan.Zero;
|
||||
public string? FormattedCurrentTime => _formattedCurrentTime?.Value;
|
||||
public bool Playing => _playing?.Value ?? false;
|
||||
|
||||
public bool KeyBindingsEnabled => _keyBindingsEnabled?.Value ?? false;
|
||||
|
||||
public bool Repeating
|
||||
{
|
||||
get => _repeating;
|
||||
@ -76,18 +77,8 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
set => RaiseAndSetIfChanged(ref _repeatSegment, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit>? PlayFromStart
|
||||
{
|
||||
get => _playFromStart;
|
||||
set => RaiseAndSetIfChanged(ref _playFromStart, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit>? TogglePlay
|
||||
{
|
||||
get => _togglePlay;
|
||||
set => RaiseAndSetIfChanged(ref _togglePlay, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> PlayFromStart { get; }
|
||||
public ReactiveCommand<Unit, Unit> TogglePlay { get; }
|
||||
public ReactiveCommand<Unit,Unit> GoToStart { get; }
|
||||
public ReactiveCommand<Unit,Unit> GoToEnd { get; }
|
||||
public ReactiveCommand<Unit,Unit> GoToPreviousFrame { get; }
|
||||
|
||||
@ -12,12 +12,12 @@
|
||||
x:DataType="profileTree:ProfileTreeViewModel">
|
||||
<!-- These cause binding errors, not my fault - https://github.com/AvaloniaUI/Avalonia/issues/5762 -->
|
||||
<UserControl.KeyBindings>
|
||||
<KeyBinding Gesture="Escape" Command="{Binding ClearSelection}" />
|
||||
<KeyBinding Gesture="F2" Command="{Binding RenameSelected}" />
|
||||
<KeyBinding Gesture="Delete" Command="{Binding DeleteSelected}" />
|
||||
<KeyBinding Gesture="Ctrl+D" Command="{Binding DuplicateSelected}" />
|
||||
<KeyBinding Gesture="Ctrl+C" Command="{Binding CopySelected}" />
|
||||
<KeyBinding Gesture="Ctrl+V" Command="{Binding PasteSelected}" />
|
||||
<KeyBinding Gesture="Escape" Command="{CompiledBinding ClearSelection}" />
|
||||
<KeyBinding Gesture="F2" Command="{CompiledBinding RenameSelected}" />
|
||||
<KeyBinding Gesture="Delete" Command="{CompiledBinding DeleteSelected}" />
|
||||
<KeyBinding Gesture="Ctrl+D" Command="{CompiledBinding DuplicateSelected}" />
|
||||
<KeyBinding Gesture="Ctrl+C" Command="{CompiledBinding CopySelected}" />
|
||||
<KeyBinding Gesture="Ctrl+V" Command="{CompiledBinding PasteSelected}" />
|
||||
</UserControl.KeyBindings>
|
||||
<UserControl.Resources>
|
||||
<converters:ColorOpacityConverter x:Key="ColorOpacityConverter" />
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -16,16 +17,15 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree;
|
||||
|
||||
public class ProfileTreeViewModel : TreeItemViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private TreeItemViewModel? _selectedChild;
|
||||
private ObservableAsPropertyHelper<bool>? _focusNone;
|
||||
private ObservableAsPropertyHelper<bool>? _focusFolder;
|
||||
private ObservableAsPropertyHelper<bool>? _focusSelection;
|
||||
private ObservableAsPropertyHelper<bool>? _keyBindingsEnabled;
|
||||
|
||||
public ProfileTreeViewModel(IWindowService windowService, IProfileEditorService profileEditorService, IProfileEditorVmFactory profileEditorVmFactory)
|
||||
: base(null, null, windowService, profileEditorService, profileEditorVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
profileEditorService.ProfileConfiguration.WhereNotNull().Subscribe(configuration =>
|
||||
@ -46,8 +46,16 @@ public class ProfileTreeViewModel : TreeItemViewModel
|
||||
_focusNone = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.None).ToProperty(this, vm => vm.FocusNone).DisposeWith(d);
|
||||
_focusFolder = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Folder).ToProperty(this, vm => vm.FocusFolder).DisposeWith(d);
|
||||
_focusSelection = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Selection).ToProperty(this, vm => vm.FocusSelection).DisposeWith(d);
|
||||
_keyBindingsEnabled = profileEditorService.SuspendedKeybindings.Select(s => !s).ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
});
|
||||
|
||||
ClearSelection = ReactiveCommand.Create(() => profileEditorService.ChangeCurrentProfileElement(null), this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
RenameSelected = ReactiveCommand.Create(() => { SelectedChild?.Rename.Execute().Subscribe(); }, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
DeleteSelected = ReactiveCommand.Create(() => { SelectedChild?.Delete.Execute().Subscribe(); }, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
DuplicateSelected = ReactiveCommand.Create(() => { SelectedChild?.Duplicate.Execute().Subscribe(); }, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
CopySelected = ReactiveCommand.Create(() => { SelectedChild?.Copy.Execute().Subscribe(); }, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
PasteSelected = ReactiveCommand.Create(() => { SelectedChild?.Paste.Execute().Subscribe(); }, this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedChild).Subscribe(model =>
|
||||
{
|
||||
if (model?.ProfileElement is RenderProfileElement renderProfileElement)
|
||||
@ -58,45 +66,23 @@ public class ProfileTreeViewModel : TreeItemViewModel
|
||||
public bool FocusNone => _focusNone?.Value ?? false;
|
||||
public bool FocusFolder => _focusFolder?.Value ?? false;
|
||||
public bool FocusSelection => _focusSelection?.Value ?? false;
|
||||
|
||||
public bool KeyBindingsEnabled => _keyBindingsEnabled?.Value ?? false;
|
||||
|
||||
public TreeItemViewModel? SelectedChild
|
||||
{
|
||||
get => _selectedChild;
|
||||
set => RaiseAndSetIfChanged(ref _selectedChild, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> ClearSelection { get; }
|
||||
public ReactiveCommand<Unit, Unit> RenameSelected { get; }
|
||||
public ReactiveCommand<Unit, Unit> DeleteSelected { get; }
|
||||
public ReactiveCommand<Unit, Unit> DuplicateSelected { get; }
|
||||
public ReactiveCommand<Unit, Unit> CopySelected { get; }
|
||||
public ReactiveCommand<Unit, Unit> PasteSelected { get; }
|
||||
|
||||
public override bool SupportsChildren => true;
|
||||
|
||||
public void ClearSelection()
|
||||
{
|
||||
_profileEditorService.ChangeCurrentProfileElement(null);
|
||||
}
|
||||
|
||||
public void RenameSelected()
|
||||
{
|
||||
SelectedChild?.Rename.Execute().Subscribe();
|
||||
}
|
||||
|
||||
public void DeleteSelected()
|
||||
{
|
||||
SelectedChild?.Delete.Execute().Subscribe();
|
||||
}
|
||||
|
||||
public void DuplicateSelected()
|
||||
{
|
||||
SelectedChild?.Duplicate.Execute().Subscribe();
|
||||
}
|
||||
|
||||
public void CopySelected()
|
||||
{
|
||||
SelectedChild?.Copy.Execute().Subscribe();
|
||||
}
|
||||
|
||||
public void PasteSelected()
|
||||
{
|
||||
SelectedChild?.Paste.Execute().Subscribe();
|
||||
}
|
||||
|
||||
public void UpdateCanPaste()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@ -55,7 +55,8 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
|
||||
Duplicate = ReactiveCommand.CreateFromTask(ExecuteDuplicate);
|
||||
Copy = ReactiveCommand.CreateFromTask(ExecuteCopy);
|
||||
Paste = ReactiveCommand.CreateFromTask(ExecutePaste, this.WhenAnyValue(vm => vm.CanPaste));
|
||||
|
||||
AbsorbCommand = ReactiveCommand.Create(() => true);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_isFocused = ProfileEditorService.FocusMode
|
||||
@ -72,6 +73,8 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
|
||||
this.WhenAnyValue(vm => vm.IsFlyoutOpen).Subscribe(UpdateCanPaste);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit,bool> AbsorbCommand { get; }
|
||||
|
||||
public bool IsFocused => _isFocused?.Value ?? false;
|
||||
|
||||
public ProfileElement? ProfileElement
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user