FileMenuActions.bas

 Attribute VB_Name = "FileMenuActions"
' This Function is specially written
' It will give you a fantastic output
' If you give the input to this function like Document.rtf
' It will return you only the Document i.e. name of the file
' without the extension (ignoring the .rtf)
' Mostly used by Microsoft in its Products

Public Function GetDocTitle(sFileName As String) As String
    If Not Len(sFileName) = 0 Then
        GetDocTitle = Left(sFileName, Len(sFileName) - 4)
    End If
End Function

Public Function NewDocument()
    Dim Reply As Integer
   
    With MainScr
        If .DocumentChange = True Then ' Document has been changed
            Reply = MsgBox("The current document named '" & .DocumentName & "' has been changed. Would you like to save these changes before starting a new document?", vbYesNoCancel + vbDefaultButton1 + vbQuestion, "XenonPad")
                If Reply = vbYes Then ' User pressed Yes button
                    With .CmDlg
                        .DialogTitle = "Save Document As..."
                        .Filter = "Rich Text Format (*.RTF)|*.rtf"
                        .ShowSave
                            If Len(.FileTitle) > 0 Then
                                MainScr.rtfText.SaveFile .FileName, rtfRTF
                                MainScr.DocumentChange = False
                                NewDocument
                            End If
                    End With
                ElseIf Reply = vbNo Then ' User pressed No button
                    .DocumentChange = False
                    NewDocument
                ElseIf Reply = vbCancel Then ' User pressed Cancel button
                    Exit Function
                End If
        Else ' Document wasn't changed
            .rtfText.Text = ""
            .rtfText.Tag = ""
            .Caption = "Untitled - XenonPad"
            .StatusBar.Panels(2).Text = "Untitled"
            RestoreWindow
            .DocumentName = "Untitled"
            .DocumentChange = False
        End If
    End With
End Function

Public Function OpenDocument()
    Dim Reply As Integer
   
    With MainScr
        If .DocumentChange = False Then
            With .CmDlg
                .DialogTitle = "Open Document..."
                .Filter = "Rich Text Format (*.RTF)|*.rtf"
                .ShowOpen
                    If Len(.FileTitle) > 0 Then
                        LoadFile .FileName, .FileTitle
                    End If
            End With
        Else
             With .CmDlg
                .DialogTitle = "Open Document..."
                .Filter = "Rich Text Format (*.RTF)|*.rtf"
                .ShowOpen
                    If Len(.FileTitle) > 0 Then
                        Reply = MsgBox("The current document named '" & MainScr.DocumentName & "' has been changed. Would you like to save these changes before opening an existing document?", vbYesNoCancel + vbDefaultButton1 + vbQuestion, "XenonPad")
                        If Reply = vbCancel Then
                            Cancel = True
                        ElseIf Reply = vbNo Then
                            LoadFile .FileName, .FileTitle
                        ElseIf Reply = vbYes Then
                            SaveFile
                            LoadFile .FileName, .FileTitle
                        End If
                    End If
            End With

        End If
    End With
End Function

Public Function LoadFile(sFileName As String, sFileTitle As String)
    With MainScr
        .rtfText.LoadFile sFileName, rtfRTF
        .rtfText.Tag = sFileName
        .Caption = GetDocTitle(sFileTitle) & " - XenonPad"
        .StatusBar.Panels(2).Text = GetDocTitle(sFileTitle)
        .DocumentName = .StatusBar.Panels(2).Text
        .DocumentChange = False
        FetchSel
    End With
End Function

Public Function SaveFile()
    With MainScr
        If Len(.rtfText.Tag) > 0 Then
            .rtfText.SaveFile .rtfText.Tag, rtfRTF
            .DocumentChange = False
        Else
            With .CmDlg
                .DialogTitle = "Save Document..."
                .Filter = "Rich Text Format (*.RTF)|*.rtf"
                .ShowSave
                    If Len(.FileTitle) > 0 Then
                        MainScr.rtfText.SaveFile .FileName, rtfRTF
                        MainScr.rtfText.Tag = .FileName
                        MainScr.Caption = GetDocTitle(.FileTitle) & " - XenonPad"
                        MainScr.StatusBar.Panels(2).Text = GetDocTitle(.FileTitle)
                        MainScr.DocumentName = MainScr.StatusBar.Panels(2).Text
                        MainScr.DocumentChange = False
                    End If
            End With
        End If
    End With
End Function

Public Function RestoreWindow()
    With MainScr
        .rtfText.SelFontName = "Trebuchet MS"
        .rtfText.SelFontSize = 12
        .rtfText.SelAlignment = rtfLeft
        .rtfText.SelColor = vbBlack
        .rtfText.SelCharOffset = 0
        .BoldBar.Buttons(9).Value = tbrUnpressed
        .BoldBar.Buttons(10).Value = tbrUnpressed
        .rtfText.BackColor = vbWhite
        .rtfText.SelBullet = False
        .LeftBar.Buttons(1).Value = tbrUnpressed
        .rtfText.SelBold = False
        .BoldBar.Buttons(1).Value = tbrUnpressed
        .FormatAttrBold.Checked = False
        .rtfText.SelItalic = False
        .BoldBar.Buttons(2).Value = tbrUnpressed
        .rtfText.SelUnderline = False
        .BoldBar.Buttons(3).Value = tbrUnpressed
        .rtfText.SelStrikeThru = False
        .BoldBar.Buttons(4).Value = tbrUnpressed
        .FormatAlignCenter.Checked = False
        .FormatAlignLeft.Checked = True
        .FormatAlignRight.Checked = False
        .FormatAttrBold.Checked = False
        .FormatAttrItalic.Checked = False
        .FormatAttrUnderline.Checked = False
        .FormatAttrStrike.Checked = False
        .cboFont.Text = "Trebuchet MS"
        .cboSize.Text = "12"
    End With
End Function


Public Function ExitProgram()
    Dim Reply As Integer
    With MainScr
        If .DocumentChange = False Then
            End
        Else
            Reply = MsgBox("The current document named '" & .DocumentName & "' has been changed. Would you like to save these changes before closing the program?", vbYesNoCancel + vbDefaultButton1 + vbQuestion, "XenonPad")
                If Reply = vbCancel Then
                    Cancel = True
                ElseIf Reply = vbNo Then
                    End
                Else
                    If Len(MainScr.rtfText.Tag) > 0 Then
                        MainScr.rtfText.SaveFile MainScr.rtfText.Tag, rtfRTF
                        End
                    Else
                        With .CmDlg
                            .DialogTitle = "Save Document..."
                            .Filter = "Rich Text Format (*.RTF)|*.rtf"
                            .ShowSave
                            If Len(.FileTitle) > 0 Then
                                MainScr.rtfText.SaveFile .FileName, rtfRTF
                                End
                            End If
                        End With
                    End If
                End If
        End If
    End With
End Function

Project Homepage: