Skip to content

Repository files navigation

FileTree: A Powerful File Explorer Library for IDEs and Code Editors.

This documentation guides you on how to integrate and use the FileTree library within your IDEs and Code Editors to provide a user-friendly and efficient file browsing experience.

Important

This Project is deprecated and no longer maintained in favor of Orbit-VFMS.

Table of Contents:

1. Introduction

2. Integration

◦ 2.1. Dependencies

◦ 2.2. Initialization and Loading

◦ 2.3. UI Integration

◦ 2.4. Event Handling

3. File Operations

4. Customizing Icons

5. AttributeSet

6. Asynchronous File System

7. Example (Android View-Based)

8. License.

1. Introduction

The FileTree library offers a comprehensive and modular solution for managing and displaying file trees within IDEs and code editors. It is designed to provide the following key features:

  • Hierarchical File Tree Representation: Displays files and folders in an organized hierarchical tree structure.

  • Hover-Navigated Directory: Highlights directories as users navigate through them with clicks. This feature enhances user experience by visually indicating the current directory, offering a clear and interactive method for exploring the directory tree.

  • Lazy Loading: Improves loading time by loading child nodes only when they are expanded.

  • Asynchronous File System: Executes file operations like expanding, collapsing, and loading files in the FileTree on a background thread, preventing the Main UI Thread from being blocked.

  • Customizable Icons: Enables the use of custom icons for files and folders.

  • Concurrent FileMap: Maintains a record of recently accessed files and directories, facilitating quick access to previously expanded files and directories.

  • RecyclerItemView: Utilizes the built-in RecycledViewPool of RecyclerView to reuse old views, reducing memory usage by avoiding the creation of new views.

Overview

2. Integration

2.1. Dependencies

First, add the FileTree library as a dependency to your project using a build system like Maven or Gradle:

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Zyron-Official:FileTree:Version'
}

The specific instructions for adding a dependency will depend on your IDE and build system.

2.2. Initialization and Loading

1. Initialize: Initialize FileTree, providing the root directory:

fileTreeView.initializeFileTree(this, "/storage/emulated/0")

2.3. UI Integration

This step involves integrating the FileTree Library within your project, here's a basic example using Android Views:

  • Android View-Based (Android/Kotlin/Java): Define FileTreeView in your Layout (XML) to display your FileTree data.

    Docs Getting Sarted

2.4. Event Handling

The FileTree library provides events that you can use to react to user actions within the file tree:

Handle these events in your IDE's logic to perform actions like opening files, displaying properties, or refreshing UI elements.

3. File Operations

The FileTree library provides Event Listeners for performing common file system operations by using FileTreeEventListener Interface.

importcom.zyron.filetree.events.FileTreeEventListenerimportjava.io.FileclassFileOperationExecutor(privatevalcontext:Context) : FileTreeEventListener {
overridefunonFileClick(file:File) {
Toast.makeText(context, "File clicked: ${file.name}", Toast.LENGTH_SHORT).show()
}
overridefunonFolderClick(folder:File) {
Toast.makeText(context, "Folder clicked: ${folder.name}", Toast.LENGTH_SHORT).show()
}
overridefunonFileLongClick(file:File): Boolean {
Toast.makeText(context, "File long-clicked: ${file.name}", Toast.LENGTH_SHORT).show()
returntrue
}
overridefunonFolderLongClick(folder:File): Boolean {
Toast.makeText(context, "Folder long-clicked: ${folder.name}", Toast.LENGTH_SHORT).show()
returntrue
}
}

4. Customizing Icons

The FileTree library allows you to specify custom icons for files and folders.

Here's a basic example to customize icons

