void ToolsPlus::BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data) { //Some library module is ready to display a pop-up menu. //Check the parameter \"type\" and see which module it is //and append any items you need in the menu... //TIP: for consistency, add a separator as the first item... m_contextvec.Empty(); if (type==mtProjectManager) { if (data) { if (data->GetKind()==FileTreeData::ftdkProject) { cbProject* prj = data->GetProject(); wxString filename=wxFileName(prj->GetFilename()).GetPath(); wxString name=_T(""); size_t sep_pos=menu->GetMenuItemCount(); size_t added=0; for (unsigned int i=0;i<m_ic.interps.size();i++) { if (WildCardListMatch(m_ic.interps[i].wildcards,name)) { m_RunTarget=filename; if (m_ic.interps[i].command.Find(_("$dir"))>=0 || m_ic.interps[i].command.Find(_("$reldir"))>=0 || m_ic.interps[i].command.Find(_("$path"))>=0 || m_ic.interps[i].command.Find(_("$relpath"))>=0 || m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } if (added>0) menu->InsertSeparator(sep_pos); } if (data->GetKind()==FileTreeData::ftdkFile) { ProjectFile *f=data->GetProjectFile(); if (f) { wxString filename=f->file.GetFullPath(); wxString name=f->file.GetFullName(); size_t sep_pos=menu->GetMenuItemCount(); size_t added=0; for (unsigned int i=0;i<m_ic.interps.size();i++) { if (WildCardListMatch(m_ic.interps[i].wildcards,name)) { m_RunTarget=filename; if (m_ic.interps[i].command.Find(_("$file"))>=0 || m_ic.interps[i].command.Find(_("$relfile"))>=0 || m_ic.interps[i].command.Find(_("$fname"))>=0 || m_ic.interps[i].command.Find(_("$fext"))>=0 || m_ic.interps[i].command.Find(_("$path"))>=0 || m_ic.interps[i].command.Find(_("$relpath"))>=0 || m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } if (added>0) menu->InsertSeparator(sep_pos); } } } } if (type==mtEditorManager) // also type==mtOpenFilesList - not sure how to find out which file has been right clicked. { EditorManager* edMan = Manager::Get()->GetEditorManager(); wxFileName activefile(edMan->GetActiveEditor()->GetFilename()); wxString filename=activefile.GetFullPath(); wxString name=activefile.GetFullName(); size_t sep_pos=menu->GetMenuItemCount(); size_t added=0; for (unsigned int i=0;i<m_ic.interps.size();i++) { if (WildCardListMatch(m_ic.interps[i].wildcards,name)) { m_RunTarget=filename; if (m_ic.interps[i].command.Find(_("$file"))>=0 || m_ic.interps[i].command.Find(_("$relfile"))>=0 || m_ic.interps[i].command.Find(_("$fname"))>=0 || m_ic.interps[i].command.Find(_("$fext"))>=0 || m_ic.interps[i].command.Find(_("$path"))>=0 || m_ic.interps[i].command.Find(_("$relpath"))>=0 || m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } if (added>0) menu->InsertSeparator(sep_pos); } if (type==mtUnknown) //Assuming file explorer -- fileexplorer fills the filetreedata with ftdkFile or ftdkFolder as "kind", the folder is the full path of the entry { if (data) { size_t sep_pos=menu->GetMenuItemCount(); size_t added=0; if (data->GetKind()==FileTreeData::ftdkFile) //right clicked on folder in file explorer { wxFileName f(data->GetFolder()); wxString filename=f.GetFullPath(); wxString name=f.GetFullName(); for (unsigned int i=0;i<m_ic.interps.size();i++) { if (WildCardListMatch(m_ic.interps[i].wildcards,name)) { m_RunTarget=filename; if (m_ic.interps[i].command.Find(_("$file"))>=0 || m_ic.interps[i].command.Find(_("$relfile"))>=0 || m_ic.interps[i].command.Find(_("$fname"))>=0 || m_ic.interps[i].command.Find(_("$fext"))>=0 || m_ic.interps[i].command.Find(_("$path"))>=0 || m_ic.interps[i].command.Find(_("$relpath"))>=0 || m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } } if (data->GetKind()==FileTreeData::ftdkFolder) //right clicked on folder in file explorer { wxFileName f(data->GetFolder()); wxString filename=f.GetFullPath(); wxString name=f.GetFullName(); for (unsigned int i=0;i<m_ic.interps.size();i++) { if (WildCardListMatch(m_ic.interps[i].wildcards,name)) { m_RunTarget=filename; if (m_ic.interps[i].command.Find(_("$dir"))>=0 || m_ic.interps[i].command.Find(_("$reldir"))>=0 || m_ic.interps[i].command.Find(_("$path"))>=0 || m_ic.interps[i].command.Find(_("$relpath"))>=0 || m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } } if (data->GetKind()==FileTreeData::ftdkVirtualGroup) //right clicked on multiple selections in file explorer { wxString paths=data->GetFolder(); //get folder contains a space separated list of the files/directories selected for (unsigned int i=0;i<m_ic.interps.size();i++) { bool match=true; // all selected items must have names that match the wildcard for this grouping wxString pathlist=paths; wxString ipath=paths.BeforeFirst('*'); // '*' separated list if (m_ic.interps[i].wildcards!=_T("")) { while (match && pathlist!=_T("")) { wxString name=wxFileName(ipath).GetFullName(); if (ipath!=_T("") && !WildCardListMatch(m_ic.interps[i].wildcards,ipath)) match=false; pathlist=pathlist.AfterFirst('*'); ipath=pathlist.BeforeFirst('*'); } } if (match) { m_RunTarget=paths; //TODO: need a m_TargetParent to allow the FileExplorer to define the parent of a selection (usually the root of the fileexplorer view?) if (m_ic.interps[i].command.Find(_("$mpaths"))>=0) { wxString menutext=m_ic.interps[i].name; m_contextvec.Add(i); AddModuleMenuEntry(menu,i,added); added++; } } } } if (added>0) menu->InsertSeparator(sep_pos); } } }
bool PythonDebugger::IsPythonFile(const wxString &file) const { if(WildCardListMatch(PythonFileExtensions,file)) return true; return false; }
void ToolsPlus::OnRunTarget(wxCommandEvent& event) { int ID=event.GetId(); wxString commandstr; wxString consolename; wxString workingdir; bool windowed=false; bool console=false; if (ID>=ID_ContextMenu_0&&ID<=ID_ContextMenu_49) { m_interpnum=m_contextvec[ID-ID_ContextMenu_0]; commandstr=m_ic.interps[m_interpnum].command; consolename=m_ic.interps[m_interpnum].name; windowed=(m_ic.interps[m_interpnum].mode==_("W")); console=(m_ic.interps[m_interpnum].mode==_("C")); workingdir=m_ic.interps[m_interpnum].wdir; } else if (ID>=ID_SubMenu_0&&ID<=ID_SubMenu_49) { m_interpnum=ID-ID_SubMenu_0; commandstr=m_ic.interps[m_interpnum].command; consolename=m_ic.interps[m_interpnum].name; windowed=(m_ic.interps[m_interpnum].mode==_("W")); console=(m_ic.interps[m_interpnum].mode==_("C")); workingdir=m_ic.interps[m_interpnum].wdir; m_wildcard=m_ic.interps[m_interpnum].wildcards; if (m_ic.interps[m_interpnum].command.Find(_("$file"))>0 || m_ic.interps[m_interpnum].command.Find(_("$path"))>0) { m_RunTarget=wxEmptyString; EditorManager* edMan = Manager::Get()->GetEditorManager(); if (edMan && edMan->GetActiveEditor() && edMan->GetActiveEditor()->GetFilename()) { wxFileName activefile(edMan->GetActiveEditor()->GetFilename()); wxString filename=activefile.GetFullPath(); wxString name=activefile.GetFullName(); if (WildCardListMatch(m_ic.interps[m_interpnum].wildcards,name)) m_RunTarget=filename; } if (m_RunTarget==wxEmptyString) OnSetTarget(event); if (!wxFileName::FileExists(m_RunTarget)) { LogMessage(_("Tools Plus plugin: ")+m_RunTarget+_(" not found")); return; } } if (m_ic.interps[m_interpnum].command.Find(_("$dir"))>0) { OnSetDirTarget(event); if (!wxFileName::DirExists(m_RunTarget)) { LogMessage(_("Tools Plus plugin: ")+m_RunTarget+_(" not found")); return; } if (m_RunTarget==_T("")) return; } if (m_ic.interps[m_interpnum].command.Find(_("$mpaths"))>0) { OnSetMultiTarget(event); if (m_RunTarget==_T("")) return; } } else { LogMessage(wxString::Format(_("WARNING: Unprocessed Tools Plus Menu Message: ID %i, IDbase %i, IDend %i, num items on menu %i"),ID,ID_ContextMenu_0,ID_ContextMenu_49,(int)m_contextvec.size())); return; } m_RunTarget.Replace(_T("*"),_T(" ")); bool setdir=true; commandstr.Replace(_("$file"),wxFileName(m_RunTarget).GetShortPath()); commandstr.Replace(_("$relfile"),wxFileName(m_RunTarget).GetFullName()); commandstr.Replace(_("$fname"),wxFileName(m_RunTarget).GetName()); commandstr.Replace(_("$fext"),wxFileName(m_RunTarget).GetExt()); commandstr.Replace(_("$dir"),wxFileName(m_RunTarget).GetShortPath()); commandstr.Replace(_("$reldir"),wxFileName(m_RunTarget).GetFullName()); commandstr.Replace(_("$path"),wxFileName(m_RunTarget).GetShortPath()); commandstr.Replace(_("$relpath"),wxFileName(m_RunTarget).GetFullPath()); if (commandstr.Replace(_("$mpaths"),m_RunTarget)>0) setdir=false; // substitute user prompted values in the format: $inputstr{Enter your message} int promptind=commandstr.Find(_("$inputstr{")); wxString substitution; while (promptind>=0) { int promptend=commandstr.Mid(promptind+10).Find(_("}")); if (promptend<=0) { cbMessageBox(_("Malformed $inputstr in command line -- no closing '}' found: ")+commandstr); return; } else promptend++; wxTextEntryDialog ted(NULL,commandstr.Mid(promptind+10,promptend-1),consolename,_T(""),wxOK|wxCANCEL); if (ted.ShowModal()==wxID_OK) substitution=ted.GetValue(); else return; commandstr=commandstr.Left(promptind)+substitution+commandstr.Mid(promptind+10+promptend); int nextind=commandstr.Mid(promptind+substitution.Len()).Find(_("$inputstr")); if (nextind>=0) promptind+=nextind+substitution.Len(); else promptind=-1; } commandstr.Replace(_("$interpreter"),wxFileName(m_ic.interps[m_interpnum].command).GetShortPath()); workingdir.Replace(_("$parentdir"),wxFileName(m_RunTarget).GetPath()); if (wxFileName::DirExists(m_RunTarget)) workingdir.Replace(_("$dir"),wxFileName(m_RunTarget).GetFullPath()); if (Manager::Get()->GetMacrosManager()) { Manager::Get()->GetMacrosManager()->RecalcVars(0, 0, 0); // hack to force-update macros Manager::Get()->GetMacrosManager()->ReplaceMacros(commandstr); Manager::Get()->GetMacrosManager()->ReplaceMacros(workingdir); } wxString olddir=wxGetCwd(); if (setdir && workingdir!=_T("")) { if (!wxSetWorkingDirectory(workingdir)) { LogMessage(_("Tools Plus Plugin: Can't change to working directory to ")+workingdir); return; } } LogMessage(wxString::Format(_("Launching '%s': %s (in %s)"), consolename.c_str(), commandstr.c_str(), workingdir.c_str())); if (windowed) { wxArrayString astr; m_shellmgr->LaunchProcess(commandstr,consolename,_("Piped Process Control"),astr); ShowConsole(); } else if (console) { wxString cmdline; #ifndef __WXMSW__ // for non-win platforms, use m_ConsoleTerm to run the console app wxString term = Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/console_terminal"), DEFAULT_CONSOLE_TERM); term.Replace(_T("$TITLE"), _T("'") + consolename + _T("'")); cmdline<< term << _T(" "); #define CONSOLE_RUNNER "cb_console_runner" #else #define CONSOLE_RUNNER "cb_console_runner.exe" #endif wxString baseDir = ConfigManager::GetExecutableFolder(); if (wxFileExists(baseDir + wxT("/" CONSOLE_RUNNER))) cmdline << baseDir << wxT("/" CONSOLE_RUNNER " "); cmdline<<commandstr; if (!wxExecute(cmdline)) cbMessageBox(_("Command Launch Failed: ")+commandstr); } else { if (!wxExecute(commandstr)) cbMessageBox(_("Command Launch Failed: ")+commandstr); } wxSetWorkingDirectory(olddir); }
// called from Thread::Entry bool FileExplorerUpdater::GetCurrentState(const wxString &path) { //wxString wildcard=m_fe->m_WildCards->GetValue(); // m_Tree->DeleteChildren(ti); //Don't delete everything, we will add new files/dirs, remove deleted files/dirs and update state of all other files. m_currentstate.clear(); wxDir dir(path); if (!dir.IsOpened()) { // deal with the error here - wxDir would already log an error message // explaining the exact reason for the failure return false; } wxString filename; int flags=wxDIR_FILES|wxDIR_DIRS; if(m_fe->m_show_hidden) flags|=wxDIR_HIDDEN; VCSstatearray sa; bool is_vcs=false; bool is_cvs=false; // TODO: THIS NEEDS TO BE CALLED FROM MAIN THREAD BUT CAN'T BE UI-BLOCKING (CAN'T CALL wxExecute FROM THREADS) // TODO: IDEALLY THE VCS COMMAND LINE PROGRAM SHOULD BE CALLED ONCE ON THE BASE DIRECTORY (SINCE THEY ARE USUALLY RECURSIVE) TO AVOID REPEATED CALLS FOR SUB-DIRS if(m_fe->m_parse_svn) if(ParseSVNstate(path,sa)) is_vcs=true; if(m_fe->m_parse_bzr && !is_vcs) if(ParseBZRstate(path,sa)) is_vcs=true; if(m_fe->m_parse_hg && !is_vcs) if(ParseHGstate(path,sa)) is_vcs=true; /* if(m_fe->m_parse_cvs && !is_vcs) if(ParseCVSstate(path,sa)) { is_vcs=true; is_cvs=true; }*/ bool cont = dir.GetFirst(&filename,wxEmptyString,flags); while ( cont && !TestDestroy() && !m_kill) { int itemstate; bool match=true; wxString fullpath=wxFileName(path,filename).GetFullPath(); if(wxFileName::DirExists(fullpath)) itemstate=fvsFolderOpen; if(wxFileName::FileExists(fullpath)) { if(is_vcs&&!is_cvs) itemstate=fvsVcUpToDate; else itemstate=fvsNormal; wxFileName fn(path,filename); #if wxCHECK_VERSION(2,8,0) if(!fn.IsFileWritable()) itemstate=fvsReadOnly; #endif int deli=-1; for(size_t i=0;i<sa.GetCount();i++) { if(fn.SameAs(sa[i].path)) { itemstate=sa[i].state; deli=i; break; } } if(deli>=0) sa.RemoveAt(deli); if(!WildCardListMatch(m_wildcard,filename,true)) match=false; } if(match) { FileData fd; fd.name=filename; fd.state=itemstate; m_currentstate.push_back(fd); } cont = dir.GetNext(&filename); } return !TestDestroy(); }