Skip to content

Commit

Permalink
[explorer] Added new package v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeShkurko committed Mar 5, 2021
1 parent f1db583 commit 27bc235
Show file tree
Hide file tree
Showing 27 changed files with 1,284 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| [![pub package][native_pdf_renderer_badge]][native_pdf_renderer_pub] | [`packages/native_pdf_renderer`][native_pdf_renderer_code] |
| [![pub package][native_pdf_view_badge]][native_pdf_view_pub] | [`packages/native_pdf_view`][native_pdf_view_code] |
| [![pub package][epub_view_badge]][epub_view_pub] | [`packages/epub_view`][epub_view_code] |
| [![pub package][explorer_badge]][explorer_pub] | [`packages/explorer`][explorer_code] |

[auto_animated_pub]: https://pub.dev/packages/auto_animated
[auto_animated_code]: https://github.com/rbcprolabs/packages.flutter/tree/master/packages/auto_animated
Expand All @@ -31,3 +32,7 @@
[epub_view_pub]: https://pub.dev/packages/epub_view
[epub_view_code]: https://github.com/rbcprolabs/packages.flutter/tree/master/packages/epub_view
[epub_view_badge]: https://img.shields.io/pub/v/epub_view.svg

[explorer_pub]: https://pub.dev/packages/explorer
[explorer_code]: https://github.com/rbcprolabs/packages.flutter/tree/master/packages/explorer
[explorer_badge]: https://img.shields.io/pub/v/explorer.svg
74 changes: 74 additions & 0 deletions packages/explorer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
10 changes: 10 additions & 0 deletions packages/explorer/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 78910062997c3a836feee883712c241a5fd22983
channel: stable

project_type: package
13 changes: 13 additions & 0 deletions packages/explorer/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "explorer",
"request": "launch",
"type": "dart"
}
]
}
5 changes: 5 additions & 0 deletions packages/explorer/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"sqlite"
]
}
1 change: 1 addition & 0 deletions packages/explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## [1.0.0] - Initial release
21 changes: 21 additions & 0 deletions packages/explorer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Serge Shkurko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions packages/explorer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# explorer

Universal explorer UI for navigate files, ftp, etc

Support custom providers and any platforms

## Getting Started

In your flutter project add the dependency:

