GithubHelp home page GithubHelp logo

olk90 / compose-filechooser Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 100 KB

Minimal application containing a file chooser for Compose

License: Apache License 2.0

Kotlin 100.00%
compose compose-for-desktop example kotlin

compose-filechooser's Introduction

compose-fileChooser

Minimal application containing a file chooser for Compose.

Overview

Main View

mainView.png

The main window consists of two text fields with trailing icons. Clicking the upper icon will open a file chooser with filters related to text files. The lower icon opens a directory chooser.

File Chooser

fileChooser.png

The file chooser will display all subdirectories and matching file types in the current directory. The text field in the upper part of the dialog displays the currently selected path. This text field can also be used to type in a path manually, the navigation of the list will follow automatically.

The top bar contains the following actions (from left to right):

  • Arrow Back: navigate to the current directory's parent
  • Plus: add new file or directory (depending on the FileChooserMode)
    • Button is enabled in all directories with writing access
    • If the entered parent folders do not exist, they are created
  • Trashcan: delete selected file
    • Button is enabled for all directories with writing access, accept the user's home directory
  • Home: Returning to user's home directory
  • Magnifying Glass: toggle invisible files and directories (with leading dot in their name)

In the bottom bar there are three options available:

  • selecting the file type (default should be All files (*.*))
  • applying the selection (check mark) will close the dialog and return to the main view
  • cancelling the selection will return to the main view without selecting the path.

Directory Chooser

directoryChooser.png

The directory chooser works in a similar fashion as the file chooser, accept for the missing file filter.

How to use

This code snippet is derived from Main.kt. To open a file chooser, simply define a MutableState<Booelean> and set it true (by clicking a button, etc.).

@Composable
fun App() { 

    val isFileChooserOpen = remember { mutableStateOf(false) }
    val filePath = remember { mutableStateOf("") }
    val directoryPath = remember { mutableStateOf("") }

    // [...]
  
    if (isFileChooserOpen.value) {
        FileChooser(
          isFileChooserOpen, // switched to false after terminal operations to close the dialog
          filePath, // stores the currently selected path. If empty, the user's home directory is used
          textFiles, // list of FileExtensionFilters (only relevant in FileChooserMode.FILE
          FileChooserMode.FILE // displays also files, if set to FileChooserMode.DIRECTORY, only directories are shown in the results
        )
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.