void MFindDialog::FindAll( const string& inWhat, bool inIgnoreCase, bool inRegex, MMultiMethod inMethod, fs::path inDirectory, bool inRecursive, bool inTextFilesOnly, const string& inFileNameFilter) { mStopFindAll = false; try { FileSet files; auto_ptr<MMessageList> list(new MMessageList); GetFilesForFindAll(inMethod, inDirectory, inRecursive, inTextFilesOnly, inFileNameFilter, files); for (FileSet::iterator file = files.begin(); file != files.end(); ++file) { if (mStopFindAll) break; SetStatusString(file->string()); MUrl url(*file); bool searched = false; gdk_threads_enter(); MTextDocument* doc = dynamic_cast<MTextDocument*>(MDocument::GetDocumentForURL(url)); if (doc != nil) { doc->FindAll(inWhat, inIgnoreCase, inRegex, false, *list.get()); searched = true; } gdk_threads_leave(); if (not searched) MTextDocument::FindAll(*file, inWhat, inIgnoreCase, inRegex, false, *list.get()); } mFindAllResult = list.release(); } catch (exception& e) { mFindAllResult = new MMessageList; // flag failure... sucks.. I know mFindAllResult->AddMessage(kMsgKindError, fs::path(), 0, 0, 0, "Error in find all, sorry"); mFindAllResult->AddMessage(kMsgKindError, fs::path(), 0, 0, 0, e.what()); } catch (...) { mFindAllResult = new MMessageList; // flag failure... sucks.. I know mFindAllResult->AddMessage(kMsgKindError, fs::path(), 0, 0, 0, "Error in find all, sorry"); } }
bool PathHandler::_HasFile(const node_ref& nodeRef) const { FileEntry setEntry; setEntry.ref.device = nodeRef.device; setEntry.node = nodeRef.node; // name does not need to be set, since it's not used for comparing FileSet::const_iterator iterator = fFiles.find(setEntry); return iterator != fFiles.end(); }
status_t PathHandler::_RemoveFile(const node_ref& nodeRef) { TRACE(" REMOVE FILE %ld:%Ld\n", nodeRef.device, nodeRef.node); FileEntry setEntry; setEntry.ref.device = nodeRef.device; setEntry.node = nodeRef.node; // name does not need to be set, since it's not used for comparing FileSet::iterator iterator = fFiles.find(setEntry); if (iterator == fFiles.end()) return B_ENTRY_NOT_FOUND; watch_node(&nodeRef, B_STOP_WATCHING, this); fFiles.erase(iterator); return B_OK; }
void PathHandler::Dump() { TRACE("WATCHING DIRECTORIES:\n"); DirectorySet::iterator i = fDirectories.begin(); for (; i != fDirectories.end(); i++) { TRACE(" %ld:%Ld (%s)\n", i->node.device, i->node.node, i->contained ? "contained" : "-"); } TRACE("WATCHING FILES:\n"); FileSet::iterator j = fFiles.begin(); for (; j != fFiles.end(); j++) { TRACE(" %ld:%Ld\n", j->ref.device, j->node); } }
void PathHandler::_NotifyTarget(BMessage* message, const node_ref& nodeRef) const { BMessage update(*message); update.what = B_PATH_MONITOR; TRACE("_NotifyTarget(): node ref %ld.%Ld\n", nodeRef.device, nodeRef.node); WatchedDirectory directory; directory.node = nodeRef; DirectorySet::const_iterator iterator = fDirectories.find(directory); if (iterator != fDirectories.end()) { if (_WatchFilesOnly()) { // stat or attr notification for a directory return; } BDirectory nodeDirectory(&nodeRef); BEntry entry; if (nodeDirectory.GetEntry(&entry) == B_OK) { BPath path(&entry); update.AddString("path", path.Path()); } } else { if (_WatchFoldersOnly()) { // this is bound to be a notification for a file return; } FileEntry setEntry; setEntry.ref.device = nodeRef.device; setEntry.node = nodeRef.node; // name does not need to be set, since it's not used for comparing FileSet::const_iterator i = fFiles.find(setEntry); if (i != fFiles.end()) { BPath path(&(i->ref)); update.AddString("path", path.Path()); } } // This is in case the target is interested in figuring out which // BPathMonitor::StartWatching() call the message is resulting from. update.AddString("watched_path", fPath.Path()); fTarget.SendMessage(&update); }
void LocalProcess::directoryChanged(const QString &str) { FileSet fs = dirFiles(openstudio::toQString(m_outdir)); std::vector<FileSet::value_type> diff; { QMutexLocker l(&m_mutex); std::set_symmetric_difference(fs.begin(), fs.end(), m_outfiles.begin(), m_outfiles.end(), std::back_inserter(diff)); m_outfiles = fs; } std::for_each(diff.begin(), diff.end(), boost::bind(&LocalProcess::emitUpdatedFileInfo, this, _1)); m_process.checkProcessStatus(); }
void MFindDialog::DoFindCommand( uint32 inCommand) { // check regular expression first? if (mMultiMode and IsChecked(kBatchCheckboxID) and mFindAllThread != nil) { PlaySound("warning"); return; } mInSelection = IsChecked(kInSelectionCheckboxID); string what; GetText(kFindComboboxID, what); StoreComboText(kFindComboboxID, what, mFindStrings); string with; GetText(kReplaceComboboxID, with); StoreComboText(kReplaceComboboxID, with, mReplaceStrings); string where; GetText(kStartDirComboboxID, where); StoreComboText(kStartDirComboboxID, where, mStartDirectories); MTextDocument* doc = MTextDocument::GetFirstTextDocument(); if (IsExpanded(kMultiFileExpanderID)) { fs::path dir; bool recursive, textFilesOnly; string filter; MMultiMethod method = eMMDirectory; recursive = IsChecked(kRecursiveCheckboxID); textFilesOnly = IsChecked(kTextFilesOnlyCheckboxID); if (IsChecked(kEnableFilterCheckboxID)) GetText(kNameFilterEditboxID, filter); switch (GetValue(kMethodPopupID)) { case kMethodDirectory: { dir = where; if (not exists(dir) or not is_directory(dir)) THROW(("Start directory does not exist or is not a directory")); method = eMMDirectory; break; } case kMethodIncludeFiles: method = eMMIncludes; break; case kMethodOpenWindows: method = eMMOpenWindows; break; } if (IsChecked(kBatchCheckboxID)) { mFindAllThread = new boost::thread( boost::bind(&MFindDialog::FindAll, this, what, IsChecked(kIgnoreCaseCheckboxID), IsChecked(kRegexCheckboxID), method, dir, recursive, textFilesOnly, filter)); } else { mMultiFiles.clear(); FileSet files; GetFilesForFindAll(method, dir, recursive, textFilesOnly, filter, files); copy(files.begin(), files.end(), back_inserter(mMultiFiles)); switch (inCommand) { case cmd_FindNext: FindNext(); break; case cmd_ReplaceAll: switch (DisplayAlert("replace-all-alert")) { case kReplaceAll_Save: ReplaceAll(true); break; case kReplaceAll_LeaveOpen: ReplaceAll(false); break; } break; } } } else if (IsChecked(kBatchCheckboxID)) { if (doc != nil) { MMessageList list; doc->FindAll(what, IsChecked(kIgnoreCaseCheckboxID), IsChecked(kRegexCheckboxID), IsChecked(kInSelectionCheckboxID), list); if (list.GetCount()) { MMessageWindow* w = new MMessageWindow(""); w->SetMessages( FormatString("Found ^0 hits for ^1", list.GetCount(), mFindStrings.front()), list); } } } else { if (doc != nil) doc->HandleFindDialogCommand(inCommand); } }
LocalProcess::FileSet LocalProcess::dirFiles(const QString &dir) const { QFileInfoList fil; QDir subdirs(dir, "mergedjob-*", QDir::Name, QDir::Dirs); QFileInfoList mergedjobdirs = subdirs.entryInfoList(); for (QFileInfoList::const_iterator itr = mergedjobdirs.begin(); itr != mergedjobdirs.end(); ++itr) { QDir mergeddir(itr->absoluteFilePath(), "", QDir::Name, QDir::Files); fil.append(mergeddir.entryInfoList()); } QDir d(dir, "", QDir::Name, QDir::Files); fil.append(d.entryInfoList()); QFileInfoList filtered; // Filter out all files that are part of the set of input files. Everything remaining should be an outputfile for (QFileInfoList::const_iterator itr = fil.begin(); itr != fil.end(); ++itr) { bool partofinput = false; for (std::vector<std::pair<openstudio::path, openstudio::path> >::const_iterator itr2 = m_requiredFiles.begin(); itr2 != m_requiredFiles.end(); ++itr2) { QString fileName = itr->fileName(); QString fileName2 = toQString(itr2->second.filename()); if (fileName == fileName2) { partofinput = true; break; } } if (!partofinput) { filtered.push_back(*itr); } } FileSet out; typedef FileInfo (*filetransform)(QFileInfo); try{ std::transform(filtered.begin(), filtered.end(), std::inserter(out, out.end()), static_cast<filetransform>(&RunManager_Util::dirFile)); } catch(openstudio::Exception& e) { LOG_AND_THROW("Exception caught " << e.what()); } return out; }