Ejemplo n.º 1
0
static gboolean
toggle_tag_selection(GntBindable *bind, GList *null)
{
	GntFileSel *sel = GNT_FILE_SEL(bind);
	char *str;
	GList *find;
	char *file;
	GntWidget *tree;

	if (!sel->multiselect)
		return FALSE;
	tree = sel->dirsonly ? sel->dirs : sel->files;
	if (!gnt_widget_has_focus(tree) ||
			gnt_tree_is_searching(GNT_TREE(tree)))
		return FALSE;

	file = gnt_tree_get_selection_data(GNT_TREE(tree));

	str = gnt_file_sel_get_selected_file(sel);
	if ((find = g_list_find_custom(sel->tags, str, (GCompareFunc)g_utf8_collate)) != NULL) {
		g_free(find->data);
		sel->tags = g_list_delete_link(sel->tags, find);
		gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_NORMAL);
		g_free(str);
	} else {
		sel->tags = g_list_prepend(sel->tags, str);
		gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_BOLD);
	}

	gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "move-down", NULL);

	return TRUE;
}
Ejemplo n.º 2
0
static gboolean
dir_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
{
	if (strcmp(key, "\r") == 0 || strcmp(key, "\n") == 0) {
		char *str = g_strdup(gnt_tree_get_selection_data(tree));
		char *path, *dir;

		if (!str)
			return TRUE;
		
		path = g_build_filename(sel->current, str, NULL);
		dir = g_path_get_basename(sel->current);
		if (!gnt_file_sel_set_current_location(sel, path)) {
			gnt_tree_set_selected(tree, str);
		} else if (strcmp(str, "..") == 0) {
			gnt_tree_set_selected(tree, dir);
		}
		gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "end-search", NULL);
		g_free(dir);
		g_free(str);
		g_free(path);
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 3
0
static gboolean
gnt_entry_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
{
	if (event == GNT_MIDDLE_MOUSE_DOWN) {
		clipboard_paste(GNT_BINDABLE(widget), NULL);
		return TRUE;
	}
	return FALSE;

}
Ejemplo n.º 4
0
static gboolean
suggest_prev_page(GntBindable *bind, GList *null)
{
	GntEntry *entry = GNT_ENTRY(bind);
	if (entry->ddown) {
		gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "page-up", NULL);
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 5
0
static gboolean
suggest_show(GntBindable *bind, GList *null)
{
	GntEntry *entry = GNT_ENTRY(bind);
	if (entry->ddown) {
		gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-down", NULL);
		return TRUE;
	}
	return show_suggest_dropdown(entry);
}
Ejemplo n.º 6
0
static void
assign_triggers(GntMenu *menu)
{
	GList *iter;
	gboolean bools[37];

	memset(bools, 0, sizeof(bools));
	bools[36] = 1;

	for (iter = menu->list; iter; iter = iter->next) {
		GntMenuItem *item = iter->data;
		char trigger = tolower(gnt_menuitem_get_trigger(item));
		if (trigger == '\0' || trigger == ' ')
			continue;
		bools[(int)GET_VAL(trigger)] = 1;
	}

	for (iter = menu->list; iter; iter = iter->next) {
		GntMenuItem *item = iter->data;
		char trigger = gnt_menuitem_get_trigger(item);
		const char *text = item->text;
		if (trigger != '\0')
			continue;
		while (*text) {
			char ch = tolower(*text++);
			char t[2] = {ch, '\0'};
			if (ch == ' ' || bools[(int)GET_VAL(ch)] || gnt_bindable_check_key(GNT_BINDABLE(menu), t))
				continue;
			trigger = ch;
			break;
		}
		if (trigger == 0)
			trigger = item->text[0];
		gnt_menuitem_set_trigger(item, trigger);
		bools[(int)GET_VAL(trigger)] = 1;
	}
}
Ejemplo n.º 7
0
static void
exit_confirmed(gpointer null)
{
	gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "wm-quit", NULL);
}
Ejemplo n.º 8
0
static gboolean
refresh_screen(void)
{
	gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL);
	return FALSE;
}
Ejemplo n.º 9
0
/**
 * Mouse support:
 *  - bring a window on top if you click on its taskbar
 *  - click on the top-bar of the active window and drag+drop to move a window
 *  - click on a window to bring it to focus
 *   - allow scrolling in tree/textview on wheel-scroll event
 *   - click to activate button or select a row in tree
 *  wishlist:
 *   - have a little [X] on the windows, and clicking it will close that window.
 */
static gboolean
detect_mouse_action(const char *buffer)
{
	int x, y;
	static enum {
		MOUSE_NONE,
		MOUSE_LEFT,
		MOUSE_RIGHT,
		MOUSE_MIDDLE
	} button = MOUSE_NONE;
	static GntWidget *remember = NULL;
	static int offset = 0;
	GntMouseEvent event;
	GntWidget *widget = NULL;
	PANEL *p = NULL;

	if (!wm->cws->ordered || buffer[0] != 27)
		return FALSE;

	buffer++;
	if (strlen(buffer) < 5)
		return FALSE;

	x = buffer[3];
	y = buffer[4];
	if (x < 0)	x += 256;
	if (y < 0)	y += 256;
	x -= 33;
	y -= 33;

	while ((p = panel_below(p)) != NULL) {
		const GntNode *node = panel_userptr(p);
		GntWidget *wid;
		if (!node)
			continue;
		wid = node->me;
		if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) {
			if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) {
				widget = wid;
				break;
			}
		}
	}

	if (strncmp(buffer, "[M ", 3) == 0) {
		/* left button down */
		/* Bring the window you clicked on to front */
		/* If you click on the topbar, then you can drag to move the window */
		event = GNT_LEFT_MOUSE_DOWN;
	} else if (strncmp(buffer, "[M\"", 3) == 0) {
		/* right button down */
		event = GNT_RIGHT_MOUSE_DOWN;
	} else if (strncmp(buffer, "[M!", 3) == 0) {
		/* middle button down */
		event = GNT_MIDDLE_MOUSE_DOWN;
	} else if (strncmp(buffer, "[M`", 3) == 0) {
		/* wheel up*/
		event = GNT_MOUSE_SCROLL_UP;
	} else if (strncmp(buffer, "[Ma", 3) == 0) {
		/* wheel down */
		event = GNT_MOUSE_SCROLL_DOWN;
	} else if (strncmp(buffer, "[M#", 3) == 0) {
		/* button up */
		event = GNT_MOUSE_UP;
	} else
		return FALSE;

	if (widget && gnt_wm_process_click(wm, event, x, y, widget))
		return TRUE;

	if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window &&
			!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) {
		if (widget != wm->cws->ordered->data) {
			gnt_wm_raise_window(wm, widget);
		}
		if (y == widget->priv.y) {
			offset = x - widget->priv.x;
			remember = widget;
			button = MOUSE_LEFT;
		}
	} else if (event == GNT_MOUSE_UP) {
		if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) {
			/* Clicked on the taskbar */
			int n = g_list_length(wm->cws->list);
			if (n) {
				int width = getmaxx(stdscr) / n;
				gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL);
			}
		} else if (button == MOUSE_LEFT && remember) {
			x -= offset;
			if (x < 0)	x = 0;
			if (y < 0)	y = 0;
			gnt_screen_move_widget(remember, x, y);
		}
		button = MOUSE_NONE;
		remember = NULL;
		offset = 0;
	}

	if (widget)
		gnt_widget_clicked(widget, event, x, y);
	return TRUE;
}
Ejemplo n.º 10
0
static gboolean
gnt_menu_key_pressed(GntWidget *widget, const char *text)
{
	GntMenu *menu = GNT_MENU(widget);
	guint current = menu->selected;

	if (menu->submenu) {
		GntMenu *sub = menu;
		do sub = sub->submenu; while (sub->submenu);
		if (gnt_widget_key_pressed(GNT_WIDGET(sub), text))
			return TRUE;
		if (menu->type != GNT_MENU_TOPLEVEL)
			return FALSE;
	}

	if ((text[0] == 27 && text[1] == 0) ||
			(menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) {
		/* Escape closes menu */
		GntMenu *par = menu->parentmenu;
		if (par != NULL) {
			par->submenu = NULL;
			gnt_widget_hide(widget);
		} else
			gnt_widget_hide(widget);
		if (par && par->type == GNT_MENU_TOPLEVEL)
			gnt_menu_key_pressed(GNT_WIDGET(par), text);
		return TRUE;
	}

	if (menu->type == GNT_MENU_TOPLEVEL) {
		GntMenuItem *item;
		GList *it;
		if (strcmp(text, GNT_KEY_LEFT) == 0) {
			do {
				if (menu->selected == 0)
					menu->selected = g_list_length(menu->list) - 1;
				else
					menu->selected--;
				it = g_list_nth(menu->list, menu->selected);
				item = it ? it->data : NULL;
			} while (!gnt_menuitem_is_visible(item));
		} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
			do {
				menu->selected++;
				if (menu->selected >= g_list_length(menu->list))
					menu->selected = 0;
				it = g_list_nth(menu->list, menu->selected);
				item = it ? it->data : NULL;
			} while (!gnt_menuitem_is_visible(item));
		} else if (strcmp(text, GNT_KEY_ENTER) == 0 ||
				strcmp(text, GNT_KEY_DOWN) == 0) {
			gnt_widget_activate(widget);
		}

		if (current != menu->selected) {
			GntMenu *sub = menu->submenu;
			if (sub)
				gnt_widget_hide(GNT_WIDGET(sub));
			show_submenu(menu);
			gnt_widget_draw(widget);
			return TRUE;
		}
	} else {
		if (text[1] == '\0') {
			if (check_for_trigger(menu, text[0]))
				return TRUE;
		} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
			GntMenuItem *item = gnt_tree_get_selection_data(GNT_TREE(menu));
			if (item && item->submenu) {
				menuitem_activate(menu, item);
				return TRUE;
			}
		}
		if (gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text))
			return TRUE;
		return org_key_pressed(widget, text);
	}

	return gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text);
}