def handleContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu user_selection = None for s in selection: if s.type == 'db.Schema': user_selection = {'schema': to_unicode(s.name), 'table': None} break elif s.type == 'db.Table': user_selection = { 'table': to_unicode(s.name), 'schema': to_unicode(s.schemaName) } break else: return if user_selection: if user_selection['table']: item = mforms.newMenuItem("Table Data Export") item.add_clicked_callback( lambda sender=sender: showPowerExport(sender, user_selection)) menu.insert_item(3, item) item = mforms.newMenuItem("Table Data Import") item.add_clicked_callback( lambda sender=sender: showPowerImport(sender, user_selection)) menu.insert_item(4, item) menu.insert_item(5, mforms.newMenuItem("", mforms.SeparatorMenuItem))
def handleContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu user_selection = None for s in selection: if s.type == 'db.Schema': user_selection = {'schema': s.name, 'table': None} break elif s.type == 'db.Table': user_selection = {'table': s.name, 'schema': s.schemaName} break else: return if user_selection: if user_selection['table']: item = mforms.newMenuItem("Table Data Export") item.add_clicked_callback(lambda sender=sender : showPowerExport(sender, user_selection)) menu.insert_item(3, item) item = mforms.newMenuItem("Table Data Import") item.add_clicked_callback(lambda sender=sender : showPowerImport(sender, user_selection)) menu.insert_item(4, item) menu.insert_item(5, mforms.newMenuItem("", mforms.SeparatorMenuItem))
def menu_will_show(self, item): # item is the parent node which will be None when the # context menu has just being opened. # So when the call is done for a sub-menu, no reset is needed. if item is None: self.menu.remove_all() if item is None: parent_nodes = {} selection = grt.List() pobj = None for node in self.tree.get_selection(): name = node.get_string(self.name_column) obj = grt.classes.db_query_LiveDBObject() obj.name = name obj.schemaName = self.schema obj.type = self.klass if hasattr(self, 'parent_name_column'): if hasattr(self, 'table'): parent_name = self.table else: parent_name = node.get_string( self.parent_name_column) if parent_nodes.has_key(parent_name): obj.owner = parent_nodes[parent_name] else: pobj = grt.classes.db_query_LiveDBObject() obj.owner = pobj pobj.type = 'db.Table' pobj.name = parent_name pobj.schemaName = self.schema parent_nodes[parent_name] = pobj selection.append(obj) if not selection and self.node_name: obj = grt.classes.db_query_LiveDBObject() obj.schemaName = self.schema obj.type = self.node_name selection.append(obj) sobj = grt.classes.db_query_LiveDBObject() sobj.schemaName = self.schema sobj.name = self.schema sobj.type = "db.Schema" obj.owner = sobj separator = mforms.newMenuItem("", mforms.SeparatorMenuItem) separator.set_name("Bottom Plugins Separator") separator.setInternalName("bottom_plugins_separator") self.menu.add_item(separator) self.menu.add_item_with_title("Refresh", self.refresh, "Refresh", "refresh") args = grt.Dict() args["selection"] = selection args["menu"] = mforms.togrt(self.menu, "ContextMenu") args['schema_inspector'] = True NotificationCenter().send("GRNLiveDBObjectMenuWillShow", self.editor, args)
def menu_will_show(self, item): # item is the parent node which will be None when the # context menu has just being opened. # So when the call is done for a sub-menu, no reset is needed. if item is None: self.menu.remove_all() if item is None: parent_nodes = {} selection = grt.List() pobj = None for node in self.tree.get_selection(): name = node.get_string(self.name_column) obj = grt.classes.db_query_LiveDBObject() obj.name = name obj.schemaName = self.schema obj.type = self.klass if hasattr(self, 'parent_name_column'): if hasattr(self, 'table'): parent_name = self.table else: parent_name = node.get_string(self.parent_name_column) if parent_nodes.has_key(parent_name): obj.owner = parent_nodes[parent_name] else: pobj = grt.classes.db_query_LiveDBObject() obj.owner = pobj pobj.type = 'db.Table' pobj.name = parent_name pobj.schemaName = self.schema parent_nodes[parent_name]= pobj selection.append(obj) if not selection and self.node_name: obj = grt.classes.db_query_LiveDBObject() obj.schemaName = self.schema obj.type = self.node_name selection.append(obj) sobj = grt.classes.db_query_LiveDBObject() sobj.schemaName = self.schema sobj.name = self.schema sobj.type = "db.Schema" obj.owner = sobj separator = mforms.newMenuItem("", mforms.SeparatorMenuItem) separator.set_name("bottom_plugins_separator") self.menu.add_item(separator) self.menu.add_item_with_title("Refresh", self.refresh, "refresh") args = grt.Dict() args["selection"] = selection args["menu"] = mforms.togrt(self.menu, "ContextMenu") args['schema_inspector'] = True NotificationCenter().send("GRNLiveDBObjectMenuWillShow", self.editor, args)
def insert_item_to_plugin_context_menu(menu, item): bottom = menu.find_item("bottom_plugins_separator") if bottom: index = menu.get_item_index(bottom) if index > 0 and not menu.find_item("top_plugins_separator"): sep = mforms.newMenuItem("", mforms.SeparatorMenuItem) sep.set_name("top_plugins_separator") menu.insert_item(index, sep) index += 1 menu.insert_item(index, item)
def handleLiveTreeContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu tables_selected = [] for s in selection: if s.type == 'db.Table': tables_selected.append((s.schemaName, s.name)) else: return if selection: item = mforms.newMenuItem("Table Inspector") item.add_clicked_callback(lambda: show_table_inspector(sender, tables_selected)) menu.insert_item(0, item)
def handleLiveTreeContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu schemas_selected = [] for s in selection: if s.type == 'db.Schema': schemas_selected.append(s.name) else: return if schemas_selected: item = mforms.newMenuItem("Schema Inspector") item.add_clicked_callback( lambda: show_schema_manager(sender, schemas_selected)) menu.insert_item(2, item)
def handleLiveTreeContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu schemas_selected = [] for s in selection: if s.type == 'db.Schema': schemas_selected.append(s.name) else: return if schemas_selected: item = mforms.newMenuItem("Schema Inspector") item.add_clicked_callback(lambda: show_schema_manager(sender, schemas_selected)) menu.insert_item(2, item)
def handleContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu schemas_selected = None for s in selection: if s.type == 'db.Schema': schemas_selected = s.name break else: return item = mforms.newMenuItem("Load Spatial Data") item.add_clicked_callback( lambda sender=sender: showImporter(sender, schemas_selected)) menu.insert_item(0, item) menu.add_separator()
def handleContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu schemas_selected = None for s in selection: if s.type == 'db.Schema': schemas_selected = s.name break else: return item = mforms.newMenuItem("Load Spatial Data") item.add_clicked_callback(lambda sender=sender : showImporter(sender, schemas_selected)) menu.insert_item(0, item) menu.add_separator()
def handleLiveTreeContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu node_type = None mixed = False selection_type = None object_selected = False object_selected_count = 0 column_selected = False if len(selection) == 1: object_type_caption = { 'db.Schema' : "Schema", 'db.Table' : "Table", 'db.View' : "View", 'db.Function' : "Function", 'db.StoredProcedure' : "Stored Procedure", 'db.Index' : "Index", 'db.Trigger' : "Trigger", 'db.ForeignKey' : "Foreign Key", } else: object_type_caption = { 'db.Schema' : "Schemas", 'db.Table' : "Tables", 'db.View' : "Views", 'db.Function' : "Functions", 'db.StoredProcedure' : "Stored Procedures", 'db.Index' : "Indexes", 'db.Trigger' : "Triggers", 'db.ForeignKey' : "Foreign Keys", } unique_tables = set() selection_db_type = None for s in selection: if s.type != node_type: if node_type is None: node_type = s.type else: mixed = True if s.type == 'columns': selection_type = s.type column_selected = True unique_tables.add(s.name) elif s.type in ['tables', 'views', 'functions', 'storedProcedures']: selection_type = s.type object_selected = False if s.type == 'tables': selection_db_type = 'db.Table' elif s.type == 'views': selection_db_type = 'db.View' elif s.type == 'functions': selection_db_type = 'db.Function' elif s.type == 'storedProcedures': selection_db_type = 'db.StoredProcedure' elif s.type in ('db.Schema', 'db.Table', 'db.View', 'db.Function', 'db.StoredProcedure'): selection_type = s.type selection_db_type = s.type object_selected = True object_selected_count += 1 if s.type == 'db.Table': unique_tables.add(s.name) elif s.type in ('db.Index', 'db.Trigger'): selection_type = s.type object_selected = False elif s.type == ('db.Column'): selection_type = s.type if s.owner: unique_tables.add(s.owner.name) selection_type = s.owner.type+':'+s.type column_selected = True else: print "Unhandled type", s.type if mixed: selection_type = None pass else: item = menu.find_item('builtins_separator') if item: index = menu.get_item_index(item)+1 else: index = 0 needs_separator = False if False and object_selected and selection_type == 'db.Table': item = mforms.newMenuItem(_("Export Data to CSV File...")) item.set_name("export_table_csv") menu.insert_item(index-1, item) index += 1 item = mforms.newMenuItem(_("Import Data from CSV File...")) item.set_name("import_table_csv") menu.insert_item(index-1, item) index += 1 item = mforms.newMenuItem(_("Dump Data to SQL File...")) item.set_name("dump_table") menu.insert_item(index-1, item) index += 1 if object_selected or column_selected: # Add menu items for generating code code_items = [ # Caption, callback name, supported node types, enable condition, mixed node types allowed (_("Name"), 'name_short', ['db.Schema'], len(selection) > 0, False), (_("Name (short)"), 'name_short', ['tables', 'views', 'functions', 'storedProcedures', 'db.Table', 'db.Table:db.Column', 'db.View:db.Column', 'db.View', 'db.StoredProcedure', 'db.Function'], len(selection) > 0, True), (_("Name (long)"), 'name_long', ['tables', 'views', 'functions', 'storedProcedures', 'db.Table', 'db.Table:db.Column', 'db.View:db.Column', 'db.View', 'db.StoredProcedure', 'db.Function'], len(selection) > 0, True), (_("Select All Statement"), 'select_all_statement', ['db.Table', 'db.View'], len(selection) > 0, False), (_("Select All Statement"), 'select_all_statement', ['columns'], len(selection) == 1 and selection[0].type == 'columns', False), (_("Select Columns Statement"), 'select_columns_statement', ['db.Table:db.Column', 'db.View:db.Column'], len(unique_tables) == 1, False), (_("Insert Statement"), 'insert_all_statement', ['db.Table', 'columns'], len(selection) > 0, False), (_("Insert Statement"), 'insert_columns_statement', ['db.Table:db.Column'], len(selection) > 0, False), (_("Update Statement"), 'update_all_statement', ['db.Table', 'columns'], len(selection) > 0, False), (_("Update Statement"), 'update_columns_statement', ['db.Table:db.Column'], len(selection) > 0, False), (_("Delete Statement"), 'delete_statement', ['db.Table'], len(selection) > 0, False), (_("Create Statement"), 'create_statement', ['db.Schema', 'db.Table', 'db.View', 'db.StoredProcedure', 'db.Function'], len(selection) > 0, False), (_("Procedure Call"), 'call_procedure', ['db.StoredProcedure'], len(selection) > 0, False), (_("Function Call"), 'call_function', ['db.Function'], len(selection) > 0, False), (None, None, ['db.Table'], None, False), (_("Join Selected Tables"), 'build_joined_select', ['db.Table'], len(selection) == 2, False), (_("Delete with References"), 'build_cascaded_delete', ['db.Table'], len(selection) == 1, False), (_("Select Row References"), 'build_cascaded_select', ['db.Table'], len(selection) == 1, False), ] copy_submenu = mforms.newMenuItem("Copy to Clipboard") copy_submenu.set_name("copy_to_clipboard") menu.insert_item(index, copy_submenu) index += 1 send_submenu = mforms.newMenuItem("Send to SQL Editor") send_submenu.set_name("send_to_editor") menu.insert_item(index, send_submenu) index += 1 gencopy = CodeGenerator(sender, selection, False) gensend = CodeGenerator(sender, selection, True) for caption, name, types, enabled, allow_mixed in code_items: if not allow_mixed and mixed: continue if types and selection_type not in types: continue if caption is None: copy_submenu.add_separator() send_submenu.add_separator() else: item = copy_submenu.add_item_with_title(caption, getattr(gencopy, name), name) item.set_enabled(enabled) item = send_submenu.add_item_with_title(caption, getattr(gensend, name), name) item.set_enabled(enabled) needs_separator = True else: needs_separator = False if selection_type in ('tables', 'views', 'functions', 'storedProcedures', 'db.Schema', 'db.Table', 'db.View', 'db.Function', 'db.StoredProcedure') and len(selection) == 1: if needs_separator: menu.insert_item(index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False item = mforms.newMenuItem("Create %s..." % object_type_caption.get(selection_db_type, selection_db_type)) item.add_clicked_callback(lambda: do_create_object(sender, selection[0].schemaName, selection_db_type)) menu.insert_item(index, item) index+= 1 if selection_type in ('db.Table', 'tables'): item = mforms.newMenuItem("Create Table Like...") menu.insert_item(index, item) index += 1 # it = item.add_item_with_title("Selected Table", lambda: template_manager.create_table_like(sender, selection[0].schemaName, selection[0].name)) # if selection[0].type == 'tables': # it.set_enabled(False) for templ in template_manager.templates: it = item.add_item_with_title(templ.name, lambda templ=templ, schema=selection[0].schemaName: template_manager.create_table_like_template(sender, schema, templ)) item.add_separator() it = item.add_item_with_title("Edit Templates...", template_manager.edit_templates) if object_selected: if needs_separator: menu.insert_item(index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False if object_selected_count == 1: item = mforms.newMenuItem("Alter %s..." % object_type_caption.get(selection_type, selection_type)) else: item = mforms.newMenuItem("Alter %i %s..." % (object_selected_count, object_type_caption.get(selection_type, selection_type))) item.add_clicked_callback(lambda: do_alter_object(sender, selection)) menu.insert_item(index, item) index+= 1 needs_separator = True if selection_type == 'db.Table' and object_selected: item = mforms.newMenuItem("Table Maintenance...") item.add_clicked_callback(lambda: show_schema_manager(sender, set([obj.schemaName for obj in selection]), True)) menu.insert_item(index, item) index += 1 if object_selected: # or selection_type in ('db.Index', 'db.Trigger'): <-- enable this once we support selective refresh of LST on drop of these objects if needs_separator: menu.insert_item(index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False if object_selected_count == 1: item = mforms.newMenuItem("Drop %s..." % object_type_caption.get(selection_type, selection_type)) else: item = mforms.newMenuItem("Drop %i %s..." % (object_selected_count, object_type_caption.get(selection_type, selection_type))) item.add_clicked_callback(lambda: do_drop_object(sender, selection)) menu.insert_item(index, item) index+= 1 if selection_type == 'db.Table' and object_selected: item = mforms.newMenuItem("Truncate %s..." % ("Table" if object_selected_count == 1 else "%i Tables" % object_selected_count)) item.add_clicked_callback(lambda: do_truncate_table(sender, selection)) menu.insert_item(index, item) index += 1 if selection_type in ('db.Table', 'db.Schema', 'tables'): item = mforms.newMenuItem("Search Table Data...") item.add_clicked_callback(lambda: open_search(sender)) insert_item_to_plugin_context_menu(menu, item)
def handleLiveTreeContextMenu(name, sender, args): menu = mforms.fromgrt(args['menu']) selection = args['selection'] # Add extra menu items to the SQL editor live schema tree context menu node_type = None mixed = False selection_type = None object_selected = False object_selected_count = 0 column_selected = False if len(selection) == 1: object_type_caption = { 'db.Schema': "Schema", 'db.Table': "Table", 'db.View': "View", 'db.Function': "Function", 'db.StoredProcedure': "Stored Procedure", 'db.Index': "Index", 'db.Trigger': "Trigger", 'db.ForeignKey': "Foreign Key", } else: object_type_caption = { 'db.Schema': "Schemas", 'db.Table': "Tables", 'db.View': "Views", 'db.Function': "Functions", 'db.StoredProcedure': "Stored Procedures", 'db.Index': "Indexes", 'db.Trigger': "Triggers", 'db.ForeignKey': "Foreign Keys", } unique_tables = set() selection_db_type = None for s in selection: if s.type != node_type: if node_type is None: node_type = s.type else: mixed = True if s.type == 'columns': selection_type = s.type column_selected = True unique_tables.add(s.name) elif s.type in ['tables', 'views', 'functions', 'storedProcedures']: selection_type = s.type object_selected = False if s.type == 'tables': selection_db_type = 'db.Table' elif s.type == 'views': selection_db_type = 'db.View' elif s.type == 'functions': selection_db_type = 'db.Function' elif s.type == 'storedProcedures': selection_db_type = 'db.StoredProcedure' elif s.type in ('db.Schema', 'db.Table', 'db.View', 'db.Function', 'db.StoredProcedure'): selection_type = s.type selection_db_type = s.type object_selected = True object_selected_count += 1 if s.type == 'db.Table': unique_tables.add(s.name) elif s.type in ('db.Index', 'db.Trigger'): selection_type = s.type object_selected = False elif s.type == ('db.Column'): selection_type = s.type if s.owner: unique_tables.add(s.owner.name) selection_type = s.owner.type + ':' + s.type column_selected = True else: print "Unhandled type", s.type if mixed: selection_type = None pass else: item = menu.find_item('builtins_separator') if item: index = menu.get_item_index(item) + 1 else: index = 0 needs_separator = False if False and object_selected and selection_type == 'db.Table': item = mforms.newMenuItem(_("Export Data to CSV File...")) item.set_name("export_table_csv") menu.insert_item(index - 1, item) index += 1 item = mforms.newMenuItem(_("Import Data from CSV File...")) item.set_name("import_table_csv") menu.insert_item(index - 1, item) index += 1 item = mforms.newMenuItem(_("Dump Data to SQL File...")) item.set_name("dump_table") menu.insert_item(index - 1, item) index += 1 if object_selected or column_selected: # Add menu items for generating code code_items = [ # Caption, callback name, supported node types, enable condition, mixed node types allowed (_("Name"), 'name_short', ['db.Schema'], len(selection) > 0, False), (_("Name (short)"), 'name_short', [ 'tables', 'views', 'functions', 'storedProcedures', 'db.Table', 'db.Table:db.Column', 'db.View:db.Column', 'db.View', 'db.StoredProcedure', 'db.Function' ], len(selection) > 0, True), (_("Name (long)"), 'name_long', [ 'tables', 'views', 'functions', 'storedProcedures', 'db.Table', 'db.Table:db.Column', 'db.View:db.Column', 'db.View', 'db.StoredProcedure', 'db.Function' ], len(selection) > 0, True), (_("Select All Statement"), 'select_all_statement', ['db.Table', 'db.View'], len(selection) > 0, False), (_("Select All Statement"), 'select_all_statement', ['columns'], len(selection) == 1 and selection[0].type == 'columns', False), (_("Select Columns Statement"), 'select_columns_statement', ['db.Table:db.Column', 'db.View:db.Column'], len(unique_tables) == 1, False), (_("Insert Statement"), 'insert_all_statement', ['db.Table', 'columns'], len(selection) > 0, False), (_("Insert Statement"), 'insert_columns_statement', ['db.Table:db.Column'], len(selection) > 0, False), (_("Update Statement"), 'update_all_statement', ['db.Table', 'columns'], len(selection) > 0, False), (_("Update Statement"), 'update_columns_statement', ['db.Table:db.Column'], len(selection) > 0, False), (_("Delete Statement"), 'delete_statement', ['db.Table'], len(selection) > 0, False), (_("Create Statement"), 'create_statement', [ 'db.Schema', 'db.Table', 'db.View', 'db.StoredProcedure', 'db.Function' ], len(selection) > 0, False), (_("Procedure Call"), 'call_procedure', ['db.StoredProcedure'], len(selection) > 0, False), (_("Function Call"), 'call_function', ['db.Function'], len(selection) > 0, False), (None, None, ['db.Table'], None, False), (_("Join Selected Tables"), 'build_joined_select', ['db.Table'], len(selection) == 2, False), (_("Delete with References"), 'build_cascaded_delete', ['db.Table'], len(selection) == 1, False), (_("Select Row References"), 'build_cascaded_select', ['db.Table'], len(selection) == 1, False), ] copy_submenu = mforms.newMenuItem("Copy to Clipboard") copy_submenu.set_name("copy_to_clipboard") menu.insert_item(index, copy_submenu) index += 1 send_submenu = mforms.newMenuItem("Send to SQL Editor") send_submenu.set_name("send_to_editor") menu.insert_item(index, send_submenu) index += 1 gencopy = CodeGenerator(sender, selection, False) gensend = CodeGenerator(sender, selection, True) for caption, name, types, enabled, allow_mixed in code_items: if not allow_mixed and mixed: continue if types and selection_type not in types: continue if caption is None: copy_submenu.add_separator() send_submenu.add_separator() else: item = copy_submenu.add_item_with_title( caption, getattr(gencopy, name), name) item.set_enabled(enabled) item = send_submenu.add_item_with_title( caption, getattr(gensend, name), name) item.set_enabled(enabled) needs_separator = True else: needs_separator = False if selection_type in ('tables', 'views', 'functions', 'storedProcedures', 'db.Schema', 'db.Table', 'db.View', 'db.Function', 'db.StoredProcedure') and len(selection) == 1: if needs_separator: menu.insert_item( index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False item = mforms.newMenuItem( "Create %s..." % object_type_caption.get(selection_db_type, selection_db_type)) item.add_clicked_callback(lambda: do_create_object( sender, selection[0].schemaName, selection_db_type)) menu.insert_item(index, item) index += 1 if selection_type in ('db.Table', 'tables'): item = mforms.newMenuItem("Create Table Like...") menu.insert_item(index, item) index += 1 # it = item.add_item_with_title("Selected Table", lambda: template_manager.create_table_like(sender, selection[0].schemaName, selection[0].name)) # if selection[0].type == 'tables': # it.set_enabled(False) for templ in template_manager.templates: it = item.add_item_with_title( templ.name, lambda templ=templ, schema=selection[0].schemaName: template_manager.create_table_like_template( sender, schema, templ)) item.add_separator() it = item.add_item_with_title("Edit Templates...", template_manager.edit_templates) if object_selected: if needs_separator: menu.insert_item( index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False if object_selected_count == 1: item = mforms.newMenuItem( "Alter %s..." % object_type_caption.get(selection_type, selection_type)) else: item = mforms.newMenuItem( "Alter %i %s..." % (object_selected_count, object_type_caption.get(selection_type, selection_type))) item.add_clicked_callback( lambda: do_alter_object(sender, selection)) menu.insert_item(index, item) index += 1 needs_separator = True if selection_type == 'db.Table' and object_selected: item = mforms.newMenuItem("Table Maintenance...") item.add_clicked_callback(lambda: show_schema_manager( sender, set([obj.schemaName for obj in selection]), True)) menu.insert_item(index, item) index += 1 if object_selected: # or selection_type in ('db.Index', 'db.Trigger'): <-- enable this once we support selective refresh of LST on drop of these objects if needs_separator: menu.insert_item( index, mforms.newMenuItem("", mforms.SeparatorMenuItem)) index += 1 needs_separator = False if object_selected_count == 1: item = mforms.newMenuItem( "Drop %s..." % object_type_caption.get(selection_type, selection_type)) else: item = mforms.newMenuItem( "Drop %i %s..." % (object_selected_count, object_type_caption.get(selection_type, selection_type))) item.add_clicked_callback( lambda: do_drop_object(sender, selection)) menu.insert_item(index, item) index += 1 if selection_type == 'db.Table' and object_selected: item = mforms.newMenuItem( "Truncate %s..." % ("Table" if object_selected_count == 1 else "%i Tables" % object_selected_count)) item.add_clicked_callback( lambda: do_truncate_table(sender, selection)) menu.insert_item(index, item) index += 1 if selection_type in ('db.Table', 'db.Schema', 'tables'): item = mforms.newMenuItem("Search Table Data...") item.add_clicked_callback(lambda: open_search(sender)) insert_item_to_plugin_context_menu(menu, item)