コード例 #1
0
        private void SaveRequested(IPluginChildWindow sender)
        {
            if (m_writeLock == null)
            {
                m_writeLock = m_project.RequestWriteLock(this, ReleaseRequested, savedDataId);
            }
            if (m_writeLock == null)
            {
                MessageBox.Show("Cannot get write lock; aborting loading data");
                m_savedText      = "";
                m_currentText    = "";
                textBox.Text     = "";
                textBox.ReadOnly = true;
                return;
            }

            m_currentText = textBox.Text;
            ProjectTextData data = new ProjectTextData
            {
                Lines = m_currentText.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
            };

            try
            {
                m_project.PutPluginData(m_writeLock, this, savedDataId, writer => m_Serializer.Serialize(writer, data));
            }
            catch (Exception e)
            {
                MessageBox.Show($"Unable to save data:\n{e.Message}");
            }
            m_savedText = m_currentText;
        }
コード例 #2
0
        private void LoadSavedText()
        {
            if (m_project == null)
            {
                MessageBox.Show("Project not provided");
                m_savedText      = "";
                m_currentText    = "";
                textBox.Text     = "";
                textBox.ReadOnly = true;
            }
            else
            {
                if (m_writeLock == null)
                {
                    m_writeLock = m_project.RequestWriteLock(this, ReleaseRequested, savedDataId);
                }
                if (m_writeLock == null)
                {
                    MessageBox.Show("Cannot get write lock; aborting loading data");
                    m_savedText      = "";
                    m_currentText    = "";
                    textBox.Text     = "";
                    textBox.ReadOnly = true;
                    return;
                }

                TextReader reader = m_project.GetPluginData(this, savedDataId);
                if (reader != null)
                {
                    try
                    {
                        ProjectTextData data = (ProjectTextData)m_Serializer.Deserialize(reader);
                        m_savedText = string.Join(Environment.NewLine, data.Lines);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show($"Unable to load data:\n{e.Message}");
                        m_savedText = "";
                    }
                    reader.Close();
                }
                else
                {
                    // This is normal if there was no data previously saved,
                    // so don't bother with a MessageBox.
                    m_savedText = "";
                }
                m_currentText    = m_savedText;
                textBox.ReadOnly = false;
                textBox.Text     = m_currentText;
                textBox.Select(0, 0);
            }
        }