mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +00:00
Fixed default profile creation
Don't allow dropping a folder into itself
This commit is contained in:
parent
602a0e6fee
commit
3084869d75
@ -69,7 +69,8 @@ namespace Artemis.Core.Services.Storage
|
|||||||
if (module.ActiveProfile != null)
|
if (module.ActiveProfile != null)
|
||||||
return module.ActiveProfile;
|
return module.ActiveProfile;
|
||||||
|
|
||||||
var profileEntity = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid).FirstOrDefault(p => p.IsActive);
|
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||||
|
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
||||||
if (profileEntity == null)
|
if (profileEntity == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,8 @@
|
|||||||
<TextBox materialDesign:HintAssist.Hint="Element name"
|
<TextBox materialDesign:HintAssist.Hint="Element name"
|
||||||
Margin="0 8 0 16"
|
Margin="0 8 0 16"
|
||||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||||
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"/>
|
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"
|
||||||
|
Loaded="FrameworkElement_OnLoaded"/>
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
|
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
|
||||||
|
|||||||
@ -1,22 +1,11 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
|
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for ProfileElementRenameView.xaml
|
/// Interaction logic for ProfileElementRenameView.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class ProfileElementRenameView : UserControl
|
public partial class ProfileElementRenameView : UserControl
|
||||||
{
|
{
|
||||||
@ -24,5 +13,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var textBox = (TextBox) sender;
|
||||||
|
Keyboard.Focus(textBox);
|
||||||
|
textBox.SelectAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,12 +118,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
|
|
||||||
private void ModuleOnActiveProfileChanged(object sender, EventArgs e)
|
private void ModuleOnActiveProfileChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (SelectedProfile == Module.ActiveProfile)
|
||||||
|
return;
|
||||||
|
|
||||||
SelectedProfile = Profiles.FirstOrDefault(p => p == Module.ActiveProfile);
|
SelectedProfile = Profiles.FirstOrDefault(p => p == Module.ActiveProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActivate()
|
protected override void OnActivate()
|
||||||
{
|
{
|
||||||
Task.Run(() => LoadProfiles());
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
LoadProfiles();
|
||||||
|
foreach (var panelViewModel in Items)
|
||||||
|
{
|
||||||
|
panelViewModel.ProfileEditorViewModel = this;
|
||||||
|
panelViewModel.ActiveProfileChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
base.OnActivate();
|
base.OnActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,12 +142,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
{
|
{
|
||||||
// Get all profiles from the database
|
// Get all profiles from the database
|
||||||
var profiles = _profileService.GetProfiles(Module);
|
var profiles = _profileService.GetProfiles(Module);
|
||||||
var activeProfile = _profileService.GetActiveProfile(Module);
|
// Get the latest active profile, this falls back to just any profile so if null, create a default profile
|
||||||
if (activeProfile == null)
|
var activeProfile = _profileService.GetActiveProfile(Module) ?? _profileService.CreateProfile(Module, "Default");
|
||||||
{
|
|
||||||
activeProfile = CreateProfile("Default");
|
|
||||||
profiles.Add(activeProfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetActiveProfile can return a duplicate because inactive profiles aren't kept in memory, make sure it's unique in the profiles list
|
// GetActiveProfile can return a duplicate because inactive profiles aren't kept in memory, make sure it's unique in the profiles list
|
||||||
profiles = profiles.Where(p => p.EntityId != activeProfile.EntityId).ToList();
|
profiles = profiles.Where(p => p.EntityId != activeProfile.EntityId).ToList();
|
||||||
@ -160,9 +167,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
_profileService.UpdateProfile(SelectedProfile, true);
|
_profileService.UpdateProfile(SelectedProfile, true);
|
||||||
|
|
||||||
foreach (var panelViewModel in Items)
|
foreach (var panelViewModel in Items)
|
||||||
{
|
|
||||||
panelViewModel.ActiveProfileUpdated();
|
panelViewModel.ActiveProfileUpdated();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,9 +84,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Farewell, cruel world
|
// Farewell, cruel world
|
||||||
|
var parent = Parent;
|
||||||
ProfileElement.Parent.RemoveChild(ProfileElement);
|
ProfileElement.Parent.RemoveChild(ProfileElement);
|
||||||
Parent.RemoveExistingElement(this);
|
parent.RemoveExistingElement(this);
|
||||||
Parent.UpdateProfileElements();
|
parent.UpdateProfileElements();
|
||||||
|
|
||||||
ProfileEditorViewModel.OnProfileUpdated();
|
ProfileEditorViewModel.OnProfileUpdated();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800"
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
d:DataContext="{d:DesignInstance {x:Type local:FolderViewModel}}">
|
d:DataContext="{d:DesignInstance {x:Type local:FolderViewModel}}">
|
||||||
<StackPanel>
|
<!-- Margin is a bit hacky but the tree view puts a margin on 10 on us which when clicked outside of doesn't trigger the context menu -->
|
||||||
|
<StackPanel Margin="-10" Background="Transparent">
|
||||||
<StackPanel.ContextMenu>
|
<StackPanel.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
||||||
@ -35,7 +36,7 @@
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</StackPanel.ContextMenu>
|
</StackPanel.ContextMenu>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal" Margin="10">
|
||||||
<materialDesign:PackIcon Kind="Folder" />
|
<materialDesign:PackIcon Kind="Folder" />
|
||||||
<TextBlock Text="{Binding Folder.Name}" Margin="10 0 0 0" />
|
<TextBlock Text="{Binding Folder.Name}" Margin="10 0 0 0" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800"
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
d:DataContext="{d:DesignInstance {x:Type local:LayerViewModel}}">
|
d:DataContext="{d:DesignInstance {x:Type local:LayerViewModel}}">
|
||||||
<StackPanel>
|
<StackPanel Margin="-10" Background="Transparent">
|
||||||
<StackPanel.ContextMenu>
|
<StackPanel.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
||||||
@ -24,7 +24,7 @@
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</StackPanel.ContextMenu>
|
</StackPanel.ContextMenu>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal" Margin="10">
|
||||||
<materialDesign:PackIcon Kind="Layers" />
|
<materialDesign:PackIcon Kind="Layers" />
|
||||||
<TextBlock Text="{Binding Layer.Name}" Margin="10 0 0 0" />
|
<TextBlock Text="{Binding Layer.Name}" Margin="10 0 0 0" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
<ContentControl s:View.Model="{Binding}" />
|
<ContentControl s:View.Model="{Binding}" />
|
||||||
</HierarchicalDataTemplate>
|
</HierarchicalDataTemplate>
|
||||||
<HierarchicalDataTemplate DataType="{x:Type profileEditor:LayerViewModel}" ItemsSource="{Binding Children}">
|
<HierarchicalDataTemplate DataType="{x:Type profileEditor:LayerViewModel}" ItemsSource="{Binding Children}">
|
||||||
<ContentControl s:View.Model="{Binding}" AllowDrop="False" />
|
<ContentControl s:View.Model="{Binding}" />
|
||||||
</HierarchicalDataTemplate>
|
</HierarchicalDataTemplate>
|
||||||
</TreeView.Resources>
|
</TreeView.Resources>
|
||||||
</TreeView>
|
</TreeView>
|
||||||
|
|||||||
@ -39,7 +39,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
|||||||
{
|
{
|
||||||
var source = (ProfileElementViewModel) dropInfo.Data;
|
var source = (ProfileElementViewModel) dropInfo.Data;
|
||||||
var target = (ProfileElementViewModel) dropInfo.TargetItem;
|
var target = (ProfileElementViewModel) dropInfo.TargetItem;
|
||||||
|
|
||||||
var dragDropType = GetDragDropType(dropInfo);
|
var dragDropType = GetDragDropType(dropInfo);
|
||||||
switch (dragDropType)
|
switch (dragDropType)
|
||||||
{
|
{
|
||||||
@ -94,6 +94,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
|||||||
if (source == target)
|
if (source == target)
|
||||||
return DragDropType.None;
|
return DragDropType.None;
|
||||||
|
|
||||||
|
var parent = target;
|
||||||
|
while (parent != null)
|
||||||
|
{
|
||||||
|
if (parent == source)
|
||||||
|
return DragDropType.None;
|
||||||
|
parent = parent.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
if (target is FolderViewModel)
|
if (target is FolderViewModel)
|
||||||
{
|
{
|
||||||
if (dropInfo.InsertPosition >= RelativeInsertPosition.TargetItemCenter)
|
if (dropInfo.InsertPosition >= RelativeInsertPosition.TargetItemCenter)
|
||||||
@ -107,7 +115,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
|||||||
{
|
{
|
||||||
if (dropInfo.InsertPosition == RelativeInsertPosition.BeforeTargetItem)
|
if (dropInfo.InsertPosition == RelativeInsertPosition.BeforeTargetItem)
|
||||||
return DragDropType.LayerInsertBefore;
|
return DragDropType.LayerInsertBefore;
|
||||||
return DragDropType.LayerInsertAfter;
|
if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem)
|
||||||
|
return DragDropType.LayerInsertAfter;
|
||||||
|
return DragDropType.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DragDropType.None;
|
return DragDropType.None;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user