2004-06-15 20:41:49 +00:00
|
|
|
/*
|
2006-12-26 10:58:39 +00:00
|
|
|
GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
|
2004-06-15 20:41:49 +00:00
|
|
|
|
|
|
|
Copyright (C) 2000-2004 Free Software Foundation
|
|
|
|
|
|
|
|
Authors: Philippe C.D. Robert
|
|
|
|
Serg Stoyan
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
#import <ProjectCenter/PCDefines.h>
|
2009-02-28 22:10:30 +00:00
|
|
|
#import <ProjectCenter/PCProjectManager.h>
|
2006-12-26 10:58:39 +00:00
|
|
|
#import <ProjectCenter/PCProject.h>
|
|
|
|
#import <ProjectCenter/PCProjectEditor.h>
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
#import <ProjectCenter/PCLogController.h>
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
#import <Protocols/CodeEditor.h>
|
|
|
|
#import <ProjectCenter/PCProjectLoadedFiles.h>
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2009-03-09 20:15:10 +00:00
|
|
|
#import "Modules/Preferences/Misc/PCMiscPrefs.h"
|
2009-02-27 00:46:25 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
@implementation PCProjectLoadedFiles
|
|
|
|
|
|
|
|
- (id)initWithProject:(PCProject *)aProj
|
|
|
|
{
|
2009-02-28 22:10:30 +00:00
|
|
|
id <PCPreferences> prefs;
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
NSAssert(aProj, @"Project is mandatory!");
|
|
|
|
|
2009-02-28 22:10:30 +00:00
|
|
|
prefs = [[aProj projectManager] prefController];
|
|
|
|
|
2004-06-19 21:55:29 +00:00
|
|
|
PCLogStatus(self, @"init");
|
2004-06-11 13:43:02 +00:00
|
|
|
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
project = aProj;
|
|
|
|
editedFiles = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// Column
|
2004-06-12 19:23:26 +00:00
|
|
|
filesColumn = [(NSTableColumn *)[NSTableColumn alloc]
|
|
|
|
initWithIdentifier:@"Files List"];
|
2004-06-11 13:43:02 +00:00
|
|
|
[filesColumn setEditable:NO];
|
|
|
|
|
|
|
|
// Table
|
|
|
|
filesList = [[NSTableView alloc]
|
|
|
|
initWithFrame:NSMakeRect(0,0,160,128)];
|
|
|
|
[filesList setAllowsMultipleSelection:NO];
|
|
|
|
[filesList setAllowsColumnReordering:NO];
|
|
|
|
[filesList setAllowsColumnResizing:NO];
|
|
|
|
[filesList setAllowsEmptySelection:YES];
|
|
|
|
[filesList setAllowsColumnSelection:NO];
|
|
|
|
[filesList setCornerView:nil];
|
|
|
|
[filesList setHeaderView:nil];
|
|
|
|
[filesList addTableColumn:filesColumn];
|
|
|
|
[filesList setDataSource:self];
|
2004-07-21 21:53:05 +00:00
|
|
|
[filesList setDrawsGrid:NO];
|
2004-06-11 13:43:02 +00:00
|
|
|
[filesList setTarget:self];
|
|
|
|
[filesList setDoubleAction:@selector(doubleClick:)];
|
|
|
|
[filesList setAction:@selector(click:)];
|
|
|
|
|
|
|
|
// Scrollview
|
|
|
|
filesScroll = [[NSScrollView alloc] initWithFrame:
|
|
|
|
NSMakeRect (0, 0, 80, 128)];
|
|
|
|
[filesScroll setDocumentView:filesList];
|
|
|
|
[filesScroll setHasHorizontalScroller:NO];
|
|
|
|
[filesScroll setHasVerticalScroller:YES];
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if (![prefs boolForKey:UseTearOffWindows])
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
[filesScroll setBorderType:NSBezelBorder];
|
|
|
|
}
|
|
|
|
|
|
|
|
sortType = PHSortByTime;
|
|
|
|
|
|
|
|
[filesList reloadData];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(fileDidOpen:)
|
|
|
|
name:PCEditorDidOpenNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(fileDidClose:)
|
|
|
|
name:PCEditorDidCloseNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(editorDidBecomeActive:)
|
|
|
|
name:PCEditorDidBecomeActiveNotification
|
|
|
|
object:nil];
|
2004-06-19 21:55:29 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(editorDidChangeFileName:)
|
|
|
|
name:PCEditorDidChangeFileNameNotification
|
|
|
|
object:nil];
|
2004-06-11 13:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2004-06-19 21:55:29 +00:00
|
|
|
#ifdef DEVELOPMENT
|
2004-06-11 13:43:02 +00:00
|
|
|
NSLog (@"PCProjectLoadedFiles: dealloc");
|
2004-06-19 21:55:29 +00:00
|
|
|
#endif
|
2004-06-11 13:43:02 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
|
|
|
RELEASE(filesColumn);
|
|
|
|
RELEASE(filesList);
|
|
|
|
RELEASE(filesScroll);
|
|
|
|
RELEASE(editedFiles);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView *)componentView
|
|
|
|
{
|
|
|
|
return filesScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)editedFilesRep
|
|
|
|
{
|
|
|
|
if (sortType == PHSortByName)
|
|
|
|
{
|
|
|
|
NSArray *sortedArray = nil;
|
|
|
|
|
|
|
|
sortedArray = [editedFiles
|
|
|
|
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
|
|
|
|
|
|
|
return sortedArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
return editedFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSortType:(PHSortType)type
|
|
|
|
{
|
|
|
|
int row;
|
|
|
|
NSString *filePath = nil;
|
|
|
|
|
|
|
|
if ([editedFiles count] > 0)
|
|
|
|
{
|
|
|
|
row = [filesList selectedRow];
|
|
|
|
filePath = [[self editedFilesRep] objectAtIndex:row];
|
|
|
|
}
|
|
|
|
|
|
|
|
sortType = type;
|
|
|
|
[filesList reloadData];
|
|
|
|
|
|
|
|
|
|
|
|
if ([editedFiles count] > 0)
|
|
|
|
{
|
|
|
|
row = [[self editedFilesRep] indexOfObject:filePath];
|
|
|
|
[filesList selectRow:row byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSortByTime
|
|
|
|
{
|
|
|
|
[self setSortType:PHSortByTime];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSortByName
|
|
|
|
{
|
|
|
|
[self setSortType:PHSortByName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectNextFile
|
|
|
|
{
|
|
|
|
int row = [filesList selectedRow];
|
|
|
|
|
|
|
|
if (row == ([filesList numberOfRows]-1))
|
|
|
|
{
|
|
|
|
[filesList selectRow:0 byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[filesList selectRow:row+1 byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
[self click:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectPreviousFile
|
|
|
|
{
|
|
|
|
int row = [filesList selectedRow];
|
|
|
|
|
|
|
|
if (row == 0)
|
|
|
|
{
|
|
|
|
[filesList selectRow:[filesList numberOfRows]-1 byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[filesList selectRow:row-1 byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
[self click:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)click:(id)sender
|
|
|
|
{
|
|
|
|
int row = [filesList selectedRow];
|
|
|
|
NSString *path = [[self editedFilesRep] objectAtIndex:row];
|
|
|
|
|
|
|
|
[[project projectEditor] orderFrontEditorForFile:path];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)doubleClick:(id)sender
|
|
|
|
{
|
|
|
|
// TODO: Open separate editor window for file
|
2004-07-01 11:36:33 +00:00
|
|
|
// PCLogInfo(self, @"ProjectLoadedFiles doubleClick received");
|
2004-06-11 13:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// ==== Notifications
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
- (void)fileDidOpen:(NSNotification *)aNotif
|
|
|
|
{
|
2006-12-26 10:58:39 +00:00
|
|
|
id<CodeEditor> editor = [aNotif object];
|
|
|
|
NSString *filePath = nil;
|
|
|
|
int row;
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2008-01-21 22:26:36 +00:00
|
|
|
if ([editor editorManager] != [project projectEditor])
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
PCLogWarning(self, @"File opened from other project");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-01 11:36:33 +00:00
|
|
|
// PCLogInfo(self, @"File did open in project %@", [project projectName]);
|
2004-06-11 13:43:02 +00:00
|
|
|
|
|
|
|
filePath = [editor path];
|
|
|
|
|
|
|
|
if ([editedFiles containsObject:filePath] == YES)
|
|
|
|
{
|
|
|
|
[editedFiles removeObject:filePath];
|
|
|
|
}
|
|
|
|
|
|
|
|
[editedFiles insertObject:filePath atIndex:0];
|
|
|
|
[filesList reloadData];
|
|
|
|
|
|
|
|
row = [[self editedFilesRep] indexOfObject:filePath];
|
|
|
|
[filesList selectRow:row byExtendingSelection:NO];
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
// PCLogInfo(self, @"fileDidOpen.END");
|
2004-06-11 13:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)fileDidClose:(NSNotification *)aNotif
|
|
|
|
{
|
2006-12-26 10:58:39 +00:00
|
|
|
id<CodeEditor> editor = [aNotif object];
|
|
|
|
NSString *filePath = [editor path];
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2008-01-21 22:26:36 +00:00
|
|
|
if ([editor editorManager] != [project projectEditor])
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
PCLogWarning(self, @"File from other project closed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([editedFiles containsObject:filePath] == YES)
|
|
|
|
{
|
|
|
|
[editedFiles removeObject:filePath];
|
|
|
|
[filesList reloadData];
|
|
|
|
|
|
|
|
if ([editedFiles count] > 0)
|
|
|
|
{
|
|
|
|
unsigned row;
|
|
|
|
|
|
|
|
filePath = [editedFiles objectAtIndex:0];
|
|
|
|
row = [[self editedFilesRep] indexOfObject:filePath];
|
|
|
|
[filesList selectRow:row byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)editorDidBecomeActive:(NSNotification *)aNotif
|
|
|
|
{
|
2006-12-26 10:58:39 +00:00
|
|
|
id<CodeEditor> editor = [aNotif object];
|
|
|
|
NSString *filePath = nil;
|
|
|
|
unsigned index;
|
|
|
|
unsigned filesCount;
|
2004-06-11 13:43:02 +00:00
|
|
|
|
2008-01-21 22:26:36 +00:00
|
|
|
if ([editor editorManager] != [project projectEditor])
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-19 21:55:29 +00:00
|
|
|
if ((filesCount = [editedFiles count]) > 0)
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
filePath = [editor path];
|
|
|
|
index = [[self editedFilesRep] indexOfObject:filePath];
|
2006-12-26 10:58:39 +00:00
|
|
|
if (index < filesCount)
|
2004-06-19 21:55:29 +00:00
|
|
|
{
|
|
|
|
[filesList selectRow:index byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)editorDidChangeFileName:(NSNotification *)aNotif
|
|
|
|
{
|
2006-12-26 10:58:39 +00:00
|
|
|
NSDictionary *_editorDict = [aNotif object];
|
|
|
|
id<CodeEditor> _editor = [_editorDict objectForKey:@"Editor"];
|
|
|
|
NSString *_oldFileName = nil;
|
|
|
|
NSString *_newFileName = nil;
|
|
|
|
unsigned index;
|
2004-06-19 21:55:29 +00:00
|
|
|
|
2008-01-21 22:26:36 +00:00
|
|
|
if ([_editor editorManager] != [project projectEditor])
|
2004-06-19 21:55:29 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_oldFileName = [_editorDict objectForKey:@"OldFile"];
|
|
|
|
_newFileName = [_editorDict objectForKey:@"NewFile"];
|
|
|
|
if ([editedFiles count] > 0)
|
|
|
|
{
|
|
|
|
index = [editedFiles indexOfObject:_oldFileName];
|
|
|
|
[editedFiles replaceObjectAtIndex:index withObject:_newFileName];
|
|
|
|
[filesList reloadData];
|
2004-06-11 13:43:02 +00:00
|
|
|
[filesList selectRow:index byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PCProjectLoadedFiles (LoadedFilesTableDelegate)
|
|
|
|
|
2013-02-10 18:34:12 +00:00
|
|
|
- (NSInteger)numberOfRowsInTableView: (NSTableView *)aTableView
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
if (aTableView != filesList)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [editedFiles count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *)aTableView
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)aTableColumn
|
2013-02-10 18:34:12 +00:00
|
|
|
row: (NSInteger)rowIndex
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
if (aTableView != filesList)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sortType == PHSortByName)
|
|
|
|
{
|
|
|
|
NSArray *sortedArray = nil;
|
|
|
|
|
|
|
|
sortedArray = [editedFiles
|
|
|
|
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
|
|
|
|
|
|
|
return [[sortedArray objectAtIndex:rowIndex] lastPathComponent];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [[editedFiles objectAtIndex:rowIndex] lastPathComponent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView:(NSTableView *)aTableView
|
|
|
|
setObjectValue:anObject
|
|
|
|
forTableColumn:(NSTableColumn *)aTableColumn
|
2013-02-10 18:34:12 +00:00
|
|
|
row:(NSInteger)rowIndex
|
2004-06-11 13:43:02 +00:00
|
|
|
{
|
|
|
|
/* NSString *path = nil;
|
|
|
|
NSParameterAssert (rowIndex >= 0 && rowIndex < [editedFiles count]);
|
|
|
|
|
|
|
|
[editedFiles removeObjectAtIndex:rowIndex];
|
|
|
|
[editedFiles insertObject:anObject atIndex:rowIndex];
|
|
|
|
|
|
|
|
path =
|
|
|
|
[filesPath removeObjectAtIndex:rowIndex];
|
|
|
|
[filesPath insertObject:[editor path] atIndex:rowIndex];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|