public DirectoryController(string path)
            : base(NSObject.AllocAndInitInstance("DirectoryController"))
        {
            m_boss = ObjectModel.Create("DirectoryEditor");
            m_path = path;
            m_dirStyler = new DirectoryItemStyler(path);

            Unused.Value = NSBundle.loadNibNamed_owner(NSString.Create("directory-editor"), this);
            m_table = new IBOutlet<NSOutlineView>(this, "table").Value;
            m_targets = new IBOutlet<NSPopUpButton>(this, "targets").Value;
            m_prefs = new IBOutlet<DirPrefsController>(this, "prefsController");

            m_name = System.IO.Path.GetFileName(path);
            window().setTitle(NSString.Create(m_name));
            Unused.Value = window().setFrameAutosaveName(NSString.Create(window().title().ToString() + " editor"));
            window().makeKeyAndOrderFront(this);

            m_table.setDoubleAction("doubleClicked:");
            m_table.setTarget(this);

            var wind = m_boss.Get<IWindow>();
            wind.Window = window();

            m_builder = new GenericBuilder(path);

            m_targets.removeAllItems();
            if (m_builder.CanBuild)
            {
                var handler = m_boss.Get<IMenuHandler>();
                handler.Register(this, 50, this.DoBuild, this.DoBuildEnabled);
                handler.Register(this, 51, this.DoBuildVariables, this.DoHaveBuilder);
                handler.Register(this, 52, this.DoBuildFlags, this.DoHaveBuilder);
                handler.Register(this, 599, () => m_builder.Cancel(), this.DoCancelEnabled);
                handler.Register(this, 1000, this.DoShowPrefs);

                DoLoadPrefs(path);
                Broadcaster.Register("global ignores changed", this);
                Broadcaster.Register("finished building", this);
                DoUpdateTargets(string.Empty, null);
            }
            else
                DoLoadPrefs(path);

            m_root = new FolderItem(m_path, m_dirStyler, this);
            m_table.reloadData();

            m_watcher = DoCreateWatcher(path);
            if (m_watcher != null)
                m_watcher.Changed += this.DoDirChanged;

            //			m_watcher = new FileSystemWatcher(path);
            //			m_watcher.IncludeSubdirectories = true;
            //			m_watcher.Created += this.DoDirChanged;
            //			m_watcher.Deleted += this.DoDirChanged;
            //			m_watcher.Renamed += this.DoDirChanged;

            foreach (IOpened open in m_boss.GetRepeated<IOpened>())
            {
                open.Opened();
            }
            Broadcaster.Invoke("opened directory", m_boss);

            ActiveObjects.Add(this);
        }
        public void windowWillClose(NSObject notification)
        {
            var handler = m_boss.Get<IMenuHandler>();
            handler.Deregister(this);

            Broadcaster.Invoke("closing directory", m_boss);
            Broadcaster.Unregister(this);

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

            if (m_root != null)
            {
                var root = m_root;
                m_root = null;

                m_table.setDelegate(null);
                m_table.setTarget(null);
                m_table.setDataSource(null);
            //				m_table.reloadData();
                root.release();
            }

            m_builder = null;

            window().autorelease();
            autorelease();
            Broadcaster.Invoke("closed directory", m_boss);
        }