示例#1
0
        /// <summary>
        /// Saves the current text.
        /// </summary>
        private void SaveText()
        {
            string text = EditText;

            ProjectTextData data = new ProjectTextData();

            data.Lines = text.Split(new [] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                if (pluginFileLock == null)
                {
                    throw new Exception("Ack! We didn't get a lock!");
                }
                project.PutPluginData(pluginFileLock, this, savedDataId, writer => dataSerializer.Serialize(writer, data));
            }
            catch (Exception e)
            {
                MessageBox.Show($"Unable to save the text:\n{e.Message}", ProjectTextEditorPlugin.pluginName);
                return;
            }

            pluginFileLock.SendNotifications();
            lastSavedValue = text;
            textChanged    = false;
        }
        /// <summary>
        /// Saves the specified text to the Paratext settings directory.
        /// </summary>
        private void SaveText(string text)
        {
            StringWriter    writer = new StringWriter();
            ProjectTextData data   = new ProjectTextData();

            data.Lines = text.Split(new [] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            dataSerializer.Serialize(writer, data);
            if (!host.PutPlugInData(this, projectName, savedDataId, writer.ToString()))
            {
                MessageBox.Show("Unable to save the text. :(", pluginName);
            }
        }
        /// <summary>
        /// Gets any previously-saved text
        /// </summary>
        private string GetSavedText()
        {
            string text = host.GetPlugInData(this, projectName, savedDataId);

            if (text == null)
            {
                return(null);
            }
            StringReader    reader = new StringReader(text);
            ProjectTextData data   = (ProjectTextData)dataSerializer.Deserialize(reader);

            return(string.Join(Environment.NewLine, data.Lines));
        }
示例#4
0
        private void NewProjectOnProjectDataChanged(IProject sender, ProjectDataChangeType details)
        {
            Debug.Assert(pluginFileLock == null);
            Debug.Assert(sender == project);

            if (details != ProjectDataChangeType.WholeProject)
            {
                return;
            }

            pluginFileLock  = project.RequestWriteLock(this, DisposeLock, savedDataId);
            txtText.Enabled = pluginFileLock != null;

            label1.Text = string.Format((txtText.Enabled ? (string)label1.Tag : "{0} project is not editable."), project.ShortName);

            try
            {
                TextReader reader = project.GetPluginData(this, savedDataId);
                if (reader == null)
                {
                    EditText = "";
                    return;
                }

                using (reader)
                {
                    ProjectTextData data = (ProjectTextData)dataSerializer.Deserialize(reader);
                    EditText    = string.Join(Environment.NewLine, data.Lines);
                    textChanged = false;
                }
            }
            catch (Exception e)
            {
                EditText = "";
                MessageBox.Show($"Unable to load the text:\n{e.Message}", ProjectTextEditorPlugin.pluginName);
            }
        }