Skip to content

Commit 12d1146

Browse files
committed
feat(widgets): add documentation link and widget addition functionality
- Updated APP_VERSION to 0.0.2. - Introduced a button for adding widgets in the WidgetsPage. - Added a hyperlink for documentation in the YamlEditorDialog. - Enhanced widget editor dialog to include a documentation link.
1 parent 1b8f5ce commit 12d1146

7 files changed

Lines changed: 44 additions & 3 deletions

File tree

app/core/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66

77
# Application metadata
8-
APP_VERSION = "0.0.1"
8+
APP_VERSION = "0.0.2"
99
DEFAULT_SETTINGS = {"language": "en", "theme": "default", "backdrop": "mica"}
1010

1111
# External URLs

app/core/locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"widgets_center_desc": "Widgets zentriert",
124124
"widgets_right_desc": "Widgets rechts ausgerichtet",
125125
"widgets_yaml_error_title": "Ungültiges YAML",
126+
"widgets_docs_link": "Widget Doku",
126127

127128
"styles_title": "Stile (CSS)",
128129

app/core/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"widgets_center_desc": "Widgets centered in the bar",
123123
"widgets_right_desc": "Widgets aligned to the right side of the bar",
124124
"widgets_yaml_error_title": "Invalid YAML",
125+
"widgets_docs_link": "Widget Docs",
125126

126127
"styles_title": "Styles (CSS)",
127128

app/core/locales/pt_BR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"widgets_center_desc": "Componentes centralizados",
124124
"widgets_right_desc": "Componentes alinhados à direita",
125125
"widgets_yaml_error_title": "YAML Inválido",
126+
"widgets_docs_link": "Widget Docs",
126127

127128
"styles_title": "Estilos (CSS)",
128129

app/pages/widgets.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
ContentDialogButton,
4747
FontIcon,
4848
Grid,
49+
HyperlinkButton,
4950
InfoBar,
5051
MenuFlyout,
5152
MenuFlyoutItem,
@@ -106,10 +107,14 @@ def show(self):
106107
page_title = content.find_name("PageTitle").as_(TextBlock)
107108
select_bar_label = content.find_name("SelectBarLabel").as_(TextBlock)
108109
bar_selector = content.find_name("BarSelector").as_(ComboBox)
110+
add_widget_button = content.find_name("AddWidgetButton").as_(Button)
111+
add_widget_text = content.find_name("AddWidgetText").as_(TextBlock)
109112
self._sections_panel = content.find_name("SectionsPanel").as_(StackPanel)
110113

111114
page_title.text = t("widgets_title")
112115
select_bar_label.text = t("bars_selection")
116+
add_widget_text.text = t("widgets_add")
117+
add_widget_button.add_click(lambda s, e: self._show_add_widget_dialog(None))
113118

114119
self._create_sections()
115120

@@ -582,12 +587,22 @@ def _show_edit_widget_dialog(self, widget_name, position):
582587
if not widget:
583588
warning(f"Widget not found: {widget_name}")
584589
return
590+
591+
# Get doc_link from registry by matching type_path
592+
widget_type = widget.get("type", "unknown")
593+
doc_link = ""
594+
for wid, info in self._widget_registry.items():
595+
if info.type_path == widget_type:
596+
doc_link = getattr(info, "doc_link", "")
597+
break
598+
585599
self._show_widget_editor_dialog(
586600
widget_name=widget_name,
587-
widget_type=widget.get("type", "unknown"),
601+
widget_type=widget_type,
588602
options=widget.get("options", {}),
589603
position=position,
590604
is_new=False,
605+
doc_link=doc_link,
591606
)
592607

593608
def _show_new_widget_dialog(self, widget_info, position):
@@ -607,9 +622,10 @@ def _show_new_widget_dialog(self, widget_info, position):
607622
options=widget_info["defaults"].copy() if widget_info["defaults"] else {},
608623
position=position,
609624
is_new=True,
625+
doc_link=widget_info.get("doc_link", ""),
610626
)
611627

