Skip to content

Commit

Permalink
Fix directory deletion and property view
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 26, 2024
1 parent d7b634b commit 41ac2b4
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 460 deletions.
332 changes: 157 additions & 175 deletions app/lib/views/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PropertyView extends StatefulWidget {
State<PropertyView> createState() => _PropertyViewState();
}

const minSize = 500.0;
const minSize = 450.0;

class _PropertyViewState extends State<PropertyView>
with SingleTickerProviderStateMixin {
Expand All @@ -33,8 +33,9 @@ class _PropertyViewState extends State<PropertyView>
end: const Offset(1.5, 0.0),
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOutCubic));
final _scrollController = ScrollController();
Selection? _lastSelection;

double _size = minSize;
double _size = 500;

@override
void dispose() {
Expand All @@ -45,7 +46,6 @@ class _PropertyViewState extends State<PropertyView>

@override
Widget build(BuildContext context) {
Selection? lastSelection;
return BlocBuilder<CurrentIndexCubit, CurrentIndex>(
buildWhen: (previous, current) =>
previous.selection?.selected != current.selection?.selected ||
Expand All @@ -55,199 +55,181 @@ class _PropertyViewState extends State<PropertyView>
if (selection == null) {
_controller.forward();
} else if (selection.runtimeType.toString() !=
lastSelection.runtimeType.toString()) {
_lastSelection.runtimeType.toString()) {
_controller.reset();
_controller.reverse(from: 1);
} else {
lastSelection = selection;
_controller.reverse();
}
selection ??= lastSelection;
if (selection != null) {
lastSelection = selection;
}
if (selection == null) {
_lastSelection = selection;
final showing = selection ?? _lastSelection;
if (showing == null) {
return Container();
}
final help = showing.help;
final multi = showing.selected.length != 1;
final selected = showing.selected.first;
final controller = MenuController();
final menuChildren = multi
? <Widget>[]
: DisplayIcons.recommended(selected)
.map((e) => IconButton(
icon: PhosphorIcon(e.icon(PhosphorIconsStyle.light)),
iconSize: 26,
onPressed: selected is! Tool
? null
: () {
final bloc = context.read<DocumentBloc>();
final state = bloc.state;
if (state is! DocumentLoadSuccess) {
return;
}
final painters = state.info.tools;
bloc.add(ToolsChanged({
painters.indexOf(selected):
selected.copyWith(displayIcon: e.name),
}));
controller.close();
}))
.toList();
final icon = showing
.icon(multi ? PhosphorIconsStyle.fill : PhosphorIconsStyle.light);
return LayoutBuilder(builder: (context, constraints) {
final isMobile =
constraints.maxWidth < minSize || constraints.maxHeight < 400;
return StatefulBuilder(builder: (context, setState) {
return Container(
padding: const EdgeInsets.all(8),
constraints: BoxConstraints(maxWidth: _size, maxHeight: 500),
child: SlideTransition(
position: _offsetAnimation,
child: Material(
elevation: 6,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
child: AnimatedSize(
alignment: Alignment.topCenter,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 200),
child: Row(children: [
if (!isMobile)
MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector(
child: const PhosphorIcon(
PhosphorIconsLight.dotsSixVertical),
onPanUpdate: (details) {
final delta = details.delta.dx;
setState(() {
_size -= delta;
_size = max(_size, minSize);
});
},
),
return Container(
padding: const EdgeInsets.all(8),
constraints: BoxConstraints(maxWidth: _size, maxHeight: 500),
child: SlideTransition(
position: _offsetAnimation,
child: Material(
elevation: 6,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
child: AnimatedSize(
alignment: Alignment.topCenter,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 200),
child: Row(children: [
if (!isMobile)
MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector(
child: const PhosphorIcon(
PhosphorIconsLight.dotsSixVertical),
onPanUpdate: (details) {
final delta = details.delta.dx;
setState(() {
_size -= delta;
_size = max(_size, minSize);
});
},
),
Expanded(child: Builder(builder: (context) {
final help = selection!.help;
final multi = selection.selected.length != 1;
final selected = selection.selected.first;
final controller = MenuController();
final menuChildren = multi
? <Widget>[]
: DisplayIcons.recommended(selected)
.map((e) => IconButton(
icon: PhosphorIcon(
e.icon(PhosphorIconsStyle.light)),
iconSize: 26,
onPressed: selected is! Tool
? null
: () {
final bloc =
context.read<DocumentBloc>();
final state = bloc.state;
if (state
is! DocumentLoadSuccess) {
return;
}
final painters = state.info.tools;
bloc.add(ToolsChanged({
painters.indexOf(selected):
selected.copyWith(
displayIcon: e.name),
}));
controller.close();
}))
.toList();
final icon = selection.icon(multi
? PhosphorIconsStyle.fill
: PhosphorIconsStyle.light);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Header(
centerTitle: false,
leadingWidth: 60,
title:
Text(selection.getLocalizedName(context)),
leading: menuChildren.length <= 1
? PhosphorIcon(
icon,
color:
Theme.of(context).iconTheme.color,
)
: MenuAnchor(
controller: controller,
builder: defaultFilledMenuButton(
iconBuilder:
(context, controller, child) =>
Row(
children: [
PhosphorIcon(
icon,
color: Theme.of(context)
.colorScheme
.onPrimary,
),
const SizedBox(width: 8),
PhosphorIcon(
controller.isOpen
? PhosphorIconsLight.caretUp
: PhosphorIconsLight
.caretDown,
color: Theme.of(context)
.colorScheme
.onPrimary,
size: 12,
),
],
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Header(
centerTitle: false,
leadingWidth: 60,
title: Text(showing.getLocalizedName(context)),
leading: menuChildren.length <= 1
? PhosphorIcon(
icon,
color: Theme.of(context).iconTheme.color,
)
: MenuAnchor(
controller: controller,
builder: defaultFilledMenuButton(
iconBuilder:
(context, controller, child) => Row(
children: [
PhosphorIcon(
icon,
color: Theme.of(context)
.colorScheme
.onPrimary,
),
const SizedBox(width: 8),
PhosphorIcon(
controller.isOpen
? PhosphorIconsLight.caretUp
: PhosphorIconsLight.caretDown,
color: Theme.of(context)
.colorScheme
.onPrimary,
size: 12,
),
tooltip:
AppLocalizations.of(context).icon,
),
menuChildren: menuChildren,
],
),
actions: [
if (selection.showDeleteButton)
IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.trash),
tooltip:
AppLocalizations.of(context).delete,
onPressed: () {
selection?.onDelete(context);
context
.read<CurrentIndexCubit>()
.resetSelection(force: true);
}),
if (help.isNotEmpty)
IconButton(
tooltip:
AppLocalizations.of(context).help,
icon: const PhosphorIcon(
PhosphorIconsLight.sealQuestion),
onPressed: () => openHelp(help),
AppLocalizations.of(context).icon,
),
const SizedBox(
height: 16, child: VerticalDivider()),
if (!isMobile)
IconButton(
tooltip: state.pinned
? AppLocalizations.of(context).unpin
: AppLocalizations.of(context).pin,
icon: state.pinned
? const PhosphorIcon(
PhosphorIconsFill.pushPin)
: const PhosphorIcon(
PhosphorIconsLight.pushPin),
onPressed: () => context
.read<CurrentIndexCubit>()
.togglePin(),
),
const SizedBox(width: 8),
IconButton.outlined(
tooltip: AppLocalizations.of(context).close,
icon: const PhosphorIcon(
PhosphorIconsLight.x),
onPressed: _closeView,
menuChildren: menuChildren,
),
],
),
Flexible(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
child: ListView(
shrinkWrap: true,
primary: true,
children:
selection.buildProperties(context)),
actions: [
if (showing.showDeleteButton)
IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.trash),
tooltip:
AppLocalizations.of(context).delete,
onPressed: () {
selection?.onDelete(context);
context
.read<CurrentIndexCubit>()
.resetSelection(force: true);
}),
if (help.isNotEmpty)
IconButton(
tooltip: AppLocalizations.of(context).help,
icon: const PhosphorIcon(
PhosphorIconsLight.sealQuestion),
onPressed: () => openHelp(help),
),
const SizedBox(
height: 16, child: VerticalDivider()),
if (!isMobile)
IconButton(
tooltip: state.pinned
? AppLocalizations.of(context).unpin
: AppLocalizations.of(context).pin,
icon: state.pinned
? const PhosphorIcon(
PhosphorIconsFill.pushPin)
: const PhosphorIcon(
PhosphorIconsLight.pushPin),
onPressed: () => context
.read<CurrentIndexCubit>()
.togglePin(),
),
const SizedBox(width: 8),
IconButton.outlined(
tooltip: AppLocalizations.of(context).close,
icon: const PhosphorIcon(PhosphorIconsLight.x),
onPressed: _closeView,
),
],
);
})),
]),
),
),
Flexible(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
child: ListView(
shrinkWrap: true,
primary: true,
children: showing.buildProperties(context)),
),
),
],
)),
]),
),
),
);
});
),
);
});
});
}
Expand Down
Loading

0 comments on commit 41ac2b4

Please sign in to comment.