Subversion Repositories Kolibri OS

Rev

Rev 4042 | Rev 4057 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3363 leency 1
//Leency & Veliant 2008-2013
2
//GNU GPL licence.
3
 
4022 leency 4
#ifndef AUTOBUILD
5
#include "lang.h--"
6
#endif
7
 
3363 leency 8
//libraries
4049 leency 9
#define MEMSIZE 0xD0000
3363 leency 10
#include "..\lib\kolibri.h"
11
#include "..\lib\strings.h"
12
#include "..\lib\mem.h"
13
#include "..\lib\dll.h"
14
#include "..\lib\lib.obj\box_lib.h"
15
#include "..\lib\file_system.h"
16
#include "..\lib\figures.h"
3412 leency 17
#include "..\lib\encoding.h"
3434 leency 18
#include "..\lib\list_box.h"
19
#include "..\lib\copyf.h"
3363 leency 20
//images
21
#include "imgs\toolbar.txt"
22
#include "imgs\left_p.txt"
23
 
3848 punk_joker 24
#ifdef LANG_RUS
25
	?define T_FILE "Файл"
26
	?define T_TYPE "Тип"
27
	?define T_SIZE "Размер"
28
	?define T_NEW_FOLDER "Новая папка"
29
	?define T_NEW_FILE "Новый файл"
30
	?define T_DELETE_FILE "Вы действительно хотите удалить"
31
	?define T_YES "Да"
32
	?define T_NO "Нет"
33
	?define T_DEL_ERROR_1 "Ошибка. Папка не пустая."
3997 leency 34
	?define WAIT_DELETING_FOLDER "Удаляется папка. Подожите..."
3848 punk_joker 35
	?define NOT_CREATE_FOLDER "Не удалось создать папку."
36
	?define NOT_CREATE_FILE "Не удалось создать файл."
37
	?define ERROR_1 "Ошибка при загрузке библиотеки /rd/1/lib/box_lib.obj"
3883 leency 38
	?define T_PASTE_WINDOW "Копирую..."
39
	?define T_PASTE_WINDOW_TEXT "Копируется файл:"
4022 leency 40
	?define T_CANCEL_PASTE "Копирование прекращено. Папка скопирована не полностью."
4049 leency 41
	?define T_SELECT_APP_TO_OPEN_WITH "Выберите программу для открытия файла"
3933 kaitz 42
#elif LANG_EST
43
	?define T_FILE "Fail"
44
	?define T_TYPE "T№№p"
45
	?define T_SIZE "Suurus"
46
	?define T_NEW_FOLDER "Uus kataloog"
47
	?define T_NEW_FILE "Uus fail"
48
	?define T_DELETE_FILE "Kas sa tahad tїesti kustutada"
49
	?define T_YES "Jah"
50
	?define T_NO "Ei"
51
	?define T_DEL_ERROR_1 "Viga. Kataloog ei ole t№hi."
3997 leency 52
	?define WAIT_DELETING_FOLDER "Deleting folder. Please, wait..."
3933 kaitz 53
	?define NOT_CREATE_FOLDER "Kataloogi ei saa luua."
54
	?define NOT_CREATE_FILE "Faili ei saa luua."
55
	?define ERROR_1 "Viga teegi laadimisel /rd/1/lib/box_lib.obj"
56
	?define T_PASTE_WINDOW "Kopeerin..."
57
	?define T_PASTE_WINDOW_TEXT "Kopeerin faili:"
4022 leency 58
	?define T_CANCEL_PASTE "Copy process terminated. Folder copied incompletely."
4049 leency 59
	?define T_SELECT_APP_TO_OPEN_WITH "Select application to open file"
3848 punk_joker 60
#else
61
	?define T_FILE "File"
62
	?define T_TYPE "Type"
63
	?define T_SIZE "Size"
64
	?define T_NEW_FOLDER "New folder"
65
	?define T_NEW_FILE "New file"
66
	?define T_DELETE_FILE "Do you really want to delete"
67
	?define T_YES "Yes"
68
	?define T_NO "No"
69
	?define T_DEL_ERROR_1 "Error. Folder isn't empty."
3997 leency 70
	?define WAIT_DELETING_FOLDER "Deleting folder. Please, wait..."
3848 punk_joker 71
	?define NOT_CREATE_FOLDER "Folder can not be created."
72
	?define NOT_CREATE_FILE "File can not be created."
73
	?define ERROR_1 "Error while loading library /rd/1/lib/box_lib.obj"
3883 leency 74
	?define T_PASTE_WINDOW "Copying..."
75
	?define T_PASTE_WINDOW_TEXT "Copying file:"
4022 leency 76
	?define T_CANCEL_PASTE "Copy process terminated. Folder copied incompletely."
4049 leency 77
	?define T_SELECT_APP_TO_OPEN_WITH "Select application to open file"
3848 punk_joker 78
#endif
79
 
3444 leency 80
enum {ONLY_SHOW, WITH_REDRAW, ONLY_OPEN}; //OpenDir
81
 
