/// <summary> /// Draws background, border, text, and the image of tooltip /// </summary> /// <param name="sender">object</param> /// <param name="e">DrawToolTipEventArgs</param> private void toolTipSLMIV_Draw(object sender, DrawToolTipEventArgs e) { try { TreeView tview = (TreeView)e.AssociatedWindow; if (tview.SelectedNode != null) { TreeNode tnode = tview.SelectedNode; //Create SLMIVImage which reads the ImageLog SLMIVImage NodeImage = new SLMIVImage(Common.ImageLog); NodeImage.Get(tnode.Name); //Draw the background and border e.DrawBackground(); e.DrawBorder(); //Draw the text StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; Rectangle rect = new Rectangle(125, 0, e.Bounds.Width - (150), e.Bounds.Height); e.Graphics.DrawString(tnode.Text, e.Font, Brushes.Black, rect, sf); if ((((string)tnode.Tag) != "notecard") && (((string)tnode.Tag) != "lsl")) { //Draw the image e.Graphics.DrawImage(NodeImage.Get(tnode.Name), 9, 9); } else { //Does it have a local text file? if (NodeImage.path_image != null && NodeImage.path_image.ToLower().Trim().EndsWith(".txt")) { System.Drawing.Image image = new Bitmap(SLMIV.Resources.Folder_open, 120, 120); e.Graphics.DrawImage(image, 9, 9); } else if (NodeImage.path_image != null && NodeImage.path_image.ToLower().Trim().EndsWith(".lsl")) { System.Drawing.Image image = new Bitmap(SLMIV.Resources.Folder_open, 120, 120); e.Graphics.DrawImage(image, 9, 9); //Draw the no image //e.Graphics.DrawImage(System.Drawing.Image.FromHbitmap(SLMIV.Resources.Nonecircle.GetHbitmap()), 9, 9); } else { //Draw the no image System.Drawing.Image image = new Bitmap(SLMIV.Resources.Nonecircle, 120, 120); e.Graphics.DrawImage(image, 9, 9); } } } } catch (Exception ex) { } }
/// <summary> /// Occurs when user clicks the open menu option /// Opens the Item {} /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { //If this is a landmark, then ask if you want to visit slr int iNodeindex = 0; MIUtils.OD_treeindex.TryGetValue(treeView1.SelectedNode.Name, out iNodeindex); if (iNodeindex != -1) { MIUtils.INV_TYPE nodeObjtype; Object objinfo = new Object(); objinfo = MIUtils.GetMyInventoryObject(iNodeindex, out nodeObjtype); //Create SLMIVImage which reads the ImageLog SLMIVImage NodeImage = new SLMIVImage(Common.ImageLog); if (nodeObjtype == MIUtils.INV_TYPE.ITEM) { if (((Item)objinfo).type == "landmark") { #region landmark try { //MessageBox.Show(((Item)objinfo).name); string temp = ((Item)objinfo).name; temp = temp.Replace(")", ""); temp = temp.Replace("(", ","); string[] location = temp.Split(','); //first word after first ',' should be region string region = location[1].Trim(); string x = location[2].Trim(); string y = location[3].Trim(); string z = location[3].Trim(); string slurl = "http://slurl.com/secondlife/" + region + "/" + x + "/" + y + "/" + z; DialogResult dResult = MessageBox.Show("Do you want to visit?\r\n" + slurl, "Visit landmark at slurl.com", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dResult == DialogResult.Yes) { System.Diagnostics.Process.Start(slurl); } else if (dResult == DialogResult.No) { } else if (dResult == DialogResult.Cancel) { } } catch (Exception ex) { if (ex.Message.StartsWith("Index")) { MessageBox.Show("Sorry, can not proceed with slurl visit.\r\nNot enough landmark information in the name of the landmark.\r\nPlease rename the landmark inworld with the correct sl default name.", "slurl visit error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else MessageBox.Show(ex.Message); } #endregion landmark //if it is a script or notecard } else if ((((Item)objinfo).type == "notecard") || (((Item)objinfo).type == "lsltext")) { #region notecard try { //MessageBox.Show(((Item)objinfo).name); string temp = ((Item)objinfo).name; string uuid = (((Item)objinfo).item_id); if (NodeImage.sbImageLog.ToString().IndexOf(uuid) != -1) { //Extract string from log int commapoint = (NodeImage.sbImageLog.ToString().Trim().IndexOf(uuid) + uuid.Length + 1); int endofpath = (NodeImage.sbImageLog.ToString().IndexOf("\r\n", commapoint + 1));//find the first return after the commapoint string[] splitline = (NodeImage.sbImageLog.ToString().Trim().Substring(commapoint, endofpath - commapoint)).Split('#');//seperate out the comments System.Diagnostics.Process.Start(splitline[0].Trim()); } } catch (Exception ex) { if (ex.Message.StartsWith("Index")) { MessageBox.Show("Sorry.\r\nNot enough information.", "browse to a file error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else MessageBox.Show(ex.Message); } #endregion notecard } else { //This works for local paths and urls if (NodeImage.sbImageLog.ToString().IndexOf(treeView1.SelectedNode.Name) != -1) { NodeImage.Display(treeView1.SelectedNode.Name); } } } } }
/// <summary> /// Event occurs when a mouse button is pressed down /// Right-Click events handled here with ContextMenuStrip /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeView1_MouseDown(object sender, MouseEventArgs e) { try { try { //Copy the node selected... selectedTreeNode = (TreeNode)(treeView1.GetNodeAt(e.X, e.Y).Clone()); //***DO SELECTION STUFF*** int startingImage = selectedTreeNode.ImageIndex; selectedTreeNode.SelectedImageIndex = startingImage; //Set Selection... treeView1.SelectedNode = selectedTreeNode; treeView1.Update(); //Get Folder or Item Object Info tbOutput.Clear(); string ObjectsKey = selectedTreeNode.Name; int ivalue = 0; MIUtils.OD_treeindex.TryGetValue(ObjectsKey, out ivalue); MIUtils.INV_TYPE objtype = new MIUtils.INV_TYPE(); Object objectinfo = new Object(); if (ivalue != -1) { objectinfo = MIUtils.GetMyInventoryObject(ivalue, out objtype); if (objtype == MIUtils.INV_TYPE.FOLDER) { tbOutput.AppendText(((Folder)objectinfo).ToString()); } else//must be item... { tbOutput.AppendText(((Item)objectinfo).ToString()); } } //If the starting image was a folder, then update... if (startingImage == 0 || startingImage == 1) { if (selectedTreeNode.IsExpanded) { selectedTreeNode.ImageIndex = 1;//then open folder } else { selectedTreeNode.ImageIndex = 0;//if closed folder } } #region If RIGHT-CLICK... //If RIGHT-CLICK... if (e.Button == MouseButtons.Right) { //***DISPLAY RIGHT-CLICK CONTEXTMENU*** try { //Copy the node selected... selectedTreeNode = (TreeNode)(treeView1.GetNodeAt(e.X, e.Y).Clone()); fullpath_ofnode = treeView1.GetNodeAt(e.X, e.Y).FullPath; //Let's select this node instead of the last selected node //treeView1.SelectedNode = selectedTreeNode; //treeView1.Update(); //Display the contextmenu if it is not the Trash can... if (selectedTreeNode.Text == "Trash" || selectedTreeNode.Text == "TrashFolder") { DialogResult dResult = MessageBox.Show("Empty Trash?", "Title", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dResult == DialogResult.Yes) { //Delete all of the nodes under Trash foreach (TreeNode originalNode in this.selectedTreeNode.Nodes) { RemoveTreeViewNode(originalNode); } //Log it Logs.LogEntry("Empty Trash", File.AppendText(Common.MainLog)); } else if (dResult == DialogResult.No) { } else if (dResult == DialogResult.Cancel) { } } else //not Trash can { //Do we enable 'Open' ??... if (objtype == MIUtils.INV_TYPE.FOLDER) { this.openToolStripMenuItem.Enabled = false; } else//must be item... { //Let's enable the Open choice this.openToolStripMenuItem.Enabled = true; //Let's disable the open if there is no image attached if (((Item)objectinfo).type != "landmark") { //Create SLMIVImage which reads the ImageLog SLMIVImage NodeImage = new SLMIVImage(Common.ImageLog); if (NodeImage.sbImageLog.ToString().IndexOf(selectedTreeNode.Name) != -1) { this.openToolStripMenuItem.Enabled = true; } else this.openToolStripMenuItem.Enabled = false; } //Let's examine for Download feature for Notecards, LSL, and other if (((Item)objectinfo).type == "notecard" || ((Item)objectinfo).type == "lsl" || ((Item)objectinfo).type == "lsltext" || ((Item)objectinfo).type == "texture" || ((Item)objectinfo).type == "snapshot") { this.downloadToolStripMenuItem.Enabled = true; } else { this.downloadToolStripMenuItem.Enabled = false; } } //now show RIGHTCLICK MENU... this.ContextMenuStrip = contextMenuStrip1; // this.ContextMenuStrip.Show();//FIX: stop first display somewhere else //Need to refresh or ToolTips will be lost treeView1.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion If RIGHT-CLICK... //Scroll to the last line and right justified tbOutput.AppendText("\r\n"); tbOutput.ScrollToCaret(); } catch (Exception) { //If clicking on nothing in treeview1, exception is thrown } } catch (Exception ex) { MessageBox.Show("treeView1_MouseDown Error: " + ex.Message, "MouseDown Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }