Custom extension file not showing contents

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?

Where is the problem?

If this code is called by an existing window instead of the app, you will get a second window.

var NewWindow As New MainWindow

So the first window is making a new window, maybe?
Have you considered stepping through the code in the debugger?

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

You already have this answer in a previous entry (answer):

remove the line


Var ReadWindow As New MainWindow

Instead of asking question at each stage of your project developement, do your home work: read the tutorials, check the examples, read the Language Reference, read the “ Introduction to Xojo Programming Book” book.

You will not have to wait for answers that are… pure bet (guess).

Of course, if after doing your home work you have troubles, ask.

IMHO.

In my experience, memory works far more efficiency after searching vs getting an answer.

I guess MainWindow is your Default Window, you either change that to None or do not create a new window and use MainWindow (without the var NewWindow) and change your code to use MainWindow instead:
image

And with:

var NewWindow As New MainWindow

you are creating another window.

If you are going to create NewWindow based on MainWindow you may want to change the ‘Implicit Instance’ to False (you can review the docs about implicit instance):
image