public static void CreateSnippet(AddHandlerDataObject data)
        {
            ISnippetGenerator gene;

            switch (EditorSettings.ScriptExtension)
            {
                    //case ScriptExtensions.JAVASCRIPT:
                default:
                    gene = new JavascriptSnippetGenerator(data);
                    break;
                case ScriptExtensions.CSHARP:
                    gene = new CSharpSnippetGenerator(data);
                    break;
                case ScriptExtensions.BOO:
                    gene = new BooSnippetGenerator(data);
                    break;
            }

            string snippet = gene.Generate();

            if (data.OpenScript)
            {
                int index = snippet.IndexOf(PersistedDataProcessor.CursorMarker);

                string[] parts = snippet.Substring(0, index).Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                // set line number
                data.SnippetLineNumber = parts.Length; // +1;

                // remove market
                snippet = snippet.Replace(PersistedDataProcessor.CursorMarker, string.Empty);
            }

            data.Snippet = snippet;
        }
Exemple #2
0
        public static void InsertHandler(AddHandlerDataObject data)
        {
            ISnippetGenerator gene;

            switch (EditorSettings.ScriptExtension)
            {
            //case ScriptExtensions.JAVASCRIPT:
            default:
                gene = new JavascriptSnippetGenerator(data);
                break;

            case ScriptExtensions.CSHARP:
                gene = new CSharpSnippetGenerator(data);
                break;

            case ScriptExtensions.BOO:
                gene = new BooSnippetGenerator(data);
                break;
            }

            string origSnippet = data.Snippet;

            if (string.IsNullOrEmpty(origSnippet))
            {
                Debug.LogError("Problem with file content");
                return;
            }

            string handlerString = gene.CreateEventHandler();

            string[] parts = origSnippet.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(parts);
            int index = Math.Max(0, parts.Length - 2);

            list.Insert(index, handlerString);
            string snippet = String.Join(Environment.NewLine, list.ToArray());

            if (data.OpenScript)
            {
                index = snippet.IndexOf(PersistedDataProcessor.CursorMarker);
                if (index == -1)
                {
                    Debug.LogError("Cannot find cursor marker");
                    return;
                }

                parts = snippet.Substring(0, index).Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                // set line number
                data.SnippetLineNumber = parts.Length; // +1;

                // remove marker
                data.Snippet = snippet.Replace(PersistedDataProcessor.CursorMarker, string.Empty);

                // set line number
                data.SnippetLineNumber = index;
            }
        }
        public static void InsertHandler(AddHandlerDataObject data)
        {
            ISnippetGenerator gene;

            switch (EditorSettings.ScriptExtension)
            {
                    //case ScriptExtensions.JAVASCRIPT:
                default:
                    gene = new JavascriptSnippetGenerator(data);
                    break;
                case ScriptExtensions.CSHARP:
                    gene = new CSharpSnippetGenerator(data);
                    break;
                case ScriptExtensions.BOO:
                    gene = new BooSnippetGenerator(data);
                    break;
            }

            string origSnippet = data.Snippet;

            if (string.IsNullOrEmpty(origSnippet))
            {
                Debug.LogError("Problem with file content");
                return;
            }

            string handlerString = gene.CreateEventHandler();

            string[] parts = origSnippet.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(parts);
            int index = Math.Max(0, parts.Length - 2);
            list.Insert(index, handlerString);
            string snippet = String.Join(Environment.NewLine, list.ToArray());

            if (data.OpenScript)
            {
                index = snippet.IndexOf(PersistedDataProcessor.CursorMarker);
                if (index == -1)
                {
                    Debug.LogError("Cannot find cursor marker");
                    return;
                }

                parts = snippet.Substring(0, index).Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                // set line number
                data.SnippetLineNumber = parts.Length; // +1;

                // remove marker
                data.Snippet = snippet.Replace(PersistedDataProcessor.CursorMarker, string.Empty);

                // set line number
                data.SnippetLineNumber = index;
            }
        }
Exemple #4
0
        public static void CreateSnippet(AddHandlerDataObject data)
        {
            ISnippetGenerator gene;

            switch (EditorSettings.ScriptExtension)
            {
            //case ScriptExtensions.JAVASCRIPT:
            default:
                gene = new JavascriptSnippetGenerator(data);
                break;

            case ScriptExtensions.CSHARP:
                gene = new CSharpSnippetGenerator(data);
                break;

            case ScriptExtensions.BOO:
                gene = new BooSnippetGenerator(data);
                break;
            }

            string snippet = gene.Generate();

            if (data.OpenScript)
            {
                int index = snippet.IndexOf(PersistedDataProcessor.CursorMarker);

                string[] parts = snippet.Substring(0, index).Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                // set line number
                data.SnippetLineNumber = parts.Length; // +1;

                // remove market
                snippet = snippet.Replace(PersistedDataProcessor.CursorMarker, string.Empty);
            }

            data.Snippet = snippet;
        }