bool wxStEditApp::OnInit() { if (!wxApp::OnInit()) // parse command line return false; #ifdef _WX_DOCH__ wxDocManager* docManager = new wxDocManager(); wxSTEditorDocTemplate::Create(docManager); // now wxWidgets tracks all the files opened (wxDocManager::GetDocuments()) #endif SetAppName(STE_APPNAME); #if (wxVERSION_NUMBER >= 2900) SetAppDisplayName(STE_APPDISPLAYNAME); #endif wxLocaleHelper::Init(&m_locale, STE_APPNAME, m_lang); wxSTEditorOptions::SetGlobalDefaultFileName(wxString(_("unnamed")) + wxT(".txt")); // translated // Create a set of wxSTEditorOptions for your editing "system." // These options control what components will be automatically // created and/or managed for you. // Every STE window created will have its virtual function CreateOptions() called. // You can start with all the options "turned off" by using // the default constructor. // For this simple editor we'll basicly use the defaults for everything. // Note that we set it up in the wxStEditApp constructor since we adjust // it in OnCmdLineParsed() to use either a single editor or notebook. //m_steOptions = wxSTEditorOptions(STE_DEFAULT_OPTIONS, STS_DEFAULT_OPTIONS, // STN_DEFAULT_OPTIONS, STF_DEFAULT_OPTIONS); wxSTEditorOptions::RegisterIds(); // ======================================================================= // A sample of things that you might do to change the behavior // no bookmark items in menus or toolbar //m_steOptions.GetMenuManager()->SetMenuItemType(STE_MENU_BOOKMARK, false); //m_steOptions.GetMenuManager()->SetToolbarToolType(STE_MENU_BOOKMARK, false); // don't create a toolbar //m_steOptions.SetFrameOption(STF_TOOLBAR, false); // allow notebook to not have any pages //m_steOptions.SetNotebookOption(STN_ALLOW_NO_PAGES, true); // don't ask the user to save a modified document, close silently //m_steOptions.SetEditorOption(STE_QUERY_SAVE_MODIFIED, false); // Maybe we're editing only python files, set global initializers // wxSTEditorOptions::SetGlobalDefaultFileName(wxT("newfile.py")); // wxSTEditorOptions::SetGlobalDefaultFileExtensions(wxT("Python file (*.py)|*.py")); // maybe the editors that use these options are only for your ini files // m_steOptions.SetDefaultFileName(wxT("MyProgram.ini")); // Maybe you want your own special menu for the splitter? // it'll delete the old one (if there was one) and replace it with yours. // m_steOptions.SetSplitterPopupMenu(myMenu, false); // Maybe you want this editor to not use the global preferences, // create a new one, set it up the way you like it and push it onto the // options so that every new editor sharing these options will use it. // Remember, you can later detach a single editors to have them // use some other prefs/styles/langs with STE::RegisterXXX(otherXXX) // wxSTEditorPrefs myPrefs(true); // myPrefs.SetPrefBool(STE_PREF_VIEW_EOL, true); // m_steOptions.SetEditorPrefs(myPrefs); // You can do the same for the styles and langs, though the languages // are pretty generic and it probably won't be necessary. // Remember, the global versions are created to be used by a set of editors // they are created because if a user likes their editor a // certain way, you might as well make all of them look that way. // There is nothing special about them and if you want to see what the // defaults are just create a wxSTEditorPrefs/Styles/Langs(true). // etc... Ok, we set things up the way we like. // end sample code // ======================================================================= // Create a notebook to show the find results in m_steOptions.SetFrameOption(STF_CREATE_RESULT_NOTEBOOK, true); // Remove the Help menu since wxMac will pull out the wxID_ABOUT to add to // the system menu and then hide the Help menu. Later on when we add items // to the help menu, they'll be hidden too. m_steOptions.GetMenuManager()->SetMenuItems(STE_MENU_HELP_MENU, 0); // create with the readonly menuitem, not set by default since I don't think // it's generally useful, but good for debugging. m_steOptions.GetMenuManager()->SetMenuItemType(STE_MENU_EDIT_MENU, STE_MENU_EDIT_READONLY, true); m_steOptions.GetMenuManager()->SetToolbarToolType(STE_TOOLBAR_PRINT, true); m_steOptions.GetMenuManager()->SetToolbarToolType(STE_TOOLBAR_EDIT_SEARCH_CTRL, true); m_steOptions.SetNotebookOption(STN_ALPHABETICAL_TABS, false); // Ctrl+N -> append tabs to the right always m_steOptions.GetMenuManager()->GetAcceleratorArray()->Add(wxAcceleratorEntry(wxACCEL_NORMAL, WXK_HELP, ID_SHOW_HELP)); // adding 'custom' accelerator m_steOptions.GetMenuManager()->GetAcceleratorArray()->Add(wxAcceleratorHelper::GetStockAccelerator(wxID_ABOUT)); // adding 'custom' accelerator // ------------------------------------------------------------------------ m_frame = CreateMainFrame(); // ------------------------------------------------------------------------ // handle loading the files size_t n; wxArrayFileName badFileNames; wxArrayFileName fileNames = m_fileNames; // handle recursive file loading if (m_recurse_dirs && m_frame->GetEditorNotebook()) { size_t max_page_count = m_frame->GetEditorNotebook()->GetMaxPageCount(); wxArrayString recurseFileNames; for (n = 0; n < fileNames.GetCount(); n++) { wxFileName fN(fileNames[n]); fN.MakeAbsolute(); //wxPrintf(wxT("Loading file '%s' to '%s'\n"), fileNames[n].wx_str(), fN.GetFullPath().wx_str()); fflush(stdout); wxDir::GetAllFiles(fN.GetPath(), &recurseFileNames, fN.GetFullName()); // if they did wxstedit /r c:\*.* stop the insanity... if (recurseFileNames.GetCount() >= max_page_count) { wxString msg = wxString::Format(_("Opening %d files, unable to open any more."), (int)max_page_count); wxMessageBox(msg, _("Maximum number of files"), wxOK|wxICON_ERROR, m_frame); recurseFileNames.RemoveAt(max_page_count - 1, recurseFileNames.GetCount() - max_page_count); break; } } //for (n=0; n < recurseFileNames.GetCount(); n++) // { wxPrintf(wxT("Loading file '%s'\n"), recurseFileNames[n].wx_str()); fflush(stdout); } // delete all wildcards and replace them with the new files fileNames.Clear(); for (n = 0; n < recurseFileNames.GetCount(); n++) { fileNames.Add(wxFileName(recurseFileNames.Item(n))); // these are really the files to open } } // if the files have *, ? or are directories, don't try to load them for (n = 0; n < fileNames.GetCount(); n++) { if (wxIsWild(fileNames[n].GetFullPath())) { badFileNames.Add(fileNames[n]); fileNames.RemoveAt(n); n--; } else if (wxDirExists(fileNames[n].GetFullPath())) { fileNames.RemoveAt(n); n--; } } // If there are any good files left, try to load them if (fileNames.GetCount() > 0u) { if (fileNames[0].FileExists()) m_frame->GetEditor()->LoadFile( fileNames[0] ); else { // fix the path to the new file using the command line path wxFileName fn(fileNames[0]); fn.Normalize(); m_frame->GetEditor()->NewFile( fn.GetFullPath() ); } fileNames.RemoveAt(0); if (m_steOptions.HasFrameOption(STF_CREATE_NOTEBOOK) && fileNames.GetCount()) m_frame->GetEditorNotebook()->LoadFiles( &fileNames ); } //frame->ShowSidebar(false); //wxSTEditorOptions::m_path_display_format = wxPATH_UNIX; // trac.wxwidgets.org/ticket/11947 m_frame->Show(); m_frame->GetEditor()->SetFocus(); // filenames had *, ? or other junk so we didn't load them if (badFileNames.GetCount()) { wxString msg(_("There was a problem trying to load file(s):\n")); for (n = 0; n < badFileNames.GetCount(); n++) { msg += wxT("'") + badFileNames[n].GetFullPath() + wxT("'\n"); if ((n > 4) && (n < badFileNames.GetCount()-1)) { msg += wxT("..."); break; } } wxMessageBox(msg, _("Unable to load file(s)"), wxOK|wxICON_ERROR, m_frame); } return true; }
int main() { fN(f_a, 1); fN(f_b, 2); fN(f_c, 3); fN(f_d, 4); fN(f_e, 5); fN(f_a, 11); fN(f_c, 13); fN(f_d, 14); fN(f_a, 101); fN(f_c, 103); fN(f_c, 1003); return (0); }
bool wxStEditApp::OnCmdLineParsed(wxCmdLineParser& parser) { // use single page, else use a notebook of editors if (parser.Found(cmdLineDesc[CMDLINE_PARAM_SINGLE].longName)) { m_steOptions.SetFrameOption(STF_CREATE_NOTEBOOK, false); m_steOptions.SetFrameOption(STF_CREATE_SINGLEPAGE, true); m_steOptions.GetMenuManager()->CreateForSinglePage(); } else { m_steOptions.SetFrameOption(STF_CREATE_SIDEBAR, true); m_steOptions.GetMenuManager()->CreateForNotebook(); } // use specified config file to load saved prefs, styles, langs wxString configFile; if (parser.Found(cmdLineDesc[CMDLINE_PARAM_CONFIG].longName, &configFile)) { wxFileName fN(configFile); if ( !fN.FileExists() ) { //wxLogMessage(wxT("Config file '")+configFile+wxT("' does not exist.")); if (configFile.IsEmpty() || !fN.IsOk() || wxIsWild(configFile)) { int ret = wxMessageBox(wxString::Format(_("Config file '%s' has an invalid name.\nContinue without using a config file?"), configFile.wx_str()), _("Invalid config file name"), wxICON_QUESTION|wxYES_NO); if (ret == wxNO) return false; configFile = wxEmptyString; } else // file doesn't exist, ask if they want to create a new one { int ret = wxMessageBox(wxString::Format(_("Config file '%s' does not exist.\nWould you like to create a new one?"), configFile.wx_str()), _("Invalid config file"), wxICON_QUESTION|wxYES_NO|wxCANCEL); if (ret == wxCANCEL) return false; else if (ret == wxNO) configFile = wxEmptyString; } } // use the specified config file, if it's still set if ( !configFile.IsEmpty() ) { wxFileConfig *config = new wxFileConfig(STE_APPDISPLAYNAME, wxT("wxWidgets"), configFile, wxEmptyString, wxCONFIG_USE_RELATIVE_PATH); wxConfigBase::Set((wxConfigBase*)config); } else // don't use any config file at all, disable saving { m_steOptions.GetMenuManager()->SetMenuItemType(STE_MENU_PREFS_MENU, STE_MENU_PREFS_SAVE, false); } } else { // Always use a wxFileConfig since I don't care for registry entries. wxFileConfig *config = new wxFileConfig(STE_APPDISPLAYNAME, wxT("wxWidgets")); wxConfigBase::Set((wxConfigBase*)config); } // they want to open the files recursively if (parser.Found(cmdLineDesc[CMDLINE_PARAM_RECURSE].longName)) m_recurse_dirs = true; // gather up all the filenames to load size_t n, count = parser.GetParamCount(); for (n = 0; n < count; n++) m_fileNames.Add(wxFileName(parser.GetParam(n))); wxString str; if (parser.Found(cmdLineDesc[CMDLINE_PARAM_LANG].longName, &str)) { if (!str.IsEmpty()) wxLocaleHelper::Find(str, &m_lang); } if (parser.Found(cmdLineDesc[CMDLINE_PARAM_LANGDIALOG].longName)) { wxArrayInt languages; wxLocaleHelper::GetSupportedLanguages(languages); wxLocaleHelper::SingleChoice(languages, &m_lang); } return wxApp::OnCmdLineParsed(parser); }