Skip to content

Commit

Permalink
Allow multiple selections in templates dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Mar 21, 2024
1 parent f984bea commit e5049f2
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/lib/actions/paste.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:butterfly/bloc/document_bloc.dart';
import 'package:butterfly_api/butterfly_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lw_sysinfo/lw_sysinfo.dart';
import 'package:lw_sysapi/lw_sysapi.dart';

import '../services/import.dart';

Expand Down
2 changes: 1 addition & 1 deletion app/lib/dialogs/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:butterfly/widgets/context_menu.dart';
import 'package:butterfly_api/butterfly_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:lw_sysinfo/lw_sysinfo.dart';
import 'package:lw_sysapi/lw_sysapi.dart';
import 'package:material_leap/material_leap.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

Expand Down
100 changes: 86 additions & 14 deletions app/lib/dialogs/template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class _TemplateDialogState extends State<TemplateDialog> {
late TemplateFileSystem _fileSystem;
late Future<List<NoteData>>? _templatesFuture;
final TextEditingController _searchController = TextEditingController();
final List<String> _selectedTemplates = [];

@override
void initState() {
super.initState();
_fileSystem =
context.read<SettingsCubit>().state.getDefaultTemplateFileSystem();
load();
}

void load() {
Expand All @@ -50,7 +52,6 @@ class _TemplateDialogState extends State<TemplateDialog> {

@override
Widget build(BuildContext context) {
load();
return ResponsiveDialog(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600, maxHeight: 800),
Expand Down Expand Up @@ -151,7 +152,44 @@ class _TemplateDialogState extends State<TemplateDialog> {
setState(() {});
},
),
const SizedBox(height: 16),
const SizedBox(height: 8),
SizedBox(
height: 64,
child: _selectedTemplates.isEmpty
? null
: Card(
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.trash),
onPressed: () async {
final result =
await showDialog<bool>(
context: context,
builder: (ctx) =>
const DeleteDialog());
if (result != true) return;
for (final template
in _selectedTemplates) {
await _fileSystem
.deleteTemplate(template);
}
_selectedTemplates.clear();
load();
setState(() {});
},
),
],
),
),
),
),
const SizedBox(height: 8),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
Expand All @@ -164,6 +202,20 @@ class _TemplateDialogState extends State<TemplateDialog> {
template: template,
fileSystem: _fileSystem,
replace: widget.bloc != null,
selected: _selectedTemplates
.contains(template.name),
onSelected: () {
setState(() {
_selectedTemplates
.add(template.name!);
});
},
onUnselected: () {
setState(() {
_selectedTemplates
.remove(template.name);
});
},
onChanged: () {
load();
setState(() {});
Expand Down Expand Up @@ -227,14 +279,17 @@ class _TemplateDialogState extends State<TemplateDialog> {
class _TemplateItem extends StatelessWidget {
final NoteData template;
final TemplateFileSystem fileSystem;
final VoidCallback onChanged;
final bool replace;
final VoidCallback onChanged, onSelected, onUnselected;
final bool replace, selected;

const _TemplateItem({
required this.template,
required this.fileSystem,
required this.onChanged,
required this.replace,
required this.selected,
required this.onSelected,
required this.onUnselected,
});

@override
Expand All @@ -256,16 +311,33 @@ class _TemplateItem extends StatelessWidget {
subtitle: Text(metadata.description),
leading: SizedBox(
height: 64,
width: 64,
child: thumbnail != null
? Image.memory(
thumbnail,
fit: BoxFit.contain,
cacheWidth: 64,
cacheHeight: 64,
errorBuilder: (context, error, stackTrace) => leading,
)
: leading,
width: 96,
child: Row(
children: [
Checkbox(
value: selected,
onChanged: (value) {
if (value == true) {
onSelected();
} else {
onUnselected();
}
},
),
const SizedBox(width: 8),
Expanded(
child: thumbnail != null
? Image.memory(
thumbnail,
fit: BoxFit.contain,
cacheWidth: 64,
cacheHeight: 64,
errorBuilder: (context, error, stackTrace) => leading,
)
: leading,
),
],
),
),
onSaved: (value) async {
if (value == metadata.name) return;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/handlers/handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:image/image.dart' as img;
import 'package:lw_sysinfo/lw_sysinfo.dart';
import 'package:lw_sysapi/lw_sysapi.dart';
import 'package:material_leap/material_leap.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';
import 'package:share_plus/share_plus.dart';
Expand Down
4 changes: 2 additions & 2 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:go_router/go_router.dart';
import 'package:lw_sysinfo/lw_sysinfo.dart';
import 'package:lw_sysapi/lw_sysapi.dart';
import 'package:material_leap/l10n/leap_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -110,7 +110,7 @@ Future<void> main([List<String> args = const []]) async {
await windowManager.setPreventClose(false);
});
}
final clipboardManager = await SysInfo.getClipboardManager();
final clipboardManager = await SysAPI.getClipboardManager();
GeneralFileSystem.dataPath = result['path'];
final isFullscreen = await isFullScreen();
runApp(
Expand Down
3 changes: 2 additions & 1 deletion app/lib/services/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class RemoteSync {
return;
}
if (syncMode == SyncMode.noMobile &&
await Connectivity().checkConnectivity() != ConnectivityResult.mobile) {
!(await Connectivity().checkConnectivity())
.contains(ConnectivityResult.mobile)) {
return;
}
await sync();
Expand Down
2 changes: 1 addition & 1 deletion app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
Expand Down

0 comments on commit e5049f2

Please sign in to comment.