private void EditSelectedGlyph( ) { if ((activeGlyphDatabase != null) && (glyphList.SelectedIndices.Count != 0)) { // get selected item and it glyph ... ListViewItem lvi = glyphList.SelectedItems[0]; Glyph glyph = (Glyph)activeGlyphDatabase[lvi.Text].Clone( ); glyphNameInEditor = glyph.Name; // ... and pass it to the glyph editting form EditGlyphForm glyphForm = new EditGlyphForm(glyph, activeGlyphDatabase.GetGlyphNames( )); glyphForm.Text = "Edit Glyph"; // set glyph data checking handler glyphForm.SetGlyphDataCheckingHandeler(new GlyphDataCheckingHandeler(CheckGlyphData)); if (glyphForm.ShowDialog( ) == DialogResult.OK) { try { // replace glyph in the database lock ( sync ) { activeGlyphDatabase.Replace(glyphNameInEditor, glyph); } lvi.Text = glyph.Name; // temporary remove icon from the list item lvi.ImageKey = null; // remove old icon and add new one glyphsImageList.Images.RemoveByKey(glyphNameInEditor); glyphsImageList.Images.Add(glyph.Name, CreateGlyphIcon(glyph)); // restore item's icon lvi.ImageKey = glyph.Name; } catch { ShowErrorBox(string.Format("A glyph with the name '{0}' already exists in the database.", glyph.Name)); } } } }
// Add new glyph to the active collection private void newGlyphToolStripMenuItem_Click(object sender, EventArgs e) { if (activeGlyphDatabase != null) { // create new glyph ... Glyph glyph = new Glyph(string.Empty, activeGlyphDatabase.Size); glyphNameInEditor = string.Empty; // ... and pass it the glyph editting form EditGlyphForm glyphForm = new EditGlyphForm(glyph, activeGlyphDatabase.GetGlyphNames( )); glyphForm.Text = "New Glyph"; // set glyph data checking handler glyphForm.SetGlyphDataCheckingHandeler(new GlyphDataCheckingHandeler(CheckGlyphData)); if (glyphForm.ShowDialog( ) == DialogResult.OK) { try { lock ( sync ) { // add glyph to active database activeGlyphDatabase.Add(glyph); } // create an icon for it glyphsImageList.Images.Add(glyph.Name, CreateGlyphIcon(glyph)); // add it to list view ListViewItem lvi = glyphList.Items.Add(glyph.Name); lvi.ImageKey = glyph.Name; } catch { ShowErrorBox(string.Format("A glyph with the name '{0}' already exists in the database.", glyph.Name)); } } } }
// Add new glyph to the active collection private void newGlyphToolStripMenuItem_Click( object sender, EventArgs e ) { if ( activeGlyphDatabase != null ) { // create new glyph ... Glyph glyph = new Glyph( string.Empty, activeGlyphDatabase.Size ); glyphNameInEditor = string.Empty; // ... and pass it the glyph editting form EditGlyphForm glyphForm = new EditGlyphForm( glyph, activeGlyphDatabase.GetGlyphNames( ) ); glyphForm.Text = "New Glyph"; // set glyph data checking handler glyphForm.SetGlyphDataCheckingHandeler( new GlyphDataCheckingHandeler( CheckGlyphData ) ); if ( glyphForm.ShowDialog( ) == DialogResult.OK ) { try { lock ( sync ) { // add glyph to active database activeGlyphDatabase.Add( glyph ); } // create an icon for it glyphsImageList.Images.Add( glyph.Name, CreateGlyphIcon( glyph ) ); // add it to list view ListViewItem lvi = glyphList.Items.Add( glyph.Name ); lvi.ImageKey = glyph.Name; } catch { ShowErrorBox( string.Format( "A glyph with the name '{0}' already exists in the database.", glyph.Name ) ); } } } }
private void EditSelectedGlyph( ) { if ( ( activeGlyphDatabase != null ) && ( glyphList.SelectedIndices.Count != 0 ) ) { // get selected item and it glyph ... ListViewItem lvi = glyphList.SelectedItems[0]; Glyph glyph = (Glyph) activeGlyphDatabase[lvi.Text].Clone( ); glyphNameInEditor = glyph.Name; // ... and pass it to the glyph editting form EditGlyphForm glyphForm = new EditGlyphForm( glyph, activeGlyphDatabase.GetGlyphNames( ) ); glyphForm.Text = "Edit Glyph"; // set glyph data checking handler glyphForm.SetGlyphDataCheckingHandeler( new GlyphDataCheckingHandeler( CheckGlyphData ) ); if ( glyphForm.ShowDialog( ) == DialogResult.OK ) { try { // replace glyph in the database lock ( sync ) { activeGlyphDatabase.Replace( glyphNameInEditor, glyph ); } lvi.Text = glyph.Name; // temporary remove icon from the list item lvi.ImageKey = null; // remove old icon and add new one glyphsImageList.Images.RemoveByKey( glyphNameInEditor ); glyphsImageList.Images.Add( glyph.Name, CreateGlyphIcon( glyph ) ); // restore item's icon lvi.ImageKey = glyph.Name; } catch { ShowErrorBox( string.Format( "A glyph with the name '{0}' already exists in the database.", glyph.Name ) ); } } } }