Share My Creation B4J PlugIn: What If?

Discussion in 'B4J Share Your Creations' started by Mashiane, Dec 6, 2017.

  1. Mashiane

    Mashiane Well-Known Member Licensed User

    Hi there

    WeCouldPlugIn.gif

    The fact that on the Files tab, one is able to open a file with an external program got me thinking this morning. What if I can write a B4J app, that can get passed the file name I selected, then process something inside the file and save it back.

    So I wrote a small script for something that I do almost often. Add a new page to my existing B4J app. To test my theory I created a form with a text area and created a UI app called NewPage...

    Code:
    #Region Project Attributes
        
    #MainFormWidth: 600
        
    #MainFormHeight: 600
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Private txtData As TextArea
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.Initialize(
    "frm"800800)
        MainForm.RootPane.LoadLayout(
    "vMain")
        MainForm.Show
        
        
    If Args.Length = 0 Then
            
    Log("File Name is missing.")
            
    Return
            
    'ExitApplication
        End If
        
    'get the file name
        Dim fName As String = Args(0)
        jMash.InformUser(
    "File Name",fName)
        
    'read the contents
        Dim contents As String = File.ReadString("",fName)
        txtData.Text = contents
        
        
    'New Page Content...
        Dim npc As StringBuilder
        npc.initialize
        npc.append(
    "Sub Process_Globals").Append(CRLF)
        npc.Append(
    "Private fx As JFX").Append(CRLF)
        npc.Append(
    "Private frm As Form").Append(CRLF)
        npc.Append(
    "End Sub").append(CRLF).Append(CRLF)
        npc.Append(
    "Sub Close").Append(CRLF)
        npc.Append(
    "frm.close").Append(CRLF)
        npc.Append(
    "End Sub").Append(CRLF)
        npc.Append(
    "Public Sub Show(ParentForm As Form)").Append(CRLF)
        npc.append(
    $"frm.Initialize("frm",400, 550)"$).Append(CRLF)
        npc.append(
    "frm.Resizable = False").Append(CRLF)
        npc.Append(
    $"frm.RootPane.LoadLayout("<Change>")"$).Append(CRLF)
        npc.Append(
    "frm.Title = <Change>").Append(CRLF)
        npc.Append(
    "frm.SetOwner(ParentForm)").Append(CRLF)
        npc.Append(
    "frm.ShowAndWait").append(CRLF)
        npc.Append(
    "End Sub").Append(CRLF)
        txtData.Text = txtData.Text & 
    CRLF & npc.tostring
    End Sub

    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub
    What the code above does is to open the selected file, read its contents, display the contents in a text area in a form after appending the code to Show and Close a form.

    After compiling this app, I needed to configure the external viewers..

    ConfigureExternal.png

    Then I right clicked on the file, selected Open with NewPage and yippiee!! See the gif.

    Now, what if the functionality to Open With could be available on the Modules tab? Me thinks the possibilities are endless..
     

    Attached Files:

    Harris, UFOCoder13 and alwaysbusy like this.
  2. Mashiane

    Mashiane Well-Known Member Licensed User

    Code for NewPage...
     

    Attached Files:

    joulongleu likes this.
  3. Cableguy

    Cableguy Expert Licensed User

    Interesting... Following
     
    joulongleu and Mashiane like this.
  4. Mashiane

    Mashiane Well-Known Member Licensed User

    Just made a feauture request for this, would be a great value add. #imagining
     
Loading...