Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8750 leency 1
//Leency, Veliant, Punk_Joker, PavelYakov & KolibriOS Team 2008-2021
7490 leency 2
//GNU GPL license.
3363 leency 3
 
8952 leency 4
/*
8953 leency 5
BUGS:
8983 leency 6
- F1 in KFM (move Properties to an external app)
8952 leency 7
TODO:
9275 leency 8
- add option Preserve all timestamps (Created, Opened, Modified)
9
  http://board.kolibrios.org/viewtopic.php?f=23&t=4521&p=77334#p77334
8952 leency 10
*/
7361 leency 11
 
9461 leency 12
#define ABOUT_TITLE "EOLITE 5.16"
13
#define TITLE_EOLITE "Eolite File Manager 5.16"
14
#define TITLE_KFM "Kolibri File Manager 2.16";
8012 leency 15
 
8417 leency 16
#define MEMSIZE 1024 * 250
7054 leency 17
#include "../lib/clipboard.h"
18
#include "../lib/strings.h"
19
#include "../lib/mem.h"
7219 leency 20
#include "../lib/fs.h"
7054 leency 21
#include "../lib/gui.h"
22
#include "../lib/list_box.h"
23
#include "../lib/random.h"
24
#include "../lib/kfont.h"
25
#include "../lib/collection.h"
26
#include "../lib/copyf.h"
5834 pavelyakov 27
 
7054 leency 28
#include "../lib/obj/libini.h"
29
#include "../lib/obj/box_lib.h"
7230 leency 30
#include "../lib/obj/libimg.h"
7054 leency 31
 
32
#include "../lib/patterns/history.h"
33
 
7462 leency 34
#include "imgs/images.h"
8947 leency 35
#include "include/const.h"
8854 leency 36
 
7634 leency 37
struct Eolite_colors
38
{
8953 leency 39
	bool  skin_is_dark;
7634 leency 40
	dword lpanel;
41
	dword list_vert_line; //vertical line between columns in list
42
	dword selec;
43
	dword selec_active;
44
	dword selec_inactive;
45
	dword selec_text;
46
	dword list_bg;
47
	dword list_gb_text;
48
	dword list_text_hidden;
49
	dword work_gradient[24];
50
	dword slider_bg_big;
51
	dword slider_bg_left;
52
	dword odd_line;
53
} col;
8240 leency 54
dword waves_pal[256];
3363 leency 55
 
8953 leency 56
//Global data
57
	bool efm = false;
58
	_history history;
8764 leency 59
 
8947 leency 60
//Folder data
8956 leency 61
	dword buf, buf_inactive;
8947 leency 62
	collection_int items=0;
63
	int folder_count;
8949 leency 64
	dword path;
8952 leency 65
	bool dir_at_fat16 = NULL;
5698 leency 66
 
8953 leency 67
//Selected element data
8947 leency 68
	byte file_path[4096];
69
	byte file_name[256];
70
	byte temp[4096];
71
	bool itdir;
3363 leency 72
 
8947 leency 73
//Window data
74
	proc_info Form;
75
	int sc_slider_h;
76
	bool scroll_used=false;
77
	char sort_type=2;
78
	bool sort_desc=false;
79
	int status_bar_h;
80
	int icon_size = 18;
8953 leency 81
	char active_popin = NULL;
82
	bool list_full_redraw;
5698 leency 83
 
8952 leency 84
//Threads data
85
	dword about_thread_id;
86
	dword settings_window;
87
	bool active_about = false;
88
	bool active_settings = false;
89
	dword about_stak=0,properties_stak=0,settings_stak=0;
90
	byte cmd_free=0;
5695 leency 91
 
8952 leency 92
//Multipanes
93
	int active_panel=0;
94
	#define PANES_COUNT 2
95
	dword location[PANES_COUNT];
8953 leency 96
	llist files, files_active, files_inactive;
8983 leency 97
	collection_int selected0, selected1;
98
	dword selected_count[PANES_COUNT]=0;
5608 leency 99
 
7054 leency 100
libimg_image icons16_default;
101
libimg_image icons16_selected;
7242 leency 102
libimg_image icons32_default;
103
libimg_image icons32_selected;
7197 leency 104
 