importcom.zyron.filetree.provider.FileTreeIconProviderimportjava.io.FileclassFileIconProvider : FileTreeIconProvider {
overridefungetChevronIcon(): Int {
returnR.drawable.ic_chevron
}
overridefungetDefaultFolderIcon(): Int {
returnR.drawable.ic_folder
}
overridefungetDefaultFileIcon(): Int {
returnR.drawable.ic_file
}
overridefungetIconForFolder(folder:File): Int {
returnwhen (folder.name) {
"app"->R.drawable.ic_folder_app
"src"->R.drawable.ic_folder_src
"kotlin"->R.drawable.ic_folder_kotlin
"java"->R.drawable.ic_folder_java
"res"->R.drawable.ic_folder_res
else-> getDefaultFolderIcon()
}
}
overridefungetIconForFile(file:File): Int {
returnwhen (file.name) {
"gradlew.bat"->R.drawable.ic_gradlewbat
"gradlew"->R.drawable.ic_gradlew
"settings.gradle"->R.drawable.ic_gradle_settings
"build.gradle"->R.drawable.ic_gradle_build
"gradle.properties"->R.drawable.ic_gradle_properties
else-> getIconForExtension(file.extension)
}
}
overridefungetIconForExtension(extension:String): Int {
returnwhen (extension) {
"xml"->R.drawable.ic_xml
"java"->R.drawable.ic_java
"kt"->R.drawable.ic_kotlin
else-> getDefaultFileIcon()
}
}
}

5. AttributeSet

Attribute NameDescriptionDefault ValueXML AttributeType
recyclerItemViewCountDefines the maximum number of items the RecyclerView can hold in its recycled view pool.200app:recyclerItemViewCountInteger
recyclerItemViewEnabledEnables or disables the use of a recycled view pool for the RecyclerView.trueapp:recyclerItemViewEnabledBoolean
itemViewCacheSizeSets the maximum size for the view cache in the RecyclerView.100app:itemViewCacheSizeInteger
itemViewCachingEnabledEnables or disables caching of item views in the RecyclerView.trueapp:itemViewCachingEnabledBoolean
fileMapMaxSizeSpecifies the maximum number of entries in the file map, which caches recently accessed files and directories.150app:fileMapMaxSizeInteger
fileMapEnabledEnables or disables the file map functionality.trueapp:fileMapEnabledBoolean
fileTreeAnimationSets the animation style for expanding and collapsing the file tree.4app:fileTreeAnimationInteger
fileTreeAnimationEnabledEnables or disables animations for the file tree.trueapp:fileTreeAnimationEnabledBoolean

Usage Example

To configure these attributes in your XML layout file, use the following syntax:

<com.zyron.filetree.widget.FileTreeView
android:layout_width="match_parent"android:layout_height="match_parent"app:recyclerItemViewCount="250"app:recyclerItemViewEnabled="true"app:itemViewCacheSize="120"app:itemViewCachingEnabled="true"app:fileMapMaxSize="180"app:fileMapEnabled="true"app:fileTreeAnimation="FallDown"app:fileTreeAnimationEnabled="false"/>

Adjust these values according to your application's needs to optimize performance and user experience.

6. Asynchronous File System

The FileTree library typically uses a built-in asynchronous system powered by Kotlin Coroutines to perform core file functions such as expanding, collapsing and loading files in FileTree on the background thread. This ensures that the UI thread remains responsive while the functions are executed.

7. Example (Android view-based)

Here's a basic example of using the FileTree library with Android views:

Define FileTreeView in Layout (XML)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical">
<com.zyron.filetree.widget.FileTreeView
android:id="@+id/file_tree_view"android:layout_width="match_parent"android:layout_height="match_parent" />
</LinearLayout>

Setup FileTree in Activity or Fragment (Kotlin)

importandroidx.appcompat.app.AppCompatActivityimportcom.zyron.filetree.widget.FileTreeViewimportcom.zyron.filetree.resources.FileIconProviderimportcom.zyron.filetree.operationexecutor.FileOperationExecutorimportjava.io.FileclassMainActivity : AppCompatActivity() {
val fileTreeView:FileTreeView= findViewById(R.id.file_tree_view)
val fileIconProvider =FileIconProvider()
val fileOperationExecutor =FileOperationExecutor(requireContext())
fileTreeView.initializeFileTree("/storage/emulated/0", fileOperationExecutor, fileIconProvider, this)
}

8. License

Copyright 2024 Zyron, Official.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.