Exemplo n.º 1
0
// buildKey builds a Cairo-Dock configuration widget with the given keys.
//
func (build *builder) buildKey(key *cftype.Key) {
	makeWidget := key.MakeWidget()
	if makeWidget == nil {
		makeWidget = cfwidget.Maker(key)
		if makeWidget == nil {
			build.Log().NewErrf("no make widget call", "type=%s  [key=%s / %s]\n", key.Type, key.Group, key.Name)
			return
		}
	}

	// build.log.DEV(key.Name, string(key.Type), key.AuthorizedValues)

	build.pKeyBox = nil
	build.pLabel = nil
	build.pWidgetBox = nil
	build.pAdditionalItemsVBox = nil

	fullSize := key.IsType(cftype.KeyListThemeApplet, cftype.KeyListViews, cftype.KeyEmptyFull, cftype.KeyHandbook)

	if !key.IsType(cftype.KeyFrame) && !key.IsType(cftype.KeyExpander) && !key.IsType(cftype.KeySeparator) {
		// Create Key box.
		if key.IsType(cftype.KeyListThemeApplet, cftype.KeyListViews) {
			build.pAdditionalItemsVBox = newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
			build.pKeyBox = newgtk.Box(gtk.ORIENTATION_HORIZONTAL, cftype.MarginGUI)
			build.PackWidget(build.pAdditionalItemsVBox, fullSize, fullSize, 0)
			build.pAdditionalItemsVBox.PackStart(build.pKeyBox, false, false, 0)

		} else {
			if key.IsAlignedVertical {
				build.log.Info("aligned /", strings.TrimSuffix(key.Name, "\n"))
				build.pKeyBox = newgtk.Box(gtk.ORIENTATION_VERTICAL, cftype.MarginGUI)
			} else {
				build.pKeyBox = newgtk.Box(gtk.ORIENTATION_HORIZONTAL, cftype.MarginGUI)
			}

			build.PackWidget(build.pKeyBox, fullSize, fullSize, 0)
		}

		if key.Tooltip != "" {
			build.pKeyBox.SetTooltipText(build.Translate(key.Tooltip))
		}

		// 	if (pControlWidgets != NULL)
		// 	{
		// 		CDControlWidget *cw = pControlWidgets->data;
		// 		//g_print ("ctrl (%d widgets)\n", NbControlled);
		// 		if (cw->pControlContainer == (pFrameVBox ? pFrameVBox : build))
		// 		{
		// 			//g_print ("ctrl (NbControlled:%d, iFirstSensitiveWidget:%d, iNbSensitiveWidgets:%d)\n", NbControlled, iFirstSensitiveWidget, iNbSensitiveWidgets);
		// 			cw->NbControlled --;
		// 			if (cw->iFirstSensitiveWidget > 0)
		// 				cw->iFirstSensitiveWidget --;
		// 			cw->iNonSensitiveWidget --;

		// 			GtkWidget *w = (pAdditionalItemsVBox ? pAdditionalItemsVBox : pKeyBox);
		// 			if (cw->iFirstSensitiveWidget == 0 && cw->iNbSensitiveWidgets > 0 && cw->iNonSensitiveWidget != 0)  // on est dans la zone des widgets sensitifs.
		// 			{
		// 				//g_print (" => sensitive\n");
		// 				cw->iNbSensitiveWidgets --;
		// 				if (GTK_IS_EXPANDER (w))
		// 					gtk_expander_set_expanded (GTK_EXPANDER (w), TRUE);
		// 			}
		// 			else
		// 			{
		// 				//g_print (" => unsensitive\n");
		// 				if (!GTK_IS_EXPANDER (w))
		// 					gtk_widget_set_sensitive (w, FALSE);
		// 			}
		// 			if (cw->iFirstSensitiveWidget == 0 && cw->NbControlled == 0)
		// 			{
		// 				pControlWidgets = g_list_delete_link (pControlWidgets, pControlWidgets);
		// 				g_free (cw);
		// 			}
		// 		}
		// 	}

		// Key description on the left.
		if key.Text != "" { // and maybe need to test different from  "loading..." ?
			build.pLabel = newgtk.Label("")
			text := strings.TrimRight(build.Translate(key.Text), ":") // dirty hack against ugly trailing colon.

			build.pLabel.SetMarkup(text)
			build.pLabel.SetHAlign(gtk.ALIGN_START)
			// margin-left
			// 		GtkWidget *pAlign = gtk_alignment_new (0., 0.5, 0., 0.);
			build.pKeyBox.PackStart(build.pLabel, false, false, 0)
		}

		// Key widgets on the right. In pWidgetBox, they will be stacked from left to right.
		if !key.IsType(cftype.KeyTextLabel) {
			build.pWidgetBox = newgtk.Box(gtk.ORIENTATION_HORIZONTAL, cftype.MarginGUI)
			build.pKeyBox.PackEnd(build.pWidgetBox, fullSize, fullSize, 0)
		}
	}

	// Build widget for the key, use the default for the type if not overridden.
	makeWidget()
}