0

嘿,我正在考虑在一个非常简单的桌面应用程序中使用 griffon,我被要求编写代码。它的 90% 的功能是在系统托盘之外点击几下鼠标,就像“开始/选择/停止”。我需要的一件事是工具提示,它会每秒(或每分钟,没关系;-))更新它的内容,计算某人一直在处理某些特定任务的时间。

我的问题是:

  • 如何定期调用“您为:${HourMin.since model.startedWorkingAt}”工作,以使提示始终保持最新?使用此代码,它只会在工具提示构建时被调用一次。
  • 如何在应用程序生命周期内向 popupMenu 动态添加“操作”?

感谢您提供任何建议 - 解决此类问题的书籍建议也会很有帮助。

actions {
  action(id: 'cutAction',
          name: 'Pokaż okno',
          closure: {
            trayIcon.displayMessage("Cut", "Cut some content", NONE)
          },
          mnemonic: 'T',
          accelerator: shortcut('X'),
          smallIcon: imageIcon(resource: "icons/cut.png", class: Console),
          shortDescription: 'Cut'
  )
//... more actions
}

systemTray {
  trayIcon(id: "trayIcon",
          resource: "/groovy/ui/ConsoleIcon.png",
          class: groovy.ui.Console,
          toolTip: {
            "Youre working for: ${HourMin.since model.startedWorkingAt}"
          },
          actionPerformed: {
//            todo do toggle
          }) {
    popupMenu {
      menuItem(cutAction)
      menuItem(copyAction)
      menuItem(pasteAction)
      separator()
      menuItem(exitAction)
    }
  }
}
4

2 回答 2

1

您是否尝试过绑定 GString?

toolTip: bind {
        "Youre working for: ${HourMin.since model.startedWorkingAt}"
      },
于 2010-12-04T20:20:12.060 回答
0

我想出了一个办法,方法如下:

// in the controller
def updateSystemTimeTask = new TimerTask() {
  @Override
  void run() {
    onSystemTimeUpdate System.currentTimeMillis()
  }
}

def onSystemTimeUpdate(Long systemTime) {
  if (model.working) {
    view.systemTray.trayIcons[0].toolTip = "Pracujesz już ${HourMin.since model.startedWorkingAt}".toString()
  } else {
    view.systemTray.trayIcons[0].toolTip = = "Obecnie nie pracujesz."
  }
}

// ant this in the initialization method
def myTimer = new Timer().schedule updateSystemTimeTask, initialDelay, minute

我不确定这是否是最干净的方式,但我想这很好,因为无论如何所有操作都在视图控制器中。

于 2010-12-04T23:47:59.487 回答