Files
macSVG-mirror/macSVG/SVGDocument Classes/AttributeEditorController.m
dsward2 3c1480d679 Implemented a modal application Preferences window in MacSVGAppDelegate. Initially, it contains controls to enable and disable the built-in HTTP server, and to specify a port number for the HTTP server.
The registered default setting for the HTTP server is not enabled, and the default port number is 8080.

Also, harmonized the unitForAttribute: method in some classes.
2016-12-24 18:33:52 -06:00

155 lines
5.1 KiB
Objective-C

//
// AttributeEditorController.m
// macSVG
//
// Created by Douglas Ward on 1/1/12.
// Copyright © 2016 ArkPhone LLC. All rights reserved.
//
#import "AttributeEditorController.h"
#import "EditorUIFrameController.h"
#import "XMLAttributesTableController.h"
#import "XMLAttributesTableView.h"
#import "MacSVGDocumentWindowController.h"
#import "MacSVGDocument.h"
@implementation AttributeEditorController
//==================================================================================
// dealloc
//==================================================================================
- (void)dealloc
{
}
//==================================================================================
// reloadData
//==================================================================================
-(void)reloadData
{
[attributeEditorTextView setRichText:NO];
[attributeEditorTextView setContinuousSpellCheckingEnabled:NO];
[attributeEditorTextView setGrammarCheckingEnabled:NO];
[attributeEditorTextView setUsesFindPanel:YES];
XMLAttributesTableController * xmlAttributesTableController =
editorUIFrameController.macSVGDocumentWindowController.xmlAttributesTableController;
XMLAttributesTableView * xmlAttributesTableView = xmlAttributesTableController.xmlAttributesTableView;
[xmlAttributesTableView abortEditing];
NSInteger selectedRow = xmlAttributesTableView.selectedRow;
if (selectedRow != -1)
{
NSArray * xmlAttributesArray = xmlAttributesTableController.xmlAttributesArray;
NSMutableDictionary * attributeDictionary = xmlAttributesArray[selectedRow];
NSString * attributeName = attributeDictionary[@"name"];
NSString * attributeValue = attributeDictionary[@"value"];
#pragma unused(attributeName)
NSString * attributeKind = attributeDictionary[@"kind"];
#pragma unused(attributeKind)
attributeEditorTextView.string = attributeValue;
}
else
{
attributeEditorTextView.string = @"";
}
}
//==================================================================================
// setEnabled
//==================================================================================
-(void)setEnabled:(BOOL)enabled
{
if (enabled == YES)
{
if (attributeEditorView.superview == NULL)
{
NSView * attributeEditorFrameView = editorUIFrameController.editorPanelFrameView;
NSRect frameRect = attributeEditorFrameView.frame;
attributeEditorView.frame = frameRect;
attributeEditorView.bounds = frameRect;
[attributeEditorFrameView addSubview:attributeEditorView];
[self reloadData];
}
}
else
{
[attributeEditorView removeFromSuperview];
}
}
//==================================================================================
// saveChangesButtonAction
//==================================================================================
- (IBAction)saveChangesButtonAction:(id)sender
{
MacSVGDocumentWindowController * macSVGDocumentWindowController =
editorUIFrameController.macSVGDocumentWindowController;
if (macSVGDocumentWindowController != NULL)
{
XMLAttributesTableController * xmlAttributesTableController =
macSVGDocumentWindowController.xmlAttributesTableController;
if (xmlAttributesTableController != NULL)
{
XMLAttributesTableView * xmlAttributesTableView = xmlAttributesTableController.xmlAttributesTableView;
NSInteger selectedRow = xmlAttributesTableView.selectedRow;
if (selectedRow != -1)
{
NSArray * xmlAttributesArray = xmlAttributesTableController.xmlAttributesArray;
NSMutableDictionary * attributeDictionary = xmlAttributesArray[selectedRow];
NSString * attributeName = attributeDictionary[@"name"];
NSString * attributeValue = attributeDictionary[@"value"];
#pragma unused(attributeValue)
NSString * attributeKind = attributeDictionary[@"kind"];
#pragma unused(attributeKind)
NSXMLElement * xmlElementForAttributes =
[xmlAttributesTableController xmlElementForAttributesTable];
if (xmlElementForAttributes != NULL)
{
NSString * newAttributeValue = attributeEditorTextView.string;
NSXMLNode * attributeNode = [xmlElementForAttributes attributeForName:attributeName];
attributeNode.stringValue = newAttributeValue;
[macSVGDocumentWindowController reloadAllViews];
}
}
}
}
}
//==================================================================================
// revertButtonAction
//==================================================================================
- (IBAction)revertButtonAction:(id)sender
{
[self reloadData];
}
@end