Ejemplo n.º 1
0
        private void Commit()
        {
            bool savedstate = internalchg;

            internalchg = true;

            try
            {
                wrapper.SynchronizeUserData();
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(pjse.Localization.GetString("errwritingfile"), ex);
            }

            btnCommit.Enabled = wrapper.Changed;

            int i = index;

            updateLists();

            internalchg = savedstate;

            setIndex((i >= lvTrcnItem.Items.Count) ? lvTrcnItem.Items.Count - 1 : i);
        }
Ejemplo n.º 2
0
        private void TRCNMaker()
        {
            bconPanel.Cursor          = Cursors.WaitCursor;
            Application.UseWaitCursor = true;
            try
            {
                int  minArgc = 0;
                Trcn trcn    = (Trcn)wrapper.SiblingResource(Trcn.Trcntype); // find Trcn for this Bcon

                wrapper.Package.BeginUpdate();

                if (trcn != null && trcn.TextOnly)
                {
                    // if it exists but is unreadable, as if user wants to overwrite
                    DialogResult dr = MessageBox.Show(
                        pjse.Localization.GetString("ml_overwriteduff")
                        , btnTRCNMaker.Text
                        , MessageBoxButtons.OKCancel
                        , MessageBoxIcon.Warning);
                    if (dr != DialogResult.OK)
                    {
                        return;
                    }
                    wrapper.Package.Remove(trcn.FileDescriptor);
                    trcn = null;
                }
                if (trcn != null)
                {
                    // if it exists ask if user wants to preserve content
                    DialogResult dr = MessageBox.Show(
                        pjse.Localization.GetString("ml_keeplabels")
                        , btnTRCNMaker.Text
                        , MessageBoxButtons.YesNoCancel
                        , MessageBoxIcon.Warning);
                    if (dr == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (!trcn.Package.Equals(wrapper.Package))
                    {
                        // Clone the original into this package
                        if (dr == DialogResult.Yes)
                        {
                            Wait.MaxProgress = trcn.Count;
                        }
                        SimPe.Interfaces.Files.IPackedFileDescriptor npfd = trcn.FileDescriptor.Clone();
                        Trcn ntrcn = new Trcn();
                        ntrcn.FileDescriptor = npfd;
                        wrapper.Package.Add(npfd, true);
                        ntrcn.ProcessData(npfd, wrapper.Package);
                        if (dr == DialogResult.Yes)
                        {
                            foreach (TrcnItem item in trcn)
                            {
                                ntrcn.Add(item); Wait.Progress++;
                            }
                        }
                        trcn = ntrcn;
                        trcn.SynchronizeUserData();
                        Wait.MaxProgress = 0;
                    }

                    if (dr == DialogResult.Yes)
                    {
                        minArgc = trcn.Count;
                    }
                    else
                    {
                        trcn.Clear();
                    }
                }
                else
                {
                    // create a new Trcn file
                    SimPe.Interfaces.Files.IPackedFileDescriptor npfd = wrapper.FileDescriptor.Clone();
                    trcn                = new Trcn();
                    npfd.Type           = Trcn.Trcntype;
                    trcn.FileDescriptor = npfd;
                    wrapper.Package.Add(npfd, true);
                    trcn.SynchronizeUserData();
                }

                Wait.MaxProgress = wrapper.Count - minArgc;
                trcn.FileName    = wrapper.FileName;

                for (int arg = minArgc; arg < wrapper.Count; arg++)
                {
                    trcn.Add(new TrcnItem(trcn));
                    trcn[arg].ConstId   = (uint)arg;
                    trcn[arg].ConstName = "Label " + arg.ToString();
                    trcn[arg].DefValue  = trcn[arg].MaxValue = trcn[arg].MinValue = 0;
                    Wait.Progress++;
                }
                trcn.SynchronizeUserData();
                wrapper.Package.EndUpdate();
            }
            finally
            {
                Wait.SubStop();
                bconPanel.Cursor          = Cursors.Default;
                Application.UseWaitCursor = false;
            }
            MessageBox.Show(
                pjse.Localization.GetString("ml_done")
                , btnTRCNMaker.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }