Example #1
0
        private void tlvwLocals_ItemAfterEdit(object sender, TreeListViewAfterEditEventArgs e)
        {
            if (e.Item != null && (e.SubItem != null && e.Item.Tag is LuaVariable) && e.SubItem.Text != e.NewValue)
            {
                LuaVariable oldVar     = e.Item.Tag as LuaVariable;
                LuaVariable updatedVar = new LuaVariable();
                double      dummyDouble;

                if (e.NewValue.StartsWith("\""))
                {
                    string strVal = e.NewValue.Substring(1);
                    // Let's consider the new value a string
                    if (e.NewValue.EndsWith("\""))
                    {
                        strVal = strVal.Substring(0, strVal.Length - 1);
                    }

                    updatedVar.Type  = LuaTypes.LUA_TSTRING;
                    updatedVar.Value = strVal;
                }
                else if (Double.TryParse(e.NewValue, out dummyDouble))
                {
                    updatedVar.Type  = LuaTypes.LUA_TNUMBER;
                    updatedVar.Value = string.Format("{0:0.000000}", Convert.ToDouble(e.NewValue));
                }
                else if (e.NewValue.ToLower() == "nil")
                {
                    updatedVar.Type  = LuaTypes.LUA_TNIL;
                    updatedVar.Value = e.NewValue.ToLower();
                }
                else if (e.NewValue.StartsWith("{"))
                {
                    // todo: handle table construct by executing "return {...}" and
                    //       setting the result of execution as the local's value
                }
                else
                {
                    updatedVar.Type  = LuaTypes.LUA_TSTRING;
                    updatedVar.Value = e.NewValue;
                }

                updatedVar.Index       = oldVar.Index;
                updatedVar.FullNameOut = oldVar.FullNameOut;
                updatedVar.Name        = oldVar.Name;

                if (oldVar.Type == LuaTypes.LUA_TTABLE && updatedVar.Type != LuaTypes.LUA_TTABLE)
                {
                    // Remove all child
                    TreeListViewItem tlvi = _nodesByFullName[oldVar.FullNameIn];
                    RemoveTreeListViewItemChildsRecursively(tlvi);
                }

                e.Item.Tag = updatedVar;
                e.Item.SubItems[0].Object = updatedVar.Name;
                e.Item.SubItems[1].Object = updatedVar.GetPrettyPrintValue();
                e.Item.SubItems[2].Object = updatedVar.Type.ToString();

                ClientDebugManager.Instance.AddCommand(new SetLuaVariableCommand(updatedVar));
            }
        }
        private void solutionExplorerTreeView_ItemAfterEdit(object sender, TreeListViewAfterEditEventArgs e)
        {
            ILuaEditDocument doc = e.Item.Tag as ILuaEditDocument;

            if (doc == null)
            {
                e.Cancel = true;
            }
            else
            {
                bool isDir = false;

                try
                {
                    isDir = (File.GetAttributes(doc.FileName) & FileAttributes.Directory) == FileAttributes.Directory;
                }
                catch (Exception ex)
                {
                    string msg = string.Format("Error while trying to rename '{0}': {1}", doc.FileName, ex.Message);
                    FrameworkManager.ShowMessageBox(msg, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                    return;
                }

                try
                {
                    string newFileName = null;

                    if (isDir)
                    {
                        newFileName = Path.Combine(Directory.GetParent(doc.FileName).FullName, e.NewValue);
                    }
                    else
                    {
                        if (e.Item.Tag is ILuaEditDocumentProject || e.Item.Tag is ILuaEditDocumentSolution)
                        {
                            newFileName = Path.Combine(Path.GetDirectoryName(doc.FileName), e.NewValue + Path.GetExtension(doc.FileName));
                        }
                        else
                        {
                            newFileName = Path.Combine(Path.GetDirectoryName(doc.FileName), e.NewValue);
                        }
                    }

                    if (newFileName != doc.FileName)
                    {
                        DocumentsManager.Instance.RenameDocument(doc, newFileName);

                        if (e.Item != null)
                        {
                            e.Item.ToolTip = doc.FileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    e.Cancel = true;
                    FrameworkManager.ShowMessageBox(ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }