Beispiel #1
0
        void Update()
        {
            string branchesPath = Path.Combine(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location), OgzContext.Resource1.strBranchFolderName);

            if (!Directory.Exists(branchesPath))
            {
                Directory.CreateDirectory(branchesPath);
            }
            string[] files = Directory.GetFiles(branchesPath, ("*" + Resource1.strBranchFileExt));

            DetachItemsClickEvents(cxtMenuStrip.Items);
            HelperSmartOp.UpdateContextMenuStrip(ref cxtMenuStrip, files);
            CreateItemsClickEvent(cxtMenuStrip.Items);
        }
Beispiel #2
0
        internal void DoShow(ref System.Windows.Forms.ContextMenuStrip cxtMenuStrip, IEnumerable <string> selectedPaths = null)
        {
            List <string> selectedItemPaths = new List <string>();;

            if (selectedPaths != null && selectedPaths.Count() > 0)
            {
                selectedItemPaths = selectedPaths.ToList();
            }

            var branchMenuList = HelperSmartOp.ToBranchMenuList(ref cxtMenuStrip);

            var  newBranchMenuList = new List <OgzShell.Branch.BranchMenu>();
            bool isAnyScriptRunned = false;

            foreach (var branchMenu in branchMenuList)
            {
                if (branchMenu.Script == null || !(branchMenu.Script is OgzShell.Branch.ContextLua) || string.IsNullOrWhiteSpace((branchMenu.Script as OgzShell.Branch.ContextLua).Show))
                {
                    newBranchMenuList.Add(branchMenu);
                    continue;
                }

                StringBuilder sbScript = new StringBuilder();

                #region Assign _SELECTEDPATHS
                //"_SELECTEDPATHS = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\"}
                sbScript.Append(_SELECTEDPATHS + " = {");
                int selItemsCount = selectedItemPaths.Count;
                for (int i = 0; i < selItemsCount; i++)
                {
                    sbScript.Append(string.Format(Resource1.strLuaStringFormat + ", ", selectedItemPaths[i]));
                    //sbScript.Append(string.Format("[[\"{0}\"]], ", selectedItemPaths[i]));//**__
                }
                sbScript.Append("}");
                //sbScript.Append(string.Format(Resource1.strLuaStringFormat + "}} ", selectedItemPaths[selItemsCount - 1]));
                //sbScript.Append(string.Format("[[\"{0}\"]]}}", selectedItemPaths[selItemsCount - 1]));
                #endregion

                #region Assign _MENU
                sbScript.AppendLine();//End Current Line
                //polyline = {color="blue", thickness=2, npoints=4, {x=13, y=4}, items={{x=-10, y=0}, {x=-10, y=1}}}
                sbScript.Append(_MENU + " = {");
                sbScript.Append(string.Format("CanShowMenu={0}, ", branchMenu.CanShowMenu.ToString().ToLower()));


                var _script = branchMenu.Script as OgzShell.Branch.ContextLua;
                sbScript.Append(string.Format("Script={{Show=" + Resource1.strLuaStringFormat + "}}, ", _script.Show));
                //sbScript.Append(string.Format("Script={{Show=\"{0}\"}}, ", _script.Show));
                // Script=
                // Remove first char '{' and append to sbScript
                sbScript.Append(GetIBranchLuaTableString(branchMenu).Remove(0, 1));

                #endregion

                sbScript.AppendLine();//end current line

                // Append user lua script
                sbScript.Append((branchMenu.Script as OgzShell.Branch.ContextLua).Show);

                //string finalScript = sbScript.ToString();
                //System.IO.File.WriteAllText(@"C:\OguzhanE\Projects\CSharp\WinForms\OgzShell\tst\luaScr.txt", finalScript);

                //Run Lua show script
                using (Lua lua = new Lua())
                {
                    lua.LoadCLRPackage();
                    lua.DoString(sbScript.ToString());

                    isAnyScriptRunned = true;
                    // Add 'New'(may be edit BranchMenu) BranchMenu to list
                    newBranchMenuList.Add(LuaTableToBranchMenu(lua.GetTable(_MENU)));
                }
            }

            if (isAnyScriptRunned && newBranchMenuList.Count > 0)
            {
                /// Apply Changes to ContextMenuStrip
                HelperSmartOp.UpdateContextMenuStrip(ref cxtMenuStrip, newBranchMenuList);
            }
        }