Ejemplo n.º 1
0
        public static Artist GetComposer(Artist defaultComposer)
        {
            ArtistSearch s = new ArtistSearch(ArtistSearch.Fields.FullName);

            s.AddTypeToSearch(ArtistSearch.TypeCategory.Composers);

            Inputbox ib = new Inputbox("Choose a composer: ", s.PerformSearchToScalar().ToArray(),
                                       defaultComposer != null ? defaultComposer.GetName(Artist.NameFormats.Last_First) : "",
                                       false);

            if (ib.ShowDialog() == DialogResult.Cancel)
            {
                return(null);
            }
            else
            {
                Artist a = new Artist(ib.SelectedItem.ToString(), "composer");
                return(a);
            }
        }
Ejemplo n.º 2
0
        public Browse()
        {
            InitializeComponent();

            status_reset_timer          = new Timer();
            status_reset_timer.Interval = 6000; // reset status message to "Ready" after 6 sec
            status_reset_timer.Tick    += (sender, e) =>
            {
                this.change_status("Ready", false);
                status_reset_timer.Enabled = false;
            };

            if (System.ComponentModel.LicenseManager.UsageMode ==
                System.ComponentModel.LicenseUsageMode.Runtime)
            {
                artistSearch = new ArtistSearch(ArtistSearch.Fields.ID,
                                                ArtistSearch.Fields.FullName,
                                                ArtistSearch.Fields.MatchName);
                artistSearch.AddTypeToSearch(ArtistSearch.TypeCategory.Composers);

                genreSearch = new GenreSearch(GenreSearch.Fields.ID, GenreSearch.Fields.Name);

                pieceSearch = new PieceSearch(PieceSearch.Fields.ID, PieceSearch.Fields.Name,
                                              PieceSearch.Fields.ParentPieceID);

                SupressUpdate = false;

                UpdateArtistList();
                UpdateGenreList();
                UpdatePieceList(false);
            }

            txbComposer.Focus();

            // hide the tabs of tabControlMode
            Rectangle rect = new Rectangle(tabPageSearch.Left, tabPageSearch.Top, tabPageSearch.Width, tabPageSearch.Height);

            tabControlMode.Region = new Region(rect);

            txbComposer.SetDefaultText(TextBoxDefaultAll);
            txbComposer.PopupWidth    = -1;
            txbComposer.ItemSelected += (sender, e) =>
            {
                UpdateGenreList();
                UpdatePieceList(false);

                if (txbComposer.SelectedItem != null)
                {
                    txbFilter.Focus();
                }
            };
            txbComposer.TextChanged += (sender, e) =>
            {
                SupressUpdate = true;
                txbGenre.ResetText();
                txbFilter.Text = TextBoxDefaultNone;
                SupressUpdate  = false;
            };
            txbComposer.KeyDown += (sender, e) =>
            {
                if (e.KeyData == Keys.Enter)
                {
                    if (txbComposer.SelectedItem != null || !txbComposer.HasText())
                    {
                        txbFilter.Focus();
                    }
                    else
                    {
                        if (AddNewComposer(txbComposer.Text)) // add new composer and set focus to dg if add is successful
                        {
                            dg.Focus();
                        }
                    }
                }
                else if (e.KeyData == Keys.F2 && txbComposer.HighlightedItem != null)
                {
                    //change_status(txbComposer.HighlightedValue.ToString() + txbComposer.HighlightedItem.ToString());
                    int id = int.Parse(txbComposer.HighlightedValue.ToString());
                    txbComposer.HideAutoCompleteList();
                    RenameComposer(id, "");
                }
                else if (e.KeyData == Keys.Delete && txbComposer.HighlightedItem != null)
                {
                    int id = int.Parse(txbComposer.HighlightedValue.ToString());
                    txbComposer.HideAutoCompleteList();
                    DeleteComposer(id);
                }
                else
                {
                    return;
                }

                e.Handled = true;
            };
            //txbComposer.LostFocus += new EventHandler(txb_LostFocus);

            txbGenre.SetDefaultText(TextBoxDefaultAll);
            txbGenre.PopupWidth = -1;
            //txbGenre.LostFocus += txb_LostFocus;
            txbGenre.ItemSelected += (sender, e) => UpdatePieceList(false);

            txbFilter.Text         = TextBoxDefaultNone;
            txbFilter.TextChanged += (sender, e) => UpdatePieceList(false);
            txbFilter.KeyDown     += txb_KeyDown;
            txbFilter.KeyDown     += (sender, e) =>
            {
                if (e.KeyData == Keys.Down)
                {
                    dg.Focus();
                }
            };
            txbFilter.Enter += (sender, e) => txbFilter.SelectAll();

            dg.Rows.Clear();
            dg.CellFormatting += (sender, e) =>
            {
                // highlight the fact that the control is not in focus
                e.CellStyle.SelectionBackColor = ((DataGridView)sender).Focused ?
                                                 SystemColors.Highlight : SystemColors.InactiveCaption;

                // highlight the pieces that are "derived" from other pieces (i.e. a transcription, etc.)
                e.CellStyle.ForeColor = (dg[2, e.RowIndex].Value == null) ?
                                        SystemColors.ControlText : Color.Gray;

                // highlight the cell in edit mode
                if (dg.IsCurrentCellInEditMode && dg.CurrentCell == dg[e.ColumnIndex, e.RowIndex])
                {
                    e.CellStyle.BackColor = CellInEditColor;
                }
            };
            dg.SortCompare += (sender, e) =>
            {
                // use natural sorting
                if (dg[1, e.RowIndex1].Value == null || dg[1, e.RowIndex2].Value == null)
                {
                    return;
                }
                e.SortResult = NaturalSortComparer.Default.Compare(dg[1, e.RowIndex1].Value.ToString(),
                                                                   dg[1, e.RowIndex2].Value.ToString());
                e.Handled = true;
            };
            dg.KeyDown += (sender, e) =>
            {
                if (e.KeyData == Keys.Up || e.KeyData == Keys.Down)
                {
                    IsScrolling = true; // don't fetch data if the user is scrolling fast
                }
                else if (e.KeyCode == Keys.Enter)
                {
                    e.Handled = true;

                    // move to next control
                    if (e.Shift)
                    {
                        tabControl.SelectedTab = tabControl.TabPages[2];
                        tabControl.Focus();
                    }
                    else
                    {
                        if (clbDetail.Items.Count != 0)
                        {
                            clbDetail.SelectedIndex = 0;
                        }
                        if (tabControl.SelectedTab == tabControl.TabPages[0] && clbDetail.Items.Count == 0)
                        {
                            tabControl.SelectedTab = tabControl.TabPages[1]; // goto text edit mode
                        }
                        tabControl.Focus();
                    }
                }
                else if (e.KeyData == Keys.Escape)
                {
                    txbFilter.Focus();
                }
                else if (e.KeyData == (Keys.Home))
                {
                    dg.ClearSelection();
                    dg.CurrentCell          = dg[1, 0];
                    dg.CurrentCell.Selected = true;
                }
                else if (e.KeyData == (Keys.End))
                {
                    dg.ClearSelection();
                    dg.CurrentCell          = dg[1, dg.RowCount - 1];
                    dg.CurrentCell.Selected = true;
                }
            };
            dg.KeyUp += (sender, e) =>
            {
                if (e.KeyData == Keys.Up || e.KeyData == Keys.Down)
                {
                    // resume fetchting data after user stop fast scrolling
                    IsScrolling = false;

                    //force re-selection so that the SelectionChanged event will fire
                    dg.ClearSelection();
                    dg.Rows[dg.CurrentRow.Index].Selected = true;
                }
                else if (e.KeyData == (Keys.Alt | Keys.P))
                {
                    tabControl.SelectedTab = tabControl.TabPages[2];
                    dg.Focus();
                }
                else if (e.KeyData == (Keys.Alt | Keys.M))
                {
                    tabControl.SelectedTab = tabControl.TabPages[0];
                    dg.Focus();
                }
                else if (e.KeyData == (Keys.Control | Keys.E))
                {
                    //start text edit mode
                    tabControl.SelectedTab = tabControl.TabPages[1];
                    tabControl.Focus();
                }
                else if (e.KeyData == Keys.Delete)
                {
                    DeletePiece();
                }
            };
            dg.SelectionChanged += (sender, e) => { if (!IsScrolling)
                                                    {
                                                        UpdateDetail();
                                                    }
            };
            dg.GotFocus += (sender, e) =>
            {
                if (dg.SelectedRows.Count == 0) //auto select first row if nothing is already selected
                {
                    dg.Rows[0].Selected = true;
                }
            };
            dg.CellEndEdit += (sender, e) =>
            {
                dg.CurrentCell = dg[e.ColumnIndex, e.RowIndex];
                if (dg[0, e.RowIndex].Value == null && dg.CurrentCell.Value != null)
                {
                    if (!AddNewPiece(dg.CurrentCell.Value.ToString()))
                    {
                        dg.Rows.Remove(dg.Rows[dg.CurrentCell.RowIndex]);
                    }
                }
                else if (!dg.CurrentRow.IsNewRow)
                {
                    RenamePiece(dg.CurrentCell.Value.ToString());
                }
            };

            clbDetail.KeyDown              += new KeyEventHandler(clbDetail_KeyDown);
            clbDetail.LostFocus            += (sender, e) => clbDetail.ClearSelected();
            clbDetail.SelectedIndexChanged += (sender, e) =>
            {
                // show preview of how the formatted name is like on statusbar
                if (!DetailPaneVisible)
                {
                    return;                     // no need to update UI
                }
                if (clbDetail.SelectedIndex != -1 && currentPiece != null)
                {
                    change_status(currentPiece.FormatDetail(clbDetail.SelectedItem.ToString()));
                }
            };

            // don't focus on the tabs themselves
            tabControl.GotFocus    += (sender, e) => this.SelectNextControl(tabControl, true, true, true, true);
            tabControl.Deselecting += (sender, e) =>
            {
                if (e.TabPage == tabPageDetailEdit)
                {
                    if (string.IsNullOrEmpty(txbEdit.Text.Trim()) || ((currentPiece.Details != null &&
                                                                       string.Join("", currentPiece.Details) == string.Join("", txbEdit.Lines))))
                    {
                        return;
                    }
                    DialogResult ret = MessageBox.Show(
                        "Your changes have not been saved; you want to save the changes?",
                        "Confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                    switch (ret)
                    {
                    case DialogResult.Cancel:
                        e.Cancel = true;
                        txbEdit.Focus();
                        break;

                    case DialogResult.No:
                        UpdateDetail();
                        break;

                    case DialogResult.Yes:
                        ChangeDetail(txbEdit.Lines);
                        break;

                    default:
                        break;
                    }
                }
            };

            txbEdit.KeyDown += (sender, e) =>
            {
                if (e.KeyData == Keys.Escape)
                {
                    tabControl.SelectTab(0);
                }
                if (e.KeyData == (Keys.Control | Keys.Enter)) // submit changes and leave edit mode
                {
                    ChangeDetail(txbEdit.Lines);
                    tabControl.SelectTab(0);
                }
                if (e.KeyData == (Keys.Shift | Keys.Enter))
                {
                    ChangeDetail(txbEdit.Lines); // submit changes but not leaving edit mode
                }
            };

            txbEdit.PreviewKeyDown += (sender, e) =>
            {
                if (e.KeyData == (Keys.Shift | Keys.Enter) || e.KeyData == (Keys.Control | Keys.Enter))
                {
                    e.IsInputKey = false; //shift+enter and ctrl+enter is used for special purposes, not input...
                }
            };
            //txbEdit.GotFocus += (sender,e) => txbEdit.Lines = currentPiece.Details;

            pgrid.PropertyValueChanged += (sender, e) =>
            {
                change_status((e.OldValue != null ? e.OldValue.ToString() : "") + " => " + e.ChangedItem.Value.ToString());
                Array.ForEach <object>(pgrid.SelectedObjects, p => ((Piece)p).Commit());
                change_status("Properties updated");
            };
            ((ContainerControl)pgrid).Controls[2].PreviewKeyDown += (sender, e) =>
            {
                if (e.KeyData == Keys.Escape)
                {
                    dg.Focus();
                }
            };
        }