From 249e0b8ea62e676ba620a3d4a220a5814bcc23ec Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 6 May 2020 15:53:34 +0000 Subject: [PATCH] menu: fix keys lib/strings.h: fix strstri() Eolite: - fix sorting - paste in a new process - delete and properties in a new process for a single item git-svn-id: svn://kolibrios.org@7878 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/eolite/Eolite.c | 234 ++++++++++------- programs/cmm/eolite/include/copy.h | 141 ----------- programs/cmm/eolite/include/copy_and_delete.h | 237 ++++++++++++++++++ programs/cmm/eolite/include/delete.h | 95 ------- programs/cmm/eolite/include/menu.h | 14 +- programs/cmm/eolite/include/progress_dialog.h | 20 +- programs/cmm/eolite/include/properties.h | 3 +- programs/cmm/eolite/include/sorting.h | 9 +- programs/cmm/eolite/include/translations.h | 4 +- programs/cmm/examples/collections.c | 8 +- programs/cmm/lib/collection.h | 14 +- programs/cmm/lib/copyf.h | 2 +- programs/cmm/lib/fs.h | 34 ++- programs/cmm/lib/strings.h | 4 +- programs/cmm/menu/menu.c | 18 +- programs/cmm/sysmon/general.h | 1 + 16 files changed, 467 insertions(+), 371 deletions(-) delete mode 100644 programs/cmm/eolite/include/copy.h create mode 100644 programs/cmm/eolite/include/copy_and_delete.h delete mode 100644 programs/cmm/eolite/include/delete.h diff --git a/programs/cmm/eolite/Eolite.c b/programs/cmm/eolite/Eolite.c index 69f02c5fb..c2c486f98 100644 --- a/programs/cmm/eolite/Eolite.c +++ b/programs/cmm/eolite/Eolite.c @@ -107,7 +107,7 @@ _ini ini; char scroll_used=false; -dword about_stak,properties_stak,settings_stak,copy_stak,delete_stak; +dword about_stak=0,properties_stak=0,settings_stak=0,delete_stak=0; proc_info Form; int sc_slider_h; @@ -138,12 +138,11 @@ byte cmd_free=0; #include "include\gui.h" #include "include\settings.h" #include "include\progress_dialog.h" -#include "include\copy.h" +#include "include\copy_and_delete.h" #include "include\sorting.h" #include "include\icons.h" #include "include\left_panel.h" #include "include\menu.h" -#include "include\delete.h" #include "include\about.h" #include "include\properties.h" #include "include\breadcrumbs.h" @@ -156,6 +155,33 @@ void load_libraries() load_dll(libimg, #libimg_init,1); } +void handle_param() +{ + //-p : just show file/folder properties dialog + //-v : paste thread + //-d : delete thread + if (param) && (param[0]=='-') switch (param[1]) + { + case 'p': + strcpy(#file_path, #param + 3); + strcpy(#file_name, #param + strrchr(#param, '/')); + itdir = dir_exists(#file_path); + properties_dialog(); + return; + case 'v': + cut_active = param[2] - '0'; + strcpy(#path, #param + 4); + PasteThread(); + return; + case 'd': + strcpy(#file_path, #param + 3); + itdir = dir_exists(#file_path); + DisplayOperationForm(DELETE_FLAG); + DeleteSingleElement(); + return; + } +} + void main() { dword id; @@ -169,14 +195,7 @@ void main() LoadIniSettings(); SystemDiscs.Get(); - //-p just show file/folder properties dialog - if (param) && (param[0]=='-') && (param[1]=='p') - { - strcpy(#file_path, #param + 3); - strcpy(#file_name, #param + strrchr(#param, '/')); - properties_dialog(); - ExitProcess(); - } + handle_param(); ESBYTE[0] = NULL; @@ -300,12 +319,9 @@ void main() id=GetButtonID(); if (new_element_active) || (del_active) { - if(POPUP_BTN1==id) || (POPUP_BTN2==id) { - if (del_active) Del_File(id-POPUP_BTN2); - if (new_element_active) NewElement(id-POPUP_BTN2); - DeleteButton(POPUP_BTN1); - DeleteButton(POPUP_BTN2); - } + if (POPUP_BTN1==id) && (del_active) EventDelete(); + if (POPUP_BTN1==id) && (new_element_active) NewElement(); + if (POPUP_BTN2==id) EventClosePopinForm(); break; } @@ -329,13 +345,13 @@ void main() Dir_Up(); break; case 24: - Copy(#file_path, CUT); + EventCopy(CUT); break; case 25: - Copy(#file_path, NOCUT); + EventCopy(NOCUT); break; case 26: - Paste(); + EventPaste(); break; case 31...33: EventSort(id-30); @@ -368,13 +384,13 @@ void main() { if (del_active) { - if (key_scancode == SCAN_CODE_ENTER) Del_File(true); - if (key_scancode == SCAN_CODE_ESC) Del_File(false); + if (key_scancode == SCAN_CODE_ENTER) EventDelete(); + if (key_scancode == SCAN_CODE_ESC) EventClosePopinForm(); } if (new_element_active) { - if (key_scancode == SCAN_CODE_ENTER) NewElement(true); - if (key_scancode == SCAN_CODE_ESC) NewElement(false); + if (key_scancode == SCAN_CODE_ENTER) NewElement(); + if (key_scancode == SCAN_CODE_ESC) EventClosePopinForm(); EAX = key_editbox; edit_box_key stdcall (#new_file_ed); } @@ -405,16 +421,16 @@ void main() SystemDiscs.Click(key_scancode); break; case SCAN_CODE_KEY_X: - Copy(#file_path, CUT); + EventCopy(CUT); break; case SCAN_CODE_KEY_C: - Copy(#file_path, NOCUT); + EventCopy(NOCUT); break; case SCAN_CODE_KEY_G: EventOpenConsoleHere(); break; case SCAN_CODE_KEY_V: - Paste(); + EventPaste(); break; case SCAN_CODE_KEY_D: //set image as bg strlcpy(#temp, "\\S__",4); @@ -485,7 +501,6 @@ void main() if (action_buf==OPERATION_END) { FnProcess(5); - if (copy_stak) SelectFileByName(#copy_to+strrchr(#copy_to,'/')); action_buf=0; } break; @@ -499,7 +514,6 @@ void main() if(cmd_free==2) about_stak=free(about_stak); else if(cmd_free==3) properties_stak=free(properties_stak); else if(cmd_free==4) settings_stak=free(settings_stak); - else if(cmd_free==5) copy_stak=free(copy_stak); else if(cmd_free==6) delete_stak=free(delete_stak); cmd_free = false; } @@ -953,85 +967,81 @@ void ShowOpenWithDialog() RunProgram("/sys/@open", #open_param); } -void NewElement(byte newf) +void NewElement() { BDVK element_info; byte del_rezult, copy_rezult, info_result; - if (newf) + + sprintf(#temp,"%s/%s",#path,new_file_ed.text); + info_result = GetFileInfo(#temp, #element_info); + switch(new_element_active) { - sprintf(#temp,"%s/%s",#path,new_file_ed.text); - info_result = GetFileInfo(#temp, #element_info); - switch(new_element_active) - { - case CREATE_FILE: - if (info_result==5) + case CREATE_FILE: + if (info_result==5) + { + CreateFile(0, 0, #temp); + if (EAX) { - CreateFile(0, 0, #temp); - if (EAX) + if (EAX==5) notify(NOT_CREATE_FILE); + else Write_Error(EAX); + } + } + else + { + notify(FS_ITEM_ALREADY_EXISTS); + } + break; + case CREATE_FOLDER: + if (info_result==5) + { + CreateDir(#temp); + if (EAX) + { + if (EAX==5) notify(NOT_CREATE_FOLDER); + else Write_Error(EAX); + } + } + else + { + notify(FS_ITEM_ALREADY_EXISTS); + } + break; + case RENAME_ITEM: + if (info_result==5) + { + if (itdir) + { + //rename only empty folders + if (del_rezult = DeleteFile(#file_path)) { - if (EAX==5) notify(NOT_CREATE_FILE); - else Write_Error(EAX); + Write_Error(del_rezult); + return; } + if (CreateDir(#temp)) CreateDir(#file_path); + Open_Dir(#path,WITH_REDRAW); + SelectFileByName(new_file_ed.text); } else { - notify(FS_ITEM_ALREADY_EXISTS); - } - break; - case CREATE_FOLDER: - if (info_result==5) - { - CreateDir(#temp); - if (EAX) + if (copy_rezult = CopyFile(#file_path,#temp)) { - if (EAX==5) notify(NOT_CREATE_FOLDER); - else Write_Error(EAX); - } - } - else - { - notify(FS_ITEM_ALREADY_EXISTS); - } - break; - case RENAME_ITEM: - if (info_result==5) - { - if (itdir) - { - //rename only empty folders - if (del_rezult = DeleteFile(#file_path)) - { - Write_Error(del_rezult); - return; - } - if (CreateDir(#temp)) CreateDir(#file_path); - Open_Dir(#path,WITH_REDRAW); - SelectFileByName(new_file_ed.text); + Write_Error(copy_rezult); } else { - if (copy_rezult = CopyFile(#file_path,#temp)) - { - Write_Error(copy_rezult); - } - else - { - DeleteFile(#file_path); - SelectFileByName(new_file_ed.text); - } + DeleteFile(#file_path); + SelectFileByName(new_file_ed.text); } } - else - { - notify(FS_ITEM_ALREADY_EXISTS); - } - } - new_element_active = 0; - Open_Dir(#path,WITH_REDRAW); - SelectFileByName(new_file_ed.text); + } + else + { + notify(FS_ITEM_ALREADY_EXISTS); + } } - new_element_active = 0; Open_Dir(#path,WITH_REDRAW); + SelectFileByName(new_file_ed.text); + EventClosePopinForm(); } void NewElement_Form(byte crt, dword strng) @@ -1093,8 +1103,7 @@ void FnProcess(byte N) NewElement_Form(CREATE_FILE, T_NEW_FILE); break; case 8: - properties_stak = malloc(8096); - CreateThread(#properties_dialog, properties_stak+8092); + EventShowProperties(); break; case 10: //F10 if (!active_settings) @@ -1253,4 +1262,45 @@ void ProceedMouseGestures() } } +void EventPaste() { + char paste_line[4096+6]; + sprintf(#paste_line, "-v%i %s", cut_active, #path); + RunProgram(#program_path, #paste_line); + EventClosePopinForm(); +} + +void EventDelete() +char line_param[4096+5]; +{ + EventClosePopinForm(); + if (!selected_count) { + sprintf(#line_param, "-d %s", #file_path); + RunProgram(#program_path, #line_param); + } else { + delete_stak = malloc(40000); + CreateThread(#DeleteSelectedElements,delete_stak+40000-4); + } +} + +void EventClosePopinForm() +{ + del_active=0; + new_element_active = 0; + draw_window(); + DeleteButton(POPUP_BTN1); + DeleteButton(POPUP_BTN2); +} + +void EventShowProperties() +char line_param[4096+5]; +{ + if (!selected_count) { + sprintf(#line_param, "-p %s", #file_path); + RunProgram(#program_path, #line_param); + } else { + properties_stak = malloc(8096); + CreateThread(#properties_dialog, properties_stak+8092); + } +} + stop: diff --git a/programs/cmm/eolite/include/copy.h b/programs/cmm/eolite/include/copy.h deleted file mode 100644 index 7a748ec04..000000000 --- a/programs/cmm/eolite/include/copy.h +++ /dev/null @@ -1,141 +0,0 @@ - -byte copy_to[4096]; -byte copy_from[4096]; -byte cut_active=0; - -enum {NOCUT, CUT}; - -void setElementSelectedFlag(dword n, int state) { - dword selected_offset = file_mas[n]*304 + buf+32 + 7; - ESBYTE[selected_offset] = state; - if (n==0) && (strncmp(file_mas[n]*304+buf+72,"..",2)==0) { - ESBYTE[selected_offset] = false; //do not selec ".." directory - return; - } - if (state==true) selected_count++; - if (state==false) selected_count--; - if (selected_count<0) selected_count=0; -} - -int getElementSelectedFlag(dword n) { - dword selected_offset = file_mas[n]*304 + buf+32 + 7; - return ESBYTE[selected_offset]; -} - -void Copy(dword pcth, char cut) -{ - byte copy_t[4096]; - dword buff_data; - dword path_len = 0; - dword size_buf = 0; - dword copy_buf_offset = 0; - dword i; - - if (files.count<=0) return; //no files - - //if no element selected by "Insert" key, then we copy current element - if (!selected_count) - setElementSelectedFlag(files.cur_y, true); - - if (!selected_count) return; - - size_buf = 4; - for (i=0; i= b) return; - for (j = a; j <= b; j++) - if (strcmp(file_mas[j]*304 + buf+72, file_mas[b]*304 + buf+72)<=0) { file_mas[isn] >< file_mas[j]; isn++;} + for (j = a; j <= b; j++) { + if (strcmpi(file_mas[j]*304 + buf+72, file_mas[b]*304 + buf+72)<=0) { file_mas[isn] >< file_mas[j]; isn++;} + } Sort_by_Name(a, isn-2); Sort_by_Name(isn, b); } @@ -44,11 +45,9 @@ void Sort_by_Type(int a, b) // n=strcmp(ext1, ext2); if (n<0) { file_mas[isn] >< file_mas[j]; isn++;} - if (!n) && (strcmp(filename1, filename2)<=0) { file_mas[isn] >< file_mas[j]; isn++;} + if (!n) && (strcmp(filename1, filename2) <= 0) { file_mas[isn] >< file_mas[j]; isn++;} } Sort_by_Type(a, isn-2); Sort_by_Type(isn, b); } - - diff --git a/programs/cmm/eolite/include/translations.h b/programs/cmm/eolite/include/translations.h index 46ebb5e81..42cd8dee2 100644 --- a/programs/cmm/eolite/include/translations.h +++ b/programs/cmm/eolite/include/translations.h @@ -1,5 +1,5 @@ -#define TITLE "Eolite File Manager 4.24b" -#define ABOUT_TITLE "EOLITE 4.24b" +#define TITLE "Eolite File Manager 4.28" +#define ABOUT_TITLE "EOLITE 4.28" #ifdef LANG_RUS ?define T_FILE "” ©«" diff --git a/programs/cmm/examples/collections.c b/programs/cmm/examples/collections.c index 7af979a37..c8aa66ea8 100644 --- a/programs/cmm/examples/collections.c +++ b/programs/cmm/examples/collections.c @@ -15,9 +15,15 @@ void test1() collection s; { s.add("Hello"); - s.add("World!"); + s.add("World"); debugln(s.get(0)); //-> Hello debugln(s.get(1)); //-> World + s.delete_last(); + debugln(s.get(0)); //-> Hello + debugln(s.get(1)); //-> 0 + s.add("Kolibri"); + debugln(s.get(0)); //-> Hello + debugln(s.get(1)); //-> Kolibri s.drop(); } diff --git a/programs/cmm/lib/collection.h b/programs/cmm/lib/collection.h index 73f317c2f..f52268e8d 100644 --- a/programs/cmm/lib/collection.h +++ b/programs/cmm/lib/collection.h @@ -20,6 +20,8 @@ struct collection dword get_pos_by_name(); void drop(); void increase_data_size(); + dword get_last(); + bool delete_last(); }; :void collection::increase_data_size() { @@ -40,7 +42,10 @@ struct collection } :int collection::addn(dword in, len) { - if (count >= 4000) return 0; + if (count >= 4000) { + debugln("collection: more than 4000 elements!"); + return 0; + } if (element_offset[count]+len+2 > data_size) { increase_data_size(); addn(in, len); @@ -57,6 +62,10 @@ struct collection return data_start + element_offset[pos]; } +:dword collection::get_last() { + return get(count-1); +} + :dword collection::get_pos_by_name(dword name) { dword i; for (i=0; i='A') && (si<='Z') si +=32; if (ue>='A') && (ue<='Z') ue +=32; - if (si != ue) return -1; + if (si != ue) return si-ue; cmp1++; cmp2++; if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0; diff --git a/programs/cmm/menu/menu.c b/programs/cmm/menu/menu.c index cc72f88b4..d2f37a454 100644 --- a/programs/cmm/menu/menu.c +++ b/programs/cmm/menu/menu.c @@ -147,6 +147,13 @@ void main() } } +void CorrectLastItem() +{ + if (menu1.cur_y > menu1.count - GetSeparatorsCount() - 1) { + menu1.cur_y = menu1.count - GetSeparatorsCount() - 1; + } +} + void ProcessKeys() { switch(key_scancode) @@ -164,10 +171,19 @@ void ProcessKeys() break; case SCAN_CODE_UP: - if (!menu1.KeyUp()) menu1.KeyEnd(); + if (!menu1.KeyUp()) { + menu1.KeyEnd(); + CorrectLastItem(); + } draw_list(); break; + case SCAN_CODE_END: + menu1.KeyEnd(); + CorrectLastItem(); + draw_list(); + break; + default: if (menu1.ProcessKey(key_scancode)) draw_list(); } diff --git a/programs/cmm/sysmon/general.h b/programs/cmm/sysmon/general.h index 9ea207637..9246f0169 100644 --- a/programs/cmm/sysmon/general.h +++ b/programs/cmm/sysmon/general.h @@ -21,6 +21,7 @@ dword tmp_size[10]; void General__Main() { + DIR_SIZE dir_size; dword cpu_frequency; incn y; SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON);