Question On "cmd.undo"

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Question On "cmd.undo"

Post by plgoldman » Tue Apr 17, 2018 6:32 pm

I have an "Undo" button on my UI which executes the "cmd.undo." With only one exception the button does exactly what I want it to do which is to simply "undo" the last executed command. The one exception is when the end user wants to undo a "cmd.document.splitPages."

Right now after the user clicks on the "Split Page" button in the UI the "click" routine splits the pages as desired by the user and then "resizes" each of the resultant page segments. As such, clicking on the "Undo" button after clicking on the "Split Page" button will only "un resize" the page segments generated by the "cmd.document.splitPages." The user then has to remember to click on the "Undo" button a second time to undo the split page command itself.

I assume that somewhere the SDK maintains a LIFO list of the executed commands which is accessed by the undo command. If this is the case, can this list be accessed via the SDK? Alternatively, is there a parameter for "cmd.document.splitPages" that would specify to resize the resultant page segments automatically? Or is there another approach to what I am trying to accomplish?

As always your help is appreciated.

Regards,
Paul

User avatar
Sasha - Tracker Dev Team
User
Posts: 4220
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Question On "cmd.undo"

Post by Sasha - Tracker Dev Team » Wed Apr 18, 2018 9:21 am

Hello Paul,
Right now after the user clicks on the "Split Page" button in the UI the "click" routine splits the pages as desired by the user and then "resizes" each of the resultant page segments.
You mean, that he first executes Split Pages command and then the Resize Pages command? If so, then the undo data would store two values, that can be only undone as Resize Pages first and the Split Pages afterwards.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Question On "cmd.undo"

Post by plgoldman » Wed Apr 18, 2018 10:19 am

HI Alex,

Let me clarify things. I have a button on the UI which says split pages. When the user clicks on that button the "click" routine which is executed first runs the "cmd.document.splitPages." After the user selects the desired split bars and hits OK, the program resumes execution in the "click" routine and executes a page resize operation on the page segments resulting from the split. See code below.

It is true that when the user then clicks the "Redo" button once the page resize operation will be undone and then when it is clicked again the page split operation will be undone. However, what I would like to do is have one click of the "Redo" button undo both the resize and the split operation. My thought was that if there was access available to the queue/stack that the last n operations were stored on, when the "Redo" button was clicked I could check to see if the last operation was a resize and if so, see if the operation before that was a page split. If both of those conditions were true, I could then programmatically issue the "cmd.undo" twice to undo the code executed by the "BtnSplit_Click" routine below.

Regards,
Paul

Code: Select all

private void BtnSplit_Click(object sender, RoutedEventArgs e)
        {
            Int16 initialPgCnt = Convert.ToInt16(pdfCtl.Doc.CoreDoc.Pages.Count);
            currPage = Convert.ToInt16(pdfCtl.CurrentPage);
            currPage++;

            EventMonitors.SplitPagesEventMonitor mySplitMonitor = new EventMonitors.SplitPagesEventMonitor(pdfCtl.Inst.Str2ID("DlgSplitPages"));
            uiInst.CurrentThreadCtx.RegisterEventMonitor(mySplitMonitor);
            pdfCtl.Inst.ExecUICmd("cmd.document.splitPages");
            uiInst.CurrentThreadCtx.UnregisterEventMonitor(mySplitMonitor);

            Int16 finalPgCnt = Convert.ToInt16(pdfCtl.Doc.CoreDoc.Pages.Count);

            if (initialPgCnt == finalPgCnt)
            {
                // No Split Was Made
                return;
            }

            Int16 lastPageSplit = Convert.ToInt16(currPage + (finalPgCnt - initialPgCnt));

            int nID = Inst.Str2ID("op.document.resizePages", false);
            PDFXEdit.IOperation Op = Inst.CreateOp(nID);
            PDFXEdit.ICabNode input = Op.Params.Root["Input"];
            input.v = pdfCtl.Doc;
            PDFXEdit.ICabNode options = Op.Params.Root["Options"];
            options["PaperType"].v = 1; //Standard values table
            options["StdPaperIndex"].v = 11; //Letter / ANSI A
            options["PagesRange.Type"].v = "Exact";
            options["PagesRange.Filter"].v = "All";
            options["PagesRange.Text"].v = currPage.ToString() + "-" + lastPageSplit.ToString();
            options["ScalePage"].v = true;
            Op.Do();

            FinalPageCount.Content = Convert.ToInt16(pdfCtl.Doc.CoreDoc.Pages.Count).ToString();

            List<Int16> pageCounts = new List<Int16>();
            foreach (KeyValuePair<string, List<Int16>> kvp in docPageCounts)
            {
                if (kvp.Key == pdfCtl.Doc.CoreDoc.SrcInfo.DispFileName)
                {
                    pageCounts.Add(kvp.Value[0]);
                    pageCounts.Add(Convert.ToInt16(kvp.Value[1] + (finalPgCnt - initialPgCnt)));
                    FinalPageCount.Content = pageCounts[1].ToString();
                    docPageCounts.Remove(pdfCtl.Doc.CoreDoc.SrcInfo.DispFileName);
                    docPageCounts.Add(pdfCtl.Doc.CoreDoc.SrcInfo.DispFileName, pageCounts);
                    break;
                }
            }
            InitialPageCount.Content = pageCounts[0].ToString();
            FinalPageCount.Content = pageCounts[1].ToString();
        }

User avatar
Sasha - Tracker Dev Team
User
Posts: 4220
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Question On "cmd.undo"

Post by Sasha - Tracker Dev Team » Thu Apr 19, 2018 6:32 am

Hello Paul,

Now I understand what you need. There is a functionality like that available:

Code: Select all

pdfCtl.Doc.OperationHistory.BeginMacro("My Operations Batch", "", "");
//All of the operations/commands executed here will be under one history (Undo/Redo) item
pdfCtl.Inst.ExecUICmd("cmd.document.insertEmptyPages");
pdfCtl.Inst.ExecUICmd("cmd.document.cropPages");
pdfCtl.Doc.OperationHistory.EndMacro();
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Question On "cmd.undo"

Post by plgoldman » Thu Apr 19, 2018 11:28 am

Hi Alex,

Thanks so much. That solution certainly made things easy.

Regards,
Paul

User avatar
Sasha - Tracker Dev Team
User
Posts: 4220
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Question On "cmd.undo"

Post by Sasha - Tracker Dev Team » Thu Apr 19, 2018 11:30 am

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

RMan
User
Posts: 172
Joined: Tue Jul 02, 2013 10:06 pm

Re: Question On "cmd.undo"

Post by RMan » Mon Aug 06, 2018 7:31 pm

Worked great for me also. Thanks so much!!!

User avatar
Sasha - Tracker Dev Team
User
Posts: 4220
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Question On "cmd.undo"

Post by Sasha - Tracker Dev Team » Tue Aug 07, 2018 5:32 am

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply