Esempio n. 1
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // check for deleted source files from project file..
            for (int i = prj.Files.Count; i > 0; i--)
            {
                CodePortingTrackerSourceFile src = prj.Files[i - 1];
                bool bFound = false;

                // check if files are already part of project..
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    DataGridViewCellCollection cc = row.Cells;
                    if (cc["SrcPath"].Value.ToString() == src.Filename)
                    {
                        // update data accordingly
                        src.LineCount = (int)cc["LineCount"].Value;
                        src.LinesDone = (int)cc["LinesDone"].Value;
                        bFound = true;
                        break;
                    }
                }

                // in case the file was removed, remove it from the list..
                if (!bFound) prj.Files.Remove(src);
            }

            // Save current data..
            if (!sm.WriteXML(prj))
                MessageBox.Show("Project could not be saved!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {
                bPrjChangePending = false; // changes were saved, so no  more pending changes
                MessageBox.Show("Project saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Event fired by child form when source file changes
        /// </summary>
        public void SrcUpdated(CodePortingTrackerSourceFile src)
        {
            // update values with latest data..
            foreach (DataGridViewRow row in dgv.Rows)
            {
                DataGridViewCellCollection cc = row.Cells;

                if (cc["SrcPath"].Value.ToString() == src.Filename)
                {
                    // update data accordingly
                    cc["LineCount"].Value = src.LineCount;
                    cc["LinesDone"].Value = src.LinesDone;
                    cc["Completion"].Value = ProjectHelper.GetSrcFilePercentage(src.LineCount, src.LinesDone);
                    break;
                }
            }
        }
Esempio n. 3
0
        private void dgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if ((e.RowIndex < 0) || (e.ColumnIndex < 0)) // no selector or header
                return;

            string filename = dgv.Rows[e.RowIndex].Cells["SrcPath"].Value.ToString();

            // Check if form is already available
            foreach (SourceForm srcform in SrcForms)
            {
                if (srcform.Filename == filename) // Is form for this file open?
                {
                    srcform.Focus();
                    return;
                }
            }

            // search for the source file data to create new form..
            for (int i = prj.Files.Count; i > 0; i--)
            {
                CodePortingTrackerSourceFile src = prj.Files[i-1];
                if (src.Filename == filename)
                {
                    try
                    {
                        SourceForm form = new SourceForm(this, ref src);
                        form.MdiParent = MdiParent;
                        SrcForms.Add(form);
                        form.Show();
                    }
                    catch (Exception) { }
                    return;
                }
            }

            throw new Exception("Cannot open source file because of an error while parsing project file!");
        }
Esempio n. 4
0
        public SourceForm(ProjectForm projectform, ref CodePortingTrackerSourceFile srcdata)
        {
            PrjForm = projectform;
            src     = srcdata;

            InitializeComponent();
            openToolStripMenuItem.BackColor       = ConvertLineStateToColor(LineState.Open);
            inProgressToolStripMenuItem.BackColor = ConvertLineStateToColor(LineState.Progress);
            doneToolStripMenuItem.BackColor       = ConvertLineStateToColor(LineState.Done);
            SourceForm_SizeChanged(this, null);


            Text += " - " + System.IO.Path.GetFileName(Filename);

            // load, validate and update file data
            rtb.LoadFile(Filename, RichTextBoxStreamType.PlainText);
            if (src.LineCount == 0) // new files loaded the first time
            {
                src.LineCount = rtb.Lines.Length;
            }
            else if (src.LineCount != rtb.Lines.Length) // file changed?
            {
                DialogResult result = MessageBox.Show("The source file has changed in the meantime:" + Environment.NewLine +
                                                      "\"" + Filename + "\"" + Environment.NewLine +
                                                      "Do you want to continue working on the changed file?" + Environment.NewLine +
                                                      "OK = Accept new file (saved data may not match with new file)" + Environment.NewLine +
                                                      "Cancel = Abort loading the file", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    throw new Exception();
                }

                if (rtb.Lines.Length < src.LineCount) // lines were removed?
                {
                    src.LineCount = rtb.Lines.Length; // cut length

                    // Remove cut off blocks from list
                    BlockState DummyBlock = new BlockState();
                    DummyBlock.Line  = 0;
                    DummyBlock.Len   = 0;
                    DummyBlock.State = LineState.Unknown;;
                    InsertBlockState(DummyBlock);
                }
                else
                {
                    src.LineCount = rtb.Lines.Length;  // increase length
                }
            }

            // Load block data into rich text box..
            foreach (BlockState block in src.Blocks)
            {
                int LineStart = block.Line;
                int LineEnd   = block.Line + block.Len - 1;

                int SelectionStart  = rtb.GetFirstCharIndexFromLine(LineStart);
                int SelectionLength = rtb.GetFirstCharIndexFromLine(LineEnd) + rtb.Lines[LineEnd].Length - SelectionStart;
                rtb.Select(SelectionStart, SelectionLength);
                rtb.SelectionBackColor = ConvertLineStateToColor(block.State);
            }
            rtb.Select(0, 0);

            statusbar.Text = "File \"" + Filename + "\" loaded!";
        }