Exemplo n.º 1
0
// New creates the config menu with add or save buttons.
//
func New(control Controller) *MenuBar {
	wmb := &MenuBar{
		Box:     *newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0),
		Save:    newgtk.ButtonWithMnemonic("_Save"),
		control: control,
	}

	wmb.Save.Set("no-show-all", true)

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

	/// Actions
	wmb.Save.Connect("clicked", wmb.control.ClickedSave)

	mainBtn, _ := gtk.MenuButtonNew()

	img := newgtk.ImageFromIconName("preferences-system", IconSize)
	mainBtn.SetImage(img)

	mainBtn.SetPopup(menus.NewMenu(
		menus.NewItem(tran.Slate("Help"), func() { control.Select("Config", "Help") }),
		menus.NewItem(tran.Slate("About"), func() { about.New() }),
		nil,
		menus.NewItem(tran.Slate("Close"), wmb.control.ClickedQuit),
	))

	/// Packing: End list = reversed.

	wmb.PackEnd(mainBtn, false, false, 0)
	wmb.PackEnd(sep, false, false, 3) // separator add 3x2px.
	wmb.PackEnd(wmb.Save, false, false, 0)
	return wmb
}
Exemplo n.º 2
0
// 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
}
Exemplo n.º 3
0
// addBoxItem adds an item to the list.
//
func (widget *List) addBoxItem(icon datatype.Iconer, indent int, bold bool) *gtk.ListBoxRow {
	row := newgtk.ListBoxRow()
	box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	row.Add(box)

	name, img := icon.DefaultNameIcon()

	box.Set("margin-start", 15*indent)
	if bold {
		name = common.Bold(name)
	}
	if img != "" {
		if pix, e := common.ImageNewFromFile(img, iconSize); !widget.log.Err(e, "Load icon") {
			box.PackStart(pix, false, false, 0)
		}
	}
	lbl := newgtk.Label(name)
	lbl.SetUseMarkup(true)
	box.PackStart(lbl, false, false, 0)

	widget.list.Add(row)
	widget.index[row] = icon

	return row
}
Exemplo n.º 4
0
Arquivo: about.go Projeto: sqp/godock
func addLinks() *gtk.Box {
	linksData := []struct {
		uri     string
		label   string
		tooltip string
	}{{
		uri:   URLdockSite,
		label: "Cairo-Dock (2007-2014)", //GLDI_VERSION;
	}, {
		uri:     URLdockCode,
		label:   tran.Slate("Development site"),
		tooltip: tran.Slate("Find the latest version of Cairo-Dock here !"),
	}, {
		uri:     URLdockFlattr,
		label:   tran.Slate("Donate") + " (Flattr)",
		tooltip: tran.Slate("Support the people who spend countless hours to bring you the best dock ever."),
	}, {
		uri:     URLdockPayPal,
		label:   tran.Slate("Donate") + " (Paypal)",
		tooltip: tran.Slate("Support the people who spend countless hours to bring you the best dock ever."),
	}}

	box := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
	for _, item := range linksData {
		link := newgtk.LinkButtonWithLabel(item.uri, item.label)
		box.PackStart(link, false, false, 0)
		if item.tooltip != "" {
			link.SetTooltipText(item.tooltip)
		}
	}
	return box
}
Exemplo n.º 5
0
Arquivo: dialog.go Projeto: sqp/godock
func dialogWidgetScale(data cdtype.DialogWidgetScale) (*gtk.Widget, func() interface{}) {
	step := (data.MaxValue - data.MinValue) / 100
	scale := newgtk.ScaleWithRange(gtk.ORIENTATION_HORIZONTAL, data.MinValue, data.MaxValue, step)
	scale.SetValue(data.InitialValue)
	scale.Set("digits", data.NbDigit)
	scale.Set("width-request", 150)
	scale.GrabFocus()

	// C.gldi_dialog_set_widget_text_color((*C.GtkWidget)(unsafe.Pointer(scale.Native()))) // WTF ???

	getValue := func() interface{} { return scale.GetValue() }

	if data.MinLabel == "" && data.MaxLabel == "" {
		return &scale.Widget, getValue
	}

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

	box.PackStart(newgtk.Label(data.MinLabel), false, false, 0)
	box.PackStart(scale, false, false, 0)
	box.PackStart(newgtk.Label(data.MaxLabel), false, false, 0)

	// 	GtkWidget *pAlign = gtk_alignment_new (1., 1., 0., 0.); // used alignments for labels
	return &box.Widget, getValue
}
Exemplo n.º 6
0
func packWindow(win *gtk.Window, source vdata.Sourcer, build cftype.Grouper) func() {
	return func() {
		win.SetDefaultSize(winWidth, winHeight)
		win.SetTitle(winTitle)
		win.SetIconFromFile(source.AppIcon())
		win.Connect("destroy", gtk.MainQuit)

		// widgets.
		box := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
		source.SetBox(box)

		menu := confmenu.New(source)
		switcher := pageswitch.New()
		w := build.BuildAll(switcher)

		btnAdd := btnaction.New(menu.Save)
		btnAdd.SetTest()

		btnHack := newgtk.ButtonWithLabel("Hack")
		btnHack.Connect("clicked", func() { build.KeyWalk(vdata.TestValues) })

		menu.PackStart(switcher, false, false, 0)
		menu.PackEnd(btnHack, false, false, 0)
		win.Add(box)
		box.PackStart(menu, false, false, 0)
		box.PackStart(w, true, true, 0)
		win.ShowAll()
	}
}
Exemplo n.º 7
0
Arquivo: menus.go Projeto: sqp/godock
// NewButtonsEntry creates a menu entry with buttons management.
//
func NewButtonsEntry(text string) *ButtonsEntry {
	be := &ButtonsEntry{
		MenuItem: *newgtk.MenuItem(),
		box:      newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 1),
		label:    newgtk.Label(text),
	}

	// Packing.
	be.Add(be.box)
	be.box.PackStart(be.label, false, false, 0)

	// Forward click to inside buttons.
	be.Connect("button-press-event", be.onMenuItemPress)

	// Highlight pointed button.
	be.Connect("motion-notify-event", be.onMenuItemMotionNotify)

	// Turn off highlight pointed button when we leave the menu-item.
	// if we leave it quickly, a motion event won't be generated.
	be.Connect("leave-notify-event", be.onMenuItemLeave)

	// Force the label to not highlight.
	// it gets highlighted, even if we overwrite the motion_notify_event callback.
	be.Connect("enter-notify-event", be.onMenuItemEnter)

	// We don't want to higlighted the whole menu-item , but only the currently
	// pointed button; so we draw the menu-item ourselves, with a propagate to
	// childs and intercept signal.
	be.Connect("draw", func(_ *gtk.MenuItem, cr *cairo.Context) bool {
		be.PropagateDraw(be.box, cr)
		return true
	})

	return be
}
Exemplo n.º 8
0
// New creates a switcher box to handle page switching.
//
func New() *Switcher {
	box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	context, _ := box.GetStyleContext()
	context.AddClass("linked")

	return &Switcher{
		Box:   *box,
		pages: make(map[string]*Page),
	}
}
Exemplo n.º 9
0
// NewBuilder creates a configuration page builder from a config storage.
//
func NewBuilder(source cftype.Source, log cdtype.Logger, conf cftype.Storage, originalConf, gettextDomain string) cftype.Builder {
	return &builder{
		Box:           *newgtk.Box(gtk.ORIENTATION_VERTICAL, 0),
		conf:          conf,
		data:          source,
		log:           log,
		originalConf:  originalConf,
		gettextDomain: gettextDomain,
	}
}
Exemplo n.º 10
0
// BuildPage builds a Cairo-Dock configuration widget for the given group.
//
func (build *builder) BuildPage(group string) cftype.GtkWidgetBase {
	// gconstpointer *data;
	// gsize length = 0;
	// gchar **pKeyList;

	// GtkWidget *pOneWidget;
	// GSList * pSubWidgetList;
	// GtkWidget *pSmallVBox;
	// GtkWidget *pEntry;
	// GtkWidget *pTable;
	// GtkWidget *pButtonAdd, *pButtonRemove;
	// GtkWidget *pButtonDown, *pButtonUp;
	// GtkWidget *pButtonFileChooser, *pButtonPlay;
	// GtkWidget *pScrolledWindow;
	// GtkWidget *pToggleButton=NULL;
	// GtkCellRenderer *rend;
	// GtkTreeIter iter;
	// GtkTreeSelection *selection;
	// GtkWidget *pBackButton;
	// GList *pControlWidgets = NULL;
	// int iFirstSensitiveWidget = 0, iNbSensitiveWidgets = 0;
	// gchar *cKeyName, *cKeyComment, **pAuthorizedValuesList;
	// const gchar *cUsefulComment, *cTipString;
	// CairoDockGroupKeyWidget *pGroupKeyWidget;
	// int j;
	// guint k, iNbElements;
	// char iType;
	// gboolean bValue, *bValueList;
	// int iValue, iMinValue, iMaxValue, *iValueList;
	// double fValue, fMinValue, fMaxValue, *fValueList;
	// gchar *cValue, **cValueList, *cSmallIcon=NULL;
	// GtkListStore *modele;
	// gboolean bAddBackButton;
	// GtkWidget *pPreviewBox;

	build.pageBox = newgtk.Box(gtk.ORIENTATION_VERTICAL, cftype.MarginGUI)
	build.pageBox.SetBorderWidth(cftype.MarginGUI)

	build.pFrameVBox = nil

	build.NbControlled = 0

	// FRAMES ONLY
	build.pFrame = nil

	for _, key := range build.buildKeys[group] {
		build.buildKey(key)
	}
	pageScroll := newgtk.ScrolledWindow(nil, nil)
	pageScroll.Add(build.pageBox)
	return pageScroll
}
Exemplo n.º 11
0
// NewMenuDownload creates the menu to control the selected applet.
//
func NewMenuDownload(log cdtype.Logger) *MenuDownload {
	widget := &MenuDownload{
		Box:       *newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0),
		installed: newgtk.Switch(),
		active:    newgtk.Switch(),
		log:       log,
	}

	// Actions
	var e error
	widget.handlerInstalled, e = widget.installed.Connect("notify::active", widget.toggledInstalled)
	log.Err(e, "Connect installed button callback")
	widget.handlerActive, e = widget.active.Connect("notify::active", widget.toggledActive)
	log.Err(e, "Connect active button callback")

	widget.PackStart(newgtk.Label("Installed"), false, false, 4)
	widget.PackStart(widget.installed, false, false, 0)
	widget.PackStart(newgtk.Box(gtk.ORIENTATION_VERTICAL, 0), false, false, 8)
	widget.PackStart(newgtk.Label("Active"), false, false, 4)
	widget.PackStart(widget.active, false, false, 0)
	return widget
}
Exemplo n.º 12
0
Arquivo: about.go Projeto: sqp/godock
func notebookPage(nb *gtk.Notebook, label, contentStr string, contentArgs []interface{}) {
	tabLabel := newgtk.Label(label)
	box := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
	scroll := newgtk.ScrolledWindow(nil, nil)
	scroll.Add(box)
	nb.AppendPage(scroll, tabLabel)

	content := fmt.Sprintf(contentStr, contentArgs...)
	contentLabel := newgtk.Label(content)
	contentLabel.SetUseMarkup(true)
	box.PackStart(contentLabel, false, false, 15)

	nb.PopupEnable()
}
Exemplo n.º 13
0
// New creates a GuiIcons widget to edit cairo-dock icons config.
//
func New(data cftype.Source, log cdtype.Logger, switcher *pageswitch.Switcher, btn btnaction.Tune) *GuiIcons {
	paned := newgtk.Paned(gtk.ORIENTATION_HORIZONTAL)
	widget := &GuiIcons{
		Paned:    *paned,
		switcher: switcher,
		btn:      btn,
		data:     data,
		log:      log,
	}
	widget.icons = NewList(widget, log)

	up := newgtk.ButtonFromIconName("go-up", gtk.ICON_SIZE_BUTTON)
	down := newgtk.ButtonFromIconName("go-down", gtk.ICON_SIZE_BUTTON)
	remove := newgtk.ButtonFromIconName("list-remove", gtk.ICON_SIZE_BUTTON)

	boxLeft := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
	boxBtns := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	boxLeft.PackStart(widget.icons, true, true, 0)
	boxLeft.PackStart(boxBtns, false, false, 0)
	boxBtns.PackStart(up, false, false, 0)
	boxBtns.PackStart(down, false, false, 0)
	boxBtns.PackEnd(remove, false, false, 0)

	widget.Pack1(boxLeft, true, true)

	widget.SetPosition(listIconsWidth) // Paned position = list icons width.

	up.Connect("clicked", widget.actionSelected(datatype.Iconer.MoveBeforePrevious))
	down.Connect("clicked", widget.actionSelected(datatype.Iconer.MoveAfterNext))
	remove.Connect("clicked", widget.actionSelected(datatype.Iconer.RemoveFromDock))

	// widget.icons.Connect("row-inserted", func() { log.Info("row inserted") })
	// widget.icons.Connect("row-deleted", func() { log.Info("row deleted") })

	return widget
}
Exemplo n.º 14
0
Arquivo: others.go Projeto: sqp/godock
// WrapKeyScale wraps a key scale with its information labels if needed (enough values).
//
// (was _pack_hscale).
func WrapKeyScale(key *cftype.Key, child *gtk.Scale) gtk.IWidget {
	child.Set("width-request", 150)
	if len(key.AuthorizedValues) >= 4 {

		child.Set("value-pos", gtk.POS_TOP)
		// log.DEV("MISSING SubScale options", string(key.Type), key.AuthorizedValues)
		box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
		// 	GtkWidget * pAlign = gtk_alignment_new(1., 1., 0., 0.)
		labelLeft := newgtk.Label(key.Translate(key.AuthorizedValues[2]))
		// 	pAlign = gtk_alignment_new(1., 1., 0., 0.)
		labelRight := newgtk.Label(key.Translate(key.AuthorizedValues[3]))

		box.PackStart(labelLeft, false, false, 0)
		box.PackStart(child, false, false, 0)
		box.PackStart(labelRight, false, false, 0)
		return box
	}
	child.Set("value-pos", gtk.POS_LEFT)
	return child
}
Exemplo n.º 15
0
func dialogAskBackend() {
	// Need to keep the string as it is for translation.
	str := "OpenGL allows you to use the hardware acceleration, reducing the CPU load to the minimum.\nIt also allows some pretty visual effects similar to Compiz.\nHowever, some cards and/or their drivers don't fully support it, which may prevent the dock from running correctly.\nDo you want to activate OpenGL ?\n (To not show this dialog, launch the dock from the Application menu,\n  or with the -o option to force OpenGL and -c to force cairo.)"

	dialog := newgtk.Dialog()
	dialog.SetTitle(tran.Slate("Use OpenGL in Cairo-Dock"))
	dialog.AddButton(tran.Slate("Yes"), gtk.RESPONSE_YES)
	dialog.AddButton(tran.Slate("No"), gtk.RESPONSE_NO)

	labelTxt := newgtk.Label(tran.Slate(str))

	content, _ := dialog.GetContentArea()
	content.PackStart(labelTxt, false, false, 0)

	askBox := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 3)
	content.PackStart(askBox, false, false, 0)

	labelSave := newgtk.Label(tran.Slate("Remember this choice"))
	check := newgtk.CheckButton()
	askBox.PackEnd(check, false, false, 0)
	askBox.PackEnd(labelSave, false, false, 0)

	dialog.ShowAll()

	answer := dialog.Run() // has its own main loop, so we can call it before gtk_main.
	remember := check.GetActive()
	dialog.Destroy()

	if answer == int(gtk.RESPONSE_NO) {
		gldi.GLBackendDeactivate()
	}

	if remember { // save user choice to file.
		value := ternary.String(gtk.ResponseType(answer) == gtk.RESPONSE_YES, "opengl", "cairo")
		updateHiddenFile("default backend", value)
	}
}
Exemplo n.º 16
0
Arquivo: about.go Projeto: sqp/godock
// New creates a GuiIcons widget to edit cairo-dock icons config.
//
func New() *About {
	// GtkWidget *pDialog = gtk_dialog_new_with_buttons (_(""),
	// 	GTK_WINDOW (pContainer->pWidget),
	// 	GTK_DIALOG_DESTROY_WITH_PARENT,
	// 	GLDI_ICON_NAME_CLOSE,
	// 	GTK_RESPONSE_CLOSE,
	// 	NULL);

	dialog := newgtk.Dialog()
	dialog.SetTitle(tran.Slate("About Cairo-Dock"))
	// dialog.SetParentWindow(parentWindow)
	dialog.AddButton(tran.Slate("_Close"), gtk.RESPONSE_CLOSE)
	dialog.Connect("response", dialog.Destroy)

	// Widgets.
	image := newgtk.ImageFromFile(Img)
	notebook := addNotebook()
	links := addLinks()

	// Packing.
	header := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	header.PackStart(image, false, false, 0)
	header.PackStart(links, false, false, 0)

	content, _ := dialog.GetContentArea()
	content.PackStart(header, false, false, 0)
	content.PackStart(notebook, true, true, 0)

	dialog.Resize(AboutWidth, AboutHeight) // had check min size compared to desktop size...
	dialog.ShowAll()

	//don't use gtk_dialog_run(), as we don't want to block the dock
	dialog.SetKeepAbove(true)

	return (*About)(dialog)
}
Exemplo n.º 17
0
func boxWidget(widget gtk.IWidget) *gtk.Box {
	box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	box.PackStart(widget, false, false, 0)
	return box
}
Exemplo n.º 18
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);
	// 			}
	// 		}
	// 	}
	// }
}
Exemplo n.º 19
0
// Frame adds a simple or expanded frame widget.
//
func Frame(key *cftype.Key) {
	if len(key.AuthorizedValues) == 0 {
		key.SetFrame(nil)
		key.SetFrameBox(nil)
		return
	}

	value, img := "", ""
	if key.AuthorizedValues[0] == "" {
		key.Log().Info("WidgetFrame, need value case 1")
		// value = g_key_file_get_string(pKeyFile, cGroupName, cKeyName, NULL) // utile ?
	} else {
		value = key.AuthorizedValues[0]
		if len(key.AuthorizedValues) > 1 {
			img = key.AuthorizedValues[1]
		}
	}

	// Create the frame label with the optional icon.
	label := newgtk.Label("")
	// key.SetLabel(label)
	label.SetMarkup(" " + common.Bold(key.Translate(value)) + " ")

	var labelContainer gtk.IWidget
	if img == "" {
		labelContainer = label
	} else {
		box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, cftype.MarginIcon/2)
		if icon, e := common.ImageNewFromFile(img, iconSizeFrame); !key.Log().Err(e, "Frame icon") { // TODO: fix size : int(gtk.ICON_SIZE_MENU)
			box.Add(icon)
		}
		box.Add(label)
		labelContainer = box
	}

	// Create the box that will contain next widgets (inside the frame).
	box := newgtk.Box(gtk.ORIENTATION_VERTICAL, cftype.MarginGUI)
	key.SetFrameBox(box)

	frame := newgtk.Frame("")
	key.SetFrame(frame)
	frame.SetBorderWidth(cftype.MarginGUI)
	frame.SetShadowType(gtk.SHADOW_OUT)
	frame.Add(box)

	// Set label and create the expander around the frame if needed.
	switch key.Type {
	case cftype.KeyFrame:
		frame.SetLabelWidget(labelContainer)
		key.BoxPage().PackStart(frame, false, false, 0)

	case cftype.KeyExpander:
		expand := newgtk.Expander("")
		expand.SetExpanded(false)
		expand.SetLabelWidget(labelContainer)

		expand.Add(frame)
		key.BoxPage().PackStart(expand, false, false, 0)
	}

	// SAME AS IN builder.go

	// 	if (pControlWidgets != NULL)
	// 	{
	// 		cd_debug ("ctrl\n");
	// 		CDControlWidget *cw = pControlWidgets->data;
	// 		if (cw->pControlContainer == key.Box)
	// 		{
	// 			cd_debug ("ctrl (NbControlled:%d, iFirstSensitiveWidget:%d, iNbSensitiveWidgets:%d)", cw->NbControlled, cw->iFirstSensitiveWidget, cw->iNbSensitiveWidgets);
	// 			cw->NbControlled --;
	// 			if (cw->iFirstSensitiveWidget > 0)
	// 				cw->iFirstSensitiveWidget --;
	// 			cw->iNonSensitiveWidget --;

	// 			GtkWidget *w = pExternFrame;
	// 			if (cw->iFirstSensitiveWidget == 0 && cw->iNbSensitiveWidgets > 0 && cw->iNonSensitiveWidget != 0)
	// 			{
	// 				cd_debug (" => sensitive\n");
	// 				cw->iNbSensitiveWidgets --;
	// 				if (GTK_IS_EXPANDER (w))
	// 					gtk_expander_set_expanded (GTK_EXPANDER (w), TRUE);
	// 			}
	// 			else
	// 			{
	// 				cd_debug (" => 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);
	// 			}
	// 		}
	// 	}
}
Exemplo n.º 20
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()
}
Exemplo n.º 21
0
// 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
}