【发布时间】:2016-07-03 02:29:49
【问题描述】:
尽我所能尝试解决我的问题,但不在这里发布问题。然而,valadoc 搜索系统最近被破坏了,#vala IRC 频道对 Genie 代码的帮助不大(可以理解)。
目标
我正在尝试提供从 this question 到 this 早期 pandoc gui 应用程序的 OOP Gtk 接口。
问题
我在编译时遇到了错误pandoc-gui.gs:56.24-56.43: error: The type name `DocumentFileSelector' could not be found\n _document_selector:DocumentFileSelector。该类稍后在程序中定义,但我似乎找不到我做错了什么导致它对 init 不可见。
这是初始化例程:
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 ()
这是转换类:
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" )
还有接口:
interface Command:Object
def abstract execute()
interface DocumentSelector:Object
def abstract select():bool
def abstract get_document():string
还有 DocumentFileSelector 类:
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
问题
为什么在这种情况下,init 看不到 DocumentFileSelector?
注意:我仍在研究如何编写一个最低限度可重现的问题,但是当涉及到所有相互依赖的部分的 OOP 时,它并不像听起来那么简单。出于这个原因,这里是整个code,以防我提供的内容不足以提供帮助。
【问题讨论】:
标签: genie