Opening a Document

Usage of the framework, compiler and tools

Opening a Document

Postby Robert » Mon May 25, 2015 9:55 am

I have some code that (roughly - this is probably not a compilable example) does:

VAR
text: TextModels.Model;
view: TextViews.View;
BEGIN
Create text ...
view := TextViews.dir.New(text);
Views.OpenView(view);


What I would like to do is have this opened in landscape mode, A4, with 2 cm margins, and with the Document width set to the page width.

I know how to use the GUI tools to do all this, but would like the program to do it for me.

Can anyone advise how to do this?

Cheers

Robert
Last edited by Robert on Tue May 26, 2015 10:18 am, edited 1 time in total.
User avatar
Robert
 
Posts: 108
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Opening a Document

Postby manumart1 » Tue May 26, 2015 6:39 am

I use this piece of code to open a window that shows a text (document) so that document's width is equal to window's width:
Code: Select all
md: TextModels.Model;
vw: TextViews.View;
cr: Containers.Controller;
prop: Properties.BoundsPref;

vw := TextViews.dir.New(md);
cr := vw.ThisController();
cr.SetOpts(cr.opts + {Containers.noCaret});
prop.w := Views.undefined; prop.h := Views.undefined; Views.HandlePropMsg(vw, prop);
Views.OpenAux(Documents.dir.New(vw, prop.w + 10 * Ports.mm, prop.h), 'Search result')

Perhaps you can try something similar.

Regards,
Manuel
manumart1
 
Posts: 66
Joined: Tue Sep 17, 2013 6:25 am

Re: Opening a Document

Postby Robert » Tue May 26, 2015 2:13 pm

[quote="manumart1"]Perhaps you can try something similar./quote]

Thanks for the suggestions.

Two difficulties are:

1 - Some of the required Modules are completely undocumented

2 - Lack of orthogonality. OpenAux takes a "title" parameter but OpenView does not.

The code below (after a LOT of trial and error) seems to do what I wanted.


Code: Select all
 CONST
    margin  =  20 * Ports.mm;
  VAR
    text              :  TextModels.Model;
    view              :  TextViews.View;
    doc               :  Documents.Document;
    w, h, l, t, r, b  :  INTEGER;
    decorate          :  BOOLEAN;
    win               :  Windows.Window;
  BEGIN
    text  :=  ...;
    view  :=  TextViews.dir.New (text);
    doc   :=  Documents.dir.New (view, Views.undefined, Views.undefined);
    doc.PollPage (w, h, l, t, r, b, decorate);
    IF  w  <  h  THEN
      I.Swap (w, h);
      doc.SetPage (w, h, margin, margin, w - margin, h - margin, decorate)
    END;
    Views.OpenView (doc);

    win  :=  Windows.dir.First ();
    LOOP
      IF  win  =  NIL  THEN  EXIT  END;
      IF  win.doc  =  doc  THEN  win.SetTitle ('My Title'); EXIT  END;
      win  :=  Windows.dir.Next (win)
    END



Regards

PS - How do you get the "Quote" tags to work properly?
User avatar
Robert
 
Posts: 108
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Opening a Document

Postby manumart1 » Tue May 26, 2015 6:49 pm

Robert wrote:...
PS - How do you get the "Quote" tags to work properly?

To reply you can push the button "Post reply" or "quote". In either case the editor is opened, but it is empty if "Post reply".
If you pushed "quote" then the entire message you wanted to quote is included in the editor area, surrounded by
Code: Select all
[quote="Robert"]
at the beginning and
Code: Select all
[/quote]
at the end. Then you can delete the lines you don't want, and write the post at the end.

In your case, you lost the "[" before "/quote]"
manumart1
 
Posts: 66
Joined: Tue Sep 17, 2013 6:25 am

Re: Opening a Document

Postby Robert » Tue May 26, 2015 7:24 pm

manumart1 wrote:In your case, you lost the "[" before "/quote]"


Magic!
User avatar
Robert
 
Posts: 108
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Opening a Document

Postby manumart1 » Wed May 27, 2015 7:15 am

Robert wrote:Lack of orthogonality. OpenAux takes a "title" parameter but OpenView does not.

Also, I noted a difference in the persistence of the model shown in the window (view) opened.
If I open a window via OpenView and modify some text, then when I try to close it I am asked to save the changes.
But if the window was opened via OpenAux I am not; supposedly because they are temporary or auxiliary data, only intended to be viewed.

Regards
manumart1
 
Posts: 66
Joined: Tue Sep 17, 2013 6:25 am


Return to Common questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron