mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 14:00:54 +00:00
Allow setting of default theme for application.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@23693 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6c647b9cbf
commit
03a95d3ca9
2 changed files with 94 additions and 24 deletions
|
@ -3,6 +3,7 @@
|
||||||
* Source/GSTheme.m: Add rudimentary inspector.
|
* Source/GSTheme.m: Add rudimentary inspector.
|
||||||
Make themes in panel be in alphabetical order except for the
|
Make themes in panel be in alphabetical order except for the
|
||||||
default theme (always first in the list).
|
default theme (always first in the list).
|
||||||
|
Allow setting of default theme for application.
|
||||||
|
|
||||||
2006-09-30 Richard Frith-Macdonald <rfm@gnu.org>
|
2006-09-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
117
Source/GSTheme.m
117
Source/GSTheme.m
|
@ -34,6 +34,7 @@
|
||||||
#include "Foundation/NSUserDefaults.h"
|
#include "Foundation/NSUserDefaults.h"
|
||||||
#include "GNUstepGUI/GSTheme.h"
|
#include "GNUstepGUI/GSTheme.h"
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
|
#include "AppKit/NSButton.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
#include "AppKit/NSColorList.h"
|
#include "AppKit/NSColorList.h"
|
||||||
#include "AppKit/NSGraphics.h"
|
#include "AppKit/NSGraphics.h"
|
||||||
|
@ -90,6 +91,8 @@ typedef enum {
|
||||||
@interface GSThemePanel : NSPanel
|
@interface GSThemePanel : NSPanel
|
||||||
{
|
{
|
||||||
NSMatrix *matrix; // Not retained.
|
NSMatrix *matrix; // Not retained.
|
||||||
|
NSScrollView *sideView; // Not retained.
|
||||||
|
NSView *bottomView; // Not retained.
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the shared panel.
|
/** Return the shared panel.
|
||||||
|
@ -104,6 +107,10 @@ typedef enum {
|
||||||
*/
|
*/
|
||||||
- (void) notified: (NSNotification*)n;
|
- (void) notified: (NSNotification*)n;
|
||||||
|
|
||||||
|
/** Toggle whether the current theme is the default theme.
|
||||||
|
*/
|
||||||
|
- (void) setDefault: (id)sender;
|
||||||
|
|
||||||
/** Update list of available themes.
|
/** Update list of available themes.
|
||||||
*/
|
*/
|
||||||
- (void) update: (id)sender;
|
- (void) update: (id)sender;
|
||||||
|
@ -301,6 +308,7 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
panel = [GSThemePanel sharedThemePanel];
|
panel = [GSThemePanel sharedThemePanel];
|
||||||
[panel update: self];
|
[panel update: self];
|
||||||
|
[panel center];
|
||||||
[panel orderFront: self];
|
[panel orderFront: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1363,14 +1371,15 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
NSRect winFrame;
|
NSRect winFrame;
|
||||||
|
NSRect sideFrame;
|
||||||
|
NSRect bottomFrame;
|
||||||
NSRect frame;
|
NSRect frame;
|
||||||
NSScrollView *scrollView;
|
|
||||||
NSView *container;
|
NSView *container;
|
||||||
NSButtonCell *proto;
|
NSButtonCell *proto;
|
||||||
|
|
||||||
/* FIXME - should actually autosave the memory panel position and frame ! */
|
winFrame = NSMakeRect(0, 0, 367, 420);
|
||||||
winFrame.size = NSMakeSize(367,388);
|
sideFrame = NSMakeRect(0, 0, 95, 420);
|
||||||
winFrame.origin = NSMakePoint (100, 200);
|
bottomFrame = NSMakeRect(95, 0, 272, 32);
|
||||||
|
|
||||||
self = [super initWithContentRect: winFrame
|
self = [super initWithContentRect: winFrame
|
||||||
styleMask: (NSTitledWindowMask | NSClosableWindowMask
|
styleMask: (NSTitledWindowMask | NSClosableWindowMask
|
||||||
|
@ -1380,18 +1389,13 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
|
|
||||||
[self setReleasedWhenClosed: NO];
|
[self setReleasedWhenClosed: NO];
|
||||||
container = [self contentView];
|
container = [self contentView];
|
||||||
frame = [container frame];
|
sideView = [[NSScrollView alloc] initWithFrame: sideFrame];
|
||||||
frame.origin = NSZeroPoint;
|
[sideView setHasHorizontalScroller: NO];
|
||||||
frame.size.width = 95;
|
[sideView setHasVerticalScroller: YES];
|
||||||
scrollView = [[NSScrollView alloc] initWithFrame: frame];
|
[sideView setBorderType: NSBezelBorder];
|
||||||
[scrollView setHasHorizontalScroller: NO];
|
[sideView setAutoresizingMask: (NSViewHeightSizable | NSViewMaxXMargin)];
|
||||||
[scrollView setHasVerticalScroller: YES];
|
[container addSubview: sideView];
|
||||||
[scrollView setBorderType: NSBezelBorder];
|
RELEASE(sideView);
|
||||||
[scrollView setAutoresizingMask: (NSViewHeightSizable)];
|
|
||||||
[container addSubview: scrollView];
|
|
||||||
RELEASE(scrollView);
|
|
||||||
frame = [scrollView frame];
|
|
||||||
frame.origin = NSZeroPoint;
|
|
||||||
|
|
||||||
proto = [[NSButtonCell alloc] init];
|
proto = [[NSButtonCell alloc] init];
|
||||||
[proto setBordered: NO];
|
[proto setBordered: NO];
|
||||||
|
@ -1401,6 +1405,8 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
[proto setEditable: NO];
|
[proto setEditable: NO];
|
||||||
[matrix setPrototype: proto];
|
[matrix setPrototype: proto];
|
||||||
|
|
||||||
|
frame = [sideView frame];
|
||||||
|
frame.origin = NSZeroPoint;
|
||||||
matrix = [[NSMatrix alloc] initWithFrame: frame
|
matrix = [[NSMatrix alloc] initWithFrame: frame
|
||||||
mode: NSRadioModeMatrix
|
mode: NSRadioModeMatrix
|
||||||
prototype: proto
|
prototype: proto
|
||||||
|
@ -1415,10 +1421,15 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
[matrix setAction: @selector(changeSelection:)];
|
[matrix setAction: @selector(changeSelection:)];
|
||||||
[matrix setTarget: self];
|
[matrix setTarget: self];
|
||||||
|
|
||||||
[scrollView setDocumentView: matrix];
|
[sideView setDocumentView: matrix];
|
||||||
RELEASE(matrix);
|
RELEASE(matrix);
|
||||||
|
|
||||||
[self setTitle: @"Theme Panel"];
|
bottomView = [[NSView alloc] initWithFrame: bottomFrame];
|
||||||
|
[bottomView setAutoresizingMask: (NSViewWidthSizable | NSViewMaxYMargin)];
|
||||||
|
[container addSubview: bottomView];
|
||||||
|
RELEASE(bottomView);
|
||||||
|
|
||||||
|
[self setTitle: @"Themes"];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
addObserver: self
|
addObserver: self
|
||||||
|
@ -1459,8 +1470,9 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
if ([[n name] isEqualToString: GSThemeDidActivateNotification] == YES)
|
if ([[n name] isEqualToString: GSThemeDidActivateNotification] == YES)
|
||||||
{
|
{
|
||||||
NSView *iView;
|
NSView *iView;
|
||||||
NSView *sView;
|
|
||||||
NSRect frame;
|
NSRect frame;
|
||||||
|
NSButton *button;
|
||||||
|
NSString *dName;
|
||||||
|
|
||||||
/* Ask the inspector to ensure that it is up to date.
|
/* Ask the inspector to ensure that it is up to date.
|
||||||
*/
|
*/
|
||||||
|
@ -1474,13 +1486,38 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
RELEASE(iView);
|
RELEASE(iView);
|
||||||
|
|
||||||
/* Set inspector view to fill the frame to the right of our
|
/* Set inspector view to fill the frame to the right of our
|
||||||
* scrollview.
|
* scrollview and above the bottom view
|
||||||
*/
|
*/
|
||||||
sView = [[cView subviews] objectAtIndex: 0];
|
frame.origin.x = [sideView frame].size.width;
|
||||||
frame = [cView frame];
|
frame.origin.y = [bottomView frame].size.height;
|
||||||
frame.origin = NSMakePoint([sView frame].size.width, 0.0);
|
frame.size = [cView frame].size;
|
||||||
frame.size.width -= [sView frame].size.width;
|
frame.size.width -= [sideView frame].size.width;
|
||||||
|
frame.size.height -= [bottomView frame].size.height;
|
||||||
[iView setFrame: frame];
|
[iView setFrame: frame];
|
||||||
|
|
||||||
|
button = [[bottomView subviews] lastObject];
|
||||||
|
if (button == nil)
|
||||||
|
{
|
||||||
|
button = [NSButton new];
|
||||||
|
[button setTarget: self];
|
||||||
|
[button setAction: @selector(setDefault:)];
|
||||||
|
[bottomView addSubview: button];
|
||||||
|
RELEASE(button);
|
||||||
|
}
|
||||||
|
dName = [[NSUserDefaults standardUserDefaults] stringForKey: @"GSTheme"];
|
||||||
|
if ([[[n object] name] isEqual: dName] == YES)
|
||||||
|
{
|
||||||
|
[button setTitle: @"Revert default theme"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[button setTitle: @"Make this the default theme"];
|
||||||
|
}
|
||||||
|
[button sizeToFit];
|
||||||
|
frame = [button frame];
|
||||||
|
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
||||||
|
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
||||||
|
[button setFrame: frame];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1491,6 +1528,36 @@ static GSThemePanel *sharedPanel = nil;
|
||||||
[cView setNeedsDisplay: YES];
|
[cView setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setDefault: (id)sender
|
||||||
|
{
|
||||||
|
NSButton *button = (NSButton*)sender;
|
||||||
|
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||||
|
NSString *cName;
|
||||||
|
NSString *dName;
|
||||||
|
NSRect frame;
|
||||||
|
|
||||||
|
dName = [defs stringForKey: @"GSTheme"];
|
||||||
|
cName = [[GSTheme theme] name];
|
||||||
|
|
||||||
|
if ([cName isEqual: dName] == YES)
|
||||||
|
{
|
||||||
|
[defs removeObjectForKey: @"GSTheme"];
|
||||||
|
[button setTitle: @"Make this the default theme"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[defs setObject: cName forKey: @"GSTheme"];
|
||||||
|
[button setTitle: @"Revert default theme"];
|
||||||
|
}
|
||||||
|
[defs synchronize];
|
||||||
|
[button sizeToFit];
|
||||||
|
frame = [button frame];
|
||||||
|
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
||||||
|
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
||||||
|
[button setFrame: frame];
|
||||||
|
[bottomView setNeedsDisplay: YES];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) update: (id)sender
|
- (void) update: (id)sender
|
||||||
{
|
{
|
||||||
NSArray *array;
|
NSArray *array;
|
||||||
|
@ -1685,6 +1752,8 @@ static GSThemeInspector *sharedInspector = nil;
|
||||||
[view setFrame: frame];
|
[view setFrame: frame];
|
||||||
[content addSubview: view];
|
[content addSubview: view];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[content setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue