Ejemplo n.º 1
0
static void on_menu_cache_reload(MenuCache* mc, gpointer user_data)
{
    g_return_if_fail(store);
    gtk_tree_store_clear(store);
    MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache);
    /* FIXME: preserve original selection */
    if(dir)
        add_menu_items(NULL, dir);
}
Ejemplo n.º 2
0
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir)
{
    GtkTreeIter it;
    GSList * l;
    GIcon* gicon;
    /* Iterate over all menu items in this directory. */
    for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next)
    {
        /* Get the menu item. */
        MenuCacheItem* item = MENU_CACHE_ITEM(l->data);
        switch(menu_cache_item_get_type(item))
        {
            case MENU_CACHE_TYPE_NONE:
            case MENU_CACHE_TYPE_SEP:
                break;
            case MENU_CACHE_TYPE_APP:
            case MENU_CACHE_TYPE_DIR:
                if(menu_cache_item_get_icon(item))
                {
                    if(g_path_is_absolute(menu_cache_item_get_icon(item)))
                    {
                        GFile* gf = g_file_new_for_path(menu_cache_item_get_icon(item));
                        gicon = g_file_icon_new(gf);
                        g_object_unref(gf);
                    }
                    else
                    {
                        char* dot = strrchr((char*)menu_cache_item_get_icon(item), '.');
                        if(dot && (strcmp(dot+1, "png") == 0 || strcmp(dot+1, "svg") == 0 || strcmp(dot+1, "xpm") == 0))
                        {
                            char* name = g_strndup(menu_cache_item_get_icon(item), dot - menu_cache_item_get_icon(item));
                            gicon = g_themed_icon_new(name);
                            g_free(name);
                        }
                        else
                            gicon = g_themed_icon_new(menu_cache_item_get_icon(item));
                    }
                }
                else
                    gicon = NULL;
                gtk_tree_store_append(store, &it, parent_it);
                gtk_tree_store_set(store, &it,
                                   COL_ICON, gicon,
                                   COL_TITLE, menu_cache_item_get_name(item),
                                   COL_ITEM, item, -1);
                if(gicon)
                    g_object_unref(gicon);

                if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR)
                    add_menu_items(&it, MENU_CACHE_DIR(item));
                break;
        }
    }
}
Ejemplo n.º 3
0
void activate_refresh (GtkMenuItem *menu, gpointer data) {
    struct program_options  options;

    if (menu == NULL && data == NULL) {
        /* Bogus condition to use parameters */
        ;
    }
/*    remove_menu_items();*/
    get_configuration(&options);
    if (options.menu_items != NULL) {
        add_menu_items(options.menu_items);
    }
}
Ejemplo n.º 4
0
/* called with lock held */
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir)
{
    GtkTreeIter it;
    GSList * l;
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    GSList *list;
#endif
    GIcon* gicon;
    /* Iterate over all menu items in this directory. */
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    for (l = list = menu_cache_dir_list_children(dir); l != NULL; l = l->next)
#else
    for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next)
#endif
    {
        /* Get the menu item. */
        MenuCacheItem* item = MENU_CACHE_ITEM(l->data);
        switch(menu_cache_item_get_type(item))
        {
            case MENU_CACHE_TYPE_NONE:
            case MENU_CACHE_TYPE_SEP:
                break;
            case MENU_CACHE_TYPE_APP:
            case MENU_CACHE_TYPE_DIR:
                if(menu_cache_item_get_icon(item))
                    gicon = G_ICON(fm_icon_from_name(menu_cache_item_get_icon(item)));
                else
                    gicon = NULL;
                gtk_tree_store_append(store, &it, parent_it);
                gtk_tree_store_set(store, &it,
                                   COL_ICON, gicon,
                                   COL_TITLE, menu_cache_item_get_name(item),
                                   COL_ITEM, item, -1);
                if(gicon)
                    g_object_unref(gicon);

                if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR)
                    add_menu_items(&it, MENU_CACHE_DIR(item));
                break;
        }
    }
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    g_slist_free_full(list, (GDestroyNotify)menu_cache_item_unref);
#endif
}
Ejemplo n.º 5
0
GtkWidget *fm_app_menu_view_new(void)
{
    GtkWidget* view;
    GtkTreeViewColumn* col;
    GtkCellRenderer* render;

    if(!store)
    {
        static GType menu_cache_item_type = 0;
        if(G_UNLIKELY(!menu_cache_item_type))
            menu_cache_item_type = g_boxed_type_register_static("MenuCacheItem", 
                                            (GBoxedCopyFunc)menu_cache_item_ref,
                                            (GBoxedFreeFunc)menu_cache_item_unref);
        store = gtk_tree_store_new(N_COLS, G_TYPE_ICON, /*GDK_TYPE_PIXBUF, */G_TYPE_STRING, menu_cache_item_type);
        g_object_weak_ref(G_OBJECT(store), (GWeakNotify)destroy_store, NULL);

        menu_cache = menu_cache_lookup("applications.menu");
        if(menu_cache)
        {
            MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache);
            menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, on_menu_cache_reload, NULL);
            if(dir) /* content of menu is already loaded */
                add_menu_items(NULL, dir);
        }
    }
    else
        g_object_ref(store);

    view = gtk_tree_view_new_with_model((GtkTreeModel*)store);

    render = gtk_cell_renderer_pixbuf_new();
    col = gtk_tree_view_column_new();
    gtk_tree_view_column_set_title(col, _("Installed Applications"));
    gtk_tree_view_column_pack_start(col, render, FALSE);
    gtk_tree_view_column_set_attributes(col, render, "gicon", COL_ICON, NULL);

    render = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(col, render, TRUE);
    gtk_tree_view_column_set_attributes(col, render, "text", COL_TITLE, NULL);

    gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);

    g_object_unref(store);
    return view;
}
Ejemplo n.º 6
0
static void on_menu_cache_reload(gpointer mc, gpointer user_data)
#endif
{
    g_return_if_fail(store);
    gtk_tree_store_clear(store);
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    MenuCacheDir* dir = menu_cache_dup_root_dir(mc);
#else
    MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache);
#endif
    /* FIXME: preserve original selection */
    if(dir)
    {
        add_menu_items(NULL, dir);
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
        menu_cache_item_unref(MENU_CACHE_ITEM(dir));
#endif
    }
}
Ejemplo n.º 7
0
static CMenu *make_menu(const CXmlTree::CElt &current_elt, int &item_no)
{
	CMenu * retval = new CMenu;
	retval->CreatePopupMenu();
	ASSERT(prev_defined.size() == 0);   // Make sure the list is cleared

	// There is no point in doing siblings of IF/SWITCH since only one element actually
	// exists - ie, if we are evaluating an element then the siblings will not exist.
	if (current_elt.GetParent().GetName() == "if" || current_elt.GetParent().GetName() == "switch")
		return retval;

	// Check all "older" siblings
	CXmlTree::CElt ee = current_elt;
	for (ee--; !ee.IsEmpty(); ee--)
	{
		add_menu_items(retval, item_no, ee, "");
	}

	prev_defined.clear();
	return retval;
}
Ejemplo n.º 8
0
/**
 * fm_app_menu_view_new
 *
 * Creates new application tree widget.
 *
 * Returns: (transfer full): a new widget.
 *
 * Since: 0.1.0
 */
