【问题标题】:using xib in firebreath plugin在 firebreath 插件中使用 xib
【发布时间】:2012-03-13 08:36:53
【问题描述】:

我在 mac os 上创建了一个 firebreath 插件,它必须弹出一个窗口来获取用户输入(只有一个文本字段和两个按钮)。

这是我当前用于测试的 projectDef.cmake。

file (GLOB XIB RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Mac/bundle_template/input.xib
)

# Make sure we can find the 'ibtool' program. If we can NOT find it we
# skip generation of this project
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
if (${IBTOOL} STREQUAL "IBTOOL-NOTFOUND")
    message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files.      It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
endif()

# make the compiled nib file to desktop for testing
set (NIBFILE /Users/develop/Desktop/input.nib)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD 
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text  --compile ${NIBFILE} ${XIB}
    COMMENT "Compiling input.xib")

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    ${XIB}
)

add_custom_command 块对 cmake 没有影响,当我的插件目标构建成功时没有编译 nib 文件,但 ibtool 在终端的命令行中工作。

【问题讨论】:

  • 对不起,我是可可新手。也许我不应该使用面板。根据浏览器的当前选项卡窗口,我需要输入对话框为窗口模式。我该如何实现?
  • 没有办法直接绑定到标签页;你所能做的就是让它成为模态的,并希望它足够好。您没有参考浏览器的 NSWindow
  • 感谢taxulian,我将使用应用程序模式对话框。目前,_window 始终为空,因此我无法显示它。我不知道为什么,我错过了什么?
  • 我按照 firebreath wiki 的说明进行操作。首先,从包标识符中获取插件的包名称,然后获取我的 xib 资源的绝对路径。一切似乎都正确,但就是无法加载窗口! :(
  • 我还是一头雾水;什么是_window?我在您的代码中的任何地方都没有看到 _window。

标签: xcode xib firebreath


【解决方案1】:

看起来您需要做的是将 .xib 文件编译为 .nib 文件。这里有一个如何做到这一点的例子:

http://www.cmake.org/Wiki/CMake:OSX_InterfaceBuilderFiles

基本上你会做类似的事情:

# Make sure we can find the 'ibtool' program. If we can NOT find it we
# skip generation of this project
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
if (${IBTOOL} STREQUAL "IBTOOL-NOTFOUND")
    message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
endif()

set (NIBFILE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/input.nib)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD 
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text 
            --compile ${NIBFILE} ${XIB}
    COMMENT "Compiling input.xib")

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    ${XIB}
    ${NIBFILE}
)

set_source_files_properties(${NIBFILE}
    PROPERTIES
        MACOSX_PACKAGE_LOCATION "Resources/English.lproj"
        GENERATED 1
)

您需要设置 NIB 文件的位置,但请记住,您还需要将其设置为 GENERATED,因为第一次运行准备脚本时它不会存在。

【讨论】:

  • 非常感谢,出租车司机。 xcode 构建过程会出现一些错误。这一行似乎不正确。(设置(NIBFILE ${CMAKE_CURRENT_BINARY_DIR}/\${CONFIGURATION}/input.nib))。我在 cmake 教程中找不到 ${CONFIGURATION}。
  • 那是因为 ${CONFIGURATION} 不是一个 cmake 变量,它是一个 xcode 变量。您可能可以改用 cmake 变量 ${CMAKE_CFG_INTDIR} 。 (cmake.org/cmake/help/…)
  • 即使我设置 GENERATED=1,问题依然存在。 nib 文件生成得太晚(在构​​建目标之后)。 pbxcp: input.nib: 没有这样的文件或目录。有没有什么命令可以代替“set_source_files_properties”?
  • 修改了projectDef.cmake,还是不行。请查看我编辑的问题。
  • 尝试将其设为 PRE_BUILD;你确定它没有运行吗?在你的构建目录中搜索它,看看你是否能找到它。它可能正在运行,但由于某种原因没有被复制到包中。
【解决方案2】:

问题解决了。见this link。这种方法有效。我的最终解决方案如下:

//projectDef.cmake

set(XIB "Mac/bundle_template/input.xib")

add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES ${XIB})

//Mac.cmake in "add_mac_plugin" macro

if (${ARGC} GREATER 5)
add_library( ${PROJECT_NAME} MODULE
    ${SOURCES} 
    ${ARGN}
    )
else()
add_library( ${PROJECT_NAME} MODULE
    ${SOURCES} 
    )
endif()

if (${ARGC} GREATER 5)
set_target_properties(${PROJECT_NAME} PROPERTIES
    BUNDLE 1
    BUNDLE_EXTENSION plugin
    XCODE_ATTRIBUTE_WRAPPER_EXTENSION plugin  #sets the extension to .plugin
    XCODE_ATTRIBUTE_MACH_O_TYPE mh_bundle
    XCODE_ATTRIBUTE_INFOPLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    RESOURCE ${ARGN}
    LINK_FLAGS "-Wl,- exported_symbols_list,${FB_ESC_ROOT_DIR}/gen_templates/ExportList_plugin.txt")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES
    BUNDLE 1
    BUNDLE_EXTENSION plugin
    XCODE_ATTRIBUTE_WRAPPER_EXTENSION plugin  #sets the extension to .plugin
    XCODE_ATTRIBUTE_MACH_O_TYPE mh_bundle
    XCODE_ATTRIBUTE_INFOPLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    LINK_FLAGS "-Wl,-exported_symbols_list,${FB_ESC_ROOT_DIR}/gen_templates/ExportList_plugin.txt")
endif()

我的修改好像不是很漂亮,cmake我不是很懂。嗨出租车司机,你能更新宏以支持 xib 等外部资源吗?顺便说一句,非常感谢,伙计。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多