Пример #1
0
        public static Dictionary <string, int> GetFileListFromEventRef(IntPtr eventRef)
        {
            AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);

            try {
                int line;
                try {
                    SelectionRange range = GetEventParameter <SelectionRange> (eventRef, CarbonEventParameterName.AEPosition, CarbonEventParameterType.Char);
                    line = range.lineNum + 1;
                } catch (Exception) {
                    line = 0;
                }

                var arr = AppleEvent.GetListFromAEDesc <string, FSRef> (ref list, CoreFoundation.FSRefToString,
                                                                        (OSType)(int)CarbonEventParameterType.FSRef);
                var files = new Dictionary <string, int> ();
                foreach (var s in arr)
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        files[s] = line;
                    }
                }
                return(files);
            } finally {
                CheckReturn((int)AppleEvent.AEDisposeDesc(ref list));
            }
        }
Пример #2
0
        public static IList <string> GetUrlListFromEventRef(IntPtr eventRef)
        {
            AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);

            try {
                return(AppleEvent.GetUtf8StringListFromAEDesc(ref list, true));
            } finally {
                Carbon.CheckReturn((int)AppleEvent.AEDisposeDesc(ref list));
            }
        }
Пример #3
0
        public static string Run(byte[] compiledBytes)
        {
            AEDesc sourceData = new AEDesc();

            try {
                AppleEvent.AECreateDesc((OSType)(int)OsaType.OsaGenericStorage, compiledBytes, out sourceData);
                return(Run(false, ref sourceData));
            } finally {
                AppleEvent.AEDisposeDesc(ref sourceData);
            }
        }
Пример #4
0
        public static string Run(string scriptSource)
        {
            AEDesc sourceData = new AEDesc();

            try {
                //apparently UnicodeText doesn't work
                AppleEvent.AECreateDescAscii(scriptSource, out sourceData);
                return(Run(true, ref sourceData));
            } finally {
                AppleEvent.AEDisposeDesc(ref sourceData);
            }
        }
Пример #5
0
        public static T[] GetListFromAEDesc <T, TRef> (ref AEDesc list, AEDescValueSelector <TRef, T> sel, OSType type)
            where TRef : struct
        {
            long count = AppleEvent.AECountItems(ref list);

            T[] arr = new T[count];
            for (int i = 1; i <= count; i++)
            {
                TRef r = AppleEvent.AEGetNthPtr <TRef> (ref list, i, type);
                arr [i - 1] = sel(ref r);
            }
            return(arr);
        }
Пример #6
0
        public static IList <string> GetUtf8StringListFromAEDesc(ref AEDesc list, bool skipEmpty)
        {
            long count = AppleEvent.AECountItems(ref list);
            var  items = new List <string> ();

            for (int i = 1; i <= count; i++)
            {
                string str = AppleEvent.GetUtf8StringFromAEPtr(ref list, i);
                if (!string.IsNullOrEmpty(str))
                {
                    items.Add(str);
                }
            }
            return(items);
        }
Пример #7
0
        public static string Run(string scriptSource)
        {
            AEDesc sourceData = new AEDesc();

            try {
                AppleEvent.AECreateDescUtf8(scriptSource, out sourceData);
                return(Run(true, ref sourceData));
            } catch (AppleScriptException ex) {
                MonoDevelop.Core.LoggingService.LogWarning(
                    "Applescript failure: {0}\n[[\n{1}\n]]",
                    ex.Message,
                    scriptSource);
                throw;
            } finally {
                AppleEvent.AEDisposeDesc(ref sourceData);
            }
        }
Пример #8
0
        static OsaError Run(bool compile, ref AEDesc scriptData, out string value)
        {
            var component = ComponentManager.OpenDefaultComponent((OSType)(int)OsaType.OsaComponent, (OSType)(int)OsaType.AppleScript);

            if (component.IsNull)
            {
                throw new Exception("Could not load component");
            }
            AEDesc resultData = new AEDesc();
            OsaId  contextId = new OsaId(), scriptId = new OsaId(), resultId = new OsaId();

            try {
                AppleEvent.AECreateDescNull(out resultData);
                //apparently UnicodeText doesn't work
                var resultType = new DescType()
                {
                    Value = (OSType)"TEXT"
                };

                //var result = OSADoScript (component, ref sourceData, contextId, resultType, OsaMode.Default, ref resultData);

                OsaError result;
                if (compile)
                {
                    result = OSACompile(component, ref scriptData, OsaMode.Default, ref scriptId);
                }
                else
                {
                    result = OSALoad(component, ref scriptData, OsaMode.Default, ref scriptId);
                }

                if (result == OsaError.Success)
                {
                    result = OSAExecute(component, scriptId, contextId, OsaMode.Default, out resultId);
                    if (result == OsaError.Success)
                    {
                        result = OSADisplay(component, resultId, resultType, OsaMode.Default, out resultData);
                        if (result == OsaError.Success)
                        {
                            value = AppleEvent.GetStringFromAEDesc(ref resultData);
                            return(result);
                        }
                    }
                }
                AEDesc errorDesc = new AEDesc();
                try {
                    AppleEvent.AECreateDescNull(out resultData);
                    if (OsaError.Success == OSAScriptError(component, OsaErrorSelector.Message, resultType, out errorDesc))
                    {
                        value = AppleEvent.GetStringFromAEDesc(ref errorDesc);
                        return(result);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Unexpected result: {0}", (long)result));
                    }
                } finally {
                    AppleEvent.AEDisposeDesc(ref errorDesc);
                }
            } finally {
                AppleEvent.AEDisposeDesc(ref scriptData);
                AppleEvent.AEDisposeDesc(ref resultData);
                if (!contextId.IsZero)
                {
                    OSADispose(component, contextId);
                }
                if (!scriptId.IsZero)
                {
                    OSADispose(component, scriptId);
                }
                if (!resultId.IsZero)
                {
                    OSADispose(component, resultId);
                }
                if (!component.IsNull)
                {
                    ComponentManager.CloseComponent(component);
                }
            }
        }