You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:win_text_editor/app/menus/menu_constants.dart';
|
|
|
|
import 'package:win_text_editor/app/providers/file_provider.dart';
|
|
|
|
import 'package:win_text_editor/app/providers/editor_provider.dart';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
class MenuActions {
|
|
|
|
static Future<void> handleMenuAction(String value, BuildContext context) async {
|
|
|
|
switch (value) {
|
|
|
|
case MenuConstants.openFolder:
|
|
|
|
await _openFolder(context);
|
|
|
|
break;
|
|
|
|
case MenuConstants.templateParser:
|
|
|
|
_openTemplateParser(context);
|
|
|
|
break;
|
|
|
|
case MenuConstants.exit:
|
|
|
|
_exitApplication();
|
|
|
|
break;
|
|
|
|
// 其他菜单项可以在这里添加处理逻辑
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> _openFolder(BuildContext context) async {
|
|
|
|
final fileProvider = Provider.of<FileProvider>(context, listen: false);
|
|
|
|
final String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
|
|
|
|
|
|
|
if (selectedDirectory != null) {
|
|
|
|
await fileProvider.loadDirectory(selectedDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _openTemplateParser(BuildContext context) {
|
|
|
|
Provider.of<EditorProvider>(context, listen: false).addTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _exitApplication() {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|