private void ActionContextOnCurrentContextChanged(object sender, EventArgs e) { try { INodeInformation[] nodes; INodeInformation node; int nodeCount; IObjectExplorerService objectExplorer = GetService(typeof(IObjectExplorerService)) as ObjectExplorerService; if (objectExplorer != null) { objectExplorer.GetSelectedNodes(out nodeCount, out nodes); node = nodeCount > 0 ? nodes[0] : null; if (node != null) { MenuItemAbstract menuItem = Factories.MenuItemFactory.CreateMenuItem(node); AddMenuItemToHierarchyObject(node, menuItem); } } } #pragma warning disable 0169 #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ObjectExplorerContextException) #pragma warning restore CS0168 // Variable is declared but never used { //MessageBox.Show("ObjectExplorerContextException: " + ObjectExplorerContextException.Message); } #pragma warning restore 0169 }
/// <summary> /// Gets the menu items. /// </summary> /// <returns></returns> public System.Windows.Forms.ToolStripItem[] GetMenuItems() { /*context menu*/ ToolStripMenuItem item = new ToolStripMenuItem("Шаблоны запросов"); INodeInformation[] nodes; INodeInformation node; int nodeCount; objectExplorer.GetSelectedNodes(out nodeCount, out nodes); node = nodeCount > 0 ? nodes[0] : null; //QueryTemplate[] templates = GetTemplates(nodeInformation.UrnPath, nodeInformation.Name); QueryTemplate[] templates = GetTemplates(node.UrnPath, node.Name); foreach (var template in templates) { ToolStripMenuItem nm = new ToolStripMenuItem(template.Name); nm.Click += new EventHandler(ScriptQuery_Click); nm.Tag = template; item.DropDownItems.Add(nm); } //ToolStripMenuItem nm = new ToolStripMenuItem(nodeInformation.UrnPath + "////"+ nodeInformation.InvariantName + "////" + nodeInformation.Name); //nm.Click += new EventHandler(ScriptQuery_Click); ///*context submenu item - generate inserts*/ //item.DropDownItems.Add(nm); return(new ToolStripItem[] { item }); }
void ObjectExplorerTreeViewAfterSelectCallback(object sender, TreeViewEventArgs e) { INodeInformation[] nodes; INodeInformation node; int nodeCount; objectExplorer.GetSelectedNodes(out nodeCount, out nodes); node = nodeCount > 0 ? nodes[0] : null; if (!nodeMenus.Keys.Any(f => f == node.UrnPath)) { var _tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler)); // if (_tableMenu.Parent.Name == node.Name) { SQLMenuItem item = new SQLMenuItem(objectExplorer, package); _tableMenu.AddChild(string.Empty, item); //if (currentMenu != null) { // currentMenu.Dispose(); //} //currentMenu = item; nodeMenus.Add(node.UrnPath, item); // } } //var menu = (HierarchyObject)node.GetService(typeof(IMenuHandler)); //var menu = e.Node.ContextMenu; //menu.MenuItems.Add(e.Node.FullPath + e.Node.Text); //menu.AddChild(string.Empty, mn); }
private void ActionContextOnCurrentContextChanged(object sender, EventArgs e) { try { INodeInformation[] nodes; int nodeCount; IObjectExplorerService objectExplorer = (ObjectExplorerService)this.ServiceProvider.GetService(typeof(IObjectExplorerService)); objectExplorer.GetSelectedNodes(out nodeCount, out nodes); var node = nodeCount > 0 ? nodes[0] : null; if (node != null) { if (node.UrnPath == "Server") { if (!IsServerMenuAdded) { var tableMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler)); PropertyInfo treeViewProp = objectExplorer.GetType().GetProperty("Tree", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase); if (treeViewProp != null) { var treeView = (TreeView)treeViewProp.GetValue(objectExplorer, null); var item = new ServerMenuItem(treeView); tableMenu.AddChild(string.Empty, item); treeView.AfterExpand += FilterDataBase; treeView.AfterSelect += (o, args) => { selectedNode = args.Node; }; } IsServerMenuAdded = true; } } } if (!IsSearchBarAdded) { PropertyInfo treeViewProp = objectExplorer.GetType().GetProperty("Tree", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase); var treeView = (TreeView)treeViewProp.GetValue(objectExplorer, null); var searchNode = new SearchNode(treeView, "search bar"); treeView.Nodes.Insert(0, searchNode); treeView.Controls.Add(searchNode.TextBox); searchNode.TextBox.AutoSize = false; searchNode.TextBox.Size = new Size(treeView.Bounds.Width, searchNode.Bounds.Height); searchNode.TextBox.KeyDown += OnKeyDown; IsSearchBarAdded = true; } if (IsSearchBarAdded && IsServerMenuAdded) { contextService.ActionContext.CurrentContextChanged -= ActionContextOnCurrentContextChanged; } } catch (Exception objectExplorerContextException) { MessageBox.Show(objectExplorerContextException.Message); } }
/// <summary> /// Gets the object explorer selected nodes. /// </summary> /// <returns></returns> private INodeInformation[] GetObjectExplorerSelectedNodes() { IObjectExplorerService objExplorer = ServiceCache.GetObjectExplorer(); int arraySize; INodeInformation[] nodes; objExplorer.GetSelectedNodes(out arraySize, out nodes); return(nodes); }
public ServerConnectionInfo GetCurrentConnection() { ServerConnectionInfo currentConnection = null; try { UIConnectionInfo connectionInfo = null; if (_scriptFactory.CurrentlyActiveWndConnectionInfo != null) { connectionInfo = _scriptFactory.CurrentlyActiveWndConnectionInfo.UIConnectionInfo; } if (connectionInfo != null) { currentConnection = new ServerConnectionInfo { ServerName = connectionInfo.ServerName, UseIntegratedSecurity = string.IsNullOrEmpty(connectionInfo.Password), UserName = connectionInfo.UserName, Password = connectionInfo.Password }; } else { int nodeCount; INodeInformation[] nodes; _objectExplorerService.GetSelectedNodes(out nodeCount, out nodes); if (nodes.Length > 0) { var info = nodes[0].Connection as SqlConnectionInfo; if (info != null) { currentConnection = new ServerConnectionInfo { ServerName = info.ServerName, UseIntegratedSecurity = info.UseIntegratedSecurity, UserName = info.UserName, Password = info.Password }; } } } } catch (Exception ex) { Trace.TraceError("Error getting current connection: {0}", ex); } return(currentConnection); }
public static INodeInformation FindSelectedNode(IObjectExplorerService explorerService) { int arraySize; INodeInformation[] array; explorerService.GetSelectedNodes(out arraySize, out array); if (arraySize == 0) { return(null); } return(array[0]); }