Example #1
0
        public override void Initialize(IApp app)
        {
            base.Initialize(app);
            contextMenu = new ContextMenuStrip();
            contextMenu.Items.Add("Close file", null, (o,e) => CloseDocument(lastNodeClick));
            contextMenu.Items.Add("Toggle document flag", null, (o,e) => ToggleFlag(lastNodeClick));
            MenuRenderer.ApplySkin(contextMenu);

            control = new OpenFilesControl();
            mainFolder = new TreeNode(App.EditorInfo(EditorFlags.Main).DisplayName.Remove("&")) { ImageKey = "Folder", SelectedImageKey = "Folder" };
            otherFolder = new TreeNode("Other Files") { ImageKey = "Folder", SelectedImageKey = "Folder" };
            flagFolder = new TreeNode("Flagged Files") { ImageKey = "Flag", SelectedImageKey = "Flag" };
            control.TreeView.Nodes.Add(mainFolder);
            control.TreeView.Nodes.Add(otherFolder);
            control.TreeView.Nodes.Add(flagFolder);

            App.GetService<IDocumentService>().DocumentAdded += (o,e) => AddDocumentNode(e.Document);
            App.GetService<IDocumentService>().DocumentRemoved += (o,e) => RemoveDocumentNode(e.Document);
            App.GetService<IDocumentService>().ActiveDocumentChanged += (o,e) => Refresh();
            Application.Idle += (o, e) =>
            {
                var sel = App.Document();
                ProcessTitles(sel, mainFolder.Nodes.OfType<TreeNode>());
                ProcessTitles(sel, otherFolder.Nodes.OfType<TreeNode>());
            };
            control.TreeView.NodeMouseClick += (o, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    var d = e.Node.Tag as Document;

                    if (d != null)
                        App.GetService<IDocumentService>().SetActiveDocument(d);
                }
                else if (e.Button == MouseButtons.Right)
                    lastNodeClick = e.Node;
            };
            control.TreeView.GotFocus += (o, e) =>
            {
                var node = FindDocumentNode(App.Document());

                if (node != null)
                {
                    node.EnsureVisible();
                    control.TreeView.SelectedNode = node;
                }
            };
            control.TreeView.DrawNode += TreeView_DrawNode;
            control.TreeView.DrawMode = TreeViewDrawMode.OwnerDrawText;
            control.Load += (o, e) => WalkDocuments();
        }
Example #2
0
        public override void Initialize(IApp app)
        {
            base.Initialize(app);
            contextMenu = new ContextMenuStrip();
            contextMenu.Items.Add("Close file", null, (o, e) => CloseDocument(lastNodeClick));
            contextMenu.Items.Add("Toggle document flag", null, (o, e) => ToggleFlag(lastNodeClick));
            MenuRenderer.ApplySkin(contextMenu);

            control    = new OpenFilesControl();
            mainFolder = new TreeNode(App.EditorInfo(EditorFlags.Main).DisplayName.Remove("&"))
            {
                ImageKey = "Folder", SelectedImageKey = "Folder"
            };
            otherFolder = new TreeNode("Other Files")
            {
                ImageKey = "Folder", SelectedImageKey = "Folder"
            };
            flagFolder = new TreeNode("Flagged Files")
            {
                ImageKey = "Flag", SelectedImageKey = "Flag"
            };
            control.TreeView.Nodes.Add(mainFolder);
            control.TreeView.Nodes.Add(otherFolder);
            control.TreeView.Nodes.Add(flagFolder);

            App.GetService <IDocumentService>().DocumentAdded         += (o, e) => AddDocumentNode(e.Document);
            App.GetService <IDocumentService>().DocumentRemoved       += (o, e) => RemoveDocumentNode(e.Document);
            App.GetService <IDocumentService>().ActiveDocumentChanged += (o, e) => Refresh();
            Application.Idle += (o, e) =>
            {
                var sel = App.Document();
                ProcessTitles(sel, mainFolder.Nodes.OfType <TreeNode>());
                ProcessTitles(sel, otherFolder.Nodes.OfType <TreeNode>());
            };
            control.TreeView.NodeMouseClick += (o, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    var d = e.Node.Tag as Document;

                    if (d != null)
                    {
                        App.GetService <IDocumentService>().SetActiveDocument(d);
                    }
                }
                else if (e.Button == MouseButtons.Right)
                {
                    lastNodeClick = e.Node;
                }
            };
            control.TreeView.GotFocus += (o, e) =>
            {
                var node = FindDocumentNode(App.Document());

                if (node != null)
                {
                    node.EnsureVisible();
                    control.TreeView.SelectedNode = node;
                }
            };
            control.TreeView.DrawNode += TreeView_DrawNode;
            control.TreeView.DrawMode  = TreeViewDrawMode.OwnerDrawText;
            control.Load += (o, e) => WalkDocuments();
        }