Beispiel #1
0
        /// <summary>
        /// Bring up Property Dialog in Add mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, System.EventArgs e)
        {
            using (PropertyDialog propDialog = new PropertyDialog(_currentNodeKind))
            {
                if (propDialog.ShowDialog(Context) != DialogResult.OK)
                {
                    return;
                }

                SvnPropertyValue value = propDialog.GetPropertyItem();
                if (value != null)
                {
                    PropertyEditItem pi;
                    if (!_propItems.TryGetValue(value.Key, out pi))
                    {
                        _propItems[value.Key] = pi = new PropertyEditItem(propListView, value.Key);
                    }

                    pi.Value = value;
                    pi.Refresh();

                    if (!propListView.Items.Contains(pi))
                    {
                        PopulateListView();
                    }

                    this.UpdateButtons();
                }
            }
        }
Beispiel #2
0
        private void UpdateButtons()
        {
            PropertyEditItem selection = null;

            if (this.propListView.SelectedItems.Count > 0)
            {
                selection = (PropertyEditItem)this.propListView.SelectedItems[0];
            }

            this.deleteButton.Enabled = selection != null && selection.Value != null;
            this.editButton.Enabled   = selection != null;
            this.revertButton.Enabled = selection != null && ((selection.Value != null) != (selection.BaseValue != null) || (selection.Value != null && !selection.Value.Equals(selection.BaseValue)));
        }
