Subversion Repositories Kolibri OS

Rev

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

Rev 8764 Rev 8826
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 {NOCUT, CUT};
48
 
48
 
49
void EventCopy(bool _cut_active)
49
void EventCopy(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
	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);
90
			//setElementSelectedFlag(i, false);
91
 
91
 
92
			if (cut_active) {
92
			if (cut_active) {
93
				if (i>=files.first) && (i
93
				if (i>=files.first) && (i
94
					PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
94
					PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
95
			}
95
			}
96
		}
96
		}
97
	}
97
	}
98
	if (cut_active) {
98
	if (cut_active) {
99
		pause(20);
99
		pause(20);
100
		List_ReDraw();
100
		List_ReDraw();
101
	}
101
	}
102
	if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
102
	if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
103
	Clipboard__SetSlotData(size_buf, buff_data);
103
	Clipboard__SetSlotData(size_buf, buff_data);
104
	free(buff_data);
104
	free(buff_data);
105
}
105
}
106
 
106
 
107
 
107
 
108
void PasteThread()
108
void PasteThread()
109
{
109
{
110
	char copy_rezult;
110
	char copy_rezult;
111
	int j;
111
	int j, i, slash_count=0;
112
	int paste_elements_count = 0;
112
	int paste_elements_count = 0;
113
	dword buf;
113
	dword buf;
114
	dword path_offset;
114
	dword path_offset;
115
	
115
	
116
	buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
116
	buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
117
	if (DSDWORD[buf+4] != 3) return;
117
	if (DSDWORD[buf+4] != 3) return;
118
	paste_elements_count = ESINT[buf+8];
118
	paste_elements_count = ESINT[buf+8];
119
	path_offset = buf + 10;
119
	path_offset = buf + 10;
120
 
120
 
121
	if (cut_active) {
121
	if (cut_active) {
122
		DisplayOperationForm(MOVE_FLAG);
122
		DisplayOperationForm(MOVE_FLAG);
123
	} else {
123
	} else {
124
		DisplayOperationForm(COPY_FLAG);	
124
		DisplayOperationForm(COPY_FLAG);	
125
	} 
125
	} 
126
 
126
 
-
 
127
	if (cut_active) {
-
 
128
		for (j = 0; j < paste_elements_count; j++) {
-
 
129
			sprintf(#copy_to, "%s/%s", #path, path_offset+strrchr(path_offset,'/'));
-
 
130
			slash_count = 0;
-
 
131
			for (i=0; i<=10; i++) {
-
 
132
				if (copy_to[i]=='/') slash_count++;
-
 
133
				if (slash_count==3) break;
-
 
134
			}
-
 
135
			if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
-
 
136
			RenameMove(#copy_to+i, path_offset);
-
 
137
			if (EAX!=0) goto _DIFFERENT_DRIVES;
-
 
138
			path_offset += strlen(path_offset) + 1;
-
 
139
		}
-
 
140
		cut_active=false;
-
 
141
		DialogExit();
-
 
142
	}
-
 
143
 
-
 
144
_DIFFERENT_DRIVES:
-
 
145
	path_offset = buf + 10;
127
	for (j = 0; j < paste_elements_count; j++) {
146
	for (j = 0; j < paste_elements_count; j++) {
128
		copy_bar.max += GetFilesCount(path_offset);
147
		copy_bar.max += GetFilesCount(path_offset);
129
		path_offset += strlen(path_offset) + 1;
148
		path_offset += strlen(path_offset) + 1;
130
	}
149
	}
131
	
150
	
132
	path_offset = buf + 10;
151
	path_offset = buf + 10;
133
	for (j = 0; j < paste_elements_count; j++) {
152
	for (j = 0; j < paste_elements_count; j++) {
134
		strcpy(#copy_from, path_offset);
153
		strcpy(#copy_from, path_offset);
135
		if (!copy_from) DialogExit();
154
		if (!copy_from) DialogExit();
136
		sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
155
		sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
137
		if (streq(#copy_from,#copy_to))
156
		if (streq(#copy_from,#copy_to))
138
		{
157
		{
139
			if (cut_active) continue;
158
			if (cut_active) continue;
140
			sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
159
			sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
141
		}
160
		}
142
		if (strstr(#copy_to, #copy_from))
161
		if (strstr(#copy_to, #copy_from))
143
		{
162
		{
144
			notify("Copy directory into itself is a bad idea...");
163
			notify("Copy directory into itself is a bad idea...");
145
			DialogExit();
164
			DialogExit();
146
		}
165
		}
147
 
166
 
148
		if (copy_rezult = copyf(#copy_from,#copy_to))
167
		if (copy_rezult = copyf(#copy_from,#copy_to))
149
		{
168
		{
150
			Write_Error(copy_rezult);
169
			Write_Error(copy_rezult);
151
			if (copy_rezult==8) DialogExit(); //not enough space
170
			if (copy_rezult==8) DialogExit(); //not enough space
152
		}
171
		}
153
		else if (cut_active)
172
		else if (cut_active)
154
		{
173
		{
155
			strcpy(#file_path, #copy_from);
174
			strcpy(#file_path, #copy_from);
156
			Del_File2(#copy_from, 0);
175
			Del_File2(#copy_from, 0);
157
			
176
			
158
		}
177
		}
159
		path_offset += strlen(path_offset) + 1;
178
		path_offset += strlen(path_offset) + 1;
160
	}
179
	}
161
	cut_active=false;
180
	cut_active=false;
162
	DialogExit();
181
	DialogExit();
163
}
182
}
164
 
183
 
165
 
184
 
166
//===================================================//
185
//===================================================//
167
//                                                   //
186
//                                                   //
168
//                     DELETE                        //
187
//                     DELETE                        //
169
//                                                   //
188
//                                                   //
170
//===================================================//
189
//===================================================//
171
 
190
 
172
int del_error;
191
int del_error;
173
int Del_File2(dword way, sh_progr)
192
int Del_File2(dword way, sh_progr)
174
{    
193
{    
175
	dword dirbuf, fcount, i, filename;
194
	dword dirbuf, fcount, i, filename;
176
	int error;
195
	int error;
177
	char del_from[4096];
196
	char del_from[4096];
178
	if (dir_exists(way))
197
	if (dir_exists(way))
179
	{
198
	{
180
		if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
199
		if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
181
		for (i=0; i
200
		for (i=0; i
182
		{
201
		{
183
			//if (CheckEvent()==evReDraw) draw_window();
202
			//if (CheckEvent()==evReDraw) draw_window();
184
			filename = i*304+dirbuf+72;
203
			filename = i*304+dirbuf+72;
185
			sprintf(#del_from,"%s/%s",way,filename);
204
			sprintf(#del_from,"%s/%s",way,filename);
186
			if ( TestBit(ESDWORD[filename-40], 4) )
205
			if ( TestBit(ESDWORD[filename-40], 4) )
187
			{
206
			{
188
				Del_File2(#del_from, 1);
207
				Del_File2(#del_from, 1);
189
			}
208
			}
190
			else
209
			else
191
			{
210
			{
192
				if (sh_progr) Operation_Draw_Progress(filename);
211
				if (sh_progr) Operation_Draw_Progress(filename);
193
				if (error = DeleteFile(#del_from)) del_error = error;
212