Ejemplo n.º 1
0
// ListDeskletDecoration adds a desklet decoration list widget.
//
func ListDeskletDecoration(key *cftype.Key) {
	current := key.Value().String()
	getList := key.Source().ListDeskletDecorations
	if key.IsType(cftype.KeyListDeskletDecoDefault) {
		getList = fieldsPrepend(getList(),
			datatype.Field{Key: "default", Name: tran.Slate("default")},
		)
	}
	PackComboBoxWithListField(key, false, false, getList)

	// 	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pListStore), CAIRO_DOCK_MODEL_NAME, GTK_SORT_ASCENDING);

	// _allocate_new_buffer;
	// data[0] = pKeyBox;
	// data[1] = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
	// NbControlled = 9;
	// data[2] = GINT_TO_POINTER (NbControlled);
	// NbControlled --;  // car dans cette fonction, on ne compte pas le separateur.
	// g_signal_connect (G_OBJECT (pOneWidget), "changed", G_CALLBACK (_cairo_dock_select_custom_item_in_combo), data);

	if current == "personnal" { // Disable the next widgets.
		// 		CDControlWidget *cw = g_new0 (CDControlWidget, 1);
		// 		pControlWidgets = g_list_prepend (pControlWidgets, cw);
		// 		cw->NbControlled = NbControlled;
		// 		cw->iNbSensitiveWidgets = 0;
		// 		cw->iFirstSensitiveWidget = 1;
		// 		cw->pControlContainer = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
	}
}
Ejemplo n.º 2
0
// ColorSelector adds a color selector widget.
//
func ColorSelector(key *cftype.Key) {
	values := key.Value().ListFloat()
	if len(values) == 3 {
		values = append(values, 1) // no transparency.
	}
	gdkColor := gdk.NewRGBA(values...)
	widget := newgtk.ColorButtonWithRGBA(gdkColor)

	var getValue func() interface{}
	switch key.Type {
	case cftype.KeyColorSelectorRGB:
		key.NbElements = 3
		getValue = func() interface{} { return widget.GetRGBA().Floats()[:3] } // Need to trunk ?

	case cftype.KeyColorSelectorRGBA:
		key.NbElements = 4
		getValue = func() interface{} { return widget.GetRGBA().Floats() }
	}

	widget.Set("use-alpha", key.IsType(cftype.KeyColorSelectorRGBA))

	key.PackKeyWidget(key,
		getValue,
		func(uncast interface{}) { widget.SetRGBA(gdk.NewRGBA(uncast.([]float64)...)) },
		widget,
	)
	oldval, e := key.Storage().Default(key.Group, key.Name)
	if e == nil {
		PackReset(key, oldval.ListFloat())
	}
}
Ejemplo n.º 3
0
// Add adds a key to the printer.
//
func (lf *lineFeed) Add(key *cftype.Key) {
	if key.Group != lf.lastGroup {
		lf.AddGroup(RowName, key.Group)
		lf.lastGroup = key.Group
		lf.hasFrame = false
	}

	var line tablist.Liner
	var title string
	switch {
	case key.IsType(cftype.KeyFrame, cftype.KeyExpander):
		line = lf.AddEmptyFilled()
		lf.hasFrame = true
		line.Set(RowType, key.Type.String())
		if len(key.AuthorizedValues) == 0 {
			title = "[*FRAME NO TITLE*]"
		} else {
			title = key.AuthorizedValues[0]
		}

	case key.IsType(cftype.KeySeparator):
		line = lf.AddEmptyFilled()
		line.Set(RowType, key.Type.String())
		title = lf.indent() + "---------"

	case key.IsType(cftype.KeyTextLabel, cftype.KeyLaunchCmdSimple):
		line = lf.AddEmptyFilled()
		line.Set(RowType, key.Type.String())
		title = lf.indent() + key.Name

	default:
		line = lf.AddLine()
		lf.valuePrint(key, line)
		line.Colored(RowType, color.FgGreen, key.Type.String())
		title = lf.indent() + key.Name
		lf.countChangeable++
	}

	line.Set(RowName, title)
}
Ejemplo n.º 4
0
// TestValues updates the key data with test values.
//
func TestValues(key *cftype.Key) {
	switch key.Type {
	case cftype.KeyBoolButton,
		cftype.KeyBoolCtrl:

		if key.NbElements > 1 {
			val := key.Value().ListBool()
			newval := make([]bool, len(val))
			for i, v := range val {
				newval[i] = !v
			}
			key.ValueSet(newval)

		} else {
			val := key.Value().Bool()
			newval := !val
			key.ValueSet(newval)
		}

	case cftype.KeyIntSpin,
		cftype.KeyIntSize,
		cftype.KeyIntScale:

		if key.NbElements > 1 {
			val := key.Value().ListInt()
			newval := make([]int, len(val))
			for i, v := range val {
				newval[i] = v + 1 + i
			}
			key.ValueSet(newval)
		} else {
			val := key.Value().Int()
			newval := val + 1
			key.ValueSet(newval)
		}

	case cftype.KeyFloatSpin,
		cftype.KeyFloatScale:

		if key.NbElements > 1 {
			val := key.Value().ListFloat()
			newval := make([]float64, len(val))
			for i, v := range val {
				newval[i] = v + 0.1 + float64(i) // hack +0.1 +i
			}
			key.ValueSet(newval)
		} else {
			val := key.Value().Float()
			newval := val + 0.1
			key.ValueSet(newval)
		}

	case cftype.KeyColorSelectorRGB,
		cftype.KeyColorSelectorRGBA:

		val := key.Value().ListFloat()
		newval := make([]float64, len(val))
		for i := range val {
			newval[i] = val[i] + 0.1
			if newval[i] > 1 {
				newval[i]--
			}
		}
		if len(newval) == 3 {
			newval = append(newval, 1)
		}
		key.ValueSet(newval)

	case cftype.KeyLink:

		val := key.Value().String()
		list := []string{urlDock, urlGoTour}
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyStringEntry,
		cftype.KeyFileSelector, cftype.KeyFolderSelector,
		cftype.KeyImageSelector, cftype.KeySoundSelector,
		cftype.KeyShortkeySelector, cftype.KeyClassSelector,
		cftype.KeyPasswordEntry,
		cftype.KeyListEntry:

		val := key.Value().String()
		newval := cycleNextString(otherStrings, val, nil)
		key.ValueSet(newval)

	case cftype.KeyFontSelector:

		val := key.Value().String()
		list := []string{"Arial 8", "Monospace 8"}
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyTreeViewSortSimple,
		cftype.KeyTreeViewSortModify:

		val := key.Value().ListString()
		newval := reverseStrings(val)
		key.ValueSet(newval)

	case cftype.KeyListNumbered,
		cftype.KeyListNbCtrlSimple,
		cftype.KeyListNbCtrlSelect:

		val := key.Value().Int()
		step := ternary.Int(key.IsType(cftype.KeyListNbCtrlSelect), 3, 1)
		newval := cycleNextID(len(key.AuthorizedValues), val, step)
		key.ValueSet(newval)

	case cftype.KeyListSimple:
		val := key.Value().String()
		newval := cycleNextString(key.AuthorizedValues, val, key)
		key.ValueSet(newval)

	case cftype.KeyListDocks:

		val := key.Value().String()
		list := []string{datatype.KeyMainDock, datatype.KeyNewDock}
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyListThemeApplet:

		val := key.Value().String()
		list := []string{"Turbo-night-fuel[0]", "Sound-Mono[0]"}
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyHandbook:

		val := key.Value().String()
		list := datatype.ListHandbooksKeys(Handbooks)
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyListViews:

		val := key.Value().String()
		books := key.Source().ListViews()
		list := datatype.IndexHandbooksKeys(books)
		newval := cycleNextString(list, val, key)
		key.ValueSet(newval)

	case cftype.KeyListIconsMainDock:

		val := key.Value().String()
		fields := key.Source().ListIconsMainDock()
		newval := cycleNextField(fields, val, key)
		key.ValueSet(newval)

	case cftype.KeyListThemeDesktopIcon:

		val := key.Value().String()
		fields := key.Source().ListThemeDesktopIcon()
		newval := cycleNextField(fields, val, key)
		key.ValueSet(newval)

	}
}
Ejemplo n.º 5
0
// TreeView adds a treeview widget.
//
func TreeView(key *cftype.Key) {
	values := key.Value().ListString()

	// Build treeview.
	model := newgtk.ListStore(
		glib.TYPE_STRING,  /* RowKey*/
		glib.TYPE_STRING,  /* RowName*/
		glib.TYPE_STRING,  /* RowIcon*/
		glib.TYPE_STRING,  /* RowDesc*/
		glib.TYPE_BOOLEAN, // active
		glib.TYPE_INT)     // order

	widget := newgtk.TreeViewWithModel(model)
	widget.Set("headers-visible", false)

	getValue := func() interface{} { // Grab data from all iters.
		var list []string
		iter, ok := model.GetIterFirst()
		for ; ok; ok = model.IterNext(iter) {
			str, e := gunvalue.New(model.GetValue(iter, RowName)).String()
			if !key.Log().Err(e, "WidgetTreeView GetValue "+key.Name) {
				list = append(list, str)
			}
		}
		return list
	}

	// Add control buttons.
	if key.IsType(cftype.KeyTreeViewMultiChoice) {
		renderer := newgtk.CellRendererToggle()
		col := newgtk.TreeViewColumnWithAttribute("", renderer, "active", 4)
		widget.AppendColumn(col)
		// 	g_signal_connect (G_OBJECT (rend), "toggled", (GCallback) _cairo_dock_activate_one_element, modele);

		renderer.Set("active", 4)
	}

	renderer := newgtk.CellRendererText()
	col := newgtk.TreeViewColumnWithAttribute("", renderer, "text", RowName)
	widget.AppendColumn(col)

	// cValueList = g_key_file_get_string_list (pKeyFile, cGroupName, cKeyName, &length, NULL);

	model.SetSortColumnId(5, gtk.SORT_ASCENDING)

	scroll := newgtk.ScrolledWindow(nil, nil)

	//

	// if len(key.AuthorizedValues) > 0 {
	// 	key.Log().Info("WidgetTreeView AuthorizedValues", key.AuthorizedValues)
	// }

	// if (key.AuthorizedValues != NULL && key.AuthorizedValues[0] != NULL)
	// 	for (k = 0; key.AuthorizedValues[k] != NULL; k++);
	// else
	// 	k = 1;
	scroll.Set("height-request", 100) // key.IsType(cftype.KeyTreeViewSortModify) ? 100 : MIN (100, k * 25)
	scroll.Set("width-request", 250)
	scroll.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

	scroll.Add(widget)

	vboxItems := newgtk.Box(gtk.ORIENTATION_VERTICAL, cftype.MarginGUI)
	grid := newgtk.Grid()
	grid.Attach(vboxItems, 0, 0, 1, 1)
	grid.Attach(scroll, 1, 0, 1, 1)

	if key.IsType(cftype.KeyTreeViewSortSimple, cftype.KeyTreeViewSortModify) {

		buttonUp := newgtk.Button()
		buttonDn := newgtk.Button()
		imgUp := newgtk.ImageFromIconName("go-up", gtk.ICON_SIZE_SMALL_TOOLBAR)
		imgDn := newgtk.ImageFromIconName("go-down", gtk.ICON_SIZE_SMALL_TOOLBAR)

		buttonUp.SetImage(imgUp)
		buttonDn.SetImage(imgDn)

		data := treeViewData{key.Log(), model, widget, nil}

		buttonUp.Connect("clicked", onTreeviewMoveUp, data) // Move selection up and down callbacks.
		buttonDn.Connect("clicked", onTreeviewMoveDown, data)

		vboxItems.PackStart(buttonUp, false, false, 0)
		vboxItems.PackStart(buttonDn, false, false, 0)

		if key.IsType(cftype.KeyTreeViewSortModify) {

			buttonAdd := newgtk.Button()
			entry := newgtk.Entry()
			buttonRm := newgtk.Button()

			imgAdd := newgtk.ImageFromIconName("list-add", gtk.ICON_SIZE_SMALL_TOOLBAR)
			imgRm := newgtk.ImageFromIconName("list-remove", gtk.ICON_SIZE_SMALL_TOOLBAR)
			buttonAdd.SetImage(imgAdd)
			buttonRm.SetImage(imgRm)

			vboxItems.PackStart(buttonRm, false, false, 0)
			grid.Attach(newgtk.Separator(gtk.ORIENTATION_HORIZONTAL), 0, 1, 2, 1)
			grid.Attach(buttonAdd, 0, 2, 1, 1)
			grid.Attach(entry, 1, 2, 1, 1)

			data.entry = entry
			buttonAdd.Connect("clicked", onTreeviewAddText, data)   // Add new iter to model with the value of the entry widget. Clear entry widget.
			buttonRm.Connect("clicked", onTreeviewRemoveText, data) // Remove selected iter from model. Set its value to the entry widget.
		}
	}

	setValues := func(newvalues []string) {
		for i, val := range newvalues {
			iter := model.Append()
			model.SetValue(iter, RowKey, val)
			model.SetValue(iter, RowName, val)

			model.SetValue(iter, 4, true) // active
			model.SetValue(iter, 5, i)    // order
		}
	}

	// Fill model with values.
	switch key.Type {
	case cftype.KeyTreeViewSortModify, // add saved values.
		cftype.KeyTreeViewSortSimple: // TODO: TEMP to improve and maybe regroup this case as was with multichoice and not modify.

		setValues(values)

		key.PackKeyWidget(key,
			getValue,
			func(uncast interface{}) { model.Clear(); setValues(uncast.([]string)) },
			grid)

	case cftype.KeyTreeViewMultiChoice:
		if len(key.AuthorizedValues) > 0 {
			// var NbMax, order int

		}
		// else if (pAuthorizedValuesList != NULL)  // on liste les choix possibles dans l'ordre choisi. Pour CAIRO_DOCK_WidgetTreeViewMultiChoice, on complete avec ceux n'ayant pas ete selectionnes.
		// {
		// 	gint iNbPossibleValues = 0, iOrder = 0;
		// 	while (pAuthorizedValuesList[iNbPossibleValues] != NULL)
		// 		iNbPossibleValues ++;
		// 	guint l;
		// 	for (l = 0; l < length; l ++)
		// 	{
		// 		cValue = cValueList[l];
		// 		if (! g_ascii_isdigit (*cValue))  // ancien format.
		// 		{
		// 			cd_debug ("old format\n");
		// 			int k;
		// 			for (k = 0; k < iNbPossibleValues; k ++)  // on cherche la correspondance.
		// 			{
		// 				if (strcmp (cValue, pAuthorizedValuesList[k]) == 0)
		// 				{
		// 					cd_debug (" correspondance %s <-> %d", cValue, k);
		// 					g_free (cValueList[l]);
		// 					cValueList[l] = g_strdup_printf ("%d", k);
		// 					cValue = cValueList[l];
		// 					break ;
		// 				}
		// 			}
		// 			if (k < iNbPossibleValues)
		// 				iValue = k;
		// 			else
		// 				continue;
		// 		}
		// 		else
		// 			iValue = atoi (cValue);

		// 		if (iValue < iNbPossibleValues)
		// 		{
		// 			memset (&iter, 0, sizeof (GtkTreeIter));
		// 			gtk_list_store_append (modele, &iter);
		// 			gtk_list_store_set (modele, &iter,
		// 				CAIRO_DOCK_MODEL_ACTIVE, TRUE,
		// 				CAIRO_DOCK_MODEL_NAME, dgettext (cGettextDomain, pAuthorizedValuesList[iValue]),
		// 				CAIRO_DOCK_MODEL_RESULT, cValue,
		// 				CAIRO_DOCK_MODEL_ORDER, iOrder ++, -1);
		// 		}
	}

	// 	if (iOrder < iNbPossibleValues)  // il reste des valeurs a inserer (ce peut etre de nouvelles valeurs apparues lors d'une maj du fichier de conf, donc CAIRO_DOCK_WidgetTreeViewSortSimple est concerne aussi).
	// 	{
	// 		gchar cResult[10];
	// 		for (k = 0; pAuthorizedValuesList[k] != NULL; k ++)
	// 		{
	// 			cValue =  pAuthorizedValuesList[k];
	// 			for (l = 0; l < length; l ++)
	// 			{
	// 				iValue = atoi (cValueList[l]);
	// 				if (iValue == (int)k)  // a deja ete inseree.
	// 					break;
	// 			}

	// 			if (l == length)  // elle n'a pas encore ete inseree.
	// 			{
	// 				snprintf (cResult, 9, "%d", k);
	// 				memset (&iter, 0, sizeof (GtkTreeIter));
	// 				gtk_list_store_append (modele, &iter);
	// 				gtk_list_store_set (modele, &iter,
	// 					CAIRO_DOCK_MODEL_ACTIVE, (iElementType == CAIRO_DOCK_WidgetTreeViewSortSimple),
	// 					CAIRO_DOCK_MODEL_NAME, dgettext (cGettextDomain, cValue),
	// 					CAIRO_DOCK_MODEL_RESULT, cResult,
	// 					CAIRO_DOCK_MODEL_ORDER, iOrder ++, -1);
	// 			}
	// 		}
	// 	}
	// }
}
Ejemplo n.º 6
0
// Lists adds a string list widget.
//
func Lists(key *cftype.Key) {
	if key.IsType(cftype.KeyListNbCtrlSimple, cftype.KeyListNbCtrlSelect) && len(key.AuthorizedValues) == 0 {
		key.Log().NewWarn("not enough values", "widget numbered control list:", key.Name)
		return
	}

	// Get full value with ';'.
	value := key.Value().String()

	// log.DEV("LIST "+string(key.Type), key.Name, value, key.AuthorizedValues)

	listIsNumbered := key.IsType(cftype.KeyListNumbered, cftype.KeyListNbCtrlSimple, cftype.KeyListNbCtrlSelect)

	iSelectedItem := -1
	current := ""

	// Control selective use 3 AuthorizedValues fields for each "value".
	step := ternary.Int(key.IsType(cftype.KeyListNbCtrlSelect), 3, 1)

	if key.IsType(cftype.KeyListEntry) {
		current = value
	}

	if listIsNumbered && value != "" {
		var e error
		iSelectedItem, e = strconv.Atoi(value)
		switch {
		case key.Log().Err(e, "selection problem", "[", value, "]", "[", iSelectedItem, "]", key.Name):
		case iSelectedItem < 0:

		case iSelectedItem < len(key.AuthorizedValues):
			current = key.AuthorizedValues[iSelectedItem*step]

		default:
			key.Log().NewWarn("selection out of range", "widget numbered list:", key.Name)
		}
	}

	var list []datatype.Field
	if len(key.AuthorizedValues) > 0 {
		// int iOrder1, iOrder2, iExcept;

		if key.IsType(cftype.KeyListNbCtrlSimple, cftype.KeyListNbCtrlSelect) {
			key.SetNbControlled(0)
		}

		// 	gchar *cResult = (listIsNumbered ? g_new0 (gchar , 10) : NULL);

		for k := 0; k < len(key.AuthorizedValues); k += step { // on ajoute toutes les chaines possibles a la combo.
			if !listIsNumbered && iSelectedItem == -1 && value == key.AuthorizedValues[k] {
				current = value
				iSelectedItem = k / step
			}

			// 		if (cResult != NULL)
			// 			snprintf (cResult, 9, "%d", k/dk); // dk becomes step

			// 		iExcept = 0;
			// 		if key.IsType(cftype.KeyListNbCtrlSelect) 		{
			// 			iOrder1 = atoi (key.AuthorizedValues[k+1]);
			// 			gchar *str = strchr (key.AuthorizedValues[k+2], ',');
			// 			if (str)  // Note: this mechanism is an addition to the original {first widget, number of widgets}; it's not very generic nor beautiful, but until we need more, it's well enough (currently, only the Dock background needs it).
			// 			{
			// 				*str = '\0';
			// 				iExcept = atoi (str+1);
			// 			}
			// 			iOrder2 = atoi (key.AuthorizedValues[k+2]);
			// 			NbControlled = MAX (NbControlled, iOrder1 + iOrder2 - 1);
			// 			//g_print ("iSelectedItem:%d ; k/dk:%d\n", iSelectedItem , k/dk);
			// 			if (iSelectedItem == (int)k/dk)
			// 			{
			// 				iFirstSensitiveWidget = iOrder1;
			// 				iNbSensitiveWidgets = iOrder2;
			// 				iNonSensitiveWidget = iExcept;
			// 				if (iNonSensitiveWidget != 0)
			// 					NbControlled ++;
			// 			}
			// 		}					else					{
			// 			iOrder1 = iOrder2 = k;
			// 		}

			//
			name := ""
			if key.IsType(cftype.KeyListEntry) {
				name = key.AuthorizedValues[k]
			} else {
				name = key.Translate(key.AuthorizedValues[k])
			}

			list = append(list, datatype.Field{
				Key:  key.AuthorizedValues[k],
				Name: name,
			})
			// 			CAIRO_DOCK_MODEL_ORDER, iOrder1,
			// 			CAIRO_DOCK_MODEL_ORDER2, iOrder2,
			// 			CAIRO_DOCK_MODEL_STATE, iExcept, -1);
		}
	}

	// Current choice wasn't in the list. Select first.
	if current == "" && len(list) > 0 {
		current = list[0].Key
		iSelectedItem = 0
	}

	// Build the combo widget.
	widget, _, getValue, setValue := NewComboBox(key, key.IsType(cftype.KeyListEntry), listIsNumbered, current, list)

	// gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (modele), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);

	// int iNonSensitiveWidget = 0;

	if len(key.AuthorizedValues) > 0 {
		if key.IsType(cftype.KeyListNbCtrlSimple, cftype.KeyListNbCtrlSelect) {
			// 		_allocate_new_buffer;
			// 		data[0] = pKeyBox;
			// 		data[1] = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
			if key.IsType(cftype.KeyListNbCtrlSimple) {
				// 			NbControlled = k;
				// 			data[2] = GINT_TO_POINTER (NbControlled);
				// 			g_signal_connect (G_OBJECT (pOneWidget), "changed", G_CALLBACK (_cairo_dock_select_one_item_in_control_combo), data);
				// 			iFirstSensitiveWidget = iSelectedItem+1;  // on decroit jusqu'a 0.
				// 			iNbSensitiveWidgets = 1;
				// 			//g_print ("CONTROL : %d,%d,%d\n", NbControlled, iFirstSensitiveWidget, iNbSensitiveWidgets);
			} else {
				// 			data[2] = GINT_TO_POINTER (NbControlled);
				// 			g_signal_connect (G_OBJECT (pOneWidget), "changed", G_CALLBACK (_cairo_dock_select_one_item_in_control_combo_selective), data);
				// 			//g_print ("CONTROL : %d,%d,%d\n", NbControlled, iFirstSensitiveWidget, iNbSensitiveWidgets);
			}
			// 		g_object_set_data (G_OBJECT (pKeyBox), "nb-ctrl-widgets", GINT_TO_POINTER (NbControlled));
			// 		g_object_set_data (G_OBJECT (pKeyBox), "one-widget", pOneWidget);
			// 		CDControlWidget *cw = g_new0 (CDControlWidget, 1);
			// 		pControlWidgets = g_list_prepend (pControlWidgets, cw);
			// 		cw->pControlContainer = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
			// 		cw->NbControlled = NbControlled;
			// 		cw->iFirstSensitiveWidget = iFirstSensitiveWidget;
			// 		cw->iNbSensitiveWidgets = iNbSensitiveWidgets;
			// 		cw->iNonSensitiveWidget = iNonSensitiveWidget;
			// 		//g_print (" pControlContainer:%x\n", pControlContainer);
		}
	}
	key.PackKeyWidget(key, getValue, setValue, widget)
}
Ejemplo n.º 7
0
// LaunchCommand adds a launch command widget.
// HELP ONLY
//
func LaunchCommand(key *cftype.Key) {
	if len(key.AuthorizedValues) == 0 || key.AuthorizedValues[0] == "" {
		key.Log().NewErrf("command missing", "widget LaunchCommand: %s", key.Name)
		return
	}
	// log.Info(key.Name, key.AuthorizedValues)

	if key.IsType(cftype.KeyLaunchCmdIf) {

		if len(key.AuthorizedValues) < 2 {
			key.Label().SetSensitive(false)
			return
		}

		key.Log().Info("KeyLaunchCmdIf : disabled for now")
		return

		// key.Log().Info("test", key.AuthorizedValues[1])

		// key.Log().Err(key.Log().ExecShow(key.AuthorizedValues[1]), "exec test")

		// gchar *cSecondCommand = pAuthorizedValuesList[1];
		// gchar *cResult = cairo_dock_launch_command_sync (cSecondCommand);
		// cd_debug ("%s: %s => %s", __func__, cSecondCommand, cResult);
		// if (cResult == NULL || *cResult == '0' || *cResult == '\0')  // result is 'fail'
		// {
		// 	gtk_widget_set_sensitive (pLabel, FALSE);
		// 	g_free (cResult);
		// 	break ;
		// }
		// g_free (cResult);
	}

	spinner := newgtk.Spinner()
	spinner.SetNoShowAll(true)
	key.PackSubWidget(spinner)

	btn := newgtk.ButtonFromIconName("go-jump", gtk.ICON_SIZE_BUTTON)
	key.PackSubWidget(btn)

	btn.Connect("clicked", func() {
		cmd, e := key.Log().ExecShlex(key.AuthorizedValues[0])
		if key.Log().Err(e, "widget LaunchCommand parse command", key.Name, ":", key.AuthorizedValues[0]) {
			return
		}

		e = cmd.Start()
		if key.Log().Err(e, "widget LaunchCommand exec", key.AuthorizedValues[0]) {
			return
		}

		btn.Hide()
		spinner.Show()
		spinner.Start()

		// Wait the external program in a go routine.
		// When finished, restore buttons state in the gtk idle loop.
		go func() {
			cmd.Wait()

			glib.IdleAdd(func() {
				btn.Show()
				spinner.Hide()
				spinner.Stop()
			})
		}()
	})

	// 	G_CALLBACK (_cairo_dock_widget_launch_command),
}
Ejemplo n.º 8
0
// CheckButton adds a check button widget.
//
func CheckButton(key *cftype.Key) {
	if key.NbElements > 1 { // TODO: remove temp test
		key.Log().Info("CheckButton multi", key.NbElements, key.Type.String())
	}

	values := key.Value().ListBool()

	var activers []widgetActiver

	for k := 0; k < key.NbElements; k++ {
		var value bool
		if k < len(values) {
			value = values[k]
		}
		w := newgtk.Switch()
		w.SetActive(value)
		key.PackSubWidget(w)
		activers = append(activers, w)

		if key.IsType(cftype.KeyBoolCtrl) {
			// 		_allocate_new_buffer;
			// 		data[0] = pKeyBox;
			// 		data[1] = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
			// 		if (pAuthorizedValuesList != NULL && pAuthorizedValuesList[0] != NULL)
			// 			NbControlled = g_ascii_strtod (pAuthorizedValuesList[0], NULL);
			// 		else
			// 			NbControlled = 1;
			// 		data[2] = GINT_TO_POINTER (NbControlled);
			// 		if (NbControlled < 0)  // a negative value means that the behavior is inverted.
			// 		{
			// 			bValue = !bValue;
			// 			NbControlled = -NbControlled;
			// 		}
			// 		g_signal_connect (G_OBJECT (pOneWidget), "toggled", G_CALLBACK(_cairo_dock_toggle_control_button), data);

			// 		g_object_set_data (G_OBJECT (pKeyBox), "nb-ctrl-widgets", GINT_TO_POINTER (NbControlled));
			// 		g_object_set_data (G_OBJECT (pKeyBox), "one-widget", pOneWidget);

			// 		if (! bValue)  // les widgets suivants seront inactifs.
			// 		{
			// 			CDControlWidget *cw = g_new0 (CDControlWidget, 1);
			// 			pControlWidgets = g_list_prepend (pControlWidgets, cw);
			// 			cw->iNbSensitiveWidgets = 0;
			// 			cw->NbControlled = NbControlled;
			// 			cw->iFirstSensitiveWidget = 1;
			// 			cw->pControlContainer = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
			// 		}  // sinon le widget suivant est sensitif, donc rien a faire.
		}
	}
	if key.NbElements == 1 {
		key.PackKeyWidget(key,
			func() interface{} { return activers[0].GetActive() },
			func(uncast interface{}) { activers[0].SetActive(uncast.(bool)) },
		)
	} else {
		key.PackKeyWidget(key,
			func() interface{} { return listActiverGet(activers) },
			func(uncast interface{}) { listActiverSet(activers, uncast.([]bool)) },
		)
	}
}
Ejemplo n.º 9
0
// Strings adds a string widget. Many options included.
// TODO: need password cypher, G_USER_DIRECTORY_PICTURES, play sound.
//
func Strings(key *cftype.Key) {
	value := key.Value().String()
	widget := newgtk.Entry()
	widget.SetText(value)

	if key.IsType(cftype.KeyPasswordEntry) { // Hide text and decrypt value.
		widget.SetVisibility(false)
		value = key.Source().DecryptString(value)
	}

	// Pack the widget before any other (in full size if needed).
	// So we do it now and fill the callbacks later
	key.PackKeyWidget(key, nil, nil, widget)
	var setValue func(interface{})

	// 	Add special buttons to fill the entry box.
	switch key.Type {
	case cftype.KeyFileSelector, cftype.KeyFolderSelector,
		cftype.KeySoundSelector, cftype.KeyImageSelector: // Add a file selector.

		fileChooser := newgtk.Button()
		img := newgtk.ImageFromIconName("document-open", gtk.ICON_SIZE_SMALL_TOOLBAR)
		fileChooser.SetImage(img)
		fileChooser.Connect("clicked", onFileChooserOpen, fileChooserData{widget, key})

		key.PackSubWidget(fileChooser)

		if key.IsType(cftype.KeySoundSelector) { //Sound Play Button
			play := newgtk.Button()
			imgPlay := newgtk.ImageFromIconName("media-playback-start", gtk.ICON_SIZE_SMALL_TOOLBAR)
			play.SetImage(imgPlay)

			// play.Connect("clicked", C._cairo_dock_play_a_sound, data)

			key.PackSubWidget(play)
		}

	case cftype.KeyShortkeySelector, cftype.KeyClassSelector: // Add a key/class grabber.
		grab := newgtk.ButtonWithLabel("Grab")
		key.PackSubWidget(grab)
		// 		gtk_widget_add_events(pMainWindow, GDK_KEY_PRESS_MASK);

		switch key.Type {
		case cftype.KeyClassSelector:
			grab.Connect("clicked", func() {
				widget.SetSensitive(false) // Block widgets.
				grab.SetSensitive(false)

				go func() {
					class, e := key.Source().GrabWindowClass() // Wait user selection in a routine.
					glib.IdleAdd(func() {                      // And resync with the GTK loop to display results.

						widget.SetSensitive(true) // Reactivate widgets.
						grab.SetSensitive(true)

						if !key.Log().Err(e, "ClassSelector", key.Group, key.Name) {

							setValue(class) // On success.
							key.Log().Debug("KeyClassSelector window selected", class)
						}
					})
				}()
			})

		case cftype.KeyShortkeySelector:
			grab.Connect("clicked", onKeyGrabClicked, &textGrabData{entry: widget, win: key.Source().GetWindow()})
		}

		// for _, sk := range key.Source().ListShortkeys() {
		// 	if sk.GetConfFilePath() == key.Storage().FilePath() {
		// 		println("found file shortkey")
		// 	}
		// }

	}

	// Display a default value when empty.
	if len(key.AuthorizedValues) > 0 && key.AuthorizedValues[0] != "" {
		defaultText := key.Translate(key.AuthorizedValues[0])
		cbChanged, _ := widget.Connect("changed", onTextDefaultChanged, key)
		data := textDefaultData{key: key, text: defaultText, cbID: cbChanged}
		widget.Connect("focus-in-event", onTextDefaultFocusIn, data)
		widget.Connect("focus-out-event", onTextDefaultFocusOut, data)

		// TODO: check other use of those fields.
		// 	 g_object_set_data (G_OBJECT (pEntry), "ignore-value", GINT_TO_POINTER (TRUE));
		// 	 g_object_set_data (G_OBJECT (pOneWidget), "default-text", cDefaultText);

		context, _ := widget.GetStyleContext()
		context.AddProvider(MainCSS(), gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

		setValue = func(uncast interface{}) {
			// if !key.IsDefault { // not sure why this was here.
			widget.SetText(uncast.(string))
			onTextDefaultFocusOut(widget, nil, data)
		}

		setValue(value) // will set IsDefault and button state.
	} else {
		setValue = func(uncast interface{}) { widget.SetText(uncast.(string)) }
	}
	getValue := func() (text interface{}) {
		if key.IsDefault {
			return ""
		}
		text, _ = widget.GetText()
		return text
	}

	key.PackKeyWidget(key, getValue, setValue)
}
Ejemplo n.º 10
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()
}