Esempio n. 1
0
        private void ShowAdd2Page()
        {
            CmisTreeStore cmisStore = new CmisTreeStore();

            Gtk.TreeView treeView = new Gtk.TreeView(cmisStore);

            bool firstRepo = true;
            List <RootFolder> repositories = new List <RootFolder>();
            Dictionary <string, AsyncNodeLoader> loader = new Dictionary <string, AsyncNodeLoader>();

            foreach (var repository in this.controller.repositories)
            {
                RootFolder root = new RootFolder()
                {
                    Name    = repository.Name,
                    Id      = repository.Id,
                    Address = this.controller.saved_address.ToString()
                };
                if (firstRepo)
                {
                    root.Selected = true;
                    firstRepo     = false;
                }
                else
                {
                    root.Selected = false;
                }

                repositories.Add(root);
                CmisRepoCredentials cred = new CmisRepoCredentials()
                {
                    UserName = this.controller.saved_user,
                    Password = this.controller.saved_password,
                    Address  = this.controller.saved_address,
                    RepoId   = repository.Id
                };
                AsyncNodeLoader asyncLoader = new AsyncNodeLoader(root, cred, PredefinedNodeLoader.LoadSubFolderDelegate, PredefinedNodeLoader.CheckSubFolderDelegate);
                asyncLoader.UpdateNodeEvent += delegate {
                    cmisStore.UpdateCmisTree(root);
                };
                cmisStore.UpdateCmisTree(root);
            }

            this.Header = Properties_Resources.Which;

            VBox layout_vertical = new VBox(false, 12);

            Button cancel_button = new Button(this.cancelText);

            cancel_button.Clicked += delegate {
                foreach (AsyncNodeLoader task in loader.Values)
                {
                    task.Cancel();
                }

                this.controller.PageCancelled();
            };

            Button continue_button = new Button(this.continueText)
            {
                Sensitive = repositories.Count > 0
            };

            continue_button.Clicked += delegate {
                RootFolder root = repositories.Find(x => (x.Selected != false));
                if (root != null)
                {
                    foreach (AsyncNodeLoader task in loader.Values)
                    {
                        task.Cancel();
                    }

                    this.controller.saved_repository = root.Id;
                    List <string> ignored  = NodeModelUtils.GetIgnoredFolder(root);
                    List <string> selected = NodeModelUtils.GetSelectedFolder(root);
                    this.controller.Add2PageCompleted(root.Id, root.Path, ignored.ToArray(), selected.ToArray());
                }
            };

            Button back_button = new Button(this.backText)
            {
                Sensitive = true
            };

            back_button.Clicked += delegate {
                foreach (AsyncNodeLoader task in loader.Values)
                {
                    task.Cancel();
                }

                this.controller.BackToPage1();
            };

            treeView.HeadersVisible = false;
            treeView.Selection.Mode = SelectionMode.Single;

            TreeViewColumn column = new TreeViewColumn();

            column.Title = "Name";
            CellRendererToggle renderToggle = new CellRendererToggle();

            column.PackStart(renderToggle, false);
            renderToggle.Activatable = true;
            column.AddAttribute(renderToggle, "active", (int)CmisTreeStore.Column.ColumnSelected);
            column.AddAttribute(renderToggle, "inconsistent", (int)CmisTreeStore.Column.ColumnSelectedThreeState);
            column.AddAttribute(renderToggle, "radio", (int)CmisTreeStore.Column.ColumnRoot);
            renderToggle.Toggled += delegate(object render, ToggledArgs args) {
                TreeIter iterToggled;
                if (!cmisStore.GetIterFromString(out iterToggled, args.Path))
                {
                    Console.WriteLine("Toggled GetIter Error " + args.Path);
                    return;
                }

                Node node = cmisStore.GetValue(iterToggled, (int)CmisTreeStore.Column.ColumnNode) as Node;
                if (node == null)
                {
                    Console.WriteLine("Toggled GetValue Error " + args.Path);
                    return;
                }

                RootFolder selectedRoot = repositories.Find(x => (x.Selected != false));
                Node       parent       = node;
                while (parent.Parent != null)
                {
                    parent = parent.Parent;
                }

                RootFolder root = parent as RootFolder;
                if (root != selectedRoot)
                {
                    selectedRoot.Selected = false;
                    cmisStore.UpdateCmisTree(selectedRoot);
                }

                if (node.Parent == null)
                {
                    node.Selected = true;
                }
                else
                {
                    node.Selected = !node.Selected;
                }

                cmisStore.UpdateCmisTree(root);
            };
            CellRendererText renderText = new CellRendererText();

            column.PackStart(renderText, false);
            column.SetAttributes(renderText, "text", (int)CmisTreeStore.Column.ColumnName);
            column.Expand = true;
            treeView.AppendColumn(column);

            treeView.RowExpanded += delegate(object o, RowExpandedArgs args) {
                Node node   = cmisStore.GetValue(args.Iter, (int)CmisTreeStore.Column.ColumnNode) as Node;
                Node parent = node;
                while (parent.Parent != null)
                {
                    parent = parent.Parent;
                }

                RootFolder root = parent as RootFolder;
                loader[root.Id].Load(node);
            };

            ScrolledWindow sw = new ScrolledWindow()
            {
                ShadowType = Gtk.ShadowType.In
            };

            sw.Add(treeView);

            layout_vertical.PackStart(new Label(string.Empty), false, false, 0);
            layout_vertical.PackStart(sw, true, true, 0);
            this.Add(layout_vertical);
            this.AddButton(back_button);
            this.AddButton(cancel_button);
            this.AddButton(continue_button);

            if (repositories.Count > 0)
            {
                continue_button.GrabDefault();
                continue_button.GrabFocus();
            }
            else
            {
                back_button.GrabDefault();
                back_button.GrabFocus();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create the UI
        /// </summary>
        private void CreateEdit()
        {
            CmisTreeStore cmisStore = new CmisTreeStore();

            Gtk.TreeView treeView = new Gtk.TreeView(cmisStore.CmisStore);

            RootFolder root = new RootFolder()
            {
                Name    = this.Name,
                Id      = credentials.RepoId,
                Address = credentials.Address.ToString()
            };

            IgnoredFolderLoader.AddIgnoredFolderToRootNode(root, Ignores);
            LocalFolderLoader.AddLocalFolderToRootNode(root, localPath);

            AsyncNodeLoader asyncLoader = new AsyncNodeLoader(root, credentials, PredefinedNodeLoader.LoadSubFolderDelegate, PredefinedNodeLoader.CheckSubFolderDelegate);

            asyncLoader.UpdateNodeEvent += delegate {
                cmisStore.UpdateCmisTree(root);
            };
            cmisStore.UpdateCmisTree(root);
            asyncLoader.Load(root);

            Header = CmisSync.Properties_Resources.EditTitle;

            VBox layout_vertical = new VBox(false, 12);

            Controller.CloseWindowEvent += delegate
            {
                asyncLoader.Cancel();
            };

            Button cancel_button = new Button(CmisSync.Properties_Resources.Cancel);

            cancel_button.Clicked += delegate {
                Close();
            };

            Button finish_button = new Button(CmisSync.Properties_Resources.SaveChanges);

            finish_button.Clicked += delegate {
                Ignores = NodeModelUtils.GetIgnoredFolder(root);
                Controller.SaveFolder();
                Close();
            };

            Gtk.TreeIter iter;
            treeView.HeadersVisible = false;
            treeView.Selection.Mode = SelectionMode.Single;

            TreeViewColumn column = new TreeViewColumn();

            column.Title = "Name";
            CellRendererToggle renderToggle = new CellRendererToggle();

            column.PackStart(renderToggle, false);
            renderToggle.Activatable = true;
            column.AddAttribute(renderToggle, "active", (int)CmisTreeStore.Column.ColumnSelected);
            column.AddAttribute(renderToggle, "inconsistent", (int)CmisTreeStore.Column.ColumnSelectedThreeState);
            column.AddAttribute(renderToggle, "radio", (int)CmisTreeStore.Column.ColumnRoot);
            renderToggle.Toggled += delegate(object render, ToggledArgs args) {
                TreeIter iterToggled;
                if (!cmisStore.CmisStore.GetIterFromString(out iterToggled, args.Path))
                {
                    Console.WriteLine("Toggled GetIter Error " + args.Path);
                    return;
                }

                Node node = cmisStore.CmisStore.GetValue(iterToggled, (int)CmisTreeStore.Column.ColumnNode) as Node;
                if (node == null)
                {
                    Console.WriteLine("Toggled GetValue Error " + args.Path);
                    return;
                }

                if (node.Parent == null)
                {
                    node.Selected = true;
                }
                else
                {
                    if (node.Selected == false)
                    {
                        node.Selected = true;
                    }
                    else
                    {
                        node.Selected = false;
                    }
                }
                cmisStore.UpdateCmisTree(root);
            };
            CellRendererText renderText = new CellRendererText();

            column.PackStart(renderText, false);
            column.SetAttributes(renderText, "text", (int)CmisTreeStore.Column.ColumnName);
            column.Expand = true;
            treeView.AppendColumn(column);

            treeView.AppendColumn("Status", new StatusCellRenderer(), "text", (int)CmisTreeStore.Column.ColumnStatus);

            treeView.RowExpanded += delegate(object o, RowExpandedArgs args) {
                Node node = cmisStore.CmisStore.GetValue(args.Iter, (int)CmisTreeStore.Column.ColumnNode) as Node;
                asyncLoader.Load(node);
            };

            ScrolledWindow sw = new ScrolledWindow()
            {
                ShadowType = Gtk.ShadowType.In
            };

            sw.Add(treeView);

            layout_vertical.PackStart(new Label(""), false, false, 0);
            layout_vertical.PackStart(sw, true, true, 0);
            Add(layout_vertical);
            AddButton(cancel_button);
            AddButton(finish_button);

            finish_button.GrabDefault();

            this.ShowAll();
        }