Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple web windows #155

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Tryouts/Prototypes/Shell/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
// * and limitations under the License.
// */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using Shell.Utilities;

namespace Shell
{
Expand All @@ -30,17 +24,24 @@ public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length != 0)
if (e.Args.Length != 0
&& CommandLineParser.TryParse<WebWindowOptions>(e.Args, out var webWindowOptions)
&& webWindowOptions.Url != null)
{
MainWebWindowOptions webWindowOptions = MainWebWindowOptionsParser.Parse(e.Args);
Application.Current.MainWindow = new MainWebWindow(webWindowOptions);
Application.Current.MainWindow.Show();
}
else
{
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
StartWithWebWindowOptions(webWindowOptions);

return;
}

Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
new MainWindow().Show();
}

private void StartWithWebWindowOptions(WebWindowOptions options)
{
var webWindow = new WebWindow(options);
Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
webWindow.Show();
}
}
}
4 changes: 0 additions & 4 deletions Tryouts/Prototypes/Shell/ImageSource/IImageSourcePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shell.ImageSource
{
Expand Down
46 changes: 0 additions & 46 deletions Tryouts/Prototypes/Shell/MainWebWindow.xaml.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Tryouts/Prototypes/Shell/MainWebWindowOptions.cs

This file was deleted.

47 changes: 0 additions & 47 deletions Tryouts/Prototypes/Shell/MainWebWindowOptionsParser.cs

This file was deleted.

57 changes: 21 additions & 36 deletions Tryouts/Prototypes/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@
// * and limitations under the License.
// */

using Manifest;
using Shell.ImageSource;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
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;
using Manifest;

namespace Shell
{
Expand All @@ -38,47 +25,45 @@ namespace Shell
/// </summary>
public partial class MainWindow : Window
{
internal List<WebContent> WebContentList { get; set; } = new List<WebContent>();
private ManifestModel _config;
private ModuleModel[]? _modules;
private ImageSourceProvider _iconProvider = new ImageSourceProvider(new EnvironmentImageSourcePolicy());
internal List<WebWindow> webWindows { get; set; } = new List<WebWindow>();
BalassaMarton marked this conversation as resolved.
Show resolved Hide resolved
private ManifestModel config;
private ModuleModel[]? modules;

public MainWindow()
{
InitializeComponent();

_config = ManifestParser.OpenManifestFile("exampleManifest.json");
_modules = _config.Modules;
DataContext = _modules;
config = ManifestParser.OpenManifestFile("exampleManifest.json");
modules = config.Modules;
DataContext = modules;
}

private void CreateViews(ModuleModel item)
private void CreateWebWindow(ModuleModel item)
{
var opt = new WebContentOptions()
var options = new WebWindowOptions
{
Title = item.AppName,
Uri = new Uri(item.Url),
IconUri = string.IsNullOrEmpty(item.IconUrl) ? null : new Uri(item.IconUrl)
Url = item.Url,
IconUrl = item.IconUrl
};

var webContent = new WebContent(opt, _iconProvider);
webContent.Owner = this;
webContent.Closed += WebContent_Closed;

WebContentList.Add(webContent);
webContent.Show();
var webWindow = new WebWindow(options);
webWindow.Owner = this;
webWindow.Closed += WebWindowClosed;
webWindows.Add(webWindow);
webWindow.Show();
}

private void WebContent_Closed(object? sender, EventArgs e)
private void WebWindowClosed(object? sender, EventArgs e)
{
WebContentList.Remove((WebContent)sender);
webWindows.Remove((WebWindow)sender!);
}

private void ShowChild_Click(object sender, RoutedEventArgs e)
{
var context = ((Button)sender).DataContext;

CreateViews((ModuleModel)context);
CreateWebWindow((ModuleModel)context);
}
}
}
4 changes: 0 additions & 4 deletions Tryouts/Prototypes/Shell/Manifest/ManifestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// * and limitations under the License.
// */

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json;

namespace Manifest
Expand Down
6 changes: 0 additions & 6 deletions Tryouts/Prototypes/Shell/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
// */

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using System.Windows.Automation;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;

namespace Manifest
{
Expand Down
2 changes: 1 addition & 1 deletion Tryouts/Prototypes/Shell/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Shell": {
"commandName": "Project",
"commandLineArgs": "--title=Jane --width=1800 --height=800 --url=http://www.google.com --icon=/images/branding/googleg/1x/googleg_standard_color_128dp.png"
"commandLineArgs": "--title Jane --width 1800 --height 800 --url http://www.google.com --icon /images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
}
}
12 changes: 6 additions & 6 deletions Tryouts/Prototypes/Shell/Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
</PropertyGroup>

<ItemGroup>
<None Remove="MainWebWindow.xaml" />
<None Remove="MainWindow.xaml" />
<None Remove="WebContent.xaml" />
<None Remove="WebWindow.xaml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,19 +19,20 @@
</ItemGroup>

<ItemGroup>
<Page Include="MainWebWindow.xaml">
<Page Include="WebWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml" />
<Page Include="WebContent.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<None Update="Manifest\exampleManifest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Utilities\" />
</ItemGroup>

</Project>
Loading