Skip to content

Commit a421354

Browse files
levinli303claude
andcommitted
Bubble OpenURL, GetInfo, ShowSubsystem events up to MainWindow
Remove fallback window creation from InfoControlStrip. All windows are now created by MainWindow with proper event wiring for time links. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 46db912 commit a421354

17 files changed

Lines changed: 308 additions & 55 deletions

CelestiaWinUI/BrowserItemUserControl.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ namespace CelestiaWinUI
2020
Microsoft.UI.Xaml.Interop.IBindableObservableVector RootItem{ get; };
2121

2222
event Windows.Foundation.EventHandler<InfoGetInfoArgs> GetInfo;
23+
event Windows.Foundation.EventHandler<InfoShowSubsystemArgs> ShowSubsystem;
24+
event Windows.Foundation.EventHandler<String> OpenURL;
2325
}
2426
}

CelestiaWinUI/BrowserItemUserControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
</DataTemplate>
1919
</TreeView.ItemTemplate>
2020
</TreeView>
21-
<local:InfoControlStrip x:Name="ControlStrip" ShowsGetInfo="True" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True"/>
21+
<local:InfoControlStrip x:Name="ControlStrip" ShowsGetInfo="True" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" GetInfo="ControlStrip_GetInfo" ShowSubsystem="ControlStrip_ShowSubsystem"/>
2222
</RelativePanel>
2323
</UserControl>

CelestiaWinUI/BrowserItemUserControl.xaml.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,34 @@ namespace winrt::CelestiaWinUI::implementation
8282
{
8383
getInfoEvent.remove(token);
8484
}
85+
86+
event_token BrowserItemUserControl::OpenURL(Windows::Foundation::EventHandler<hstring> const& handler)
87+
{
88+
return openURLEvent.add(handler);
89+
}
90+
91+
void BrowserItemUserControl::OpenURL(event_token const& token) noexcept
92+
{
93+
openURLEvent.remove(token);
94+
}
95+
96+
event_token BrowserItemUserControl::ShowSubsystem(Windows::Foundation::EventHandler<CelestiaWinUI::InfoShowSubsystemArgs> const& handler)
97+
{
98+
return showSubsystemEvent.add(handler);
99+
}
100+
101+
void BrowserItemUserControl::ShowSubsystem(event_token const& token) noexcept
102+
{
103+
showSubsystemEvent.remove(token);
104+
}
105+
106+
void BrowserItemUserControl::ControlStrip_GetInfo(IInspectable const&, CelestiaWinUI::InfoGetInfoArgs const& args)
107+
{
108+
getInfoEvent(*this, args);
109+
}
110+
111+
void BrowserItemUserControl::ControlStrip_ShowSubsystem(IInspectable const&, CelestiaWinUI::InfoShowSubsystemArgs const& args)
112+
{
113+
showSubsystemEvent(*this, args);
114+
}
85115
}

CelestiaWinUI/BrowserItemUserControl.xaml.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ namespace winrt::CelestiaWinUI::implementation
2525

2626
event_token GetInfo(Windows::Foundation::EventHandler<CelestiaWinUI::InfoGetInfoArgs> const& handler);
2727
void GetInfo(event_token const& token) noexcept;
28+
event_token ShowSubsystem(Windows::Foundation::EventHandler<CelestiaWinUI::InfoShowSubsystemArgs> const& handler);
29+
void ShowSubsystem(event_token const& token) noexcept;
30+
event_token OpenURL(Windows::Foundation::EventHandler<hstring> const& handler);
31+
void OpenURL(event_token const& token) noexcept;
32+
33+
void ControlStrip_GetInfo(Windows::Foundation::IInspectable const&, CelestiaWinUI::InfoGetInfoArgs const&);
34+
void ControlStrip_ShowSubsystem(Windows::Foundation::IInspectable const&, CelestiaWinUI::InfoShowSubsystemArgs const&);
2835

2936
private:
3037
CelestiaComponent::CelestiaAppCore appCore;
3138
CelestiaComponent::CelestiaRenderer renderer;
3239
bool preserveMargin;
3340
Microsoft::UI::Xaml::Interop::IBindableObservableVector rootItem{ nullptr };
3441
event<Windows::Foundation::EventHandler<CelestiaWinUI::InfoGetInfoArgs>> getInfoEvent;
42+
event<Windows::Foundation::EventHandler<CelestiaWinUI::InfoShowSubsystemArgs>> showSubsystemEvent;
43+
event<Windows::Foundation::EventHandler<hstring>> openURLEvent;
3544
};
3645
}
3746

