@@ -469,160 +469,47 @@ struct ContentView: View {
469469 }
470470
471471 /// Gemeinsamer List-Inhalt für Palette + Aktionen.
472- @ ViewBuilder
473472 private var paletteListStackBody : some View {
474- let isCompact = horizontalSizeClass != . regular
475- List {
476- Section {
477- ForEach ( ElementPalette . PaletteItem . paletteOrder ) { item in
478- paletteStructureRow ( item , isCompact : isCompact )
479- }
473+ PaletteActionList (
474+ isSimulationMode : isSimulationMode ,
475+ canDeleteSelection : selectedPath . map { path in
476+ VisuStructDocumentEditing . canDeleteElement ( at : path , in : document )
477+ } ?? false ,
478+ codeGeneratorAccessGranted : codeGeneratorAccessGranted ,
479+ onInsertItem : insertPaletteItem ,
480+ onDeleteSelection : deleteSelection ,
481+ onToggleSimulation : toggleSimulationMode ,
482+ onGenerateCode : openCodeGenerator ,
483+ onSharePNG : exportPNG ,
484+ onShareDocument : shareDocumentAsFile ,
485+ onExportPDF : shareDiagramPDF ,
486+ onShowAbout : { showInfo = true }
487+ )
488+ }
489+
490+ private func toggleSimulationMode ( ) {
491+ if ! isSimulationMode {
492+ applyLineEditorRespectingTextFocus ( )
493+ DispatchQueue . main . async {
494+ beginSimulationMode ( )
480495 }
481- Section {
482- Button {
483- deleteSelection ( )
484- } label : {
485- Label ( lang . tr ( " action_delete_selection " ) , systemImage : " trash " )
486- }
487- . buttonStyle ( PaletteListElementButtonStyle ( emphasis : . destructive ) )
488- . disabledAndDimmed ( isSimulationMode )
489- . listRowInsets (
490- isCompact
491- ? EdgeInsets ( top : 4 , leading : 10 , bottom : 3 , trailing : 10 )
492- : EdgeInsets ( top : 8 , leading : 12 , bottom : 5 , trailing : 12 )
493- )
494- . listRowSeparator ( . hidden )
495- . listRowBackground ( Color . clear )
496- . disabled (
497- isSimulationMode || ( selectedPath . map { path in
498- ! VisuStructDocumentEditing . canDeleteElement ( at : path , in : document )
499- } ?? true )
500- )
501- Button {
502- if ! isSimulationMode {
503- applyLineEditorRespectingTextFocus ( )
504- DispatchQueue . main . async {
505- beginSimulationMode ( )
506- }
507- } else {
508- endSimulationMode ( )
509- }
510- } label : {
511- Label (
512- isSimulationMode ? lang . tr ( " action_diagram " ) : lang . tr ( " action_simulation " ) ,
513- systemImage : isSimulationMode ? " rectangle.split.3x1 " : " play.circle "
514- )
515- }
516- . buttonStyle ( PaletteListElementButtonStyle ( ) )
517- . listRowInsets (
518- isCompact
519- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 3 , trailing : 10 )
520- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
521- )
522- . listRowSeparator ( . hidden )
523- . listRowBackground ( Color . clear )
524- . accessibilityLabel ( isSimulationMode ? lang . tr ( " action_diagram " ) : lang . tr ( " action_simulation " ) )
525- Button {
526- if codeGeneratorAccessGranted {
527- // Wichtig: Text im Inspector ist nicht immer sofort ins Dokument geschrieben (Button „Text übernehmen“).
528- // Für Code-Generierung wollen wir immer den aktuell sichtbaren Stand verwenden.
529- applyLineEditorRespectingTextFocus ( )
530- DispatchQueue . main . async {
531- codeGeneratorRegenerationToken &+= 1
532- showCodeGeneratorPlaceholder = true
533- }
534- } else {
535- showCodeGeneratorPaywall = true
536- }
537- } label : {
538- HStack ( spacing : 10 ) {
539- Label ( lang . tr ( " action_generate_code " ) , systemImage : " chevron.left.forwardslash.chevron.right " )
540- . foregroundStyle ( isSimulationMode ? . tertiary : . primary )
541- Spacer ( minLength : 8 )
542- if ! codeGeneratorAccessGranted {
543- Image ( systemName : " lock.fill " )
544- . font ( . body )
545- . foregroundStyle ( . secondary )
546- }
547- }
548- }
549- . buttonStyle ( PaletteListElementButtonStyle ( ) )
550- . disabledAndDimmed ( isSimulationMode )
551- . listRowInsets (
552- isCompact
553- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 3 , trailing : 10 )
554- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
555- )
556- . listRowSeparator ( . hidden )
557- . listRowBackground ( Color . clear )
558- . accessibilityLabel (
559- codeGeneratorAccessGranted ? lang . tr ( " a11y_generate_code " ) : lang . tr ( " a11y_generate_code_locked " )
560- )
561- Button {
562- exportPNG ( )
563- } label : {
564- Label ( lang . tr ( " action_share_png " ) , systemImage : " square.and.arrow.up " )
565- . foregroundStyle ( isSimulationMode ? . tertiary : . primary )
566- }
567- . buttonStyle ( PaletteListElementButtonStyle ( ) )
568- . disabledAndDimmed ( isSimulationMode )
569- . listRowInsets (
570- isCompact
571- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 3 , trailing : 10 )
572- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
573- )
574- . listRowSeparator ( . hidden )
575- . listRowBackground ( Color . clear )
576- Button {
577- shareDocumentAsFile ( )
578- } label : {
579- Label ( lang . tr ( " action_share_document " ) , systemImage : " square.and.arrow.up.on.square " )
580- . foregroundStyle ( isSimulationMode ? . tertiary : . primary )
581- }
582- . buttonStyle ( PaletteListElementButtonStyle ( ) )
583- . disabledAndDimmed ( isSimulationMode )
584- . listRowInsets (
585- isCompact
586- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 3 , trailing : 10 )
587- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
588- )
589- . listRowSeparator ( . hidden )
590- . listRowBackground ( Color . clear )
591- Button {
592- shareDiagramPDF ( )
593- } label : {
594- Label ( lang . tr ( " action_export_pdf " ) , systemImage : " doc.text.magnifyingglass " )
595- . foregroundStyle ( isSimulationMode ? . tertiary : . primary )
596- }
597- . buttonStyle ( PaletteListElementButtonStyle ( ) )
598- . disabledAndDimmed ( isSimulationMode )
599- . listRowInsets (
600- isCompact
601- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 3 , trailing : 10 )
602- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
603- )
604- . listRowSeparator ( . hidden )
605- . listRowBackground ( Color . clear )
496+ } else {
497+ endSimulationMode ( )
498+ }
499+ }
606500
607- Button {
608- showInfo = true
609- } label : {
610- Label ( lang . tr ( " action_about " ) , systemImage : " info.circle " )
611- }
612- . buttonStyle ( PaletteListElementButtonStyle ( ) )
613- . listRowInsets (
614- isCompact
615- ? EdgeInsets ( top : 3 , leading : 10 , bottom : 4 , trailing : 10 )
616- : EdgeInsets ( top : 5 , leading : 12 , bottom : 8 , trailing : 12 )
617- )
618- . listRowSeparator ( . hidden )
619- . listRowBackground ( Color . clear )
501+ private func openCodeGenerator ( ) {
502+ if codeGeneratorAccessGranted {
503+ // Wichtig: Text im Inspector ist nicht immer sofort ins Dokument geschrieben (Button „Text übernehmen“).
504+ // Für Code-Generierung wollen wir immer den aktuell sichtbaren Stand verwenden.
505+ applyLineEditorRespectingTextFocus ( )
506+ DispatchQueue . main . async {
507+ codeGeneratorRegenerationToken &+= 1
508+ showCodeGeneratorPlaceholder = true
620509 }
510+ } else {
511+ showCodeGeneratorPaywall = true
621512 }
622- . listStyle ( . insetGrouped )
623- . listSectionSpacing ( isCompact ? 8 : 18 )
624- . environment ( \. defaultMinListRowHeight , isCompact ? 34 : 48 )
625- . scrollContentBackground ( . hidden )
626513 }
627514
628515 // MARK: - Haupteditor (NavigationStack, Tabs, Fehler)
@@ -745,50 +632,12 @@ struct ContentView: View {
745632
746633 // MARK: - Simulations-Ansicht
747634
748- @ ViewBuilder
749635 private var simulationDetailView : some View {
750- GeometryReader { geo in
751- let useColumns = geo . size . width >= 760
752- let panelWidth = min ( max ( geo . size . width * 0.32 , 280 ) , 360 )
753-
754- if useColumns {
755- HStack ( alignment : . top , spacing : 16 ) {
756- simulationCanvasBlock
757- . layoutPriority ( 1 )
758- SimulationStatePanel (
759- engine : simulation . engine ,
760- isPlaying : simulation . isPlaying ,
761- inputText : $simulation . inputText ,
762- highlightModeRaw : $simulationHighlightModeRaw ,
763- onPlay : { simulation . play ( ) } ,
764- onPause : { simulation . pause ( ) } ,
765- onStep : { simulation . step ( ) } ,
766- onSubmitInput : { simulation . submitInput ( ) } ,
767- onStop : { simulation . reset ( ) }
768- )
769- . frame ( width : panelWidth )
770- . frame ( maxHeight : . infinity , alignment : . top )
771- }
772- } else {
773- ScrollView {
774- VStack ( alignment : . leading , spacing : 16 ) {
775- simulationCanvasBlock
776- . frame ( height : max ( 340 , geo . size . height * 0.55 ) )
777- SimulationStatePanel (
778- engine : simulation . engine ,
779- isPlaying : simulation . isPlaying ,
780- inputText : $simulation . inputText ,
781- highlightModeRaw : $simulationHighlightModeRaw ,
782- onPlay : { simulation . play ( ) } ,
783- onPause : { simulation . pause ( ) } ,
784- onStep : { simulation . step ( ) } ,
785- onSubmitInput : { simulation . submitInput ( ) } ,
786- onStop : { simulation . reset ( ) }
787- )
788- }
789- . frame ( maxWidth : . infinity , alignment : . leading )
790- }
791- }
636+ SimulationDetailView (
637+ simulation : simulation ,
638+ highlightModeRaw : $simulationHighlightModeRaw
639+ ) {
640+ simulationCanvasBlock
792641 }
793642 }
794643
@@ -1582,46 +1431,6 @@ struct ContentView: View {
15821431 }
15831432 }
15841433
1585- @ ViewBuilder
1586- private func paletteStructureRow ( _ item : ElementPalette . PaletteItem , isCompact : Bool ) -> some View {
1587- let rowInsets = isCompact
1588- ? EdgeInsets ( top : 1 , leading : 10 , bottom : 1 , trailing : 10 )
1589- : EdgeInsets ( top : 5 , leading : 12 , bottom : 5 , trailing : 12 )
1590-
1591- if isSimulationMode {
1592- Button {
1593- insertPaletteItem ( item )
1594- } label : {
1595- Label ( item . localizedTitle ( in : lang ) , systemImage : item . symbolName )
1596- . foregroundStyle ( . tertiary )
1597- . multilineTextAlignment ( . leading )
1598- }
1599- . buttonStyle ( PaletteListElementButtonStyle ( ) )
1600- . accessibilityAddTraits ( . isButton )
1601- . disabled ( true )
1602- . opacity ( 0.55 )
1603- . listRowInsets ( rowInsets )
1604- . listRowSeparator ( . hidden )
1605- . listRowBackground ( Color . clear )
1606- } else {
1607- Button {
1608- insertPaletteItem ( item )
1609- } label : {
1610- Label ( item . localizedTitle ( in : lang ) , systemImage : item . symbolName )
1611- . foregroundStyle ( . primary )
1612- . multilineTextAlignment ( . leading )
1613- }
1614- . buttonStyle ( PaletteListElementButtonStyle ( ) )
1615- . draggable ( DiagramDragPayload ( raw : ElementPalette . paletteDragIdentifier ( item ) ) ) {
1616- paletteDragPreview ( for : item )
1617- }
1618- . accessibilityAddTraits ( . isButton )
1619- . listRowInsets ( rowInsets )
1620- . listRowSeparator ( . hidden )
1621- . listRowBackground ( Color . clear )
1622- }
1623- }
1624-
16251434 // MARK: - Zeileneditor (Synchronisation Element ↔ Textfeld)
16261435
16271436 private func refreshLineEditor ( ) {
@@ -1768,23 +1577,4 @@ struct ContentView: View {
17681577 controller . present ( animated : true )
17691578 }
17701579 #endif
1771-
1772- // MARK: - Palette Drag-Vorschau
1773-
1774- @ ViewBuilder
1775- private func paletteDragPreview ( for item : ElementPalette . PaletteItem ) -> some View {
1776- HStack ( spacing : 8 ) {
1777- Image ( systemName : item . symbolName )
1778- Text ( item . localizedTitle ( in : lang ) )
1779- . font ( . callout . weight ( . medium ) )
1780- }
1781- . padding ( . horizontal , 12 )
1782- . padding ( . vertical , 10 )
1783- . background ( . regularMaterial , in : RoundedRectangle ( cornerRadius : 8 ) )
1784- . overlay (
1785- RoundedRectangle ( cornerRadius : 8 )
1786- . strokeBorder ( Color . blue . opacity ( 0.9 ) , lineWidth : 2 )
1787- )
1788- . shadow ( color : . black . opacity ( 0.22 ) , radius : 8 , x : 0 , y : 4 )
1789- }
17901580}
0 commit comments