Esempio n. 1
0
        private void ResolveClicked(object sender, EventArgs e)
        {
            int index = m_NotesListBox.SelectedIndex;

            if (index < 0)              // Nothing selected
            {
                MessageBox.Show("Select a note first.");
                return;
            }
            var note = m_noteList[index];

            if (note.IsResolved == false)
            {
                IWriteLock writeLock = m_project.RequestWriteLock(
                    this,
                    WriteLockReleaseRequested,
                    WriteLockScope.ProjectNotes);
                if (writeLock == null)
                {
                    MessageBox.Show("Can't get a write lock");
                }
                else
                {
                    note.Resolve(writeLock);
                    writeLock.Dispose();
                    UpdateNotesList();
                }
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
 private void ObtainLock()
 {
     if (pluginFileLock == null && project != null)
     {
         pluginFileLock = project.RequestWriteLock(this, DisposeLock, savedDataId);
     }
 }
Esempio n. 4
0
 protected override void OnHandleDestroyed(EventArgs e)
 {
     pluginFileLock?.Dispose();
     pluginFileLock = null;
     lastSavedValue = null;
     base.OnHandleDestroyed(e);
 }
Esempio n. 5
0
        private void AddNewNote(object sender, EventArgs e)
        {
            AddNoteDialog dialog = new AddNoteDialog(m_project);

            dialog.Verse = m_verseRef;
            dialog.ShowDialog();
            if (dialog.DialogResult == DialogResult.OK)
            {
                if (dialog.m_comment.Lines.Length == 0)
                {
                    MessageBox.Show("Comment cannot be empty");
                }
                else
                {
                    IWriteLock writeLock = m_project.RequestWriteLock(
                        this,
                        WriteLockReleaseRequested,
                        WriteLockScope.ProjectNotes);

                    if (writeLock == null)
                    {
                        MessageBox.Show("Can't get a write lock");
                    }
                    else
                    {
                        string text = dialog.SelectedText;
                        IScriptureTextSelection anchor = null;
                        if (string.IsNullOrEmpty(text))
                        {
                            anchor = m_project.GetScriptureSelectionForVerse(dialog.Verse);
                        }
                        else
                        {
                            IReadOnlyList <IScriptureTextSelection> anchors;
                            anchors = m_project.FindMatchingScriptureSelections(dialog.Verse, text, wholeWord: dialog.WholeWord);
                            if (anchors.Count != 0)
                            {
                                anchor = anchors[0];
                            }
                        }
                        if (anchor == null)
                        {
                            MessageBox.Show("Nothing matches selection");
                        }
                        else
                        {
                            List <CommentParagraph> paragraphs = FormParagraphs(dialog.m_comment.Lines);

                            IUserInfo assignee = dialog.Assignee;

                            m_project.AddNote(writeLock, anchor, paragraphs, assignedUser: assignee);
                        }
                        writeLock.Dispose();
                    }
                }
                UpdateNotesList();
            }
            dialog.Dispose();
        }
Esempio n. 6
0
 public ControlF()
 {
     InitializeComponent();
     m_currentText = null;
     m_savedText   = null;
     m_writeLock   = null;
     m_project     = null;
 }
Esempio n. 7
0
        private void DisposeLock(IWriteLock lockToDispose)
        {
            Debug.Assert(lockToDispose == pluginFileLock);

            PromptAndSave();
            pluginFileLock?.Dispose();
            pluginFileLock = null;
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
 private void Unlock()
 {
     chapterText.Text = "";
     chapterText.BringToFront();
     changedCheckBox.Checked = false;
     if (m_WriteLock != null)
     {
         IWriteLock temp = m_WriteLock;
         temp.Dispose();
         m_WriteLock = null;
     }
     lockedCheckBox.Checked = false;
     EnableRadioButtons();
 }
Esempio n. 10
0
        private void UpdateProject(IProject newProject)
        {
            if (project != null)
            {
                PromptAndSave();
                newProject.ProjectDataChanged -= NewProjectOnProjectDataChanged;
            }

            project = newProject;
            pluginFileLock?.Dispose();
            pluginFileLock = null;
            newProject.ProjectDataChanged += NewProjectOnProjectDataChanged;

            NewProjectOnProjectDataChanged(newProject, ProjectDataChangeType.WholeProject);
        }
Esempio n. 11
0
        public void GetScripture(object sender, EventArgs e)
        {
            if (m_project == null)
            {
                MessageBox.Show("No project selected");
                return;
            }

            if (m_WriteLock != null)
            {
                MessageBox.Show("'Quit' to release current lock before getting more Scripture");
                return;
            }

            lockedCheckBox.Checked = true;

            if (UsfmRadioButton.Checked)
            {
                m_WriteLock      = m_project.RequestWriteLock(this, ReleaseRequested, m_Reference.BookNum, m_Reference.ChapterNum);
                chapterText.Text = m_project.GetUSFM(m_Reference.BookNum, m_Reference.ChapterNum);
                chapterText.BringToFront();
            }
            else if (UsfmTokensRadioButton.Checked)
            {
                m_WriteLock = m_project.RequestWriteLock(this, ReleaseRequested, m_Reference.BookNum, m_Reference.ChapterNum);
                IEnumerable <IUSFMToken> tokens = m_project.GetUSFMTokens(m_Reference.BookNum, m_Reference.ChapterNum);
                GetUsfmTokens(tokens);
            }
            else             // UsxRadioButton.Checked
            {
                m_WriteLock      = m_project.RequestWriteLock(this, ReleaseRequested, m_Reference.BookNum);
                chapterText.Text = m_project.GetUSX(m_Reference.BookNum);
                chapterText.BringToFront();
            }

            if (m_WriteLock == null)
            {
                Unlock();
                MessageBox.Show("Unable to get a Write Lock");
                EnableRadioButtons();
            }
            else
            {
                DisableRadioButtons();
            }

            changedCheckBox.Checked = false;
        }
Esempio n. 12
0
        private void PromptSaveAndDispose(IPluginChildWindow sender)
        {
            if (textBox.Text != m_savedText)
            {
                var response = MessageBox.Show("Save changed data?", "Plugin F", MessageBoxButtons.YesNo);
                if (response == DialogResult.Yes)
                {
                    SaveRequested(sender);
                }
            }

            if (m_writeLock != null)
            {
                m_writeLock.Dispose();
                m_writeLock = null;
            }
        }
Esempio n. 13
0
        private void OnAddComment(object sender, EventArgs e)
        {
            AddCommentDialog dialog = new AddCommentDialog(m_project);

            dialog.ShowDialog();
            if (dialog.DialogResult == DialogResult.OK)
            {
                if (dialog.m_comment.Lines.Length == 0)
                {
                    MessageBox.Show("Comment cannot be empty");
                }
                else
                {
                    List <CommentParagraph> paragraphs = FormParagraphs(dialog.m_comment.Lines);
                    IWriteLock writeLock = m_project.RequestWriteLock(
                        this,
                        WriteLockReleaseRequested,
                        WriteLockScope.ProjectNotes);
                    if (writeLock == null)
                    {
                        MessageBox.Show("Can't get a write lock");
                    }
                    else
                    {
                        int       index    = m_NotesListBox.SelectedIndex;
                        var       note     = m_noteList[index];
                        IUserInfo assignee = dialog.Assignee;

                        note.AddNewComment(writeLock, paragraphs, assignedUser: assignee);

                        writeLock.Dispose();
                    }
                }
                RefreshNoteList();
                UpdateNoteDisplay();
            }

            dialog.Dispose();
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
        public override void DoLoad(IProgressInfo progressInfo)
        {
            // Actually do the load:
            // Since DoLoad is done on a different thread than what was used
            // to create the control, we need to use the Invoke method.
            Invoke((Action)(() => LoadSavedText()));

            // Illustrate use of progressInfo
            const int MAX_TIME = 100;

            progressInfo.Initialize("Loading Reference F", MAX_TIME);
            for (int i = 0; i < MAX_TIME; i++)
            {
                if (progressInfo.CancelRequested)
                {
                    m_writeLock.Dispose();
                    m_writeLock      = null;
                    textBox.Text     = "";
                    textBox.ReadOnly = true;
                }
                Thread.Sleep(20);
                progressInfo.Value = i;
            }
        }
Esempio n. 16
0
        public override void OnAddedToParent(IPluginChildWindow parent, IWindowPluginHost host, string state)
        {
            parent.SetTitle(PluginI.pluginName);

            SetProject(parent.CurrentState.Project);
            m_Reference        = parent.CurrentState.VerseRef;
            chapterText.Text   = "Click 'Get Chapter'";
            bookName.Text      = m_Reference.BookCode;
            chapterNumber.Text = m_Reference.ChapterNum.ToString();
            chapterText.Text   = "";
            chapterText.BringToFront();
            changedCheckBox.Checked = false;
            EnableRadioButtons();
            UsfmRadioButton.Checked       = true;
            UsfmTokensRadioButton.Checked = false;
            UsxRadioButton.Checked        = false;
            m_WriteLock            = null;
            lockedCheckBox.Checked = false;

            parent.VerseRefChanged += ReferenceChanged;
            parent.WindowClosing   += WindowClosing;
            parent.SaveRequested   += SaveRequested;
            parent.ProjectChanged  += ProjectChanged;
        }
Esempio n. 17
0
 internal bool IsValid(IWriteLock state)
 => ReferenceEquals(this.state, state) && state.Version == version;
Esempio n. 18
0
 private void ReleaseRequested(IWriteLock writeLock)
 {
     writeLock.Dispose();
     m_writeLock      = null;
     textBox.ReadOnly = true;
 }
Esempio n. 19
0
 public ControlI()
 {
     InitializeComponent();
     m_WriteLock = null;
 }
Esempio n. 20
0
 private void WriteLockReleaseRequested(IWriteLock obj)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 internal WriteLockToken(IWriteLock state)
 {
     this.state = state;
     version    = state.Version;
 }
Esempio n. 22
0
 private void ReleaseRequested(IWriteLock writeLock)
 {
     PromptSaveAndUnlock();
 }