Beispiel #3
0
        /// <summary>
        /// Brings up the Property Dialog in edit mode.
        /// </summary>
        private void editButton_Click(object sender, System.EventArgs e)
        {
            PropertyEditItem item = (PropertyEditItem)this.propListView.SelectedItems[0];

            using (PropertyDialog pDialog = new PropertyDialog(item.Value, _currentNodeKind))
            {
                if (pDialog.ShowDialog(Context) != DialogResult.OK)
                {
                    return;
                }

                SvnPropertyValue value = pDialog.GetPropertyItem();
                if (value != null)
                {
                    if (value.Key != item.PropertyName)
                    {
                        item.Value = null; // Deleted
                        item.Refresh();

                        PropertyEditItem pi;

                        if (!_propItems.TryGetValue(value.Key, out pi))
                        {
                            _propItems[value.Key] = pi = new PropertyEditItem(propListView, value.Key);
                        }

                        pi.Value = value;

                        PopulateListView(); // Add new item
                    }
                    else
                    {
                        item.Value = value;
                        item.Refresh();
                    }
                }
                else
                {
                    item.Value = null;
                    if (item.BaseValue == null)
                    {
                        _propItems.Remove(item.PropertyName);
                        propListView.Items.Remove(item);
                    }
                    else
                    {
                        item.Refresh();
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Delete the selected item if delete-button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteButton_Click(object sender, System.EventArgs e)
        {
            PropertyEditItem item = (PropertyEditItem)this.propListView.SelectedItems[0];

            item.Value = null;
            if (item.BaseValue == null)
            {
                propListView.Items.Remove(item);
            }
            else
            {
                item.Refresh();
            }
            this.UpdateButtons();
        }
Beispiel #5
0
        /// <summary>
        /// Brings up the Property Dialog in edit mode.
        /// </summary>
        private void editButton_Click(object sender, System.EventArgs e)
        {
            PropertyEditItem item = (PropertyEditItem)this.propListView.SelectedItems[0];

            using (PropertyDialog pDialog = new PropertyDialog(item.Value, _currentNodeKind))
            {
                if (pDialog.ShowDialog(Context) != DialogResult.OK)
                    return;

                SvnPropertyValue value = pDialog.GetPropertyItem();
                if (value != null)
                {
                    if (value.Key != item.PropertyName)
                    {
                        item.Value = null; // Deleted
                        item.Refresh();

                        PropertyEditItem pi;

                        if (!_propItems.TryGetValue(value.Key, out pi))
                            _propItems[value.Key] = pi = new PropertyEditItem(propListView, value.Key);

                        pi.Value = value;

                        PopulateListView(); // Add new item
                    }
                    else
                    {
                        item.Value = value;
                        item.Refresh();
                    }
                }
                else
                {
                    item.Value = null;
                    if(item.BaseValue == null)
                    {
                        _propItems.Remove(item.PropertyName);
                        propListView.Items.Remove(item);
                    }
                    else
                        item.Refresh();
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Bring up Property Dialog in Add mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, System.EventArgs e)
        {
            using (PropertyDialog propDialog = new PropertyDialog(_currentNodeKind))
            {
                if (propDialog.ShowDialog(Context) != DialogResult.OK)
                    return;

                SvnPropertyValue value = propDialog.GetPropertyItem();
                if (value != null)
                {
                    PropertyEditItem pi;
                    if (!_propItems.TryGetValue(value.Key, out pi))
                        _propItems[value.Key] = pi = new PropertyEditItem(propListView, value.Key);

                    pi.Value = value;
                    pi.Refresh();

                    if (!propListView.Items.Contains(pi))
                        PopulateListView();

                    this.UpdateButtons();
                }
            }
        }
        public override void OnExecute(CommandEventArgs e)
        {
            SvnItem firstVersioned = null;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            switch (e.Command)
            {
                case AnkhCommand.ItemEditProperties:
                case AnkhCommand.ItemShowPropertyChanges:
                    foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
                    {
                        if (i.IsVersioned)
                        {
                            firstVersioned = i;
                            break;
                        }
                    }
                    break;
                case AnkhCommand.ProjectEditProperties: // use project folder
                    foreach (SvnProject p in e.Selection.GetSelectedProjects(false))
                    {
                        IProjectFileMapper pfm = e.GetService<IProjectFileMapper>();
                        if (pfm != null)
                        {
                            ISvnProjectInfo info = pfm.GetProjectInfo(p);
                            if (info != null && info.ProjectDirectory != null)
                            {
                                firstVersioned = cache[info.ProjectDirectory];
                            }
                            if (firstVersioned != null)
                            {
                                break;
                            }
                        }
                    }
                    break;
                case AnkhCommand.SolutionEditProperties: // use solution folder
                    IAnkhSolutionSettings solutionSettings = e.GetService<IAnkhSolutionSettings>();
                    if (solutionSettings != null)
                    {
                        firstVersioned = cache[solutionSettings.ProjectRoot];
                    }
                    break;
            }
            if (firstVersioned == null)
                return; // exceptional case

            //using (SvnClient client = e.GetService<ISvnClientPool>().GetNoUIClient())
            using (PropertyEditorDialog dialog = new PropertyEditorDialog(firstVersioned))
            {
                dialog.Context = e.Context;

                SortedList<string, PropertyEditItem> editItems = new SortedList<string, PropertyEditItem>();
                if (!e.GetService<IProgressRunner>().RunModal("Retrieving Properties",
                    delegate(object Sender, ProgressWorkerArgs wa)
                    {
                        // Retrieve base properties
                        wa.Client.PropertyList(new SvnPathTarget(firstVersioned.FullPath, SvnRevision.Base),
                            delegate(object s, SvnPropertyListEventArgs la)
                            {
                                foreach (SvnPropertyValue pv in la.Properties)
                                {
                                    PropertyEditItem ei;
                                    if (!editItems.TryGetValue(pv.Key, out ei))
                                        editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key));

                                    ei.BaseValue = pv;
                                }
                            });
                        //

                        wa.Client.PropertyList(firstVersioned.FullPath,
                            delegate(object s, SvnPropertyListEventArgs la)
                            {
                                foreach (SvnPropertyValue pv in la.Properties)
                                {
                                    PropertyEditItem ei;
                                    if (!editItems.TryGetValue(pv.Key, out ei))
                                        editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key));

                                    ei.OriginalValue = ei.Value = pv;
                                }
                            });

                    }).Succeeded)
                {
                    return; // Canceled
                }

                PropertyEditItem[] items = new PropertyEditItem[editItems.Count];
                editItems.Values.CopyTo(items, 0);
                dialog.PropertyValues = items;

                if (dialog.ShowDialog(e.Context) == DialogResult.OK)
                {
                    // Hack: Currently we save all properties, not only the in memory changed ones

                    items = dialog.PropertyValues;

                    bool hasChanges = false;
                    foreach (PropertyEditItem i in items)
                    {
                        if (i.ShouldPersist)
                        {
                            hasChanges = true;
                            break;
                        }
                    }

                    if (!hasChanges)
                        return;

                    e.GetService<IProgressRunner>().RunModal("Applying property changes",
                        delegate(object sender, ProgressWorkerArgs wa)
                        {
                            foreach (PropertyEditItem ei in items)
                            {
                                if (!ei.ShouldPersist)
                                    continue;

                                if (ei.Value == null)
                                {
                                    if (ei.OriginalValue != null)
                                        wa.Client.DeleteProperty(firstVersioned.FullPath, ei.PropertyName);
                                }
                                else if (!ei.Value.ValueEquals(ei.OriginalValue))
                                {
                                    if (ei.Value.StringValue != null)
                                        wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.StringValue);
                                    else
                                        wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.RawValue);
                                }
                            }
                        });

                } // if

            }
        }