-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code to order directories and files in filebrowser using qsort #89
base: master
Are you sure you want to change the base?
Conversation
================================== Add list processing functions to glui_filebrowser.cpp and glui.h to allow Filebrowser to process directory entries.
============================ Changes to glui_filebrowser.cpp and glui_list.cpp to correct bug.
========================================= The FileBrowser now sorts the file and directory names. There is also an option to filter the filenames. This version still contains many debug 'printf' statements. 1. glui.h New FileBrowser private variable 'list_filter' and public functions 'set filter' and 'filter_cstr' to set and read 'list filter'. 2. glui_filebrowser C function 'fnmatch' used to filter list of filenames using string 'list_filter'. See: http://pubs.opengroup.org/onlinepubs/009695399/functions/fnmatch.html C function 'qsort' used to sort filenames and directory names using criteria of new private function 'fb_list_compare'. If present this places './' first, '../' next followed by directories in order and then filtered files in order. 3. example6.cpp New variable 'fb_filter', plus EditText box to process filter. Callback 'filter_cb' sets 'list_filter' and calls 'fbreaddir' to reprocess directory.
Merge djw_1 with origin/master to ensure there are no new conflicts.
A number of small changes made as a result of compiler suggestions. These include: Remove unused variables. Comparison of singed and unsigned integers. Convert parameters for %p format to (void*).
Two initial thoughts:
|
Nigel,
Sorry - I am not an expert on this:
- Use std::list<>, perhaps
I am happy to make the change but what do I need to do?
- do all the whitespace cleanup seperately for clarity
I tend to modify whitespace as I go along - to make it easier for myself to
follow the code. Is there a way I can use git to revert just the whitespace?
Regards,
David.
|
@djwebb I managed to rebase this branch with respect to a seperate one that trimmed all the whitespace for the files of interest here. https://github.com/nigels-com/glui/tree/qsort Would you mind giving it a try to confirm that it's fully functional? |
On Thursday, 14 March 2019 11:19:15 GMT Nigel Stewart wrote:
@djwebb I managed to rebase this branch with respect to a seperate one that
trimmed all the whitespace for the files of interest here.
https://github.com/nigels-com/glui/tree/qsort
Would you mind giving it a try to confirm that it's fully functional?
Bit behind today. I'll try and get it checked over the weekend.
David.
|
My rebase wasn't quite right, but I pushed a fix. Fingers crossed. (Update: Build seems happy now, at least for Linux: https://travis-ci.org/nigels-com/glui/builds/506232858) |
On Thursday, 14 March 2019 11:19:15 GMT Nigel Stewart wrote:
@djwebb I managed to rebase this branch with respect to a seperate one that
trimmed all the whitespace for the files of interest here.
https://github.com/nigels-com/glui/tree/qsort
Would you mind giving it a try to confirm that it's fully functional?
I tool a new clone, checked out remotes/origin/qsort and compiled. The
compiler complained (see below) but otherwise compiled the glui library and
examples without problems.
I then compiled and tried my own main program with the FileBrowser routine.
Everything worked correctly.
Anyway - as far as I can tell the changes to glui are fully functional.
Please let me know once they are on the master branch.
Thanks,
David.
|
I forgot the compiler complaints:
quaternion.cpp: In function ‘quat operator*(const quat&, const quat&)’:
quaternion.cpp:117:55: warning: suggest parentheses around arithmetic
in operand of ‘^’ [-Wparentheses]
return quat( a.s*b.s - a.v*b.v, a.s*b.v + b.s*a.v + a.v^b.v );
glui_textbox.cpp:964:3: note: in expansion of macro ‘CLAMP’
CLAMP( insertion_pt, 0, text.length()); /* Make sure insertion_pt
^~~~~
glui_internal.h:104:66: warning: comparison between signed and unsigned
integer expressions [-Wsign-compare]
#define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) >
(hi)) {(x)=(hi);}}
Similar CLAMP errors at lines 966 and 968.
David
|
I will implement something like this. The correct way (other than a kind of linked bubble-sort) is to implement something like I've changed add_item so it can work with nodes derived from the item object, so a list is immensely more useful. EDITED: Or better, takes a generic node, and only the predicate knows it is an Item node. IOW, the predicate can be used with other kinds of Nodes also. |
Follow-up: Oops, sorry, I had it in my head this was just about implementing the missing Here is some (untested) code I just through together to do a sort. The sorting predicate is unspecified, but could be alphabetical, or give priority to directories. It's based on the buffering strategy of
|
The code was originally written for the previous version of glui. I have modified it to work with your latest version. The main changes are in files glui_filebrowser.cpp and include/GL/glui.h, but I have made a few other small changes to get rid of compiler warnings (unused variables, comparison of signed and unsigned int, etc.)
I have left a lot of debug print statements, these are turned off but you can switch them on (iprint=1). The unused variablee lines have been commented out but are still there.
If you want a version without the debug statements or the commented out lines let me know.
Regards,
David.