comparison postdog/main.c @ 117:b91f2dd6f84d

[PostDog] Fixed delete logic.
author June Park <parkjune1995@gmail.com>
date Wed, 07 Jan 2026 05:02:45 -0800
parents 7bd795bac997
children 249881ceff7b
comparison
equal deleted inserted replaced
116:7bd795bac997 117:b91f2dd6f84d
46 46
47 typedef struct { 47 typedef struct {
48 char *filename; 48 char *filename;
49 Rectangle rect; 49 Rectangle rect;
50 long time_modified; 50 long time_modified;
51 boolean deleted;
51 } HistoryItem; 52 } HistoryItem;
52 53
53 typedef struct { 54 typedef struct {
54 Rectangle rectangle; 55 Rectangle rectangle;
55 char *label; 56 char *label;
88 printf("Directory is empty or cannot be read.\n"); 89 printf("Directory is empty or cannot be read.\n");
89 } else { 90 } else {
90 do { 91 do {
91 HistoryItem item = {0}; 92 HistoryItem item = {0};
92 item.filename = strdup(fileinfo.name); 93 item.filename = strdup(fileinfo.name);
93 item.rect = (Rectangle){0};
94 item.time_modified = fileinfo.time_write; 94 item.time_modified = fileinfo.time_write;
95 item.deleted = FALSE;
95 Dowa_Array_Push(file_arr, item); 96 Dowa_Array_Push(file_arr, item);
96 } while (_findnext(handle, &fileinfo) == 0); 97 } while (_findnext(handle, &fileinfo) == 0);
97 _findclose(handle); 98 _findclose(handle);
98 } 99 }
99 #else 100 #else
111 if (stat(full_path, &file_stat) == 0) 112 if (stat(full_path, &file_stat) == 0)
112 { 113 {
113 HistoryItem item = {0}; 114 HistoryItem item = {0};
114 item.filename = strdup(entry->d_name); 115 item.filename = strdup(entry->d_name);
115 item.time_modified = file_stat.st_mtime; 116 item.time_modified = file_stat.st_mtime;
117 item.deleted = FALSE;
116 Dowa_Array_Push(file_arr, item); 118 Dowa_Array_Push(file_arr, item);
117 } 119 }
118 } 120 }
119 closedir(dp); 121 closedir(dp);
120 #endif 122 #endif
230 int32 seed = (uint32)time(NULL) ^ counter++; 232 int32 seed = (uint32)time(NULL) ^ counter++;
231 Dowa_String_UUID(seed, uuid4); 233 Dowa_String_UUID(seed, uuid4);
232 snprintf(filename, 1024, "%s.txt", uuid4); 234 snprintf(filename, 1024, "%s.txt", uuid4);
233 PostDog_History_CreateFile(filename, new_file); 235 PostDog_History_CreateFile(filename, new_file);
234 236
235 HistoryItem item = (HistoryItem){ .filename = malloc(sizeof(char) * strlen(filename) + 1), .rect = (Rectangle){0} }; 237 HistoryItem item = {0};
238 item.filename = strdup(filename);
239 item.deleted = FALSE;
236 memcpy(item.filename, filename, strlen(filename) + 1); 240 memcpy(item.filename, filename, strlen(filename) + 1);
237 Dowa_Array_Push(new_history_items, item); 241 Dowa_Array_Push(new_history_items, item);
238 242
239 Dowa_Arena_Free(arena); 243 Dowa_Arena_Free(arena);
240 } 244 }
683 float item_height = history_list_area.height * 0.10; 687 float item_height = history_list_area.height * 0.10;
684 688
685 int32 number_of_skipped_items = 0; 689 int32 number_of_skipped_items = 0;
686 for (int i = 0; i < total; i++) 690 for (int i = 0; i < total; i++)
687 { 691 {
688 boolean skip = FALSE;
689 for (int32 j = 0; j < Dowa_Array_Length(history_deleted_items); j++)
690 {
691 if (i == j)
692 {
693 skip = TRUE;
694 number_of_skipped_items++;
695 break;
696 }
697 }
698 if (skip)
699 continue;
700
701 HistoryItem *curr_history_items = i < new_history_items_length ? 692 HistoryItem *curr_history_items = i < new_history_items_length ?
702 &new_history_items[i] : &history_items[i - new_history_items_length]; 693 &new_history_items[i] : &history_items[i - new_history_items_length];
694
695 if (curr_history_items->deleted)
696 {
697 number_of_skipped_items++;
698 continue;
699 }
703 700
704 curr_history_items->rect = (Rectangle){ 701 curr_history_items->rect = (Rectangle){
705 .x = history_list_area.x, 702 .x = history_list_area.x,
706 .y = history_list_area.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset, 703 .y = history_list_area.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset,
707 .width = history_list_area.width, 704 .width = history_list_area.width,
819 816
820 // Draw history items with scissor mode for clipping 817 // Draw history items with scissor mode for clipping
821 BeginScissorMode(history_list_area.x, history_list_area.y, history_list_area.width, history_list_area.height); 818 BeginScissorMode(history_list_area.x, history_list_area.y, history_list_area.width, history_list_area.height);
822 for (int i = 0; i < total; i++) 819 for (int i = 0; i < total; i++)
823 { 820 {
824 boolean skip = FALSE; 821 HistoryItem *curr_history_items = i < new_history_items_length ?
825 for (int32 j = 0; j < Dowa_Array_Length(history_deleted_items); j++) 822 &new_history_items[i] : &history_items[i - new_history_items_length];
826 { 823
827 if (i == j) 824 if (curr_history_items->deleted)
828 {
829 skip = TRUE;
830 break;
831 }
832 }
833 if (skip)
834 continue; 825 continue;
835 HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length];
836 826
837 float diff = curr_history_items->rect.height*0.3; 827 float diff = curr_history_items->rect.height*0.3;
838 // DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f)); 828 // DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f));
839 Rectangle filename_area = curr_history_items->rect; 829 Rectangle filename_area = curr_history_items->rect;
840 830
858 &url_result_text 848 &url_result_text
859 ); 849 );
860 if (GuiButton(AddPaddingHorizontal(icon_area_right_column,padding), "delete")) 850 if (GuiButton(AddPaddingHorizontal(icon_area_right_column,padding), "delete"))
861 { 851 {
862 if (!remove(PostDog_Construct_URL(curr_history_items->filename))) 852 if (!remove(PostDog_Construct_URL(curr_history_items->filename)))
863 Dowa_Array_Push(history_deleted_items, i); 853 curr_history_items->deleted = TRUE;
864 else 854 else
865 {
866 fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename); 855 fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename);
867 }
868 } 856 }
869 } 857 }
870 EndScissorMode(); 858 EndScissorMode();
871 859
872 // Draw scroll indicator for history 860 // Draw scroll indicator for history