Ejemplo n.º 1
0
    public void DerivedArg()
    {
        Subclass1 x = Subclass1.make(13);
        NSString  s = NSString.Create("hey");

        NSString t = x.Call("concat", s, s).To <NSString>();

        Assert.AreEqual("heyhey", t.description());
    }
Ejemplo n.º 2
0
		private void DoReadData(NSData data, NSString typeName)
		{
			switch (typeName.description())
			{
				// Note that this does not mean that the file is utf8, instead it means that the
				// file is our default document type which means we need to deduce the encoding.
				case "Plain Text, UTF8 Encoded":
				case "HTML":
					Boss boss = ObjectModel.Create("TextEditorPlugin");
					var encoding = boss.Get<ITextEncoding>();
					NSString str = encoding.Decode(data, out m_encoding);
					m_text = NSMutableAttributedString.Alloc().initWithString(str).To<NSMutableAttributedString>();
					
					if (m_encoding == Enums.NSMacOSRomanStringEncoding)
						DoEncodingWarning();
					
					// If an html file is being edited in Continuum then ensure that it is saved
					// as plain text. (To save a document as html the user needs to use save as
					// and explicitly select html).
					setFileType(NSString.Create("Plain Text, UTF8 Encoded"));
					break;
				
				// These types are based on the file's extension so we can (more or less) trust them.
				case "Rich Text Format (RTF)":
					m_text = DoReadWrapped(data, Externs.NSRTFTextDocumentType);
					break;
					
				case "Word 97 Format (doc)":
					m_text = DoReadWrapped(data, Externs.NSDocFormatTextDocumentType);
					break;
					
				case "Word 2007 Format (docx)":
					m_text = DoReadWrapped(data, Externs.NSOfficeOpenXMLTextDocumentType);
					break;
					
				case "Open Document Text (odt)":
					m_text = DoReadWrapped(data, Externs.NSOpenDocumentTextDocumentType);
					break;
					
				// Open as Binary
				case "binary":
					m_text = NSMutableAttributedString.Create(data.bytes().ToText());
					m_binary = true;
					m_encoding = Enums.NSUTF8StringEncoding;
					break;
				
				default:
					Contract.Assert(false, "bad typeName: " + typeName.description());
					break;
			}
		}
Ejemplo n.º 3
0
		// Used to write the document.
		public NSData dataOfType_error(NSString typeName, IntPtr outError)
		{
			NSData data = null;
			
			try
			{
				DoCheckForControlChars(m_controller.TextView.textStorage().string_());
				
				NSMutableAttributedString astr = m_controller.TextView.textStorage().mutableCopy().To<NSMutableAttributedString>();
				NSMutableString str = astr.mutableString();
				astr.autorelease();
				
				DoRestoreEndian(str);
				
				switch (typeName.description())
				{
					case "Plain Text, UTF8 Encoded":
						// This is more like the default plain text type: when loading a document that is not
						// rtf or word or whatever this typename will be chosen via the plist. However the actual
						// encoding is inferred from the contents of the file (or set via the Get Info panel).
						data = str.dataUsingEncoding_allowLossyConversion(m_encoding, true);
						break;
					
					case "Plain Text, UTF16 Encoded":
						// This case is only used when the user selects save as and then the utf16 encoding.
						m_encoding = Enums.NSUTF16LittleEndianStringEncoding;
						data = str.dataUsingEncoding_allowLossyConversion(m_encoding, true);
						break;
					
					case "HTML":
						data = DoWriteWrapped(astr, Externs.NSHTMLTextDocumentType);
						break;
						
					case "Rich Text Format (RTF)":
						data = DoWriteWrapped(astr, Externs.NSRTFTextDocumentType);
						break;
						
					case "Word 97 Format (doc)":
						data = DoWriteWrapped(astr, Externs.NSDocFormatTextDocumentType);
						break;
						
					case "Word 2007 Format (docx)":
						data = DoWriteWrapped(astr, Externs.NSOfficeOpenXMLTextDocumentType);
						break;
						
					case "Open Document Text (odt)":
						data = DoWriteWrapped(astr, Externs.NSOpenDocumentTextDocumentType);
						break;
						
					default:
						Contract.Assert(false, "bad typeName: " + typeName.description());
						break;
				}
			}
			catch (Exception e)
			{
				Log.WriteLine(TraceLevel.Error, "App", "couldn't save:");
				Log.WriteLine(TraceLevel.Error, "App", "{0}", e);
				
				NSMutableDictionary userInfo = NSMutableDictionary.Create();
				userInfo.setObject_forKey(NSString.Create("Couldn't convert the document to NSData."), Externs.NSLocalizedDescriptionKey);
				userInfo.setObject_forKey(NSString.Create(e.Message), Externs.NSLocalizedFailureReasonErrorKey);
				
				NSObject error = NSError.errorWithDomain_code_userInfo(Externs.Cocoa3Domain, 1, userInfo);
				Marshal.WriteIntPtr(outError, error);
			}
			
			return data;
		}
Ejemplo n.º 4
0
        public void OnPathChanged()
        {
            if (Path != null || m_boss.Has<IDocumentExtension>())
                Language = DoFindLanguage();

            if (Path != null)
            {
                NSRect frame = WindowDatabase.GetFrame(Path);
                if (frame != NSRect.Empty)
                    window().setFrame_display(frame, true);		// note that Cocoa will ensure that windows with title bars are not moved off screen

                if (m_watcher != null)
                {
                    m_watcher.Dispose();
                    m_watcher = null;
                }

                if ((object) m_dir != null)
                {
                    m_dir.release();
                    m_dir = null;
                }

                var complete = m_boss.Get<IAutoComplete>();
                complete.OnPathChanged();

                string dir = System.IO.Path.GetDirectoryName(Path);
                m_dir = NSString.Create(dir).stringByResolvingSymlinksInPath().Retain();
                m_watcher = new DirectoryWatcher(m_dir.description(), TimeSpan.FromMilliseconds(250));
                m_watcher.Changed += this.DoDirChanged;

                if (m_restorer != null)
                    m_restorer.SetPath(Path);
            }
            else
                ((DeclarationsPopup) m_decPopup.Value).Init(this);
        }
Ejemplo n.º 5
0
        // Returns the (open) item which matches the specified path or null
        // if no item was found.
        public virtual TableItem Find(NSString path)
        {
            if (Paths.AreEqual(path.description(), Path))
                return this;

            return null;
        }