forked from KolibriOS/kolibrios
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:
parent
4e3e119a57
commit
9c68973677
@ -6,7 +6,7 @@
|
||||
#endif
|
||||
|
||||
//libraries
|
||||
#define MEMSIZE 4096 * 150
|
||||
#define MEMSIZE 4096 * 180
|
||||
#include "..\lib\clipboard.h"
|
||||
#include "..\lib\strings.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;
|
||||
|
||||
int toolbar_buttons_x[7]={9,46,85,134,167,203};
|
||||
struct path_string { char Item[4096]; };
|
||||
|
||||
byte smooth_font=false;
|
||||
byte active_about=0;
|
||||
@ -110,8 +109,6 @@ char *fd_path_eolite_ini_path;
|
||||
#include "include\about.h"
|
||||
#include "include\properties.h"
|
||||
|
||||
char TMPS[4096];
|
||||
//char *TMP_PARS,*TMP_PARS2;
|
||||
void main()
|
||||
{
|
||||
word id;
|
||||
@ -125,27 +122,9 @@ void main()
|
||||
|
||||
load_dll(boxlib, #box_lib_init,0);
|
||||
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";
|
||||
/*
|
||||
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();
|
||||
GetSystemDiscs();
|
||||
@ -159,13 +138,6 @@ void main()
|
||||
Open_Dir(#path,ONLY_OPEN);
|
||||
strcpy(#inactive_path, #path);
|
||||
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);
|
||||
loop(){
|
||||
switch(WaitEvent())
|
||||
@ -198,7 +170,7 @@ void main()
|
||||
{
|
||||
if (dif_x > 150)
|
||||
{
|
||||
if (HistoryPath(GO_FORWARD))
|
||||
if (FoldersHistory.forward())
|
||||
{
|
||||
files.KeyHome();
|
||||
Open_Dir(#path,WITH_REDRAW);
|
||||
@ -351,7 +323,7 @@ void main()
|
||||
GoBack();
|
||||
break;
|
||||
case 22: //Forward
|
||||
if (HistoryPath(GO_FORWARD))
|
||||
if (FoldersHistory.forward())
|
||||
{
|
||||
files.KeyHome();
|
||||
Open_Dir(#path,WITH_REDRAW);
|
||||
@ -763,7 +735,7 @@ void Open_Dir(dword dir_path, redraw){
|
||||
if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
|
||||
if (errornum)
|
||||
{
|
||||
HistoryPath(ADD_NEW_PATH);
|
||||
FoldersHistory.add();
|
||||
GoBack();
|
||||
Write_Error(errornum);
|
||||
return;
|
||||
@ -781,7 +753,7 @@ void Open_Dir(dword dir_path, redraw){
|
||||
PathShow_prepare stdcall(#PathShow);
|
||||
PathShow_draw stdcall(#PathShow);
|
||||
}
|
||||
HistoryPath(ADD_NEW_PATH);
|
||||
FoldersHistory.add();
|
||||
files.visible = files.h / files.item_h;
|
||||
if (files.count < files.visible) files.visible = files.count;
|
||||
if (redraw!=ONLY_SHOW) Sorting();
|
||||
@ -966,8 +938,8 @@ void Del_File(byte dodel) {
|
||||
del_active=0;
|
||||
if (dodel)
|
||||
{
|
||||
delete_stak = malloc(20000);
|
||||
CreateThread(#Del_File_Thread,delete_stak+20000-4);
|
||||
delete_stak = malloc(40000);
|
||||
CreateThread(#Del_File_Thread,delete_stak+40000-4);
|
||||
}
|
||||
else draw_window();
|
||||
}
|
||||
@ -1024,12 +996,12 @@ void Open(byte rez)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline fastcall void GoBack()
|
||||
{
|
||||
char cur_folder[4096];
|
||||
strcpy(#cur_folder, GetCurrentFolder());
|
||||
if (HistoryPath(GO_BACK)) SelectFileByName(#cur_folder);
|
||||
strcpy(#cur_folder, #path);
|
||||
cur_folder[strlen(#cur_folder)-1]=0x00; //delete last '/'
|
||||
if (FoldersHistory.back()) SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
|
||||
}
|
||||
|
||||
void ShowOpenWithDialog()
|
||||
|
@ -1,57 +1,35 @@
|
||||
//06.04.2012
|
||||
|
||||
path_string history_list[40];
|
||||
int history_num;
|
||||
struct _FoldersHistory {
|
||||
collection history;
|
||||
int history_current;
|
||||
int add();
|
||||
int back();
|
||||
int forward();
|
||||
} FoldersHistory;
|
||||
|
||||
#define ADD_NEW_PATH 1
|
||||
#define GO_BACK 2
|
||||
#define GO_FORWARD 3
|
||||
|
||||
dword GetCurrentFolder()
|
||||
int _FoldersHistory::add()
|
||||
{
|
||||
char cur_fol[4096];
|
||||
strcpy(#cur_fol, #path);
|
||||
cur_fol[strlen(#cur_fol)-1]=0x00; //îáðåçàåì ïîñëåäíèé /
|
||||
strcpy(#cur_fol, #cur_fol+strrchr(#cur_fol,'/'));
|
||||
return #cur_fol;
|
||||
}
|
||||
|
||||
int HistoryPath(byte action)
|
||||
{
|
||||
int MAX_HISTORY_NUM;
|
||||
|
||||
if (action==ADD_NEW_PATH)
|
||||
{
|
||||
if (history_num>0) && (!strcmp(#path,#history_list[history_current].Item)) return;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (!strcmp(#path, history.get(history_current-1))) return 0;
|
||||
history.count = history_current;
|
||||
history.add(#path);
|
||||
history_current++;
|
||||
strcpy(#history_list[history_current].Item, #path);
|
||||
history_num=history_current;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (action==GO_BACK)
|
||||
int _FoldersHistory::back()
|
||||
{
|
||||
if (history_current<=2) return 0;
|
||||
if (history_current==1) return 0;
|
||||
history_current--;
|
||||
strcpy(#path, #history_list[history_current].Item);
|
||||
strcpy(#path, history.get(history_current-1));
|
||||
debugln(#path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (action==GO_FORWARD)
|
||||
int _FoldersHistory::forward()
|
||||
{
|
||||
if (history_current==history_num) return 0;
|
||||
if (history_current==history.count) return 0;
|
||||
history_current++;
|
||||
strcpy(#path, #history_list[history_current].Item);
|
||||
strcpy(#path, history.get(history_current-1));
|
||||
debugln(#path);
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -117,6 +117,13 @@ void LoadIniSettings()
|
||||
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_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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#define TITLE "Eolite File Manager v3.27"
|
||||
#define ABOUT_TITLE "Eolite 3.27"
|
||||
#define TITLE "Eolite File Manager v3.28"
|
||||
#define ABOUT_TITLE "Eolite 3.28"
|
||||
|
||||
#ifdef LANG_RUS
|
||||
?define T_FILE "” ©«"
|
||||
|
@ -3,14 +3,34 @@
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/collection.h"
|
||||
|
||||
collection s;
|
||||
|
||||
void main()
|
||||
{
|
||||
collection s;
|
||||
int i;
|
||||
io.run("/sys/develop/board", "");
|
||||
test1();
|
||||
test2();
|
||||
}
|
||||
|
||||
void test1() {
|
||||
s.add("Hello");
|
||||
s.add("World!");
|
||||
debugln(s.get(0));
|
||||
debugln(s.get(1));
|
||||
debugln(s.get(0)); //-> Hello
|
||||
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();
|
||||
}
|
@ -6,7 +6,6 @@ struct collection
|
||||
{
|
||||
int realloc_size, count;
|
||||
dword data_start;
|
||||
dword data_cur_pos;
|
||||
dword data_size;
|
||||
dword element_offset[4090];
|
||||
int add();
|
||||
@ -31,25 +30,25 @@ void collection::increase_data_size() {
|
||||
|
||||
int collection::add(dword in) {
|
||||
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();
|
||||
add(in);
|
||||
return;
|
||||
}
|
||||
strcpy(data_start+data_cur_pos, in);
|
||||
element_offset[count] = data_cur_pos;
|
||||
data_cur_pos += strlen(in) + 1;
|
||||
strcpy(data_start+element_offset[count], in);
|
||||
count++;
|
||||
element_offset[count] = element_offset[count-1] + strlen(in) + 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
dword collection::get(dword pos) {
|
||||
if (pos<0) || (pos>=count) return 0;
|
||||
return data_start + element_offset[pos];
|
||||
}
|
||||
|
||||
void collection::drop() {
|
||||
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
|
Loading…
Reference in New Issue
Block a user