Skip to content
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
4 changes: 4 additions & 0 deletions lib/pages/auto_editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class _AutoEditorPageState extends State<AutoEditorPage> {
widget.telemetry?.hotReloadAuto(widget.auto);
}
},
onEditPathPressed: (pathName) {
widget.undoStack.clearHistory();
Navigator.of(context).pop(pathName);
},
);

return Scaffold(
Expand Down
121 changes: 65 additions & 56 deletions lib/pages/project/project_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:file/file.dart';
import 'package:flutter/material.dart';
import 'package:multi_split_view/multi_split_view.dart';
Expand Down Expand Up @@ -919,55 +920,8 @@ class _ProjectPageState extends State<ProjectPage> {
}
}
},
onRenamed: (value) => _renamePath(i, value, context),
onOpened: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PathEditorPage(
prefs: widget.prefs,
path: _paths[i],
fieldImage: widget.fieldImage,
undoStack: widget.undoStack,
onRenamed: (value) => _renamePath(i, value, context),
shortcuts: widget.shortcuts,
telemetry: widget.telemetry,
hotReload: widget.hotReload,
simulatePath: widget.simulatePath,
onPathChanged: () {
// Make sure all paths with linked waypoints are updated
for (PathPlannerPath p in _paths) {
bool changed = false;

for (Waypoint w in p.waypoints) {
if (w.linkedName != null) {
var anchor = Waypoint.linked[w.linkedName];

if (anchor != null &&
anchor.getDistance(w.anchor) >= 0.01) {
w.move(anchor.x, anchor.y);
changed = true;
}
}
}

if (changed) {
p.generateAndSavePath();

if (widget.hotReload) {
widget.telemetry?.hotReloadPath(p);
}
}
}
},
),
),
);

setState(() {
_sortPaths(_pathSortValue);
});
},
onRenamed: (value) => _renamePath(_paths[i], value, context),
onOpened: () => _openPath(_paths[i]),
);

return LayoutBuilder(builder: (context, constraints) {
Expand Down Expand Up @@ -1029,10 +983,58 @@ class _ProjectPageState extends State<ProjectPage> {
});
}

