Subversion Repositories Kolibri OS

Rev

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