GtkTreeView *fm_app_menu_view_new(void)
{
    GtkTreeView* view;
    GtkTreeViewColumn* col;
    GtkCellRenderer* render;

    if(!store)
    {
        static GType menu_cache_item_type = 0;
        char* oldenv;
        if(G_UNLIKELY(!menu_cache_item_type))
            menu_cache_item_type = g_boxed_type_register_static("MenuCacheItem",
                                            (GBoxedCopyFunc)menu_cache_item_ref,
                                            (GBoxedFreeFunc)menu_cache_item_unref);
        store = gtk_tree_store_new(N_COLS, G_TYPE_ICON, /*GDK_TYPE_PIXBUF, */G_TYPE_STRING, menu_cache_item_type);
        g_object_weak_ref(G_OBJECT(store), destroy_store, NULL);

        /* ensure that we're using lxmenu-data */
        oldenv = g_strdup(g_getenv("XDG_MENU_PREFIX"));
        g_setenv("XDG_MENU_PREFIX", "lxde-", TRUE);
        menu_cache = menu_cache_lookup("applications.menu");
        if(oldenv)
        {
            g_setenv("XDG_MENU_PREFIX", oldenv, TRUE);
            g_free(oldenv);
        }
        else
            g_unsetenv("XDG_MENU_PREFIX");

        if(menu_cache)
        {
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
            MenuCacheDir* dir = menu_cache_dup_root_dir(menu_cache);
#else
            MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache);
#endif
            menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, on_menu_cache_reload, NULL);
            if(dir) /* content of menu is already loaded */
            {
                add_menu_items(NULL, dir);
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
                menu_cache_item_unref(MENU_CACHE_ITEM(dir));
#endif
            }
        }
    }
    else
        g_object_ref(store);

    view = (GtkTreeView*)gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));

    render = gtk_cell_renderer_pixbuf_new();
    col = gtk_tree_view_column_new();
    gtk_tree_view_column_set_title(col, _("Installed Applications"));
    gtk_tree_view_column_pack_start(col, render, FALSE);
    gtk_tree_view_column_set_attributes(col, render, "gicon", COL_ICON, NULL);

    render = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(col, render, TRUE);
    gtk_tree_view_column_set_attributes(col, render, "text", COL_TITLE, NULL);

    gtk_tree_view_append_column(view, col);

    g_object_unref(store);
    return view;
}
Ejemplo n.º 9
0
// Make a whole menu system that shows all the variables that can be accessed
// by an element in an expression.
// Returns a pointer to a CMenu that must be destroyed and freed, unless NULL
// is returned in which case no variables were found.
CMenu *make_var_menu_tree(const CXmlTree::CElt &current_elt, bool this_too /*=false*/, bool file_too /*=false*/)
{
	int item_no = 1;

	// Get sibling items
	CMenu *retval = make_menu(current_elt, item_no);

	// Add "this" if required
	if (this_too)
	{
		ASSERT(current_elt.GetName() != "if" && current_elt.GetName() != "switch");
		ASSERT(current_elt.GetNumChildren() <= 1);
		ASSERT(prev_defined.size() == 0);   // Make sure the list is cleared
		if (current_elt.GetNumChildren() > 0)
			add_menu_items(retval, item_no, current_elt.GetFirstChild(), _T("this"));
		else
			retval->AppendMenu(MF_ENABLED, item_no++, _T("this"));
		prev_defined.clear();
	}

	// Added in 3.5 - ability to use file values (cursor, mark, eof) in expressions
	if (file_too)
	{
		CMenu * submenu = new CMenu;
		submenu->CreatePopupMenu();

		submenu->AppendMenu(MF_ENABLED, item_no++, _T("cursor"));
		submenu->AppendMenu(MF_ENABLED, item_no++, _T("mark"));
		submenu->AppendMenu(MF_ENABLED, item_no++, _T("eof"));
		retval->AppendMenu(MF_POPUP, (UINT)submenu->m_hMenu, _T("From File"));
	}

	// Now check each ancestor in turn and add sub-menu (if not empty)
	CXmlTree::CElt ee;                  // Node of ancestor (starting with parent)
	int ii;                             // Keep track of which ancestor (1 = parent)
	for (ee = current_elt.GetParent(), ii = 1;
		 ee.GetName() != "binary_file_format";
		 ee = ee.GetParent(), ++ii )
	{
		CMenu *submenu = make_menu(ee, item_no);
		if (submenu->GetMenuItemCount() > 0)
		{
			// Add this menu as a submenu (popup)
			CString submenu_name;
			if (ii == 1)
				submenu_name = "Parent siblings";
			else if (ii == 2)
				submenu_name = "Grandparent siblings";
			else
				submenu_name.Format("Ancestor [%d] siblings", ii);

			retval->AppendMenu(MF_POPUP, (UINT)submenu->m_hMenu, submenu_name);
		}
		else
			submenu->DestroyMenu();
		delete submenu;
	}

	// If we added nothing just put a dummy (disabled) menu item in there
	if (retval->GetMenuItemCount() == 0)
		retval->AppendMenu(MF_GRAYED, -1, _T("No values available"));

	return retval;
}
Ejemplo n.º 10
0
// Static functions used by make_var_menu_tree (below)
static void add_menu_items(CMenu *pmenu, int &item_no, const CXmlTree::CElt &current_elt, CString name)
{
	CString ss = current_elt.GetName();    // type of this node

	// Add element name unless parent is FOR (or we are IF/SWITCH/JUMP which use child name)
	if (ss != "if" && ss != "switch" && ss != "jump" && name.Right(1) != "]")
		name += current_elt.GetAttr("name");

	if (ss == "data")
	{
		pmenu->AppendMenu(MF_ENABLED, item_no++, name);
	}
	else if (ss == "for")
	{
		// Add array access operator [] and add item(s) for sub-element
		ASSERT(current_elt.GetNumChildren() <= 1);                              // May be zero for new elt
		if (current_elt.GetNumChildren() > 0)
			add_menu_items(pmenu, item_no, current_elt.GetFirstChild(), name+"[ ]");
	}
	else if (ss == "struct")
	{
		// Add items for all sub-elements of the struct
		for (CXmlTree::CElt ee = current_elt.GetFirstChild(); !ee.IsEmpty(); ++ee)
		{
			add_menu_items(pmenu, item_no, ee, name+".");
		}
	}
	else if (ss == "use_struct")
	{
		CString ss = current_elt.GetAttr("type_name");            // Find struct name to use
		CXmlTree::CElt ee = current_elt.GetOwner()->GetRoot().GetFirstChild();
		for ( ; !ee.IsEmpty() && ee.GetName() == "define_struct"; ++ee)
			if (ss == ee.GetAttr("type_name"))
			{
				// Check if recursive call to same defined struct
				for (std::vector<CString>::const_iterator ps = prev_defined.begin(); ps != prev_defined.end(); ++ps)
				{
					if (*ps == ss)
						return;    // avoid recursion into same define_struct
				}
				prev_defined.push_back(ss);

				// Add items for all sub-elements of the struct
				for (CXmlTree::CElt ee2 = ee.GetFirstChild(); !ee2.IsEmpty(); ++ee2)
				{
					add_menu_items(pmenu, item_no, ee2, name+".");
				}
				break;    // Found the (hopefully) only one with the correct name
			}
	}
	else if (ss == "if")
	{
		if (current_elt.GetNumChildren() > 0)
			add_menu_items(pmenu, item_no, current_elt.GetFirstChild(), name);
		if (current_elt.GetNumChildren() > 1)
		{
			// Add a separate item for the else part
			ASSERT(current_elt.GetNumChildren() == 3 && current_elt.GetChild(1).GetName() == "else");
			add_menu_items(pmenu, item_no, current_elt.GetChild(2), name);
		}
	}
	else if (ss == "switch")
	{
		// Add names of all case sub-elements
		CStringList found;      // just used to eliminate duplicate data elts
		for (CXmlTree::CElt ee = current_elt.GetFirstChild(); !ee.IsEmpty(); ++ee)
		{
			ASSERT(ee.GetName() == "case");
			if (ee.GetFirstChild().GetName() == "data")
			{
				CString ss = ee.GetFirstChild().GetAttr("name");
				if (!ss.IsEmpty())
				{
					if (found.Find(ss) != NULL)
						continue;           // ignore data elements with the same name
					else
						found.AddTail(ss);  // store this one for later checks
				}
			}
			add_menu_items(pmenu, item_no, ee.GetFirstChild(), name);
		}
	}
	else if (ss == "jump")
	{
		if (current_elt.GetNumChildren() > 0)
			add_menu_items(pmenu, item_no, current_elt.GetFirstChild(), name);
	}
	else if (ss == "define_struct" || ss == "eval")
	{
		// Do nothing here
	}
	else
		ASSERT(0);
}
Ejemplo n.º 11
0
static gboolean trw_layer_waypoint_menu_popup ( GtkWidget *tree_view,
                                                GdkEventButton *event,
                                                gpointer data )
{
	static GtkTreeIter iter;

	// Use selected item to get a single iterator ref
	// This relies on an row being selected as part of the right click
	GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(tree_view) );
	if ( gtk_tree_selection_count_selected_rows (selection) != 1 )
		return FALSE;

	GtkTreePath *path;
	GtkTreeModel *model = gtk_tree_view_get_model ( GTK_TREE_VIEW(tree_view) );

	// All this just to get the iter
	if ( gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(tree_view),
	                                     (gint) event->x,
	                                     (gint) event->y,
	                                     &path, NULL, NULL, NULL)) {
		gtk_tree_model_get_iter_from_string ( model, &iter, gtk_tree_path_to_string (path) );
		gtk_tree_path_free ( path );
	}
	else
		return FALSE;

	VikWaypoint *wpt;
	gtk_tree_model_get ( model, &iter, WPT_COL_NUM, &wpt, -1 );
	if ( !wpt ) return FALSE;

	VikTrwLayer *vtl;
	gtk_tree_model_get ( model, &iter, TRW_COL_NUM, &vtl, -1 );
	if ( !IS_VIK_TRW_LAYER(vtl) ) return FALSE;

	wpu_udata udataU;
	udataU.wp   = wpt;
	udataU.uuid = NULL;

	gpointer *wptf;
	wptf = g_hash_table_find ( vik_trw_layer_get_waypoints(vtl), (GHRFunc) trw_layer_waypoint_find_uuid, &udataU );

	if ( wptf && udataU.uuid ) {
		VikViewport *vvp = vik_window_viewport((VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)));

		GtkWidget *menu = gtk_menu_new();

		// Originally started to reuse the trw_layer menu items
		//  however these offer too many ways to edit the waypoint data
		//  so without an easy way to distinguish read only operations,
		//  create a very minimal new set of operations
		add_menu_items ( GTK_MENU(menu),
		                 vtl,
		                 wpt,
		                 udataU.uuid,
		                 vvp,
		                 tree_view,
		                 data );

		gtk_menu_popup ( GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, gtk_get_current_event_time() );
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 12
0
void NotebookApplicationAddin::on_new_notebook_menu_shown()
{
    add_menu_items(m_mainWindowNotebookMenu, m_mainWindowNotebookMenuItems);
}
Ejemplo n.º 13
0
void NotebookApplicationAddin::on_tray_notebook_menu_shown()
{
    add_menu_items(m_trayNotebookMenu, m_trayNotebookMenuItems);
}
Ejemplo n.º 14
0
int main (int argc, char *argv[]) {
#ifdef GUI
    void               *status;
    char                path[256];
    pthread_t           thr_menu;
#endif

    /*
     * Program setup
     *     Handle user interrupt and alarm
     *     Get program options
     *     Open report file for logging if needed
     *     Initialize UI
     */
    signal(SIGINT, handle_break);
    signal(SIGALRM, handle_alarm);
    alarm(1);

    get_configuration(&opts);
    if (parse_options(argc, argv, &opts)) {
        return 1;
    }
    if (opts.save_options) {
        save_configuration(&opts);
    }

    if (opts.text_out) {
        report = fopen(opts.filename, "a");
        if(report == NULL) {
            report = stdout;
        }
    }

    init_idle();
    init_winmgmt(&opts);
    window_state_init(&current);
#ifdef GUI
    get_executable_path(path, sizeof(path));
    init_indicator(argc, argv, path, &opts);
    if (opts.menu_items != NULL) {
        add_menu_items(opts.menu_items);
    }
    fflush(NULL);
    pthread_create(&thr_menu, NULL, run_indicator, &current.force);
#endif
    if (opts.use_database) {
        open_database(opts.dbname);
    }

    while(poll_continue || current.force) {
        sleep(1);                       /* Just wait for program close */
    }
    /*
     * Clean up
     */
    alarm(1);                           /* Last hurrah */
    sleep(1);
#ifdef GUI
    pthread_join(thr_menu, &status);
#endif
    if (report != stdout && opts.text_out) {
        fclose(report);
    }
    if (opts.use_database) {
        close_database();
    }
    return 0;
}