mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-03-19 09:02:02 +00:00
Automatic, periodic saving of all open projectfiles is now supported.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@11914 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0a98952de1
commit
738cd02b95
4 changed files with 112 additions and 40 deletions
|
@ -43,16 +43,12 @@
|
|||
|
||||
NSString *rootBuildPath;
|
||||
|
||||
NSTimer *saveTimer;
|
||||
|
||||
@private
|
||||
BOOL _needsReleasing;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Class files
|
||||
// ===========================================================================
|
||||
|
||||
+ (void)initialize;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Intialization & deallocation
|
||||
// ===========================================================================
|
||||
|
@ -67,24 +63,33 @@
|
|||
- (id)delegate;
|
||||
- (void)setDelegate:(id)aDelegate;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Timer handling
|
||||
// ===========================================================================
|
||||
|
||||
- (void)resetSaveTimer:(NSNotification *)notif;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Project management
|
||||
// ===========================================================================
|
||||
|
||||
- (NSMutableDictionary *)loadedProjects;
|
||||
// Returns all currently loaded projects. They are stored with their absolut paths as the keys.
|
||||
// Returns all currently loaded projects. They are stored with their absolut paths as the keys.
|
||||
|
||||
- (PCProject *)activeProject;
|
||||
// Returns the currently active project
|
||||
// Returns the currently active project
|
||||
|
||||
- (void)setActiveProject:(PCProject *)aProject;
|
||||
// Sets the new currently active project
|
||||
// Sets the new currently active project
|
||||
|
||||
- (void)saveAllProjectsIfNeeded;
|
||||
// Calls saveAllProjects if the preferences are setup accordingly.
|
||||
|
||||
- (void)saveAllProjects;
|
||||
// Saves all projects if needed.
|
||||
// Saves all projects if needed.
|
||||
|
||||
- (NSString *)rootBuildPath;
|
||||
// Gets set while initialising!
|
||||
// Gets set while initialising!
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Project actions
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#import <AppKit/IMLoading.h>
|
||||
#endif
|
||||
|
||||
#define SavePeriodDCN @"SavePeriodDidChangeNotification"
|
||||
|
||||
NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
||||
|
||||
@interface PCProjectManager (CreateUI)
|
||||
|
@ -89,14 +91,6 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
|||
|
||||
@implementation PCProjectManager
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Class methods
|
||||
// ===========================================================================
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Intialization & deallocation
|
||||
// ===========================================================================
|
||||
|
@ -104,12 +98,31 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
|||
- (id)init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
SEL sall = @selector(saveAllProjectsIfNeeded);
|
||||
SEL spdc = @selector(resetSaveTimer:);
|
||||
NSTimeInterval interval = [[defs objectForKey:AutoSavePeriod] intValue];
|
||||
|
||||
loadedProjects = [[NSMutableDictionary alloc] init];
|
||||
|
||||
rootBuildPath = [[[NSUserDefaults standardUserDefaults] stringForKey:RootBuildDirectory] copy];
|
||||
if (!rootBuildPath || rootBuildPath == @"") {
|
||||
rootBuildPath = [[defs stringForKey:RootBuildDirectory] copy];
|
||||
if (!rootBuildPath || [rootBuildPath isEqualToString:@""]) {
|
||||
rootBuildPath = [NSTemporaryDirectory() copy];
|
||||
}
|
||||
|
||||
if( [[defs objectForKey:AutoSave] isEqualToString:@"YES"] ) {
|
||||
saveTimer = [NSTimer scheduledTimerWithTimeInterval:interval
|
||||
target:self
|
||||
selector:sall
|
||||
userInfo:nil
|
||||
repeats:YES];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:spdc
|
||||
name:SavePeriodDCN
|
||||
object:nil];
|
||||
|
||||
_needsReleasing = NO;
|
||||
}
|
||||
return self;
|
||||
|
@ -117,16 +130,24 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
[rootBuildPath release];
|
||||
[loadedProjects release];
|
||||
[rootBuildPath release];
|
||||
[loadedProjects release];
|
||||
|
||||
if( [saveTimer isValid] )
|
||||
{
|
||||
[saveTimer invalidate];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
if (_needsReleasing) {
|
||||
[inspector release];
|
||||
[inspectorView release];
|
||||
[inspectorPopup release];
|
||||
}
|
||||
if (_needsReleasing)
|
||||
{
|
||||
[inspector release];
|
||||
[inspectorView release];
|
||||
[inspectorPopup release];
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
@ -143,6 +164,27 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
|||
delegate = aDelegate;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Timer handling
|
||||
// ===========================================================================
|
||||
|
||||
- (void)resetSaveTimer:(NSNotification *)notif
|
||||
{
|
||||
NSTimeInterval interval = [[notif object] intValue];
|
||||
SEL sall = @selector(saveAllProjectsIfNeeded);
|
||||
|
||||
if( [saveTimer isValid] )
|
||||
{
|
||||
[saveTimer invalidate];
|
||||
}
|
||||
|
||||
saveTimer = [NSTimer scheduledTimerWithTimeInterval:interval
|
||||
target:self
|
||||
selector:sall
|
||||
userInfo:nil
|
||||
repeats:YES];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Project management
|
||||
// ===========================================================================
|
||||
|
@ -159,20 +201,38 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
|
|||
|
||||
- (void)setActiveProject:(PCProject *)aProject
|
||||
{
|
||||
if (aProject != activeProject) {
|
||||
activeProject = aProject;
|
||||
if (aProject != activeProject) {
|
||||
activeProject = aProject;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:ActiveProjectDidChangeNotification object:activeProject];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:ActiveProjectDidChangeNotification object:activeProject];
|
||||
|
||||
//~ Is this needed?
|
||||
if (activeProject) {
|
||||
[[activeProject projectWindow] makeKeyAndOrderFront:self];
|
||||
}
|
||||
//~ Is this needed?
|
||||
if (activeProject) {
|
||||
[[activeProject projectWindow] makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
if ([inspector isVisible]) {
|
||||
[self inspectorPopupDidChange:inspectorPopup];
|
||||
if ([inspector isVisible]) {
|
||||
[self inspectorPopupDidChange:inspectorPopup];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)saveAllProjectsIfNeeded
|
||||
{
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
if( [[defs objectForKey:AutoSave] isEqualToString:@"YES"] ) {
|
||||
NSRunAlertPanel(@"Save All",
|
||||
@"Going to save all projects!",
|
||||
@"OK",nil,nil);
|
||||
|
||||
[self saveAllProjects];
|
||||
}
|
||||
else {
|
||||
if( [saveTimer isValid] ) {
|
||||
[saveTimer invalidate];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)saveAllProjects
|
||||
|
|
|
@ -84,3 +84,6 @@
|
|||
- (NSString *)selectFileWithTypes:(NSArray *)types;
|
||||
|
||||
@end
|
||||
|
||||
extern NSString *SavePeriodDidChangeNotification;
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#import <AppKit/IMLoading.h>
|
||||
#endif
|
||||
|
||||
NSString *SavePeriodDidChangeNotification = @"SavePeriodDidChangeNotification";
|
||||
|
||||
@interface PCPrefController (CreateUI)
|
||||
|
||||
- (void)_initUI;
|
||||
|
@ -528,12 +530,14 @@
|
|||
NSString *periodString = [autoSaveField stringValue];
|
||||
|
||||
if (periodString == nil || [periodString isEqualToString:@""]) {
|
||||
periodString = [NSString stringWithString:@"120"];
|
||||
periodString = [NSString stringWithString:@"300"];
|
||||
}
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setObject:periodString
|
||||
forKey:AutoSavePeriod];
|
||||
[preferencesDict setObject:periodString forKey:AutoSavePeriod];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SavePeriodDidChangeNotification object:periodString];
|
||||
}
|
||||
|
||||
- (void)setSaveOnQuit:(id)sender
|
||||
|
|
Loading…
Reference in a new issue