Beispiel #1
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
     }
 }