Doing my best to try to solve my problems w/o posting questions here. However, valadoc search system has been broken recently and #vala IRC channel is less helpful when it comes to Genie code (understandably).
I am trying to provide a OOP Gtk interface from this question to this early pandoc gui app.
I got stuck with the error pandoc-gui.gs:56.24-56.43: error: The type name `DocumentFileSelector' could not be found\n _document_selector:DocumentFileSelector
at compilation. The class is defined later in the program, but I can't seem to find what I did wrong that makes it not visible to init.
This is the init routine:
init
Intl.setlocale()
Gtk.init (ref args)
var header = new Header ( "Pandoc GUI" )
var body = new WorkingFile( )
var app = new AppWindow ( header,body )
var load_new_content_command = new Load( body, document_selector )
var document_selector = new DocumentFileSelector( app )
var convert_command = new Convert (document_selector)
header.add_item( new OpenButton( load_new_content_command ) )
header.add_item( new ConvertButton ( convert_command ) )
app.show_all ()
Gtk.main ()
This is the Convert class:
class Convert:Object implements Command
_document_selector:DocumentFileSelector
construct ( document_selector:DocumentFileSelector )
_document_selector = document_selector
def execute()
var a = new ToPDF()
a.convert.begin( document_selector.whichFile(), "output_file.pdf" )
And the interfaces:
interface Command:Object
def abstract execute()
interface DocumentSelector:Object
def abstract select():bool
def abstract get_document():string
And the DocumentFileSelector class:
class DocumentFileSelector:Object implements DocumentSelector
_parent:Window
_uri:string = ""
_filename:string = ""
construct( parent:Window )
_parent = parent
def select():bool
var dialog = new FileChooserDialog( "Open file",
_parent,
FileChooserAction.OPEN,
dgettext( "gtk30", "_OK"),
ResponseType.ACCEPT,
dgettext( "gtk30", "_Cancel" ),
ResponseType.CANCEL)
selected:bool = false
var response = dialog.run()
case response
when ResponseType.ACCEPT
_filename = dialog.get_filename()
_uri = dialog.get_uri()
selected = true
dialog.destroy()
return selected
def whichFile():string
return _uri
def get_document():string
text : string
len : size_t
try
FileUtils.get_contents (_filename, out text, out len)
except ex : FileError
print "%s\n", ex.message
return text
Why is DocumentFileSelector not being seen by init in this case?
Note: I am still figuring out how to write a minimally reproducible question, however it is not as simple as it sounds when it comes to OOP with all the interdependent parts. For this reason, here is the entire code in case what I provided wasn't enough to help.
Unfortunately you have encountered a bug in the Genie parser. There are three places in your code where you are using two indentations to indicate a single new block of code. These are:
case when ...
block in the select()
method of DocumentFileSelector
try...except
block in the get_document()
method of DocumentFileSelector
For example, change
interface Command:Object
def abstract execute()
to
interface Command:Object
def abstract execute()
Once you have fixed those you will encounter a number of other type errors in your code, but you should be able to figure out how to fix those from the Genie error messages.
The Genie parser is reading the two indentations, but gets confused because it doesn't keep a record it is looking for two dedentations to mark the end of the block. Anyone wishing to fix that take a look at Developing Genie.