4049 leency 82
#define TITLE "Eolite File Manager v1.99"
83
#define ABOUT_TITLE "Eolite v1.99"
3363 leency 84
dword col_work    = 0xE4DFE1;
3444 leency 85
dword col_border  = 0x9098B0; //A0A0B8; //0x819FC5;
3363 leency 86
dword col_padding = 0xC8C9C9;
87
dword col_selec   = 0x94AECE;
88
dword col_lpanel  = 0x00699C;
89
 
3434 leency 90
int toolbar_buttons_x[7]={9,46,85,134,167,203};
91
char tmp_disk_del_param[3]="d0";
92
struct path_string { char Item[4096]; };
3363 leency 93
 
4040 punk_joker 94
int active_about=0;
95
 
3434 leency 96
llist files;
97
 
98
byte
3363 leency 99
	path[4096],
100
	file_path[4096],
3404 leency 101
	file_name[256],
3434 leency 102
	temp[4096];
103
byte
3439 leency 104
	rename_active=0,
105
	del_active=0,
3434 leency 106
	show_dev_name=1,
107
	sort_num=2,
3441 leency 108
	itdir;
3363 leency 109
 
110
proc_info Form;
111
mouse m;
4022 leency 112
int mouse_dd, scroll_used, scroll_size, sorting_arrow_x;
3434 leency 113
dword buf, off;
114
dword file_mas[6898];
115
int j, i;
4028 leency 116
int action_buf;
3363 leency 117
 
