This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LDDestroier's profile picture

LDDFM - An API-based file manager for your programs!

Started by LDDestroier, 18 September 2016 - 11:53 PM
LDDestroier #1
Posted 19 September 2016 - 01:53 AM
Way back when I first coded Whisk (or heck, even back when I had to use other people's file transfer programs), I kinda found it cumbersome to remember the names of files and type them into a prompt to send it or whatever. I know, a nitpick…but no longer!

(by the way I am listening to some epic music; forgive my glamour)

LDDFM


The idea is that it can be easily snuck into your program code so you can have the user select a file/folder with a file manager instead of through a read() prompt. Makes it way better.
One cool thing this does it that the whole interface can be fit into a rectangle (x1,y1,x2,y2), so you can slip the thing into an existing GUI!

I made this primarily for Whisk, but this can be used anywhere.


pastebin get wfdb986Z lddfm
std PB wfdb986Z lddfm

HOW TO USE: (recommended)
SpoilerThere is only one function, so it's not too involved. Which is the point.

makeMenu(x1,y1,x2,y2, _path,_noFiles,_noFolders,_noCD,_noSelectFolders)

Let me explain.
  • x1 and y1: Numbers. These are the TOP LEFT coordinates of the file manager interface. Defaults to the top-left corner of the screen.
  • x2 and y2: Numbers. The same thing, but for the BOTTOM RIGHT coordinates. Defaults to the bottom-right corner of the screen.
  • _path: String. The directory that the file manager starts out in. Defaults to root. ("/")
  • _noFiles: Boolean. If true, will filter out all files from the list. I just added this feature just in case. Defaults to false, of course.
  • _noFolders: Boolean. Same thing, but filters out all folders instead. Again, if you need it. Also prevents you from selecting the current directory. Defaults to false.
  • _noCD: Boolean. If true, then you won't be able to change directories, as well as selecting the current directory. Defaults to false.
  • _noSelectFolders: Boolean. Pretty self-explanatory; if true, will prevent you from selecting any folders. You can still navigate them. Defaults to false.
  • _doHidden: Boolean. If true, will display hidden files and folders (starts with '.'). Defaults to false.
  • _p: Table. This is where you could add a custom table of colors. Look inside the code to see which table entries you have to change.
  • _canClose: Boolean. If true, a button labeled 'close' will be at the top-right part of the screen to click. Defaults to false.
It is impossible to have _noFiles and _noFolders true at once, so don't try.
If anything goes wrong, or if you click 'close', then it will return false instead of a string.

CONTROLS:
Use the mouse to select items on the menu.
Use LEFT/RIGHT CLICK to select files or navigate in folders.
Use MIDDLECLICK to return folders instead of going in them.
Use MOUSEWHEEL or UPARROW and DOWNARROW to scroll up and down.
Use PAGEUP or PAGEDOWN to go up and down exactly one page's worth.
Use HOME and END to go to the top and bottom, respectively.
Use ENTER to return the current directory.

makeMenu(insert arguments here) will return the path of the file/folder selected.

SCREENSHOTS:
Spoiler
This is when you don't enter any arguments into makeMenu(). White text is files, yellow is folders, and the scrollbar is on the right. The path is up on the top, by the way.



This is the same thing…but rendered between (4,3) and (28,16)! I made sure no text leaks out of it, so don't worry.

In another update, I might add a text prompt in addition to the file select GUI.
When putting this in a program, feel free to strip any blank newlines or comments. I added them for clarity, mostly.
Edited on 20 September 2016 - 05:01 PM
Lupus590 #2
Posted 19 September 2016 - 01:47 PM
does it work on non-advanced?
LDDestroier #3
Posted 19 September 2016 - 02:24 PM
does it work on non-advanced?

Afraid not. I bet I could just add an arrow-controlled cursor, but I'm currently working on getting the scrollbar to be dragable.
ReBraLaCC #4
Posted 19 September 2016 - 02:27 PM
could you also add a filter for hidden files?
LDDestroier #5
Posted 19 September 2016 - 02:28 PM
could you also add a filter for hidden files?

Sure, even though that's not particularly useful, CTRL+H will be the toggle for hidden files in the next update!!
DannySMc #6
Posted 19 September 2016 - 06:47 PM
I have been waiting for this!!

Completely love it, my only question, is if you can also have another parameter where we can give it a table of colours :P/> So an example:
local theme = {
["background_colour"] = "white";
["folder_colour"] = "blue";
["menu_colour"] = "red";
}

// ^ example

local path = makeMenu(3, 3, 40, 11, "/", _, _, _, _, theme
);

So we could have colours for path display at the top right, path text colour, background colour, file colour, folder colour etc???

Also can you add a little close button also please? This would be awesome! Top-right or something?
Sewbacca #7
Posted 19 September 2016 - 07:38 PM
I've don't seen the code, but I would love it, if i could give makeMenu a term object created by window.create (it would be usefull).
Sewbacca #8
Posted 19 September 2016 - 08:09 PM
Okay, it is really nice.
I just typed in lua:

local sPath = makeMenu()
while true do
  shell.run('edit', sPath)
  sPath = makeMenu(nil, nil, nil, nil, fs.getDir(sPath))
end

and i love it.
Nice work dude
=)
Sewbacca
Edited on 19 September 2016 - 06:10 PM
LDDestroier #9
Posted 20 September 2016 - 07:07 PM
An update! Woo!
  • A palate can now be specified in the makeMenu() arguments (file txt/bg, folder txt/bg, path txt/bg, close button txt/bg, scrollbar colors)
  • You can toggle hidden files/folders with CTRL+H (defaults to hidden)
  • You can add an argument (the twelfth one) to add a close button
  • Fixed minor graphical bugs
  • Made makeMenu(true) return all argument names
And I'm putting it on the STD store list.

…oh, and uh, I tried to make the scrollbar dragable, but I couldn't remember how to do it. Even though STD-GUI has that. Mhm.
Sewbacca #10
Posted 21 September 2016 - 10:36 PM
Sorry, but what is STD?
I hope that i didn't missed anything.

Sewbacca
LDDestroier #11
Posted 21 September 2016 - 10:51 PM
STD is a file downloader that was made before wget was a default command. It downloads from pastebin, hastebin, codepad, and most importantly, from a premade list of programs and their URLs. Basically, I take programs on the forums and add them to this list, which STD downloads.

It's kinda like apt-get, but with only one repository. STD-GUI is the GUI version that just downloads programs from that list. You can look at the forum post too. There's a link in my profile page.


…It means 'Super Text Downloader', if you were curious.
Edited on 14 October 2016 - 01:07 AM