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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
#import "MQueryBrowserController.h"
#import "MQueryBrowserDocument.h"
#import "MQueryBrowser.h"
#import "MQHistory.h"
#import "MQBookmark.h"
#import "MQPreferences.h"
#import <MySQLToolsCommon/MConnectionPanel.h>
#import <MySQLToolsCommon/MPreferences.h>
#import <MySQLToolsCommon/MPreferenceEditor.h>
#import <MySQLToolsCommon/MSyntaxColoring.h>
@interface MQueryBrowserController(Private)
- (void)connectionPanel:(MConnectionPanel*)panel finished:(MYSQL*)mysql info:(MConnectionInfo*)info;
- (void)connectionPanel:(MConnectionPanel*)panel aborted:(BOOL)error;
- (void)recentMenuActivate:(id)sender;
- (void)updateRecentMenu;
@end
@implementation MQueryBrowserController(Private)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self newConnection:nil];
}
- (void)connectionPanel:(MConnectionPanel*)panel finished:(MYSQL*)mysql info:(MConnectionInfo*)info
{
MQueryBrowserDocument *qb;
qb= [[MQueryBrowserDocument alloc] initWithConnection:mysql info:info];
if (qb)
{
[self addDocument:qb];
[qb makeWindowControllers];
// [self noteNewRecentConnection:info];
[qb release];
}
else
NSLog(@"Main window initialization failed!");
[panel autorelease];
}
- (void)connectionPanel:(MConnectionPanel*)panel aborted:(BOOL)error
{
[panel release];
}
#if 0
- (void)recentMenuActivate:(id)sender
{
[self openInstanceWithConnectionName:[sender representedObject]];
}
- (void)updateRecentMenu
{
/*
NSMenu *menu= [recentMenu submenu];
unsigned int i;
NSArray *array= [[NSUserDefaults standardUserDefaults] arrayForKey:@"RecentConnections"];
while ([menu numberOfItems] > 2)
[menu removeItemAtIndex:0];
for (i= 0; i < [array count]; i++)
{
id item= [menu addItemWithTitle:[array objectAtIndex:i]
action:@selector(recentMenuActivate:)
keyEquivalent:@""];
[item setRepresentedObject:[array objectAtIndex:i]];
}
*/
}
#endif
@end
//=======================================================================
@implementation MQueryBrowserController
- (void)setupDefaults
{
NSMutableDictionary *appDefaults= [NSMutableDictionary dictionaryWithCapacity:8];
[appDefaults setObject:[NSNumber numberWithInt:0] forKey:@"QueryHistoryLimit"];
[appDefaults setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:@"EditorBackgroundColor"];
[appDefaults setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"EditorForegroundColor"];
[appDefaults setObject:[NSArchiver archivedDataWithRootObject:[NSFont fontWithName:@"Monaco" size:12.0]] forKey:@"EditorFont"];
[appDefaults setObject:[NSArray array] forKey:@"RecentConnections"];
[appDefaults setObject:[MPreferences checkDirectory:@"QueryBrowser"] forKey: @"QBDirectory"];
[appDefaults setObject:[NSNumber numberWithInt:100] forKey:@"PartialTableListLimit"];
[appDefaults setObject:[NSNumber numberWithInt: 18] forKey:@"ResultsetRowHeight"];
[appDefaults addEntriesFromDictionary:[MSyntaxColoring defaultColorDictionary]];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
}
- (id)init
{
NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
[self setupDefaults];
self= [super init];
if (!self)
return nil;
_history= [[MQHistory alloc] init];
[_history loadFromFile: [NSString stringWithFormat:@"%@/history.xml",
[defaults valueForKey:@"QBDirectory"]]];
_bookmarks= [[MQBookmarkList alloc] init];
[_bookmarks loadFromFile:[NSString stringWithFormat:@"%@/bookmarks.xml",
[defaults valueForKey:@"QBDirectory"]]];
return self;
}
- (void)dealloc
{
[_history release];
[_prefPanel release];
[super dealloc];
}
- (IBAction)newConnection: (id)sender
{
MConnectionPanel *panel;
panel= [[MConnectionPanel alloc] initWithConnectionsFile:
[[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];
[panel setEditsSchema];
[panel setDelegate:self];
[panel show];
[panel setHeaderImage: [[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"connect_header_qb"
ofType:@"png"]] autorelease]];
}
- (void)openInstanceWithConnectionName: (NSString*)connectionName
{
MConnectionPanel *panel;
panel= [[MConnectionPanel alloc] initWithConnectionsFile:
[[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];
[panel setEditsSchema];
[panel setDelegate:self];
[panel showAndConnectTo:connectionName];
[panel setHeaderImage: [[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"connect_header_qb"
ofType:@"png"]] autorelease]];
}
- (void)noteNewRecentConnection: (MConnectionInfo*)info
{
NSString *name;
NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
NSMutableArray *array= [NSMutableArray arrayWithArray:[defaults objectForKey:@"RecentConnections"]];
name= [info description];
[array removeObject:name];
while ([array count] > 9)
{
[array removeLastObject];
}
[array insertObject:name atIndex:0];
[defaults setObject:array forKey:@"RecentConnections"];
[self updateRecentMenu];
}
- (IBAction)showAbout:(id)sender
{
[versionLabel setStringValue:[NSString stringWithFormat:@"Version %@",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
[aboutPanel makeKeyAndOrderFront:sender];
}
- (IBAction)showPreferences:(id)sender
{
if (!_prefPanel)
{
MQPreferences *prefs;
_prefPanel= [[MPreferenceEditor alloc] initForConnectionsFile:
[[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];
prefs= [_prefPanel registerMultiPageNib:@"Preferences" withLabels:[NSArray arrayWithObjects:@"Query Browser",@"SQL Editor",nil]];
[prefs setHistory:_history];
}
[_prefPanel show];
}
- (IBAction)clearRecentMenu:(id)sender
{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray array] forKey:@"RecentConnections"];
[self updateRecentMenu];
}
- (MQHistory*)history
{
return _history;
}
- (void)rememberQuery:(NSString*)query
catalog:(NSString*)catalog
schema:(NSString*)schema
{
[_history rememberQuery:query catalog:catalog schema:schema];
_historyNeedsSave= YES;
}
- (MQBookmarkList*)bookmarks
{
return _bookmarks;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
if (_historyNeedsSave)
{
_historyNeedsSave= NO;
[_history storeToFile:[NSString stringWithFormat:@"%@/history.xml",
[[NSUserDefaults standardUserDefaults] valueForKey:@"QBDirectory"]]];
}
[_bookmarks storeToFile:[NSString stringWithFormat:@"%@/bookmarks.xml",
[[NSUserDefaults standardUserDefaults] valueForKey:@"QBDirectory"]]];
}
- (int)numberOfItemsInMenu:(NSMenu *)menu
{
return [menu numberOfItems];
}
- (IBAction)enterpriseHome:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/"]];
}
- (IBAction)enterpriseSoftware:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/software/enterprise.php"]];
}
- (IBAction)enterpriseKB:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://kb.mysql.com/index.php"]];
}
- (IBAction)enterpriseUpdate:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/updates/index.php"]];
}
- (IBAction)enterpriseMonitoring:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/monitoring/"]];
}
- (IBAction)enterpriseSupport:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://support.mysql.com/main.php"]];
}
- (BOOL)menu:(NSMenu *)menu
updateItem:(NSMenuItem *)item
atIndex:(int)index
shouldCancel:(BOOL)shouldCancel
{
NSWindow *window= [NSApp keyWindow];
if (window)
{
MQueryBrowser *document= [self documentForWindow:window];
if (document)
return [document menu:menu
updateItem:item
atIndex:index
shouldCancel:NO];
}
if (windowsMenu != menu)
[item setEnabled:NO];
return YES;
}
@end
|