Skip to content

Commit

Permalink
Merge pull request #942 from w1th0utnam3/master
Browse files Browse the repository at this point in the history
Fix KDialog file open dialog and file filters
  • Loading branch information
philenius authored Jan 26, 2022
2 parents d9abfb7 + a473bbc commit 9c58307
Show file tree
Hide file tree
Showing 12 changed files with 611 additions and 269 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.3.3

#### Desktop (Linux)
Introduces two fixes for the KDE Plasma Linux implementation which uses `kdialog` to open the file picker dialogs. Firstly, the selection of multiple files is fixed so that file paths with blanks/spaces are handled correctly. Secondly, file type filters are implemented. Thank you @w1th0utnam3.

## 4.3.2

#### Desktop (Windows)
Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributing to File Picker

:+1: :tada: First off, thanks for taking the time to contribute to _File Picker_! :tada: :+1:

The following is a first version of guidelines for contributing to _File Picker_. Feel free to propose changes to this document in a pull request.

## Issue a Pull Request

* **Dart code only:** before creating a pull request, please **write unit tests** if you added changes to Dart code under `lib/` (Java/Objective-C code is currently not tested). Please ensure that the **code analysis** via `dart analyze` throws no errors. Please also make sure that your **code is formatted correctly** via `dart format`. You can take a look into our CI pipeline at `.github/workflows/main.yml` for further details. The CI pipeline is triggered automatically when you create a pull request on GitHub. All steps in our pipeline must run without errors.

* Please **update the package version** in `pubspec.yaml` and `CHANGELOG.md`. We use [semantic versionining (SemVer)](https://semver.org/). TL;DR: increase the patch version when your pull request contains a bug fix. Increase the minor version when a new feature is added. Breaking changes to _File Picker_'s public API should result in an increase in the major version.

* Please **update the changelog** in `CHANGELOG.md`. Add a new level two heading with the updated package version to the top of the document, e.g. `## major.minor.patch`. Below that, add another level four heading that notes the affected platform(s), e.g. `#### Desktop (Linux)` or `Android`, and describe your changes. If your pull request is associated to an issue, then please reference the issue. The changelog will be shown on https://pub.dev/packages/file_picker/changelog.
2 changes: 1 addition & 1 deletion lib/src/file_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';
import 'dart:io';

import 'package:file_picker/src/file_picker_io.dart';
import 'package:file_picker/src/file_picker_linux.dart';
import 'package:file_picker/src/file_picker_macos.dart';
import 'package:file_picker/src/file_picker_result.dart';
import 'package:file_picker/src/linux/file_picker_linux.dart';
import 'package:file_picker/src/windows/stub.dart'
if (dart.library.io) 'package:file_picker/src/windows/file_picker_windows.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
Expand Down
219 changes: 0 additions & 219 deletions lib/src/file_picker_linux.dart

This file was deleted.

42 changes: 42 additions & 0 deletions lib/src/linux/dialog_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:file_picker/file_picker.dart';
import 'package:file_picker/src/linux/kdialog_handler.dart';
import 'package:file_picker/src/linux/qarma_and_zenity_handler.dart';

abstract class DialogHandler {
factory DialogHandler(String pathToExecutable) {
pathToExecutable = pathToExecutable.toLowerCase();

if (pathToExecutable.endsWith('kdialog')) {
return KDialogHandler();
} else if (pathToExecutable.endsWith('qarma') ||
pathToExecutable.endsWith('zenity')) {
return QarmaAndZenityHandler();
}
throw UnimplementedError(
'DialogHandler for executable $pathToExecutable has not been implemented',
);
}

/// Generates the command line arguments to open a dialog with the respective
/// dialog tool (`kdialog`, `qarma`, or `zenity`).
List<String> generateCommandLineArguments(
String dialogTitle, {
String fileFilter = '',
String fileName = '',
bool multipleFiles = false,
bool pickDirectory = false,
bool saveFile = false,
});

/// Converts the specified combination of [type] and [allowedExtensions] into
/// the format required by the respective dialog tool (`kdialog`, `qarma`,
/// or `zenity`) to filter for specific file types.
///
/// [allowedExtensions] must only be used in combination with [type] equal to
/// [FileType.custom].
String fileTypeToFileFilter(FileType type, List<String>? allowedExtensions);

/// Converts the result string (stdout) of `qarma`, `zenity` or `kdialog`
/// into a [List<String>] of file paths.
List<String> resultStringToFilePaths(String fileSelectionResult);
}
Loading

0 comments on commit 9c58307

Please sign in to comment.