1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Fixed default profile creation

Don't allow dropping a folder into itself
This commit is contained in:
Robert 2019-11-25 19:27:55 +01:00
parent 602a0e6fee
commit 3084869d75
9 changed files with 49 additions and 34 deletions

View File

@ -69,7 +69,8 @@ namespace Artemis.Core.Services.Storage
if (module.ActiveProfile != null)
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)
return null;

View File

@ -15,7 +15,8 @@
<TextBox materialDesign:HintAssist.Hint="Element name"
Margin="0 8 0 16"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"/>
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"
Loaded="FrameworkElement_OnLoaded"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">

View File

@ -1,22 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
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
{
/// <summary>
/// Interaction logic for ProfileElementRenameView.xaml
/// Interaction logic for ProfileElementRenameView.xaml
/// </summary>
public partial class ProfileElementRenameView : UserControl
{
@ -24,5 +13,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
{
InitializeComponent();
}
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
var textBox = (TextBox) sender;
Keyboard.Focus(textBox);
textBox.SelectAll();
}
}
}
}

View File

@ -118,12 +118,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
private void ModuleOnActiveProfileChanged(object sender, EventArgs e)
{
if (SelectedProfile == Module.ActiveProfile)
return;
SelectedProfile = Profiles.FirstOrDefault(p => p == Module.ActiveProfile);
}
protected override void OnActivate()
{
Task.Run(() => LoadProfiles());
Task.Run(() =>
{
LoadProfiles();
foreach (var panelViewModel in Items)
{
panelViewModel.ProfileEditorViewModel = this;
panelViewModel.ActiveProfileChanged();
}
});
base.OnActivate();
}
@ -131,12 +142,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
{
// Get all profiles from the database
var profiles = _profileService.GetProfiles(Module);
var activeProfile = _profileService.GetActiveProfile(Module);
if (activeProfile == null)
{
activeProfile = CreateProfile("Default");
profiles.Add(activeProfile);
}
// Get the latest active profile, this falls back to just any profile so if null, create a default profile
var activeProfile = _profileService.GetActiveProfile(Module) ?? _profileService.CreateProfile(Module, "Default");
// 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();
@ -160,9 +167,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
_profileService.UpdateProfile(SelectedProfile, true);
foreach (var panelViewModel in Items)
{
panelViewModel.ActiveProfileUpdated();
}
}
}
}

View File

@ -84,9 +84,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract
return;
// Farewell, cruel world
var parent = Parent;
ProfileElement.Parent.RemoveChild(ProfileElement);
Parent.RemoveExistingElement(this);
Parent.UpdateProfileElements();
parent.RemoveExistingElement(this);
parent.UpdateProfileElements();
ProfileEditorViewModel.OnProfileUpdated();
}

View File

@ -9,7 +9,8 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
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>
<ContextMenu>
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
@ -35,7 +36,7 @@
</MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Margin="10">
<materialDesign:PackIcon Kind="Folder" />
<TextBlock Text="{Binding Folder.Name}" Margin="10 0 0 0" />
</StackPanel>

View File

@ -9,7 +9,7 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type local:LayerViewModel}}">
<StackPanel>
<StackPanel Margin="-10" Background="Transparent">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
@ -24,7 +24,7 @@
</MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Margin="10">
<materialDesign:PackIcon Kind="Layers" />
<TextBlock Text="{Binding Layer.Name}" Margin="10 0 0 0" />
</StackPanel>

View File

@ -28,7 +28,7 @@
<ContentControl s:View.Model="{Binding}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type profileEditor:LayerViewModel}" ItemsSource="{Binding Children}">
<ContentControl s:View.Model="{Binding}" AllowDrop="False" />
<ContentControl s:View.Model="{Binding}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>

View File

@ -39,7 +39,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{
var source = (ProfileElementViewModel) dropInfo.Data;
var target = (ProfileElementViewModel) dropInfo.TargetItem;
var dragDropType = GetDragDropType(dropInfo);
switch (dragDropType)
{
@ -94,6 +94,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
if (source == target)
return DragDropType.None;
var parent = target;
while (parent != null)
{
if (parent == source)
return DragDropType.None;
parent = parent.Parent;
}
if (target is FolderViewModel)
{
if (dropInfo.InsertPosition >= RelativeInsertPosition.TargetItemCenter)
@ -107,7 +115,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{
if (dropInfo.InsertPosition == RelativeInsertPosition.BeforeTargetItem)
return DragDropType.LayerInsertBefore;
return DragDropType.LayerInsertAfter;
if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem)
return DragDropType.LayerInsertAfter;
return DragDropType.None;
}
return DragDropType.None;