Skip to content

Commit eefc771

Browse files
committed
[ADD] : add a define for have places pane shown by default
[ADD] : add a param for have place group opened by default or not
1 parent c908c28 commit eefc771

3 files changed

Lines changed: 126 additions & 112 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ inline bool inRadioButton(const char* vLabel, bool vToggled) {
354354
#ifndef editPlaceButtonString
355355
#define editPlaceButtonString "E"
356356
#endif // editPlaceButtonString
357+
#ifndef PLACES_PANE_DEFAULT_SHOWN
358+
#define PLACES_PANE_DEFAULT_SHOWN false
359+
#endif // PLACES_PANE_DEFAULT_SHOWN
357360
#ifndef IMGUI_TOGGLE_BUTTON
358361
inline bool inToggleButton(const char* vLabel, bool* vToggled) {
359362
bool pressed = false;
@@ -2985,6 +2988,7 @@ void IGFD::ThumbnailFeature::ManageGPUThumbnails() {
29852988
IGFD::PlacesFeature::PlacesFeature() {
29862989
#ifdef USE_PLACES_FEATURE
29872990
m_PlacesPaneWidth = defaultPlacePaneWith;
2991+
m_PlacesPaneShown = PLACES_PANE_DEFAULT_SHOWN;
29882992
#endif // USE_PLACES_FEATURE
29892993
}
29902994

@@ -3017,7 +3021,7 @@ bool IGFD::PlacesFeature::m_DrawPlacesPane(FileDialogInternal& vFileDialogIntern
30173021
for (const auto& group : m_OrderedGroups) {
30183022
auto group_ptr = group.second.lock();
30193023
if (group_ptr != nullptr) {
3020-
if (ImGui::CollapsingHeader(group_ptr->name.c_str())) {
3024+
if (ImGui::CollapsingHeader(group_ptr->name.c_str(), group_ptr->collapsingHeaderFlag)) {
30213025
ImGui::BeginChild(group_ptr->name.c_str(), ImVec2(0, 0), ImGuiChildFlags_AutoResizeY);
30223026
if (group_ptr->canBeEdited) {
30233027
ImGui::PushID(group_ptr.get());
@@ -3143,13 +3147,17 @@ void IGFD::PlacesFeature::DeserializePlaces(const std::string& vPlaces) {
31433147
}
31443148
}
31453149

3146-
bool IGFD::PlacesFeature::AddPlacesGroup(const std::string& vGroupName, const size_t& vDisplayOrder, const bool& vCanBeEdited) {
3150+
bool IGFD::PlacesFeature::AddPlacesGroup(const std::string& vGroupName, const size_t& vDisplayOrder, const bool& vCanBeEdited, const bool& vOpenedByDefault) {
31473151
if (vGroupName.empty()) {
31483152
return false;
31493153
}
31503154
auto group_ptr = std::make_shared<GroupStruct>();
31513155
group_ptr->displayOrder = vDisplayOrder;
31523156
group_ptr->name = vGroupName;
3157+
group_ptr->defaultOpened = vOpenedByDefault;
3158+
if (group_ptr->defaultOpened) {
3159+
group_ptr->collapsingHeaderFlag = ImGuiTreeNodeFlags_DefaultOpen;
3160+
}
31533161
group_ptr->canBeSaved = group_ptr->canBeEdited = vCanBeEdited; // can be user edited mean can be saved
31543162
m_Groups[vGroupName] = group_ptr;
31553163
m_OrderedGroups[group_ptr->displayOrder] = group_ptr; // an exisitng display order will be overwrote for code simplicity

ImGuiFileDialog.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,22 +2052,24 @@ class IGFD_API PlacesFeature {
20522052
};
20532053

20542054
struct GroupStruct {
2055-
bool canBeSaved = false; // defined by code, can be used for prevent serialization / deserialization
2056-
size_t displayOrder = 0U; // the display order will be usedf first, then alphanumeric
2057-
std::string name; // the group name, will be displayed
2058-
std::vector<PlaceStruct> places; // the places (name + path)
2059-
bool canBeEdited = false; // will show +/- button for add/remove place in the group
2060-
char editBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // temp buffer for name edition
2055+
bool canBeSaved = false; // defined by code, can be used for prevent serialization / deserialization
2056+
size_t displayOrder = 0U; // the display order will be usedf first, then alphanumeric
2057+
bool defaultOpened = false; // the group is opened by default
2058+
bool canBeEdited = false; // will show +/- button for add/remove place in the group
2059+
char editBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // temp buffer for name edition
20612060
int32_t selectedPlaceForEdition = -1;
2062-
ImGuiListClipper clipper; // the list clipper of the grou
2063-
bool AddPlace( // add a place by code
2064-
const std::string& vPlaceName, // place name
2065-
const std::string& vPlacePath, // place path
2066-
const bool& vCanBeSaved, // prevent serialization
2067-
const FileStyle& vStyle = {}); // style
2061+
ImGuiTreeNodeFlags collapsingHeaderFlag = ImGuiTreeNodeFlags_None;
2062+
ImGuiListClipper clipper; // the list clipper of the grou
2063+
std::string name; // the group name, will be displayed
2064+
std::vector<PlaceStruct> places; // the places (name + path)
2065+
bool AddPlace( // add a place by code
2066+
const std::string& vPlaceName, // place name
2067+
const std::string& vPlacePath, // place path
2068+
const bool& vCanBeSaved, // prevent serialization
2069+
const FileStyle& vStyle = {}); // style
20682070
void AddPlaceSeparator(const float& vThickness = 1.0f);
2069-
bool RemovePlace( // remove a place by code, return true if succeed
2070-
const std::string& vPlaceName); // place name to remove
2071+
bool RemovePlace( // remove a place by code, return true if succeed
2072+
const std::string& vPlaceName); // place name to remove
20712073
};
20722074

20732075
private:
@@ -2085,13 +2087,14 @@ class IGFD_API PlacesFeature {
20852087

20862088
public:
20872089
std::string SerializePlaces( // serialize place : return place buffer to save in a file
2088-
const bool& vForceSerialisationForAll = true); // for avoid serialization of places with flag canBeSaved to false
2090+
const bool& vForceSerialisationForAll = true); // for avoid serialization of places with flag 'canBeSaved to false'
20892091
void DeserializePlaces( // deserialize place : load place buffer to load in the dialog (saved from
20902092
const std::string& vPlaces); // previous use with SerializePlaces()) place buffer to load
20912093
bool AddPlacesGroup( // add a group
20922094
const std::string& vGroupName, // the group name
20932095
const size_t& vDisplayOrder, // the display roder of the group
2094-
const bool& vCanBeEdited); // let the user add/remove place in the group
2096+
const bool& vCanBeEdited = false, // let the user add/remove place in the group
2097+
const bool& vOpenedByDefault = true); // hte group is opened by default
20952098
bool RemovePlacesGroup(const std::string& vGroupName); // remove the group
20962099
GroupStruct* GetPlacesGroupPtr(const std::string& vGroupName); // get the group, if not existed, will be created
20972100
#endif // USE_PLACES_FEATURE

ImGuiFileDialogConfig.h

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -9,138 +9,141 @@
99
// this options need c++17
1010
// #define USE_STD_FILESYSTEM
1111

12-
//#define MAX_FILE_DIALOG_NAME_BUFFER 1024
13-
//#define MAX_PATH_BUFFER_SIZE 1024
12+
// #define MAX_FILE_DIALOG_NAME_BUFFER 1024
13+
// #define MAX_PATH_BUFFER_SIZE 1024
1414

1515
// the slash's buttons in path cna be used for quick select parallles directories
16-
//#define USE_QUICK_PATH_SELECT
16+
// #define USE_QUICK_PATH_SELECT
1717

18-
// the spacing between button path's can be customized.
18+
// the spacing between button path's can be customized.
1919
// if disabled the spacing is defined by the imgui theme
20-
// define the space between path buttons
21-
//#define CUSTOM_PATH_SPACING 2
22-
23-
//#define USE_THUMBNAILS
24-
//the thumbnail generation use the stb_image and stb_resize lib who need to define the implementation
25-
//btw if you already use them in your app, you can have compiler error due to "implemntation found in double"
26-
//so uncomment these line for prevent the creation of implementation of these libs again
27-
//#define DONT_DEFINE_AGAIN__STB_IMAGE_IMPLEMENTATION
28-
//#define DONT_DEFINE_AGAIN__STB_IMAGE_RESIZE_IMPLEMENTATION
29-
//#define IMGUI_RADIO_BUTTON RadioButton
30-
//#define DisplayMode_ThumbailsList_ImageHeight 32.0f
31-
//#define tableHeaderFileThumbnailsString "Thumbnails"
32-
//#define DisplayMode_FilesList_ButtonString "FL"
33-
//#define DisplayMode_FilesList_ButtonHelp "File List"
34-
//#define DisplayMode_ThumbailsList_ButtonString "TL"
35-
//#define DisplayMode_ThumbailsList_ButtonHelp "Thumbnails List"
20+
// define the space between path buttons
21+
// #define CUSTOM_PATH_SPACING 2
22+
23+
// #define USE_THUMBNAILS
24+
// the thumbnail generation use the stb_image and stb_resize lib who need to define the implementation
25+
// btw if you already use them in your app, you can have compiler error due to "implemntation found in double"
26+
// so uncomment these line for prevent the creation of implementation of these libs again
27+
// #define DONT_DEFINE_AGAIN__STB_IMAGE_IMPLEMENTATION
28+
// #define DONT_DEFINE_AGAIN__STB_IMAGE_RESIZE_IMPLEMENTATION
29+
// #define IMGUI_RADIO_BUTTON RadioButton
30+
// #define DisplayMode_ThumbailsList_ImageHeight 32.0f
31+
// #define tableHeaderFileThumbnailsString "Thumbnails"
32+
// #define DisplayMode_FilesList_ButtonString "FL"
33+
// #define DisplayMode_FilesList_ButtonHelp "File List"
34+
// #define DisplayMode_ThumbailsList_ButtonString "TL"
35+
// #define DisplayMode_ThumbailsList_ButtonHelp "Thumbnails List"
3636
// todo
37-
//#define DisplayMode_ThumbailsGrid_ButtonString "TG"
38-
//#define DisplayMode_ThumbailsGrid_ButtonHelp "Thumbnails Grid"
37+
// #define DisplayMode_ThumbailsGrid_ButtonString "TG"
38+
// #define DisplayMode_ThumbailsGrid_ButtonHelp "Thumbnails Grid"
3939

40-
//#define USE_EXPLORATION_BY_KEYS
40+
// #define USE_EXPLORATION_BY_KEYS
4141
// this mapping by default is for GLFW but you can use another
42-
//#include <GLFW/glfw3.h>
42+
// #include <GLFW/glfw3.h>
4343
// Up key for explore to the top
44-
//#define IGFD_KEY_UP ImGuiKey_UpArrow
44+
// #define IGFD_KEY_UP ImGuiKey_UpArrow
4545
// Down key for explore to the bottom
46-
//#define IGFD_KEY_DOWN ImGuiKey_DownArrow
46+
// #define IGFD_KEY_DOWN ImGuiKey_DownArrow
4747
// Enter key for open directory
48-
//#define IGFD_KEY_ENTER ImGuiKey_Enter
48+
// #define IGFD_KEY_ENTER ImGuiKey_Enter
4949
// BackSpace for comming back to the last directory
50-
//#define IGFD_KEY_BACKSPACE ImGuiKey_Backspace
50+
// #define IGFD_KEY_BACKSPACE ImGuiKey_Backspace
5151

5252
// by ex you can quit the dialog by pressing the key excape
53-
//#define USE_DIALOG_EXIT_WITH_KEY
54-
//#define IGFD_EXIT_KEY ImGuiKey_Escape
53+
// #define USE_DIALOG_EXIT_WITH_KEY
54+
// #define IGFD_EXIT_KEY ImGuiKey_Escape
5555

5656
// widget
5757
// begin combo widget
58-
//#define IMGUI_BEGIN_COMBO ImGui::BeginCombo
58+
// #define IMGUI_BEGIN_COMBO ImGui::BeginCombo
5959
// when auto resized, FILTER_COMBO_MIN_WIDTH will be considered has minimum width
6060
// FILTER_COMBO_AUTO_SIZE is enabled by default now to 1
6161
// uncomment if you want disable
62-
//#define FILTER_COMBO_AUTO_SIZE 0
62+
// #define FILTER_COMBO_AUTO_SIZE 0
6363
// filter combobox width
64-
//#define FILTER_COMBO_MIN_WIDTH 120.0f
64+
// #define FILTER_COMBO_MIN_WIDTH 120.0f
6565
// button widget use for compose path
66-
//#define IMGUI_PATH_BUTTON ImGui::Button
66+
// #define IMGUI_PATH_BUTTON ImGui::Button
6767
// standard button
68-
//#define IMGUI_BUTTON ImGui::Button
68+
// #define IMGUI_BUTTON ImGui::Button
6969

7070
// locales string
71-
//#define createDirButtonString "+"
72-
//#define resetButtonString "R"
73-
//#define drivesButtonString "Drives"
74-
//#define editPathButtonString "E"
75-
//#define searchString "Search"
76-
//#define dirEntryString "[DIR] "
77-
//#define linkEntryString "[LINK] "
78-
//#define fileEntryString "[FILE] "
79-
//#define fileNameString "File Name : "
80-
//#define dirNameString "Directory Path :"
81-
//#define buttonResetSearchString "Reset search"
82-
//#define buttonDriveString "Drives"
83-
//#define buttonEditPathString "Edit path\nYou can also right click on path buttons"
84-
//#define buttonResetPathString "Reset to current directory"
85-
//#define buttonCreateDirString "Create Directory"
86-
//#define OverWriteDialogTitleString "The file Already Exist !"
87-
//#define OverWriteDialogMessageString "Would you like to OverWrite it ?"
88-
//#define OverWriteDialogConfirmButtonString "Confirm"
89-
//#define OverWriteDialogCancelButtonString "Cancel"
90-
91-
//Validation buttons
92-
//#define okButtonString " OK"
93-
//#define okButtonWidth 0.0f
94-
//#define cancelButtonString " Cancel"
95-
//#define cancelButtonWidth 0.0f
96-
//alignement [0:1], 0.0 is left, 0.5 middle, 1.0 right, and other ratios
97-
//#define okCancelButtonAlignement 0.0f
98-
//#define invertOkAndCancelButtons 0
71+
// #define createDirButtonString "+"
72+
// #define resetButtonString "R"
73+
// #define drivesButtonString "Drives"
74+
// #define editPathButtonString "E"
75+
// #define searchString "Search"
76+
// #define dirEntryString "[DIR] "
77+
// #define linkEntryString "[LINK] "
78+
// #define fileEntryString "[FILE] "
79+
// #define fileNameString "File Name : "
80+
// #define dirNameString "Directory Path :"
81+
// #define buttonResetSearchString "Reset search"
82+
// #define buttonDriveString "Drives"
83+
// #define buttonEditPathString "Edit path\nYou can also right click on path buttons"
84+
// #define buttonResetPathString "Reset to current directory"
85+
// #define buttonCreateDirString "Create Directory"
86+
// #define OverWriteDialogTitleString "The file Already Exist !"
87+
// #define OverWriteDialogMessageString "Would you like to OverWrite it ?"
88+
// #define OverWriteDialogConfirmButtonString "Confirm"
89+
// #define OverWriteDialogCancelButtonString "Cancel"
90+
91+
// Validation buttons
92+
// #define okButtonString " OK"
93+
// #define okButtonWidth 0.0f
94+
// #define cancelButtonString " Cancel"
95+
// #define cancelButtonWidth 0.0f
96+
// alignement [0:1], 0.0 is left, 0.5 middle, 1.0 right, and other ratios
97+
// #define okCancelButtonAlignement 0.0f
98+
// #define invertOkAndCancelButtons 0
9999

100100
// DateTimeFormat
101101
// see strftime functionin <ctime> for customize
102102
// "%Y/%m/%d %H:%M" give 2021:01:22 11:47
103103
// "%Y/%m/%d %i:%M%p" give 2021:01:22 11:45PM
104-
//#define DateTimeFormat "%Y/%m/%d %i:%M%p"
104+
// #define DateTimeFormat "%Y/%m/%d %i:%M%p"
105105

106106
// theses icons will appear in table headers
107-
//#define USE_CUSTOM_SORTING_ICON
108-
//#define tableHeaderAscendingIcon "A|"
109-
//#define tableHeaderDescendingIcon "D|"
110-
//#define tableHeaderFileNameString " File name"
111-
//#define tableHeaderFileTypeString " Type"
112-
//#define tableHeaderFileSizeString " Size"
113-
//#define tableHeaderFileDateTimeString " Date"
114-
//#define fileSizeBytes "o"
115-
//#define fileSizeKiloBytes "Ko"
116-
//#define fileSizeMegaBytes "Mo"
117-
//#define fileSizeGigaBytes "Go"
107+
// #define USE_CUSTOM_SORTING_ICON
108+
// #define tableHeaderAscendingIcon "A|"
109+
// #define tableHeaderDescendingIcon "D|"
110+
// #define tableHeaderFileNameString " File name"
111+
// #define tableHeaderFileTypeString " Type"
112+
// #define tableHeaderFileSizeString " Size"
113+
// #define tableHeaderFileDateTimeString " Date"
114+
// #define fileSizeBytes "o"
115+
// #define fileSizeKiloBytes "Ko"
116+
// #define fileSizeMegaBytes "Mo"
117+
// #define fileSizeGigaBytes "Go"
118118

119119
// default table sort field (must be FIELD_FILENAME, FIELD_TYPE, FIELD_SIZE, FIELD_DATE or FIELD_THUMBNAILS)
120-
//#define defaultSortField FIELD_FILENAME
120+
// #define defaultSortField FIELD_FILENAME
121121

122122
// default table sort order for each field (true => Descending, false => Ascending)
123-
//#define defaultSortOrderFilename true
124-
//#define defaultSortOrderType true
125-
//#define defaultSortOrderSize true
126-
//#define defaultSortOrderDate true
127-
//#define defaultSortOrderThumbnails true
128-
129-
//#define USE_PLACES_FEATURE
130-
//#define placesPaneWith 150.0f
131-
//#define IMGUI_TOGGLE_BUTTON ToggleButton
132-
//#define placesButtonString "Place"
133-
//#define placesButtonHelpString "Places"
134-
//#define addPlaceButtonString "+"
135-
//#define removePlaceButtonString "-"
123+
// #define defaultSortOrderFilename true
124+
// #define defaultSortOrderType true
125+
// #define defaultSortOrderSize true
126+
// #define defaultSortOrderDate true
127+
// #define defaultSortOrderThumbnails true
128+
129+
// #define USE_PLACES_FEATURE
130+
// #define PLACES_PANE_DEFAULT_SHOWN false
131+
// #define placesPaneWith 150.0f
132+
// #define IMGUI_TOGGLE_BUTTON ToggleButton
133+
// #define placesButtonString "Place"
134+
// #define placesButtonHelpString "Places"
135+
// #define addPlaceButtonString "+"
136+
// #define removePlaceButtonString "-"
137+
// #define validatePlaceButtonString "ok"
138+
// #define editPlaceButtonString "E"
136139

137140
// a group for bookmarks will be added by default, but you can also create it yourself and many more
138141
// #define USE_PLACES_BOOKMARKS
139-
// #define PLACE_BOOKMARKS_NAME "Bookmarks"
140-
// #define PLACE_BOOKMARKS_DISPLAY_ORDER 0 // to the first
142+
// #define placesBookmarksGroupName "Bookmarks"
143+
// #define placesBookmarksDisplayOrder 0 // to the first
141144

142145
// a group for system devices (returned by IFileSystem), but you can also add yours
146+
// by ex if you would like to display a specific icon for some devices
143147
// #define USE_PLACES_DEVICES
144-
// #define PLACE_DEVICES_NAME "Devices"
145-
// #define PLACE_DEVICES_DISPLAY_ORDER 10 // to the end
146-
// #define PLACE_DEVICES_ICON ""
148+
// #define placesDevicesGroupName "Devices"
149+
// #define placesDevicesDisplayOrder 10 // to the end

0 commit comments

Comments
 (0)