Eolite: use collections for history.h, better code

git-svn-id: svn://kolibrios.org@5974 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-16 16:13:34 +00:00
parent 4e3e119a57
commit 9c68973677
6 changed files with 79 additions and 103 deletions

View File

@ -6,7 +6,7 @@
#endif #endif
//libraries //libraries
#define MEMSIZE 4096 * 150 #define MEMSIZE 4096 * 180
#include "..\lib\clipboard.h" #include "..\lib\clipboard.h"
#include "..\lib\strings.h" #include "..\lib\strings.h"
#include "..\lib\mem.h" #include "..\lib\mem.h"
@ -33,7 +33,6 @@ enum {CREATE_FILE=1, CREATE_FOLDER, RENAME_ITEM }; //NewElement
dword col_padding, col_selec, col_lpanel; dword col_padding, col_selec, col_lpanel;
int toolbar_buttons_x[7]={9,46,85,134,167,203}; int toolbar_buttons_x[7]={9,46,85,134,167,203};
struct path_string { char Item[4096]; };
byte smooth_font=false; byte smooth_font=false;
byte active_about=0; byte active_about=0;
@ -110,8 +109,6 @@ char *fd_path_eolite_ini_path;
#include "include\about.h" #include "include\about.h"
#include "include\properties.h" #include "include\properties.h"
char TMPS[4096];
//char *TMP_PARS,*TMP_PARS2;
void main() void main()
{ {
word id; word id;
@ -125,27 +122,9 @@ void main()
load_dll(boxlib, #box_lib_init,0); load_dll(boxlib, #box_lib_init,0);
load_dll(libini, #lib_init,1); load_dll(libini, #lib_init,1);
eolite_ini_path = abspath("Eolite.ini"); eolite_ini_path = abspath("Eolite.ini");
fd_path_eolite_ini_path = "/fd/1/File Managers/Eolite.ini"; fd_path_eolite_ini_path = "/fd/1/File Managers/Eolite.ini";
/*
TMP_PARS2 = #fd_path_eolite_ini_path;
WHILE(DSBYTE[TMP_PARS])
{
IF(count_sl!=1)
{
DSBYTE[TMP_PARS2] = DSBYTE[TMP_PARS];
TMP_PARS2++;
}
ELSE IF(count_sl==2)
{
strlcpy(TMP_PARS2,"fd",2);
TMP_PARS2+=2;
}
IF(DSBYTE[TMP_PARS]=='/')count_sl++;
TMP_PARS++;
}
*/
LoadIniSettings(); LoadIniSettings();
GetSystemDiscs(); GetSystemDiscs();
@ -159,13 +138,6 @@ void main()
Open_Dir(#path,ONLY_OPEN); Open_Dir(#path,ONLY_OPEN);
strcpy(#inactive_path, #path); strcpy(#inactive_path, #path);
llist_copy(#files_inactive, #files); llist_copy(#files_inactive, #files);
font.no_bg_copy = true;
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#TMPS,4096,"/sys/FONTS/Tahoma.kf");
font.load(#TMPS);
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#TMPS,4096,"on");
if(!strcmp(#TMPS,"off"))smooth_font = false;
else smooth_font = true;
SetEventMask(1100111b); SetEventMask(1100111b);
loop(){ loop(){
switch(WaitEvent()) switch(WaitEvent())
@ -198,7 +170,7 @@ void main()
{ {
if (dif_x > 150) if (dif_x > 150)
{ {
if (HistoryPath(GO_FORWARD)) if (FoldersHistory.forward())
{ {
files.KeyHome(); files.KeyHome();
Open_Dir(#path,WITH_REDRAW); Open_Dir(#path,WITH_REDRAW);
@ -351,7 +323,7 @@ void main()
GoBack(); GoBack();
break; break;
case 22: //Forward case 22: //Forward
if (HistoryPath(GO_FORWARD)) if (FoldersHistory.forward())
{ {
files.KeyHome(); files.KeyHome();
Open_Dir(#path,WITH_REDRAW); Open_Dir(#path,WITH_REDRAW);
@ -510,7 +482,7 @@ void main()
case 059...068: //F1-F10 case 059...068: //F1-F10
FnProcess(key_scancode-58); FnProcess(key_scancode-58);
break; break;
default: default:
for (i=files.cur_y+1; i<files.count; i++) for (i=files.cur_y+1; i<files.count; i++)
{ {
strcpy(#temp, file_mas[i]*304+buf+72); strcpy(#temp, file_mas[i]*304+buf+72);
@ -763,7 +735,7 @@ void Open_Dir(dword dir_path, redraw){
if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/'); if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
if (errornum) if (errornum)
{ {
HistoryPath(ADD_NEW_PATH); FoldersHistory.add();
GoBack(); GoBack();
Write_Error(errornum); Write_Error(errornum);
return; return;
@ -781,7 +753,7 @@ void Open_Dir(dword dir_path, redraw){
PathShow_prepare stdcall(#PathShow); PathShow_prepare stdcall(#PathShow);
PathShow_draw stdcall(#PathShow); PathShow_draw stdcall(#PathShow);
} }
HistoryPath(ADD_NEW_PATH); FoldersHistory.add();
files.visible = files.h / files.item_h; files.visible = files.h / files.item_h;
if (files.count < files.visible) files.visible = files.count; if (files.count < files.visible) files.visible = files.count;
if (redraw!=ONLY_SHOW) Sorting(); if (redraw!=ONLY_SHOW) Sorting();
@ -966,8 +938,8 @@ void Del_File(byte dodel) {
del_active=0; del_active=0;
if (dodel) if (dodel)
{ {
delete_stak = malloc(20000); delete_stak = malloc(40000);
CreateThread(#Del_File_Thread,delete_stak+20000-4); CreateThread(#Del_File_Thread,delete_stak+40000-4);
} }
else draw_window(); else draw_window();
} }
@ -1024,12 +996,12 @@ void Open(byte rez)
} }
} }
inline fastcall void GoBack() inline fastcall void GoBack()
{ {
char cur_folder[4096]; char cur_folder[4096];
strcpy(#cur_folder, GetCurrentFolder()); strcpy(#cur_folder, #path);
if (HistoryPath(GO_BACK)) SelectFileByName(#cur_folder); cur_folder[strlen(#cur_folder)-1]=0x00; //delete last '/'
if (FoldersHistory.back()) SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
} }
void ShowOpenWithDialog() void ShowOpenWithDialog()

View File

@ -1,57 +1,35 @@
//06.04.2012
path_string history_list[40]; struct _FoldersHistory {
int history_num; collection history;
int history_current; int history_current;
int add();
int back();
int forward();
} FoldersHistory;
#define ADD_NEW_PATH 1 int _FoldersHistory::add()
#define GO_BACK 2
#define GO_FORWARD 3
dword GetCurrentFolder()
{ {
char cur_fol[4096]; if (!strcmp(#path, history.get(history_current-1))) return 0;
strcpy(#cur_fol, #path); history.count = history_current;
cur_fol[strlen(#cur_fol)-1]=0x00; //îáðåçàåì ïîñëåäíèé / history.add(#path);
strcpy(#cur_fol, #cur_fol+strrchr(#cur_fol,'/')); history_current++;
return #cur_fol; return 1;
}
int _FoldersHistory::back()
{
if (history_current==1) return 0;
history_current--;
strcpy(#path, history.get(history_current-1));
debugln(#path);
return 1;
} }
int HistoryPath(byte action) int _FoldersHistory::forward()
{ {
int MAX_HISTORY_NUM; if (history_current==history.count) return 0;
history_current++;
if (action==ADD_NEW_PATH) strcpy(#path, history.get(history_current-1));
{ debugln(#path);
if (history_num>0) && (!strcmp(#path,#history_list[history_current].Item)) return; return 1;
MAX_HISTORY_NUM = sizeof(history_list)/sizeof(path_string);
if (history_current>=MAX_HISTORY_NUM-1)
{
history_current/=2;
for (i=0; i<history_current; i++;)
{
strcpy(#history_list[i].Item, #history_list[MAX_HISTORY_NUM-i].Item);
}
}
history_current++;
strcpy(#history_list[history_current].Item, #path);
history_num=history_current;
}
if (action==GO_BACK)
{
if (history_current<=2) return 0;
history_current--;
strcpy(#path, #history_list[history_current].Item);
return 1;
}
if (action==GO_FORWARD)
{
if (history_current==history_num) return 0;
history_current++;
strcpy(#path, #history_list[history_current].Item);
return 1;
}
} }

View File

@ -116,7 +116,14 @@ void LoadIniSettings()
ini_get_int stdcall (eolite_ini_path, #config_section, "WinY", 50); WinY = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "WinY", 50); WinY = EAX;
ini_get_int stdcall (eolite_ini_path, #config_section, "WinW", 550); WinW = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "WinW", 550); WinW = EAX;
ini_get_int stdcall (eolite_ini_path, #config_section, "WinH", 500); WinH = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "WinH", 500); WinH = EAX;
ini_get_str stdcall (eolite_ini_path, #config_section, "DefaultPath", #path,4096,"/rd/1/"); ini_get_str stdcall (eolite_ini_path, #config_section, "DefaultPath", #path,4096,"/rd/1/");
font.no_bg_copy = true;
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#temp,4096,"/sys/FONTS/Tahoma.kf");
font.load(#temp);
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#temp,4096,"on");
if(!strcmp(#temp,"off"))smooth_font = false;
else smooth_font = true;
} }

View File

@ -1,5 +1,5 @@
#define TITLE "Eolite File Manager v3.27" #define TITLE "Eolite File Manager v3.28"
#define ABOUT_TITLE "Eolite 3.27" #define ABOUT_TITLE "Eolite 3.28"
#ifdef LANG_RUS #ifdef LANG_RUS
?define T_FILE "” ©«" ?define T_FILE "” ©«"

View File

@ -3,14 +3,34 @@
#include "../lib/io.h" #include "../lib/io.h"
#include "../lib/collection.h" #include "../lib/collection.h"
collection s;
void main() void main()
{ {
collection s;
int i;
io.run("/sys/develop/board", ""); io.run("/sys/develop/board", "");
test1();
test2();
}
void test1() {
s.add("Hello"); s.add("Hello");
s.add("World!"); s.add("World!");
debugln(s.get(0)); debugln(s.get(0)); //-> Hello
debugln(s.get(1)); debugln(s.get(1)); //-> World
s.drop();
}
void main()
{
int i;
s.add("0");
s.add("1");
s.add("2");
s.add("3");
for (i=0; i<s.count; i++) debugln(s.get(i)); //-> 0 1 2 3
s.count--;
s.count--;
s.add("4");
for (i=0; i<s.count; i++) debugln(s.get(i)); //-> 0 1 4
s.drop(); s.drop();
} }

View File

@ -6,7 +6,6 @@ struct collection
{ {
int realloc_size, count; int realloc_size, count;
dword data_start; dword data_start;
dword data_cur_pos;
dword data_size; dword data_size;
dword element_offset[4090]; dword element_offset[4090];
int add(); int add();
@ -31,25 +30,25 @@ void collection::increase_data_size() {
int collection::add(dword in) { int collection::add(dword in) {
if (count >= 4090) return 0; if (count >= 4090) return 0;
if (data_cur_pos+strlen(in)+2 > data_size) { if (element_offset[count]+strlen(in)+2 > data_size) {
increase_data_size(); increase_data_size();
add(in); add(in);
return; return;
} }
strcpy(data_start+data_cur_pos, in); strcpy(data_start+element_offset[count], in);
element_offset[count] = data_cur_pos;
data_cur_pos += strlen(in) + 1;
count++; count++;
element_offset[count] = element_offset[count-1] + strlen(in) + 1;
return 1; return 1;
} }
dword collection::get(dword pos) { dword collection::get(dword pos) {
if (pos<0) || (pos>=count) return 0;
return data_start + element_offset[pos]; return data_start + element_offset[pos];
} }
void collection::drop() { void collection::drop() {
if (data_start) free(data_start); if (data_start) free(data_start);
data_size = data_start = data_cur_pos = count = 0; data_size = data_start = element_offset[count] = count = 0;
} }
#endif #endif