1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
|
/*
GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
Copyright (C) 2000-2010 Free Software Foundation
Authors: Philippe C.D. Robert
Serg Stoyan
Riccardo Mottola
German Arias
This file is part of GNUstep.
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <ProjectCenter/PCDefines.h>
#import <ProjectCenter/PCProjectManager.h>
#import <ProjectCenter/PCProject.h>
#import <ProjectCenter/PCProjectBrowser.h>
#import <ProjectCenter/PCProjectWindow.h>
#import <ProjectCenter/PCProjectInspector.h>
#import <ProjectCenter/PCFileManager.h>
#import <ProjectCenter/PCLogController.h>
@implementation PCProjectInspector
// ============================================================================
// ==== Intialization & deallocation
// ============================================================================
- (id)initWithProjectManager:(PCProjectManager *)manager
{
projectManager = manager;
[self loadPanel];
// Track project switching
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(activeProjectDidChange:)
name:PCActiveProjectDidChangeNotification
object:nil];
// Track project dictionary changing
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateValues:)
name:PCProjectDictDidChangeNotification
object:nil];
// Track Browser selection changes
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector (browserDidSetPath:)
name:PCBrowserDidSetPathNotification
object:nil];
[self inspectorPopupDidChange:inspectorPopup];
return self;
}
- (void)close
{
[inspectorPanel performClose:self];
}
- (void)dealloc
{
#ifdef DEVELOPMENT
NSLog (@"PCProjectInspector: dealloc");
#endif
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE(buildAttributesView);
RELEASE(projectAttributesSubview);
RELEASE(projectAttributesView);
RELEASE(projectDescriptionView);
RELEASE(projectLanguagesView);
RELEASE(fileAttributesView);
RELEASE(inspectorPanel);
RELEASE(fileName);
[super dealloc];
}
// ============================================================================
// ==== Panel & contents
// ============================================================================
- (BOOL)loadPanel
{
if ([NSBundle loadNibNamed:@"ProjectInspector" owner:self] == NO)
{
PCLogError(self, @"error loading NIB file!");
return NO;
}
// Panel
[inspectorPanel setFrameAutosaveName:@"ProjectInspector"];
[inspectorPanel setFrameUsingName:@"ProjectInspector"];
project = [projectManager activeProject];
projectDict = [project projectDict];
// PopUp
[inspectorPopup selectItemAtIndex:0];
// Build Attributes
[self createBuildAttributes];
// Project Attributes
[self createProjectAttributes];
// Project Description
[self createProjectDescription];
// Project Languages
[self createProjectLanguages];
// File Attributes
[self createFileAttributes];
[self activeProjectDidChange:nil];
return YES;
}
- (NSPanel *)panel
{
if (!inspectorPanel && ([self loadPanel] == NO))
{
return nil;
}
return inspectorPanel;
}
- (NSView *)contentView
{
if (!contentView && ([self loadPanel] == NO))
{
return nil;
}
return contentView;
}
// ============================================================================
// ==== Actions
// ============================================================================
- (void)inspectorPopupDidChange:(id)sender
{
switch([sender indexOfSelectedItem])
{
case 0:
[inspectorView setContentView:buildAttributesView];
break;
case 1:
[inspectorView setContentView:projectAttributesView];
break;
case 2:
[inspectorView setContentView:projectDescriptionView];
break;
case 3:
[inspectorView setContentView:projectLanguagesView];
break;
case 4:
[inspectorView setContentView:fileAttributesView];
break;
}
[inspectorView display];
}
- (void)changeCommonProjectEntry:(id)sender
{
NSString *newEntry = [sender stringValue];
// Build Atributes
if (sender == installDomainPopup)
{
[project setProjectDictObject:newEntry
forKey:PCInstallDomain
notify:YES];
}
else if (sender == cppOptField)
{
[project setProjectDictObject:newEntry
forKey:PCPreprocessorOptions
notify:YES];
}
else if (sender == objcOptField)
{
[project setProjectDictObject:newEntry
forKey:PCObjCCompilerOptions
notify:YES];
}
else if (sender == cOptField)
{
[project setProjectDictObject:newEntry
forKey:PCCompilerOptions
notify:YES];
}
else if (sender == ldOptField)
{
[project setProjectDictObject:newEntry
forKey:PCLinkerOptions
notify:YES];
}
// Project Description
else if (sender == descriptionField)
{
[project setProjectDictObject:newEntry forKey:PCDescription notify:YES];
}
else if (sender == releaseField)
{
[project setProjectDictObject:newEntry forKey:PCRelease notify:YES];
}
else if (sender == licenseField)
{
[project setProjectDictObject:newEntry forKey:PCCopyright notify:YES];
}
else if (sender == licDescriptionField)
{
[project setProjectDictObject:newEntry
forKey:PCCopyrightDescription
notify:YES];
}
else if (sender == urlField)
{
[project setProjectDictObject:newEntry forKey:PCURL notify:YES];
}
}
- (void)selectSectionWithTitle:(NSString *)sectionTitle
{
[inspectorPopup selectItemWithTitle:sectionTitle];
[self inspectorPopupDidChange:inspectorPopup];
}
// When user ends editing of text field with Tab or changing focus, entered
// changes should be accepted. The exception is PCFileName fields. I'm not sure
// if this is correct implementation. Action is performed twice if user ends
// editing with Enter key.
- (void)controlTextDidEndEditing:(NSNotification *)aNotif
{
NSControl *anObject = [aNotif object];
id target = [anObject target];
SEL action = [anObject action];
if ([anObject isKindOfClass:[PCFileNameField class]])
{
return;
}
if ([target respondsToSelector:action])
{
[target performSelector:action withObject:anObject];
}
}
// ============================================================================
// ==== Notifications
// ============================================================================
- (void)activeProjectDidChange:(NSNotification *)aNotif
{
PCProject *rootProject = [projectManager rootActiveProject];
NSView *newProjAttrSubview = nil;
if (rootProject != project)
{
[inspectorPanel setTitle: [NSString stringWithFormat:
@"%@ - Project Inspector", [rootProject projectName]]];
}
project = [projectManager activeProject];
projectDict = [project projectDict];
PCLogStatus(self, @"Active projectChanged to %@",
[[project projectDict] objectForKey:PCProjectName]);
// 1. Get custom project attributes view
newProjAttrSubview = [project projectAttributesView];
if (projectAttributesSubview == nil)
{
[projectAttributesView addSubview:newProjAttrSubview];
}
else
{
[projectAttributesView replaceSubview:projectAttributesSubview
with:newProjAttrSubview];
}
projectAttributesSubview = newProjAttrSubview;
// 2. Update values in UI elements
[self updateValues:nil];
// 3. Display current view
[self inspectorPopupDidChange:inspectorPopup];
}
- (void)updateValues:(NSNotification *)aNotif
{
// Build Attributes view
searchHeaders = [projectDict objectForKey:PCSearchHeaders];
searchLibs = [projectDict objectForKey:PCSearchLibs];
[self searchOrderPopupDidChange:searchOrderPopup];
[projectNameLabel setStringValue:[project projectName]];
[cppOptField setStringValue:
[projectDict objectForKey:PCPreprocessorOptions]];
[objcOptField setStringValue:
[projectDict objectForKey:PCObjCCompilerOptions]];
[cOptField setStringValue:
[projectDict objectForKey:PCCompilerOptions]];
[ldOptField setStringValue:
[projectDict objectForKey:PCLinkerOptions]];
[installDomainPopup selectItemWithTitle:
[projectDict objectForKey:PCInstallDomain]];
// Project Attributes
[projectTypeField setStringValue:[projectDict objectForKey:PCProjectType]];
[projectNameField setStringValue:[projectDict objectForKey:PCProjectName]];
[projectLanguagePB removeAllItems];
[projectLanguagePB addItemsWithTitles:
[projectDict objectForKey:PCUserLanguages]];
[projectLanguagePB selectItemWithTitle:
[projectDict objectForKey:PCLanguage]];
// Project Description view
[descriptionField setStringValue:
[projectDict objectForKey:PCDescription]];
[releaseField setStringValue:
[projectDict objectForKey:PCRelease]];
[licenseField setStringValue:
[projectDict objectForKey:PCCopyright]];
[licDescriptionField setStringValue:
[projectDict objectForKey:PCCopyrightDescription]];
[urlField setStringValue:
[projectDict objectForKey:PCURL]];
authorsItems = [projectDict objectForKey:PCAuthors];
[authorsList reloadData];
//Project Languages
languagesItems = [projectDict objectForKey:PCUserLanguages];
[languagesList reloadData];
// File Attributes
[fileIconView setDelegate:[project projectBrowser]];
[fileIconView updateIcon];
[self updateFileAttributes];
}
- (void)browserDidSetPath:(NSNotification *)aNotif
{
[fileIconView updateIcon];
[self updateFileAttributes];
}
// ============================================================================
// ==== Build Attributes
// ============================================================================
- (void)createBuildAttributes
{
if (buildAttributesView)
{
return;
}
if ([NSBundle loadNibNamed:@"BuildAttributes" owner:self] == NO)
{
PCLogError(self, @"error loading BuildAttributes NIB file!");
return;
}
// Search Order
// Popup
[searchOrderPopup selectItemAtIndex:0];
// Table
[searchOrderList setCornerView:nil];
[searchOrderList setHeaderView:nil];
[searchOrderList setTarget:self];
[searchOrderList setAction:@selector(searchOrderClick:)];
// [searchOrderColumn setEditable:NO];
// Buttons
[self setSearchOrderButtonsState];
// Retain view
[buildAttributesView retain];
}
// --- Search Order
- (void)searchOrderPopupDidChange:(id)sender
{
NSString *selectedTitle = [sender titleOfSelectedItem];
if ([selectedTitle isEqualToString:@"Header Directories Search Order"])
{
ASSIGN(searchItems, [NSMutableArray arrayWithArray:searchHeaders]);
}
else if ([selectedTitle isEqualToString:@"Library Directories Search Order"])
{
ASSIGN(searchItems, [NSMutableArray arrayWithArray:searchLibs]);
}
else if ([selectedTitle isEqualToString:@"Build Targets"])
{
ASSIGN(searchItems,[NSMutableArray arrayWithArray:[project buildTargets]]);
}
else
{
ASSIGN(searchItems,nil);
}
[searchOrderList reloadData];
[searchOrderList deselectAll:self];
[searchOrderTF setStringValue:@""];
// Enable/disable buttons according to selected/not selected item
[self setSearchOrderButtonsState];
}
- (void)searchOrderDoubleClick:(id)sender
{
}
- (void)searchOrderClick:(id)sender
{
int row = [searchOrderList selectedRow];
[searchOrderTF setStringValue:[searchItems objectAtIndex:row]];
[searchOrderTF selectText:self];
[self setSearchOrderButtonsState];
}
- (void)setSearchOrderButtonsState
{
// "Set..." button is always off until functionality will be implemented
[searchOrderSet setEnabled:NO];
// After loadable inspectors implementation make it work by
// detection of text field becoming first responder.
/* if ([inspectorPanel firstResponder] == searchOrderTF)
{
[searchOrderAdd setEnabled:YES];
}
else
{
[searchOrderAdd setEnabled:NO];
}*/
if ([searchOrderList selectedRow] == -1)
{
[searchOrderRemove setEnabled:NO];
}
else
{
[searchOrderRemove setEnabled:YES];
}
}
- (void)setSearchOrder:(id)sender
{
}
- (void)removeSearchOrder:(id)sender
{
int row = [searchOrderList selectedRow];
if (row != -1)
{
[searchItems removeObjectAtIndex:row];
[self syncSearchOrder];
[searchOrderList reloadData];
}
}
- (void)addSearchOrder:(id)sender
{
NSString *value = [searchOrderTF stringValue];
if ([value isEqualToString:@""])
{
return;
}
[searchItems addObject:value];
[searchOrderTF setStringValue:@""];
[self syncSearchOrder];
[searchOrderList reloadData];
}
- (void)syncSearchOrder
{
int pIndex;
pIndex = [searchOrderPopup indexOfSelectedItem];
switch (pIndex)
{
case 0: // Headers
[project setProjectDictObject:searchItems
forKey:PCSearchHeaders
notify:YES];
break;
case 1: // Libraries
[project setProjectDictObject:searchItems
forKey:PCSearchLibs
notify:YES];
break;
case 2: // Targets
[project setProjectDictObject:searchItems
forKey:PCBuilderTargets
notify:YES];
return;
}
}
// ============================================================================
// ==== Project Attributes
// ============================================================================
- (void)createProjectAttributes
{
if (projectAttributesView)
{
return;
}
if ([NSBundle loadNibNamed:@"ProjectAttributes" owner:self] == NO)
{
PCLogError(self, @"error loading ProjectAttributes NIB file!");
return;
}
// Languages
[projectLanguagePB removeAllItems];
[projectLanguagePB addItemsWithTitles:
[projectDict objectForKey:PCUserLanguages]];
// Retain view
[projectAttributesView retain];
}
- (void)setCurrentLanguage:(id)sender
{
NSLog(@"set current language to %@", [sender titleOfSelectedItem]);
[project setProjectDictObject:[sender titleOfSelectedItem]
forKey:PCLanguage
notify:NO];
[[project projectWindow] setTitle];
}
// ============================================================================
// ==== Project Description
// ============================================================================
- (void)createProjectDescription
{
if (projectDescriptionView)
{
return;
}
if ([NSBundle loadNibNamed:@"ProjectDescription" owner:self] == NO)
{
PCLogError(self, @"error loading ProjectDescription NIB file!");
return;
}
// Authors table
authorsColumn = [(NSTableColumn *)[NSTableColumn alloc]
initWithIdentifier: @"Authors List"];
[authorsColumn setEditable:YES];
authorsList = [[NSTableView alloc]
initWithFrame:NSMakeRect(6,6,209,111)];
[authorsList setAllowsMultipleSelection:NO];
[authorsList setAllowsColumnReordering:NO];
[authorsList setAllowsColumnResizing:NO];
[authorsList setAllowsEmptySelection:YES];
[authorsList setAllowsColumnSelection:NO];
[authorsList setRowHeight:17.0];
[authorsList setCornerView:nil];
[authorsList setHeaderView:nil];
[authorsList addTableColumn:authorsColumn];
[authorsList setDataSource:self];
[authorsList setDelegate:self];
//
[authorsScroll setDocumentView:authorsList];
[authorsScroll setHasHorizontalScroller:NO];
[authorsScroll setHasVerticalScroller:YES];
[authorsScroll setBorderType:NSBezelBorder];
// Authors' buttons
[authorAdd setRefusesFirstResponder:YES];
[authorRemove setRefusesFirstResponder:YES];
[authorUp setRefusesFirstResponder:YES];
[authorUp setImage: [NSImage imageNamed:@"common_ArrowUp"]];
[authorDown setRefusesFirstResponder:YES];
[authorDown setImage: [NSImage imageNamed:@"common_ArrowDown"]];
// Link textfields
[descriptionField setNextText:releaseField];
[releaseField setNextText:licenseField];
[licenseField setNextText:licDescriptionField];
[licDescriptionField setNextText:urlField];
[urlField setNextText:descriptionField];
[projectDescriptionView retain];
}
// --- Actions
- (void)addAuthor:(id)sender
{
int row;
[authorsItems addObject:[NSMutableString stringWithString:@""]];
[authorsList reloadData];
row = [authorsItems count] - 1;
[authorsList selectRow:row byExtendingSelection:NO];
[authorsList editColumn:0 row:row withEvent:nil select:YES];
[project setProjectDictObject:authorsItems forKey:PCAuthors notify:YES];
}
- (void)removeAuthor:(id)sender
{
int selectedRow = [authorsList selectedRow];
if (selectedRow >= 0)
{
[authorsList selectRow:selectedRow byExtendingSelection:NO];
[authorsItems removeObjectAtIndex:selectedRow];
[authorsList reloadData];
}
if ([authorsList selectedRow] < 0 && [authorsItems count] > 0)
{
[authorsList selectRow:[authorsItems count]-1 byExtendingSelection:NO];
}
[project setProjectDictObject:authorsItems forKey:PCAuthors notify:YES];
}
- (void)upAuthor:(id)sender
{
int selectedRow = [authorsList selectedRow];
id previousRow;
id currentRow;
if (selectedRow > 0)
{
previousRow = [[authorsItems objectAtIndex: selectedRow-1] copy];
currentRow = [authorsItems objectAtIndex: selectedRow];
[authorsItems replaceObjectAtIndex: selectedRow-1 withObject: currentRow];
[authorsItems replaceObjectAtIndex: selectedRow withObject: previousRow];
[authorsList selectRow: selectedRow-1 byExtendingSelection: NO];
[authorsList reloadData];
[project setProjectDictObject:authorsItems forKey:PCAuthors notify:YES];
}
}
- (void)downAuthor:(id)sender
{
unsigned selectedRow = [authorsList selectedRow];
id nextRow;
id currentRow;
if (selectedRow < [authorsItems count]-1)
{
nextRow = [[authorsItems objectAtIndex: selectedRow+1] copy];
currentRow = [authorsItems objectAtIndex: selectedRow];
[authorsItems replaceObjectAtIndex: selectedRow+1 withObject: currentRow];
[authorsItems replaceObjectAtIndex: selectedRow withObject: nextRow];
[authorsList selectRow: selectedRow+1 byExtendingSelection: NO];
[authorsList reloadData];
[project setProjectDictObject:authorsItems forKey:PCAuthors notify:YES];
}
}
// ============================================================================
// ==== Project Languages
// ============================================================================
- (void)createProjectLanguages
{
if (projectLanguagesView)
{
return;
}
if ([NSBundle loadNibNamed:@"ProjectLanguages" owner:self] == NO)
{
PCLogError(self, @"error loading ProjectLanguages NIB file!");
return;
}
[projectLanguagesView retain];
[languagesList setDataSource:self];
}
- (void)addLanguage:(id)sender
{
NSString *language = [newLanguage stringValue];
[newLanguage setStringValue: @""];
//If there is a language and is new, add this
if (([language length] > 0) && (![languagesItems containsObject: language]))
{
//Add the language to the projectDict
[languagesItems addObject: language];
[project setProjectDictObject:languagesItems
forKey:PCUserLanguages
notify:YES];
/* If there are localizable resources, copy these into the new language
directory */
if ([[projectDict objectForKey:PCLocalizedResources] count] > 0)
{
NSString *file, *englishPath, *languagePath;
NSEnumerator *resources =
[[projectDict objectForKey:PCLocalizedResources] objectEnumerator];
englishPath = [project resourceDirForLanguage:@"English"];
languagePath = [project resourceDirForLanguage:language];
while ((file = [resources nextObject]))
{
if ([[projectManager fileManager] copyFile:file
fromDirectory:englishPath
intoDirectory:languagePath])
{
NSLog(@"file copied: %@", file);
}
}
}
}
}
- (void)removeLanguage:(id)sender
{
/* We don't remove the English language sice is needed if the app
isn't available at the end user language */
if (![[languagesItems objectAtIndex:
[languagesList selectedRow]] isEqualToString:@"English"])
{
NSString *language =
[languagesItems objectAtIndex:[languagesList selectedRow]];
NSString *languagePath = [project resourceDirForLanguage:language];
NSArray *resources = [projectDict objectForKey:PCLocalizedResources];
/* If there are localizable resources, remove these at the language
directory and the directory itsel */
if ([resources count] > 0)
{
if ([[projectManager fileManager] removeFiles:resources
fromDirectory:languagePath
removeDirsIfEmpty:YES])
{
NSLog(@"removed resources for language %@",language);
}
}
//Update the languages list
[languagesItems removeObject:language];
//If the removed language is the actual PCLanguage, set English
if ([[projectDict objectForKey: PCLanguage] isEqualToString:language])
{
NSLog(@"set current language to English");
[project setProjectDictObject:@"English"
forKey:PCLanguage
notify:NO];
}
//Update the projectDict
[project setProjectDictObject:languagesItems
forKey:PCUserLanguages
notify:YES];
}
else
{
NSRunAlertPanel(@"Remove Language",
@"You shouldn't remove language English",
@"Ok",nil,nil);
}
}
// ============================================================================
// ==== File Attributes
// ============================================================================
- (void)createFileAttributes
{
if (fileAttributesView)
{
return;
}
if ([NSBundle loadNibNamed:@"FileAttributes" owner:self] == NO)
{
PCLogError(self, @"error loading FileAttributes NIB file!");
return;
}
[fileAttributesView retain];
[localizableButton setRefusesFirstResponder:YES];
[publicHeaderButton setRefusesFirstResponder:YES];
[fileIconView setFileNameField:fileNameField];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(panelDidResignKey:)
name: NSWindowDidResignKeyNotification
object:inspectorPanel];
}
- (void)updateFileAttributes
{
PCProjectBrowser *browser = [project projectBrowser];
NSString *category = [browser nameOfSelectedCategory];
NSString *categoryKey = [project keyForCategory:category];
NSArray *files = [browser selectedFiles];
NSString *file = nil;
int array_count = [files count];
int present_count = 0;
NSArray *publicHeaders = nil;
NSArray *localizedResources = nil;
NSEnumerator *enumerator = nil;
// Initial default buttons state
[localizableButton setEnabled:NO];
[localizableButton setState:NSOffState];
[publicHeaderButton setEnabled:NO];
[publicHeaderButton setState:NSOffState];
if (files == nil)
{
return;
}
// --- Enable buttons
// If selection is not category AND category is allow localization
// enable localizableButton checkbox
if ([[project localizableKeys] containsObject:categoryKey])
{
[localizableButton setEnabled:YES];
}
// If selection is not category
// AND project accepts public headers
// AND file extension is .h or .H enable publicHeaders checkbox.
if ([project canHavePublicHeaders] == YES )
{
BOOL enable = YES;
enumerator = [files objectEnumerator];
while ((file = [enumerator nextObject]))
{
if (![[file pathExtension] isEqualToString:@"h"] &&
![[file pathExtension] isEqualToString:@"H"])
{
enable = NO;
}
}
if (enable)
{
[publicHeaderButton setEnabled:YES];
}
}
// --- Set state of buttons
// There are 3 sutiuations:
// - all files present in group (state: ON)
// - part of file present in group (state: OFF)
// - no files present in group (state: OFF)
// Set state of Public Headers button
if ([publicHeaderButton isEnabled])
{
publicHeaders = [project publicHeaders];
enumerator = [files objectEnumerator];
present_count = 0;
while ((file = [enumerator nextObject]))
{
if ([publicHeaders containsObject:file])
{
present_count++;
}
}
if (array_count == present_count)
{
[publicHeaderButton setState:NSOnState];
}
}
// Set state of Localized Resource button
if ([localizableButton isEnabled])
{
localizedResources = [project localizedResources];
enumerator = [files objectEnumerator];
present_count = 0;
while ((file = [enumerator nextObject]))
{
if ([localizedResources containsObject:file])
{
present_count++;
}
}
if (array_count == present_count)
{
[localizableButton setState:NSOnState];
}
}
}
- (void)beginFileRename
{
[fileNameField setEditableField:YES];
[inspectorPanel makeFirstResponder:fileNameField];
}
// Delegate method of PCFileNameField class
- (void)controlStringValueDidChange:(NSString *)aString
{
if (fileName != nil)
{
[fileName release];
}
fileName = [aString copy];
}
// Delegate method of PCFileNameField class
- (BOOL)textShouldSetEditable:(NSString *)text
{
if ([[project rootCategories] containsObject:text])
{
return NO;
}
return YES;
}
- (void)fileNameDidChange:(id)sender
{
if ([fileName isEqualToString:[fileNameField stringValue]])
{
return;
}
/* PCLogInfo(self, @"{%@} file name changed from: %@ to: %@",
[project projectName], fileName, [fileNameField stringValue]);*/
if ([project renameFile:fileName toFile:[fileNameField stringValue]] == NO)
{
[fileNameField setStringValue:fileName];
}
}
- (void)setPublicHeader:(id)sender
{
PCProjectBrowser *browser = [project projectBrowser];
NSArray *files = [browser selectedFiles];
NSEnumerator *enumerator = [files objectEnumerator];
NSString *file = nil;
while ((file = [enumerator nextObject]))
{
if ([sender state] == NSOffState)
{
[project setHeaderFile:fileName public:NO];
}
else
{
[project setHeaderFile:fileName public:YES];
}
}
}
- (void)setLocalizableResource:(id)sender
{
PCProjectBrowser *browser = [project projectBrowser];
NSArray *files = [browser selectedFiles];
NSEnumerator *enumerator = [files objectEnumerator];
NSString *file = nil;
while ((file = [enumerator nextObject]))
{
if ([sender state] == NSOffState)
{
[project setResourceFile:file localizable:NO];
}
else
{
[project setResourceFile:file localizable:YES];
}
}
}
- (void)panelDidResignKey:(NSNotification *)aNotif
{
if ([fileNameField isEditable] == YES)
{
[inspectorPanel makeFirstResponder:fileIconView];
[fileNameField setStringValue:fileName];
}
}
// ============================================================================
// ==== NSTableViews
// ============================================================================
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
if (searchOrderList != nil && aTableView == searchOrderList)
{
return [searchItems count];
}
else if (authorsList != nil && aTableView == authorsList)
{
return [authorsItems count];
}
else if (languagesList != nil && aTableView == languagesList)
{
return [languagesItems count];
}
return 0;
}
- (id) tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
if (searchOrderList != nil && aTableView == searchOrderList)
{
return [searchItems objectAtIndex:rowIndex];
}
else if (authorsList != nil && aTableView == authorsList)
{
return [authorsItems objectAtIndex:rowIndex];
}
else if (languagesList != nil && aTableView == languagesList)
{
return [languagesItems objectAtIndex:rowIndex];
}
return nil;
}
- (void) tableView:(NSTableView *)aTableView
setObjectValue:anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
if (authorsList != nil && aTableView == authorsList)
{
if([authorsItems count] == 0)
{
return;
}
[authorsItems removeObjectAtIndex:rowIndex];
[authorsItems insertObject:anObject atIndex:rowIndex];
[project setProjectDictObject:authorsItems forKey:PCAuthors notify:YES];
}
}
- (void) tableView: (NSTableView*)aTableView
willDisplayCell: (id)aCell
forTableColumn: (NSTableColumn*)aTableColumn
row: (NSInteger)rowIndex
{
[(NSTextFieldCell *)aCell setScrollable:YES];
}
@end
|