示例#1
0
文件: eventmouse.go 项目: sqp/godock
// OnDropData triggers a dock drop data action on the icon.
//
func OnDropData(icon gldi.Icon, container *gldi.Container, data string, order float64) bool {
	if !gldi.ObjectIsDock(container) {
		log.Debug("notifDropData", "ignored: container is not a dock")
		return notif.AnswerLetPass
	}

	receivingDock := container.ToCairoDock()

	switch {
	case strings.HasSuffix(data, ".desktop"): // -> add a new launcher if dropped on or amongst launchers.

		if !current.Taskbar.MixLauncherAppli() && icon.IsAppli() {
			log.Debug("notifDropData", "ignored: desktop file found but maybe bad location in dock (or need mix launchers)")
			return notif.AnswerLetPass
		}

		// drop onto a container icon.
		if order == gldi.IconLastOrder && icon.IsStackIcon() && icon.GetSubDock() != nil {
			// add into the pointed sub-dock.
			receivingDock = icon.GetSubDock()
		}

		// else, still try to consider it a file?

	case icon == nil || order != gldi.IconLastOrder:
		//  dropped between 2 icons -> try to add it (for instance a script).

	case icon.IsStackIcon(): // sub-dock -> propagate to the sub-dock.
		receivingDock = icon.GetSubDock()

		// dropped on an icon

	case icon.IsLauncher() || icon.IsAppli() || icon.IsClassIcon():
		// launcher/appli -> fire the command with this file.
		cmd := icon.GetCommand()
		if cmd == "" {
			log.Debug("notifDropData", "ignored: no command to trigger")
			return notif.AnswerLetPass
		}

		// Some programs doesn't handle URI. Convert it to local path.
		if strings.HasPrefix(data, "file://") {

			// gchar *cPath = g_filename_from_uri (cReceivedData, NULL, NULL);
			// data = bouine(data)
		}

		ok := icon.LaunchCommand(log, data)
		if ok {
			icon.RequestAnimation("blink", 2)
			log.Debug("notifDropData", "opened with", icon.GetName(), "::", data)
		}

		return notif.AnswerIntercept

	default: // skip any other case.
		log.Debug("notifDropData", "ignored: nothing to do with icon type", icon.GetName())
		return notif.AnswerLetPass
	}

	if current.DockIsLocked() || current.Docks.LockAll() {
		log.Debug("notifDropData", "ignored: dock is locked, can't add icon")
		return notif.AnswerLetPass
	}

	// Still here ? Try to add to target dock.

	newicon := gldi.LauncherAddNew(data, receivingDock, order)
	if newicon == nil {
		log.Debug("notifDropData", "add icon failed ::", data)
		return notif.AnswerIntercept
	}

	log.Debug("notifDropData", "icon added:", icon.GetName())
	return notif.AnswerLetPass
}