wlmaker
Loading...
Searching...
No Matches
item.c File Reference
#include "item.h"
#include <stdlib.h>
#include <string.h>
#include <libbase/libbase.h>
#include <libbase/plist.h>
Include dependency graph for item.c:

Classes

struct  wlmtool_item
struct  wlmtool_menu
struct  wlmtool_entry

Functions

static void _wlmtool_item_destroy_dlnode (bs_dllist_node_t *dlnode_ptr, void *ud_ptr)
static int _wlmtool_item_cmp (const bs_avltree_node_t *node_ptr, const void *key_ptr)
static int _wlmtool_item_dlnode_cmp (const bs_dllist_node_t *n1, const bs_dllist_node_t *n2)
static bool _wlmtool_item_dlnode_add_to_array (bs_dllist_node_t *dlnode_ptr, void *ud_ptr)
static void _wlmtool_menu_destroy_item (struct wlmtool_item *item_ptr)
static bspl_array_t * _wlmtool_menu_create_array (struct wlmtool_item *item_ptr)
static void _wlmtool_entry_destroy (struct wlmtool_item *item_ptr)
static bspl_array_t * _wlmtool_entry_create_array (struct wlmtool_item *item_ptr)
void wlmtool_item_destroy (struct wlmtool_item *item_ptr)
bspl_array_t * wlmtool_item_create_array (struct wlmtool_item *item_ptr)
struct wlmtool_menuwlmtool_menu_create (const char *title_ptr)
struct wlmtool_itemwlmtool_item_from_menu (struct wlmtool_menu *menu_ptr)
bool wlmtool_menu_add_item (struct wlmtool_menu *menu_ptr, struct wlmtool_item *item_ptr)
struct wlmtool_menuwlmtool_menu_get_or_create_submenu (struct wlmtool_menu *menu_ptr, const void *key_ptr)
struct wlmtool_itemwlmtool_file_action_create (const char *title_ptr, const char *action_ptr, const char *resolved_path_ptr)
struct wlmtool_itemwlmtool_entry_create (const char *key_ptr, const char **args_ptr)
static void _wlmaker_item_test_create (bs_test_t *test_ptr)
static void _wlmaker_item_test_array (bs_test_t *test_ptr)

Variables

static const bs_test_case_t _wlmtool_item_test_cases []
const bs_test_set_t wlmtool_item_test_set

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmaker_item_test_array()

void _wlmaker_item_test_array ( bs_test_t * test_ptr)
static

Tests plist array creation.

◆ _wlmaker_item_test_create()

void _wlmaker_item_test_create ( bs_test_t * test_ptr)
static

Tests item creation and destruction.

◆ _wlmtool_entry_create_array()

bspl_array_t * _wlmtool_entry_create_array ( struct wlmtool_item * item_ptr)
static
Returns
A plist array for the entry, or NULL on error.

◆ _wlmtool_entry_destroy()

void _wlmtool_entry_destroy ( struct wlmtool_item * item_ptr)
static

Implements wlmtool_item::destroy. Dtor for the entry.

◆ _wlmtool_item_cmp()

int _wlmtool_item_cmp ( const bs_avltree_node_t * node_ptr,
const void * key_ptr )
static

Comparator for the AVL tree.

◆ _wlmtool_item_destroy_dlnode()

void _wlmtool_item_destroy_dlnode ( bs_dllist_node_t * dlnode_ptr,
void * ud_ptr )
static

Callback for bs_dllist_each(), destroy the item at dlnode_ptr.

◆ _wlmtool_item_dlnode_add_to_array()

bool _wlmtool_item_dlnode_add_to_array ( bs_dllist_node_t * dlnode_ptr,
void * ud_ptr )
static

Creates array from item at dlnode_ptr and adds to array at ud_ptr.

◆ _wlmtool_item_dlnode_cmp()

int _wlmtool_item_dlnode_cmp ( const bs_dllist_node_t * n1,
const bs_dllist_node_t * n2 )
static

Comparator for the double-linked list.

◆ _wlmtool_menu_create_array()

bspl_array_t * _wlmtool_menu_create_array ( struct wlmtool_item * item_ptr)
static

Creates a plist array representing the menu and it's items.

Note
The menu's items will be sorted, meaning: will change order.
Parameters
item_ptr
Returns
the plist array, or NULL on error.

◆ _wlmtool_menu_destroy_item()

void _wlmtool_menu_destroy_item ( struct wlmtool_item * item_ptr)
static

Implements wlmtool_item::destroy.

◆ wlmtool_entry_create()

struct wlmtool_item * wlmtool_entry_create ( const char * key_ptr,
const char ** args_ptr )

Adds a menu entry.

Parameters
key_ptrKey that is expected unique within the submenu.
args_ptrNULL-terminted array to build the entry from.
Returns
Menu item, or NULL on error.

◆ wlmtool_file_action_create()

struct wlmtool_item * wlmtool_file_action_create ( const char * title_ptr,
const char * action_ptr,
const char * resolved_path_ptr )

Creates a "file action" menu item.

Parameters
title_ptrTitle to use for the menu entry.
action_ptrAction command to use.
resolved_path_ptrFully resolved path to the file to act on.
Returns
Menu item, or NULL on error.

◆ wlmtool_item_create_array()

bspl_array_t * wlmtool_item_create_array ( struct wlmtool_item * item_ptr)

Returns a plist array representing the item (or menu).

◆ wlmtool_item_destroy()

void wlmtool_item_destroy ( struct wlmtool_item * item_ptr)

Destroys the item.

◆ wlmtool_item_from_menu()

struct wlmtool_item * wlmtool_item_from_menu ( struct wlmtool_menu * menu_ptr)
Returns
the parent item handle for the menu.

◆ wlmtool_menu_add_item()

bool wlmtool_menu_add_item ( struct wlmtool_menu * menu_ptr,
struct wlmtool_item * item_ptr )

Adds an item to the menu.

Adds an item to this menu.

Parameters
menu_ptr
item_ptrThe item to add. The menu will take ownership.
Returns
true on success.

◆ wlmtool_menu_create()

struct wlmtool_menu * wlmtool_menu_create ( const char * title_ptr)

Creates a menu.

Parameters
title_ptr
Returns
The menu, or NULL on failure. To release associates, the function wlmtool_item_destroy must be called, on the menu's item (
See also
wlmtool_item_from_menu).

◆ wlmtool_menu_get_or_create_submenu()

struct wlmtool_menu * wlmtool_menu_get_or_create_submenu ( struct wlmtool_menu * menu_ptr,
const void * key_ptr )

Returns a submenu for key, if it exists. If not, create it.

Obtain (or create) the submenu with the provided key within a menu.

Parameters
menu_ptr
key_ptr
Returns
The submenu, or NULL on error.

Variable Documentation

◆ _wlmtool_item_test_cases

const bs_test_case_t _wlmtool_item_test_cases[]
static
Initial value:
= {
{ true, "create", _wlmaker_item_test_create },
{ true, "array", _wlmaker_item_test_array },
BS_TEST_CASE_SENTINEL(),
}
static void _wlmaker_item_test_array(bs_test_t *test_ptr)
Definition item.c:413
static void _wlmaker_item_test_create(bs_test_t *test_ptr)
Definition item.c:384

Test cases for the menu item classes.

◆ wlmtool_item_test_set

const bs_test_set_t wlmtool_item_test_set
Initial value:
= BS_TEST_SET(
static const bs_test_case_t _wlmtool_item_test_cases[]
Definition item.c:373

Unit tests for the menu item classes.