Esempio n. 1
0
 private void mMetadataListView_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (mMetadataListView.SelectedItems.Count == 0)
     {
         mView.Selection = null;
     }
     else
     {
         ListViewItem item = mMetadataListView.SelectedItems[0];
         if (item != null)
         {
             mView.Selection = new MetadataSelection((ObiNode)mView.Presentation.RootNode, this,
                                                     new MetadataItemSelection(item, MetadataEntryDescription.GetDAISYEntry(item.Text)));
         }
     }
 }
Esempio n. 2
0
        // Import metadata entries from the presentation
        private void ImportMetadata()
        {
            if (InvokeRequired)
            {
                Invoke(new ImportMetadataInvokation(ImportMetadata));
            }
            else
            {
                mMetadataListView.ItemChecked -= new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked);
                m_IsImportingMetadata          = true;
                mMetadataListView.Items.Clear();
                string[] nameContent = new string[2];
                List <urakawa.metadata.Metadata> items = mView.Presentation.Metadatas.ContentsAs_ListCopy;
                items.Sort(delegate(urakawa.metadata.Metadata a, urakawa.metadata.Metadata b)
                {
                    int names = a.NameContentAttribute.Name.CompareTo(b.NameContentAttribute.Name);
                    if (a.NameContentAttribute.Value != null && b.NameContentAttribute.Value != null)
                    {
                        return(names == 0 ? a.NameContentAttribute.Value.CompareTo(b.NameContentAttribute.Value) : names);
                    }
                    else
                    {
                        if (a.NameContentAttribute.Value == null)
                        {
                            a.NameContentAttribute.Value = Localizer.Message("Metadata_Empty");
                        }
                        if (b.NameContentAttribute.Value == null)
                        {
                            b.NameContentAttribute.Value = Localizer.Message("Metadata_Empty");
                        }
                        return(names);
                    }
                });

                // a list of metadata names which already exists
                // purpose is to compare addable items and prevent their addition to list if it is already there
                List <string> ExistingItemsList = new List <string>();

                foreach (urakawa.metadata.Metadata m in items)
                {
                    nameContent[0] = m.NameContentAttribute.Name;
                    nameContent[1] = m.NameContentAttribute.Value;
                    ListViewItem item = new ListViewItem(nameContent);
                    mMetadataListView.Items.Add(item);
                    item.Checked = true;
                    item.Tag     = m;

                    ExistingItemsList.Add(nameContent[0]);
                    MetadataEntryDescription metDes = MetadataEntryDescription.GetDAISYEntry(m.NameContentAttribute.Name);
                    if (metDes != null)
                    {
                        if (metDes.ReadOnly)
                        {
                            item.BackColor = SystemColors.InactiveCaption;
                        }
                    }
                }
                List <string> addables = mView.AddableMetadataNames;
                addables.Sort();
                addables.Add(Localizer.Message("metadata_custom"));
                foreach (string name in addables)
                {
                    if (!ExistingItemsList.Contains(name))
                    {
                        nameContent[0] = name;
                        nameContent[1] = "";
                        ListViewItem item = new ListViewItem(nameContent);
                        mMetadataListView.Items.Add(item);
                        item.Checked = false;
                        item.Tag     = null;
                        MetadataEntryDescription metDes = MetadataEntryDescription.GetDAISYEntry(name);
                        if (metDes != null)
                        {
                            if (metDes.ReadOnly)
                            {
                                item.BackColor = SystemColors.InactiveCaption;
                            }
                        }
                    }
                }
                m_IsImportingMetadata          = false;
                mMetadataListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked);
            }
        }
