Пример #1
0
        private void InvokeEmbeddControlEndEditing(EmbeddControlEndEditingArgs args)
        {
            EmbeddControlEndEditingEvent editing = embeddControlEndEditing;

            if (editing != null)
            {
                editing(args);
            }
        }
Пример #2
0
        private void lvWorkspaces_EmbeddControlEndEditing(EmbeddControlEndEditingArgs args)
        {
            bool   isHintItem        = args.ControlItem.Tag == null;
            bool   convertToRealItem = false;
            string serverFolder;
            string localFolder;

            if (!args.Editing)
            {
                switch (args.Column)
                {
                case COLUMN_STATUS:
                {
                    serverFolder = (args.ControlItem.SubItems[COLUMN_SERVERFOLDER].Tag as TextBox).Text;
                    localFolder  = (args.ControlItem.SubItems[COLUMN_LOCALFOLDER].Tag as TextBox).Text;

                    convertToRealItem = (isHintItem &&
                                         (!string.IsNullOrEmpty(serverFolder) || !string.IsNullOrEmpty(localFolder)));

                    var cmb = args.EmbeddControl as ComboBox;
                    if (convertToRealItem)
                    {
                        args.ControlItem.SubItems[args.Column].Text = cmb.SelectedItem as string;
                    }

                    break;
                }

                case COLUMN_SERVERFOLDER:
                case COLUMN_LOCALFOLDER:
                {
                    var       pnl       = args.EmbeddControl as Panel;
                    Control[] controls  = pnl.Controls.Find("edit", false);
                    var       edit      = controls[0] as TextBox;
                    bool      textEmpty = string.IsNullOrEmpty(edit.Text);

                    if (!isHintItem || !textEmpty)
                    {
                        args.ControlItem.SubItems[args.Column].Text = edit.Text;
                    }

                    convertToRealItem = (isHintItem && !textEmpty);
                    break;
                }
                }

                string status = args.ControlItem.SubItems[COLUMN_STATUS].Text;
                serverFolder = args.ControlItem.SubItems[COLUMN_SERVERFOLDER].Text;
                localFolder  = args.ControlItem.SubItems[COLUMN_LOCALFOLDER].Text;

                // item with tag null is 'hint' item
                if (convertToRealItem)
                {
                    if (string.IsNullOrEmpty(localFolder))
                    {
                        string[] items = serverFolder.Split('/');
                        // $/FAST/Development/Main/Source
                        //LOCAL_FOLDER_SOURCEDIR
                        var part = new StringBuilder();
                        if (items.Length >= 3)
                        {
                            part.Append("\\");
                            for (int i = 2; i < items.Length; i++)
                            {
                                part.Append(items[i]);
                                if (i + 1 < items.Length)
                                {
                                    part.Append("\\");
                                }
                            }
                        }

                        localFolder = LOCAL_FOLDER_SOURCEDIR + part;
                        (args.ControlItem.SubItems[COLUMN_LOCALFOLDER].Tag as TextBox).Text = localFolder;
                        args.ControlItem.SubItems[COLUMN_LOCALFOLDER].Text = localFolder;
                    }

                    WorkspaceMappingType mappingType = (status.ToLower() == "active"
                        ? WorkspaceMappingType.Map : WorkspaceMappingType.Cloak);
                    IWorkspaceMapping mapping = this.definition.Workspace.AddMapping(serverFolder, localFolder,
                                                                                     mappingType);

                    args.ControlItem.UseItemStyleForSubItems = true;
                    args.ControlItem.SubItems[COLUMN_SERVERFOLDER].ForeColor =
                        Color.FromKnownColor(KnownColor.ControlText);

                    args.ControlItem.Tag = mapping;
                    AddItemToList(null, true);
                }

                if ((isHintItem && !convertToRealItem) &&
                    args.ControlItem.SubItems[COLUMN_STATUS].Text.ToLower() == "active")
                {
                    args.ControlItem.SubItems[COLUMN_STATUS].Text       = string.Empty;
                    args.ControlItem.SubItems[COLUMN_SERVERFOLDER].Text = HINT_ITEM_TEXT;
                }
            }
            else
            {
                if ((args.Column == COLUMN_SERVERFOLDER || args.Column == COLUMN_LOCALFOLDER))
                {
                    ListViewItem.ListViewSubItem subItemServerFolder = args.ControlItem.SubItems[COLUMN_SERVERFOLDER];
                    string editText = (subItemServerFolder.Tag as TextBox).Text;
                    if (subItemServerFolder.Text != string.Empty && editText == string.Empty)
                    {
                        subItemServerFolder.Text = string.Empty;
                    }

                    if (args.ControlItem.SubItems[COLUMN_STATUS].Text == string.Empty)
                    {
                        args.ControlItem.SubItems[COLUMN_STATUS].Text = "Active";
                    }
                }

                if (args.Column == COLUMN_STATUS && isHintItem)
                {
                    if (args.ControlItem.SubItems[COLUMN_STATUS].Text.ToLower() == "active")
                    {
                        args.ControlItem.SubItems[COLUMN_STATUS].Text = string.Empty;
                    }

                    args.ControlItem.SubItems[COLUMN_SERVERFOLDER].Text = HINT_ITEM_TEXT;
                }
            }
        }