126_uppsrc2.diff

The diff file to apply for uppsrc directory (second version) - Sender Ghost, 11/08/2011 09:35 AM

Download (5.17 KB)

View differences:

uppsrc/ide/ide.lay 2011-11-08 13:36:45 +0600
622 622
	ITEM(EditString, folder, LeftPosZ(80, 312).TopPosZ(8, 19))
623 623
	ITEM(Label, dv___2, SetLabel(t_("Import files")).LeftPosZ(8, 72).TopPosZ(32, 19))
624 624
	ITEM(EditString, files, LeftPosZ(80, 312).TopPosZ(32, 19))
625
	ITEM(Option, tree, SetLabel(t_("Including tree structure")).LeftPosZ(8, 192).TopPosZ(56, 19))
625 626
	ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(260, 64).TopPosZ(60, 24))
626 627
	ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(328, 64).TopPosZ(60, 24))
627 628
END_LAYOUT
uppsrc/ide/UppDlg.h 2011-11-08 13:36:45 +0600
218 218
	void AddItem(const String& name, bool separator, bool readonly);
219 219
	void AddTopicGroup();
220 220
	void AddSeparator();
221
	void Import();
221
	void DoImportTree(const String& dir, const String& mask, bool sep, Progress& pi, int from);
222
	void DoImportTree(const String& dir, const String& mask, bool sep, Progress& pi);
222 223
	void DoImport(const String& dir, const String& mask, bool sep, Progress& pi);
224
	void DoImport(const String& dir, const String& mask, bool sep, Progress& pi, bool tree);
225
	void Import();
223 226
	void RemoveFile();
224 227
	void DelFile();
225 228
	void RenameFile();
uppsrc/ide/UppWspc.cpp 2011-11-08 14:11:33 +0600
435 435
	files <<= "*.cpp *.h *.hpp *.c *.C *.cxx *.cc";
436 436
}
437 437

  
438
void WorkspaceWork::DoImportTree(const String& dir, const String& mask, bool sep, Progress& pi, int from)
439
{
440
	String active = GetActivePackage();
441
	if(active.IsEmpty()) return;
442
	FindFile ff(AppendFileName(dir, "*.*"));
443
	Vector<String> dirs, files;
444
	while(ff) {
445
		String p = AppendFileName(dir, ff.GetName());
446
		if(ff.IsFile() && PatternMatchMulti(mask, ff.GetName()))
447
			files.Add(p);
448
		if(ff.IsFolder())
449
			dirs.Add(p);
450
		ff.Next();
451
	}
452
	String relPath(dir.Mid(from)),
453
		absPath = SourcePath(active, relPath);
454
	if(sep && files.GetCount()) {
455
		if(!DirectoryExists(absPath))
456
			if(!RealizeDirectory(absPath))
457
				throw Format("An error occurred while creating the directory:&\1%s", absPath);
458
		Package::File& f = actual.file.Add();
459
		f = relPath;
460
		f.separator = f.readonly = true;
461
	}
462
	Sort(files, GetLanguageInfo());
463
	Sort(dirs, GetLanguageInfo());
464
	for(int i = 0; i < files.GetCount(); i++) {
465
		if(pi.StepCanceled())
466
			throw String();
467
		String name = GetFileName(files[i]);
468
		if(FileCopy(files[i], AppendFileName(absPath, name))) {
469
			Package::File& f = actual.file.Add();
470
			f = AppendFileName(relPath, name);
471
			f.separator = f.readonly = false;
472
		}
473
		else
474
			throw Format("An error occurred while copying the file:&\1%s", files[i]);
475
	}
476
	for(int i = 0; i < dirs.GetCount(); i++)
477
		DoImportTree(dirs[i], mask, true, pi, from);
478
}
479

  
480
void WorkspaceWork::DoImportTree(const String& dir, const String& mask, bool sep, Progress& pi)
481
{
482
	int from = dir.EndsWith(AsString(DIR_SEP)) ? dir.GetCount() : dir.GetCount() + 1;
483
	DoImportTree(dir, mask, sep, pi, from);
484
}
485

  
438 486
void WorkspaceWork::DoImport(const String& dir, const String& mask, bool sep, Progress& pi)
439 487
{
440 488
	String active = GetActivePackage();
441 489
	if(active.IsEmpty()) return;
442 490
	FindFile ff(AppendFileName(dir, "*.*"));
443
	Vector<String> files;
444
	Vector<String> dirs;
491
	Vector<String> dirs, files;
445 492
	while(ff) {
446 493
		String p = AppendFileName(dir, ff.GetName());
447 494
		if(ff.IsFile() && PatternMatchMulti(mask, ff.GetName()))
......
454 501
		Package::File& f = actual.file.Add();
455 502
		f = GetFileTitle(dir);
456 503
		f.separator = f.readonly = true;
457
		sep = false;
458 504
	}
459
	Sort(files);
460
	Sort(dirs);
505
	Sort(files, GetLanguageInfo());
506
	Sort(dirs, GetLanguageInfo());
461 507
	for(int i = 0; i < files.GetCount(); i++) {
462 508
		if(pi.StepCanceled())
463 509
			throw String();
464 510
		String name = GetFileName(files[i]);
465
		SaveFile(SourcePath(active, name), LoadFile(files[i]));
466
		Package::File& f = actual.file.Add();
467
		f = name;
468
		f.separator = f.readonly = false;
511
		if(FileCopy(files[i], SourcePath(active, name))) {
512
			Package::File& f = actual.file.Add();
513
			f = name;
514
			f.separator = f.readonly = false;
515
		}
516
		else
517
			throw Format("An error occurred while copying the file:&\1%s", files[i]);
469 518
	}
470 519
	for(int i = 0; i < dirs.GetCount(); i++)
471 520
		DoImport(dirs[i], mask, true, pi);
472 521
}
473 522

  
523
void WorkspaceWork::DoImport(const String& dir, const String& mask, bool sep, Progress& pi, bool tree)
524
{
525
	if(tree)
526
		DoImportTree(dir, mask, sep, pi);
527
	else
528
		DoImport(dir, mask, sep, pi);
529
}
530

  
474 531
void WorkspaceWork::Import()
475 532
{
476 533
	String active = GetActivePackage();
......
482 539
	int fci = filelist.GetCursor();
483 540
	int cs = filelist.GetSbPos();
484 541
	try {
485
		DoImport(~dlg.folder, ~dlg.files, false, pi);
542
		DoImport(~dlg.folder, ~dlg.files, false, pi, ~dlg.tree);
543
	}
544
	catch(String msg) {
545
		if(!msg.IsEmpty())
546
			Exclamation(msg);
486 547
	}
487
	catch(String) {}
488 548
	SaveLoadPackage();
489 549
	filelist.SetSbPos(cs);
490 550
	filelist.SetCursor(fci >= 0 ? fci : filelist.GetCount() - 1);