Custom extension file not showing contents

Extract the code that use OpenFileDialog (the part after OpenFileDialog) and create a new Method with it.

Then, call this Method from the code that OpenFileDialog and in the OpenDocument Event(s)…

http://documentation.xojo.com/api/deprecated/application.html#application-openDocument_event

Do ! The code example there do not have error handling (in fact, it do not have Exception Handling).

I am able understand what you want to say?

Based on what you are saying, I’m going to make the assumption that you have some code in App.FileOpen which shows an Open dialog, creates a window and then loads the file into it.

Now, following that assumption, I am also assuming that you have not implemented the App.OpenDocument event to do the same exact thing (minus the open dialog)

Perhaps if you could show your code from both of these places?

Code to load data

var FileDialog As FolderItem
FileDialog = FolderItem.ShowOpenFileDialog(FileExt.NoteDocument)

if FileDialog <> nil then
var UserSelect As TextInputStream
UserSelect = TextInputStream.Open(FileDialog)
UserSelect.Encoding = Encodings.UTF8

var ReadData As String
ReadData = UserSelect.ReadAll()

var NewWindow As new MainWindow

// -------------- TITLE BOX ----------------

NewWindow.TitleBox_1.Text = ReadData.NthField(“field_divider”, 1)
NewWindow.TitleBox_2.Text = ReadData.NthField(“field_divider”, 2)
NewWindow.TitleBox_3.Text = ReadData.NthField(“field_divider”, 3)

// -------------- TEXT BOX ----------------

NewWindow.TextBox_1.Text = ReadData.NthField(“field_divider”, 4)
NewWindow.TextBox_2.Text = ReadData.NthField(“field_divider”, 5)
NewWindow.TextBox_3.Text = ReadData.NthField(“field_divider”, 6)

NewWindow.Title="Note++ - "+FileDialog.Name
NewWindow.NameFile = FileDialog

UserSelect.Close

end if

I have not implemented the App.OpenDocument event.
How can I use it?

Here’s what I would do…

Make a method on MainWindow with the following signature:

LoadData(f as FolderItem)

Inside that method, put everything inside the if statement, and replace FileDialog with f. You will also need to replace NewWindow with Self.

if FileDialog <> nil Then
...
End If

Cut the line that creates the window and put the following back into your open method:

if FileDialog <> Nil Then
  var NewWindow As new MainWindow
  NewWindow.Load(FileDialog)
End If

Put that same code into the App.OpenDocument method but replace FileDialog with f:

if f <> Nil Then
  var NewWindow As new MainWindow
  NewWindow.Load(f)
End If

It doesn’t work.

Then you didn’t follow the instructions correctly.
What is in your OpenDocument event right now?

@Vansaj_Jain
If you want help here, you need to give more information than “it doesn’t work”.

2 Likes
var f as FolderItem

if f <> Nil Then
  var NewWindow As new MainWindow
  NewWindow.LoadData(f)
End If

LoadData contains

if f <> nil then
  var UserSelect As TextInputStream
  UserSelect = TextInputStream.Open(f)
  UserSelect.Encoding = Encodings.UTF8
  
  var ReadData As String
  ReadData = UserSelect.ReadAll()
  
  var NewWindow As new MainWindow
  
  // -------------- TITLE BOX ----------------
  
  NewWindow.TitleBox_1.Text = ReadData.NthField("field_divider", 1)
  NewWindow.TitleBox_2.Text = ReadData.NthField("field_divider", 2)
  NewWindow.TitleBox_3.Text = ReadData.NthField("field_divider", 3)
  
  // -------------- TEXT BOX ----------------
  
  NewWindow.TextBox_1.Text = ReadData.NthField("field_divider", 4)
  NewWindow.TextBox_2.Text = ReadData.NthField("field_divider", 5)
  NewWindow.TextBox_3.Text = ReadData.NthField("field_divider", 6)
  
  NewWindow.Title="Note++ - "+f.Name
  NewWindow.NameFile = f
  
  UserSelect.Close
  
end if

What are you doing between lines 1 and 2? Your folderitem is always nil.

1 Like

In the OpenDocument event, you dont get an ‘f’
You get item

The docs (Vansaj should read these):

https://documentation.xojo.com/api/deprecated/application.html#application-openDocument_event

So in the Opendocument event , it would need to be

if item <> Nil  and item.exists Then
  var NewWindow As new MainWindow
  NewWindow.LoadData(item)
End If
if item <> Nil  and item.exists Then
  var NewWindow As new MainWindow
  NewWindow.LoadData(item)
End If

Showing an error, item does not exist.

Maybe share a sample using dropbox/google drive/etc, that way others can see what you are doing.

Then the code is not in the OpenDocument event.

Where is it?
Post a screenshot ?
Post your project?

This is the screenshot.

Thank you.
Can you now put that code into the Application.OpenDocument event instead of the Window’s Opening event ?

If you want the Window to display something when it is opened, either you need to ask the user for the file (using your original code), or go get a file which you know the location of.

Where Application.OpenDocument is located?

Right click on the app, and add the event

I explained it all here:


if item <> nil then
  var UserSelect As TextInputStream
  UserSelect = TextInputStream.Open(item)
  UserSelect.Encoding = Encodings.UTF8
  
  var ReadData As String
  ReadData = UserSelect.ReadAll()
  
  var NewWindow As New MainWindow
  
  // -------------- TITLE BOX ----------------
  
  NewWindow.TitleBox_1.Text = ReadData.NthField("field_divider", 1)
  NewWindow.TitleBox_2.Text = ReadData.NthField("field_divider", 2)
  NewWindow.TitleBox_3.Text = ReadData.NthField("field_divider", 3)
  
  // -------------- TEXT BOX ----------------
  
  NewWindow.TextBox_1.Text = ReadData.NthField("field_divider", 4)
  NewWindow.TextBox_2.Text = ReadData.NthField("field_divider", 5)
  NewWindow.TextBox_3.Text = ReadData.NthField("field_divider", 6)
  
  NewWindow.Title="Note++ - "+item.Name
  NewWindow.NameFile = item
  
  UserSelect.Close
  
end if

Code is opening two window - one is blank and other is with content. Where is the problem?