TRVAControlPanel.OnCustomFileOperation

Top  Previous  Next

Occurs when the application needs to save or load a file in a custom format.

type

  TRVAFileOperation = (rvafoOpen, rvafoSave, rvafoExport, rvafoInsert);

  TRVCustomFileOperationEvent = procedure (Sender: TrvAction; Edit: TCustomRichViewEdit;

    const FileName: String; Operation: TRVAFileOperation;

    var SaveFormat: TrvFileSaveFilter;

    var CustomFilterIndex: Integer; var Success: Boolean) of object;

 

property OnCustomFileOperation: TRVCustomFileOperationEvent;

This event occurs when the following actions are executed:

TrvActionOpen (Operation=rvafoOpen)

TrvActionSave (Operation=rvafoSave)

TrvActionExport (Operation=rvafoExport)

TrvActionInsertFile (Operation=rvafoInsertFile)

FileName is a file name (full path) for opening/saving.

CustomFilterIndex is an index of custom format (in the CustomFilter property of the corresponding action), from 1.

For an opening operation, you can define a saving format in SaveFormat parameter (this format will be used for subsequent saving of document loaded from this file); you can also change CustomFilterIndex (on input, it corresponds to TrvActionOpen.CustomFilter; on output, it must correspond to TrvActionSaveAs.CustomFilter, if SaveFormat=ffeCustom). For all other operations, SaveFormat and output value of CustomFilterIndex are ignored.

Set Success to True if you loaded/saved file successfully.

See also:

TrvActionSave.SuppressNextErrorMessage

You can use LoadCSV function to implement an insertion of CSV files.

Example

By default, RichViewActions allows opening and saving HTML files only with rvHtmlViewImporter.

This example allows using rvHtmlImporter for this. Use it at your own risk, because a quality of rvHtmlImporter is not guaranteed.

First, assign CustomFilter property of TrvActionOpen and TrvActionSaveAs. You can do it at design time in the Object Inspector. But if you want to make it localizable, do it at run time in

the localization procedure (in the ActionTest project, do it in the procedure TForm3.Localize):

  rvActionsResource.rvActionOpen1.CustomFilter :=  RVA_GetS(rvam_flt_HTMLOpen);

  rvActionsResource.rvActionSaveAs1.CustomFilter :=  RVA_GetS(rvam_flt_HTMLOpen);

Make sure that ffiCustom is in TrvActionOpen.Filter, and ffeCustom is in TrvActionSaveAs.Filter.

Next, process RVAContolPanel.OnCustomFileOperation event:

procedure TForm3.RVAControlPanel1CustomFileOperation(Sender: TrvAction;

  Edit: TCustomRichViewEdit; const FileName: String;

  Operation: TRVAFileOperation; var SaveFormat: TrvFileSaveFilter;

  var CustomFilterIndex: Integer; var Success: Boolean);

var Stream: TFileStream;

    s: TRVRawByteString;

begin

  case Operation of

    rvafoOpen:

      begin

        try

          // This example assumes that there is only one custom open format,

          // so it does not check CustomFilterIndex (it must be 1)

          Stream := TFileStream.Create(FileName, fmOpenRead);

          try

            SetLength(s, Stream.Size);

            Stream.ReadBuffer(PRVAnsiChar(s)^, Length(s));

          finally

            Stream.Free;

          end;

          RvHtmlImporter1.RichView := Edit;

          RvHtmlImporter1.LoadHtml(s);

          // This example assumes that there is only one custom save format,

          // so it does not assign CustomFilterIndex and SaveFormat

          // (they are already 1 and ffeCustom correspondingly)

          Success := True;

        except;

          Success := False;

        end;

      end;

    rvafoSave:

      begin

          // This example assumes that there is only one custom save format,

          // so it does not check CustomFilterIndex (it must be 1)      

          Success := Edit.SaveHTML(FileName, rvActionsResource.rvActionExport1.FileTitle,

            rvActionsResource.rvActionExport1.ImagePrefix,

            rvActionsResource.rvActionExport1.SaveOptions+[rvsoOverrideImages]);

      end;

  end;

end;


RichViewActions © trichview.com