1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
//
// MGRTObjectEditor.mm
// MySQL GRT
//
// Created by Alfredo Kojima on 05/9/11.
// Copyright 2005 MySQL AB. All rights reserved.
//
#import "MGRTObjectEditor.h"
#import <MySQLToolsCommon/mxUtils.h>
@implementation MGRTObjectEditor
- (BOOL)commit // override
{
return NO;
}
- (void)revert // override
{
}
- (void)showObject // override
{
}
- (MYX_GRT_VALUE*)editedObject // override
{
return NULL;
}
- (const char*)objectId
{
return myx_grt_dict_id_item_as_string([self editedObject]);
}
- (IBAction)applyChanges:(id)sender
{
if ([self commit])
{
if ([_delegate respondsToSelector:@selector(objectEditorSaved:)])
[_delegate objectEditorSaved:self];
}
}
- (IBAction)close:(id)sender
{
[self revert];
[self close];
if ([_delegate respondsToSelector:@selector(objectEditorClosed:)])
[_delegate objectEditorClosed:self];
}
- (IBAction)discardChanges:(id)sender
{
[self revert];
[self showObject];
}
- (id)initWithWindowNibName:(NSString*)name
{
self= [super initWithWindowNibName:name];
if (self)
{
[self loadWindow];
[[self window] setDelegate:self];
}
return self;
}
- (void)setMGRT:(MGRT*)grt catalogs:(MGRTValue)catalogs
{
_grt= [grt retain];
_catalogs= new MGRTValue(catalogs);
}
- (void)setDelegate:(id)delegate
{
_delegate= delegate;
}
- (void)dealloc
{
delete _catalogs;
[_grt release];
[super dealloc];
}
- (NSString*)editedObjectName
{
return [NSString stringWithUTF8String:MGRTValue([self editedObject])["name"].asString()];
}
- (void)fillCollationPopUp:(NSPopUpButton*)popup
{
[popup removeAllItems];
[popup addItemWithTitle:@""];
[[popup menu] addItem:[NSMenuItem separatorItem]];
//XXX add most recently used items
//[[popup menu] addItem:[NSMenuItem separatorItem]];
if (_catalogs && _catalogs->isValid())
{
MGRTValue charsets((*_catalogs)["characterSets"]);
if (charsets.isValid())
{
int i, c= charsets.count();
for (i= 0; i < c; i++)
{
MGRTValue chs(MGRTValue::refObject([_grt grt], charsets[i].asString()));
MGRTValue colls(chs["collations"]);
for (int j= 0; j < colls.count(); j++)
{
[popup addItemWithTitle:NSStr(colls[j].asString())];
}
}
}
}
}
- (void)fillCharsetPopUp:(NSPopUpButton*)popup
{
[popup removeAllItems];
[popup addItemWithTitle:@""];
[[popup menu] addItem:[NSMenuItem separatorItem]];
if (_catalogs && _catalogs->isValid())
{
MGRTValue charsets((*_catalogs)["characterSets"]);
if (charsets.isValid())
{
int i, c= charsets.count();
for (i= 0; i < c; i++)
{
MGRTValue chs(MGRTValue::refObject([_grt grt], charsets[i].asString()));
[popup addItemWithTitle:NSStr(chs["name"].asString())];
[[popup lastItem] setRepresentedObject:NSStr(chs["name"].asString())];
}
}
}
}
- (void)fillCollationPopUp:(NSPopUpButton*)popup forCharset:(NSString*)charset
{
[popup removeAllItems];
if (_catalogs && _catalogs->isValid() && charset)
{
MGRTValue charsets((*_catalogs)["characterSets"]);
if (charsets.isValid())
{
int i, c= charsets.count();
for (i= 0; i < c; i++)
{
MGRTValue chs(MGRTValue::refObject([_grt grt], charsets[i].asString()));
const char *defaultCollation= chs["defaultCollation"].asString();
if (strcmp(chs["name"].asString(), [charset UTF8String])==0)
{
MGRTValue colls(chs["collations"]);
for (int j= 0; j < colls.count(); j++)
{
[popup addItemWithTitle:NSStr(colls[j].asString())];
if (strcmp(defaultCollation, colls[j].asString())==0)
[popup selectItem:[popup lastItem]];
}
break;
}
}
}
}
}
- (void)setReleaseOnClose:(BOOL)flag
{
_releaseOnClose= flag;
}
- (void)windowWillClose:(NSNotification*)notification
{
if (_releaseOnClose)
[self autorelease];
}
@end
|