Mercurial > octave-nkf
comparison src/graphics.cc @ 9585:06b8b51dca48
also handle user-defined graphics properties in new property name validation scheme
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 28 Aug 2009 18:37:31 -0400 |
parents | 0fcbfddaa87f |
children | dfc68e6d8741 |
comparison
equal
deleted
inserted
replaced
9584:0fcbfddaa87f | 9585:06b8b51dca48 |
---|---|
64 // Check to see that PNAME matches just one of PNAMES uniquely. | 64 // Check to see that PNAME matches just one of PNAMES uniquely. |
65 // Return the full name of the match, or an empty caseless_str object | 65 // Return the full name of the match, or an empty caseless_str object |
66 // if there is no match, or the match is ambiguous. | 66 // if there is no match, or the match is ambiguous. |
67 | 67 |
68 static caseless_str | 68 static caseless_str |
69 validate_property_name (const std::string& who, | 69 validate_property_name (const std::string& who, const std::string& what, |
70 const std::set<std::string>& pnames, | 70 const std::set<std::string>& pnames, |
71 const caseless_str& pname) | 71 const caseless_str& pname) |
72 { | 72 { |
73 size_t len = pname.length (); | 73 size_t len = pname.length (); |
74 std::set<std::string> matches; | 74 std::set<std::string> matches; |
90 | 90 |
91 size_t num_matches = matches.size (); | 91 size_t num_matches = matches.size (); |
92 | 92 |
93 if (num_matches == 0) | 93 if (num_matches == 0) |
94 { | 94 { |
95 error ("%s: unknown property %s", who.c_str (), pname.c_str ()); | 95 error ("%s: unknown %s property %s", |
96 who.c_str (), what.c_str (), pname.c_str ()); | |
96 } | 97 } |
97 else if (num_matches > 1) | 98 else if (num_matches > 1) |
98 { | 99 { |
99 string_vector sv (matches); | 100 string_vector sv (matches); |
100 | 101 |
102 | 103 |
103 sv.list_in_columns (os); | 104 sv.list_in_columns (os); |
104 | 105 |
105 std::string match_list = os.str (); | 106 std::string match_list = os.str (); |
106 | 107 |
107 error ("%s: ambiguous property name %s; possible matches:\n\n%s", | 108 error ("%s: ambiguous %s property name %s; possible matches:\n\n%s", |
108 who.c_str (), pname.c_str (), match_list.c_str ()); | 109 who.c_str (), what.c_str (), pname.c_str (), match_list.c_str ()); |
109 } | 110 } |
110 else if (num_matches == 1) | 111 else if (num_matches == 1) |
111 { | 112 { |
112 // Exact match was handled above. | 113 // Exact match was handled above. |
113 | 114 |
114 std::string possible_match = *(matches.begin ()); | 115 std::string possible_match = *(matches.begin ()); |
115 | 116 |
116 warning_with_id ("Octave:abbreviated-property-match", | 117 warning_with_id ("Octave:abbreviated-property-match", |
117 "%s: allowing %s to match %s", who.c_str (), | 118 "%s: allowing %s to match %s property %s", |
118 pname.c_str (), possible_match.c_str ()); | 119 who.c_str (), pname.c_str (), what.c_str (), |
120 possible_match.c_str ()); | |
119 | 121 |
120 return possible_match; | 122 return possible_match; |
121 } | 123 } |
122 | 124 |
123 return caseless_str (); | 125 return caseless_str (); |
1246 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); | 1248 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
1247 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); | 1249 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
1248 | 1250 |
1249 bool has_property = false; | 1251 bool has_property = false; |
1250 if (pfx == "axes") | 1252 if (pfx == "axes") |
1251 has_property = axes::properties::has_property (pname); | 1253 has_property = axes::properties::has_core_property (pname); |
1252 else if (pfx == "line") | 1254 else if (pfx == "line") |
1253 has_property = line::properties::has_property (pname); | 1255 has_property = line::properties::has_core_property (pname); |
1254 else if (pfx == "text") | 1256 else if (pfx == "text") |
1255 has_property = text::properties::has_property (pname); | 1257 has_property = text::properties::has_core_property (pname); |
1256 else if (pfx == "image") | 1258 else if (pfx == "image") |
1257 has_property = image::properties::has_property (pname); | 1259 has_property = image::properties::has_core_property (pname); |
1258 else if (pfx == "patch") | 1260 else if (pfx == "patch") |
1259 has_property = patch::properties::has_property (pname); | 1261 has_property = patch::properties::has_core_property (pname); |
1260 else if (pfx == "figure") | 1262 else if (pfx == "figure") |
1261 has_property = figure::properties::has_property (pname); | 1263 has_property = figure::properties::has_core_property (pname); |
1262 else if (pfx == "surface") | 1264 else if (pfx == "surface") |
1263 has_property = surface::properties::has_property (pname); | 1265 has_property = surface::properties::has_core_property (pname); |
1264 else if (pfx == "hggroup") | 1266 else if (pfx == "hggroup") |
1265 has_property = hggroup::properties::has_property (pname); | 1267 has_property = hggroup::properties::has_core_property (pname); |
1266 | 1268 |
1267 if (has_property) | 1269 if (has_property) |
1268 { | 1270 { |
1269 bool remove = false; | 1271 bool remove = false; |
1270 if (val.is_string ()) | 1272 if (val.is_string ()) |
1849 error ("get_property: unknown property \"%s\"", name.c_str ()); | 1851 error ("get_property: unknown property \"%s\"", name.c_str ()); |
1850 return property (); | 1852 return property (); |
1851 } | 1853 } |
1852 else | 1854 else |
1853 return it->second; | 1855 return it->second; |
1854 } | |
1855 | |
1856 bool | |
1857 base_properties::has_property (const caseless_str& name) | |
1858 { | |
1859 property p; | |
1860 | |
1861 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); | |
1862 | |
1863 unwind_protect::protect_var (discard_error_messages); | |
1864 unwind_protect::protect_var (error_state); | |
1865 | |
1866 discard_error_messages = true; | |
1867 | |
1868 p = get_property (name); | |
1869 | |
1870 unwind_protect::run_frame (uwp_frame); | |
1871 | |
1872 return (p.ok ()); | |
1873 } | 1856 } |
1874 | 1857 |
1875 void | 1858 void |
1876 base_properties::remove_child (const graphics_handle& h) | 1859 base_properties::remove_child (const graphics_handle& h) |
1877 { | 1860 { |
2167 { | 2150 { |
2168 Octave_map m = get (true).map_value (); | 2151 Octave_map m = get (true).map_value (); |
2169 | 2152 |
2170 for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) | 2153 for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) |
2171 { | 2154 { |
2172 if (get_properties().has_property (pa->first)) | 2155 // FIXME -- there has to be a better way. I think we want to |
2173 { | 2156 // ask whether it is OK to delete the listener for the given |
2174 property p = get_properties ().get_property (pa->first); | 2157 // property. How can we know in advance that it will be OK? |
2175 | 2158 |
2176 if (! error_state && p.ok ()) | 2159 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
2177 p.delete_listener (); | 2160 |
2178 } | 2161 unwind_protect::protect_var (discard_error_messages); |
2162 unwind_protect::protect_var (error_state); | |
2163 | |
2164 discard_error_messages = true; | |
2165 | |
2166 property p = get_properties ().get_property (pa->first); | |
2167 | |
2168 if (! error_state && p.ok ()) | |
2169 p.delete_listener (); | |
2170 | |
2171 unwind_protect::run_frame (uwp_frame); | |
2179 } | 2172 } |
2180 } | 2173 } |
2181 | 2174 |
2182 // --------------------------------------------------------------------- | 2175 // --------------------------------------------------------------------- |
2183 | 2176 |