CelestiaWinUI/BrowserUserControl.idl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// as published by the Free Software Foundation; either version 2
88
// of the License, or (at your option) any later version.
99

10+
import "InfoControlStrip.idl";
11+
1012
namespace CelestiaWinUI
1113
{
1214
[default_interface]
@@ -15,5 +17,9 @@ namespace CelestiaWinUI
1517
BrowserUserControl(CelestiaComponent.CelestiaAppCore appCore, CelestiaComponent.CelestiaRenderer renderer);
1618

1719
Windows.Foundation.Collections.IObservableVector<CelestiaAppComponent.BrowserItemTab> RootItems{ get; };
20+
21+
event Windows.Foundation.EventHandler<String> OpenURL;
22+
event Windows.Foundation.EventHandler<InfoGetInfoArgs> GetInfo;
23+
event Windows.Foundation.EventHandler<InfoShowSubsystemArgs> ShowSubsystem;
1824
}
1925
}

CelestiaWinUI/BrowserUserControl.xaml.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ namespace winrt::CelestiaWinUI::implementation
5050
auto browserItem = item.try_as<BrowserItemTab>();
5151
if (browserItem == nullptr) return;
5252
BrowserItemUserControl userControl{ appCore, renderer, browserItem, false };
53+
userControl.OpenURL([weak_this{ get_weak() }](IInspectable const&, hstring const& url)
54+
{
55+
auto strong_this{ weak_this.get() };
56+
if (strong_this == nullptr) return;
57+
strong_this->openURLEvent(*strong_this, url);
58+
});
59+
userControl.GetInfo([weak_this{ get_weak() }](IInspectable const&, CelestiaWinUI::InfoGetInfoArgs const& args)
60+
{
61+
auto strong_this{ weak_this.get() };
62+
if (strong_this == nullptr) return;
63+
strong_this->getInfoEvent(*strong_this, args);
64+
});
65+
userControl.ShowSubsystem([weak_this{ get_weak() }](IInspectable const&, CelestiaWinUI::InfoShowSubsystemArgs const& args)
66+
{
67+
auto strong_this{ weak_this.get() };
68+
if (strong_this == nullptr) return;
69+
strong_this->showSubsystemEvent(*strong_this, args);
70+
});
5371

5472
BrowserItemListContainer().Children().Append(userControl);
5573
BrowserItemListContainer().SetAlignTopWithPanel(userControl, true);
@@ -252,4 +270,34 @@ namespace winrt::CelestiaWinUI::implementation
252270
}
253271
Nav().SelectedItem(rootItems.GetAt(0));
254272
}
273+
274+
event_token BrowserUserControl::OpenURL(EventHandler<hstring> const& handler)
275+
{
276+
return openURLEvent.add(handler);
277+
}
278+
279+
void BrowserUserControl::OpenURL(event_token const& token) noexcept
280+
{
281+
openURLEvent.remove(token);
282+
}
283+
284+
event_token BrowserUserControl::GetInfo(EventHandler<CelestiaWinUI::InfoGetInfoArgs> const& handler)
285+
{
286+
return getInfoEvent.add(handler);
287+
}
288+
289+
void BrowserUserControl::GetInfo(event_token const& token) noexcept
290+
{
291+
getInfoEvent.remove(token);
292+
}
293+
294+
event_token BrowserUserControl::ShowSubsystem(EventHandler<CelestiaWinUI::InfoShowSubsystemArgs> const& handler)
295+
{
296+
return showSubsystemEvent.add(handler);
297+
}
298+
299+
void BrowserUserControl::ShowSubsystem(event_token const& token) noexcept
300+
{
301+
showSubsystemEvent.remove(token);
302+
}
255303
}

CelestiaWinUI/BrowserUserControl.xaml.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ namespace winrt::CelestiaWinUI::implementation
2323

2424
void NavigationView_SelectionChanged(Windows::Foundation::IInspectable const&, Microsoft::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs const& args);
2525

