Revision: 27996
          http://sourceforge.net/p/bibdesk/svn/27996
Author:   hofman
Date:     2022-10-04 14:43:12 +0000 (Tue, 04 Oct 2022)
Log Message:
-----------
make sure decoded secure text field has the correct cell class

Modified Paths:
--------------
    trunk/bibdesk/BDSKSecureTextField.m

Modified: trunk/bibdesk/BDSKSecureTextField.m
===================================================================
--- trunk/bibdesk/BDSKSecureTextField.m 2022-10-04 09:43:54 UTC (rev 27995)
+++ trunk/bibdesk/BDSKSecureTextField.m 2022-10-04 14:43:12 UTC (rev 27996)
@@ -89,35 +89,57 @@
     return image;
 }
 
-- (void)commonInit {
-    if (button == nil) {
-        button = [[BDSKEmbeddedButton alloc] init];
-        [button setButtonType:NSToggleButton];
-        [button setBordered:NO];
-        [button setImagePosition:NSImageOnly];
-        [button setImageScaling:NSImageScaleProportionallyDown];
-        [button setImage:[[self class] showTextImage]];
-        [button setAlternateImage:[[self class] hideTextImage]];
-        [button setRefusesFirstResponder:YES];
-        [button setTarget:self];
-        [button setAction:@selector(toggleShowsText:)];
-        [button setToolTip:showsText ? NSLocalizedString(@"Hide password", 
@"Tool tip message") : NSLocalizedString(@"Show password", @"Tool tip 
message")];
-        [button setTranslatesAutoresizingMaskIntoConstraints:NO];
-        [button 
setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow 
forOrientation:NSLayoutConstraintOrientationHorizontal];
-        [button 
setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow 
forOrientation:NSLayoutConstraintOrientationVertical];
-        [button addConstraint:[NSLayoutConstraint constraintWithItem:button 
attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:button 
attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0]];
-        [self addSubview:button];
-        [self addConstraints:[NSArray arrayWithObjects:
-            [NSLayoutConstraint constraintWithTrailingMargin:2.0 
forItem:button toItem:self],
-            [NSLayoutConstraint constraintWithTopMargin:1.0 forItem:button 
toItem:self],
-            [NSLayoutConstraint constraintWithBottomMargin:1.0 forItem:button 
toItem:self], nil]];
-    }
+- (void)makeButton {
+    button = [[BDSKEmbeddedButton alloc] init];
+    [button setButtonType:NSToggleButton];
+    [button setBordered:NO];
+    [button setImagePosition:NSImageOnly];
+    [button setImageScaling:NSImageScaleProportionallyDown];
+    [button setImage:[[self class] showTextImage]];
+    [button setAlternateImage:[[self class] hideTextImage]];
+    [button setRefusesFirstResponder:YES];
+    [button setTarget:self];
+    [button setAction:@selector(toggleShowsText:)];
+    [button setToolTip:showsText ? NSLocalizedString(@"Hide password", @"Tool 
tip message") : NSLocalizedString(@"Show password", @"Tool tip message")];
+    [button setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [button setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow 
forOrientation:NSLayoutConstraintOrientationHorizontal];
+    [button setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow 
forOrientation:NSLayoutConstraintOrientationVertical];
+    [button addConstraint:[NSLayoutConstraint constraintWithItem:button 
attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:button 
attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0]];
+    [self addSubview:button];
+    [self addConstraints:[NSArray arrayWithObjects:
+        [NSLayoutConstraint constraintWithTrailingMargin:2.0 forItem:button 
toItem:self],
+        [NSLayoutConstraint constraintWithTopMargin:1.0 forItem:button 
toItem:self],
+        [NSLayoutConstraint constraintWithBottomMargin:1.0 forItem:button 
toItem:self], nil]];
 }
 
+- (Class)cellClass {
+    return showsText ? [BDSKUnsecureTextFieldCell class] : 
[BDSKSecureTextFieldCell  class];
+}
+
+- (NSTextFieldCell *)newCellOfClass:(Class)cellClass {
+    NSTextFieldCell *newCell = [[[cellClass alloc] alloc] initTextCell:@""];
+    NSTextFieldCell *oldCell = [self cell];
+    [newCell setFont:[oldCell font]];
+    [newCell setControlSize:[oldCell controlSize]];
+    [newCell setControlTint:[oldCell controlTint]];
+    [newCell setEnabled:[oldCell isEnabled]];
+    [newCell setAlignment:[oldCell alignment]];
+    [newCell setWraps:[oldCell wraps]];
+    [newCell setScrollable:[oldCell isScrollable]];
+    [newCell setSelectable:[oldCell isSelectable]];
+    [newCell setEditable:[oldCell isEditable]];
+    [newCell setDrawsBackground:[oldCell drawsBackground]];
+    [newCell setBordered:[oldCell isBordered]];
+    [newCell setBezeled:[oldCell isBezeled]];
+    if ([oldCell isBezeled])
+        [newCell setBezelStyle:[oldCell bezelStyle]];
+    return newCell;
+}
+
 - (id)initWithFrame:(NSRect)frameRect {
     self = [super initWithFrame:frameRect];
     if (self) {
-        [self commonInit];
+        [self makeButton];
     }
     return self;
 }
@@ -127,7 +149,12 @@
     if (self) {
         button = [[coder decodeObjectForKey:@"button"] retain];
         showsText = [coder decodeBoolForKey:@"showsText"];
-        [self commonInit];
+        
+        Class cellClass = [self cellClass];
+        if ([[self cell] isKindOfClass:cellClass] == NO)
+            [self setCell:[[self newCellOfClass:cellClass] autorelease]];
+        if (button == nil)
+            [self makeButton];
     }
     return self;
 }
@@ -158,23 +185,8 @@
     
     NSTextFieldCell *oldCell = [[self cell] retain];
     
-    if (alternateCell == nil) {
-        alternateCell = [(showsText ? [BDSKUnsecureTextFieldCell alloc] : 
[BDSKSecureTextFieldCell alloc]) initTextCell:@""];
-        [alternateCell setFont:[oldCell font]];
-        [alternateCell setControlSize:[oldCell controlSize]];
-        [alternateCell setControlTint:[oldCell controlTint]];
-        [alternateCell setEnabled:[oldCell isEnabled]];
-        [alternateCell setAlignment:[oldCell alignment]];
-        [alternateCell setWraps:[oldCell wraps]];
-        [alternateCell setScrollable:[oldCell isScrollable]];
-        [alternateCell setSelectable:[oldCell isSelectable]];
-        [alternateCell setEditable:[oldCell isEditable]];
-        [alternateCell setDrawsBackground:[oldCell drawsBackground]];
-        [alternateCell setBordered:[oldCell isBordered]];
-        [alternateCell setBezeled:[oldCell isBezeled]];
-        if ([oldCell isBezeled])
-            [alternateCell setBezelStyle:[oldCell bezelStyle]];
-    }
+    if (alternateCell == nil)
+        alternateCell = [self newCellOfClass:[self cellClass]];
     
     NSRange selectedRange = NSMakeRange(NSNotFound, 0);
     if ([self currentEditor]) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to