bool MController::OpenInclude( string inFileName) { MProject* project = MProject::Instance(); MUrl url; if (mDocument != nil) { url = mDocument->GetURL(); url.SetPath(url.GetPath().branch_path() / inFileName); } bool result = false; if (url.IsValid()) { if (url.IsLocal()) result = fs::exists(url.GetPath()); else result = true; } MPath p; if (not result and project != nil and project->LocateFile(inFileName, true, p)) { result = true; url = MUrl(p); } if (result) gApp->OpenOneDocument(url); return result; }
bool VMsgLog::saveLogAs() { bool ok = FALSE; WFileName fn( "log" ); MProject* project = _parent->project(); if( project ) { project->filename().noPath( fn ); } fn.setExt( ".txt" ); WFileDialog fd( this, sFilter ); fn = fd.getOpenFileName( fn, "Save Log as", WFSaveDefault ); if( fn.legal() ) { // fn.toLower(); WFile f; if( !f.open( fn, OStyleWrite ) ) { WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to save log file '%s'", (const char*)fn ); } else { int icount = _data.count(); for( int i=0; i<icount; i++ ) { f.puts( *(WString*)_data[i] ); f.puts( "\n" ); } f.close(); ok = TRUE; } } return ok; }
bool MFindAndOpenDialog::OKClicked() { string s; GetText(kTextBoxControlID, s); Preferences::SetString("last open include", s); if (mController != nil) { if (not mController->OpenInclude(s)) PlaySound("warning"); } else { MProject* project = dynamic_cast<MProject*>(GetParentWindow()); if (project == nil) project = MProject::Instance(); MPath p(s); if (exists(p) or (project != nil and project->LocateFile(s, true, p))) gApp->OpenOneDocument(MUrl(p)); } return true; }
void MTextController::DoOpenCounterpart() { MTextDocument* doc = dynamic_cast<MTextDocument*>(mDocument); if (doc == nil) return; bool result = false; const char* kSourceExtensions[] = { "c", "cc", "cp", "cpp", "c++", nil }; const char* kHeaderExtensions[] = { "h", "hp", "hpp", nil }; if (doc->IsSpecified()) { string name = doc->GetURL().GetFileName(); fs::path p; const char** ext = nil; if (FileNameMatches("*.h;*.hp;*.hpp", name)) ext = kSourceExtensions; else if (FileNameMatches("*.c;*.cc;*.cp;*.cpp;*.c++;*.inl", name)) ext = kHeaderExtensions; if (ext != nil) { name.erase(name.rfind('.') + 1); MProject* project = MProject::Instance(); if (project != nil) { for (const char** e = ext; result == false and *e != nil; ++e) result = project->LocateFile(name + *e, true, p); if (result) gApp->OpenOneDocument(MUrl(p)); } if (not result) { for (const char** e = ext; result == false and *e != nil; ++e) result = OpenInclude(name + *e); } } } if (not result) PlaySound("warning"); }
void copySysOSX(const char* projName) { #ifdef _DEBUG const char * appName = "MaratisPlayerDebug"; #else const char * appName = "MaratisPlayer"; #endif MWindow * window = MWindow::getInstance(); MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char filename[256]; getLocalFilename(filename, system->getWorkingDirectory(), projName); if(char* ext = strstr(filename, ".mproj")) { MProject proj; if(proj.loadXML(projName)) { strcpy(ext, ".app"); char path[256]; char srcName[256]; char destName[256]; char appPath[256]; char level[256]; getLocalFilename(level, system->getWorkingDirectory(), proj.startLevel.c_str()); getGlobalFilename(appPath, getPubDir(), filename); sprintf(path, "../../../%s.app", appName); getGlobalFilename(srcName, window->getCurrentDirectory(), path); copyDirectory(srcName, appPath); strcpy(ext, ""); sprintf(srcName, "%s/Contents/MacOS/%s", appPath, appName); strcpy(ext, ".mproj"); embedProject(srcName, srcName, filename, level, proj.renderer.c_str()); chmod(srcName, 0777); // we need to put all data in app/Contents/Resources/ sprintf(destName, "%s/Contents/Resources", appPath); createDirectory(destName); s_dataDir = destName; } } }
bool MaratisPlayer::loadProject(const char * filename) { if(! filename) return false; // load project file MProject proj; if(proj.loadXML(filename)) { loadProject(&proj, filename); return true; } return false; }
void copySysLinux(const char* projName) { #ifdef _DEBUG const char * appName = "MaratisPlayerDebug"; #else const char * appName = "MaratisPlayer"; #endif MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char filename[256]; getLocalFilename(filename, system->getWorkingDirectory(), projName); if(char* ext = strstr(filename, ".mproj")) { *ext = 0; MProject proj; if(proj.loadXML(projName)) { char destName[256]; getGlobalFilename(destName, getPubDir(), filename); char level[256]; getLocalFilename(level, system->getWorkingDirectory(), proj.startLevel.c_str()); strcpy(ext, ".mproj"); embedProject(appName, destName, filename, level, proj.renderer.c_str()); chmod(destName, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); // find all dynamic libraries copyDirFiles(".", getPubDir(), ".so"); } } }
void copySysWindows(const char* projName) { #ifdef _DEBUG const char * appName = "MaratisPlayerDebug.exe"; #else const char * appName = "MaratisPlayer.exe"; #endif MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char filename[256]; getLocalFilename(filename, system->getWorkingDirectory(), projName); if(char* ext = strstr(filename, ".mproj")) { MProject proj; if(proj.loadXML(projName)) { strcpy(ext, ".exe"); char destName[256]; getGlobalFilename(destName, getPubDir(), filename); char level[256]; getLocalFilename(level, system->getWorkingDirectory(), proj.startLevel.c_str()); // we need the project "filename" to still be a .mproj for MaratisPlayer to behave // correctly strcpy(ext, ".mproj"); embedProject(appName, destName, filename, level, proj.renderer.c_str()); // find all dynamic libraries copyDirFiles(".", getPubDir(), ".dll"); } } }
bool MController::UpdateCommandStatus( uint32 inCommand, MMenu* inMenu, uint32 inItemIndex, bool& outEnabled, bool& outChecked) { bool result = true; MProject* project = MProject::Instance(); MLanguage* lang = mDocument->GetLanguage(); string title; switch (inCommand) { // always case cmd_Close: case cmd_SaveAs: case cmd_SelectAll: case cmd_MarkLine: case cmd_CompleteLookingBack: case cmd_CompleteLookingFwd: case cmd_JumpToNextMark: case cmd_JumpToPrevMark: case cmd_FastFind: case cmd_FastFindBW: case cmd_Find: case cmd_FindNext: case cmd_FindPrev: case cmd_ReplaceAll: case cmd_Entab: case cmd_Detab: case cmd_SwitchHeaderSource: case cmd_GoToLine: case cmd_ShiftLeft: case cmd_ShiftRight: case cmd_OpenIncludeFile: case cmd_ShowDocInfoDialog: case cmd_ShowDiffWindow: outEnabled = true; break; // dirty case cmd_Save: outEnabled = mDocument->IsModified() and (not mDocument->IsSpecified() or not mDocument->IsReadOnly()); break; // has selection case cmd_Cut: case cmd_Copy: case cmd_Clear: case cmd_CopyAppend: case cmd_CutAppend: case cmd_EnterSearchString: case cmd_EnterReplaceString: outEnabled = not mDocument->GetSelection().IsEmpty(); break; // special case cmd_Undo: outEnabled = mDocument->CanUndo(title); break; case cmd_Redo: outEnabled = mDocument->CanRedo(title); break; case cmd_Revert: outEnabled = mDocument->IsSpecified() and mDocument->IsModified(); break; case cmd_Paste: case cmd_PasteNext: outEnabled = MClipboard::Instance().HasData(); break; case cmd_Balance: case cmd_Comment: case cmd_Uncomment: outEnabled = mDocument->GetLanguage() != nil and not mDocument->GetSelection().IsBlock(); break; case cmd_Replace: case cmd_ReplaceFindNext: case cmd_ReplaceFindPrev: outEnabled = mDocument->CanReplace(); break; case cmd_Softwrap: outEnabled = true; outChecked = mDocument->GetSoftwrap(); break; case cmd_Preprocess: case cmd_Compile: case cmd_CheckSyntax: case cmd_Disassemble: outEnabled = project != nil and mDocument->GetURL().IsLocal() and project->IsFileInProject(mDocument->GetURL().GetPath()); break; case cmd_2CharsPerTab: outEnabled = true; outChecked = mDocument->GetCharsPerTab() == 2; break; case cmd_4CharsPerTab: outEnabled = true; outChecked = mDocument->GetCharsPerTab() == 4; break; case cmd_8CharsPerTab: outEnabled = true; outChecked = mDocument->GetCharsPerTab() == 8; break; case cmd_16CharsPerTab: outEnabled = true; outChecked = mDocument->GetCharsPerTab() == 16; break; case cmd_SyntaxNone: outEnabled = true; outChecked = (lang == nil); break; case cmd_SyntaxLanguage: outEnabled = true; outChecked = (lang != nil and lang->GetName() == inMenu->GetItemLabel(inItemIndex)); break; default: result = false; break; } return result; }
bool MController::ProcessCommand( uint32 inCommand, const MMenu* inMenu, uint32 inItemIndex) { bool result = false; if (mDocument != nil) { result = true; MProject* project = MProject::Instance(); string s; switch (inCommand) { case cmd_Close: TryCloseController(kSaveChangesClosingDocument); break; case cmd_Save: SaveDocument(); break; case cmd_SaveAs: SaveDocumentAs(); break; case cmd_Revert: TryDiscardChanges(); break; case cmd_Undo: mDocument->DoUndo(); break; case cmd_Redo: mDocument->DoRedo(); break; case cmd_Cut: mDocument->DoCut(false); break; case cmd_Copy: mDocument->DoCopy(false); break; case cmd_Paste: mDocument->DoPaste(); break; case cmd_Clear: mDocument->DoClear(); break; case cmd_SelectAll: mDocument->SelectAll(); break; case cmd_Balance: mDocument->DoBalance(); break; case cmd_ShiftLeft: mDocument->DoShiftLeft(); break; case cmd_ShiftRight: mDocument->DoShiftRight(); break; case cmd_Entab: mDocument->DoEntab(); break; case cmd_Detab: mDocument->DoDetab(); break; case cmd_Comment: mDocument->DoComment(); break; case cmd_Uncomment: mDocument->DoUncomment(); break; case cmd_PasteNext: mDocument->DoPasteNext(); break; case cmd_CopyAppend: mDocument->DoCopy(true); break; case cmd_CutAppend: mDocument->DoCut(true); break; case cmd_FastFind: mDocument->DoFastFind(kDirectionForward); break; case cmd_FastFindBW: mDocument->DoFastFind(kDirectionBackward); break; case cmd_Find: MFindDialog::Instance().Select(); break; case cmd_FindNext: if (not mDocument->DoFindNext(kDirectionForward)) PlaySound("warning"); break; case cmd_FindPrev: if (not mDocument->DoFindNext(kDirectionBackward)) PlaySound("warning"); break; case cmd_EnterSearchString: mDocument->GetSelectedText(s); MFindDialog::Instance().SetFindString(s, false); break; case cmd_EnterReplaceString: mDocument->GetSelectedText(s); MFindDialog::Instance().SetReplaceString(s); break; case cmd_Replace: mDocument->DoReplace(false, kDirectionForward); break; case cmd_ReplaceAll: mDocument->DoReplaceAll(); break; case cmd_ReplaceFindNext: mDocument->DoReplace(true, kDirectionForward); break; case cmd_ReplaceFindPrev: mDocument->DoReplace(true, kDirectionBackward); break; case cmd_CompleteLookingBack: mDocument->DoComplete(kDirectionBackward); break; case cmd_CompleteLookingFwd: mDocument->DoComplete(kDirectionForward); break; case cmd_ClearMarks: mDocument->ClearAllMarkers(); break; case cmd_MarkLine: mDocument->DoMarkLine(); break; case cmd_JumpToNextMark: mDocument->DoJumpToNextMark(kDirectionForward); break; case cmd_JumpToPrevMark: mDocument->DoJumpToNextMark(kDirectionBackward); break; case cmd_MarkMatching: DoMarkMatching(); break; case cmd_CutMarkedLines: mDocument->CCCMarkedLines(true, true); break; case cmd_CopyMarkedLines: mDocument->CCCMarkedLines(true, false); break; case cmd_ClearMarkedLines: mDocument->CCCMarkedLines(false, true); break; case cmd_OpenIncludeFile: DoOpenIncludeFile(); break; case cmd_GoToLine: DoGoToLine(); break; case cmd_SwitchHeaderSource: DoOpenCounterpart(); break; case cmd_Softwrap: mDocument->DoSoftwrap(); break; case cmd_ShowDocInfoDialog: // if (mDocument != nil) // { // std::auto_ptr<MDocInfoDialog> dlog(new MDocInfoDialog); // dlog->Initialize(mDocument, mWindow); // dlog.release(); // } break; case cmd_SelectFunctionFromMenu: mDocument->SelectParsePopupItem(inItemIndex); break; case cmd_OpenIncludeFromMenu: mDocument->SelectIncludePopupItem(inItemIndex); break; case cmd_Preprocess: if (project != nil) project->Preprocess(mDocument->GetURL().GetPath()); break; case cmd_CheckSyntax: if (project != nil) project->CheckSyntax(mDocument->GetURL().GetPath()); break; case cmd_Compile: if (project != nil) project->Compile(mDocument->GetURL().GetPath()); break; case cmd_Disassemble: if (project != nil) project->Disassemble(mDocument->GetURL().GetPath()); break; case cmd_2CharsPerTab: if (mDocument != nil) mDocument->SetCharsPerTab(2); break; case cmd_4CharsPerTab: if (mDocument != nil) mDocument->SetCharsPerTab(4); break; case cmd_8CharsPerTab: if (mDocument != nil) mDocument->SetCharsPerTab(8); break; case cmd_16CharsPerTab: if (mDocument != nil) mDocument->SetCharsPerTab(16); break; case cmd_SyntaxNone: mDocument->SetLanguage(""); break; case cmd_SyntaxLanguage: mDocument->SetLanguage(inMenu->GetItemLabel(inItemIndex)); break; case cmd_Stop: result = mDocument->StopRunningShellCommand(); break; case cmd_ShowDiffWindow: { auto_ptr<MDiffWindow> w(new MDiffWindow(mDocument)); w->Select(); w.release(); break; } default: result = false; break; } } return result; }
void MFindDialog::GetFilesForFindAll( MMultiMethod inMethod, const fs::path& inDirectory, bool inRecursive, bool inTextFilesOnly, const string& inFileNameFilter, FileSet& outFiles) { SetStatusString(inDirectory.string()); switch (inMethod) { case eMMDirectory: { uint32 flags = 0; if (inRecursive) flags |= kFileIter_Deep; if (inTextFilesOnly) flags |= kFileIter_TEXTFilesOnly; MFileIterator iter(inDirectory, flags); if (inFileNameFilter.c_str()) iter.SetFilter(inFileNameFilter); fs::path file; while (iter.Next(file)) outFiles.insert(file); break; } case eMMOpenWindows: { MDocument* doc = MDocument::GetFirstDocument(); while (doc != nil) { fs::path file = doc->GetURL().GetPath(); if (exists(file)) outFiles.insert(file); doc = doc->GetNextDocument(); } break; } case eMMIncludes: { MProject* project = MProject::Instance(); if (project != nil) { vector<fs::path> includePaths; project->GetIncludePaths(includePaths); sort(includePaths.begin(), includePaths.end()); includePaths.erase(unique(includePaths.begin(), includePaths.end()), includePaths.end()); for (vector<fs::path>::iterator p = includePaths.begin(); p != includePaths.end(); ++p) GetFilesForFindAll(eMMDirectory, *p, inRecursive, inTextFilesOnly, inFileNameFilter, outFiles); } break; } } }