Save vs Save As

1 Answer 22 Views
RichTextEditor
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Martin Hamilton asked on 12 Sep 2023, 05:17 PM

I'm capturing the event below

    Private Sub RadRichTextEditor1_CommandExecuting(sender As Object, e As Telerik.WinForms.Documents.RichTextBoxCommands.CommandExecutingEventArgs) Handles RadRichTextEditor1.CommandExecuting
        If TypeOf e.Command Is SaveCommand Then
            If e.CommandParameter = "pdf" Then
                'allow export to pdf
            Else
                e.Cancel = True

          End If
       End If

    End Sub

I was hoping to find

 If TypeOf e.Command Is SaveASCommand - but from what I can see, that doesn't exist.

The problem is - if the user clicks the Save Button or BackStage Save - I'm doing special processing to the database.

But if they click on Save As - It indicates that the user wants to 'export' the document to a pdf or to a word .docx

But in both cases - e.command is always SaveCommand.

It would have been nice to have a (1) SaveCommand and (2) SaveAsCommand

Anyway, is there any event that I can tap into so that these 2 methods can be dealt with differently?

I did add a handler for the SaveButton itself... and that works just fine.

AddHandler RichTextEditorRibbonBar1.QuickAccessToolBarItems(0).MouseDown, AddressOf SaveButton_MouseDown

Maybe you can show me how to create an addhandler for the BackStage Save Menu Option

And

For the BackStage SaveAs Menu Option

That would be of great help and probably solve my special handling needs.

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 13 Sep 2023, 10:58 AM

Hi Martin,

Thank you for the provided details.

You are right that there is no SaveAsCommand. However, if the Save button is pressed, the CommandParameter will be null. This way you could distinguish if the user is pressing the save button or using some of the save as document option buttons.

Private Sub RadRichTextEditor1_CommandExecuting(ByVal sender As Object, ByVal e As Telerik.WinForms.Documents.RichTextBoxCommands.CommandExecutingEventArgs)
    If TypeOf e.Command Is SaveCommand Then
        If e.CommandParameter Is Nothing Then
		' save button
        Else
		' save as button
        End If
    End If
End Sub

Another approach that I can suggest is to subscribe to the MouseDown events. For the Save Button in the backstage, you can use the following approach:

 Dim saveButton = TryCast(Me.richTextEditorRibbonBar1.BackstageControl.Items(4), BackstageButtonItem)
  AddHandler  saveButton.MouseDown, Addressoff  SaveButton_MouseDown

Now for the save as options, it is a little bit different. Here you can create a custom class that derives from RichTextEditorRibbonBar. Inside the custom class, you can access the buttons and subscribe to their MouseDown events.

Public Class CustomRichTextEditorRibbonBar
    Inherits RichTextEditorRibbonBar

    Protected Overrides Sub Initialize()
        MyBase.Initialize()
        Me.buttonSaveWord.MouseDown += AddressOf ButtonSaveWord_MouseDown
        Me.buttonSavePDF.MouseDown += AddressOf ButtonSavePDF_MouseDown
        Me.buttonSaveHTML.MouseDown += AddressOf ButtonSaveHTML_MouseDown
        Me.buttonSaveRich.MouseDown += AddressOf ButtonSaveRich_MouseDown
        Me.buttonSavePlain.MouseDown += AddressOf ButtonSavePlain_MouseDown
        Me.buttonXAML.MouseDown += AddressOf ButtonXAML_MouseDown
    End Sub

    Private Sub ButtonSavePDF_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub

    Private Sub ButtonSaveWord_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub

    Private Sub ButtonXAML_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub

    Private Sub ButtonSaveRich_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub

    Private Sub ButtonSavePlain_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub

    Private Sub ButtonSaveHTML_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    End Sub
End Class

You can now replace the RadRichTextEditorRibbonBar with the custom one.

I hope that I was able to cover your questions.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
RichTextEditor
Asked by
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or