예제 #1
0
        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);
        }
예제 #2
0
        private bool DoReload(List<TableItem> added)
        {
            bool changed = false;

            // Get the current state of the folder.
            string[] paths = DoGetPaths();

            // Remove items not in paths.
            for (int i = m_children.Count - 1; i >= 0; --i)
            {
                if (!paths.Any(p => p == m_children[i].CanonicalPath))
                {
                    m_children[i].release();
                    m_children.RemoveAt(i);
                    changed = true;
                }
            }

            // Reload any existing items.
            foreach (TableItem item in m_children)
            {
                if (item.Reload(added))
                    changed = true;
            }

            // Add any items from paths that are missing.
            foreach (string path in paths)
            {
                if (!m_children.Any(c => c.CanonicalPath == path))
                {
                    TableItem item;
                    if (System.IO.File.Exists(path) || NSWorkspace.sharedWorkspace().isFilePackageAtPath(NSString.Create(path)))
                        item = new FileItem(path, Styler);
                    else
                        item = new FolderItem(path, Styler, m_controller);

                    m_children.Add(item);
                    if (added != null)
                        added.Add(item);

                    changed = true;
                }
            }

            // Sort them without using case and with packages treated as files.
            if (changed)
            {
                m_children.Sort((lhs, rhs) =>
                {
                    bool file1 = lhs is FileItem;
                    bool file2 = rhs is FileItem;

                    if (file1 && !file2)
                        return -1;
                    else if (!file1 && file2)
                        return +1;
                    else
                        return lhs.Path.ToLower().CompareTo(rhs.Path.ToLower());
                });
            }

            return changed;
        }
예제 #3
0
        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);
        }