File: MQSyntaxHelp.m

package info (click to toggle)
mysql-gui-tools 5.0r14%2BopenSUSE-2.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 116,956 kB
  • ctags: 48,715
  • sloc: sql: 341,918; pascal: 276,698; ansic: 91,020; cpp: 90,451; objc: 33,236; sh: 29,481; yacc: 10,756; xml: 10,589; java: 10,079; php: 2,806; python: 2,092; makefile: 1,783; perl: 4
file content (184 lines) | stat: -rw-r--r-- 4,891 bytes parent folder | download | duplicates (2)
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
//
//  MQSyntaxHelp.m
//  MySQL QueryBrowser
//
//  Created by Alfredo Kojima on 05/6/11.
//  Copyright 2005 MySQL AB. All rights reserved.
//

#import "MQSyntaxHelp.h"
#include <myx_public_interface.h>
#include <myx_qb_public_interface.h>

#import <MySQLToolsCommon/MPtrNode.h>

@implementation MQSyntaxHelp

- (void) fillArray: (NSMutableArray *)arr forGroup: (MYX_SQL_FUNCTIONGROUP *)parent_group
{
  unsigned f;

  [arr addObject:[NSString stringWithUTF8String: parent_group->caption]];

  for (f= 0; f < parent_group->functions_num; f++)
  {
    MYX_SQL_FUNCTION *func= parent_group->functions+f;
    MPtrNode *node= [[MPtrNode alloc] init];
    [node setCaption: [NSString stringWithUTF8String: func->caption]];
    [node setPointer: g_strdup(func->id) destroyer: (MPtrFree)g_free];
    [arr addObject: node];
    [node release];
  }

  for(f= 0; f < parent_group->subgroups_num; f++)
  {
    struct MYX_SQL_FUNCTIONGROUP *subgroup= parent_group->subgroups+f;
    NSMutableArray *subarray= [[NSMutableArray alloc] init];
    MPtrNode *node= [[MPtrNode alloc] init];
    [arr addObject:node];
    [node release];
    [self fillArray: subarray forGroup: subgroup];
    [node setSubnodes: subarray];
  }
}

- (void)loadFile:(NSString*)file
{
  NSString *path= [[NSBundle mainBundle] pathForResource:file
                                                  ofType:@"xml"];
  MYX_LIB_ERROR error;
  MYX_SQL_FUNCTIONINDEX *index;
  unsigned int g;

  
  // _index
  //    [ [group_caption func_node(name,id) func_node(name,id) ...],
  //      ...]

  index= myx_load_sql_function_list([path fileSystemRepresentation], &error);
  if (index)
  {
    _index= [[NSMutableArray alloc] initWithCapacity:index->groups_num];
    for (g= 0; g < index->groups_num; g++)
    {
      MYX_SQL_FUNCTIONGROUP *group= index->groups+g;
      NSMutableArray *groupArray= [NSMutableArray arrayWithCapacity:group->functions_num+1];
      
      //[groupArray addObject:[NSString stringWithUTF8String:group->caption]];
      [self fillArray: groupArray forGroup: group];

/*      
      for (f= 0; f < group->functions_num; f++)
      {
        MYX_SQL_FUNCTION *func= group->functions+f;
        MPtrNode *node= [[MPtrNode alloc] init];
        [node setCaption:[NSString stringWithUTF8String:func->caption]];
        [node setPointer:g_strdup(func->id) destroyer:(MPtrFree)g_free];
        [groupArray addObject:node];
        [node release];
      }

      if (f= 0; f < group->subgroups_num; f++)
      {
        MYX_SQL_FUNCTIONGROUP *subgroup= group->subgroups[f];
      }
*/      
      [_index addObject:groupArray];
    }
    myx_free_sql_function_list(index);
  }
}

- (void)setGroupIcon:(NSImage*)groupIcon
            itemIcon:(NSImage*)icon
{
  _groupIcon= [groupIcon retain];
  _icon= [icon retain];
}

- (void)dealloc
{
  [_groupIcon release];
  [_icon release];
  [_index release];
  [super dealloc];
}

- (const char*)topicIdForItem:(id)item
{
  if (![item isKindOfClass:[NSArray class]])
    return [item pointer];
  else
    return NULL;
}

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
  if ([item isKindOfClass:[NSArray class]])
  {
    return [item objectAtIndex:0];
  }
  else if([item isKindOfClass:[MPtrNode class]])
  {
    if([(MPtrNode *)item subnodeCount] > 0)
      return [[(MPtrNode *)item subnodes] objectAtIndex:0];
    else
      return [item caption];
  }
  else 
  {
    return @"";
  }
}


- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
{
  if (!item)
    return [_index objectAtIndex:index];
  else if ([item isKindOfClass:[NSArray class]])
    return [item objectAtIndex:index+1];
   else if(([item isKindOfClass:[MPtrNode class]]) && ([(MPtrNode *)item subnodeCount] > 0))
    return [[(MPtrNode *)item subnodes] objectAtIndex: index+1];
  else
    return nil;
}


- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
  if (!item)
    return YES;
  else if ([item isKindOfClass:[NSArray class]])
    return YES;
  else if(([item isKindOfClass:[MPtrNode class]]) && ([(MPtrNode *)item subnodeCount] > 0))
    return YES;
  else
    return NO;
}


- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
  if (!item)
    return [_index count];
  else if ([item isKindOfClass:[NSArray class]])
    return [item count]-1;
  else if([item isKindOfClass:[MPtrNode class]])
    return [(MPtrNode *)item subnodeCount]-1;
  else
    return 0;
}


- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
  if ([item isKindOfClass:[NSArray class]])
    [cell setImage:_groupIcon];
  else if(([item isKindOfClass:[MPtrNode class]]) && ([(MPtrNode *)item subnodeCount] > 0))
    [cell setImage:_groupIcon];  
  else
    [cell setImage:_icon];
}

@end