-
Notifications
You must be signed in to change notification settings - Fork 0
/
activate.R
102 lines (75 loc) · 2.36 KB
/
activate.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#' Flag a record as being active
#'
#' This allows an easy mechanism to edit particular records without specifying them each time.
#'
#' @param gedcom A tidyged object.
#' @param xref The xref of the record to activate.
#'
#' @return The same tidyged object with an "active_record" attribute set to the xref of the record
set_active_record <- function(gedcom, xref) {
if(length(xref) > 0) attr(gedcom, "active_record") <- xref
gedcom
}
#' Get the active record in a tidyged object
#'
#' @param gedcom A tidyged object.
#' @return The xref of the active record.
#'
#' @export
active_record <- function(gedcom) {
attr(gedcom, "active_record")
}
null_active_record <- function(gedcom) {
attr(gedcom, "active_record") <- NULL
gedcom
}
#' Activate a record
#'
#' Set a specific record to be the active record.
#'
#' @param gedcom A tidyged object.
#' @param record The xref of the record to be activated.
#'
#' @return The same tidyged object with "active_record" attribute set to the specific
#' record to allow easy editing.
#' @export
activate_indi <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_indi, is_indi)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_famg <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_famg, is_famg)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_subm <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_subm, is_subm)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_media <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_obje, is_media)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_note <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_note, is_note)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_sour <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_sour, is_sour)
set_active_record(gedcom, xref)
}
#' @rdname activate_indi
#' @export
activate_repo <- function(gedcom, record) {
xref <- get_valid_xref(gedcom, record, .pkgenv$record_string_repo, is_repo)
set_active_record(gedcom, xref)
}