Exemple #1
0
// NewComboBox creates a combo box.
//
func NewComboBox(key *cftype.Key, withEntry, numbered bool, current string, list []datatype.Field) (
	widget *gtk.ComboBox, model *gtk.ListStore, getValue func() interface{}, setValue func(interface{})) {

	model = newModelSimple()
	// gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(modele), CAIRO_DOCK_MODEL_NAME, GTK_SORT_ASCENDING)

	widget = newgtk.ComboBoxWithModel(model)
	renderer := newgtk.CellRendererText()
	widget.PackStart(renderer, true)
	widget.AddAttribute(renderer, "text", RowName)

	// Fill and set current.
	iter := fillModelWithFields(key, model, list, current, nil)
	widget.SetActiveIter(iter)

	switch {
	case withEntry: // get and set the entry content string.
		entry := newgtk.Entry() // Add entry manually so we don't have to recast a GetChild
		entry.SetText(current)
		widget.Add(entry)
		widget.Set("id-column", RowName)
		widget.Connect("changed", func() { entry.SetText(widget.GetActiveID()) })
		getValue = func() interface{} { v, _ := entry.GetText(); return v }
		setValue = func(uncast interface{}) { entry.SetText(uncast.(string)) }

	case numbered: // get and set selected as position int
		getValue = func() interface{} { return widget.GetActive() }
		setValue = func(uncast interface{}) { widget.SetActive(uncast.(int)) }

	default: // get and set selected as content string
		widget.Set("id-column", RowKey)
		getValue = func() interface{} { return widget.GetActiveID() }
		setValue = func(uncast interface{}) {
			newID := datatype.ListFieldsIDByName(list, uncast.(string), key.Log())
			widget.SetActive(newID)
		}
	}

	return
}
Exemple #2
0
// ListDock adds a dock list widget.
//
func ListDock(key *cftype.Key) {
	// Get current Icon name if its a Subdock.
	iIconType, _ := key.Storage().Int(key.Group, "Icon Type")
	SubdockName := ""
	if iIconType == cftype.UserIconStack { // it's a stack-icon
		SubdockName, _ = key.Storage().String(key.Group, "Name") // It's a subdock, get its name to remove the selection of a recursive position (inside itself).
	}

	list := key.Source().ListDocks("", SubdockName) // Get the list of available docks. Keep parent, but remove itself from the list.
	list = append(list, datatype.Field{
		Key:  datatype.KeyNewDock,
		Name: tran.Slate("New main dock")},
	)

	model := newModelSimple()
	current := key.Value().String()

	if current == "" {
		current = datatype.KeyMainDock
	}

	model.SetSortColumnId(RowName, gtk.SORT_ASCENDING)
	widget := newgtk.ComboBoxWithModel(model)
	renderer := newgtk.CellRendererText()
	widget.PackStart(renderer, false)
	widget.AddAttribute(renderer, "text", RowName)

	saved := indexiter.NewByString(widget, key.Log())
	iter := fillModelWithFields(key, model, list, current, saved)
	widget.SetActiveIter(iter)

	key.PackKeyWidget(key,
		getValueListCombo(widget, model, key.Log()),
		func(uncast interface{}) { saved.SetActive(uncast.(string)) },
		widget)
}
Exemple #3
0
// NewComboBoxWithModel adds a combo box with the given model (can be nil).
//
// _add_combo_from_modele
// used do/while. find why
func NewComboBoxWithModel(model *gtk.ListStore, log cdtype.Logger, bAddPreviewWidgets, bWithEntry, bHorizontalPackaging bool) (
	widget *gtk.ComboBox, getValue func() interface{}) {

	if model == nil {
		// TODO: need the one with entry.
		combo := newgtk.ComboBox()
		getValue = func() interface{} { v := combo.GetActive(); return v }

		widget = combo
		return
	}
	if bWithEntry {
		widget := newgtk.ComboBoxWithEntry()
		widget.SetModel(model)
	} else {

		combo := newgtk.ComboBoxWithModel(model)
		renderer := newgtk.CellRendererText()
		combo.PackStart(renderer, false)
		combo.AddAttribute(renderer, "text", RowName)

		getValue = getValueListCombo(combo, model, log)

		widget = combo
	}
	if bAddPreviewWidgets {
		// pPreviewBox = cairo_dock_gui_make_preview_box(pMainWindow, pOneWidget, bHorizontalPackaging, 1, NULL, NULL, pDataGarbage)
		// fullSize := bWithEntry || bHorizontalPackaging
		// gtk_box_pack_start (GTK_BOX (pAdditionalItemsVBox ? pAdditionalItemsVBox : pKeyBox), pPreviewBox, fullSize, fullSize, 0);
	}
	// cValue = g_key_file_get_string(pKeyFile, cGroupName, cKeyName, NULL)
	// if _cairo_dock_find_iter_from_name(model, cValue, &iter) {
	// 	gtk_combo_box_set_active_iter(GTK_COMBO_BOX(pOneWidget), &iter)
	// }
	return
}
Exemple #4
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);
	// 			}
	// 		}
	// 	}
	// }
}
Exemple #5
0
// ListIconsMainDock adds an icon list widget.
//
func ListIconsMainDock(key *cftype.Key) {
	// {
	// 	if (g_pMainDock == NULL) // maintenance mode... no dock, no icons
	// 	{
	// 		cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, NULL);

	// 		pOneWidget = gtk_entry_new ();
	// 		gtk_entry_set_text (GTK_ENTRY (pOneWidget), cValue); // if there is a problem, we can edit it.
	// 		_pack_subwidget (pOneWidget);

	// 		g_free (cValue);
	// 		break;
	// 	}

	//

	//

	current := key.Value().String()
	model := newModelSimple()
	widget := newgtk.ComboBoxWithModel(model)

	rp := newgtk.CellRendererPixbuf()
	widget.PackStart(rp, false)
	widget.AddAttribute(rp, "pixbuf", RowIcon)

	renderer := newgtk.CellRendererText()
	widget.PackStart(renderer, true)
	widget.AddAttribute(renderer, "text", RowName)

	list := key.Source().ListIconsMainDock()
	saved := indexiter.NewByString(widget, key.Log())
	iter := fillModelWithFields(key, model, list, current, saved)
	widget.SetActiveIter(iter)

	//

	// 	// build the modele and combo
	// 	modele = _cairo_dock_gui_allocate_new_model ();
	// 	pOneWidget = gtk_combo_box_new_with_model (GTK_TREE_MODEL (modele));
	// 	rend = gtk_cell_renderer_pixbuf_new ();
	// 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (pOneWidget), rend, FALSE);
	// 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (pOneWidget), rend, "pixbuf", CAIRO_DOCK_MODEL_ICON, NULL);
	// 	rend = gtk_cell_renderer_text_new ();
	// 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (pOneWidget), rend, FALSE);
	// 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (pOneWidget), rend, "text", CAIRO_DOCK_MODEL_NAME, NULL);
	// 	_pack_subwidget (pOneWidget);

	// 	// get the dock
	// 	CairoDock *pDock = NULL;
	// 	if (pAuthorizedValuesList != NULL && pAuthorizedValuesList[0] != NULL)
	// 		pDock = gldi_dock_get (pAuthorizedValuesList[0]);
	// 	if (!pDock)
	// 		pDock = g_pMainDock;

	// 	// insert each icon
	// 	cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, NULL);
	// 	gint iDesiredIconSize = cairo_dock_search_icon_size (GTK_ICON_SIZE_LARGE_TOOLBAR); // 24 by default
	// 	GtkTreeIter iter;
	// 	Icon *pIcon;
	// 	gchar *cImagePath, *cID;
	// 	const gchar *cName;
	// 	GdkPixbuf *pixbuf;
	// 	GList *ic;
	// 	for (ic = pDock->icons; ic != NULL; ic = ic->next)
	// 	{
	// 		pIcon = ic->data;
	// 		if (pIcon->cDesktopFileName != NULL
	// 		|| pIcon->pModuleInstance != NULL)
	// 		{
	// 			pixbuf = NULL;
	// 			cImagePath = NULL;
	// 			cName = NULL;

	// 			// get the ID
	// 			if (pIcon->cDesktopFileName != NULL)
	// 				cID = pIcon->cDesktopFileName;
	// 			else
	// 				cID = pIcon->pModuleInstance->cConfFilePath;

	// 			// get the image
	// 			if (pIcon->cFileName != NULL)
	// 			{
	// 				cImagePath = cairo_dock_search_icon_s_path (pIcon->cFileName, iDesiredIconSize);
	// 			}
	// 			if (cImagePath == NULL || ! g_file_test (cImagePath, G_FILE_TEST_EXISTS))
	// 			{
	// 				g_free (cImagePath);
	// 				if (GLDI_OBJECT_IS_SEPARATOR_ICON (pIcon))
	// 				{
	// 					if (myIconsParam.cSeparatorImage)
	// 						cImagePath = cairo_dock_search_image_s_path (myIconsParam.cSeparatorImage);
	// 				}
	// 				else if (CAIRO_DOCK_IS_APPLET (pIcon))
	// 				{
	// 					cImagePath = g_strdup (pIcon->pModuleInstance->pModule->pVisitCard->cIconFilePath);
	// 				}
	// 				else
	// 				{
	// 					cImagePath = cairo_dock_search_image_s_path (CAIRO_DOCK_DEFAULT_ICON_NAME);
	// 					if (cImagePath == NULL || ! g_file_test (cImagePath, G_FILE_TEST_EXISTS))
	// 					{
	// 						g_free (cImagePath);
	// 						cImagePath = g_strdup (GLDI_SHARE_DATA_DIR"/icons/"CAIRO_DOCK_DEFAULT_ICON_NAME);
	// 					}
	// 				}
	// 			}
	// 			//g_print (" + %s\n", cImagePath);
	// 			if (cImagePath != NULL)
	// 			{
	// 				pixbuf = gdk_pixbuf_new_from_file_at_size (cImagePath, iDesiredIconSize, iDesiredIconSize, NULL);
	// 			}
	// 			//g_print (" -> %p\n", pixbuf);

	// 			// get the name
	// 			if (CAIRO_DOCK_IS_USER_SEPARATOR (pIcon))  // separator
	// 				cName = "---------";
	// 			else if (CAIRO_DOCK_IS_APPLET (pIcon))  // applet
	// 				cName = pIcon->pModuleInstance->pModule->pVisitCard->cTitle;
	// 			else  // launcher
	// 				cName = (pIcon->cInitialName ? pIcon->cInitialName : pIcon->cName);

	// 			// store the icon
	// 			memset (&iter, 0, sizeof (GtkTreeIter));
	// 			gtk_list_store_append (GTK_LIST_STORE (modele), &iter);
	// 			gtk_list_store_set (GTK_LIST_STORE (modele), &iter,
	// 				CAIRO_DOCK_MODEL_NAME, cName,
	// 				CAIRO_DOCK_MODEL_RESULT, cID,
	// 				CAIRO_DOCK_MODEL_ICON, pixbuf, -1);
	// 			g_free (cImagePath);
	// 			if (pixbuf)
	// 				g_object_unref (pixbuf);

	// 			if (cValue && strcmp (cValue, cID) == 0)
	// 				gtk_combo_box_set_active_iter (GTK_COMBO_BOX (pOneWidget), &iter);
	// 		}
	// 	}
	// 	g_free (cValue);
	// }

	key.PackKeyWidget(key,
		getValueListCombo(widget, model, key.Log()),
		func(uncast interface{}) { saved.SetActive(uncast.(string)) },
		widget)
}