Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void windowWillClose(NSObject notification)
        {
            Broadcaster.Invoke("closing document window", m_boss);
            m_closed= true;

            if (Path != null)
            {
                // If the document has changes but is not being saved then we don't
                // want to persist this information because it will likely be wrong when
                // the old text is loaded.
                if (!document().isDocumentEdited())
                {
                    NSRect frame = window().frame();
                    int length = (int) m_textView.Value.string_().length();
                    NSPoint scrollers = m_scrollView.Value.contentView().bounds().origin;
                    NSRange selection = m_textView.Value.selectedRange();
                    WindowDatabase.Set(Path, frame, length, scrollers, selection, m_wordWrap);
                }

                if (Path.Contains("/var/") && Path.Contains("/-Tmp-/"))		// TODO: seems kind of fragile
                    DoDeleteFile(Path);
            }

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

            if (m_watcher != null)
            {
                m_watcher.Dispose();
                m_watcher.Changed -= this.DoDirChanged;
                m_watcher = null;
            }

            Broadcaster.Unregister(this);

            if (m_applier != null)
            {
                m_applier.Stop();
            }
            ((DeclarationsPopup) m_decPopup.Value).Stop();

            m_textView.Value.Call("onClosing:", this);

            // If the windows are closed very very quickly then if we don't do this
            // we get a crash when Cocoa tries to call our delegate.
            m_textView.Value.layoutManager().setDelegate(null);

            window().autorelease();
            NSApplication.sharedApplication().BeginInvoke(	// we only want to broadcast this once the window actually closed, but we don't get a notification for that...
                () => Broadcaster.Invoke("closed document window", m_boss), TimeSpan.FromMilliseconds(250));
            //			m_boss.Free();
        }