コード例 #1
0
ファイル: others.go プロジェクト: sqp/godock
// 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
}
コード例 #2
0
ファイル: widgets.go プロジェクト: sqp/godock
// 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)
}
コード例 #3
0
ファイル: others.go プロジェクト: sqp/godock
// 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
}
コード例 #4
0
ファイル: widgets.go プロジェクト: sqp/godock
// 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)
}