| 1 |
#include "wxgui_helpers.h" |
| 2 |
|
| 3 |
#include "file_logger.h" |
| 4 |
#include "main.h" |
| 5 |
#include "wxc_project_metadata.h" |
| 6 |
#include "xmlutils.h" |
| 7 |
|
| 8 |
#include <algorithm> |
| 9 |
#include <cl_command_event.h> |
| 10 |
#include <event_notifier.h> |
| 11 |
#include <macros.h> |
| 12 |
#include <map> |
| 13 |
#include <plugin.h> |
| 14 |
#include <project.h> |
| 15 |
#include <workspace.h> |
| 16 |
#include <wx/app.h> |
| 17 |
#include <wx/arrstr.h> |
| 18 |
#include <wx/ffile.h> |
| 19 |
#include <wx/filename.h> |
| 20 |
#include <wx/headercol.h> |
| 21 |
#include <wx/log.h> |
| 22 |
#include <wx/msgdlg.h> |
| 23 |
#include <wx/propgrid/advprops.h> |
| 24 |
#include <wx/propgrid/propgrid.h> |
| 25 |
#include <wx/regex.h> |
| 26 |
#include <wx/settings.h> |
| 27 |
#include <wx/sstream.h> |
| 28 |
#include <wx/stdpaths.h> |
| 29 |
#include <wx/tokenzr.h> |
| 30 |
#include <wx/xml/xml.h> |
| 31 |
#include <wx/xrc/xmlres.h> |
| 32 |
|
| 33 |
namespace |
| 34 |
{ |
| 35 |
wxFont GetSystemFont(const wxString& name) |
| 36 |
{ |
| 37 |
// name is in the format of name,style,weight,underlined |
| 38 |
if(!name.IsEmpty()) { |
| 39 |
wxArrayString parts = ::wxStringTokenize(name, wxT(","), wxTOKEN_STRTOK); |
| 40 |
if(parts.IsEmpty()) |
| 41 |
return wxNullFont; |
| 42 |
|
| 43 |
wxFont font; |
| 44 |
wxString name, style, weight, underlined; |
| 45 |
name = parts.Item(0); |
| 46 |
|
| 47 |
if(parts.GetCount() > 1) |
| 48 |
style = parts.Item(1); |
| 49 |
|
| 50 |
if(parts.GetCount() > 2) |
| 51 |
weight = parts.Item(2); |
| 52 |
|
| 53 |
if(parts.GetCount() > 3) |
| 54 |
underlined = parts.Item(3); |
| 55 |
|
| 56 |
if(name == wxT("wxSYS_OEM_FIXED_FONT")) |
| 57 |
font = wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT); |
| 58 |
|
| 59 |
else if(name == wxT("wxSYS_ANSI_FIXED_FONT")) { |
| 60 |
font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
| 61 |
font.SetFamily(wxFONTFAMILY_TELETYPE); |
| 62 |
} |
| 63 |
|
| 64 |
else if(name == wxT("wxSYS_ANSI_VAR_FONT")) |
| 65 |
font = wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT); |
| 66 |
else if(name == wxT("wxSYS_SYSTEM_FONT")) |
| 67 |
font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); |
| 68 |
else if(name == wxT("wxSYS_DEVICE_DEFAULT_FONT")) |
| 69 |
font = wxSystemSettings::GetFont(wxSYS_DEVICE_DEFAULT_FONT); |
| 70 |
else if(name == wxT("wxSYS_SYSTEM_FIXED_FONT")) |
| 71 |
font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FIXED_FONT); |
| 72 |
else if(name == wxT("wxSYS_DEFAULT_GUI_FONT")) |
| 73 |
font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
| 74 |
else |
| 75 |
return wxNullFont; |
| 76 |
|
| 77 |
if(style == wxT("italic")) |
| 78 |
font.SetStyle(wxFONTSTYLE_ITALIC); |
| 79 |
else |
| 80 |
font.SetStyle(wxFONTSTYLE_NORMAL); |
| 81 |
|
| 82 |
if(weight == wxT("bold")) |
| 83 |
font.SetWeight(wxFONTWEIGHT_BOLD); |
| 84 |
else |
| 85 |
font.SetWeight(wxFONTWEIGHT_NORMAL); |
| 86 |
|
| 87 |
if(underlined == wxT("underlined")) |
| 88 |
font.SetUnderlined(true); |
| 89 |
else |
| 90 |
font.SetUnderlined(false); |
| 91 |
return font; |
| 92 |
} |
| 93 |
return wxNullFont; |
| 94 |
} |
| 95 |
|
| 96 |
wxFontFamily StringToFontFamily(const wxString& str) |
| 97 |
{ |
| 98 |
wxFontFamily family = wxFONTFAMILY_DEFAULT; |
| 99 |
if(str == wxT("decorative")) |
| 100 |
family = wxFONTFAMILY_DECORATIVE; |
| 101 |
|
| 102 |
if(str == wxT("roman")) |
| 103 |
family = wxFONTFAMILY_ROMAN; |
| 104 |
|
| 105 |
if(str == wxT("script")) |
| 106 |
family = wxFONTFAMILY_SCRIPT; |
| 107 |
|
| 108 |
if(str == wxT("swiss")) |
| 109 |
family = wxFONTFAMILY_SWISS; |
| 110 |
|
| 111 |
if(str == wxT("modern")) |
| 112 |
family = wxFONTFAMILY_MODERN; |
| 113 |
|
| 114 |
if(str == wxT("teletype")) |
| 115 |
family = wxFONTFAMILY_TELETYPE; |
| 116 |
|
| 117 |
return family; |
| 118 |
} |
| 119 |
|
| 120 |
wxFontStyle StringToFontStyle(const wxString& str) |
| 121 |
{ |
| 122 |
wxFontStyle style = wxFONTSTYLE_NORMAL; |
| 123 |
if((str == wxT("italic")) || (wxCrafter::ToNumber(str, -1) == wxFONTSTYLE_ITALIC)) { |
| 124 |
style = wxFONTSTYLE_ITALIC; |
| 125 |
} else if((str == wxT("slant")) || (wxCrafter::ToNumber(str, -1) == wxFONTSTYLE_SLANT)) { |
| 126 |
style = wxFONTSTYLE_SLANT; |
| 127 |
} |
| 128 |
|
| 129 |
return style; |
| 130 |
} |
| 131 |
|
| 132 |
wxFontWeight StringToFontWeight(const wxString& str) |
| 133 |
{ |
| 134 |
wxFontWeight weight = wxFONTWEIGHT_NORMAL; |
| 135 |
if((str == wxT("bold")) || (wxCrafter::ToNumber(str, -1) == wxFONTWEIGHT_BOLD)) { |
| 136 |
weight = wxFONTWEIGHT_BOLD; |
| 137 |
} else if((str == wxT("light")) || (wxCrafter::ToNumber(str, -1) == wxFONTWEIGHT_LIGHT)) { |
| 138 |
weight = wxFONTWEIGHT_LIGHT; |
| 139 |
} |
| 140 |
|
| 141 |
return weight; |
| 142 |
} |
| 143 |
} // namespace |
| 144 |
|
| 145 |
wxBorder wxCrafter::GetControlBorder() |
| 146 |
{ |
| 147 |
#if wxVERSION_NUMBER >= 3300 && defined(__WXMSW__) |
| 148 |
return wxSystemSettings::GetAppearance().IsDark() ? wxBORDER_SIMPLE : wxBORDER_STATIC; |
| 149 |
#else |
| 150 |
return wxBORDER_DEFAULT; |
| 151 |
#endif |
| 152 |
} |
| 153 |
|
| 154 |
wxSize wxCrafter::DecodeSize(const wxString& strSize) |
| 155 |
{ |
| 156 |
// Strip any braces |
| 157 |
wxString s = strSize; |
| 158 |
s.Replace(wxT("("), wxT("")); |
| 159 |
s.Replace(wxT(")"), wxT("")); |
| 160 |
s.Replace(wxT("wxSize"), wxT("")); |
| 161 |
|
| 162 |
wxString strWidth = s.BeforeFirst(wxT(',')).Trim().Trim(false); |
| 163 |
wxString strHeight = s.AfterFirst(wxT(',')).Trim().Trim(false); |
| 164 |
|
| 165 |
long x(-1), y(-1); |
| 166 |
strWidth.ToLong(&x); |
| 167 |
strHeight.ToLong(&y); |
| 168 |
return wxSize(x, y); |
| 169 |
} |
| 170 |
|
| 171 |
wxString wxCrafter::ToUnixPath(const wxString& path) |
| 172 |
{ |
| 173 |
wxString p(path); |
| 174 |
p.Replace("\\", "/"); |
| 175 |
return p; |
| 176 |
} |
| 177 |
|
| 178 |
wxString wxCrafter::EncodeSize(const wxSize& size) |
| 179 |
{ |
| 180 |
wxString str; |
| 181 |
str << size.x << wxT(",") << size.y; |
| 182 |
return str; |
| 183 |
} |
| 184 |
|
| 185 |
wxString wxCrafter::GetSizeAsDlgUnits(const wxSize& size, const wxString& parent) |
| 186 |
{ |
| 187 |
wxString str; |
| 188 |
str << "wxDLG_UNIT(" << parent << ", wxSize(" << size.x << wxT(",") << size.y << "))"; |
| 189 |
return str; |
| 190 |
} |
| 191 |
|
| 192 |
wxFileName wxCrafter::LoadXRC(const wxString& xrcString, const wxString& filename, wxString& caption, wxString& style, |
| 193 |
wxString& bmppath) |
| 194 |
{ |
| 195 |
{ |
| 196 |
wxXmlDocument doc; |
| 197 |
wxStringInputStream inStr(xrcString); |
| 198 |
if(doc.Load(inStr)) { |
| 199 |
wxXmlNode* root = doc.GetRoot(); |
| 200 |
if(root) { |
| 201 |
wxXmlNode* child = root->GetChildren(); |
| 202 |
while(child) { |
| 203 |
if(child->GetName() == "object" && child->GetAttribute("name") == "PreviewPanel") { |
| 204 |
// we got the main view |
| 205 |
wxXmlNode* captionNode = XmlUtils::FindFirstByTagName(child, "caption-title"); |
| 206 |
if(captionNode) { |
| 207 |
caption = captionNode->GetNodeContent(); |
| 208 |
} |
| 209 |
|
| 210 |
wxXmlNode* tlwStyle = XmlUtils::FindFirstByTagName(child, "tlw-style"); |
| 211 |
if(tlwStyle) { |
| 212 |
style = tlwStyle->GetNodeContent(); |
| 213 |
} |
| 214 |
|
| 215 |
wxXmlNode* tlwIcon = XmlUtils::FindFirstByTagName(child, "tlw-icon"); |
| 216 |
if(tlwIcon) { |
| 217 |
bmppath = tlwIcon->GetNodeContent(); |
| 218 |
} |
| 219 |
|
| 220 |
break; |
| 221 |
} |
| 222 |
child = child->GetNext(); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
wxString fmtStr; |
| 229 |
#ifndef NDEBUG |
| 230 |
wxXmlDocument doc; |
| 231 |
wxStringOutputStream str(&fmtStr); |
| 232 |
wxStringInputStream inStr(xrcString); |
| 233 |
|
| 234 |
if(!doc.Load(inStr)) { |
| 235 |
::wxMessageBox(_("Invalid XRC! could not save DesignerPreview.xrc"), wxT("wxCrafter"), wxOK | wxICON_WARNING); |
| 236 |
return wxFileName(GetUserDataDir(), filename); |
| 237 |
} |
| 238 |
doc.Save(str); |
| 239 |
#else |
| 240 |
fmtStr = xrcString; |
| 241 |
#endif |
| 242 |
|
| 243 |
wxFFile fp(wxFileName(GetUserDataDir(), filename).GetFullPath(), wxT("w+b")); |
| 244 |
if(fp.IsOpened()) { |
| 245 |
fp.Write(fmtStr, wxConvUTF8); |
| 246 |
fp.Close(); |
| 247 |
} |
| 248 |
|
| 249 |
wxFileName xrcFile = wxFileName(GetUserDataDir(), filename); |
| 250 |
wxXmlResource::Get()->Load(xrcFile.GetFullPath()); |
| 251 |
return xrcFile; |
| 252 |
} |
| 253 |
|
| 254 |
int wxCrafter::ToNumber(const wxString& str, int defaultValue) |
| 255 |
{ |
| 256 |
long num(defaultValue); |
| 257 |
if(str.ToLong(&num)) { |
| 258 |
return num; |
| 259 |
} else { |
| 260 |
return defaultValue; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
wxString wxCrafter::ToString(int n) |
| 265 |
{ |
| 266 |
wxString str; |
| 267 |
str << n; |
| 268 |
return str; |
| 269 |
} |
| 270 |
|
| 271 |
wxArrayString wxCrafter::SplitByString(const wxString& str, const wxString& delim, bool keepEmptyLines) |
| 272 |
{ |
| 273 |
wxArrayString arr; |
| 274 |
wxString tmp = str; |
| 275 |
int where = tmp.Find(delim); |
| 276 |
|
| 277 |
while(where != wxNOT_FOUND) { |
| 278 |
wxString token = tmp.Mid(0, where); |
| 279 |
if(!keepEmptyLines) { |
| 280 |
token.Trim().Trim(false); |
| 281 |
if(!token.IsEmpty()) |
| 282 |
arr.Add(token); |
| 283 |
} else { |
| 284 |
arr.Add(token); |
| 285 |
} |
| 286 |
|
| 287 |
tmp = tmp.Mid(where + delim.length()); // Skip the delimiter |
| 288 |
where = tmp.Find(delim); |
| 289 |
} |
| 290 |
|
| 291 |
if(tmp.IsEmpty() == false) |
| 292 |
arr.Add(tmp); |
| 293 |
|
| 294 |
return arr; |
| 295 |
} |
| 296 |
|
| 297 |
wxString wxCrafter::Join(const wxArrayString& arr, const wxString& delim) |
| 298 |
{ |
| 299 |
wxString res; |
| 300 |
for(size_t i = 0; i < arr.GetCount(); i++) { |
| 301 |
wxString item = arr.Item(i); |
| 302 |
item.Trim().Trim(false); |
| 303 |
res << item << delim; |
| 304 |
} |
| 305 |
|
| 306 |
if(res.IsEmpty() == false) { |
| 307 |
res.RemoveLast(delim.Len()); |
| 308 |
} |
| 309 |
return res; |
| 310 |
} |
| 311 |
|
| 312 |
wxString wxCrafter::CamelCase(const wxString& str) |
| 313 |
{ |
| 314 |
#ifndef __WXMAC__ |
| 315 |
int re_flags = wxRE_ADVANCED; |
| 316 |
#else |
| 317 |
int re_flags = wxRE_DEFAULT; |
| 318 |
#endif |
| 319 |
|
| 320 |
wxString tmpstr = str; |
| 321 |
// Convert CamelCase to '_' separated string |
| 322 |
static wxRegEx re(wxT("([a-z])([A-Z])"), re_flags); |
| 323 |
while(re.IsValid() && re.Matches(tmpstr)) { |
| 324 |
re.Replace(&tmpstr, wxT("\\1_\\2")); |
| 325 |
} |
| 326 |
|
| 327 |
wxArrayString parts = wxCrafter::Split(tmpstr, wxT("_")); |
| 328 |
wxString fooname; |
| 329 |
for(size_t i = 0; i < parts.GetCount(); i++) { |
| 330 |
parts.Item(i).MakeLower(); |
| 331 |
wxString firstChar = parts.Item(i).at(0); |
| 332 |
firstChar.MakeUpper(); |
| 333 |
parts.Item(i).at(0) = firstChar.at(0); |
| 334 |
fooname << parts.Item(i); |
| 335 |
} |
| 336 |
return fooname; |
| 337 |
} |
| 338 |
|
| 339 |
static wxArrayString s_colorNames; |
| 340 |
static wxArrayString s_colorSysNames; |
| 341 |
static wxArrayInt s_colorIdx; |
| 342 |
|
| 343 |
static void init_color_indexes() |
| 344 |
{ |
| 345 |
if(s_colorNames.IsEmpty()) { |
| 346 |
s_colorNames.Add("AppWorkspace"); |
| 347 |
s_colorNames.Add("ActiveBorder"); |
| 348 |
s_colorNames.Add("ActiveCaption"); |
| 349 |
s_colorNames.Add("ButtonFace"); |
| 350 |
s_colorNames.Add("ButtonHighlight"); |
| 351 |
s_colorNames.Add("ButtonShadow"); |
| 352 |
s_colorNames.Add("ButtonText"); |
| 353 |
s_colorNames.Add("CaptionText"); |
| 354 |
s_colorNames.Add("ControlDark"); |
| 355 |
s_colorNames.Add("ControlLight"); |
| 356 |
s_colorNames.Add("Desktop"); |
| 357 |
s_colorNames.Add("GrayText"); |
| 358 |
s_colorNames.Add("Highlight"); |
| 359 |
s_colorNames.Add("HighlightText"); |
| 360 |
s_colorNames.Add("InactiveBorder"); |
| 361 |
s_colorNames.Add("InactiveCaption"); |
| 362 |
s_colorNames.Add("InactiveCaptionText"); |
| 363 |
s_colorNames.Add("Menu"); |
| 364 |
s_colorNames.Add("Scrollbar"); |
| 365 |
s_colorNames.Add("Tooltip"); |
| 366 |
s_colorNames.Add("TooltipText"); |
| 367 |
s_colorNames.Add("Window"); |
| 368 |
s_colorNames.Add("WindowFrame"); |
| 369 |
s_colorNames.Add("WindowText"); |
| 370 |
s_colorNames.Add("Custom"); |
| 371 |
} |
| 372 |
|
| 373 |
if(s_colorIdx.IsEmpty()) { |
| 374 |
s_colorIdx.Add(wxSYS_COLOUR_APPWORKSPACE); |
| 375 |
s_colorIdx.Add(wxSYS_COLOUR_ACTIVEBORDER); |
| 376 |
s_colorIdx.Add(wxSYS_COLOUR_ACTIVECAPTION); |
| 377 |
s_colorIdx.Add(wxSYS_COLOUR_BTNFACE); |
| 378 |
s_colorIdx.Add(wxSYS_COLOUR_BTNHIGHLIGHT); |
| 379 |
s_colorIdx.Add(wxSYS_COLOUR_BTNSHADOW); |
| 380 |
s_colorIdx.Add(wxSYS_COLOUR_BTNTEXT); |
| 381 |
s_colorIdx.Add(wxSYS_COLOUR_CAPTIONTEXT); |
| 382 |
s_colorIdx.Add(wxSYS_COLOUR_3DDKSHADOW); |
| 383 |
s_colorIdx.Add(wxSYS_COLOUR_3DLIGHT); |
| 384 |
s_colorIdx.Add(wxSYS_COLOUR_BACKGROUND); |
| 385 |
s_colorIdx.Add(wxSYS_COLOUR_GRAYTEXT); |
| 386 |
s_colorIdx.Add(wxSYS_COLOUR_HIGHLIGHT); |
| 387 |
s_colorIdx.Add(wxSYS_COLOUR_HIGHLIGHTTEXT); |
| 388 |
s_colorIdx.Add(wxSYS_COLOUR_INACTIVEBORDER); |
| 389 |
s_colorIdx.Add(wxSYS_COLOUR_INACTIVECAPTION); |
| 390 |
s_colorIdx.Add(wxSYS_COLOUR_INACTIVECAPTIONTEXT); |
| 391 |
s_colorIdx.Add(wxSYS_COLOUR_MENU); |
| 392 |
s_colorIdx.Add(wxSYS_COLOUR_SCROLLBAR); |
| 393 |
s_colorIdx.Add(wxSYS_COLOUR_INFOBK); |
| 394 |
s_colorIdx.Add(wxSYS_COLOUR_INFOTEXT); |
| 395 |
s_colorIdx.Add(wxSYS_COLOUR_WINDOW); |
| 396 |
s_colorIdx.Add(wxSYS_COLOUR_WINDOWFRAME); |
| 397 |
s_colorIdx.Add(wxSYS_COLOUR_WINDOWTEXT); |
| 398 |
s_colorIdx.Add(wxPG_COLOUR_CUSTOM); |
| 399 |
} |
| 400 |
|
| 401 |
if(s_colorSysNames.IsEmpty()) { |
| 402 |
s_colorSysNames.Add("wxSYS_COLOUR_APPWORKSPACE"); |
| 403 |
s_colorSysNames.Add("wxSYS_COLOUR_ACTIVEBORDER"); |
| 404 |
s_colorSysNames.Add("wxSYS_COLOUR_ACTIVECAPTION"); |
| 405 |
s_colorSysNames.Add("wxSYS_COLOUR_BTNFACE"); |
| 406 |
s_colorSysNames.Add("wxSYS_COLOUR_BTNHIGHLIGHT"); |
| 407 |
s_colorSysNames.Add("wxSYS_COLOUR_BTNSHADOW"); |
| 408 |
s_colorSysNames.Add("wxSYS_COLOUR_BTNTEXT"); |
| 409 |
s_colorSysNames.Add("wxSYS_COLOUR_CAPTIONTEXT"); |
| 410 |
s_colorSysNames.Add("wxSYS_COLOUR_3DDKSHADOW"); |
| 411 |
s_colorSysNames.Add("wxSYS_COLOUR_3DLIGHT"); |
| 412 |
s_colorSysNames.Add("wxSYS_COLOUR_BACKGROUND"); |
| 413 |
s_colorSysNames.Add("wxSYS_COLOUR_GRAYTEXT"); |
| 414 |
s_colorSysNames.Add("wxSYS_COLOUR_HIGHLIGHT"); |
| 415 |
s_colorSysNames.Add("wxSYS_COLOUR_HIGHLIGHTTEXT"); |
| 416 |
s_colorSysNames.Add("wxSYS_COLOUR_INACTIVEBORDER"); |
| 417 |
s_colorSysNames.Add("wxSYS_COLOUR_INACTIVECAPTION"); |
| 418 |
s_colorSysNames.Add("wxSYS_COLOUR_INACTIVECAPTIONTEXT"); |
| 419 |
s_colorSysNames.Add("wxSYS_COLOUR_MENU"); |
| 420 |
s_colorSysNames.Add("wxSYS_COLOUR_SCROLLBAR"); |
| 421 |
s_colorSysNames.Add("wxSYS_COLOUR_INFOBK"); |
| 422 |
s_colorSysNames.Add("wxSYS_COLOUR_INFOTEXT"); |
| 423 |
s_colorSysNames.Add("wxSYS_COLOUR_WINDOW"); |
| 424 |
s_colorSysNames.Add("wxSYS_COLOUR_WINDOWFRAME"); |
| 425 |
s_colorSysNames.Add("wxSYS_COLOUR_WINDOWTEXT"); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
wxString wxCrafter::ColourToCpp(const wxString& guiname) |
| 430 |
{ |
| 431 |
init_color_indexes(); |
| 432 |
wxString colorname = guiname; |
| 433 |
if(colorname == wxT("<Default>") || guiname.IsEmpty()) { |
| 434 |
return wxT(""); |
| 435 |
|
| 436 |
} else if(colorname.StartsWith(wxT("("))) { |
| 437 |
// Custom color |
| 438 |
wxString code; |
| 439 |
colorname.Prepend("rgb"); |
| 440 |
code << wxT("wxColour(") << WXT(colorname) << wxT(")"); |
| 441 |
return code; |
| 442 |
|
| 443 |
} else if(colorname.StartsWith(wxT("#"))) { |
| 444 |
// Custom color |
| 445 |
wxString code; |
| 446 |
code << wxT("wxColour(") << WXT(colorname) << wxT(")"); |
| 447 |
return code; |
| 448 |
|
| 449 |
} else { |
| 450 |
int guinameidx = s_colorNames.Index(guiname); |
| 451 |
wxString code; |
| 452 |
if(guinameidx != wxNOT_FOUND) { |
| 453 |
code << wxT("wxSystemSettings::GetColour(") << s_colorSysNames.Item(guinameidx) << wxT(")"); |
| 454 |
} |
| 455 |
return code; |
| 456 |
} |
| 457 |
return ""; |
| 458 |
} |
| 459 |
|
| 460 |
wxString wxCrafter::ESCAPE(const wxString& s) |
| 461 |
{ |
| 462 |
wxString escaped = s; |
| 463 |
|
| 464 |
// Remove any already escaped |
| 465 |
escaped.Replace("\\r", "\r"); |
| 466 |
escaped.Replace("\\n", "\n"); |
| 467 |
escaped.Replace("\\\"", "\""); |
| 468 |
|
| 469 |
escaped.Replace("\r", "\\r"); |
| 470 |
escaped.Replace("\n", "\\n"); |
| 471 |
escaped.Replace("\"", "\\\""); |
| 472 |
return escaped; |
| 473 |
} |
| 474 |
|
| 475 |
wxString wxCrafter::UNDERSCORE(const wxString& s) |
| 476 |
{ |
| 477 |
wxString str; |
| 478 |
if(s.empty()) { |
| 479 |
// Don't annoy translators by giving them "" to translate |
| 480 |
return WXT(s); |
| 481 |
} else { |
| 482 |
if(!wxcProjectMetadata::Get().IsUseUnderscoreMacro()) { |
| 483 |
// Use the wxT() macro |
| 484 |
str << "wxT(\"" << ESCAPE(s) << "\")"; |
| 485 |
} else { |
| 486 |
str << "_(\"" << ESCAPE(s) << "\")"; |
| 487 |
} |
| 488 |
} |
| 489 |
return str; |
| 490 |
} |
| 491 |
|
| 492 |
wxString wxCrafter::WXT(const wxString& s) |
| 493 |
{ |
| 494 |
wxString str; |
| 495 |
str << wxT("wxT(\"") << ESCAPE(s) << wxT("\")"); |
| 496 |
return str; |
| 497 |
} |
| 498 |
|
| 499 |
wxString wxCrafter::FontToString(const wxFont& font) |
| 500 |
{ |
| 501 |
wxString str; |
| 502 |
if(!font.IsOk()) { |
| 503 |
return wxEmptyString; |
| 504 |
} |
| 505 |
|
| 506 |
// size, style, weight, family, underlined, face |
| 507 |
|
| 508 |
// Size |
| 509 |
str << font.GetPointSize() << wxT(","); |
| 510 |
|
| 511 |
// style |
| 512 |
if(font.GetStyle() == wxFONTSTYLE_ITALIC) { |
| 513 |
str << wxT("italic, "); |
| 514 |
|
| 515 |
} else if(font.GetStyle() == wxFONTSTYLE_SLANT) { |
| 516 |
str << wxT("slant, "); |
| 517 |
|
| 518 |
} else { |
| 519 |
str << wxT("normal, "); |
| 520 |
} |
| 521 |
|
| 522 |
// weight |
| 523 |
if(font.GetWeight() == wxFONTWEIGHT_LIGHT) { |
| 524 |
str << wxT("light, "); |
| 525 |
|
| 526 |
} else if(font.GetWeight() == wxFONTWEIGHT_BOLD) { |
| 527 |
str << wxT("bold, "); |
| 528 |
|
| 529 |
} else { |
| 530 |
str << wxT("normal, "); |
| 531 |
} |
| 532 |
|
| 533 |
// family |
| 534 |
if(font.GetFamily() == wxFONTFAMILY_DECORATIVE) { |
| 535 |
str << wxT("decorative, "); |
| 536 |
|
| 537 |
} else if(font.GetFamily() == wxFONTFAMILY_ROMAN) { |
| 538 |
str << wxT("roman, "); |
| 539 |
|
| 540 |
} else if(font.GetFamily() == wxFONTFAMILY_SCRIPT) { |
| 541 |
str << wxT("script, "); |
| 542 |
|
| 543 |
} else if(font.GetFamily() == wxFONTFAMILY_SWISS) { |
| 544 |
str << wxT("swiss, "); |
| 545 |
|
| 546 |
} else if(font.GetFamily() == wxFONTFAMILY_MODERN) { |
| 547 |
str << wxT("modern, "); |
| 548 |
|
| 549 |
} else if(font.GetFamily() == wxFONTFAMILY_TELETYPE) { |
| 550 |
str << wxT("teletype, "); |
| 551 |
|
| 552 |
} else { |
| 553 |
str << wxT("default, "); |
| 554 |
} |
| 555 |
|
| 556 |
str << font.GetUnderlined() << wxT(", "); |
| 557 |
|
| 558 |
// face |
| 559 |
str << font.GetFaceName(); |
| 560 |
return str; |
| 561 |
} |
| 562 |
|
| 563 |
wxFont wxCrafter::StringToFont(const wxString& font) |
| 564 |
{ |
| 565 |
// is this a system font? |
| 566 |
wxFont f = GetSystemFont(font); |
| 567 |
if(f.IsOk() == true) { |
| 568 |
return f; |
| 569 |
} |
| 570 |
|
| 571 |
// Some imported fonts may be missing e.g. a 'face', so use wxTOKEN_RET_EMPTY_ALL |
| 572 |
wxArrayString parts = Split(font, wxT(","), wxTOKEN_RET_EMPTY_ALL); |
| 573 |
if(parts.GetCount() != 6) { |
| 574 |
return wxNullFont; |
| 575 |
} |
| 576 |
|
| 577 |
// size, style, weight, family, underlined, face |
| 578 |
int size = ToNumber(parts.Item(0), -1); |
| 579 |
wxFontStyle style = StringToFontStyle(parts.Item(1)); |
| 580 |
wxFontWeight weight = StringToFontWeight(parts.Item(2)); |
| 581 |
wxFontFamily family = StringToFontFamily(parts.Item(3)); |
| 582 |
bool underlined = false; |
| 583 |
|
| 584 |
if(parts.Item(4) == wxT("1")) |
| 585 |
underlined = true; |
| 586 |
|
| 587 |
wxString face = parts.Item(5); |
| 588 |
|
| 589 |
return wxFont(size, family, style, weight, underlined, face); |
| 590 |
} |
| 591 |
|
| 592 |
bool wxCrafter::IsSystemFont(const wxString& font) { return GetSystemFont(font).IsOk(); } |
| 593 |
|
| 594 |
wxString wxCrafter::FontToXRC(const wxString& font) |
| 595 |
{ |
| 596 |
wxString xrc; |
| 597 |
if(IsSystemFont(font)) { |
| 598 |
wxFont f = GetSystemFont(font); |
| 599 |
wxArrayString parts = Split(font, wxT(",")); |
| 600 |
xrc << wxT("<sysfont>") << parts.Item(0) << wxT("</sysfont>"); |
| 601 |
|
| 602 |
if(parts.GetCount() > 1) |
| 603 |
xrc << wxT("<style>") << parts.Item(1) << wxT("</style>"); |
| 604 |
|
| 605 |
if(parts.GetCount() > 2) |
| 606 |
xrc << wxT("<weight>") << parts.Item(2) << wxT("</weight>"); |
| 607 |
|
| 608 |
xrc << wxT("<underlined>") << (f.GetUnderlined() ? wxT("1") : wxT("0")) << wxT("</underlined>"); |
| 609 |
|
| 610 |
} else { |
| 611 |
|
| 612 |
wxArrayString parts = Split(font, wxT(",")); |
| 613 |
if(parts.GetCount() == 6) { |
| 614 |
xrc << wxT("<size>") << parts.Item(0) << wxT("</size>"); |
| 615 |
xrc << wxT("<style>") << parts.Item(1) << wxT("</style>"); |
| 616 |
xrc << wxT("<weight>") << parts.Item(2) << wxT("</weight>"); |
| 617 |
xrc << wxT("<family>") << parts.Item(3) << wxT("</family>"); |
| 618 |
xrc << wxT("<underlined>") << parts.Item(4) << wxT("</underlined>"); |
| 619 |
xrc << wxT("<face>") << parts.Item(5) << wxT("</face>"); |
| 620 |
} |
| 621 |
} |
| 622 |
return xrc; |
| 623 |
} |
| 624 |
|
| 625 |
wxString wxCrafter::XRCToFontstring(const wxXmlNode* node) |
| 626 |
{ |
| 627 |
wxFont font; |
| 628 |
// We might be offered a sysfont node +/- other info, |
| 629 |
// or else anything between 1 and 6 of: size,style,weight,family,underlined,face |
| 630 |
// So start with creating a basic font, either standard or otherwise |
| 631 |
wxXmlNode* sysfontnode = XmlUtils::FindFirstByTagName(node, wxT("sysfont")); |
| 632 |
if(sysfontnode) { |
| 633 |
// There's a system font requested |
| 634 |
font = StringToFont(sysfontnode->GetNodeContent()); |
| 635 |
} |
| 636 |
|
| 637 |
if(!font.IsOk()) { |
| 638 |
// No preferred font, so use the standard one |
| 639 |
font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); |
| 640 |
if(!font.IsOk()) { |
| 641 |
return ""; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
// Now override with any other info |
| 646 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("size")); |
| 647 |
if(propertynode) { |
| 648 |
wxString content = propertynode->GetNodeContent(); |
| 649 |
// The XRC docs say this should be a wxSize for SetPixelSize() |
| 650 |
// but wxFB's XRC output contains a point setting |
| 651 |
if(content.Contains(",")) { |
| 652 |
font.SetPixelSize(DecodeSize(content)); |
| 653 |
} else { |
| 654 |
int pt = ToNumber(content, -1); |
| 655 |
if(pt >= 0) { |
| 656 |
font.SetPointSize(pt); |
| 657 |
} |
| 658 |
} |
| 659 |
} |
| 660 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("style")); |
| 661 |
if(propertynode) { |
| 662 |
font.SetStyle(StringToFontStyle(propertynode->GetNodeContent())); |
| 663 |
} |
| 664 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("weight")); |
| 665 |
if(propertynode) { |
| 666 |
font.SetWeight(StringToFontWeight(propertynode->GetNodeContent())); |
| 667 |
} |
| 668 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("family")); |
| 669 |
if(propertynode) { |
| 670 |
font.SetFamily(StringToFontFamily(propertynode->GetNodeContent())); |
| 671 |
} |
| 672 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("underlined")); |
| 673 |
if(propertynode) { |
| 674 |
font.SetUnderlined(propertynode->GetNodeContent() == "1"); |
| 675 |
} |
| 676 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("face")); |
| 677 |
if(propertynode) { |
| 678 |
font.SetFaceName(propertynode->GetNodeContent()); |
| 679 |
} |
| 680 |
|
| 681 |
return FontToString(font); |
| 682 |
} |
| 683 |
|
| 684 |
wxString wxCrafter::FBToFontstring(const wxString& FBstr) |
| 685 |
{ |
| 686 |
wxString str; |
| 687 |
if(FBstr.empty()) { |
| 688 |
return str; |
| 689 |
} |
| 690 |
|
| 691 |
// Though FBstr is already a comma-delimited string, it's in the wrong order for wxC |
| 692 |
// wxFB supplies: face, style, weight, size, family, underlined |
| 693 |
// We want: size, style, weight, family, underlined, face |
| 694 |
// The wxFB default font is also faceless, so we must use wxTOKEN_RET_EMPTY_ALL here |
| 695 |
wxArrayString arr = Split(FBstr, ",", wxTOKEN_RET_EMPTY_ALL); |
| 696 |
if(arr.GetCount() < 6) { |
| 697 |
return str; |
| 698 |
} |
| 699 |
wxString face = arr.Item(0), sz = arr.Item(3); |
| 700 |
// wxFB uses a value of -1 as (presumably) a default size if the user didn't specify. |
| 701 |
// This is the same as (the valid) wxFONTSIZE_SMALL but, at least on my system, results in a size of 12 pts which is |
| 702 |
// too large so use the system font size instead |
| 703 |
static int defaultfontsize = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT).GetPointSize(); |
| 704 |
if(sz == "-1") { |
| 705 |
sz = wxString::Format("%d", defaultfontsize); |
| 706 |
} |
| 707 |
|
| 708 |
arr.RemoveAt(3); |
| 709 |
arr.Item(0) = sz; |
| 710 |
arr.Add(face); |
| 711 |
wxFont font = wxCrafter::StringToFont(Join(arr, ",")); |
| 712 |
if(font.IsOk()) { |
| 713 |
str = wxCrafter::FontToString(font); |
| 714 |
} |
| 715 |
|
| 716 |
return str; |
| 717 |
} |
| 718 |
|
| 719 |
wxString wxCrafter::FontToCpp(const wxString& font, const wxString& fontMemberName) |
| 720 |
{ |
| 721 |
if(font.IsEmpty()) |
| 722 |
return wxT("wxNullFont"); |
| 723 |
|
| 724 |
wxString code; |
| 725 |
if(IsSystemFont(font)) { |
| 726 |
|
| 727 |
wxFont f = GetSystemFont(font); |
| 728 |
wxArrayString parts = Split(font, wxT(",")); |
| 729 |
|
| 730 |
if(parts.Item(0) == "wxSYS_ANSI_FIXED_FONT") { |
| 731 |
|
| 732 |
code << "#ifdef __WXMSW__\n"; |
| 733 |
code << "// To get the newer version of the font on MSW, we use font wxSYS_DEFAULT_GUI_FONT with family " |
| 734 |
"set to wxFONTFAMILY_TELETYPE\n"; |
| 735 |
code << "wxFont " << fontMemberName << " = " |
| 736 |
<< "wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);\n"; |
| 737 |
code << fontMemberName << ".SetFamily(wxFONTFAMILY_TELETYPE);\n"; |
| 738 |
code << "#else\n"; |
| 739 |
code << "wxFont " << fontMemberName << " = " |
| 740 |
<< "wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);\n"; |
| 741 |
code << fontMemberName << ".SetFamily(wxFONTFAMILY_TELETYPE);\n"; |
| 742 |
code << "#endif\n"; |
| 743 |
|
| 744 |
} else { |
| 745 |
code << wxT("wxFont ") << fontMemberName << wxT(" = ") << wxT("wxSystemSettings::GetFont(") << parts.Item(0) |
| 746 |
<< wxT(");\n"); |
| 747 |
} |
| 748 |
|
| 749 |
if(f.GetStyle() == wxFONTSTYLE_ITALIC) |
| 750 |
code << fontMemberName << wxT(".SetStyle(wxFONTSTYLE_ITALIC);\n"); |
| 751 |
|
| 752 |
if(f.GetUnderlined()) |
| 753 |
code << fontMemberName << wxT(".SetUnderlined(true);\n"); |
| 754 |
|
| 755 |
if(f.GetWeight() == wxFONTWEIGHT_BOLD) |
| 756 |
code << fontMemberName << wxT(".SetWeight(wxFONTWEIGHT_BOLD);\n"); |
| 757 |
return code; |
| 758 |
|
| 759 |
} else { |
| 760 |
// Custom font |
| 761 |
wxArrayString parts = Split(font, wxT(",")); |
| 762 |
if(parts.GetCount() != 6) { |
| 763 |
return wxT("wxNullFont"); |
| 764 |
} |
| 765 |
|
| 766 |
// size, style, weight, family, underlined |
| 767 |
int size = ToNumber(parts.Item(0), -1); |
| 768 |
wxString style = wxT("wxFONTSTYLE_NORMAL"); |
| 769 |
wxString weight = wxT("wxFONTWEIGHT_NORMAL"); |
| 770 |
wxString family = wxT("wxFONTFAMILY_DEFAULT"); |
| 771 |
wxString underlined = wxT("false"); |
| 772 |
wxString face = parts.Item(5); |
| 773 |
|
| 774 |
if(parts.Item(1) == wxT("italic")) { |
| 775 |
style = wxT("wxFONTSTYLE_ITALIC"); |
| 776 |
|
| 777 |
} else if(parts.Item(1) == wxT("slant")) { |
| 778 |
style = wxT("wxFONTSTYLE_SLANT"); |
| 779 |
} |
| 780 |
|
| 781 |
if(parts.Item(2) == wxT("bold")) { |
| 782 |
weight = wxT("wxFONTWEIGHT_BOLD"); |
| 783 |
|
| 784 |
} else if(parts.Item(2) == wxT("light")) { |
| 785 |
weight = wxT("wxFONTWEIGHT_LIGHT"); |
| 786 |
} |
| 787 |
|
| 788 |
// family |
| 789 |
if(parts.Item(3) == wxT("decorative")) |
| 790 |
family = wxT("wxFONTFAMILY_DECORATIVE"); |
| 791 |
|
| 792 |
if(parts.Item(3) == wxT("roman")) |
| 793 |
family = wxT("wxFONTFAMILY_ROMAN"); |
| 794 |
|
| 795 |
if(parts.Item(3) == wxT("script")) |
| 796 |
family = wxT("wxFONTFAMILY_SCRIPT"); |
| 797 |
|
| 798 |
if(parts.Item(3) == wxT("swiss")) |
| 799 |
family = wxT("wxFONTFAMILY_SWISS"); |
| 800 |
|
| 801 |
if(parts.Item(3) == wxT("modern")) |
| 802 |
family = wxT("wxFONTFAMILY_MODERN"); |
| 803 |
|
| 804 |
if(parts.Item(3) == wxT("teletype")) |
| 805 |
family = wxT("wxFONTFAMILY_TELETYPE"); |
| 806 |
|
| 807 |
if(parts.Item(4) == wxT("1")) |
| 808 |
underlined = wxT("true"); |
| 809 |
else |
| 810 |
underlined = wxT("false"); |
| 811 |
|
| 812 |
code << wxT("wxFont ") << fontMemberName << wxT("(") << size << wxT(", ") << family << wxT(", ") << style |
| 813 |
<< wxT(", ") << weight << wxT(", ") << underlined << wxT(", ") << WXT(face) << wxT(");\n"); |
| 814 |
return code; |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
wxString wxCrafter::XMLEncode(const wxString& text, bool decode /*=false*/) |
| 819 |
{ |
| 820 |
wxString str = text; |
| 821 |
static std::map<wxString, wxString> s_xmlEntities; |
| 822 |
if(s_xmlEntities.empty()) { |
| 823 |
s_xmlEntities[wxT("\"")] = wxT("""); |
| 824 |
s_xmlEntities[wxT("'")] = wxT("'"); |
| 825 |
s_xmlEntities[wxT("<")] = wxT("<"); |
| 826 |
s_xmlEntities[wxT(">")] = wxT(">"); |
| 827 |
s_xmlEntities[wxT("&")] = wxT("&"); |
| 828 |
s_xmlEntities[wxT("\\n")] = wxT("
"); |
| 829 |
} |
| 830 |
|
| 831 |
std::map<wxString, wxString>::const_iterator iter = s_xmlEntities.begin(); |
| 832 |
for(; iter != s_xmlEntities.end(); iter++) { |
| 833 |
if(!decode) { |
| 834 |
str.Replace(iter->first, iter->second); |
| 835 |
} else { |
| 836 |
str.Replace(iter->second, iter->first); |
| 837 |
} |
| 838 |
} |
| 839 |
return str; |
| 840 |
} |
| 841 |
|
| 842 |
wxString wxCrafter::ToBool(const wxString& text) |
| 843 |
{ |
| 844 |
if(text == wxT("1")) |
| 845 |
return wxT("true"); |
| 846 |
else |
| 847 |
return wxT("false"); |
| 848 |
} |
| 849 |
|
| 850 |
wxString wxCrafter::CDATA(const wxString& text) |
| 851 |
{ |
| 852 |
wxString s; |
| 853 |
|
| 854 |
s << wxT("<![CDATA[") << text << wxT("]]>"); |
| 855 |
return s; |
| 856 |
} |
| 857 |
|
| 858 |
wxArrayString wxCrafter::MakeUnique(const wxArrayString& arr) |
| 859 |
{ |
| 860 |
wxArrayString res; |
| 861 |
for(size_t i = 0; i < arr.GetCount(); i++) { |
| 862 |
if(res.Index(arr.Item(i)) == wxNOT_FOUND) { |
| 863 |
res.Add(arr.Item(i)); |
| 864 |
} |
| 865 |
} |
| 866 |
return res; |
| 867 |
} |
| 868 |
|
| 869 |
void wxCrafter::WriteFile(const wxFileName& filename, const wxString& content, bool overwriteContent) |
| 870 |
{ |
| 871 |
if(!overwriteContent && filename.FileExists()) { |
| 872 |
return; |
| 873 |
} |
| 874 |
|
| 875 |
wxFFile fp(filename.GetFullPath(), wxT("w+b")); |
| 876 |
if(fp.IsOpened()) { |
| 877 |
fp.Write(content, wxConvUTF8); |
| 878 |
fp.Close(); |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
bool wxCrafter::IsTheSame(const wxFileName& f1, const wxFileName& f2) |
| 883 |
{ |
| 884 |
if(f1.FileExists() == false || f2.FileExists() == false) |
| 885 |
return false; |
| 886 |
|
| 887 |
wxString fileOneContent, fileTwoContent; |
| 888 |
|
| 889 |
wxFFile fileOne(f1.GetFullPath(), wxT("r+b")); |
| 890 |
wxFFile fileTwo(f2.GetFullPath(), wxT("r+b")); |
| 891 |
|
| 892 |
if(fileOne.IsOpened() && fileTwo.IsOpened()) { |
| 893 |
// Compare the content |
| 894 |
if(fileOne.ReadAll(&fileOneContent, wxConvUTF8) && fileTwo.ReadAll(&fileTwoContent, wxConvUTF8) && |
| 895 |
fileOneContent == fileTwoContent) { |
| 896 |
return true; |
| 897 |
} |
| 898 |
} |
| 899 |
return false; |
| 900 |
} |
| 901 |
|
| 902 |
bool wxCrafter::IsTheSame(const wxString& fileContent, const wxFileName& f) |
| 903 |
{ |
| 904 |
if(!f.FileExists()) |
| 905 |
return false; |
| 906 |
|
| 907 |
wxString fileOneContent; |
| 908 |
|
| 909 |
wxFFile fileOne(f.GetFullPath(), wxT("r+b")); |
| 910 |
|
| 911 |
if(fileOne.IsOpened()) { |
| 912 |
// Compare the content |
| 913 |
if(fileOne.ReadAll(&fileOneContent, wxConvUTF8) && fileOneContent == fileContent) { |
| 914 |
return true; |
| 915 |
} |
| 916 |
} |
| 917 |
return false; |
| 918 |
} |
| 919 |
|
| 920 |
float wxCrafter::ToFloat(const wxString& str, float defaultValue) |
| 921 |
{ |
| 922 |
double v; |
| 923 |
|
| 924 |
/// Use ToCDouble to avoid cases (e.g. German locale) |
| 925 |
/// where 0.5 is actually 0,5 - which obvisouly breaks compilation |
| 926 |
if(str.ToCDouble(&v)) { |
| 927 |
return v; |
| 928 |
} else { |
| 929 |
return defaultValue; |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
std::set<wxString> wxCrafter::VectorToSet(const std::vector<wxFileName>& v) |
| 934 |
{ |
| 935 |
std::set<wxString> s; |
| 936 |
for(size_t i = 0; i < v.size(); i++) { |
| 937 |
wxString fullpath = v.at(i).GetFullPath(); |
| 938 |
s.insert(fullpath); |
| 939 |
} |
| 940 |
return s; |
| 941 |
} |
| 942 |
|
| 943 |
wxArrayString wxCrafter::GetToolTypes(bool forToolbar) |
| 944 |
{ |
| 945 |
wxArrayString kinds; |
| 946 |
kinds.Add(ITEM_NORMAL); |
| 947 |
kinds.Add(ITEM_CHECK); |
| 948 |
kinds.Add(ITEM_RADIO); |
| 949 |
kinds.Add(ITEM_SEPARATOR); |
| 950 |
if(forToolbar) { |
| 951 |
kinds.Add(ITEM_DROPDOWN); |
| 952 |
} |
| 953 |
return kinds; |
| 954 |
} |
| 955 |
|
| 956 |
wxCrafter::TOOL_TYPE wxCrafter::GetToolType(const wxString& name) |
| 957 |
{ |
| 958 |
if(name == ITEM_NORMAL) { |
| 959 |
return TOOL_TYPE_NORMAL; |
| 960 |
|
| 961 |
} else if(name == ITEM_CHECK) { |
| 962 |
return TOOL_TYPE_CHECK; |
| 963 |
|
| 964 |
} else if(name == ITEM_RADIO) { |
| 965 |
return TOOL_TYPE_RADIO; |
| 966 |
|
| 967 |
} else if(name == ITEM_SEPARATOR) { |
| 968 |
return TOOL_TYPE_SEPARATOR; |
| 969 |
|
| 970 |
} else if(name == ITEM_SPACE) { |
| 971 |
return TOOL_TYPE_SPACE; |
| 972 |
|
| 973 |
} else if(name == ITEM_DROPDOWN) { |
| 974 |
return TOOL_TYPE_DROPDOWN; |
| 975 |
|
| 976 |
/* } else if(name == ITEM_AUILABEL) { This, and those of the other aui oddities, aren't needed atm |
| 977 |
return TOOL_TYPE_AUILABEL;*/ |
| 978 |
|
| 979 |
} else { |
| 980 |
return TOOL_TYPE_NORMAL; |
| 981 |
} |
| 982 |
} |
| 983 |
|
| 984 |
wxString wxCrafter::ToolTypeToWX(TOOL_TYPE type) |
| 985 |
{ |
| 986 |
if(type == TOOL_TYPE_NORMAL) { |
| 987 |
return wxT("wxITEM_NORMAL"); |
| 988 |
|
| 989 |
} else if(type == TOOL_TYPE_CHECK) { |
| 990 |
return wxT("wxITEM_CHECK"); |
| 991 |
|
| 992 |
} else if(type == TOOL_TYPE_RADIO) { |
| 993 |
return wxT("wxITEM_RADIO"); |
| 994 |
|
| 995 |
} else if(type == TOOL_TYPE_SEPARATOR) { |
| 996 |
return wxT("wxITEM_SEPARATOR"); |
| 997 |
|
| 998 |
} else if(type == TOOL_TYPE_DROPDOWN) { |
| 999 |
return wxT("wxITEM_DROPDOWN"); |
| 1000 |
|
| 1001 |
} else { |
| 1002 |
return wxT("wxITEM_NORMAL"); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
wxString wxCrafter::GetUserDataDir() |
| 1007 |
{ |
| 1008 |
wxFileName dir(wxStandardPaths::Get().GetUserDataDir(), wxEmptyString); |
| 1009 |
#ifndef NDEBUG |
| 1010 |
dir.SetPath(dir.GetPath() + "-dbg"); |
| 1011 |
#endif |
| 1012 |
dir.AppendDir(wxT("wxcrafter")); |
| 1013 |
static bool once = true; |
| 1014 |
if(once) { |
| 1015 |
dir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); |
| 1016 |
once = false; |
| 1017 |
} |
| 1018 |
return dir.GetPath(); |
| 1019 |
} |
| 1020 |
|
| 1021 |
void wxCrafter::SetStatusMessage(const wxString& msg) |
| 1022 |
{ |
| 1023 |
if(TopFrame()) { |
| 1024 |
MainFrame* frame = dynamic_cast<MainFrame*>(TopFrame()); |
| 1025 |
if(frame) { |
| 1026 |
frame->SetStatusMessage(msg); |
| 1027 |
} |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
wxString wxCrafter::GetConfigFile() |
| 1032 |
{ |
| 1033 |
wxFileName dir(GetUserDataDir(), wxT("wxcrafter.conf")); |
| 1034 |
return dir.GetFullPath(); |
| 1035 |
} |
| 1036 |
|
| 1037 |
wxArrayString wxCrafter::Split(const wxString& str, const wxString& delim, wxStringTokenizerMode mode) |
| 1038 |
{ |
| 1039 |
wxArrayString arr = wxStringTokenize(str, delim, mode); |
| 1040 |
for(size_t i = 0; i < arr.GetCount(); i++) { |
| 1041 |
arr.Item(i).Trim().Trim(false); |
| 1042 |
} |
| 1043 |
return arr; |
| 1044 |
} |
| 1045 |
|
| 1046 |
int wxCrafter::GetColourSysIndex(const wxString& name) |
| 1047 |
{ |
| 1048 |
init_color_indexes(); |
| 1049 |
int where = s_colorNames.Index(name); |
| 1050 |
if(where == wxNOT_FOUND) { |
| 1051 |
// try the system colours |
| 1052 |
where = s_colorSysNames.Index(name); |
| 1053 |
if(where != wxNOT_FOUND) { |
| 1054 |
return s_colorIdx.Item(where); |
| 1055 |
} |
| 1056 |
} else { |
| 1057 |
return s_colorIdx.Item(where); |
| 1058 |
} |
| 1059 |
return wxNOT_FOUND; |
| 1060 |
} |
| 1061 |
|
| 1062 |
wxString wxCrafter::GetColourForXRC(const wxString& name) |
| 1063 |
{ |
| 1064 |
init_color_indexes(); |
| 1065 |
if(name == "<Default>" || name.IsEmpty()) |
| 1066 |
return wxEmptyString; |
| 1067 |
|
| 1068 |
if(s_colorSysNames.Index(name) != wxNOT_FOUND) |
| 1069 |
return name; |
| 1070 |
|
| 1071 |
int colorIdx = s_colorNames.Index(name); |
| 1072 |
if(colorIdx == wxNOT_FOUND) { |
| 1073 |
wxString colname = name; |
| 1074 |
colname.Trim().Trim(false); |
| 1075 |
if(colname.StartsWith("(")) { |
| 1076 |
colname.Prepend("rgb"); |
| 1077 |
} |
| 1078 |
|
| 1079 |
wxColour col(colname); |
| 1080 |
return col.GetAsString(wxC2S_HTML_SYNTAX); |
| 1081 |
|
| 1082 |
} else { |
| 1083 |
return s_colorSysNames.Item(colorIdx); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1087 |
wxColour wxCrafter::NameToColour(const wxString& name) |
| 1088 |
{ |
| 1089 |
int sysidx = GetColourSysIndex(name); |
| 1090 |
if(sysidx != wxNOT_FOUND) |
| 1091 |
return wxSystemSettings::GetColour((wxSystemColour)sysidx); |
| 1092 |
|
| 1093 |
// not a system colour name nor PG name, a custom color then |
| 1094 |
wxString colname = name; |
| 1095 |
colname.Trim().Trim(false); |
| 1096 |
|
| 1097 |
if(colname.StartsWith("#")) { |
| 1098 |
// HTML format |
| 1099 |
wxColour col(colname); |
| 1100 |
return col; |
| 1101 |
|
| 1102 |
} else if(colname.StartsWith("rgb")) { |
| 1103 |
return wxColour(colname); |
| 1104 |
|
| 1105 |
} else if(colname.StartsWith("(")) { |
| 1106 |
return wxColour(colname.Prepend("rgb")); |
| 1107 |
} |
| 1108 |
return *wxWHITE; |
| 1109 |
} |
| 1110 |
|
| 1111 |
wxString wxCrafter::ValueToColourString(const wxString& value) |
| 1112 |
{ |
| 1113 |
wxString str(value); |
| 1114 |
// Value might be any of the ways of specifying colour, |
| 1115 |
// but it may also be imported from wxFB as rgb() but without the syntax |
| 1116 |
if((value.Left(1) != "(") && (value.BeforeLast(',') != "")) { |
| 1117 |
str = '(' + value + ')'; |
| 1118 |
} |
| 1119 |
|
| 1120 |
wxColour col = NameToColour(str); |
| 1121 |
return col.GetAsString(); |
| 1122 |
} |
| 1123 |
|
| 1124 |
wxString wxCrafter::WXVER_CHECK_BLOCK_END() |
| 1125 |
{ |
| 1126 |
wxString code; |
| 1127 |
code << "#endif\n"; |
| 1128 |
return code; |
| 1129 |
} |
| 1130 |
|
| 1131 |
wxString wxCrafter::WX294_BLOCK_START() |
| 1132 |
{ |
| 1133 |
wxString code; |
| 1134 |
code << "#if wxVERSION_NUMBER >= 2904\n"; |
| 1135 |
return code; |
| 1136 |
} |
| 1137 |
|
| 1138 |
wxString wxCrafter::WX30_BLOCK_START() |
| 1139 |
{ |
| 1140 |
wxString code; |
| 1141 |
code << "#if wxVERSION_NUMBER >= 3000\n"; |
| 1142 |
return code; |
| 1143 |
} |
| 1144 |
|
| 1145 |
wxString wxCrafter::WX31_BLOCK_START() |
| 1146 |
{ |
| 1147 |
wxString code; |
| 1148 |
code << "#if wxVERSION_NUMBER >= 3100\n"; |
| 1149 |
return code; |
| 1150 |
} |
| 1151 |
|
| 1152 |
wxString wxCrafter::WX33_BLOCK_START() |
| 1153 |
{ |
| 1154 |
wxString code; |
| 1155 |
code << "#if wxVERSION_NUMBER >= 3300\n"; |
| 1156 |
return code; |
| 1157 |
} |
| 1158 |
|
| 1159 |
wxString wxCrafter::WX29_BLOCK_START() |
| 1160 |
{ |
| 1161 |
wxString code; |
| 1162 |
code << "#if wxVERSION_NUMBER >= 2900\n"; |
| 1163 |
return code; |
| 1164 |
} |
| 1165 |
|
| 1166 |
wxString wxCrafter::AddQuotes(const wxString& str) |
| 1167 |
{ |
| 1168 |
wxString s = str; |
| 1169 |
s.Trim().Trim(false); |
| 1170 |
if(!s.StartsWith('"')) |
| 1171 |
s.Prepend('"'); |
| 1172 |
|
| 1173 |
if(!s.EndsWith('"')) |
| 1174 |
s.Append('"'); |
| 1175 |
|
| 1176 |
return s; |
| 1177 |
} |
| 1178 |
|
| 1179 |
void wxCrafter::MakeAbsToProject(wxFileName& fn) |
| 1180 |
{ |
| 1181 |
if(fn.IsRelative()) { |
| 1182 |
fn.MakeAbsolute(wxcProjectMetadata::Get().GetProjectPath()); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
|
| 1186 |
int wxCrafter::ToAligment(const wxString& aligment) |
| 1187 |
{ |
| 1188 |
static std::map<wxString, int> s_stringToAlignment; |
| 1189 |
if(s_stringToAlignment.empty()) { |
| 1190 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_NOT", wxALIGN_NOT)); |
| 1191 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_CENTER_HORIZONTAL", wxALIGN_CENTER_HORIZONTAL)); |
| 1192 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_CENTRE_HORIZONTAL", wxALIGN_CENTRE_HORIZONTAL)); |
| 1193 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_LEFT", wxALIGN_LEFT)); |
| 1194 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_TOP", wxALIGN_TOP)); |
| 1195 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_RIGHT", wxALIGN_RIGHT)); |
| 1196 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_BOTTOM", wxALIGN_BOTTOM)); |
| 1197 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_CENTER_VERTICAL", wxALIGN_CENTER_VERTICAL)); |
| 1198 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_CENTRE_VERTICAL", wxALIGN_CENTRE_VERTICAL)); |
| 1199 |
s_stringToAlignment.insert( |
| 1200 |
std::make_pair("wxALIGN_CENTER", wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL)); |
| 1201 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_CENTRE", wxALIGN_CENTRE)); |
| 1202 |
s_stringToAlignment.insert(std::make_pair("wxALIGN_INVALID", wxALIGN_INVALID)); |
| 1203 |
} |
| 1204 |
|
| 1205 |
if(s_stringToAlignment.count(aligment) == 0) |
| 1206 |
return wxALIGN_NOT; |
| 1207 |
return s_stringToAlignment.find(aligment)->second; |
| 1208 |
} |
| 1209 |
|
| 1210 |
wxString wxCrafter::FloatToCString(float f) { return wxString::FromCDouble(f); } |
| 1211 |
|
| 1212 |
int wxCrafter::ColumnFlagsFromString(const wxString& col_flags) |
| 1213 |
{ |
| 1214 |
int flags = 0; |
| 1215 |
static std::map<wxString, int> s_stringToFlag; |
| 1216 |
if(s_stringToFlag.empty()) { |
| 1217 |
s_stringToFlag.insert(std::make_pair("wxCOL_RESIZABLE", (int)wxCOL_RESIZABLE)); |
| 1218 |
s_stringToFlag.insert(std::make_pair("wxCOL_SORTABLE", (int)wxCOL_SORTABLE)); |
| 1219 |
s_stringToFlag.insert(std::make_pair("wxCOL_REORDERABLE", (int)wxCOL_REORDERABLE)); |
| 1220 |
s_stringToFlag.insert(std::make_pair("wxCOL_HIDDEN", (int)wxCOL_HIDDEN)); |
| 1221 |
s_stringToFlag.insert(std::make_pair("wxCOL_DEFAULT_FLAGS", (int)wxCOL_DEFAULT_FLAGS)); |
| 1222 |
} |
| 1223 |
|
| 1224 |
wxArrayString flagsStringArr = ::wxStringTokenize(col_flags, "|", wxTOKEN_STRTOK); |
| 1225 |
for(size_t i = 0; i < flagsStringArr.GetCount(); ++i) { |
| 1226 |
wxString flagString = flagsStringArr.Item(i).Trim(); |
| 1227 |
; |
| 1228 |
if(s_stringToFlag.count(flagString)) { |
| 1229 |
flags |= s_stringToFlag.find(flagString)->second; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
return flags; |
| 1233 |
} |
| 1234 |
|
| 1235 |
bool wxCrafter::IsArtProviderBitmap(const wxString& bmpString, wxString& artId, wxString& clientID, wxString& sizeHint) |
| 1236 |
{ |
| 1237 |
static wxArrayString arr; |
| 1238 |
if(arr.IsEmpty()) { |
| 1239 |
arr.Add(wxT("wxART_ERROR")); |
| 1240 |
arr.Add(wxT("wxART_QUESTION")); |
| 1241 |
arr.Add(wxT("wxART_WARNING")); |
| 1242 |
arr.Add(wxT("wxART_INFORMATION")); |
| 1243 |
arr.Add(wxT("wxART_ADD_BOOKMARK")); |
| 1244 |
arr.Add(wxT("wxART_DEL_BOOKMARK")); |
| 1245 |
arr.Add(wxT("wxART_HELP_SIDE_PANEL")); |
| 1246 |
arr.Add(wxT("wxART_HELP_SETTINGS")); |
| 1247 |
arr.Add(wxT("wxART_HELP_BOOK")); |
| 1248 |
arr.Add(wxT("wxART_HELP_FOLDER")); |
| 1249 |
arr.Add(wxT("wxART_HELP_PAGE")); |
| 1250 |
arr.Add(wxT("wxART_GO_BACK")); |
| 1251 |
arr.Add(wxT("wxART_GO_FORWARD")); |
| 1252 |
arr.Add(wxT("wxART_GO_UP")); |
| 1253 |
arr.Add(wxT("wxART_GO_DOWN")); |
| 1254 |
arr.Add(wxT("wxART_GO_TO_PARENT")); |
| 1255 |
arr.Add(wxT("wxART_GO_HOME")); |
| 1256 |
arr.Add(wxT("wxART_GOTO_FIRST")); |
| 1257 |
arr.Add(wxT("wxART_GOTO_LAST")); |
| 1258 |
arr.Add(wxT("wxART_PRINT")); |
| 1259 |
arr.Add(wxT("wxART_HELP")); |
| 1260 |
arr.Add(wxT("wxART_TIP")); |
| 1261 |
arr.Add(wxT("wxART_REPORT_VIEW")); |
| 1262 |
arr.Add(wxT("wxART_LIST_VIEW")); |
| 1263 |
arr.Add(wxT("wxART_NEW_DIR")); |
| 1264 |
arr.Add(wxT("wxART_FOLDER")); |
| 1265 |
arr.Add(wxT("wxART_FOLDER_OPEN")); |
| 1266 |
arr.Add(wxT("wxART_GO_DIR_UP")); |
| 1267 |
arr.Add(wxT("wxART_EXECUTABLE_FILE")); |
| 1268 |
arr.Add(wxT("wxART_NORMAL_FILE")); |
| 1269 |
arr.Add(wxT("wxART_TICK_MARK")); |
| 1270 |
arr.Add(wxT("wxART_CROSS_MARK")); |
| 1271 |
arr.Add(wxT("wxART_MISSING_IMAGE")); |
| 1272 |
arr.Add(wxT("wxART_NEW")); |
| 1273 |
arr.Add(wxT("wxART_FILE_OPEN")); |
| 1274 |
arr.Add(wxT("wxART_FILE_SAVE")); |
| 1275 |
arr.Add(wxT("wxART_FILE_SAVE_AS")); |
| 1276 |
arr.Add(wxT("wxART_DELETE")); |
| 1277 |
arr.Add(wxT("wxART_COPY")); |
| 1278 |
arr.Add(wxT("wxART_CUT")); |
| 1279 |
arr.Add(wxT("wxART_PASTE")); |
| 1280 |
arr.Add(wxT("wxART_UNDO")); |
| 1281 |
arr.Add(wxT("wxART_REDO")); |
| 1282 |
arr.Add(wxT("wxART_PLUS")); |
| 1283 |
arr.Add(wxT("wxART_MINUS")); |
| 1284 |
arr.Add(wxT("wxART_CLOSE")); |
| 1285 |
arr.Add(wxT("wxART_QUIT")); |
| 1286 |
arr.Add(wxT("wxART_FIND")); |
| 1287 |
arr.Add(wxT("wxART_FIND_AND_REPLACE")); |
| 1288 |
arr.Add(wxT("wxART_HARDDISK")); |
| 1289 |
arr.Add(wxT("wxART_FLOPPY")); |
| 1290 |
arr.Add(wxT("wxART_CDROM")); |
| 1291 |
arr.Add(wxT("wxART_REMOVABLE")); |
| 1292 |
arr.Sort(); |
| 1293 |
} |
| 1294 |
|
| 1295 |
// Art ID |
| 1296 |
wxArrayString parts = ::wxStringTokenize(bmpString, ",", wxTOKEN_STRTOK); |
| 1297 |
sizeHint = "wxDefaultSize"; |
| 1298 |
if(parts.GetCount() > 1) { |
| 1299 |
artId = parts.Item(0); |
| 1300 |
clientID = parts.Item(1); |
| 1301 |
} |
| 1302 |
if(parts.GetCount() > 2) { |
| 1303 |
sizeHint = parts.Item(2); |
| 1304 |
} |
| 1305 |
|
| 1306 |
if(arr.Index(artId) != wxNOT_FOUND) { |
| 1307 |
return true; |
| 1308 |
} |
| 1309 |
return false; |
| 1310 |
} |
| 1311 |
|
| 1312 |
wxString wxCrafter::MakeWxSizeStr(const wxString& size) |
| 1313 |
{ |
| 1314 |
wxString strSize; |
| 1315 |
if(size.StartsWith("wxSize")) { |
| 1316 |
return size; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if(size.Contains(",")) { |
| 1320 |
strSize << "wxSize(" << size << ")"; |
| 1321 |
|
| 1322 |
} else if(size == "wxDefaultSize") { |
| 1323 |
strSize = "wxDefaultSize"; |
| 1324 |
|
| 1325 |
} else { |
| 1326 |
strSize << "wxSize(" << size << ", " << size << ")"; |
| 1327 |
} |
| 1328 |
return strSize; |
| 1329 |
} |
| 1330 |
|
| 1331 |
wxShowEffect wxCrafter::ShowEffectFromString(const wxString& effect) |
| 1332 |
{ |
| 1333 |
std::map<wxString, wxShowEffect> m; |
| 1334 |
m.insert(std::make_pair("wxSHOW_EFFECT_ROLL_TO_LEFT", wxSHOW_EFFECT_ROLL_TO_LEFT)); |
| 1335 |
m.insert(std::make_pair("wxSHOW_EFFECT_ROLL_TO_RIGHT", wxSHOW_EFFECT_ROLL_TO_RIGHT)); |
| 1336 |
m.insert(std::make_pair("wxSHOW_EFFECT_ROLL_TO_TOP", wxSHOW_EFFECT_ROLL_TO_TOP)); |
| 1337 |
m.insert(std::make_pair("wxSHOW_EFFECT_ROLL_TO_BOTTOM", wxSHOW_EFFECT_ROLL_TO_BOTTOM)); |
| 1338 |
m.insert(std::make_pair("wxSHOW_EFFECT_SLIDE_TO_LEFT", wxSHOW_EFFECT_SLIDE_TO_LEFT)); |
| 1339 |
m.insert(std::make_pair("wxSHOW_EFFECT_SLIDE_TO_RIGHT", wxSHOW_EFFECT_SLIDE_TO_RIGHT)); |
| 1340 |
m.insert(std::make_pair("wxSHOW_EFFECT_SLIDE_TO_TOP", wxSHOW_EFFECT_SLIDE_TO_TOP)); |
| 1341 |
m.insert(std::make_pair("wxSHOW_EFFECT_SLIDE_TO_BOTTOM", wxSHOW_EFFECT_SLIDE_TO_BOTTOM)); |
| 1342 |
m.insert(std::make_pair("wxSHOW_EFFECT_BLEND", wxSHOW_EFFECT_BLEND)); |
| 1343 |
m.insert(std::make_pair("wxSHOW_EFFECT_EXPAND", wxSHOW_EFFECT_EXPAND)); |
| 1344 |
|
| 1345 |
if(m.count(effect)) { |
| 1346 |
return m.find(effect)->second; |
| 1347 |
} |
| 1348 |
|
| 1349 |
return wxSHOW_EFFECT_NONE; |
| 1350 |
} |
| 1351 |
|
| 1352 |
void wxCrafter::NotifyFileSaved(const wxFileName& fn) |
| 1353 |
{ |
| 1354 |
#if !STANDALONE_BUILD |
| 1355 |
EventNotifier::Get()->PostFileSavedEvent(fn.GetFullPath()); |
| 1356 |
#else |
| 1357 |
wxUnusedVar(fn); |
| 1358 |
#endif |
| 1359 |
} |
| 1360 |
|
| 1361 |
void wxCrafter::WrapInIfBlock(const wxString& condname, wxString& codeblock) |
| 1362 |
{ |
| 1363 |
if(condname.IsEmpty()) |
| 1364 |
return; |
| 1365 |
|
| 1366 |
wxString topBlock, bottomBlock; |
| 1367 |
if(codeblock.StartsWith("\n")) { |
| 1368 |
topBlock << "\n"; |
| 1369 |
} |
| 1370 |
|
| 1371 |
if(!codeblock.EndsWith("\n")) { |
| 1372 |
bottomBlock << "\n"; |
| 1373 |
} |
| 1374 |
|
| 1375 |
topBlock << "#if " << condname << "\n"; |
| 1376 |
bottomBlock << "#endif // " << condname << "\n"; |
| 1377 |
|
| 1378 |
codeblock.Prepend(topBlock).Append(bottomBlock); |
| 1379 |
} |
| 1380 |
|
| 1381 |
void wxCrafter::GetWorkspaceFiles(wxStringSet_t& files) |
| 1382 |
{ |
| 1383 |
wxArrayString arrFiles; |
| 1384 |
clCxxWorkspaceST::Get()->GetWorkspaceFiles(arrFiles); |
| 1385 |
for(size_t i = 0; i < arrFiles.GetCount(); ++i) { |
| 1386 |
files.insert(arrFiles.Item(i)); |
| 1387 |
} |
| 1388 |
} |
| 1389 |
|
| 1390 |
void wxCrafter::GetProjectFiles(const wxString& projectName, wxStringSet_t& files) |
| 1391 |
{ |
| 1392 |
ProjectPtr p = clCxxWorkspaceST::Get()->GetProject(projectName); |
| 1393 |
if(!p) { |
| 1394 |
return; |
| 1395 |
} |
| 1396 |
const Project::FilesMap_t& filesMap = p->GetFiles(); |
| 1397 |
files.reserve(filesMap.size()); |
| 1398 |
std::for_each(filesMap.begin(), filesMap.end(), |
| 1399 |
[&](const Project::FilesMap_t::value_type& vt) { files.insert(vt.first); }); |
| 1400 |
} |
| 1401 |
|
| 1402 |
void wxCrafter::FormatString(wxString& content, const wxFileName& filename) |
| 1403 |
{ |
| 1404 |
#if !STANDALONE_BUILD |
| 1405 |
clSourceFormatEvent event{ wxEVT_FORMAT_STRING }; |
| 1406 |
event.SetFileName(filename.GetFullPath()); |
| 1407 |
event.SetInputString(content); |
| 1408 |
EventNotifier::Get()->ProcessEvent(event); |
| 1409 |
if(!event.GetFormattedString().IsEmpty()) { |
| 1410 |
content = event.GetFormattedString(); |
| 1411 |
} |
| 1412 |
#endif |
| 1413 |
} |
| 1414 |
|
| 1415 |
void wxCrafter::FormatFile(const wxFileName& filename) |
| 1416 |
{ |
| 1417 |
#if !STANDALONE_BUILD |
| 1418 |
clSourceFormatEvent event(wxEVT_FORMAT_FILE); |
| 1419 |
event.SetFileName(filename.GetFullPath()); |
| 1420 |
EventNotifier::Get()->ProcessEvent(event); |
| 1421 |
#endif |
| 1422 |
} |
| 1423 |
|
| 1424 |
static wxWindow* sTopFrame = NULL; |
| 1425 |
wxWindow* wxCrafter::TopFrame() |
| 1426 |
{ |
| 1427 |
if(!sTopFrame) { |
| 1428 |
return wxTheApp->GetTopWindow(); |
| 1429 |
} |
| 1430 |
return sTopFrame; |
| 1431 |
} |
| 1432 |
|
| 1433 |
void wxCrafter::SetTopFrame(wxWindow* frame) { sTopFrame = frame; } |