0

ここに質問を投稿せずに問題を解決するために最善を尽くしています。ただし、valadoc 検索システムは最近壊れており、Genie コードに関しては #vala IRC チャネルはあまり役に立ちません (当然のことです)。

標的

この質問からこの初期の 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 ()

これは Convert クラスです。

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

質問

この場合、DocumentFileSelector が init によって認識されないのはなぜですか?

: 最小限の再現性のある質問を作成する方法をまだ考えていますが、すべての相互依存部分がある OOP に関しては、思ったほど単純ではありません。このため、私が提供したものが役に立たなかった場合に備えて、ここにコード全体を示します。

4

1 に答える 1

0

残念ながら、Genie パーサーでバグに遭遇しました。コードの 3 つの場所で、2 つのインデントを使用して 1 つの新しいコード ブロックを示しています。これらは:

  1. インターフェイス定義
  2. のメソッドcase when ...内のブロックselect()DocumentFileSelector
  3. のメソッドtry...except内のブロックget_document()DocumentFileSelector

たとえば、

interface Command:Object
        def abstract execute()

interface Command:Object
    def abstract execute()

それらを修正すると、コード内で他のタイプのエラーが多数発生しますが、Genie エラー メッセージからそれらを修正する方法を理解できるはずです。

Genie パーサーは 2 つのくぼみを読み取っていますが、ブロックの終わりを示す 2 つのくぼみを探している記録を保持していないため、混乱します。それを修正したい人は、Developmenting Genieを見てください。

于 2016-07-03T15:39:47.633 に答える