4028 leency 118
edit_box edit2 = {250,213,80,0xFFFFCC,0x94AECE,0xFFFFCC,0xffffff,0,248,#file_name,#mouse_dd,64,6,6};
3434 leency 119
PathShow_data PathShow = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, #path, #temp, 0};
3363 leency 120
PathShow_data FileShow = {0, 56,215, 6, 100, 0, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
121
 
4042 leency 122
#include "include\copy.h"
123
#include "include\other.h"
3363 leency 124
#include "include\sorting.h"
4042 leency 125
#include "include\icons.h"
3363 leency 126
#include "include\ini.h"
127
#include "include\left_panel.h"
128
#include "include\history.h"
4042 leency 129
#include "include\menu.h"
130
#include "include\about.h"
131
#include "include\open_with.h"
3363 leency 132
 
133
void main()
134
{
3444 leency 135
	word key, id, can_show, can_select, m_selected;
3363 leency 136
 
3434 leency 137
	files.line_h=18;
3363 leency 138
	mem_Init();
3848 punk_joker 139
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify(ERROR_1);
3434 leency 140
	SystemDiscsGet();
3432 leency 141
	GetIni(1);
3363 leency 142
	if (param)
143
	{
144
		strcpy(#path, #param);
3434 leency 145
		if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //add "/" to the end of the string
3363 leency 146
	}
147
	else
3695 leency 148
	{
3432 leency 149
		strcpy(#path, "/rd/1/");
3695 leency 150
	}
3363 leency 151
	Open_Dir(#path,ONLY_OPEN);
3432 leency 152
	SetEventMask(0x27);
3434 leency 153
	loop() switch(WaitEvent())
3363 leency 154
	{
155
		case evMouse:
3434 leency 156
			IF (del_active) break;
3363 leency 157
			id=GetProcessSlot(Form.ID);
3444 leency 158
			IF (id!=GetActiveProcess()) || (Form.status_window>2) break;
3434 leency 159
			IF (rename_active) { edit_box_mouse stdcall(#edit2); break; }
3363 leency 160
 
161
			m.get();
162
 
3444 leency 163
			if (m.x > files.x) && (m.x < files.x + files.w) && (m.y > files.y) && (m.y < files.y+files.h) && (!can_select)
3363 leency 164
			{
4042 leency 165
				m_selected = m.y - files.y / files.line_h;
3434 leency 166
				if (m.lkm) can_select = 1;
167
				if (m.pkm)
168
				{
169
					can_show = 1;
4042 leency 170
					if (m.y - files.y / files.line_h != files.current) can_select = 1;
3434 leency 171
				}
172
			}
173
 
174
			//select/open file {
175
			if (!m.lkm) && (!m.pkm) && (can_select)
176
			{
177
				can_select = 0;
4042 leency 178
				if (m.y>=files.y)
3695 leency 179
				{
4042 leency 180
					id = m.y - files.y / files.line_h;
3695 leency 181
					if (id!=m_selected)
182
					{
183
						can_show=0;
184
						break;
185
					}
186
					if (files.current!=id)
3876 leency 187
					{
188
						if (id
189
					}
3695 leency 190
					else
191
						Open();
192
				}
3434 leency 193
			};
194
			// } select/open file
195
 
196
			//file menu {
197
			if (!m.pkm) && (!m.lkm) && (can_show)
198
			{
199
				can_show = 0;
4042 leency 200
				if (m.y>=files.y)
3695 leency 201
				{
202
					SwitchToAnotherThread();
203
					CreateThread(#FileMenu,#menu_stak);
204
				}
3434 leency 205
				break;
206
			}
207
			// } file menu
3363 leency 208
 
3434 leency 209
			if (m.vert)
210
			{
211
				files.MouseScroll(m.vert);
212
				List_ReDraw();
213
				break;
214
			}
215
 
4042 leency 216
			if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>40) && (m.y
3363 leency 217
			{
218
				IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),41,14,14,0xC7C7C7,0xFFFFFF);
3434 leency 219
				WHILE (m.lkm==1) && (files.first>0)
3363 leency 220
				{
3434 leency 221
					pause(8);
222
					files.first--;
3363 leency 223
					List_ReDraw();
224
					m.get();
225
				}
226
				DrawRectangle3D(onLeft(26,0),41,14,14,0xFFFFFF,0xC7C7C7);
227
			}
228
 
229
			if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>onTop(22,0)+1) && (m.y
230
			{
231
				IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xC7C7C7,0xFFFFFF);
3434 leency 232
				while (m.lkm==1) && (files.first
3363 leency 233
				{
3434 leency 234
					pause(8);
235
					files.first++;
3363 leency 236
					List_ReDraw();
237
					m.get();
238
				}
239
				DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xFFFFFF,0xC7C7C7);
240
			}
241
 
3434 leency 242
			//Scrooll
243
			if (!m.lkm) && (scroll_used) { scroll_used=NULL; Scroll(); }
244
			if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>56) && (m.y
3363 leency 245
 
246
			if (scroll_used)
247
			{
4042 leency 248
				IF (scroll_size/2+files.y>m.y) || (m.y<0) || (m.y>4000) m.y=scroll_size/2+files.y; //anee eo?ni? iaa ieiii
3434 leency 249
				id=files.first;
3363 leency 250
				j= scroll_size/2;
4042 leency 251
				files.first = m.y -j -files.y * files.count;
252
				files.first /= onTop(22,files.y);
3434 leency 253
				IF (files.visible+files.first>files.count) files.first=files.count-files.visible;
3444 leency 254
				IF (id!=files.first) List_ReDraw();
3363 leency 255
			}
256
			break;
257
//Button pressed-----------------------------------------------------------------------------
258
		case evButton:
259
			id=GetButtonID();
3439 leency 260
			if (id==1) ExitProcess();
261
			if (rename_active) break;
262
			if (del_active)
3363 leency 263
			{
264
				IF (id==301) || (id==302) Del_File(302-id);
265
				break;
266
			}
3439 leency 267
 
3363 leency 268
			switch(id)
269
			{
270
				case 21: //Back
271
						GoBack();
272
						break;
273
				case 22: //Forward
274
						if (HistoryPath(GO_FORWARD))
275
						{
3434 leency 276
							files.first=files.current=NULL; //aaa?o nienea
3363 leency 277
							Open_Dir(#path,WITH_REDRAW);
278
						}
279
						break;
280
				case 23: //up!
281
						Dir_Up();
282
						break;
283
				case 24: //cut
3846 punk_joker 284
						Copy(#file_path, CUT);
3444 leency 285
						break;
3363 leency 286
				case 25: //copy
3846 punk_joker 287
						Copy(#file_path, NOCUT);
3444 leency 288
						break;
3363 leency 289
				case 26: //paste
3444 leency 290
						CreateThread(#Paste,#copy_stak);
3363 leency 291
						break;
292
				case 31...33: //sort
4022 leency 293
						IF(sort_num==1) DrawFilledBar(sorting_arrow_x,42,6,10);
294
						IF(sort_num==2) DrawFilledBar(sorting_arrow_x,42,6,10);
295
						IF(sort_num==3) DrawFilledBar(sorting_arrow_x,42,6,10);
3363 leency 296
						sort_num=id-30;
3434 leency 297
						Open_Dir(#path,WITH_REDRAW);
3363 leency 298
						break;
3434 leency 299
				case 50...60: //Actions
3444 leency 300
						FnProcess(id-50);
3363 leency 301
						break;
302
				case 100...120:
303
					DEVICE_MARK:
3444 leency 304
						DrawRectangle(17,id-100*16+74,159,16, 0); //auaaeaiea
3363 leency 305
						strcpy(#path, #disk_list[id-100].Item);
3434 leency 306
						files.first=files.current=0;
3444 leency 307
						Open_Dir(#path,WITH_REDRAW);
3363 leency 308
						pause(5);
3444 leency 309
						DrawRectangle(17,id-100*16+74,159,16, 0xFFFFFF);
3363 leency 310
						break;
311
				case 130...160:
312
						tmp_disk_del_param[1]=disk_list[id-130].Item[4];
313
						RunProgram("/sys/tmpdisk", #tmp_disk_del_param);
314
						pause(10);
3434 leency 315
						SystemDiscsGet();
3363 leency 316
						Open_Dir(#path,WITH_REDRAW);
317
						DrawLeftPanel();
318
						break;
319
			}
320
			break;
321
//Key pressed-----------------------------------------------------------------------------
322
		case evKey:
323
			key = GetKey();
324
			if (Form.status_window>2) break;
325
			IF (del_active)
326
			{
327
				IF (key==013) Del_File(true);
328
				IF (key==027) Del_File(false);
329
				break;
330
			}
3444 leency 331
			IF (edit2.flags!=64) && (key!=13) && (key!=27)
3363 leency 332
			{
333
				EAX=key<<8;
334
				edit_box_key stdcall (#edit2);
335
				break;
336
			}
337
			switch (key)
338
			{
339
					case 209...217:
340
							id=key-110;
341
							IF (id-100>=disc_num) break;
342
							GOTO DEVICE_MARK;
3434 leency 343
					case 008:
3363 leency 344
							//GoBack();
345
							Dir_Up();
346
							break;
3434 leency 347
					case 004: //Ctrl+D set as bg
3363 leency 348
							strcpy(#temp, "\\S__");
349
							strcat(#temp, #file_path);
350
							RunProgram("/sys/media/kiv", #temp);
351
							break;
3434 leency 352
					case 014: //Ctrl+N new window
3363 leency 353
							IF (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
354
							RunProgram("/sys/File Managers/Eolite", #path);
355
							break;
356
					case 024: //Ctrl+X
3444 leency 357
							Copy(#file_path, CUT);
358
							break;
3363 leency 359
					case 003: //Ctrl+C
3444 leency 360
							Copy(#file_path, NOCUT);
3363 leency 361
							break;
362
					case 022: //Ctrl+V
3444 leency 363
							CreateThread(#Paste,#copy_stak);
3363 leency 364
							break;
365
					case 027: //Esc
366
							IF (rename_active==1) ReName(false);
367
							break;
368
					case 013: //Enter
369
							IF (rename_active==1) {ReName(true); break;}
3434 leency 370
							Open();
3363 leency 371
							break;
372
					case 178: //up
3444 leency 373
							List_Current(-1);
3363 leency 374
							break;
375
					case 177: //down
3444 leency 376
							List_Current(1);
3363 leency 377
							break;
378
					case 180: //home
3434 leency 379
							files.first=0;
380
							files.current=0;
3363 leency 381
							List_ReDraw();
382
							break;
383
					case 181: //end
3447 leency 384
							files.first = files.count - files.visible;
385
							files.current = files.visible - 1;
3363 leency 386
							List_ReDraw();
387
							break;
388
					case 183: //Page Down
3444 leency 389
							List_Current(files.visible-1);
3363 leency 390
							break;
391
					case 184: //Page Up
3444 leency 392
							List_Current(-files.visible+1);
3363 leency 393
							break;
3434 leency 394
					case 182: //del
395
							Del_Form();
3363 leency 396
							break;
3434 leency 397
					case 050...059: //F1-F10
3444 leency 398
							FnProcess(key-49);
3363 leency 399
							break;
400
					default:
3434 leency 401
							for (i=files.current+files.first+1; i
3363 leency 402
							{
403
								strcpy(#temp, file_mas[i]*304+buf+72);
404
								IF (temp[0]==key) || (temp[0]==key-32)
405
								{
3444 leency 406
									List_Current(i-files.current-files.first);
3363 leency 407
									break;
408
								}
409
							}
410
			}
411
			break;
412
		case evReDraw:
4042 leency 413
			draw_window();
4028 leency 414
			if (action_buf) { menu_action(action_buf); action_buf=0;}
3363 leency 415
	}
416
}
417
 
4028 leency 418
void menu_action(dword id)
419
{
420
	if (id==COPY_PASTE_END)
421
	{
422
		FnProcess(5);
423
		SelectFile(#copy_to+strrchr(#copy_to,'/'));
424
	}
425
	if (id==100) Open();
4042 leency 426
	if (id==201)
427
	{
428
		SwitchToAnotherThread();
429
		CreateThread(#OpenWith,#open_with_stak);
430
	}
4028 leency 431
	if (id==202) FnProcess(3); //F3
432
	if (id==203) FnProcess(4); //F4
433
	if (id==104) Copy(#file_path, NOCUT);
434
	if (id==105) Copy(#file_path, CUT);
435
	if (id==106) CreateThread(#Paste,#copy_stak);
4034 leency 436
	if (id==207) FnProcess(2);
4028 leency 437
	if (id==108) Del_Form();
438
	if (id==109) FnProcess(5);
439
}
3363 leency 440
 
4028 leency 441
 
3444 leency 442
void draw_window()
443
{
444
	DefineAndDrawWindow(40,20,550,500,0x73,col_work,TITLE);
445
	GetProcessInfo(#Form, SelfInfo);
446
	if (Form.status_window>2) return;
447
	files.SetSizes(192, 57, onLeft(192,27), onTop(57,6), disc_num*16+195,files.line_h);
448
	if (Form.height < files.min_h) MoveSize(OLD,OLD,OLD,files.min_h);
449
	if (Form.width<480) MoveSize(OLD,OLD,480,OLD);
450
	GetProcessInfo(#Form, SelfInfo); //if win_size changed
451
 
3363 leency 452
	PutPaletteImage(#toolbar,246,34,0,0,8,#toolbar_pal);
3444 leency 453
	DrawBar(127, 8, 1, 25, col_border);
3363 leency 454
	for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,col_work);
455
	for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,col_work);
3444 leency 456
	DrawBar(246,0,onLeft(246,60),12, col_work); //upper editbox
457
	DrawBar(246,29,onLeft(246,60),5,col_work);  //under editbox
458
	DrawRectangle(246,12,onLeft(66,246),16,col_border);
459
	DefineButton(onLeft(34,0),6,27,28,51+BT_HIDE+BT_NOFRAME,0); //about
3363 leency 460
	PutPaletteImage(#goto_about,56,34,Form.width-65,0,8,#goto_about_pal);
3434 leency 461
	//main rectangles
3444 leency 462
	DrawRectangle(1,40,Form.cwidth-3,onTop(46,0),col_border);
463
	DrawRectangle(0,39,Form.cwidth-1,onTop(44,0),col_palette[4]); //bg
3363 leency 464
	for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
465
	DrawLeftPanel();
3434 leency 466
	//ListBox
3848 punk_joker 467
	DrawFlatButton(files.x,40,onLeft(files.x,168),16,31,col_work,T_FILE);
468
	DrawFlatButton(onLeft(168,0),40,73,16,32,col_work,T_TYPE);
469
	DrawFlatButton(onLeft(95,0),40,68,16,33,col_work,T_SIZE);
4042 leency 470
	DrawBar(onLeft(27,0),files.y,1,onTop(22,files.y),col_border); //line to the left from the scroll
3434 leency 471
	DrawFlatButton(onLeft(27,0),40,16,16,0,col_work,"\x18");
472
	DrawFlatButton(onLeft(27,0),onTop(22,0),16,16,0,col_work,"\x19");
3363 leency 473
	Open_Dir(#path,ONLY_SHOW);
474
	if (del_active) Del_Form();
4002 leency 475
	//if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
3444 leency 476
	if (rename_active) FnProcess(2);
3363 leency 477
}
478
 
479
 
480
void KEdit()
481
{
3434 leency 482
	if (Form.width<480) return;
3363 leency 483
	PathShow.area_size_x = Form.cwidth-306;
484
	DrawBar(PathShow.start_x-3, PathShow.start_y-4, PathShow.area_size_x+2, 15, 0xFFFfff);
485
	PathShow_prepare stdcall(#PathShow);
486
	PathShow_draw stdcall(#PathShow);
487
}
488
 
489
 
3444 leency 490
void List_Current(int cur)
3363 leency 491
{
3434 leency 492
	if (cur<=0) //up
3363 leency 493
	{
3434 leency 494
		IF (files.first==0) && (files.current<=0) return;
495
		IF (-cur-1
3363 leency 496
		{
3434 leency 497
			Line_ReDraw(0xFFFFFF, files.current);
498
			files.current+=cur;
499
			Line_ReDraw(col_selec, files.current);
3363 leency 500
			return;
501
		}
502
		ELSE
503
		{
3434 leency 504
			IF (-cur
505
			files.current=0;
3363 leency 506
			List_ReDraw();
507
			return;
508
		}
509
	}
3434 leency 510
	else  //down
3363 leency 511
	{
3434 leency 512
		IF (files.first==files.count-files.visible) && (files.current==files.visible-1) return;
513
		IF (files.visible-files.current>cur)
3363 leency 514
		{
3434 leency 515
			Line_ReDraw(0xFFFFFF, files.current);
516
			files.current+=cur;
517
			Line_ReDraw(col_selec, files.current);
3363 leency 518
			return;
519
		}
520
		else
521
		{
3434 leency 522
			IF(files.first+files.current+cur>=files.count)
3363 leency 523
			{
3434 leency 524
				files.first=files.count-files.visible;
525
				files.current=cur-files.first+files.current;
3363 leency 526
				}
527
			ELSE
528
			{
3434 leency 529
				files.first+=cur+files.current-files.visible+1;
530
				files.current=files.visible-1;
3363 leency 531
			}
532
 
3434 leency 533
			IF (files.current<0) || (files.current>files.visible)
3363 leency 534
			{
3434 leency 535
				files.current=files.visible-1;
3363 leency 536
			}
537
			List_ReDraw();
538
		}
539
	}
540
}
541
 
542
 
543
void List_ReDraw()
544
{
3434 leency 545
	int paint_y;
3876 leency 546
	//we are in the end of the list => maximize window => there will be white lines after the last element
3434 leency 547
	if (files.count-files.firstfiles.visible-1)
548
	{ files.first=files.count-files.visible; files.current=files.visible-1; }
3444 leency 549
	for (j=0; j
3434 leency 550
	//in the bottom
551
	paint_y = j * files.line_h + files.y;
552
	DrawBar(files.x,paint_y,files.w,onTop(paint_y,6),0xFFFFFF);
3447 leency 553
	DrawBar(Form.cwidth-159,paint_y,1,onTop(paint_y,6),col_work);
554
	DrawBar(Form.cwidth-86,paint_y,1,onTop(paint_y,6),col_work);
3434 leency 555
	Scroll();
3363 leency 556
}
557
 
3444 leency 558
 
3363 leency 559
void Line_ReDraw(dword color, filenum){
3467 leency 560
	dword text_col=0,
561
	      name_len=0,
562
	      attr,
4042 leency 563
	      y=filenum*files.line_h+files.y;
3447 leency 564
	DrawBar(files.x,y,3,files.line_h,color);
565
	DrawBar(files.x+19,y,files.w-19,files.line_h,color);
566
	DrawBar(files.x+3,y+17,16,1,color);
567
	if (files.line_h>18) DrawBar(files.x+3,y+18,16,files.line_h-18,color);
568
	if (files.line_h>15) DrawBar(files.x+3,y,16,files.line_h-15,color);
3363 leency 569
 
3434 leency 570
	off=file_mas[filenum+files.first]*304 + buf+72;
3467 leency 571
	attr = ESDWORD[off - 40];
3363 leency 572
 
3467 leency 573
	if (! TestBit(attr, 4) ) //file or folder?
3363 leency 574
	{
4049 leency 575
		Put_icon(off+_strrchr(off,'.'), files.x+3, files.line_h/2-7+y, color);
3434 leency 576
		WriteText(7-strlen(ConvertMemSize(ESDWORD[off-8]))*6+onLeft(75,0),files.line_h-6/2+y,0x80,0,ConvertMemSize(ESDWORD[off-8])); //size
3363 leency 577
	}
578
	else
579
		if (!strcmp("..",off))
4049 leency 580
			Put_icon("..", files.x+3, files.line_h/2-7+y, color);
3363 leency 581
		else
4049 leency 582
			Put_icon("", files.x+3, files.line_h/2-7+y, color);
3467 leency 583
	if ( TestBit(attr, 1) ) || ( TestBit(attr, 2) ) text_col=0xA6A6B7; //system or hiden?
3444 leency 584
	if (color!=0xFFFfff)
3363 leency 585
	{
3467 leency 586
		itdir = TestBit(attr, 4);
3363 leency 587
		strcpy(#file_name, off);
588
		strcpy(#file_path, #path);
3434 leency 589
		strcat(#file_path, #file_name);
3363 leency 590
		if (text_col==0xA6A6B7) text_col=0xFFFFFF;
591
	}
3434 leency 592
	if (Form.width>=480)
593
	{
3447 leency 594
		FileShow.start_x = files.x + 23;
3434 leency 595
		FileShow.font_color = text_col;
596
		FileShow.area_size_x = Form.width - 380;
597
		FileShow.text_pointer = off;
598
		FileShow.start_y = files.line_h/2-3+y;
599
		PathShow_prepare stdcall(#FileShow);
600
		PathShow_draw stdcall(#FileShow);
601
	}
3447 leency 602
	DrawBar(Form.cwidth-159,y,1,files.line_h,col_work); //gray line 1
603
	DrawBar(Form.cwidth-86,y,1,files.line_h,col_work); //gray line 2
3363 leency 604
}
605
 
606
 
3444 leency 607
void Open_Dir(dword dir_path, redraw){
608
	int errornum, maxcount;
3434 leency 609
 
3444 leency 610
	if (redraw!=ONLY_SHOW)
3363 leency 611
	{
3444 leency 612
		if (ESBYTE[dir_path+1]!='\0') ESBYTE[dir_path+strlen(dir_path)-1] = '\0';
3363 leency 613
		if (buf) free(buf);
3444 leency 614
		errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
615
		if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
616
		if (errornum)
3363 leency 617
		{
618
			HistoryPath(ADD_NEW_PATH);
619
			GoBack();
620
			Write_Error(errornum);
621
			return;
622
		}
3444 leency 623
		maxcount = sizeof(file_mas)/sizeof(dword)-1;
624
		if (files.count>maxcount) files.count = maxcount;
3363 leency 625
	}
3444 leency 626
	if (files.count!=-1)
3363 leency 627
	{
628
		KEdit();
629
		HistoryPath(ADD_NEW_PATH);
3444 leency 630
		files.visible = files.h / files.line_h;
631
		IF (files.count < files.visible) files.visible = files.count;
4022 leency 632
		IF (sort_num==1) sorting_arrow_x = Form.width+60/2;
633
		IF (sort_num==2) sorting_arrow_x = Form.width-115;
634
		IF (sort_num==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
635
		WriteText(sorting_arrow_x,45,0x80,col_border,"\x19");
3444 leency 636
		IF (redraw!=ONLY_SHOW) Sorting();
637
		IF (redraw!=ONLY_OPEN) List_ReDraw();
3363 leency 638
	}
3444 leency 639
	IF (files.count==-1) && (redraw!=ONLY_OPEN) {files.visible=files.count=0; List_ReDraw();}
3363 leency 640
}
641
 
642
 
643
inline Sorting()
644
{
645
	dword k=0, l=1;
646
	int i;
3434 leency 647
	if (!strcmp(#path,"/")) //do not sort
3363 leency 648
	{
3434 leency 649
		FOR(k=1;k
3363 leency 650
		return;
651
	}
3434 leency 652
	FOR (j=files.count-1, off=files.count-1*304+buf+32; j>=0; j--, off-=304;)  //files | folders
3363 leency 653
	{
654
		strttl(off+40);
3441 leency 655
		if (TestBit(ESDWORD[off],4)) //directory?
3363 leency 656
		{
657
			file_mas[k]=j;
658
			k++;
659
		}
660
		else
661
		{
3434 leency 662
			file_mas[files.count-l]=j;
3363 leency 663
			l++;
664
		}
665
	}
3434 leency 666
	//sorting: files first, then folders
3363 leency 667
	Sort_by_Name(0,k-1);
3434 leency 668
	IF (sort_num==1) Sort_by_Name(k,files.count-1);
669
	IF (sort_num==2) Sort_by_Type(k,files.count-1);
670
	IF (sort_num==3) Sort_by_Size(k,files.count-1);
671
	//".." should be first
3444 leency 672
	IF (k>0) && (strcmp(file_mas[0]*304+buf+72,"..")!=0)
673
		FOR(k--; k>0; k--;) IF (!strcmp(file_mas[k]*304+buf+72,"..")) {file_mas[k]>
3363 leency 674
}
675
 
676
 
677
void Del_Form()
678
{
4002 leency 679
	int dform_x=files.w-220/2+files.x;
4022 leency 680
	if (strcmp(#file_name,".")==0) || (strcmp(#file_name,"..")==0) return;
4002 leency 681
	if (del_active==2)
3991 leency 682
	{
4002 leency 683
		if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
3991 leency 684
	}
685
	else
686
	{
4002 leency 687
		if (!files.count) return;
688
		DrawPopup(dform_x,160,220,80,1,col_work,col_border);
689
		WriteText(-strlen(T_DELETE_FILE)*3+110+dform_x,175,0x80,0,T_DELETE_FILE);
690
		IF (strlen(#file_name)<28)
691
		{
692
			WriteText(strlen(#file_name)*3+110+dform_x+2,190,0x80,0,"?");
693
			WriteText(-strlen(#file_name)*3+110+dform_x,190,0x80,0,#file_name);
694
		}
695
		else
696
		{
697
			WriteText(164+dform_x,190,0x80,0,"...?");
698
			ESI = 24;
699
			WriteText(dform_x+20,190,0,0,#file_name);
700
		}
701
		DrawFlatButton(dform_x+27,208,70,20,301,0xFFB6B5,T_YES);
702
		DrawFlatButton(dform_x+120,208,70,20,302,0xC6DFC6,T_NO);
703
		del_active=1;
3991 leency 704
	}
3363 leency 705
}
706
 
4022 leency 707
int del_error;
708
int Del_File2(dword way)
3980 punk_joker 709
{
710
	dword dirbuf, fcount, i, filename;
4022 leency 711
	int error;
712
	char del_from[4096];
713
	if (isdir(way))
3997 leency 714
	{
4022 leency 715
		if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
3997 leency 716
		for (i=0; i
3980 punk_joker 717
		{
4002 leency 718
			if (CheckEvent()==evReDraw) draw_window();
3997 leency 719
			filename = i*304+dirbuf+72;
720
			strcpy(#del_from, way);
721
			chrcat(#del_from, '/');
722
			strcat(#del_from, filename);
723
			if ( TestBit(ESDWORD[filename-40], 4) )
724
				Del_File2(#del_from);
725
			else
4022 leency 726
			{
727
				if (error = DeleteFile(#del_from)) del_error = error;
728
			}
3980 punk_joker 729
		}
3997 leency 730
	}
4022 leency 731
	if (error = DeleteFile(way)) del_error = error;
3980 punk_joker 732
}
733
 
734
 
3363 leency 735
void Del_File(byte dodel)
4022 leency 736
{
3980 punk_joker 737
	if (dodel==true)
3363 leency 738
	{
4002 leency 739
		del_active=2;
3997 leency 740
		if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
4022 leency 741
		del_error = 0;
3980 punk_joker 742
		Del_File2(#file_path);
4022 leency 743
		if (del_error) Write_Error(del_error);
3363 leency 744
 	}
745
	del_active=0;
3997 leency 746
	DeleteButton(301);
747
	DeleteButton(302);
3444 leency 748
	Open_Dir(#path,WITH_REDRAW);
3363 leency 749
}
750
 
751
 
752
void ReName(byte rename)
753
{
3404 leency 754
	int del_rezult, copy_rezult;
3363 leency 755
	char edit_name[256];
756
	rename_active=0;
757
	edit2.flags=64;
758
	if (rename==true)
759
	{
760
		strcpy(#temp, #path);
3434 leency 761
		strcpy(#edit_name, #file_name); //save edit name to select it later
3363 leency 762
		strcat(#temp, #file_name);
3444 leency 763
		if (strcmp(#file_path,#temp)!=0) && (file_name)
764
		if (itdir)
3363 leency 765
		{
4029 leency 766
			if (del_rezult = DeleteFile(#file_path))
3363 leency 767
			{
3404 leency 768
				Write_Error(del_rezult);
3997 leency 769
				ShowMessage(T_DEL_ERROR_1, 150);
3363 leency 770
				return;
771
			}
4029 leency 772
			if (CreateDir(#temp)) CreateDir(#file_path);
3444 leency 773
			Open_Dir(#path,WITH_REDRAW);
4029 leency 774
			SelectFile(#edit_name);
3363 leency 775
		}
3877 leency 776
		else
3363 leency 777
		{
4029 leency 778
			if (copy_rezult = CopyFile(#file_path,#temp))
779
			{
780
				Write_Error(copy_rezult);
781
			}
782
			else
783
			{
784
				Del_File(true);
785
				SelectFile(#edit_name);
786
			}
3363 leency 787
		}
788
	}
3434 leency 789
	Line_ReDraw(col_selec,files.current);
3363 leency 790
}
791
 
792
 
793
void SelectFile(dword that_file)
794
{
3434 leency 795
	files.first=files.current=0;
3363 leency 796
   	Open_Dir(#path,ONLY_OPEN);
797
	strttl(that_file);
3434 leency 798
	for (i=files.count-1; i>=0; i--;)
3363 leency 799
		if (!strcmp(file_mas[i]*304+buf+72,that_file)) break;
3444 leency 800
	List_Current(i);
3363 leency 801
	List_ReDraw();
802
}
803
 
804
 
805
void Dir_Up()
806
{
807
	char cur_folder[4096];
808
	i=strlen(#path)-1;
809
	if (i==0) return;
810
	path[i]=0x00;
811
	i = strrchr(#path, '/');
812
	strcpy(#cur_folder, #path+i);
813
	path[i]=0x00;
814
	SelectFile(#cur_folder);
815
}
816
 
3434 leency 817
void Open()
818
{
3444 leency 819
	if (!files.count) return;
3441 leency 820
	if (!itdir)
3434 leency 821
	{
822
		GetIni(0);
823
	}
824
	else
825
	{
826
		if (!strcmp(#file_name,"..")) { Dir_Up(); return; }
827
		strcpy(#path, #file_path);
828
		if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //need "/" in the end
829
		files.first=files.current=0;
3444 leency 830
		Open_Dir(#path,WITH_REDRAW);
3434 leency 831
	}
832
}
3363 leency 833
 
3434 leency 834
 
835
inline fastcall void GoBack()
3363 leency 836
{
837
	char cur_folder[4096];
838
	strcpy(#cur_folder, GetCurrentFolder());
839
	if (HistoryPath(GO_BACK)) SelectFile(#cur_folder);
840
}
841
 
3444 leency 842
void FnProcess(char N)
3434 leency 843
{
844
	switch(N)
845
	{
846
		case 1:
847
			SwitchToAnotherThread();
3444 leency 848
			CreateThread(#about_dialog,#about_stak);
3434 leency 849
			break;
850
		case 2:
851
			if (!files.count) break;
3447 leency 852
			edit2.flags = 100000000000010b; //set active
853
			edit2.left = files.x + 21;
854
			edit2.width = files.w - 26;
3434 leency 855
			edit2.top=files.current*files.line_h+59;
856
			edit2.size=edit2.pos=strlen(#file_name);
857
			edit_box_draw  stdcall (#edit2);
3447 leency 858
			DrawBar(edit2.left,files.current*files.line_h+58,edit2.width+1,1,0xFFFFCC); //bg
3434 leency 859
			rename_active=1;
860
			break;
861
		case 3:
3441 leency 862
			IF (!itdir) RunProgram("/sys/tinypad", #file_path);
3434 leency 863
			break;
864
		case 4:
3441 leency 865
			IF (!itdir) RunProgram("/sys/develop/heed", #file_path);
3434 leency 866
			break;
3440 leency 867
		case 5: //refresh cur dir & devs
3854 leency 868
			Tip(56, T_DEVICES, 55, "-");
3440 leency 869
			Open_Dir(#path,WITH_REDRAW);
870
			pause(10);
871
			GetIni(1);
872
			SystemDiscsGet();
3444 leency 873
			Open_Dir(#path,WITH_REDRAW);
3440 leency 874
			DrawLeftPanel();
3434 leency 875
			break;
876
		case 6:
877
			strcpy(#temp, #path);
3848 punk_joker 878
			strcat(#temp, T_NEW_FOLDER);
3434 leency 879
			CreateDir(#temp);
880
			if (!EAX){
3848 punk_joker 881
				SelectFile(T_NEW_FOLDER);
3444 leency 882
				FnProcess(2);
3434 leency 883
			}
884
			else
885
			{
886
				Write_Error(EAX);
3997 leency 887
				ShowMessage(NOT_CREATE_FOLDER, 150);
3434 leency 888
			}
889
			break;
890
		case 7:
891
			strcpy(#temp, #path);
3848 punk_joker 892
			strcat(#temp, T_NEW_FILE);
3434 leency 893
			WriteFile(0, 0, #temp);
894
			if (!EAX){
3848 punk_joker 895
				SelectFile(T_NEW_FILE);
3444 leency 896
				FnProcess(2);
3434 leency 897
			}
898
			else
899
			{
900
				Write_Error(EAX);
3997 leency 901
				ShowMessage(NOT_CREATE_FILE, 150);
3434 leency 902
			}
903
			break;
904
		case 10: //F10
905
			RunProgram(EDITOR_PATH, abspath("Eolite.ini"));
906
			break;
907
	}
908
}
909
 
910
 
3363 leency 911
stop:
912
 
3444 leency 913
char about_stak[512];
914
char menu_stak[512];
4042 leency 915
char open_with_stak[512];
3846 punk_joker 916
char copy_stak[4096];