/* StyleSet::initCurrent * Initialises the 'current' style set from the previously saved * 'current.sss' file, or uses the default set if the file does not * exist *******************************************************************/ void StyleSet::initCurrent() { // Create 'current' styleset ss_current = new StyleSet(); ss_current->name = "<current styleset>"; // First up, check if "<userdir>/current.sss" exists string path = appPath("current.sss", DIR_USER); if (wxFileExists(path)) { // Read it in Tokenizer tz; tz.openFile(path); // Parse it ParseTreeNode root; root.allowDup(true); root.parse(tz); // Find definition ParseTreeNode* node = (ParseTreeNode*)root.getChild("styleset"); if (node) { // If found, load it into the current set ss_current->parseSet(node); return; } } // Unable to load from userdir, just load first styleset (should be default) if (style_sets.size() > 0) ss_current->copySet(style_sets[0]); }
/* StyleSet::loadCustomStyles * Loads all text styles from the user text style directory *******************************************************************/ bool StyleSet::loadCustomStyles() { // If the custom stylesets directory doesn't exist, create it if (!wxDirExists(appPath("text_styles", DIR_USER))) wxMkdir(appPath("text_styles", DIR_USER)); // Open the custom stylesets directory wxDir res_dir; res_dir.Open(appPath("text_styles", DIR_USER)); // Go through each file in the directory string filename = wxEmptyString; bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES); while (files) { // Read file into tokenizer Tokenizer tz; tz.openFile(res_dir.GetName() + "/" + filename); // Parse it ParseTreeNode root; root.allowDup(true); root.parse(tz); // Read any styleset definitions vector<STreeNode*> nodes = root.getChildren("styleset"); for (unsigned b = 0; b < nodes.size(); b++) { StyleSet* newset = new StyleSet(); if (newset->parseSet((ParseTreeNode*)nodes[b])) style_sets.push_back(newset); else delete newset; } // Next file files = res_dir.GetNext(&filename); } return true; }
/* MainWindow::loadLayout * Loads the previously saved layout file for the window *******************************************************************/ void MainWindow::loadLayout() { // Open layout file Tokenizer tz; if (!tz.openFile(appPath("mainwindow.layout", DIR_USER))) return; // Parse layout wxAuiManager *m_mgr = wxAuiManager::GetManager(this); while (true) { // Read component+layout pair string component = tz.getToken(); string layout = tz.getToken(); // Load layout to component if (!component.IsEmpty() && !layout.IsEmpty()) m_mgr->LoadPaneInfo(layout, m_mgr->GetPane(component)); // Check if we're done if (tz.peekToken().IsEmpty()) break; } }
/* TranslationEditorDialog::onBtnLoad * Called when the 'Load Translation' button is clicked *******************************************************************/ void TranslationEditorDialog::onBtnLoad(wxCommandEvent& e) { // Get user directory string dir = appPath("translations", DIR_USER); // Create open file dialog wxFileDialog dialog_open(this, "Load Translation from File", dir, wxEmptyString, "Text Files (*.txt)|*.txt", wxFD_OPEN|wxFD_FILE_MUST_EXIST, wxDefaultPosition); // Run the dialog & check that the user didn't cancel if (dialog_open.ShowModal() == wxID_OK) { // Get the selected filename string filename = dialog_open.GetPath(); // Load file in a tokenizer Tokenizer tz; tz.openFile(dialog_open.GetPath()); // Parse translation Translation trans; string token = tz.getToken(); while (!token.IsEmpty()) { // Parse translation range trans.parse(token); tz.getToken(); // Skip , token = tz.getToken(); } // Open it if parsed ok if (trans.nRanges() > 0) openTranslation(trans); else wxMessageBox("Not a valid translation file", "Error", wxICON_ERROR); } }
/* MainWindow::loadLayout * Loads the previously saved layout file for the window *******************************************************************/ void MainWindow::loadLayout() { // Open layout file Tokenizer tz; if (!tz.openFile(App::path("mainwindow.layout", App::Dir::User))) return; // Parse layout while (true) { // Read component+layout pair string component = tz.getToken(); string layout = tz.getToken(); // Load layout to component if (!component.IsEmpty() && !layout.IsEmpty()) m_mgr->LoadPaneInfo(layout, m_mgr->GetPane(component)); // Check if we're done if (tz.peekToken().IsEmpty()) break; } }
/* MainApp::readConfigFile * Reads and parses the SLADE configuration file *******************************************************************/ void MainApp::readConfigFile() { // Open SLADE.cfg Tokenizer tz; if (!tz.openFile(appPath("slade3.cfg", DIR_USER))) return; // Go through the file with the tokenizer string token = tz.getToken(); while (token.Cmp("")) { // If we come across a 'cvars' token, read in the cvars section if (!token.Cmp("cvars")) { token = tz.getToken(); // Skip '{' // Keep reading name/value pairs until we hit the ending '}' string cvar_name = tz.getToken(); while (cvar_name.Cmp("}")) { string cvar_val = tz.getToken(); read_cvar(cvar_name, cvar_val); cvar_name = tz.getToken(); } } // Read base resource archive paths if (!token.Cmp("base_resource_paths")) { // Skip { token = wxString::FromUTF8(UTF8(tz.getToken())); // Read paths until closing brace found token = tz.getToken(); while (token.Cmp("}")) { theArchiveManager->addBaseResourcePath(token); token = wxString::FromUTF8(UTF8(tz.getToken())); } } // Read recent files list if (token == "recent_files") { // Skip { token = tz.getToken(); // Read files until closing brace found token = wxString::FromUTF8(UTF8(tz.getToken())); while (token != "}") { theArchiveManager->addRecentFile(token); token = wxString::FromUTF8(UTF8(tz.getToken())); } } // Read keybinds if (token == "keys") { token = tz.getToken(); // Skip { KeyBind::readBinds(tz); } // Read nodebuilder paths if (token == "nodebuilder_paths") { token = tz.getToken(); // Skip { // Read paths until closing brace found token = tz.getToken(); while (token != "}") { string path = tz.getToken(); NodeBuilders::addBuilderPath(token, path); token = tz.getToken(); } } // Read game exe paths if (token == "executable_paths") { token = tz.getToken(); // Skip { // Read paths until closing brace found token = tz.getToken(); while (token != "}") { if (token.length()) { string path = tz.getToken(); Executables::setExePath(token, path); } token = tz.getToken(); } } // Read window size/position info if (token == "window_info") { token = tz.getToken(); // Skip { Misc::readWindowInfo(&tz); } // Get next token token = tz.getToken(); } }
// ----------------------------------------------------------------------------- // Reads and parses the SLADE configuration file // ----------------------------------------------------------------------------- void readConfigFile() { // Open SLADE.cfg Tokenizer tz; if (!tz.openFile(App::path("slade3.cfg", App::Dir::User))) return; // Go through the file with the tokenizer while (!tz.atEnd()) { // If we come across a 'cvars' token, read in the cvars section if (tz.advIf("cvars", 2)) { // Keep reading name/value pairs until we hit the ending '}' while (!tz.checkOrEnd("}")) { CVar::set(tz.current().text, tz.peek().text); tz.adv(2); } tz.adv(); // Skip ending } } // Read base resource archive paths if (tz.advIf("base_resource_paths", 2)) { while (!tz.checkOrEnd("}")) { archive_manager.addBaseResourcePath(tz.current().text); tz.adv(); } tz.adv(); // Skip ending } } // Read recent files list if (tz.advIf("recent_files", 2)) { while (!tz.checkOrEnd("}")) { archive_manager.addRecentFile(tz.current().text); tz.adv(); } tz.adv(); // Skip ending } } // Read keybinds if (tz.advIf("keys", 2)) KeyBind::readBinds(tz); // Read nodebuilder paths if (tz.advIf("nodebuilder_paths", 2)) { while (!tz.checkOrEnd("}")) { NodeBuilders::addBuilderPath(tz.current().text, tz.peek().text); tz.adv(2); } tz.adv(); // Skip ending } } // Read game exe paths if (tz.advIf("executable_paths", 2)) { while (!tz.checkOrEnd("}")) { Executables::setGameExePath(tz.current().text, tz.peek().text); tz.adv(2); } tz.adv(); // Skip ending } } // Read window size/position info if (tz.advIf("window_info", 2)) Misc::readWindowInfo(tz); // Next token tz.adv(); } }