Subversion Repositories Kolibri OS

Rev

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