8953 leency 105
byte popin_string[4096];
106
edit_box popin_text = {200,213,180,0xFFFFFF,0x94AECE,0xFFFFFF,0xFFFFFF,0x10000000,
107
	248,#popin_string,0,ed_focus+ed_always_focus,6,0};
108
 
7004 leency 109
PathShow_data FileShow = {0, 56,215, 8, 100, 1, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
5834 pavelyakov 110
 
8951 leency 111
#include "include\settings.h"
7462 leency 112
#include "include\gui.h"
5804 punk_joker 113
#include "include\progress_dialog.h"
7878 leency 114
#include "include\copy_and_delete.h"
3363 leency 115
#include "include\sorting.h"
4042 leency 116
#include "include\icons.h"
3363 leency 117
#include "include\left_panel.h"
4042 leency 118
#include "include\menu.h"
119
#include "include\about.h"
5447 punk_joker 120
#include "include\properties.h"
3363 leency 121
 
7878 leency 122
void handle_param()
123
{
7879 leency 124
	//-p  : just show file/folder properties dialog
125
	//-d  : delete file/folder
126
	//-v : paste files/folder from clipboard
8947 leency 127
	int i;
8764 leency 128
	dword p = #param;
8983 leency 129
	if (streq(#program_path+strrchr(#program_path,'/'), "KFM")) {
130
		efm = true;
131
		//now we need to restore the original app name
132
		//without this external operations down won't work
133
		strcpy(#program_path+strrchr(#program_path,'/'), "EOLITE");
134
	}
8764 leency 135
 
8779 leency 136
	LoadIniSettings();
137
 
8947 leency 138
	for (i=0; i
139
		location[i] = malloc(4096);
140
		strcpy(location[i], #path_start);
141
	}
8949 leency 142
	path = location[0];
8947 leency 143
 
8764 leency 144
	if (ESBYTE[p]=='\0') return;
145
 
9269 leency 146
	if (ESBYTE[p]=='-') switch (ESBYTE[p+1])
7878 leency 147
	{
148
		case 'p':
8764 leency 149
			strcpy(#file_path, p + 3);
7920 leency 150
			itdir = dir_exists(#file_path);
8764 leency 151
			strcpy(#file_name, p + strrchr(p, '/'));
152
			ESBYTE[strrchr(p, '/')+p-1] = '\0';
8949 leency 153
			strcpy(path, p + 3);
7878 leency 154
			properties_dialog();
8020 leency 155
			ExitProcess();
7878 leency 156
		case 'd':
8949 leency 157
			strcpy(path, p + 3);
8861 leency 158
			DeleteThread();
8020 leency 159
			ExitProcess();
7879 leency 160
		case 'v':
8764 leency 161
			cut_active = ESBYTE[p+2] - '0';
8949 leency 162
			strcpy(path, p + 4);
7879 leency 163
			PasteThread();
8020 leency 164
			ExitProcess();
7878 leency 165
	}
8764 leency 166
 
9275 leency 167
	if (param[strlen(#param)-1]=='/') param[strlen(#param)-1]='\0'; //no "/" at the end
8779 leency 168
 
8764 leency 169
	if (dir_exists(p)) {
8949 leency 170
		strcpy(path, p);
8764 leency 171
	} else {
172
		if (file_exists(p)) {
173
			ESBYTE[strrchr(p, '/')+p-1] = '\0';
8949 leency 174
			strcpy(path, p);
175
			SelectFileByName(p+strlen(path)+1);
8764 leency 176
		} else {
177
			notify(T_NOTIFY_APP_PARAM_WRONG);
178
		}
9269 leency 179
	}
7878 leency 180
}
181
 
9269 leency 182
void main()
3363 leency 183
{
6289 leency 184
	dword id;
7993 leency 185
	int old_cur_y;
7786 leency 186
 
8947 leency 187
	load_dll(boxlib, #box_lib_init,0);
188
	load_dll(libini, #lib_init,1);
189
	load_dll(libimg, #libimg_init,1);
190
 
8765 leency 191
	SetAppColors();
8764 leency 192
	handle_param();
5651 pavelyakov 193
 
6034 leency 194
	SystemDiscs.Get();
8956 leency 195
	OpenDir(ONLY_OPEN);
5733 leency 196
	llist_copy(#files_inactive, #files);
7051 leency 197
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
8947 leency 198
	loop() switch(@WaitEventTimeout(100))
7786 leency 199
	{
200
		case evMouse:
8953 leency 201
			if (Form.status_window&ROLLED_UP) break;
202
 
203
			if (active_popin) {
204
				if (popin_string[0]!=-1) edit_box_mouse stdcall(#popin_text);
7786 leency 205
				break;
8953 leency 206
			}
9269 leency 207
 
7786 leency 208
			mouse.get();
7422 leency 209
 
7786 leency 210
			ProceedMouseGestures();
7989 leency 211
 
7993 leency 212
			if (mouse.vert)
213
			{
214
				if (files.MouseScroll(mouse.vert)) List_ReDraw();
7989 leency 215
				break;
216
			}
7993 leency 217
 
7786 leency 218
			if (files.MouseOver(mouse.x, mouse.y))
219
			{
220
				//select file
221
				if (mouse.key&MOUSE_LEFT) && (mouse.up)
5549 punk_joker 222
				{
9276 leency 223
					GetKeyModifier();
7993 leency 224
					old_cur_y = files.cur_y;
9276 leency 225
					if (files.ProcessMouse(mouse.x, mouse.y)) && (!key_modifier) {
8012 leency 226
						List_ReDraw();
9276 leency 227
						break;
8012 leency 228
					}
9276 leency 229
					if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
230
						EventChooseFilesRange(old_cur_y, files.cur_y);
7993 leency 231
					} else if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
232
						EventChooseFile(files.cur_y);
233
						DrawStatusBar();
7989 leency 234
						List_ReDraw();
9276 leency 235
					} else {
236
						if (mouse.y - files.y / files.item_h + files.first == files.cur_y) EventOpen(0);
7786 leency 237
					}
5591 pavelyakov 238
				}
7786 leency 239
				//file menu
240
				if (mouse.key&MOUSE_RIGHT) && (mouse.up)
5591 pavelyakov 241
				{
7786 leency 242
					if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw();
9269 leency 243
					if (getElementSelectedFlag(files.cur_y) == false) unselectAll(); //on redraw selection would be flashed, see [L001]
7786 leency 244
					EventShowListMenu();
245
				}
246
			}
247
 
248
			if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y-17) && (mouse.y
249
			{
7806 leency 250
				if (mouse.lkm) DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,sc.work_dark,sc.work_light);
7786 leency 251
				WHILE (mouse.lkm) && (files.first>0)
5549 punk_joker 252
				{
7786 leency 253
					pause(8);
254
					files.first--;
255
					List_ReDraw();
256
					mouse.get();
5575 pavelyakov 257
				}
7806 leency 258
				DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,sc.work_light,sc.work_dark);
7786 leency 259
			}
5591 pavelyakov 260
 
7786 leency 261
			if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y+files.h-16) && (mouse.y
262
			{
7806 leency 263
				if (mouse.lkm) DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,sc.work_dark,sc.work_light);
7786 leency 264
				while (mouse.lkm) && (files.first
5575 pavelyakov 265
				{
7786 leency 266
					pause(8);
267
					files.first++;
268
					List_ReDraw();
269
					mouse.get();
5591 pavelyakov 270
				}
7806 leency 271
				DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,sc.work_light,sc.work_dark);
7786 leency 272
			}
5591 pavelyakov 273
 
7786 leency 274
			//Scrooll
9269 leency 275
			if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+18) && (mouse.y>files.y)
8947 leency 276
				&& (mouse.y
277
			if (scroll_used) && (!mouse.key&MOUSE_LEFT) { scroll_used=false; DrawScroll(scroll_used); }
9269 leency 278
 
7786 leency 279
			if (scroll_used)
280
			{
281
				if (sc_slider_h/2+files.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=sc_slider_h/2+files.y; //anee eo?ni? iaa ieiii
282
				id = files.first;
283
				files.first = -sc_slider_h / 2 + mouse.y -files.y * files.count;
284
				files.first /= files.h - 18;
285
				if (files.visible+files.first>files.count) files.first=files.count-files.visible;
286
				if (files.first<0) files.first=0;
287
				if (id!=files.first) List_ReDraw();
288
				break;
289
			}
290
 
8902 leency 291
			if (efm) && (mouse.y < files.y + files.h) && (mouse.down) {
8872 leency 292
				if (mouse.x
8946 leency 293
					SetActivePanel(0);
8861 leency 294
				} else {
8946 leency 295
					SetActivePanel(1);
3363 leency 296
				}
7786 leency 297
			}
9269 leency 298
			break;
7786 leency 299
//Button pressed-----------------------------------------------------------------------------
300
		case evButton:
8417 leency 301
			id = GetButtonID();
3363 leency 302
 
8953 leency 303
			if (CLOSE_BTN == id) {
8872 leency 304
				KillProcess(about_thread_id);
305
				SaveIniSettings();
306
				ExitProcess();
307
			}
308
 
8953 leency 309
			if (active_popin) {
8956 leency 310
				if (POPUP_BTN2==id) { EventClosePopinForm(); break; }
311
				if (POPUP_BTN1==id) { EventPopinClickOkay(); break; }
312
 
8953 leency 313
				if (POPIN_DISK==active_popin) {
8956 leency 314
					active_popin = NULL;
315
					EventDriveClick(id-100);
316
				}
317
 
318
				if (POPIN_BREADCR==active_popin) {
319
					EventClosePopinForm();
320
					ClickOnBreadCrumb(id-BREADCRUMB_ID);
321
				}
322
 
9269 leency 323
				break;
7786 leency 324
			}
5719 leency 325
 
9269 leency 326
			switch(id)
7786 leency 327
			{
8854 leency 328
				case KFM_DEV_DROPDOWN_1:
329
				case KFM_DEV_DROPDOWN_2:
8953 leency 330
						ShowPopinForm(POPIN_DISK);
7786 leency 331
						break;
8854 leency 332
				case BACK_BTN...PASTE_BTN:
333
						EventToolbarButtonClick(id);
7786 leency 334
						break;
8953 leency 335
				case BTN_PATH:
336
				case BTN_PATH+1:
337
						ShowPopinForm(POPIN_PATH);
338
						break;
339
				case BTN_BREADCRUMB:
340
				case BTN_BREADCRUMB+1:
341
						ShowPopinForm(POPIN_BREADCR);
342
						break;
7786 leency 343
				case 31...33:
344
						EventSort(id-30);
345
						break;
7813 leency 346
				case 51:
347
						EventShowBurgerMenu();
348
						break;
349
				case 52...60: //Actions
7786 leency 350
						FnProcess(id-50);
351
						break;
8953 leency 352
				case 100...120:
8956 leency 353
						EventDriveClick(id-100);
7786 leency 354
						break;
8881 leency 355
				case KFM_FUNC_ID...KFM_FUNC_ID+10:
8953 leency 356
						FnProcess(id-KFM_FUNC_ID);
357
						break;
7786 leency 358
			}
359
			break;
9269 leency 360
 
7786 leency 361
//Key pressed-----------------------------------------------------------------------------
362
		case evKey:
363
			GetKeys();
7398 leency 364
 
8946 leency 365
			if (Form.status_window&ROLLED_UP) break;
7786 leency 366
 
8953 leency 367
			if (active_popin)
7786 leency 368
			{
8861 leency 369
				if (key_scancode == SCAN_CODE_ESC) EventClosePopinForm();
370
 
8953 leency 371
				if (POPIN_DISK == active_popin) {
9269 leency 372
					if (key_scancode >= SCAN_CODE_1)
8956 leency 373
						&& (key_scancode <= SCAN_CODE_10) {
374
							EventDriveClick(key_scancode-2);
8953 leency 375
						}
376
				} else {
377
					if (key_scancode == SCAN_CODE_ENTER) EventPopinClickOkay();
378
					if (popin_string[0] != -1) {
379
						EAX = key_editbox;
380
						edit_box_key stdcall (#popin_text);
9269 leency 381
					}
7398 leency 382
				}
7786 leency 383
				break;
384
			}
7398 leency 385
 
9341 leency 386
			if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT)
387
			{
8417 leency 388
				if (key_scancode == SCAN_CODE_ENTER) {
9269 leency 389
					EventOpenSelected();
8417 leency 390
					break;
391
				}
7993 leency 392
				old_cur_y = files.cur_y;
393
				files.ProcessKey(key_scancode);
394
				EventChooseFilesRange(old_cur_y, files.cur_y);
7989 leency 395
				break;
396
			}
397
 
7786 leency 398
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
399
			{
400
				switch(key_scancode)
5591 pavelyakov 401
				{
7786 leency 402
					case SCAN_CODE_F1...SCAN_CODE_F3:
403
							EventSort(key_scancode - 58);
7422 leency 404
							break;
8953 leency 405
					case SCAN_CODE_1...SCAN_CODE_2:
406
							if (efm) {
407
								active_panel = key_scancode - SCAN_CODE_1;
408
								ShowPopinForm(POPIN_DISK);
409
								break;
410
							}
411
					case SCAN_CODE_3...SCAN_CODE_10:
7786 leency 412
							key_scancode-=2;
413
							if (key_scancode >= SystemDiscs.list.count) break;
8861 leency 414
							if (!efm) {
8956 leency 415
								DrawRectangle(17,key_scancode*17+74,159,17, 0); //display click
9269 leency 416
								pause(7);
5591 pavelyakov 417
							}
8956 leency 418
							EventDriveClick(key_scancode);
5591 pavelyakov 419
							break;
7786 leency 420
					case SCAN_CODE_KEY_X:
8861 leency 421
							CopyFilesListToClipboard(CUT);
9269 leency 422
							break;
7786 leency 423
					case SCAN_CODE_KEY_C:
8861 leency 424
							CopyFilesListToClipboard(COPY);
3363 leency 425
							break;
7813 leency 426
					case SCAN_CODE_KEY_G:
427
							EventOpenConsoleHere();
428
							break;
7786 leency 429
					case SCAN_CODE_KEY_V:
8949 leency 430
							EventPaste(path);
3363 leency 431
							break;
9356 leency 432
					case SCAN_CODE_KEY_S: //set image as bg tile
433
							sprintf(#temp, "\\S__%s",#file_path);
7786 leency 434
							RunProgram("/sys/media/kiv", #temp);
5512 punk_joker 435
							break;
9356 leency 436
					case SCAN_CODE_KEY_T: //set image as bg stretch
437
							sprintf(#temp, "\\T__%s",#file_path);
438
							RunProgram("/sys/media/kiv", #temp);
439
							break;
7813 leency 440
					case SCAN_CODE_KEY_N:
441
							EventOpenNewEolite();
9269 leency 442
							break;
8854 leency 443
					case SCAN_CODE_KEY_R:
8947 leency 444
							EventManualFolderRefresh();
8854 leency 445
							break;
7786 leency 446
					case SCAN_CODE_ENTER:
447
							if (!itdir) ShowOpenWithDialog();
8417 leency 448
							else EventOpen(1);
5512 punk_joker 449
							break;
7786 leency 450
					case SCAN_CODE_KEY_A:
7993 leency 451
							EventChooseAllFiles(true);
7386 pavelyakov 452
							break;
7786 leency 453
					case SCAN_CODE_KEY_U: //unselect all files
7993 leency 454
							EventChooseAllFiles(false);
7786 leency 455
							break;
5591 pavelyakov 456
				}
457
				break;
9341 leency 458
			}
9347 leency 459
 
460
			switch (calc(key_scancode))
7786 leency 461
			{
462
					case SCAN_CODE_BS:
463
							Dir_Up();
9269 leency 464
							break;
7786 leency 465
					case SCAN_CODE_ENTER:
8417 leency 466
							EventOpen(0);
9269 leency 467
							break;
7786 leency 468
					case SCAN_CODE_TAB:
8854 leency 469
							if (!efm) break;
8946 leency 470
							SetActivePanel(active_panel^1);
7786 leency 471
							break;
472
					case SCAN_CODE_MENU:
473
							mouse.x = files.x+15;
474
							mouse.y = files.cur_y - files.first * files.item_h + files.y + 5;
475
							EventShowListMenu();
476
							break;
477
					case SCAN_CODE_DEL:
8953 leency 478
							ShowPopinForm(POPIN_DELETE);
7786 leency 479
							break;
8872 leency 480
					case SCAN_CODE_SPACE:
481
							EventChooseFile(files.cur_y);
482
							DrawStatusBar();
483
							Line_ReDraw(col.selec, files.cur_y);
484
							break;
7786 leency 485
					case SCAN_CODE_INS:
7989 leency 486
							EventChooseFile(files.cur_y);
7786 leency 487
							files.KeyDown();
7999 leency 488
							DrawStatusBar();
7786 leency 489
							List_ReDraw();
490
							break;
8780 leency 491
					case SCAN_CODE_F1...SCAN_CODE_F10:
7786 leency 492
							FnProcess(key_scancode-58);
9269 leency 493
							break;
9341 leency 494
					case SCAN_CODE_DOWN:
495
					case SCAN_CODE_UP:
496
					case SCAN_CODE_HOME:
497
					case SCAN_CODE_END:
498
					case SCAN_CODE_PGUP:
499
					case SCAN_CODE_PGDN:
500
							if (files.ProcessKey(key_scancode)) List_ReDraw();
501
							break;
7786 leency 502
					default:
503
							EventSelectFileByKeyPress();
9269 leency 504
			}
8861 leency 505
			break;
7786 leency 506
		case evIPC:
507
		case evReDraw:
508
			draw_window();
509
			if (CheckActiveProcess(Form.ID)) && (GetMenuClick()) break;
8861 leency 510
			break;
7786 leency 511
		default:
8947 leency 512
			if (!Form.status_window&ROLLED_UP) EventRefreshDisksAndFolders();
5576 pavelyakov 513
	}
9269 leency 514
 
7786 leency 515
	if(cmd_free)
516
	{
517
		if(cmd_free==2) about_stak=free(about_stak);
518
		else if(cmd_free==3) properties_stak=free(properties_stak);
519
		else if(cmd_free==4) settings_stak=free(settings_stak);
520
		cmd_free = false;
521
	}
3363 leency 522
}
523
 
3444 leency 524
void draw_window()
525
{
8854 leency 526
	dword i=0;
8764 leency 527
	incn x;
8854 leency 528
	dword title;
8947 leency 529
	static int rand_n;
9269 leency 530
	if (!rand_n) rand_n = random(80);
8947 leency 531
 
8872 leency 532
	if (show_status_bar.checked) {
8952 leency 533
		#define STBAR_EOLITE_H 16
534
		#define STBAR_KFM_H 21
8881 leency 535
		if (efm) status_bar_h = STBAR_KFM_H;
536
		else status_bar_h = STBAR_EOLITE_H;
8872 leency 537
	} else {
538
		status_bar_h = 0;
539
	}
8861 leency 540
	if (efm) title = TITLE_KFM; else title = TITLE_EOLITE;
8854 leency 541
	DefineAndDrawWindow(Form.left+rand_n,Form.top+rand_n,Form.width,Form.height,0x73,NULL,title,0);
3444 leency 542
	GetProcessInfo(#Form, SelfInfo);
8946 leency 543
	if (Form.status_window&ROLLED_UP) return;
8854 leency 544
	if (Form.height < 356) { MoveSize(OLD,OLD,OLD,356); return; }
7490 leency 545
	GetProcessInfo(#Form, SelfInfo);
7635 leency 546
	SetAppColors();
8854 leency 547
	if (efm) {
548
		if (screen.width > 693) && (Form.width < 693) { MoveSize(OLD,OLD,693,OLD); return; }
8952 leency 549
		DrawBar(0, 4, Form.cwidth, SELECTY-5, sc.work);
550
		DrawBar(0, SELECTY+KFM2_DEVH+1, Form.cwidth, 3, sc.work);
551
		DrawBar(0, SELECTY-1, 1, KFM2_DEVH+2, sc.work);
552
		DrawBar(Form.cwidth-1, SELECTY-1, 1, KFM2_DEVH+2, sc.work);
8953 leency 553
		DrawBar(Form.cwidth/2-16, SELECTY-1, 15, KFM2_DEVH+2, sc.work);
8952 leency 554
		/*
8764 leency 555
		#define PAD 7
556
		#define GAP_S 26+5
557
		#define GAP_B 26+14
8854 leency 558
		x.set(Form.cwidth/2-DDW-203/2-GAP_S);
559
		while (i<200) {
560
			DrawTopPanelButton(i+BACK_BTN, x.inc(GAP_S), PAD, 30, false);
561
			DrawTopPanelButton(i+FWRD_BTN, x.inc(GAP_S), PAD, 31, false);
562
			DrawTopPanelButton(i+GOUP_BTN, x.inc(GAP_B), PAD, 01, false);
563
			DrawTopPanelButton(i+COPY_BTN, x.inc(GAP_B), PAD, 55, false);
564
			DrawTopPanelButton(i+CUT_BTN,  x.inc(GAP_S), PAD, 20, false);
565
			DrawTopPanelButton(i+PASTE_BTN,x.inc(GAP_S), PAD, 56, false);
566
			x.set(Form.cwidth/2-DDW-203/2-GAP_S+calc(Form.cwidth/2));
567
			i+=100;
568
		}
569
		//DrawTopPanelButton(51, Form.cwidth-GAP_S-PAD, PAD, -1, false); //burger menu
8952 leency 570
		*/
8764 leency 571
	} else {
572
		if (Form.width < 480) { MoveSize(OLD,OLD,480,OLD); return; }
573
		ESDWORD[#toolbar_pal] = sc.work;
574
		ESDWORD[#toolbar_pal+4] = MixColors(0, sc.work, 35);
9269 leency 575
		PutPaletteImage(#toolbar, 246, 34, 0, 0, 8, #toolbar_pal);
8861 leency 576
		for (i=0; i<3; i++) DefineHiddenButton(toolbar_buttons_x[i]+2,7,31-5,29-5,BACK_BTN+i);
577
		for (i=3; i<6; i++) DefineHiddenButton(toolbar_buttons_x[i],  5,31,  29,  BACK_BTN+i);
8764 leency 578
		DrawBar(127, 8, 1, 25, sc.work_graph);
579
		DrawBar(246,0, Form.cwidth - 246, 34, sc.work);
580
		DrawDot(Form.cwidth-17,12);
581
		DrawDot(Form.cwidth-17,12+6);
582
		DrawDot(Form.cwidth-17,12+12);
583
		DefineHiddenButton(Form.cwidth-24,7,20,25,51+BT_NOFRAME); //dots
584
	}
3434 leency 585
	//main rectangles
7806 leency 586
	DrawRectangle(1,40,Form.cwidth-3,Form.cheight - 42-status_bar_h,sc.work_graph);
7634 leency 587
	DrawRectangle(0,39,Form.cwidth-1,-show_status_bar.checked*status_bar_h + Form.cheight - 40,col.work_gradient[4]); //bg
7806 leency 588
	for (i=0; i<6; i++) DrawBar(0, 34+i, Form.cwidth, 1, MixColors(sc.work_dark, sc.work, i*10));
7819 leency 589
	for (i=0; i<6; i++) DrawBar(0, 5-i, Form.cwidth, 1, MixColors(sc.work_light, sc.work, i*10));
5733 leency 590
	llist_copy(#files_active, #files);
6564 leency 591
	DrawStatusBar();
8983 leency 592
	if (!getSelectedCount()) {
9269 leency 593
		OpenDir(ONLY_OPEN); //if there are no selected files -> refresh folder [L001]
8952 leency 594
	}
5723 leency 595
	DrawFilePanels();
8956 leency 596
 
597
	if (files.x!=files_inactive.x) {
598
		if (active_popin) ShowPopinForm(active_popin);
599
	}
5723 leency 600
}
601
 
9269 leency 602
void DrawButtonsAroundList()
5723 leency 603
{
5733 leency 604
	word sorting_arrow_x;
7490 leency 605
	dword sorting_arrow_t = "\x19";
606
	if (sort_desc) sorting_arrow_t = "\x18";
8764 leency 607
	DrawFlatButtonSmall(files.x - efm,           files.y-17,files.w-141+efm,16,31,T_FILE);
6678 leency 608
	DrawFlatButtonSmall(files.x + files.w - 141, files.y-17,73,16,32,T_TYPE);
609
	DrawFlatButtonSmall(files.x + files.w -  68, files.y-17,68,16,33,T_SIZE);
610
	DrawFlatButtonSmall(files.x + files.w,       files.y-17,16,16, 0,"\x18");
611
	DrawFlatButtonSmall(files.x + files.w,files.y+files.h-16,16,16,0,"\x19");
7490 leency 612
	if (sort_type==1) sorting_arrow_x = files.w - 141 / 2 + files.x + 18;
613
	if (sort_type==2) sorting_arrow_x = files.x + files.w - 90;
614
	if (sort_type==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
7806 leency 615
	WriteText(sorting_arrow_x,files.y-12,0x80, sc.work_text, sorting_arrow_t);
616
	DrawBar(files.x+files.w,files.y,1,files.h,sc.work_graph);
8949 leency 617
	if (efm) && (files.x<5) {
618
		DrawBar(files.x+files.w+16,files.y,1,files.h,EDX); //line between panel
619
	}
5723 leency 620
}
621
 
8881 leency 622
void DrawFuncButtonsInKfm()
623
{
624
	int i, x=0, len, min_w=0, padding;
8927 leency 625
	for (i=0; i<10; i++) min_w += strlen(kfm_func[i])+2*6 + 2;
8881 leency 626
	padding = Form.cwidth - min_w + 4 / 10;
627
	for (i=0; i<10; i++) {
8927 leency 628
		len = strlen(kfm_func[i])+2*6 + padding;
8881 leency 629
		if (i==9) len = Form.cwidth - x - 3;
8949 leency 630
		DrawBar(x, Form.cheight - 19, 1, 17, sc.work);
8927 leency 631
		DrawFuncButton(x+1, Form.cheight - 19, len, i+KFM_FUNC_ID+1, i+1, kfm_func[i]);
8881 leency 632
		x += len + 2;
633
	}
634
}
635
 
6404 punk_joker 636
void DrawStatusBar()
637
{
6572 leency 638
	char status_bar_str[80];
6570 leency 639
	int go_up_folder_exists=0;
8854 leency 640
 
9269 leency 641
	if (efm) {
8952 leency 642
		DrawBar(0, Form.cheight - status_bar_h, Form.cwidth, 2, sc.work);
8949 leency 643
		DrawBar(0, Form.cheight - 2, Form.cwidth,  2, sc.work);
644
		DrawBar(Form.cwidth-1, Form.cheight - 19, 1,  17, sc.work);
8881 leency 645
		DrawFuncButtonsInKfm();
8952 leency 646
	} else {
647
		if (!show_status_bar.checked) return;
648
		if (files.count>0) && (streq(items.get(0)*304+buf+72,"..")) go_up_folder_exists=1;
649
		DrawBar(0, Form.cheight - status_bar_h, Form.cwidth,  status_bar_h, sc.work);
650
		sprintf(#status_bar_str, T_STATUS_EVEMENTS, folder_count-go_up_folder_exists, files.count-folder_count);
651
		WriteText(6,Form.cheight - 13,0x80,sc.work_text,#status_bar_str);
8983 leency 652
		if (getSelectedCount()) {
653
			sprintf(#status_bar_str, T_STATUS_SELECTED, getSelectedCount());
8952 leency 654
			WriteText(Form.cwidth - calc(strlen(#status_bar_str)*6)-6,Form.cheight - 13,
655
				0x80,sc.work_text,#status_bar_str);
656
		}
8854 leency 657
	}
6404 punk_joker 658
}
659
 
5723 leency 660
void DrawFilePanels()
661
{
8949 leency 662
	int files_y = files.y;
8826 leency 663
	int w2 = -Form.cwidth-1/2+Form.cwidth;
8949 leency 664
	int h2 = Form.cheight-files_y-2 - status_bar_h;
8854 leency 665
	if (!efm)
5698 leency 666
	{
8951 leency 667
		SystemDiscs.Draw();
9349 leency 668
		files.SetSizes(SIDEBAR_W, 57, Form.cwidth - SIDEBAR_W-18, Form.cheight - 59 - status_bar_h, files.item_h);
8872 leency 669
		DrawButtonsAroundList();
670
		List_ReDraw();
8952 leency 671
		DrawPathBar();
5698 leency 672
	}
673
	else
674
	{
8952 leency 675
		llist_copy(#files_active, #files);
676
		llist_copy(#files, #files_inactive);
677
 
8951 leency 678
		if (!active_panel) {
8826 leency 679
			files.SetSizes(Form.cwidth/2, files_y, w2-17, h2, files.item_h);
8951 leency 680
		} else {
8826 leency 681
			files.SetSizes(2, files_y, Form.cwidth/2-2-17, h2, files.item_h);
5719 leency 682
		}
8951 leency 683
 
684
		files_inactive.x = files.x;
685
		DrawButtonsAroundList();
686
		path = location[active_panel^1];
8983 leency 687
		active_panel ^= 1;
688
		OpenDir2(WITH_REDRAW);
689
		active_panel ^= 1;
690
		if (!getSelectedCount()) files_inactive.count = files.count;
8952 leency 691
		llist_copy(#files, #files_active);
8951 leency 692
 
693
		if (!active_panel) {
8826 leency 694
			files.SetSizes(2, files_y, Form.cwidth/2-2-17, h2, files.item_h);
8951 leency 695
		} else {
8826 leency 696
			files.SetSizes(Form.cwidth/2, files_y, w2 -17, h2, files.item_h);
5719 leency 697
		}
8951 leency 698
 
699
		DrawButtonsAroundList();
700
		path = location[active_panel];
8983 leency 701
		OpenDir2(WITH_REDRAW);
5698 leency 702
	}
3363 leency 703
}
704
 
8983 leency 705
void OpenDir2(char redraw){
706
	if (buf) free(buf);
707
	if (GetDir(#buf, #files.count, path, DIRS_NOROOT)) {
708
		Write_Error(EAX);
709
		history.add(path);
710
		EventHistoryGoBack();
711
		return;
712
	}
713
	SetCurDir(path);
714
	if (files.count>0) && (files.cur_y-files.first==-1) files.cur_y=0;
715
	files.visible = math.min(files.h / files.item_h, files.count);
9269 leency 716
	if (!strncmp(path, "/rd/1",5)) || (!strncmp(path, "/sys/",4))
717
		dir_at_fat16 = true; else dir_at_fat16 = false;
8983 leency 718
	Sorting();
719
	SystemDiscs.Draw();
720
	list_full_redraw = true;
721
	List_ReDraw();
722
	DrawPathBar();
723
}
724
 
725
 
726
void OpenDir(char redraw){
727
	int errornum;
728
	unselectAll();
729
	if (buf) free(buf);
730
	if (errornum = GetDir(#buf, #files.count, path, DIRS_NOROOT)) {
731
		history.add(path);
9269 leency 732
		//EventHistoryGoBack();
733
		Dir_Up();
8983 leency 734
		Write_Error(errornum);
735
		return;
736
	}
737
	if (files.count>0) && (files.cur_y-files.first==-1) files.cur_y=0;
738
	history.add(path);
739
	SystemDiscs.Draw();
740
	files.visible = math.min(files.h / files.item_h, files.count);
9269 leency 741
	if (!strncmp(path, "/rd/1",5)) || (!strncmp(path, "/sys/",4))
742
		dir_at_fat16 = true; else dir_at_fat16 = false;
8983 leency 743
	Sorting();
744
	list_full_redraw = true;
745
	SetCurDir(path);
746
	if (redraw!=ONLY_OPEN) {
747
		List_ReDraw();
748
		DrawStatusBar();
749
		DrawPathBar();
750
	}
751
}
752
 
753
 
5694 leency 754
void List_ReDraw()
3363 leency 755
{
5719 leency 756
	int all_lines_h;
7422 leency 757
	dword j;
5825 leency 758
	static int old_cur_y, old_first;
8779 leency 759
	dword separator_color;
3363 leency 760
 
5694 leency 761
	files.CheckDoesValuesOkey(); //prevent some shit
8872 leency 762
	if (files.count < files.visible) files.visible = files.count;
3363 leency 763
 
5694 leency 764
	if (list_full_redraw) || (old_first != files.first)
3363 leency 765
	{
5825 leency 766
		old_cur_y = files.cur_y;
5694 leency 767
		old_first = files.first;
768
		list_full_redraw = false;
769
		goto _ALL_LIST_REDRAW;
3363 leency 770
	}
5825 leency 771
	if (old_cur_y != files.cur_y)
3363 leency 772
	{
7634 leency 773
		if (old_cur_y-files.first
774
		Line_ReDraw(col.selec, files.cur_y-files.first);
5825 leency 775
		old_cur_y = files.cur_y;
5694 leency 776
		return;
3363 leency 777
	}
778
 
5694 leency 779
	_ALL_LIST_REDRAW:
3363 leency 780
 
7634 leency 781
	for (j=0; j
9269 leency 782
		if (files.cur_y-files.first!=j) Line_ReDraw(col.list_bg, j);
783
		else Line_ReDraw(col.selec, files.cur_y-files.first);
7634 leency 784
	}
3434 leency 785
	//in the bottom
5825 leency 786
	all_lines_h = j * files.item_h;
7634 leency 787
	DrawBar(files.x,all_lines_h + files.y,files.w,files.h - all_lines_h, col.list_bg);
8779 leency 788
	if (colored_lines.checked) separator_color = col.list_bg; else separator_color = col.list_vert_line;
789
	DrawBar(files.x+files.w-141,all_lines_h + files.y,1,files.h - all_lines_h, separator_color);
790
	DrawBar(files.x+files.w-68,all_lines_h + files.y,1,files.h - all_lines_h, separator_color);
8947 leency 791
	DrawScroll(scroll_used);
3363 leency 792
}
793
 
5761 leency 794
void Line_ReDraw(dword bgcol, filenum){
7634 leency 795
	dword text_col=col.list_gb_text,
5991 leency 796
		  ext1, attr,
797
		  file_name_off,
7515 leency 798
		  file_size=0,
6290 leency 799
		  y=filenum*files.item_h+files.y,
8762 leency 800
		  icon_y = files.item_h-icon_size/2+y;
5991 leency 801
		  BDVK file;
7921 leency 802
		  char full_path[4096];
8779 leency 803
		  dword separator_color;
8949 leency 804
		  bool current_inactive = false;
9277 leency 805
		  char volume_label[64] = 0;
5996 leency 806
	char label_file_name[4096];
4859 leency 807
	if (filenum==-1) return;
8779 leency 808
 
8949 leency 809
	if (bgcol==col.selec) && (files.x==files_inactive.x) {
810
		bgcol = col.list_bg;
811
		current_inactive = true;
812
	}
813
 
7054 leency 814
	DrawBar(files.x,y,4,files.item_h,bgcol);
7197 leency 815
	DrawBar(files.x+4,y,icon_size,icon_y-y,bgcol);
8953 leency 816
	if (files.item_h>icon_size) DrawBar(files.x+4,icon_y+icon_size,icon_size,y+files.item_h-icon_y-icon_size,bgcol);
8779 leency 817
	if (colored_lines.checked) {
818
		if (bgcol!=col.selec) && (filenum%2) bgcol=col.odd_line;
819
		separator_color = bgcol;
820
	} else {
821
		separator_color = col.list_vert_line;
822
	}
7422 leency 823
	DrawBar(files.x+icon_size+4,y,files.w-icon_size-4,files.item_h,bgcol);
8779 leency 824
	DrawBar(files.x+files.w-141,y,1,files.item_h, separator_color);
825
	DrawBar(files.x+files.w-68,y,1,files.item_h, separator_color);
3363 leency 826
 
8949 leency 827
	ESI = items.get(filenum+files.first)*304 + buf+32;
828
	attr = ESDWORD[ESI];
9275 leency 829
	file.sizelo   = ESI.BDVK.sizelo;
830
	file.sizehi   = ESI.BDVK.sizehi;
831
	file_name_off = #ESI.BDVK.name;
9277 leency 832
	sprintf(#full_path,"%s/%s",path,file_name_off);
3363 leency 833
 
8949 leency 834
	if (attr&ATR_FOLDER)
9269 leency 835
	{
8949 leency 836
		if (!strcmp(file_name_off,"..")) ext1=""; else {
837
			ext1="";
838
			WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, col.list_gb_text, ext1);
839
		}
9269 leency 840
		if (chrnum(path, '/')==1) && (streq(path, "/kolibrios")==false)
9277 leency 841
			&& (streq(path, "/sys")==false) {
842
				file_size = GetDeviceSize(#full_path);
843
				if (ESBYTE[path+1]) strlcpy(#volume_label, GetVolumeLabel(#full_path), sizeof(volume_label));
844
			}
8949 leency 845
	}
846
	else
847
	{
5698 leency 848
		ext1 = strrchr(file_name_off,'.') + file_name_off;
7515 leency 849
		if (ext1==file_name_off) ext1 = NULL; //if no extension then show nothing
850
		file_size = ConvertSize64(file.sizelo, file.sizehi);
7634 leency 851
		if (ext1) && (strlen(ext1)<9) WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, col.list_gb_text, ext1);
3363 leency 852
	}
9269 leency 853
	if (file_size) WriteText(7-strlen(file_size)*6+files.x+files.w-58,
7634 leency 854
			files.text_y+y+1, files.font_type, col.list_gb_text, file_size);
4846 leency 855
 
8949 leency 856
	if (attr&ATR_HIDDEN) || (attr&ATR_SYSTEM) text_col=col.list_text_hidden;
7634 leency 857
	if (bgcol==col.selec)
3363 leency 858
	{
7628 leency 859
		file_name_is_8_3(file_name_off);
8944 leency 860
		itdir = attr & ATR_FOLDER;
4897 leency 861
		strcpy(#file_name, file_name_off);
8949 leency 862
		if (streq(path,"/")) sprintf(#file_path,"%s%s",path,file_name_off);
863
			else sprintf(#file_path,"%s/%s",path,file_name_off);
7634 leency 864
		if (text_col==col.list_text_hidden) {
9269 leency 865
			text_col=MixColors(col.selec_text, col.list_text_hidden, 65);
7634 leency 866
		} else text_col=col.selec_text;
3363 leency 867
	}
8983 leency 868
	if (getElementSelectedFlag(filenum+files.first)) text_col=0xFF0000;
6806 leency 869
	if (kfont.size.pt==9) || (!kfont.font)
3434 leency 870
	{
5745 leency 871
		if (Form.width>=480)
872
		{
8789 leency 873
			FileShow.start_x = files.x + icon_size + 7;
5745 leency 874
			FileShow.font_color = text_col;
875
			FileShow.area_size_x = files.w - 164;
876
			FileShow.text_pointer = file_name_off;
7004 leency 877
			FileShow.start_y = files.text_y + y - 3;
5745 leency 878
			PathShow_prepare stdcall(#FileShow);
879
			PathShow_draw stdcall(#FileShow);
9269 leency 880
		}
3434 leency 881
	}
5745 leency 882
	else
883
	{
9277 leency 884
		//that shit must be in a library
5996 leency 885
		strcpy(#label_file_name, file_name_off);
9277 leency 886
		if (volume_label) sprintf(#label_file_name, "%s [%s]", file_name_off, #volume_label);
6806 leency 887
		if (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w)
5996 leency 888
		{
6806 leency 889
			while (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w) {
5996 leency 890
				ESBYTE[#label_file_name+strlen(#label_file_name)-1] = NULL;
891
			}
9269 leency 892
			strcpy(#label_file_name+strlen(#label_file_name)-2, "...");
5996 leency 893
		}
9269 leency 894
		kfont.WriteIntoWindow(files.x + icon_size+7, files.item_h - kfont.height / 2 + y,
7634 leency 895
			bgcol, text_col, kfont.size.pt, #label_file_name);
5745 leency 896
	}
8779 leency 897
	DrawIconByExtension(#full_path, ext1, files.x+4, icon_y, bgcol);
8953 leency 898
	if (current_inactive) DrawWideRectangle(files.x+2, y, files.w-4, files.item_h, 2, col.selec);
3363 leency 899
}
900
 
901
inline Sorting()
902
{
7490 leency 903
	dword d=0, f=1;
7422 leency 904
	int j=0;
4897 leency 905
	dword file_off;
7422 leency 906
 
7972 leency 907
	items.drop();
908
 
8949 leency 909
	if (streq(path,"/")) //do not sort root folder
3363 leency 910
	{
7972 leency 911
		for(d=1;d
8947 leency 912
		folder_count = d;
3363 leency 913
		return;
914
	}
5591 pavelyakov 915
	for (j=files.count-1, file_off=files.count-1*304+buf+32; j>=0; j--, file_off-=304;)  //files | folders
3363 leency 916
	{
7628 leency 917
		if (dir_at_fat16) && (file_name_is_8_3(file_off+40)) strttl(file_off+40);
8944 leency 918
		if (ESDWORD[file_off] & ATR_FOLDER) {
7972 leency 919
			items.set(d, j);
7490 leency 920
			d++;
8944 leency 921
		} else {
7972 leency 922
			items.set(files.count-f, j);
7490 leency 923
			f++;
3363 leency 924
		}
925
	}
8947 leency 926
	folder_count = d;
3434 leency 927
	//sorting: files first, then folders
7490 leency 928
	Sort_by_Name(0,d-1);
929
	if (sort_type==1) Sort_by_Name(d,files.count-1);
930
	else if (sort_type==2) Sort_by_Type(d,files.count-1);
931
	else if (sort_type==3) Sort_by_Size(d,files.count-1);
932
	//reversed sorting
933
	if (sort_desc) {
7972 leency 934
		for (j=0; j
935
			items.swap(files.count-j-1, d+j);
936
		}
937
		//if (sort_type==1) for (j=0; j
7490 leency 938
	}
5581 leency 939
	//make ".." first item in list
7972 leency 940
	if (d>0) && (strncmp(items.get(0)*304+buf+72,"..",2)!=0)
941
		for(d--; d>0; d--;) if (!strncmp(items.get(d)*304+buf+72,"..",2)) {items.swap(d,0); break;}
3363 leency 942
}
943
 
944
 
5694 leency 945
void SelectFileByName(dword that_file)
3363 leency 946
{
5694 leency 947
	int ind;
948
	files.KeyHome();
8956 leency 949
	OpenDir(ONLY_OPEN);
7628 leency 950
	if (dir_at_fat16) && (file_name_is_8_3(that_file)) strttl(that_file);
8392 leency 951
	for (ind=files.count-1; ind>=0; ind--;) { if (!strcmpi(items.get(ind)*304+buf+72,that_file)) break; }
5825 leency 952
	files.cur_y = ind - 1;
5694 leency 953
	files.KeyDown();
6570 leency 954
	DrawStatusBar();
3363 leency 955
	List_ReDraw();
956
}
957
 
958
 
959
void Dir_Up()
960
{
7422 leency 961
	int iii;
6635 leency 962
	char old_folder_name[4096];
8949 leency 963
	iii=strlen(path)-1;
7422 leency 964
	if (iii==0) return;
8949 leency 965
	iii = strrchr(path, '/');
966
	strcpy(#old_folder_name, path+iii);
967
	if (iii>1) ESBYTE[path+iii-1]=NULL; else ESBYTE[path+iii]=NULL;
6635 leency 968
	SelectFileByName(#old_folder_name);
8981 leency 969
	DrawPathBar();
3363 leency 970
}
971
 
8417 leency 972
void EventOpenSelected()
3434 leency 973
{
8417 leency 974
	int i;
9269 leency 975
	for (i=0; i
8417 leency 976
		EDX = items.get(i)*304 + buf+32;
8944 leency 977
		if (ESDWORD[EDX]&ATR_FOLDER) continue; //is foder
8949 leency 978
		sprintf(#param,"%s/%s",path, EDX+40);
8417 leency 979
		RunProgram("/sys/@open", #param);
980
	}
981
}
982
 
983
void EventOpen(byte _new_window)
984
{
8983 leency 985
	if (getSelectedCount()) && (!itdir) notify(T_USE_SHIFT_ENTER);
8417 leency 986
	if (_new_window)
5443 punk_joker 987
	{
8417 leency 988
		if (streq(#file_name,"..")) return;
989
		RunProgram(I_Path, #file_path);
5443 punk_joker 990
		return;
991
	}
3444 leency 992
	if (!files.count) return;
3441 leency 993
	if (!itdir)
3434 leency 994
	{
5401 leency 995
		if (strrchr(#file_name, '.')==0) RunProgram(#file_path, ""); else RunProgram("/sys/@open", #file_path);
9269 leency 996
	}
3434 leency 997
	else
998
	{
5606 pavelyakov 999
		if (!strncmp(#file_name,"..",3)) { Dir_Up(); return; }
8949 leency 1000
		strcpy(path, #file_path);
5825 leency 1001
		files.first=files.cur_y=0;
8956 leency 1002
		OpenDir(WITH_REDRAW);
3434 leency 1003
	}
1004
}
3363 leency 1005
 
8956 leency 1006
void EventHistoryGoBack()
3363 leency 1007
{
1008
	char cur_folder[4096];
8949 leency 1009
	strcpy(#cur_folder, path);
6021 leency 1010
	if (history.back()) {
8949 leency 1011
		strcpy(path, history.current());
5977 leency 1012
		SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
8956 leency 1013
		DrawPathBar();
5977 leency 1014
	}
3363 leency 1015
}
1016
 
8956 leency 1017
void EventHistoryGoForward()
1018
{
1019
	if (history.forward()) {
1020
		strcpy(path, history.current());
1021
		files.KeyHome();
1022
		OpenDir(WITH_REDRAW);
1023
		DrawPathBar();
1024
	}
1025
}
1026
 
1027
 
5397 punk_joker 1028
void ShowOpenWithDialog()
1029
{
6930 leency 1030
	byte open_param[4097];
1031
	sprintf(#open_param,"~%s",#file_path);
1032
	RunProgram("/sys/@open", #open_param);
5397 punk_joker 1033
}
1034
 
8953 leency 1035
bool EventCreateAndRename()
5555 punk_joker 1036
{
8953 leency 1037
	sprintf(#temp,"%s/%s",path,popin_text.text);
1038
	if (file_exists(#temp)) {
1039
		notify(FS_ITEM_ALREADY_EXISTS);
1040
		return false;
1041
	}
9269 leency 1042
	switch(active_popin)
5555 punk_joker 1043
	{
8953 leency 1044
		case POPIN_NEW_FILE:
1045
				if (CreateFile(0, 0, #temp)) goto __FAIL;
1046
				break;
1047
		case POPIN_NEW_FOLDER:
1048
				if (CreateDir(#temp)) goto __FAIL;
1049
				break;
1050
		case POPIN_RENAME:
1051
				if (RenameMove(popin_text.text, #file_path))
5557 punk_joker 1052
				{
8750 leency 1053
					if (itdir) {
8953 leency 1054
						goto __FAIL;
8750 leency 1055
					} else {
8953 leency 1056
						if (CopyFile(#file_path,#temp)) {
1057
							goto __FAIL;
8750 leency 1058
						} else {
1059
							DeleteFile(#file_path);
1060
						}
5571 punk_joker 1061
					}
1062
				}
5555 punk_joker 1063
	}
8953 leency 1064
	SelectFileByName(popin_text.text);
1065
	return true;
1066
	__FAIL:
1067
	Write_Error(EAX);
9269 leency 1068
	return false;
8953 leency 1069
}
1070
 
1071
void EventPopinClickOkay()
1072
{
1073
	switch(active_popin) {
1074
		case POPIN_PATH:
1075
			strcpy(path, #popin_string);
8956 leency 1076
			OpenDir(WITH_REDRAW);
8953 leency 1077
			break;
1078
		case POPIN_DELETE:
1079
			CopyFilesListToClipboard(DELETE);
8995 leency 1080
			EventChooseAllFiles(false);
8953 leency 1081
			sprintf(#param, "-d %s", #file_path);
1082
			RunProgram(#program_path, #param);
9269 leency 1083
			break;
8953 leency 1084
		case POPIN_RENAME:
1085
		case POPIN_NEW_FILE:
1086
		case POPIN_NEW_FOLDER:
1087
			if (!EventCreateAndRename()) return;
1088
	}
7878 leency 1089
	EventClosePopinForm();
5555 punk_joker 1090
}
1091
 
8953 leency 1092
void EventClosePopinForm()
5555 punk_joker 1093
{
8953 leency 1094
	active_popin = NULL;
1095
	draw_window();
1096
}
1097
 
1098
void ShowPopinForm(byte _popin_type)
1099
{
1100
	int popinx;
1101
	popin_string[0] = -1;
1102
	switch(_popin_type) {
1103
		case POPIN_PATH:
1104
				edit_box_set_text stdcall (#popin_text, path);
1105
				DrawEolitePopup(T_GOPATH, T_CANCEL);
1106
				break;
1107
		case POPIN_NEW_FILE:
1108
				edit_box_set_text stdcall (#popin_text, T_NEW_FILE);
1109
				DrawEolitePopup(T_CREATE, T_CANCEL);
1110
				break;
1111
		case POPIN_NEW_FOLDER:
1112
				edit_box_set_text stdcall (#popin_text, T_NEW_FOLDER);
1113
				DrawEolitePopup(T_CREATE, T_CANCEL);
1114
				break;
1115
		case POPIN_RENAME:
1116
				edit_box_set_text stdcall (#popin_text, #file_name);
1117
				DrawEolitePopup(T_RENAME, T_CANCEL);
1118
				break;
1119
		case POPIN_DELETE:
1120
				if (!files.count) return;
8983 leency 1121
				if (!getSelectedCount()) && (!strncmp(#file_name,"..",2)) return;
8953 leency 1122
				popinx = DrawEolitePopup(T_YES, T_NO);
1123
				WriteTextCenter(popinx, 178, POPIN_W, sc.work_text, T_DELETE_FILE);
8983 leency 1124
				if (getSelectedCount()) {
1125
					sprintf(#param,"%s%d%s",DEL_MORE_FILES_1,getSelectedCount(),DEL_MORE_FILES_2);
8953 leency 1126
				} else {
1127
					if (strlen(#file_name)<28) {
1128
						sprintf(#param,"%s ?",#file_name);
1129
					} else {
1130
						strncpy(#param, #file_name, POPIN_W-20/6-4);
1131
						strcat(#param, "...?");
1132
					}
1133
				}
9349 leency 1134
				WriteTextCenter(popinx, SIDEBAR_W, POPIN_W, sc.work_text, #param);
8953 leency 1135
				break;
1136
		case POPIN_DISK:
8956 leency 1137
				DefineHiddenButton(0,0,5000,3000,POPUP_BTN2+BT_NOFRAME);
8953 leency 1138
				if (active_panel==0) {
1139
					SystemDiscs.DrawOptions(1);
1140
				} else {
1141
					SystemDiscs.DrawOptions(Form.cwidth/2-1);
1142
				}
1143
				break;
1144
		case POPIN_BREADCR:
8956 leency 1145
				DefineHiddenButton(0,0,5000,3000,POPUP_BTN2+BT_NOFRAME);
1146
				DrawBreadCrumbs();
8953 leency 1147
				break;
5555 punk_joker 1148
	}
8953 leency 1149
	active_popin = _popin_type;
5555 punk_joker 1150
}
1151
 
8780 leency 1152
void EventShowAbout()
1153
{
1154
	if (!active_about) {
1155
		about_stak = malloc(4096);
1156
		about_thread_id = CreateThread(#about_dialog,about_stak+4092);
1157
	} else {
1158
		ActivateWindow(GetProcessSlot(about_thread_id));
1159
	}
1160
}
1161
 
5576 pavelyakov 1162
void FnProcess(byte N)
3434 leency 1163
{
1164
	switch(N)
1165
	{
1166
		case 1:
8780 leency 1167
			EventShowProperties();
3434 leency 1168
			break;
1169
		case 2:
8953 leency 1170
			if (files.count) ShowPopinForm(POPIN_RENAME);
3434 leency 1171
			break;
1172
		case 3:
8780 leency 1173
			if (files.count) && (!itdir) RunProgram("/sys/quark", #file_path);
3434 leency 1174
			break;
1175
		case 4:
8780 leency 1176
			if (files.count) && (!itdir) RunProgram("/sys/develop/cedit", #file_path);
3434 leency 1177
			break;
8854 leency 1178
		case 5:
1179
			if (efm) {
8861 leency 1180
				CopyFilesListToClipboard(COPY);
8949 leency 1181
				EventPaste(location[active_panel^1]);
8779 leency 1182
			} else {
8947 leency 1183
				EventManualFolderRefresh();
5719 leency 1184
			}
3434 leency 1185
			break;
1186
		case 6:
8854 leency 1187
			if (efm) {
8861 leency 1188
				CopyFilesListToClipboard(CUT);
8995 leency 1189
				EventChooseAllFiles(false);
8949 leency 1190
				EventPaste(location[active_panel^1]);
8854 leency 1191
			}
3434 leency 1192
			break;
1193
		case 7:
8953 leency 1194
			ShowPopinForm(POPIN_NEW_FOLDER);
3434 leency 1195
			break;
5447 punk_joker 1196
		case 8:
8953 leency 1197
			ShowPopinForm(POPIN_DELETE);
5447 punk_joker 1198
			break;
8780 leency 1199
		case 9:
8953 leency 1200
			ShowPopinForm(POPIN_NEW_FILE);
8780 leency 1201
			break;
3434 leency 1202
		case 10: //F10
8949 leency 1203
			if (active_settings) {
1204
				ActivateWindow(GetProcessSlot(settings_window));
1205
			} else {
5576 pavelyakov 1206
				settings_stak = malloc(4096);
1207
				settings_window = CreateThread(#settings_dialog, settings_stak+4092);
5416 punk_joker 1208
			}
3434 leency 1209
			break;
1210
	}
1211
}
1212
 
8946 leency 1213
void SetActivePanel(int _active)
5738 leency 1214
{
9269 leency 1215
	if (active_panel != _active) {
8946 leency 1216
		active_panel = _active;
1217
		llist_copy(#files_active, #files_inactive);
1218
		llist_copy(#files_inactive, #files);
8949 leency 1219
		llist_copy(#files, #files_active);
1220
		path = location[active_panel];
8946 leency 1221
		DrawFilePanels();
1222
	}
5738 leency 1223
}
1224
 
7422 leency 1225
void EventSelectFileByKeyPress()
1226
{
1227
	int i;
1228
	for (i=files.cur_y+1; i
1229
	{
7972 leency 1230
		strcpy(#temp, items.get(i)*304+buf+72);
7422 leency 1231
		if (temp[0]==key_ascii) || (temp[0]==key_ascii-32)
1232
		{
1233
			files.cur_y = i - 1;
1234
			files.KeyDown();
1235
			List_ReDraw();
1236
			return;
1237
		}
1238
	}
1239
}
1240
 
8949 leency 1241
dword GetDeviceSize(dword p)
7515 leency 1242
{
1243
	BDVK bdvk;
8949 leency 1244
	if (ESBYTE[p+1] == '/') p++;
1245
	if (ESBYTE[p+1] == 'c') && (ESBYTE[p+2] == 'd')
1246
		&& (ESBYTE[p+4] == 0) return 0;
9044 leency 1247
	if (GetFileInfo(p, #bdvk)) {
1248
		return 0;
1249
	} else {
1250
		ConvertSize64(bdvk.sizelo, bdvk.sizehi);
1251
	}
7515 leency 1252
}
1253
 
7422 leency 1254
int GetRealFileCountInFolder(dword folder_path)
1255
{
1256
	int fcount;
1257
	dword countbuf;
1258
 
1259
	GetDir(#countbuf, #fcount, folder_path, DIRS_NOROOT);
1260
	if (countbuf) free(countbuf);
1261
 
1262
	return fcount;
1263
}
1264
 
1265
void EventRefreshDisksAndFolders()
1266
{
8947 leency 1267
	if(efm) {
8949 leency 1268
		if (GetRealFileCountInFolder(location[active_panel^1]) != files_inactive.count) {
8947 leency 1269
			DrawFilePanels();
1270
			return;
1271
		}
8902 leency 1272
	} else {
8947 leency 1273
		if (GetRealFileCountInFolder("/")+dir_exists("/kolibrios") != SystemDiscs.dev_num) {
1274
			SystemDiscs.Get();
8951 leency 1275
			SystemDiscs.Draw();
7422 leency 1276
		}
1277
	}
8956 leency 1278
	if(GetRealFileCountInFolder(path) != files.count) OpenDir(WITH_REDRAW);
7422 leency 1279
}
1280
 
8947 leency 1281
void EventManualFolderRefresh()
1282
{
1283
	Tip(56, T_DEVICES, 55, "-");
1284
	pause(10);
8951 leency 1285
	DrawFilePanels();
8947 leency 1286
}
1287
 
7628 leency 1288
void EventSort(dword id)
1289
{
1290
	char selected_filename[256];
1291
	if (sort_type == id) sort_desc ^= 1;
1292
	else sort_type = id;
1293
	strcpy(#selected_filename, #file_name);
8872 leency 1294
	DrawButtonsAroundList();
8956 leency 1295
	OpenDir(WITH_REDRAW);
7628 leency 1296
	SelectFileByName(#selected_filename);
1297
}
1298
 
7813 leency 1299
void EventOpenNewEolite()
1300
{
8949 leency 1301
	RunProgram(I_Path, path);
7813 leency 1302
}
1303
 
1304
void EventOpenConsoleHere()
1305
{
8949 leency 1306
	sprintf(#param, "pwd cd %s", path);
7813 leency 1307
	RunProgram("/sys/shell", #param);
1308
}
1309
 
7786 leency 1310
void ProceedMouseGestures()
1311
{
1312
	char stats;
1313
	signed x_old, y_old, dif_x, dif_y, adif_x, adif_y;
1314
	if (!mouse.mkm) && (stats>0) stats = 0;
1315
	if (mouse.mkm) && (!stats)
1316
	{
1317
		x_old = mouse.x;
1318
		y_old = mouse.y;
1319
		stats = 1;
1320
	}
1321
	if (mouse.mkm) && (stats==1)
1322
	{
1323
		dif_x = mouse.x-x_old;
1324
		dif_y = mouse.y-y_old;
1325
		adif_x = fabs(dif_x);
1326
		adif_y = fabs(dif_y);
9269 leency 1327
 
7786 leency 1328
		if (adif_x>adif_y) {
1329
			if (dif_x > 150) {
1330
				EventHistoryGoForward();
1331
				stats = 0;
1332
			}
1333
			if (dif_x < -150) {
1334
				EventHistoryGoBack();
1335
				stats = 0;
1336
			}
1337
		} else {
1338
			if (dif_y < -100) {
1339
				Dir_Up();
1340
				stats = 0;
1341
			}
1342
		}
1343
	}
1344
}
1345
 
8854 leency 1346
void EventPaste(dword _into_path) {
7878 leency 1347
	char paste_line[4096+6];
8854 leency 1348
	sprintf(#paste_line, "-v%i %s", cut_active, _into_path);
7878 leency 1349
	RunProgram(#program_path, #paste_line);
1350
	EventClosePopinForm();
1351
}
1352
 
1353
void EventShowProperties()
1354
char line_param[4096+5];
1355
{
8983 leency 1356
	if (!getSelectedCount()) {
7878 leency 1357
		sprintf(#line_param, "-p %s", #file_path);
1358
		RunProgram(#program_path, #line_param);
1359
	} else {
1360
		properties_stak = malloc(8096);
1361
		CreateThread(#properties_dialog, properties_stak+8092);
1362
	}
1363
}
1364
 
7989 leency 1365
void EventChooseFile(int _id)
1366
{
1367
	if (getElementSelectedFlag(_id) == true) {
1368
		setElementSelectedFlag(_id, false);
1369
	} else {
1370
		setElementSelectedFlag(_id, true);
1371
	}
7993 leency 1372
}
1373
 
1374
void EventChooseFilesRange(int _start, _end)
1375
{
1376
	if (_start > _end) _start >< _end;
1377
	if (_end - _start > 1) list_full_redraw = true;
1378
	while (_start < _end) {
9269 leency 1379
		EventChooseFile(_start);
7993 leency 1380
		_start++;
1381
	}
7989 leency 1382
	DrawStatusBar();
7993 leency 1383
	List_ReDraw();
7989 leency 1384
}
1385
 
7993 leency 1386
void EventChooseAllFiles(dword state)
1387
{
1388
	int i;
1389
	for (i=0; i
1390
	List_ReDraw();
1391
	DrawStatusBar();
1392
}
1393
 
8854 leency 1394
void EventToolbarButtonClick(int _btid)
1395
{
1396
	switch(_btid) {
1397
		case BACK_BTN: EventHistoryGoBack(); break;
1398
		case FWRD_BTN: EventHistoryGoForward(); break;
1399
		case GOUP_BTN: Dir_Up(); break;
8861 leency 1400
		case COPY_BTN: CopyFilesListToClipboard(CUT); break;
1401
		case CUT_BTN:  CopyFilesListToClipboard(COPY); break;
9269 leency 1402
		case PASTE_BTN:EventPaste(path); break;
8854 leency 1403
	}
1404
}
7993 leency 1405
 
8854 leency 1406
void EventDriveClick(int __id)
1407
{
8956 leency 1408
	if (__id >= SystemDiscs.list.count) return;
8854 leency 1409
	if (efm) {
8956 leency 1410
		EventClosePopinForm();
8854 leency 1411
		draw_window();
1412
	}
8956 leency 1413
	strcpy(path, SystemDiscs.list.get(__id));
1414
	files.KeyHome();
9269 leency 1415
	OpenDir(WITH_REDRAW);
8854 leency 1416
}
1417
 
3363 leency 1418
stop: