Subversion Repositories Kolibri OS

Rev

Rev 8826 | Rev 8868 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8826 Rev 8861
1
//===================================================//
1
//===================================================//
2
//                                                   //
2
//                                                   //
3
//                   MASS ACTIONS                    //
3
//                   MASS ACTIONS                    //
4
//                                                   //
4
//                                                   //
5
//===================================================//
5
//===================================================//
6
 
6
 
7
void setElementSelectedFlag(dword n, int state) {
7
void setElementSelectedFlag(dword n, int state) {
8
	dword selected_offset = items.get(n)*304 + buf+32 + 7;
8
	dword selected_offset = items.get(n)*304 + buf+32 + 7;
9
	ESBYTE[selected_offset] = state;
9
	ESBYTE[selected_offset] = state;
10
	if (n==0) && (strncmp(items.get(n)*304+buf+72,"..",2)==0) {
10
	if (n==0) && (strncmp(items.get(n)*304+buf+72,"..",2)==0) {
11
		ESBYTE[selected_offset] = false; //do not selec ".." directory
11
		ESBYTE[selected_offset] = false; //do not selec ".." directory
12
		return;
12
		return;
13
	}
13
	}
14
	if (state==true) selected_count++;
14
	if (state==true) selected_count++;
15
	if (state==false) selected_count--;
15
	if (state==false) selected_count--;
16
	if (selected_count<0) selected_count=0;
16
	if (selected_count<0) selected_count=0;
17
}
17
}
18
 
18
 
19
int getElementSelectedFlag(dword n) {
19
int getElementSelectedFlag(dword n) {
20
	dword selected_offset = items.get(n)*304 + buf+32 + 7;
20
	dword selected_offset = items.get(n)*304 + buf+32 + 7;
21
	return ESBYTE[selected_offset];
21
	return ESBYTE[selected_offset];
22
}
22
}
23
 
23
 
24
dword GetFilesCount(dword _in_path)
24
dword GetFilesCount(dword _in_path)
25
{
25
{
26
	int j;
26
	int j;
27
	BDVK file_info_count;
27
	BDVK file_info_count;
28
	DIR_SIZE paste_dir_size;
28
	DIR_SIZE paste_dir_size;
29
 
29
 
30
	GetFileInfo(_in_path, #file_info_count);
30
	GetFileInfo(_in_path, #file_info_count);
31
	if ( file_info_count.isfolder ) {
31
	if ( file_info_count.isfolder ) {
32
		return paste_dir_size.get(_in_path);
32
		return paste_dir_size.get(_in_path);
33
	} else {
33
	} else {
34
		return 1;
34
		return 1;
35
	}
35
	}
36
}
36
}
37
 
37
 
38
//===================================================//
38
//===================================================//
39
//                                                   //
39
//                                                   //
40
//                  COPY AND PASTE                   //
40
//                  COPY AND PASTE                   //
41
//                                                   //
41
//                                                   //
42
//===================================================//
42
//===================================================//
43
byte copy_to[4096];
43
byte copy_to[4096];
44
byte copy_from[4096];
44
byte copy_from[4096];
45
bool cut_active = false;
45
bool cut_active = false;
46
 
46
 
47
enum {NOCUT, CUT};
47
enum {COPY, CUT, DELETE};
48
 
48
 
49
void EventCopy(bool _cut_active)
49
void CopyFilesListToClipboard(bool _cut_active)
50
{
50
{
51
	byte copy_t[4096];
51
	byte copy_t[4096];
52
	dword buff_data;
52
	dword buff_data;
53
	dword path_len = 0;
53
	dword path_len = 0;
54
	dword size_buf = 0;
54
	dword size_buf = 0;
55
	dword copy_buf_offset = 0;
55
	dword copy_buf_offset = 0;
56
	dword i;
56
	dword i;
57
 
57
 
58
	if (files.count<=0) return; //no files
58
	if (files.count<=0) return; //no files
59
 
59
 
60
	cut_active = _cut_active;
60
	if (cut_active!=DELETE) cut_active = _cut_active;
61
 
61
 
62
	//if no element selected by "Insert" key, then we copy current element
62
	//if no element selected by "Insert" key, then we copy current element
63
	if (!selected_count) {
63
	if (!selected_count) {
64
		setElementSelectedFlag(files.cur_y, true);
64
		setElementSelectedFlag(files.cur_y, true);
65
	}
65
	}
66
 
66
 
67
	if (!selected_count) return;
67
	if (!selected_count) return;
68
	
68
	
69
	size_buf = 4;
69
	size_buf = 4;
70
	for (i=0; i
70
	for (i=0; i
71
	{
71
	{
72
		if (getElementSelectedFlag(i) == true) {
72
		if (getElementSelectedFlag(i) == true) {
73
			sprintf(#copy_t,"%s/%s",#path,items.get(i)*304+buf+72);
73
			sprintf(#copy_t,"%s/%s",#path,items.get(i)*304+buf+72);
74
			path_len = strlen(#copy_t);
74
			path_len = strlen(#copy_t);
75
			size_buf += path_len + 1;
75
			size_buf += path_len + 1;
76
		}
76
		}
77
	}
77
	}
78
	size_buf += 20;
78
	size_buf += 20;
79
	buff_data = malloc(size_buf);
79
	buff_data = malloc(size_buf);
80
	ESDWORD[buff_data] = size_buf;
80
	ESDWORD[buff_data] = size_buf;
81
	ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
81
	ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
82
	ESINT[buff_data+8] = selected_count;
82
	ESINT[buff_data+8] = selected_count;
83
	copy_buf_offset = buff_data + 10;
83
	copy_buf_offset = buff_data + 10;
84
	for (i=0; i
84
	for (i=0; i
85
	{
85
	{
86
		if (getElementSelectedFlag(i) == true) {
86
		if (getElementSelectedFlag(i) == true) {
87
			sprintf(copy_buf_offset,"%s/%s",#path,items.get(i)*304+buf+72);
87
			sprintf(copy_buf_offset,"%s/%s",#path,items.get(i)*304+buf+72);
88
			copy_buf_offset += strlen(copy_buf_offset) + 1;
88
			copy_buf_offset += strlen(copy_buf_offset) + 1;
89
 
89
 
90
			//setElementSelectedFlag(i, false);
-
 
91
 
-
 
92
			if (cut_active) {
90
			if (cut_active) {
93
				if (i>=files.first) && (i
91
				if (i>=files.first) && (i
94
					PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
92
					PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
95
			}
93
			}
96
		}
94
		}
97
	}
95
	}
98
	if (cut_active) {
96
	if (cut_active) {
99
		pause(20);
97
		pause(20);
100
		List_ReDraw();
98
		List_ReDraw();
101
	}
99
	}
102
	if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
100
	if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
103
	Clipboard__SetSlotData(size_buf, buff_data);
101
	Clipboard__SetSlotData(size_buf, buff_data);
104
	free(buff_data);
102
	free(buff_data);
105
}
103
}
106
 
104
 
107
 
105
 
108
void PasteThread()
106
void PasteThread()
109
{
107
{
110
	char copy_rezult;
108
	char copy_rezult;
111
	int j, i, slash_count=0;
109
	int j, i, slash_count=0;
112
	int paste_elements_count = 0;
110
	int paste_elements_count = 0;
113
	dword buf;
111
	dword buf;
114
	dword path_offset;
112
	dword path_offset;
115
	
113
	
116
	buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
114
	buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
117
	if (DSDWORD[buf+4] != 3) return;
115
	if (DSDWORD[buf+4] != 3) return;
118
	paste_elements_count = ESINT[buf+8];
116
	paste_elements_count = ESINT[buf+8];
119
	path_offset = buf + 10;
117
	path_offset = buf + 10;
120
 
118
 
121
	if (cut_active) {
119
	if (cut_active) {
122
		DisplayOperationForm(MOVE_FLAG);
120
		DisplayOperationForm(MOVE_FLAG);
123
	} else {
121
	} else {
124
		DisplayOperationForm(COPY_FLAG);	
122
		DisplayOperationForm(COPY_FLAG);	
125
	} 
123
	} 
126
 
124
 
127
	if (cut_active) {
125
	if (cut_active) {
128
		for (j = 0; j < paste_elements_count; j++) {
126
		for (j = 0; j < paste_elements_count; j++) {
129
			sprintf(#copy_to, "%s/%s", #path, path_offset+strrchr(path_offset,'/'));
127
			sprintf(#copy_to, "%s/%s", #path, path_offset+strrchr(path_offset,'/'));
130
			slash_count = 0;
128
			slash_count = 0;
131
			for (i=0; i<=10; i++) {
129
			for (i=0; i<=10; i++) {
132
				if (copy_to[i]=='/') slash_count++;
130
				if (copy_to[i]=='/') slash_count++;
133
				if (slash_count==3) break;
131
				if (slash_count==3) break;
134
			}
132
			}
135
			if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
133
			if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
136
			RenameMove(#copy_to+i, path_offset);
134
			RenameMove(#copy_to+i, path_offset);
137
			if (EAX!=0) goto _DIFFERENT_DRIVES;
135
			if (EAX!=0) goto _DIFFERENT_DRIVES;
138
			path_offset += strlen(path_offset) + 1;
136
			path_offset += strlen(path_offset) + 1;
139
		}
137
		}
140
		cut_active=false;
138
		DialogExit();
141
		DialogExit();
-
 
142
	}
139
	}
143
 
140
 
144
_DIFFERENT_DRIVES:
141
_DIFFERENT_DRIVES:
145
	path_offset = buf + 10;
142
	path_offset = buf + 10;
146
	for (j = 0; j < paste_elements_count; j++) {
143
	for (j = 0; j < paste_elements_count; j++) {
147
		copy_bar.max += GetFilesCount(path_offset);
144
		copy_bar.max += GetFilesCount(path_offset);
148
		path_offset += strlen(path_offset) + 1;
145
		path_offset += strlen(path_offset) + 1;
149
	}
146
	}
150
	
147
	
151
	path_offset = buf + 10;
148
	path_offset = buf + 10;
152
	for (j = 0; j < paste_elements_count; j++) {
149
	for (j = 0; j < paste_elements_count; j++) {
153
		strcpy(#copy_from, path_offset);
150
		strcpy(#copy_from, path_offset);
154
		if (!copy_from) DialogExit();
151
		if (!copy_from) DialogExit();
155
		sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
152
		sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
156
		if (streq(#copy_from,#copy_to))
153
		if (streq(#copy_from,#copy_to))
157
		{
154
		{
158
			if (cut_active) continue;
155
			if (cut_active) continue;
159
			sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
156
			sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
160
		}
157
		}
161
		if (strstr(#copy_to, #copy_from))
158
		if (strstr(#copy_to, #copy_from))
162
		{
159
		{
163
			notify("Copy directory into itself is a bad idea...");
160
			notify("'Not possible to copy directory into itself.\nProcess terminated.' -E");
164
			DialogExit();
161
			DialogExit();
165
		}
162
		}
166
 
163
 
167
		if (copy_rezult = copyf(#copy_from,#copy_to))
164
		if (copy_rezult = copyf(#copy_from,#copy_to))
168
		{
165
		{
169
			Write_Error(copy_rezult);
166
			Write_Error(copy_rezult);
170
			if (copy_rezult==8) DialogExit(); //not enough space
167
			if (copy_rezult==8) DialogExit(); //not enough space
171
		}
168
		}
172
		else if (cut_active)
169
		else if (cut_active)
173
		{
170
		{
174
			strcpy(#file_path, #copy_from);
171
			strcpy(#file_path, #copy_from);
175
			Del_File2(#copy_from, 0);
172
			RecursiveDelete(#copy_from, false);
176
			
173
			
177
		}
174
		}
178
		path_offset += strlen(path_offset) + 1;
175
		path_offset += strlen(path_offset) + 1;
179
	}
176
	}
180
	cut_active=false;
177
	DialogExit();
181
	DialogExit();
-
 
182
}
178
}
183
 
179
 
184
 
180
 
185
//===================================================//
181
//===================================================//
186
//                                                   //
182
//                                                   //
187
//                     DELETE                        //
183
//                     DELETE                        //
188
//                                                   //
184
//                                                   //
189
//===================================================//
185
//===================================================//
190
 
186
 
191
int del_error;
187
int del_error;
192
int Del_File2(dword way, sh_progr)
188
int RecursiveDelete(dword way, bool show_progress)
193
{    
189
{    
194
	dword dirbuf, fcount, i, filename;
190
	dword dirbuf, fcount, i, filename;
195
	int error;
191
	int error;
196
	char del_from[4096];
192
	char del_from[4096];
197
	if (dir_exists(way))
193
	if (dir_exists(way))
198
	{
194
	{
199
		if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
195
		if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
200
		for (i=0; i
196
		for (i=0; i
201
		{
197
		{
202
			//if (CheckEvent()==evReDraw) draw_window();
198
			//if (CheckEvent()==evReDraw) draw_window();
203
			filename = i*304+dirbuf+72;
199
			filename = i*304+dirbuf+72;
204
			sprintf(#del_from,"%s/%s",way,filename);
200
			sprintf(#del_from,"%s/%s",way,filename);
205
			if ( TestBit(ESDWORD[filename-40], 4) )
201
			if ( TestBit(ESDWORD[filename-40], 4) )
206
			{
202
			{
207
				Del_File2(#del_from, 1);
203
				RecursiveDelete(#del_from, true);
208
			}
204
			}
209
			else
205
			else
210
			{
206
			{
211
				if (sh_progr) Operation_Draw_Progress(filename);
207
				if (show_progress) Operation_Draw_Progress(filename);
212
				if (error = DeleteFile(#del_from)) del_error = error;
208
				if (error = DeleteFile(#del_from)) del_error = error;
213
			}
209
			}
214
		}
210
		}
215
	}
211
	}
216
	if (error = DeleteFile(way)) del_error = error;
212
	if (error = DeleteFile(way)) del_error = error;
217
}
213
}
218
 
214
 
219
void DeleteSingleElement()
215
void DeleteThread()
220
{   
216
{
221
	DIR_SIZE delete_dir_size;
-
 
222
	del_error = NULL;
-
 
223
	
-
 
224
	if (itdir) { 
-
 
225
		copy_bar.max = delete_dir_size.get(#file_path); 
-
 
226
	} else {
217
	int j;
227
		copy_bar.max = 1;
-
 
228
	}
-
 
229
	
-
 
230
	Del_File2(#file_path, 1);			
218
	int elements_count = 0;
231
 
-
 
232
	if (del_error) Write_Error(del_error);
-
 
233
	DialogExit();
219
	dword buf;
234
}
-
 
235
 
-
 
236
void DeleteSelectedElements()
-
 
237
{   
-
 
238
	byte del_from[4096];
220
	dword path_offset;
239
	int i;
-
 
240
 
221
 
241
	DisplayOperationForm(DELETE_FLAG);
222
	DisplayOperationForm(DELETE_FLAG);
242
 
223
	
243
	if (!selected_count) { DeleteSingleElement(); return; }
224
	buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
-
 
225
	Clipboard__DeleteLastSlot();
-
 
226
	if (DSDWORD[buf+4] != 3) return;
-
 
227
	elements_count = ESINT[buf+8];
244
	
228
 
245
	for (i=0; i
-
 
246
	{
229
	path_offset = buf + 10;
247
		if (getElementSelectedFlag(i) == true) {
230
	for (j = 0; j < elements_count; j++) {
248
			sprintf(#del_from,"%s/%s",#path,items.get(i)*304+buf+72);
231
		copy_bar.max += GetFilesCount(path_offset);
249
			copy_bar.max += GetFilesCount(#del_from);
-
 
250
		}
232
		path_offset += strlen(path_offset) + 1;
251
	}	
233
	}
252
 
-
 
253
	del_error = 0;
234
	
254
 
-
 
255
	for (i=0; i
235
	path_offset = buf + 10;
256
	{
-
 
257
		if (getElementSelectedFlag(i) == true) {
236
	for (j = 0; j < elements_count; j++) {
258
			sprintf(#del_from,"%s/%s", #path, items.get(i)*304+buf+72);
-
 
259
			Del_File2(#del_from, 1);
237
		RecursiveDelete(path_offset, true);
260
		}
-
 
261
	}
238
		path_offset += strlen(path_offset) + 1;
262
 
-
 
263
	if (del_error) Write_Error(del_error);
239
	}
264
	cmd_free = 6;
240
	if (del_error) Write_Error(del_error);
265
	DialogExit();
241
	DialogExit();
266
}
242
}
267
>
243
>