explorer: fixed (bool)path[0]
[ede] / explorer / src / FileListItem.ec
1 public import "ecere"
2
3 import "ExplorerTree"
4
5 public class FileListItem : struct
6 {
7    char * name;
8    char * info;
9    FileItemType type;
10    int indent;
11
12    void OnDisplay(Surface surface, int x, int y, int width, ExplorerListBox icons, Alignment alignment, DataDisplayFlags displayFlags)
13    {
14       int indentSize = (displayFlags.dropBox) ? 0 : 10;
15       int textOffset;
16       int len;
17       char label[MAX_FILENAME];
18
19       Bitmap icon = icons.icons[type].bitmap;
20       if(!icon)
21       {
22          if(type == folder || type == folderOpen)
23             surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
24          indentSize = 8;
25       }
26       textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
27       
28       if(info)
29          sprintf(label, "%s [%s]", name, info);
30       else
31          strcpy(label, name);
32       len = strlen(label);
33
34       surface.WriteTextDots
35          (alignment, x + textOffset, y + 2, width - textOffset, label, len);
36       if(icon)
37          surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
38    }
39
40    int OnCompare(FileListItem b)
41    {
42       int result;
43       if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
44          result = strcmpi(name, b.name);
45       else
46       {
47          if(type == folder && b.type < folder) result = -1;
48          else if(type < folder && b.type == folder) result = 1;
49       }
50       return result;
51    }
52
53    void OnCopy(FileListItem newData)
54    {
55       type = newData.type;
56       indent = newData.indent;
57       if(newData.name)
58       {
59          int len = strlen(newData.name) + 1;
60          name = new char[len];
61          CopyBytes(name, newData.name, len);
62       }
63    }
64
65    bool OnGetDataFromString(char * string)
66    {
67       int len = strlen(string) + 1;
68       name = new char[len];
69       CopyBytes(name, string, len);
70       return true;
71    }
72
73    void OnFree()
74    {
75       delete name;
76       delete info;
77    }
78
79    char * OnGetString(char * string, void * fieldData, bool * needClass)
80    {
81       return name;
82    }
83 };
84
85 FileListItem MakeFileListItem(const FileAttribs attribs, const char * name, const char * extension)
86 {
87    FileListItem fileListRow { };
88    fileListRow.name = CopyString(name);
89    if(attribs.isDirectory)
90    {
91       fileListRow.type = (attribs.isDrive) ? drive : folder;
92       if(attribs.isServer) fileListRow.type = server;
93       if(attribs.isShare) fileListRow.type = share;
94       if(attribs.isCDROM) fileListRow.type = cdrom;
95       if(attribs.isRemote) fileListRow.type = netDrive;
96       if(attribs.isRemovable) 
97       {
98          if(name[0] == 'A' || name[0] == 'B')
99             fileListRow.type = floppy;
100          else
101             fileListRow.type = removable;
102       }
103    }
104    else
105       fileListRow.type = FileItemType::SelectByExtension(extension);
106    return fileListRow;
107 }
108