| 140 | } |
| 141 | |
| 142 | FileView::FileView(rect_t bounds, const char* path, void(*_OnFileOpened)(const char*, FileView*)) : Container(bounds) { |
| 143 | OnFileOpened = _OnFileOpened; |
| 144 | currentPath = path; |
| 145 | |
| 146 | fileList = new GridView({sidepanelWidth, 24, 0, 0}); |
| 147 | AddWidget(fileList); |
| 148 | fileList->SetLayout(LayoutSize::Stretch, LayoutSize::Stretch, WidgetAlignment::WAlignLeft); |
| 149 | |
| 150 | fileList->OnSubmit = OnListSubmit; |
| 151 | fileList->OnSelect = FileViewOnListSelect; |
| 152 | |
| 153 | pathBox = new TextBox({2, 2, 2, 20}, false); |
| 154 | AddWidget(pathBox); |
| 155 | pathBox->SetLayout(LayoutSize::Stretch, LayoutSize::Fixed, WidgetAlignment::WAlignLeft); |
| 156 | pathBox->OnSubmit = OnTextBoxSubmit; |
| 157 | |
| 158 | int sideBar = open("/", O_DIRECTORY); |
| 159 | int ypos = pathBox->GetFixedBounds().height + 20; |
| 160 | char str[NAME_MAX]; |
| 161 | int i = 0; |
| 162 | lemon_dirent_t dirent; |
| 163 | while(lemon_readdir(sideBar, i++, &dirent) > 0){ |
| 164 | int icon = 3; |
| 165 | |
| 166 | if(strcmp(dirent.name, "lib") == 0 || strcmp(dirent.name, "etc") == 0){ |
| 167 | continue; |
| 168 | } |
| 169 | |
| 170 | if(strncmp(dirent.name, "hd", 2) == 0 && dirent.name[2]){ // hd(x)? |
| 171 | snprintf(str, NAME_MAX, "Harddrive (%s)", dirent.name); |
| 172 | icon = 1; |
| 173 | } else if(strcmp(dirent.name, "system") == 0){ |
| 174 | strcpy(str, "System"); |
| 175 | icon = 0; |
| 176 | } else if(strcmp(dirent.name, "dev") == 0){ // dev? |
| 177 | snprintf(str, NAME_MAX, "Devices (%s)", dirent.name); |
| 178 | icon = 3; |
| 179 | } else if(strcmp(dirent.name, "initrd") == 0){ // initrd? |
| 180 | snprintf(str, NAME_MAX, "Ramdisk (%s)", dirent.name); |
| 181 | icon = 2; |
| 182 | } else sprintf(str, "%s", dirent.name); |
| 183 | strcat(dirent.name, "/"); |
| 184 | FileButton* fb = new FileButton(str, (rect_t){bounds.pos + (vector2i_t){2, ypos}, {sidepanelWidth - 4,20}}); |
| 185 | fb->file = dirent.name; |
| 186 | fb->icon = icon; |
| 187 | fb->OnPress = OnFileButtonPress; |
| 188 | |
| 189 | AddWidget(fb); |
| 190 | |
| 191 | ypos += 22; |
| 192 | } |
| 193 | close(sideBar); |
| 194 | |
| 195 | Refresh(); |
| 196 | } |
| 197 | |
| 198 | void FileView::Refresh(){ |
| 199 | char* rPath = realpath(currentPath.c_str(), nullptr); |
nothing calls this directly
no test coverage detected