* Start rewriting of PC preferences. "Build" preferences implemented

as loadable module. See Changelog for details.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@27969 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Sergii Stoian 2009-02-25 00:34:59 +00:00
parent ecec5ece13
commit 4b2e398b0d
14 changed files with 417 additions and 202 deletions

View file

@ -90,7 +90,8 @@ Modules/Projects/ResourceSet/ResourceSet.project \
Modules/Projects/Tool/Tool.project \
Modules/Editors/ProjectCenter/ProjectCenter.editor \
Modules/Parsers/ProjectCenter/ProjectCenter.parser \
Modules/Debuggers/ProjectCenter/ProjectCenter.debugger
Modules/Debuggers/ProjectCenter/ProjectCenter.debugger \
Modules/Preferences/Build/Build.preferences
#
# Localization

View file

@ -27,28 +27,19 @@
#import <Protocols/Preferences.h>
#ifndef PCDefaultBuildTool
#define PCDefaultBuildTool @"/usr/bin/make"
#endif
#ifndef PCDefaultDebugger
#define PCDefaultDebugger @"/usr/bin/gdb"
#endif
@interface PCPrefController : NSObject <PCPreferences>
{
NSUserDefaults *userDefaults;
IBOutlet NSPanel *panel;
IBOutlet NSPopUpButton *popupButton;
IBOutlet NSBox *sectionsView;
IBOutlet NSBox *buildingView;
IBOutlet NSTextField *successField;
IBOutlet NSButton *setSuccessButton;
IBOutlet NSTextField *failureField;
IBOutlet NSButton *setFailureButton;
IBOutlet NSTextField *rootBuildDirField;
IBOutlet NSButton *rootBuildDirButton;
IBOutlet NSButton *promptOnClean;
NSMutableDictionary *sectionsDict;
IBOutlet NSBox *savingView;
IBOutlet NSButton *saveOnQuit;
@ -64,8 +55,6 @@
IBOutlet NSButton *promptWhenQuit;
IBOutlet NSButton *deleteCache;
IBOutlet NSButton *fullPathInFilePanels;
IBOutlet NSTextField *buildToolField;
IBOutlet NSButton *buildToolButton;
IBOutlet NSTextField *debuggerField;
IBOutlet NSButton *debuggerButton;
IBOutlet NSTextField *editorField;
@ -100,11 +89,6 @@
- (void)popupChanged:(id)sender;
- (void)setSuccessSound:(id)sender;
- (void)setFailureSound:(id)sender;
- (void)setRootBuildDir:(id)sender;
- (void)setPromptOnClean:(id)sender;
- (void)setSaveOnQuit:(id)sender;
- (void)setKeepBackup:(id)sender;
- (void)setSavePeriod:(id)sender;

View file

@ -34,11 +34,15 @@
- (NSDictionary *)preferencesDict;
- (id)objectForKey:(NSString *)key;
- (void)setObject:(id)anObject forKey:(NSString *)aKey;
@end
@protocol PCPrefSection <NSObject>
@protocol PCPrefsSection <NSObject>
- (void)setPrefController:(id <PCPreferences>)prefs;
- (void)loadDefaults;
- (NSView *)view;
@end

View file

@ -32,7 +32,8 @@ SUBPROJECTS = \
Projects/ResourceSet \
Projects/Tool \
Editors/ProjectCenter \
Parsers/ProjectCenter
Parsers/ProjectCenter \
Preferences/Build
# Do not compile the Debuggers/ProjectCenter module on MinGW since I'm
# told at the moment it doesn't even compile there.

View file

@ -0,0 +1,41 @@
#
# GNUmakefile - Build preferences
#
PACKAGE_NAME = Build
include $(GNUSTEP_MAKEFILES)/common.make
#
# Bundle
#
BUNDLE_NAME = Build
BUNDLE_EXTENSION = .preferences
Build_PRINCIPAL_CLASS = PCBuildPrefs
#
# Additional libraries
#
Build_LIBRARIES_DEPEND_UPON +=
#
# Resource files
#
Build_RESOURCE_FILES= \
Resources/BuildPrefs.gorm \
Resources/Info.table
#
# Header files
#
Build_HEADERS= \
PCBuildPrefs.h
#
# Class files
#
Build_OBJC_FILES= \
PCBuildPrefs.m
include ../../GNUmakefile.bundles
include $(GNUSTEP_MAKEFILES)/bundle.make

View file

@ -0,0 +1,61 @@
//
// GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
//
// Copyright (C) 2001-2009 Free Software Foundation
//
// Authors: Sergii Stoian
//
// Description:
//
// 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 <AppKit/AppKit.h>
#import <Protocols/Preferences.h>
#ifndef PCDefaultBuildTool
#define PCDefaultBuildTool @"/usr/bin/make"
#endif
@interface PCBuildPrefs : NSObject <PCPrefsSection>
{
id <PCPreferences> prefs;
NSDictionary *prefsDict;
IBOutlet NSBox *buildingView;
IBOutlet NSTextField *successField;
IBOutlet NSButton *setSuccessButton;
IBOutlet NSTextField *failureField;
IBOutlet NSButton *setFailureButton;
IBOutlet NSTextField *rootBuildDirField;
IBOutlet NSButton *setRootBuildDirButton;
IBOutlet NSTextField *buildToolField;
IBOutlet NSButton *setBuildToolButton;
IBOutlet NSButton *promptOnClean;
}
// ----------------------------------------------------------------------------
// --- Init and free
// ----------------------------------------------------------------------------
- (id)init;
- (void)dealloc;
@end

View file

@ -0,0 +1,206 @@
//
// GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
//
// Copyright (C) 2001-2009 Free Software Foundation
//
// Authors: Sergii Stoian
//
// Description:
//
// 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/PCFileManager.h>
#import "PCBuildPrefs.h"
@implementation PCBuildPrefs
// ----------------------------------------------------------------------------
// --- Init and free
// ----------------------------------------------------------------------------
- (id)init
{
self = [super init];
if ([NSBundle loadNibNamed:@"BuildPrefs" owner:self] == NO)
{
NSLog(@"PCBuildPrefs: error loading NIB file!");
}
RETAIN(buildingView);
return self;
}
- (void)awakeFromNib
{
[setSuccessButton setRefusesFirstResponder:YES];
[setFailureButton setRefusesFirstResponder:YES];
[setRootBuildDirButton setRefusesFirstResponder:YES];
[setBuildToolButton setRefusesFirstResponder:YES];
[promptOnClean setRefusesFirstResponder:YES];
}
- (void)setPrefController:(id <PCPreferences>)aPrefs
{
NSString *val;
int state;
prefs = aPrefs;
// Building
if (!(val = [prefs objectForKey:SuccessSound]))
val = @"";
[successField setStringValue:val];
if (!(val = [prefs objectForKey:FailureSound]))
val = @"";
[failureField setStringValue:val];
if (!(val = [prefs objectForKey:RootBuildDirectory]))
val = @"";
[rootBuildDirField setStringValue:val];
if (!(val = [prefs objectForKey:BuildTool]))
val = PCDefaultBuildTool;
[buildToolField setStringValue:val];
val = [prefs objectForKey:PromptOnClean];
state = [val isEqualToString:@"YES"] ? NSOnState : NSOffState;
[promptOnClean setState:state];
}
- (void)loadDefaults
{
[prefs setObject:@"" forKey:SuccessSound];
[prefs setObject:@"" forKey:FailureSound];
[prefs setObject:@"" forKey:RootBuildDirectory];
[prefs setObject:PCDefaultBuildTool forKey:BuildTool];
[prefs setObject:@"YES" forKey:PromptOnClean];
}
- (void)dealloc
{
#ifdef DEBUG
NSLog (@"PCBuildPrefs: dealloc");
#endif
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE(buildingView);
[super dealloc];
}
// Protocol
- (NSView *)view
{
return buildingView;
}
// Actions
- (void)setSuccessSound:(id)sender
{
NSArray *types = [NSArray arrayWithObjects:@"snd",@"au",@"wav",nil];
NSArray *files;
NSString *path;
files = [[PCFileManager defaultManager] filesOfTypes:types
operation:PCOpenFileOperation
multiple:NO
title:@"Set Success Sound"
accView:nil];
if ((path = [files objectAtIndex:0]))
{
[successField setStringValue:path];
[prefs setObject:path forKey:SuccessSound];
}
}
- (void)setFailureSound:(id)sender
{
NSArray *types = [NSArray arrayWithObjects:@"snd",@"au",@"wav",nil];
NSArray *files;
NSString *path;
files = [[PCFileManager defaultManager] filesOfTypes:types
operation:PCOpenFileOperation
multiple:NO
title:@"Set Failure Sound"
accView:nil];
if ((path = [files objectAtIndex:0]))
{
[failureField setStringValue:path];
[prefs setObject:path forKey:FailureSound];
}
}
- (void)setRootBuildDir:(id)sender
{
NSArray *files;
NSString *path;
files = [[PCFileManager defaultManager] filesOfTypes:nil
operation:PCOpenProjectOperation
multiple:NO
title:@"Set Build Directory"
accView:nil];
if ((path = [files objectAtIndex:0]))
{
[rootBuildDirField setStringValue:path];
[prefs setObject:path forKey:RootBuildDirectory];
}
}
- (void)setBuildTool:(id)sender
{
NSArray *files;
NSString *path;
files = [[PCFileManager defaultManager] filesOfTypes:nil
operation:PCOpenFileOperation
multiple:NO
title:@"Set Build Tool"
accView:nil];
if ((path = [files objectAtIndex:0]))
{
[buildToolField setStringValue:path];
[prefs setObject:path forKey:BuildTool];
}
}
- (void)setPromptOnClean:(id)sender
{
NSString *state;
if (promptOnClean == nil)
{// HACK!!! need to be fixed in GNUstep
promptOnClean = sender;
return;
}
state = ([sender state] == NSOffState) ? @"NO" : @"YES";
[prefs setObject:state forKey:PromptOnClean];
}
@end

View file

@ -0,0 +1,35 @@
{
"## Comment" = "Do NOT change this file, Gorm maintains it";
FirstResponder = {
Actions = (
"setBuildTool:",
"setFailureSound:",
"setPromptOnClean:",
"setRootBuildDir:",
"setSuccessSound:"
);
Super = NSObject;
};
PCBuildPrefs = {
Actions = (
"setPromptOnClean:",
"setFailureSound:",
"setRootBuildDir:",
"setSuccessSound:",
"setBuildTool:"
);
Outlets = (
buildingView,
failureField,
promptOnClean,
rootBuildDirField,
setRootBuildDirButton,
setFailureButton,
setSuccessButton,
successField,
buildToolField,
setBuildToolButton
);
Super = NSObject;
};
}

View file

@ -0,0 +1,6 @@
{
Type = "Preferences";
Name = "Build";
Description = "Preferences for Project Build.";
PrincipalClassName = "PCBuildPrefs";
}

View file

@ -22,6 +22,7 @@
#import <ProjectCenter/PCDefines.h>
#import <ProjectCenter/PCLogController.h>
#import <ProjectCenter/PCBundleManager.h>
#import "PCPrefController.h"
#import <Protocols/Preferences.h>
@ -58,8 +59,14 @@ static PCPrefController *_prefCtrllr = nil;
}
// The prefs from the defaults
prefs = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
preferencesDict = [[NSMutableDictionary alloc] initWithDictionary:prefs];
userDefaults = [NSUserDefaults standardUserDefaults];
RETAIN(userDefaults);
preferencesDict = [[NSMutableDictionary alloc]
initWithDictionary:[userDefaults dictionaryRepresentation]];
[userDefaults setPersistentDomain:preferencesDict forName:@"ProjectCenter"];
if ([preferencesDict objectForKey:@"Version"] == nil)
{
@ -79,7 +86,6 @@ static PCPrefController *_prefCtrllr = nil;
RELEASE(panel);
RELEASE(buildingView);
RELEASE(savingView);
RELEASE(keyBindingsView);
RELEASE(miscView);
@ -100,12 +106,6 @@ static PCPrefController *_prefCtrllr = nil;
[preferencesDict setObject:@"0.4" forKey:@"Version"];
// Building
[preferencesDict setObject:@"" forKey:SuccessSound];
[preferencesDict setObject:@"" forKey:FailureSound];
[preferencesDict setObject:@"YES" forKey:PromptOnClean];
[preferencesDict setObject:@"" forKey:RootBuildDirectory];
// Saving
[preferencesDict setObject:@"YES" forKey:SaveOnQuit];
[preferencesDict setObject:@"YES" forKey:KeepBackup];
@ -118,7 +118,6 @@ static PCPrefController *_prefCtrllr = nil;
[preferencesDict setObject:@"YES" forKey:PromptOnQuit];
[preferencesDict setObject:@"YES" forKey:DeleteCacheWhenQuitting];
[preferencesDict setObject:@"YES" forKey:FullPathInFilePanels];
[preferencesDict setObject:@"/usr/bin/make" forKey:BuildTool];
[preferencesDict setObject:@"/usr/bin/gdb" forKey:Debugger];
[preferencesDict setObject:@"ProjectCenter" forKey:Editor];
@ -140,28 +139,11 @@ static PCPrefController *_prefCtrllr = nil;
- (void)loadPreferences
{
NSDictionary *prefs;
NSString *val;
NSString *defValue = @"";
prefs = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
[preferencesDict addEntriesFromDictionary: prefs];
// Fill in the defaults
// Building
[successField setStringValue:
(val = [preferencesDict objectForKey:SuccessSound]) ? val : defValue];
[failureField setStringValue:
(val = [preferencesDict objectForKey:FailureSound]) ? val : defValue];
[promptOnClean setState:
([[preferencesDict objectForKey:PromptOnClean]
isEqualToString: @"YES"]) ? NSOnState : NSOffState];
[rootBuildDirField setStringValue:
(val = [preferencesDict objectForKey:RootBuildDirectory]) ? val : defValue];
// Saving
[saveOnQuit setState:
([[preferencesDict objectForKey: SaveOnQuit]
@ -207,8 +189,6 @@ static PCPrefController *_prefCtrllr = nil;
([[preferencesDict objectForKey: FullPathInFilePanels]
isEqualToString:@"YES"]) ? NSOnState : NSOffState];
[buildToolField setStringValue:
(val = [preferencesDict objectForKey:BuildTool]) ? val : PCDefaultBuildTool];
[debuggerField setStringValue:
(val = [preferencesDict objectForKey: Debugger]) ? val : PCDefaultDebugger];
[editorField setStringValue:
@ -251,8 +231,6 @@ static PCPrefController *_prefCtrllr = nil;
NSArray *tabMatrixCells;
unsigned i;
[promptOnClean setRefusesFirstResponder:YES];
[saveOnQuit setRefusesFirstResponder:YES];
[keepBackup setRefusesFirstResponder:YES];
@ -279,12 +257,22 @@ static PCPrefController *_prefCtrllr = nil;
// Accessory
- (NSDictionary *)preferencesDict
{
return preferencesDict;
return [userDefaults dictionaryRepresentation];
}
- (id)objectForKey:(NSString *)key
{
return [preferencesDict objectForKey:key];
return [userDefaults objectForKey:key];
}
- (void)setObject:(id)anObject forKey:(NSString *)aKey
{
[userDefaults setObject:anObject forKey:aKey];
[userDefaults synchronize];
[[NSNotificationCenter defaultCenter]
postNotificationName:PCPreferencesDidChangeNotification
object:self];
}
- (NSString *)selectFileWithTypes:(NSArray *)types
@ -314,6 +302,32 @@ static PCPrefController *_prefCtrllr = nil;
return file;
}
- (void)loadPrefsSections
{
PCBundleManager *bundleManager = [[PCBundleManager alloc] init];
NSDictionary *bundlesInfo;
NSEnumerator *enumerator;
NSString *bundlePath;
NSString *sectionName;
id<PCPrefsSection> section;
sectionsDict = [[NSMutableDictionary alloc] init];
bundlesInfo = [bundleManager infoForBundlesType:@"preferences"];
enumerator = [[bundlesInfo allKeys] objectEnumerator];
while ((bundlePath = [enumerator nextObject]))
{
sectionName = [[bundlesInfo objectForKey:bundlePath]
objectForKey:@"Name"];
section = [bundleManager
objectForBundleWithName:sectionName
type:@"preferences"
protocol:@protocol(PCPrefsSection)];
[section setPrefController:self];
[sectionsDict setObject:section forKey:sectionName];
}
}
- (void)showPanel:(id)sender
{
if (panel == nil
@ -328,135 +342,29 @@ static PCPrefController *_prefCtrllr = nil;
{
[panel center];
}
RETAIN(buildingView);
RETAIN(savingView);
RETAIN(keyBindingsView);
RETAIN(miscView);
RETAIN(interfaceView);
[self loadPrefsSections];
// The popup and selected view
[popupButton removeAllItems];
[popupButton addItemWithTitle:@"Building"];
[popupButton addItemWithTitle:@"Saving"];
[popupButton addItemWithTitle:@"Key Bindings"];
[popupButton addItemWithTitle:@"Miscellaneous"];
[popupButton addItemWithTitle:@"Interface"];
[popupButton selectItemWithTitle:@"Building"];
[popupButton addItemsWithTitles:[sectionsDict allKeys]];
[popupButton selectItemAtIndex:0];
[self popupChanged:popupButton];
// Load saved prefs
[self loadPreferences];
[panel makeKeyAndOrderFront:self];
}
//
- (void)popupChanged:(id)sender
{
NSView *view = nil;
id<PCPrefsSection> section;
NSView *view;
switch ([sender indexOfSelectedItem])
{
case 0:
view = buildingView;
break;
case 1:
view = savingView;
break;
case 2:
view = keyBindingsView;
break;
case 3:
view = miscView;
break;
case 4:
view = interfaceView;
break;
}
section = [sectionsDict objectForKey:[sender titleOfSelectedItem]];
view = [section view];
[sectionsView setContentView:view];
[sectionsView display];
}
// Building
- (void)setSuccessSound:(id)sender
{
NSArray *types = [NSArray arrayWithObjects:@"snd",@"au",@"wav",nil];
NSString *path = [self selectFileWithTypes:types];
if (path)
{
[successField setStringValue: path];
[[NSUserDefaults standardUserDefaults] setObject:path
forKey:SuccessSound];
[preferencesDict setObject:path forKey:SuccessSound];
}
}
- (void)setFailureSound:(id)sender
{
NSArray *types = [NSArray arrayWithObjects:@"snd",@"au",@"wav",nil];
NSString *path = [self selectFileWithTypes:types];
if (path)
{
[failureField setStringValue:path];
[[NSUserDefaults standardUserDefaults] setObject:path
forKey:FailureSound];
[preferencesDict setObject:path forKey:FailureSound];
}
}
- (void)setRootBuildDir:(id)sender
{
NSString *path;
if (sender == rootBuildDirButton)
{
path = [self selectFileWithTypes:nil];
[rootBuildDirField setStringValue:path];
}
else
{
path = [rootBuildDirField stringValue];
}
if (path)
{
[[NSUserDefaults standardUserDefaults] setObject:path
forKey:RootBuildDirectory];
[preferencesDict setObject:path
forKey:RootBuildDirectory];
}
}
- (void)setPromptOnClean:(id)sender
{
NSUserDefaults *def = nil;
if (promptOnClean == nil)
{// HACK!!! need to be fixed in GNUstep
promptOnClean = sender;
return;
}
def = [NSUserDefaults standardUserDefaults];
switch ([sender state])
{
case NSOffState:
[def setObject:@"NO" forKey:PromptOnClean];
break;
case NSOnState:
[def setObject:@"YES" forKey:PromptOnClean];
break;
}
[def synchronize];
[preferencesDict setObject:[def objectForKey:PromptOnClean]
forKey:PromptOnClean];
// [sectionsView display];
}
// Saving
@ -663,38 +571,6 @@ static PCPrefController *_prefCtrllr = nil;
forKey:FullPathInFilePanels];
}
- (void)setBuildTool:(id)sender
{
NSString *path;
if (sender == buildToolButton)
{
path = [self selectFileWithTypes:nil];
[buildToolField setStringValue:path];
}
else
{
path = [buildToolField stringValue];
}
if ([path isEqualToString:@""] || !path)
{
[buildToolField setStringValue:PCDefaultBuildTool];
path = [buildToolField stringValue];
}
else if (!path || ![[NSFileManager defaultManager] fileExistsAtPath:path])
{
[buildToolField selectText:self];
NSRunAlertPanel(@"Build Tool not found!",
@"File %@ doesn't exist!",
@"OK", nil, nil, path);
}
[[NSUserDefaults standardUserDefaults] setObject:path forKey:BuildTool];
[preferencesDict setObject:path forKey:BuildTool];
}
- (void)setDebugger:(id)sender
{
NSString *path;