Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 7b6f344

Browse files
committed
feat: update file list style
1 parent 50fef53 commit 7b6f344

File tree

3 files changed

+71
-25
lines changed

3 files changed

+71
-25
lines changed

app/assets/views/file.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
<ui>
44
<w class="container">
55
<h1 ref="header" class="v-file__header">Directory listing for /</h1>
6-
<w ref="body" class="v-file__body" />
6+
<hr />
7+
<w ref="body" class="v-file__body">
8+
<w class="c-file-list-header">
9+
<text class="c-file-list-item__name">Name</text>
10+
<text class="c-file-list-item__size">Size</text>
11+
<text class="c-file-list-item__date">Modified time</text>
12+
</w>
13+
</w>
714
</w>
815
</ui>
916
</lcui-app>

src/ui/stylesheets/views/_file.scss

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,20 @@
1919
display: inline-block;
2020
}
2121

22-
router-link.c-file-list-item__link {
23-
color: $primary;
24-
25-
&:hover {
26-
color: lighten($primary, 10);
27-
}
28-
&:active {
29-
color: darken($primary, 10);
30-
}
31-
}
32-
3322
.c-file-list-item__icon {
3423
margin-right: 5px;
3524
flex: 0 0 auto;
3625
}
3726

3827
.c-file-list-item__size {
3928
flex: 0 0 auto;
40-
width: 100px;
29+
width: 80px;
4130
}
4231

4332
.c-file-list-item__date {
4433
flex: 0 0 auto;
4534
text-align: right;
46-
width: 180px;
35+
width: 160px;
4736
}
4837