612-
def _show_widget_editor_dialog(self, widget_name, widget_type, options, position, is_new):
628+
def _show_widget_editor_dialog(self, widget_name, widget_type, options, position, is_new, doc_link=""):
613629
"""Show dialog to edit or create a widget's options using Monaco editor.
614630
615631
Args:
@@ -618,6 +634,7 @@ def _show_widget_editor_dialog(self, widget_name, widget_type, options, position
618634
options: Widget options dict
619635
position: Bar position ("left", "center", "right") or None
620636
is_new: True if creating new widget, False if editing existing
637+
doc_link: URL to widget documentation (optional)
621638
"""
622639
try:
623640
self._app._loading = True
@@ -650,6 +667,7 @@ def _show_widget_editor_dialog(self, widget_name, widget_type, options, position
650667
name_input = dialog_content.find_name("NameInput").as_(TextBox)
651668
name_error = dialog_content.find_name("NameError").as_(TextBlock)
652669
type_text = dialog_content.find_name("TypeText").as_(TextBlock)
670+
docs_link = dialog_content.find_name("DocsLink").as_(HyperlinkButton)
653671
options_label = dialog_content.find_name("OptionsLabel").as_(TextBlock)
654672
webview = dialog_content.find_name("EditorWebView").as_(WebView2)
655673
loading_overlay = dialog_content.find_name("LoadingOverlay").as_(Grid)
@@ -658,6 +676,13 @@ def _show_widget_editor_dialog(self, widget_name, widget_type, options, position
658676
type_text.text = widget_type
659677
options_label.text = t("widgets_options")
660678

679+
# Set up docs link if available
680+
if doc_link:
681+
docs_link_text = dialog_content.find_name("DocsLinkText").as_(TextBlock)
682+
docs_link_text.text = t("widgets_docs_link")
683+
docs_link.add_click(lambda s, e, url=doc_link: __import__("webbrowser").open(url))
684+
docs_link.visibility = Visibility.VISIBLE
685+
661686
# Name validation state
662687
editor_state_name = {"valid": True, "original_name": widget_name}
663688

@@ -929,6 +954,7 @@ def _setup_widget_data(self):
929954
"description": info.description,
930955
"type_path": info.type_path,
931956
"defaults": getattr(info, "defaults", {}),
957+
"doc_link": getattr(info, "doc_link", ""),
932958
}
933959
)
934960
all_widgets.sort(key=lambda x: (x["category"], x["name"]))

app/xaml/dialogs/YamlEditorDialog.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
<Border Background="{{ThemeResource SystemControlBackgroundBaseLowBrush}}" CornerRadius="4" Padding="6,2" VerticalAlignment="Center">
2929
<TextBlock x:Name="TypeText" FontFamily="Consolas, Courier New, monospace"/>
3030
</Border>
31+
<HyperlinkButton x:Name="DocsLink" Padding="0" VerticalAlignment="Center" Visibility="Collapsed">
32+
<StackPanel Orientation="Horizontal" Spacing="4">
33+
<TextBlock x:Name="DocsLinkText"/>
34+
<FontIcon Glyph="&#xE8A7;" FontSize="12"/>
35+
</StackPanel>
36+
</HyperlinkButton>
3137
</StackPanel>
3238
<TextBlock x:Name="OptionsLabel" Style="{{StaticResource BodyStrongTextBlockStyle}}"/>
3339
<Grid Height="420">

app/xaml/pages/WidgetsPage.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
1717
<TextBlock x:Name="SelectBarLabel" Text="Select bar" VerticalAlignment="Center"/>
1818
<ComboBox x:Name="BarSelector" MinWidth="180"/>
19+
<Button x:Name="AddWidgetButton">
20+
<StackPanel Orientation="Horizontal" Spacing="6">
21+
<FontIcon Glyph="&#xE710;" FontSize="12"/>
22+
<TextBlock x:Name="AddWidgetText" Text="Add Widget" VerticalAlignment="Center"/>
23+
</StackPanel>
24+
</Button>
1925
</StackPanel>
2026
</Grid>
2127
<StackPanel x:Name="SectionsPanel" Spacing="4"/>

0 commit comments

Comments
 (0)