Esempio n. 3
0
 private void CommitValues()
 {
     if (mSelection != null && !String.IsNullOrEmpty(mNameTextbox.Text))
     {
         if (GetTextFromContentTextbox() != "")
         {
             string contentBoxText = GetTextFromContentTextbox();
             int    itemIndex      = 0;
             if (mMetadataListView.SelectedItems.Count > 0)
             {
                 itemIndex = mMetadataListView.SelectedItems[0].Index;
             }
             urakawa.metadata.Metadata entry = mSelection.Item.Entry;
             if (entry == null && mNameTextbox.Text != "")
             {
                 if (mMetadataListView.Items.Count > 0 && mMetadataListView.Items[itemIndex].Tag == null &&
                     CanAdd(MetadataEntryDescription.GetDAISYEntry(mNameTextbox.Text)))
                 {
                     entry = mView.AddMetadataEntry(mNameTextbox.Text);
                 }
                 else
                 {
                     return;
                 }
             }
             if (mSelection == null)
             {
                 return;
             }
             CompositeCommand command =
                 mView.Presentation.CreateCompositeCommand(Localizer.Message("modify_metadata_entry"));
             if (entry.NameContentAttribute.Name != mNameTextbox.Text)
             {
                 if (CanModify(mSelection.Item.Description, mNameTextbox.Text))
                 {
                     command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyName(mView, entry, mNameTextbox.Text));
                 }
                 else
                 {
                     MessageBox.Show(String.Format(Localizer.Message("metadata_name_error_text"), mNameTextbox.Text),
                                     Localizer.Message("metadata_name_error_caption"),
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                     mNameTextbox.Text = entry.NameContentAttribute.Name;
                 }
             }
             if (entry.NameContentAttribute.Value != contentBoxText)
             {
                 command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyContent(mView, entry, contentBoxText));
             }
             if (command.ChildCommands.Count > 0)
             {
                 mView.Presentation.UndoRedoManager.Execute(command);
             }
         }
         else
         {
             if (!IsDateMetadataSelected || string.IsNullOrEmpty(mContentTextbox.Text))
             {
                 MessageBox.Show(Localizer.Message("MetadataView_CannotCommitEmptyContent"), Localizer.Message("Caption_Error"));
             }
             mContentTextbox.Focus();
             if (mSelection != null && mSelection.Item.Entry == null &&
                 mMetadataListView.SelectedItems.Count > 0 && mMetadataListView.SelectedItems[0] != null && mMetadataListView.SelectedItems[0].Checked)
             {
                 mMetadataListView.SelectedItems[0].Checked = false;
             }
         }     // contentbox check ends
     }
 }
Esempio n. 4
0
        private void UpdateMetaDataListForItemAdd(MetadataEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateMetadataInvokation(UpdateMetaDataListForContentChange), e);
            }
            else
            {
                mMetadataListView.ItemChecked -= new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked);
                this.mMetadataListView.SelectedIndexChanged -= new System.EventHandler(this.mMetadataListView_SelectedIndexChanged);
                m_IsImportingMetadata = true;

                string[] nameContent = new string[2];
                List <urakawa.metadata.Metadata> items = mView.Presentation.Metadatas.ContentsAs_ListCopy;
                items.Sort(delegate(urakawa.metadata.Metadata a, urakawa.metadata.Metadata b)
                {
                    int names = a.NameContentAttribute.Name.CompareTo(b.NameContentAttribute.Name);
                    return(names == 0 && a.NameContentAttribute.Value != null && b.NameContentAttribute.Value != null
                        ? a.NameContentAttribute.Value.CompareTo(b.NameContentAttribute.Value)
                        : names);
                });
                string        itemToRemove      = "";
                List <string> ExistingItemsList = new List <string> ();
                int           i = 0;

                if (mMetadataListView.Items.Count == 0)
                {
                    return;
                }

                for (i = 0; i < items.Count; i++)
                {
                    string metaDataListString = mMetadataListView.Items[i].SubItems[0].Text;
                    string itemsListString    = items[i].NameContentAttribute.Name;

                    if (string.CompareOrdinal(metaDataListString, itemsListString) != 0)
                    {
                        itemToRemove = itemsListString;
                        urakawa.metadata.Metadata m = items[i];
                        nameContent[0] = m.NameContentAttribute.Name;
                        nameContent[1] = m.NameContentAttribute.Value;
                        ListViewItem item = new ListViewItem(nameContent);
                        mMetadataListView.Items.Insert(i, item);
                        item.Checked = true;
                        item.Tag     = m;
                        MetadataEntryDescription metDes = MetadataEntryDescription.GetDAISYEntry(m.NameContentAttribute.Name);
                        if (metDes != null)
                        {
                            if (metDes.ReadOnly)
                            {
                                item.BackColor = SystemColors.InactiveCaption;
                            }
                        }
                    }

                    ExistingItemsList.Add(itemsListString);
                }

                // remove only if metadata is not custom
                if (itemToRemove != Localizer.Message("metadata_custom"))
                {
                    // now search items below checked items and remove the item which we have just added above.
                    for (i = i; i < mMetadataListView.Items.Count; i++)
                    {
                        if (string.CompareOrdinal(itemToRemove, mMetadataListView.Items[i].SubItems[0].Text) == 0)
                        {
                            mMetadataListView.Items.RemoveAt(i);
                            break;
                        }
                    }
                }     // check for custom ends

                m_IsImportingMetadata = false;
                this.mMetadataListView.SelectedIndexChanged += new System.EventHandler(this.mMetadataListView_SelectedIndexChanged);
                mMetadataListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked);
            }
        }