4938
.c-file-list-item {
@@ -52,6 +41,17 @@ router-link.c-file-list-item__link {
5241

5342
&:hover {
5443
background-color: rgba($primary, 0.05);
44+
45+
router-link.c-file-list-item__link {
46+
color: $primary;
47+
48+
&:hover {
49+
color: lighten($primary, 10);
50+
}
51+
&:active {
52+
color: darken($primary, 10);
53+
}
54+
}
5555
}
5656

5757
&.is-folder {
@@ -60,3 +60,12 @@ router-link.c-file-list-item__link {
6060
}
6161
}
6262
}
63+
64+
.c-file-list-header {
65+
display: flex;
66+
padding: 5px;
67+
68+
text {
69+
font-weight: bold;
70+
}
71+
}

src/ui/views/file.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
typedef struct FileViewTaskRec_ {
1515
wchar_t path[1024];
1616
LCUI_BOOL active;
17+
LCUI_BOOL has_error;
1718
LCUI_Widget folders;
1819
LCUI_Widget files;
20+
size_t count;
1921
} FileViewTaskRec, *FileViewTask;
2022

2123
typedef struct FileViewRec_ {
@@ -66,7 +68,7 @@ static LCUI_Widget CreateFileItem(const wchar_t *dirname,
6668
1023 - dirname_len, ENCODING_ANSI);
6769
path[dirname_len + len] = 0;
6870
if (stat(path, &file_stat) == 0) {
69-
strftime(date_str, 64, "%F %T", localtime(&file_stat.st_ctime));
71+
strftime(date_str, 64, "%F %T", localtime(&file_stat.st_mtime));
7072
TextView_SetText(date, date_str);
7173

7274
unit_i = 0;
@@ -94,6 +96,7 @@ static LCUI_Widget CreateFileItem(const wchar_t *dirname,
9496
}
9597
full_path[2047] = 0;
9698
Widget_SetAttribute(link, "to", full_path);
99+
Widget_AddClass(item, "is-folder");
97100
} else {
98101
Icon_SetName(icon, "file-outline");
99102
link = LCUIWidget_New("text");
@@ -115,17 +118,38 @@ static LCUI_Widget CreateFileItem(const wchar_t *dirname,
115118
return item;
116119
}
117120

118-
static void FileView_OnLinkFiles(void *arg1, void *arg2)
121+
static void FileView_OnLoadedFiles(void *arg1, void *arg2)
119122
{
123+
LCUI_Widget message;
124+
LCUI_WidgetEventRec e;
125+
120126
FileViewTask task = arg2;
121127
FileView self = Widget_GetData(arg1, file_proto);
122128

123129
if (task->active) {
124-
Widget_Append(self->body, task->folders);
125-
Widget_Append(self->body, task->files);
126-
Widget_Unwrap(task->folders);
127-
Widget_Unwrap(task->files);
130+
if (task->has_error) {
131+
message = LCUIWidget_New("text");
132+
TextView_SetTextW(message,
133+
L"[b][color=#f00]Error:[/color][/b] cannot "
134+
L"read the files in this directory.");
135+
Widget_Append(self->body->parent, message);
136+
} else if (task->count < 1) {
137+
message = LCUIWidget_New("text");
138+
TextView_SetTextW(message, L"This directory is empty.");
139+
Widget_Append(self->body->parent, message);
140+
} else {
141+
Widget_Append(self->body, task->folders);
142+
Widget_Append(self->body, task->files);
143+
Widget_Unwrap(task->folders);
144+
Widget_Unwrap(task->files);
145+
}
146+
LCUI_InitWidgetEvent(&e, "PageLoaded");
147+
Widget_TriggerEvent(arg1, &e, NULL);
148+
} else {
149+
Widget_Destroy(task->files);
150+
Widget_Destroy(task->folders);
128151
}
152+
self->task = NULL;
129153
free(task);
130154
}
131155

@@ -142,9 +166,11 @@ static void FileView_OnLoadFiles(void *arg1, void *arg2)
142166
free(t);
143167
return;
144168
}
145-
if (LCUI_OpenDirW(t->path, &dir) != 0) {
146-
return;
147-
}
169+
if (LCUI_OpenDirW(t->path, &dir) != 0) {
170+
t->has_error = TRUE;
171+
LCUI_PostSimpleTask(FileView_OnLoadedFiles, arg1, t);
172+
return;
173+
}
148174
t->folders = LCUIWidget_New(NULL);
149175
t->files = LCUIWidget_New(NULL);
150176
while ((entry = LCUI_ReadDirW(&dir))) {
@@ -157,6 +183,7 @@ static void FileView_OnLoadFiles(void *arg1, void *arg2)
157183
continue;
158184
}
159185
}
186+
t->count++;
160187
if (LCUI_FileIsDirectory(entry)) {
161188
Widget_Append(t->folders,
162189
CreateFileItem(t->path, name, TRUE));
@@ -170,7 +197,7 @@ static void FileView_OnLoadFiles(void *arg1, void *arg2)
170197
free(t);
171198
return;
172199
}
173-
LCUI_PostSimpleTask(FileView_OnLinkFiles, arg1, t);
200+
LCUI_PostSimpleTask(FileView_OnLoadedFiles, arg1, t);
174201
}
175202

176203
static void FileView_OnReady(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
@@ -201,14 +228,16 @@ static void FileView_OnReady(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
201228
router = router_get_by_name(name);
202229
route = router_get_current_route(router);
203230
self->task = malloc(sizeof(FileViewTaskRec));
231+
self->task->count = 0;
204232
self->task->active = TRUE;
233+
self->task->has_error = FALSE;
205234
self->header = Dict_FetchValue(refs, "header");
206235
self->body = Dict_FetchValue(refs, "body");
207236
path = router_route_get_param(route, "pathMatch");
208237
if (path) {
209238
LCUI_DecodeUTF8String(self->task->path, path, 1023);
210239
self->task->path[1023] = 0;
211-
swprintf(header_str, 1023, L"Directory listing for %s",
240+
swprintf(header_str, 1023, L"Directory listing for /%s",
212241
self->task->path);
213242
header_str[1023] = 0;
214243
} else {
@@ -217,6 +246,7 @@ static void FileView_OnReady(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
217246
wcscpy(header_str, L"Directory listing for /");
218247
}
219248
TextView_SetTextW(self->header, header_str);
249+
Widget_SetTitleW(w, header_str);
220250
task.arg[0] = w;
221251
task.arg[1] = self->task;
222252
task.destroy_arg[0] = NULL;

0 commit comments

Comments
 (0)