[![pub package](https://img.shields.io/pub/v/explorer.svg)](https://pub.dartlang.org/packages/explorer)

```yaml
dependencies:
flutter_color: any
```
## Examples
```dart
_controller = ExplorerController(
navigator: IoNavigatorExplorer(
entryPath: _server.serverDirectory,
),
uploadFiles: uploadFiles,
filePressed: (file) {
if (file.size > 200000) {
final snackBar =
SnackBar(content: Text('Can\'t open files with size > 200kb'));

// Find the Scaffold in the widget tree and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return;
}
if (file.extension.contains(RegExp(r'^(phar|dat)$'))) {
final snackBar = SnackBar(
content: Text('Can\'t open files with extensions: ' +
' phar|dat'));

// Find the Scaffold in the widget tree and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return;
}

Navigator.of(context).pushNamed(
EditorScreen.routeName,
arguments: EditorScreenArguments(property: file),
);
},
)

Explorer(
controller: _controller,
builder: (_) => [
ExplorerToolbar(translate: toolbarTranslate),
ExplorerActionView(translate: _actionTranslate),
ExplorerFilesGridView(translate: filesTranslate),
],
)
```
1 change: 1 addition & 0 deletions packages/explorer/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../../analysis_options.yaml
8 changes: 8 additions & 0 deletions packages/explorer/lib/explorer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library explorer;

export 'src/data/models/entry.dart';
export 'src/explorer.dart';
export 'src/ui/widgets/action.dart';
export 'src/ui/widgets/breadcrumbs.dart';
export 'src/ui/widgets/grid.dart';
export 'src/ui/widgets/toolbar.dart';
2 changes: 2 additions & 0 deletions packages/explorer/lib/explorer_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export './explorer.dart';
export 'src/io/navigator.dart';
141 changes: 141 additions & 0 deletions packages/explorer/lib/src/data/controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
part of '../explorer.dart';

class ExplorerController {
ExplorerController({
@required this.navigator,
this.filePressed,
this.uploadFiles,
});

final Future<List<Entry>> Function() uploadFiles;
final NavigatorExplorer navigator;
final void Function(ExplorerFile) filePressed;

// _ExplorerState _explorerState;
final StreamController<ExplorerState> _files =
StreamController<ExplorerState>.broadcast();
Stream<ExplorerState> get stream => _files.stream;

String get entryPath => navigator.entryPath;
String get currentPath => navigator.currentPath;

final StreamController<ExplorerAction> _actions =
StreamController<ExplorerAction>.broadcast();
Stream<ExplorerAction> get actionStream => _actions.stream;

void _attach(_ExplorerState _explorerState) {
assert(_explorerState != null);
// this._explorerState = _explorerState;
navigator.go(navigator.entryPath).then((entries) {
_files.add(ExplorerState(
path: navigator.currentPath,
entries: entries,
));
});
_actions.add(ExplorerActionEmpty());
}

void _detach() {
// _explorerState = null;
}

void dispose() {
_files?.close();
_actions?.close();
}

Future<void> uploadLocalFiles() async {
if (uploadFiles == null) {
return;
}

final entries = await uploadFiles();
for (final entry in entries) {
await copy(entry, Entry(path: p.join(currentPath, entry.name)));
}
return refresh();
}

void copyEntriesRequest(List<Entry> entries) {
_actions.add(ExplorerActionCopy(from: entries));
}

void copyEntriesConfirm(List<Entry> entries) async {
for (final entry in entries) {
await copy(entry, Entry(path: p.join(currentPath, entry.name)));
}
_actions.add(ExplorerActionEmpty());
return refresh();
}

void moveEntriesRequest(List<Entry> entries) {
_actions.add(ExplorerActionMove(from: entries));
}

void moveEntriesConfirm(List<Entry> entries) async {
for (final entry in entries) {
await copy(entry, Entry(path: p.join(currentPath, entry.name)));
await remove(entry);
}
_actions.add(ExplorerActionEmpty());
return refresh();
}

void cancelAction() {
_actions.add(ExplorerActionEmpty());
}

Future<void> copy(Entry from, Entry to) async => navigator.copy(from, to);

Future<void> goEntry(Entry entry) async {
if (entry is ExplorerDirectory) {
return go(entry.path);
} else {
filePressed(entry);
}
}

Future<void> go(String path) async {
final entries = await navigator.go(path);
_files.add(ExplorerState(
path: navigator.currentPath,
entries: entries,
));
}

Future<void> newDirectory(String name) async {
await navigator.newDirectory(name);
return refresh();
}

Future<void> newFile(String name) async {
await navigator.newFile(name);
return refresh();
}

Future<void> remove(Entry entry) async {
await navigator.remove(entry);
return refresh();
}

Future<void> refresh() => go(currentPath);

List<PathBreadCrumb> get breadCrumbs {
final names = currentPath.replaceFirst(entryPath, '').split('/')
..removeWhere((element) => element?.isEmpty);
final crumbs = <PathBreadCrumb>[
PathBreadCrumb(path: entryPath),
];

for (final name in names) {
final String path = (crumbs.isNotEmpty)
? p.join(crumbs.last.path, name)
: p.join(entryPath, name);
crumbs.add(PathBreadCrumb(
path: path,
));
}

return crumbs;
}
}
10 changes: 10 additions & 0 deletions packages/explorer/lib/src/data/models/bread_crumb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:path/path.dart' as p;

class PathBreadCrumb {
PathBreadCrumb({this.path}) : name = p.basename(path);

final String name, path;

@override
String toString() => '$runtimeType{name: $name, path: $path}';
}
Loading

0 comments on commit 27bc235

Please sign in to comment.