26+
event_token OpenURL(Windows::Foundation::EventHandler<hstring> const& handler);
27+
void OpenURL(event_token const& token) noexcept;
28+
event_token GetInfo(Windows::Foundation::EventHandler<CelestiaWinUI::InfoGetInfoArgs> const& handler);
29+
void GetInfo(event_token const& token) noexcept;
30+
event_token ShowSubsystem(Windows::Foundation::EventHandler<CelestiaWinUI::InfoShowSubsystemArgs> const& handler);
31+
void ShowSubsystem(event_token const& token) noexcept;
32+
2633
private:
2734
CelestiaComponent::CelestiaAppCore appCore;
2835
CelestiaComponent::CelestiaRenderer renderer;
2936
Windows::Foundation::Collections::IObservableVector<CelestiaAppComponent::BrowserItemTab> rootItems;
3037

3138
void LoadData();
39+
event<Windows::Foundation::EventHandler<hstring>> openURLEvent;
40+
event<Windows::Foundation::EventHandler<CelestiaWinUI::InfoGetInfoArgs>> getInfoEvent;
41+
event<Windows::Foundation::EventHandler<CelestiaWinUI::InfoShowSubsystemArgs>> showSubsystemEvent;
3242
};
3343
}
3444

CelestiaWinUI/InfoControlStrip.xaml.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,6 @@ namespace winrt::CelestiaWinUI::implementation
179179
{
180180
auto args = make<InfoShowSubsystemArgs>(selection);
181181
showSubsystemEvent(*this, args);
182-
if (!args.Handled())
183-
{
184-
CelestiaAppCore core = appCore;
185-
auto items = single_threaded_observable_vector<BrowserItem>();
186-
CelestiaBrowserItem browserItem{ appCore.Simulation().Universe().NameForSelection(selection), selection.Object(), [core](CelestiaBrowserItem const& item)
187-
{
188-
return CelestiaExtension::GetChildren(item, core);
189-
}, false };
190-
items.Append(BrowserItem(browserItem));
191-
BrowserItemUserControl userControl{ appCore, renderer, BrowserItemTab(items, L"") };
192-
Window window;
193-
window.SystemBackdrop(Media::MicaBackdrop());
194-
window.Content(userControl);
195-
window.Title(appCore.Simulation().Universe().NameForSelection(selection));
196-
WindowHelper::SetWindowIcon(window);
197-
WindowHelper::SetWindowTheme(window);
198-
WindowHelper::SetWindowFlowDirection(window);
199-
WindowHelper::ResizeWindow(window, 600, 600);
200-
window.Activate();
201-
}
202182
}
203183
else if (auto inputAction = action.try_as<BrowserInputAction>(); inputAction != nullptr)
204184
{
@@ -214,19 +194,6 @@ namespace winrt::CelestiaWinUI::implementation
214194
{
215195
auto args = make<InfoGetInfoArgs>(selection);
216196
getInfoEvent(*this, args);
217-
if (!args.Handled())
218-
{
219-
InfoUserControl userControl{ appCore, renderer, selection };
220-
Window window;
221-
window.SystemBackdrop(Media::MicaBackdrop());
222-
window.Content(userControl);
223-
window.Title(appCore.Simulation().Universe().NameForSelection(selection));
224-
WindowHelper::SetWindowIcon(window);
225-
WindowHelper::SetWindowTheme(window);
226-
WindowHelper::SetWindowFlowDirection(window);
227-
WindowHelper::ResizeWindow(window, 600, 600);
228-
window.Activate();
229-
}
230197
}
231198
else if (action.try_as<BrowserSelectAction>() != nullptr)
232199
{

CelestiaWinUI/InfoUserControl.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ namespace CelestiaWinUI
1818
InfoUserControl(CelestiaComponent.CelestiaAppCore appCore, CelestiaComponent.CelestiaRenderer renderer, CelestiaComponent.CelestiaSelection selection, Boolean preserveMargin);
1919

2020
event Windows.Foundation.EventHandler<InfoShowSubsystemArgs> ShowSubsystem;
21+
event Windows.Foundation.EventHandler<InfoGetInfoArgs> GetInfo;
22+
event Windows.Foundation.EventHandler<String> OpenURL;
2123
}
2224
}

CelestiaWinUI/InfoUserControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<HyperlinkButton x:Name="LinkButton" Margin="0" Padding="0"/>
1717
</StackPanel>
1818
</ScrollViewer>
19-
<local:InfoControlStrip x:Name="ControlStrip" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" ShowSubsystem="ControlStrip_ShowSubsystem"/>
19+
<local:InfoControlStrip x:Name="ControlStrip" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" ShowSubsystem="ControlStrip_ShowSubsystem" GetInfo="ControlStrip_GetInfo"/>
2020
</RelativePanel>
2121
</UserControl>

0 commit comments

Comments
 (0)