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

Commit

Permalink
Allow Import & Export of profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
CShark committed May 26, 2022
1 parent 1b6bdc4 commit 32f7008
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 47 deletions.
16 changes: 0 additions & 16 deletions BetterMultiview/ObsMultiview/Dialogs/CopySetup.xaml

This file was deleted.

24 changes: 0 additions & 24 deletions BetterMultiview/ObsMultiview/Dialogs/CopySetup.xaml.cs

This file was deleted.

19 changes: 16 additions & 3 deletions BetterMultiview/ObsMultiview/Dialogs/ProfileConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Padding" Value="7,3"></Setter>
</Style>
</Grid.Resources>

<Grid VerticalAlignment="Top">
<Grid.Resources>
<Style TargetType="TextBlock">
Expand Down Expand Up @@ -47,9 +55,14 @@
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Columns}" />
</Grid>

<UniformGrid Columns="2" Grid.Row="1" HorizontalAlignment="Right" Margin="5">
<Button Margin="2" IsDefault="True" Padding="7,3" Click="Ok_OnClick" Content="{lex:Loc Ok}" />
<Button Margin="2" Padding="7,3" IsCancel="True" Click="Cancel_OnClick" Content="{lex:Loc Cancel}" />
<UniformGrid Grid.Row="1" Columns="2">
<Button Content="{lex:Loc Import}" Click="Import_OnClick"></Button>
<Button Content="{lex:Loc Export}" Click="Export_OnClick"></Button>
</UniformGrid>

<UniformGrid Columns="2" Grid.Row="2" HorizontalAlignment="Right" Margin="5">
<Button IsDefault="True" Click="Ok_OnClick" Content="{lex:Loc Ok}" />
<Button IsCancel="True" Click="Cancel_OnClick" Content="{lex:Loc Cancel}" />
</UniformGrid>
</Grid>
</Window>
38 changes: 36 additions & 2 deletions BetterMultiview/ObsMultiview/Dialogs/ProfileConfig.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Windows;
using System;
using System.IO;
using System.Windows;
using Microsoft.Win32;
using Newtonsoft.Json;
using ObsMultiview.Data;

namespace ObsMultiview.Dialogs {
Expand All @@ -14,7 +18,10 @@ public partial class ProfileConfig : Window {
set { SetValue(ConfigProperty, value); }
}

public ProfileConfig() {
private Action<UserProfile.DSceneViewConfig> _replaceConfig;

public ProfileConfig(Action<UserProfile.DSceneViewConfig> replaceConfigCallback) {
_replaceConfig = replaceConfigCallback;
InitializeComponent();
}

Expand All @@ -27,5 +34,32 @@ public partial class ProfileConfig : Window {
DialogResult = false;
Close();
}

private void Export_OnClick(object sender, RoutedEventArgs e) {
var sfd = new SaveFileDialog {
Title="Export multiview config",
Filter="*.json|*.json"
};

if (sfd.ShowDialog() == true) {
var json = JsonConvert.SerializeObject(Config);
File.WriteAllText(sfd.FileName, json);
}
}

private void Import_OnClick(object sender, RoutedEventArgs e) {
var ofd = new OpenFileDialog {
Title="Import multiview config",
Filter="*.json|*.json"
};

if (ofd.ShowDialog() == true) {
var json = File.ReadAllText(ofd.FileName);
var obj = JsonConvert.DeserializeObject<UserProfile.DSceneViewConfig>(json);
_replaceConfig?.Invoke(obj);
DialogResult = true;
Close();
}
}
}
}
7 changes: 7 additions & 0 deletions BetterMultiview/ObsMultiview/Services/ProfileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,12 @@ public class ProfileWatcher {
ActiveProfileChanged?.Invoke(obj);
});
}

public void ReplaceProfile(UserProfile.DSceneViewConfig config) {
var newProfile = new UserProfile.DObsProfile(ActiveProfile.Id);
newProfile.SceneView = config;

OnActiveProfileChanged(newProfile);
}
}
}
8 changes: 8 additions & 0 deletions BetterMultiview/ObsMultiview/Services/SceneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,13 @@ public class SceneService {
}
}
}

public void ClearPreview() {
OnPreviewChanged(null);
}

public void ClearLive() {
OnLiveChanged(null);
}
}
}
18 changes: 17 additions & 1 deletion BetterMultiview/ObsMultiview/StreamView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ public partial class StreamView : Window {
foreach (var inv in invalid) {
profile.SceneView.Slots.Remove(inv);
}
if (_scenes.ActivePreviewSlot != null) {
if (!_sceneSlots.ContainsKey(_scenes.ActivePreviewSlot)) {
_scenes.ClearPreview();
}
}
if (_scenes.ActiveLiveSlot != null) {
if (!_sceneSlots.ContainsKey(_scenes.ActiveLiveSlot)) {
_scenes.ClearLive();
}
}
}).Wait();

PrepareObsPreview();
Expand Down Expand Up @@ -263,7 +275,7 @@ public partial class StreamView : Window {
var settings = JObject.FromObject(_watcher.ActiveProfile.SceneView);
var id = _watcher.ActiveProfile.Id;

var config = new ProfileConfig();
var config = new ProfileConfig(ReplaceRunningConfig);
config.Config = _watcher.ActiveProfile.SceneView;
config.Owner = this;
if (config.ShowDialog() == true) {
Expand All @@ -274,5 +286,9 @@ public partial class StreamView : Window {
}
}
}

private void ReplaceRunningConfig(UserProfile.DSceneViewConfig config) {
_watcher.ReplaceProfile(config);
}
}
}
20 changes: 19 additions & 1 deletion BetterMultiview/ObsMultiview/Strings/Dialogs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BetterMultiview/ObsMultiview/Strings/Dialogs.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,10 @@
<data name="RenameProfile.FailedMessage" xml:space="preserve">
<value>Das Profil kann nicht umbenannt werden, weil bereits ein Profil mit diesem Namen existiert.</value>
</data>
<data name="Import" xml:space="preserve">
<value>Importieren</value>
</data>
<data name="Export" xml:space="preserve">
<value>Exportieren</value>
</data>
</root>
6 changes: 6 additions & 0 deletions BetterMultiview/ObsMultiview/Strings/Dialogs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@
<data name="RenameProfile.FailedMessage" xml:space="preserve">
<value>Profile could not be renamed, because a profile with the same name already exists.</value>
</data>
<data name="Import" xml:space="preserve">
<value>Import</value>
</data>
<data name="Export" xml:space="preserve">
<value>Export</value>
</data>
</root>

0 comments on commit 32f7008

Please sign in to comment.