void _renamePath(int pathIdx, String newName, BuildContext context) {
void _openPath(PathPlannerPath path) async {
await Navigator.push(
this.context,
MaterialPageRoute(
builder: (context) => PathEditorPage(
prefs: widget.prefs,
path: path,
fieldImage: widget.fieldImage,
undoStack: widget.undoStack,
onRenamed: (value) => _renamePath(path, value, context),
shortcuts: widget.shortcuts,
telemetry: widget.telemetry,
hotReload: widget.hotReload,
simulatePath: widget.simulatePath,
onPathChanged: () {
// Make sure all paths with linked waypoints are updated
for (PathPlannerPath p in _paths) {
bool changed = false;

for (Waypoint w in p.waypoints) {
if (w.linkedName != null) {
var anchor = Waypoint.linked[w.linkedName];

if (anchor != null && anchor.getDistance(w.anchor) >= 0.01) {
w.move(anchor.x, anchor.y);
changed = true;
}
}
}

if (changed) {
p.generateAndSavePath();

if (widget.hotReload) {
widget.telemetry?.hotReloadPath(p);
}
}
}
},
),
),
);

setState(() {
_sortPaths(_pathSortValue);
});
}

void _renamePath(PathPlannerPath path, String newName, BuildContext context) {
List<String> pathNames = [];
for (PathPlannerPath path in _paths) {
pathNames.add(path.name);
for (PathPlannerPath p in _paths) {
pathNames.add(p.name);
}

if (pathNames.contains(newName)) {
Expand All @@ -1051,9 +1053,9 @@ class _ProjectPageState extends State<ProjectPage> {
);
});
} else {
String oldName = _paths[pathIdx].name;
String oldName = path.name;
setState(() {
_paths[pathIdx].renamePath(newName);
path.renamePath(newName);
for (PathPlannerAuto auto in _autos) {
auto.updatePathName(oldName, newName);
}
Expand Down Expand Up @@ -1419,7 +1421,7 @@ class _ProjectPageState extends State<ProjectPage> {
},
onRenamed: (value) => _renameAuto(i, value, context),
onOpened: () async {
await Navigator.push(
String? pathNameToOpen = await Navigator.push<String?>(
context,
MaterialPageRoute(
builder: (context) => AutoEditorPage(
Expand All @@ -1439,10 +1441,17 @@ class _ProjectPageState extends State<ProjectPage> {
),
),
);

setState(() {
_sortAutos(_autoSortValue);
});

if (pathNameToOpen != null) {
final pathToOpen =
_paths.firstWhereOrNull((p) => p.name == pathNameToOpen);
if (pathToOpen != null) {
_openPath(pathToOpen);
}
}
},
warningMessage: warningMessage,
);
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/editor/split_auto_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SplitAutoEditor extends StatefulWidget {
final VoidCallback? onAutoChanged;
final FieldImage fieldImage;
final ChangeStack undoStack;
final Function(String?)? onEditPathPressed;

const SplitAutoEditor({
required this.prefs,
Expand All @@ -34,6 +35,7 @@ class SplitAutoEditor extends StatefulWidget {
required this.fieldImage,
required this.undoStack,
this.onAutoChanged,
this.onEditPathPressed,
super.key,
});

Expand Down Expand Up @@ -183,6 +185,7 @@ class _SplitAutoEditorState extends State<SplitAutoEditor>
_controller.areas = _controller.areas.reversed.toList();
}),
undoStack: widget.undoStack,
onEditPathPressed: widget.onEditPathPressed,
),
),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/editor/tree_widgets/auto_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AutoTree extends StatefulWidget {
final VoidCallback? onAutoChanged;
final ChangeStack undoStack;
final num? autoRuntime;
final Function(String?)? onEditPathPressed;

const AutoTree({
super.key,
Expand All @@ -23,6 +24,7 @@ class AutoTree extends StatefulWidget {
this.onAutoChanged,
required this.undoStack,
this.autoRuntime,
this.onEditPathPressed,
});

@override
Expand Down Expand Up @@ -74,6 +76,8 @@ class _AutoTreeState extends State<AutoTree> {
removable: false,
onUpdated: widget.onAutoChanged,
undoStack: widget.undoStack,
showEditPathButton: !widget.auto.choreoAuto,
onEditPathPressed: widget.onEditPathPressed,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CommandGroupWidget extends StatelessWidget {
final ValueChanged<String?>? onPathCommandHovered;
final ChangeStack undoStack;
final VoidCallback? onDuplicateCommand;
final bool showEditPathButton;
final Function(String?)? onEditPathPressed;

const CommandGroupWidget({
super.key,
Expand All @@ -36,6 +38,8 @@ class CommandGroupWidget extends StatelessWidget {
this.onPathCommandHovered,
required this.undoStack,
this.onDuplicateCommand,
this.showEditPathButton = true,
this.onEditPathPressed,
});

@override
Expand Down Expand Up @@ -179,6 +183,8 @@ class CommandGroupWidget extends StatelessWidget {
},
undoStack: undoStack,
onDuplicateCommand: () => _duplicateCommand(index),
showEditButton: showEditPathButton,
onEditPathPressed: onEditPathPressed,
),
),
],
Expand Down Expand Up @@ -259,6 +265,8 @@ class CommandGroupWidget extends StatelessWidget {
onRemoved: () => _removeCommand(cmdIndex),
allPathNames: allPathNames,
onPathCommandHovered: onPathCommandHovered,
showEditPathButton: showEditPathButton,
onEditPathPressed: onEditPathPressed,
onGroupTypeChanged: (value) {
undoStack.add(Change(
command.commands[cmdIndex].type,
Expand Down
33 changes: 26 additions & 7 deletions lib/widgets/editor/tree_widgets/commands/path_command_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:pathplanner/commands/path_command.dart';
import 'package:pathplanner/widgets/conditional_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/duplicate_command_button.dart';
import 'package:undo/undo.dart';

Expand All @@ -11,6 +12,8 @@ class PathCommandWidget extends StatefulWidget {
final VoidCallback? onRemoved;
final ChangeStack undoStack;
final VoidCallback? onDuplicateCommand;
final Function(String?)? onEditPathPressed;
final bool showEditButton;

const PathCommandWidget({
super.key,
Expand All @@ -20,6 +23,8 @@ class PathCommandWidget extends StatefulWidget {
this.onRemoved,
required this.undoStack,
this.onDuplicateCommand,
this.onEditPathPressed,
this.showEditButton = true,
});

@override
Expand Down Expand Up @@ -150,14 +155,28 @@ class _PathCommandWidgetState extends State<PathCommandWidget> {
),
),
const SizedBox(width: 8),
Visibility(
visible: widget.command.pathName == null,
child: Tooltip(
ConditionalWidget(
condition: widget.command.pathName == null,
trueChild: Tooltip(
message: 'Missing path name',
child: Icon(
Icons.warning_amber_rounded,
color: Colors.orange[300]!,
size: 32,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Icon(
Icons.warning_amber_rounded,
color: Colors.orange[300]!,
size: 32,
),
),
),
falseChild: Visibility(
visible: widget.showEditButton,
child: Tooltip(
message: 'Edit Path',
child: IconButton(
onPressed: () =>
widget.onEditPathPressed?.call(widget.command.pathName),
icon: const Icon(Icons.edit),
),
),
),
),
Expand Down