示例#1
0
文件: confgui.go 项目: sqp/godock
// NewWidget creates the main Cairo-Dock configuration widget.
//
func NewWidget(source datatype.Source, log cdtype.Logger) *GuiConfigure {
	box := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)

	widget := &GuiConfigure{
		Box:    *box,
		Source: source,

		stack:     newgtk.Stack(),
		btnAction: make(map[string]btnaction.Tune),
		pages:     make(map[string]*Page),
		log:       log,
	}

	// Create widgets.

	widget.Menu = confmenu.New(widget)
	menuIcons := pageswitch.New()
	menuIcons.Set("no-show-all", true)
	menuCore := pageswitch.New()
	menuCore.Set("no-show-all", true)

	// Box for separator on left of menuIcons.
	boxIcons := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	sepIcons := newgtk.Separator(gtk.ORIENTATION_VERTICAL)
	boxIcons.PackStart(sepIcons, false, false, 6)
	boxIcons.PackStart(menuIcons, false, false, 0)
	boxIcons.PackStart(menuCore, false, false, 0)

	widget.mainSwitch = pageswitch.New()

	btnIcons := btnaction.New(widget.Menu.Save)
	btnCore := btnaction.New(widget.Menu.Save)
	btnAdd := btnaction.New(widget.Menu.Save)
	btnAdd.SetAdd()

	icons := conficons.New(widget, log, menuIcons, btnIcons)
	core := confcore.New(widget, log, menuCore, btnCore)
	add := confapplets.New(widget, log, nil, confapplets.ListCanAdd)
	add.Hide() // TODO: REMOVE THE NEED OF THAT.

	// Add pages to the switcher. This will pack the pages widgets to the gui box.

	widget.AddPage(GroupIcons, "", icons, btnIcons, menuIcons.Show, menuIcons.Hide)
	widget.AddPage(GroupAdd, "list-add", add, btnAdd, nil, nil)
	widget.AddPage(GroupConfig, "", core, btnCore, menuCore.Show, menuCore.Hide)

	// Packing menu.

	sep := newgtk.Separator(gtk.ORIENTATION_HORIZONTAL)

	widget.Menu.PackStart(widget.mainSwitch, false, false, 0)
	widget.Menu.PackStart(boxIcons, false, false, 0)

	widget.PackStart(widget.Menu, false, false, 2)
	widget.PackStart(sep, false, false, 0)

	widget.PackStart(widget.stack, true, true, 0)

	return widget
}
示例#2
0
文件: widgets.go 项目: sqp/godock
// Separator adds a simple horizontal separator.
//
func Separator(key *cftype.Key) {
	// GtkWidget *pAlign = gtk_alignment_new (.5, .5, 0.8, 1.);
	// g_object_set (pAlign, "height-request", 12, NULL);
	widget := newgtk.Separator(gtk.ORIENTATION_HORIZONTAL)
	// gtk_container_add (GTK_CONTAINER (pAlign), pOneWidget);
	key.PackWidget(widget, false, false, 0)
}
示例#3
0
文件: widgets.go 项目: sqp/godock
// 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);
	// 			}
	// 		}
	// 	}
	// }
}
示例#4
0
文件: confapplets.go 项目: sqp/godock
// New creates a widget to list cairo-dock applets and themes.
//
func New(control GUIControl, log cdtype.Logger, menu MenuDownloader, mode ListMode) *ConfApplet {
	mainbox := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)

	widget := &ConfApplet{
		Box:     *mainbox,
		menu:    menu,
		preview: appletpreview.New(log),
		control: control,
		log:     log,
		mode:    mode,
	}
	var preview gtk.IWidget = widget.preview

	switch widget.mode {
	case ListCanAdd:
		widget.applets = appletlist.NewListAdd(widget, log)
		widget.preview.HideState()
		widget.preview.HideSize()

	case ListExternal:
		widget.applets = appletlist.NewListExternal(widget, log)

		widget.preview.Load(&datatype.HandbookSimple{
			Title:  "Download applets page",
			Author: tran.Slate("Cairo-Dock contributors"),
			// Preview: "",
			Description: `Here, you can download external applets from the repository.
They will be directly activated after the download

You can also find them on the <a href="http://glx-dock.org/mc_album.php?a=12">Repository website</a>`,
		})

		if menu == nil { // Menu not provided, pack one above the preview.
			menu := NewMenuDownload(log)
			widget.menu = menu
			box := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
			box.PackStart(menu, false, false, 2)
			box.PackStart(newgtk.Separator(gtk.ORIENTATION_HORIZONTAL), false, false, 2)
			box.PackStart(preview, true, true, 2)

			preview = box
		}

	case ListThemes:
		widget.applets = appletlist.NewListThemes(widget, log)

		widget.preview.Load(&datatype.HandbookSimple{
			Title:  "Download themes page",
			Author: tran.Slate("Cairo-Dock contributors"),
			// Preview: "",
			Description: "Here, you can download full dock themes from the repository.",
		})
	}

	inbox := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)

	widget.PackStart(inbox, true, true, 0)
	inbox.PackStart(widget.applets, false, false, 0)
	inbox.PackStart(preview, true, true, 4)
	widget.ShowAll()
	return widget
}