/// <summary>Shows form to edit activated text message item.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void lvChildren_ItemActivate(object sender, EventArgs e)
        {
            ListViewItem lvi = textMessageListView.SelectedItems[0];
            TextMessage message = (TextMessage) lvi.Tag;
            string filePath = message.FilePath;
            NewEditMessage form = new NewEditMessage(message);

            if (form.ShowDialog(this) != DialogResult.Cancel) {
                ListViewItem lvi2 = new TextMessageListViewItem(form.Message);
                textMessageListView.Items.Insert(lvi.Index, lvi2);
                lvi.Remove();
                textMessageListView.Sort();
            }
        }
        /// <summary>Presents form to edit and then update the currently selected text message within the ListView.</summary>
        /// <returns>True, when changes are committed, false, otherwise.</returns>
        public bool EditTextMessage()
        {
            bool result = false;
            if (SelectedItems.Count > 0) {
                TextMessageListViewItem lvi = SelectedItems[0] as TextMessageListViewItem;
                TextMessage message = lvi.Message;
                string filePath = message.FilePath;
                NewEditMessage form = new NewEditMessage(message);

                if (form.ShowDialog(this) != DialogResult.Cancel) {
                    TextMessageListViewItem lvi2 = new TextMessageListViewItem(form.Message);
                    Items.Insert(lvi.Index, lvi2);
                    lvi.Remove();
                    Sort();
                    result = true;
                    AfterTextMessageItemUpdateEventArgs args = new AfterTextMessageItemUpdateEventArgs(lvi, lvi2);
                    OnAfterTextMessageItemUpdate(args);
                }
            }
            return result;
        }
Пример #3
0
        /// <summary>Presents form to create new text message and adds new text message to lvChildren.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            // as files are numbered from 0, lvChildren.Items.Count will give the next file number
            string fileNumber = lvChildren.Items.Count.ToString();
            MessageFolder messageFolder = (MessageFolder) tvParents.SelectedNode.Tag;
            string filePath = messageFolder.RetrievePath();
            MessageFormat format = messageFolder.RetrieveFormat();

            if (format == MessageFormat.Motorola) {
                fileNumber = fileNumber.PadLeft(4, '0');
            }
            string nextFile = MessageNameFormatAttribute.FileFormat(format).Replace("*", fileNumber);
            filePath += nextFile;
            NewEditMessage form = new NewEditMessage(filePath, format);
            if (form.ShowDialog(this) != DialogResult.Cancel) {
                //TODO: shouldn't(?) do this directly - should add to phone and trigger event to add message!
                ListViewItem lvi = new TextMessageListViewItem(form.Message);
                lvChildren.Items.Add(lvi);
                lvChildren.Sort();

                //add to cache
                string cacheKey = messageFolder.RetrievePath();
                List<ListViewItem> items = new List<ListViewItem>(messageCache[cacheKey]);
                items.Add(lvi);
                messageCache[cacheKey] = items.ToArray();
            }
        }