Beispiel #1
0
void Styler_Syntax::ApplyDiff(const vector<cxLineChange>& linechanges) {
	if (m_lines.GetLength() == 0) {
		Invalidate();
		return;
	}

	m_updateLineHeight = true;
#ifdef __WXDEBUG__
	// Syntax after change is not valid during application of diff
	m_verifyEnabled = false;
#endif

	for (vector<cxLineChange>::const_iterator l = linechanges.begin(); l != linechanges.end(); ++l) {
		// Adjust syntax end
		if (m_syntax_end > l->start) {
			if (m_syntax_end > l->end) m_syntax_end += l->diff;
			else m_syntax_end = l->start;
		}
		else goto cleanup_and_return; // Change after search area, no need to re-search

		const unsigned int old_line_end = l->end - l->diff;
		const unsigned int new_length = l->end - l->start;
		unsigned int change_end = l->end;

		// Adjust matches
		if (l->start != old_line_end) change_end = wxMax(AdjustForDeletion(l->start, old_line_end, m_topMatches, 0, l->start), change_end);;
		if (new_length) change_end = wxMax(AdjustForInsertion(l->start, new_length, m_topMatches, 0, l->start), change_end);

		// limit parsing upto next changed line
		unsigned int limit;
		vector<cxLineChange>::const_iterator nextchange = l+1;
		if (nextchange != linechanges.end()) limit = nextchange->start;
		else limit = m_lines.GetLineEndFromPos(change_end);
		
		if (l->start < limit) DoSearch(l->start, l->end, limit); 	
	}

cleanup_and_return:
	m_updateLineHeight = false;

#ifdef __WXDEBUG__
	m_verifyEnabled = true;
	Verify();
#endif
}
Beispiel #2
0
void SoundCloudService::Search(const QString& text, bool now) {
  pending_search_ = text;

  // If there is no text (e.g. user cleared search box), we don't need to do a
  // real query that will return nothing: we can clear the playlist now
  if (text.isEmpty()) {
    search_delay_->stop();
    ClearSearchResults();
    return;
  }

  if (now) {
    search_delay_->stop();
    DoSearch();
  } else {
    search_delay_->start();
  }
}
Beispiel #3
0
bool cAmp::KeysEdit(bool shift, WPARAM k)
{
	//  Edit Tab Name
	switch(k)  {	// strlen, left,right,ctrl, home,end ...
		//  <del
		case VK_BACK:  ied--;  if (ied<0) ied=0;  sed[ied]=0;  fTi=0.5f;  rt
		
		case VK_ESCAPE: case VK_F2: case VK_F3:  GuiOff();  rt	//  exit

		case VK_RETURN: //  accept
			switch(ed)	{
				case ED_nTab:
				{	pls->name = sed;	GuiOff();
					pls->Save();  SetSave();  }  rt
				case ED_nFind:
				{	scpy(srch, sed);  GuiOff();  DoSearch();  }  rt
			}	rt

		default:	//  add char
		{	if (ied >= (ed==ED_nTab?NamePls:NameSrch)-1)  rt
			char c = 0;
			//  key char codes
			if (k>='0' && k<='9'){	if (shift) c=chShNum[k-'0']; else c=k;  }  else
			if (k>='A' && k<='Z'){	if (shift) c=k; else c=k-'A'+'a';  }  else
			switch (k)
			{
				case VK_SPACE:		c=' ';  break;
				case VK_OEM_3:		if (shift) c='~'; else c='`';  break;
				case VK_OEM_MINUS:	if (shift) c='_'; else c='-';  break;
				case VK_OEM_PLUS:	if (shift) c='+'; else c='=';  break;
				case VK_OEM_4:		if (shift) c='{'; else c='[';  break;
				case VK_OEM_6:		if (shift) c='}'; else c=']';  break;
				case VK_OEM_7:		c='\'';  break;
				case VK_OEM_PERIOD:	c='.';  break;
				case VK_OEM_COMMA:	c=',';  break;
			}
			if (c==0)  rt	//  write char
			sed[ied]= (char)c;  ied++;  sed[ied]=0;  fTi=0.5f;
			//... le ri del bck
		}  rt
	}	rf
}
void QuickFindBar::OnFindPreviousCaret(wxCommandEvent& e)
{
    CHECK_FOCUS_WIN();

    wxString selection(DoGetSelectedText());
    if(selection.IsEmpty()) {
        // select the word
        long pos = m_sci->GetCurrentPos();
        long start = m_sci->WordStartPosition(pos, true);
        long end = m_sci->WordEndPosition(pos, true);

        selection = m_sci->GetTextRange(start, end);
        if(selection.IsEmpty() == false) m_sci->SetCurrentPos(start);
    }

    if(selection.IsEmpty()) return;

    m_findWhat->ChangeValue(selection);
    DoSearch(0);
}
Beispiel #5
0
/**
 * Make some initial calculations and preparations
 */
IPath::SearchResult CPathEstimator::InitSearch(const MoveData& moveData, const CPathFinderDef& peDef) {
	// is starting square inside goal area?
	int xSquare = blockState[startBlocknr].sqrCenter[moveData.pathType].x;
	int zSquare = blockState[startBlocknr].sqrCenter[moveData.pathType].y;
	if (peDef.IsGoal(xSquare, zSquare))
		return CantGetCloser;

	// no, clean the system from last search
	ResetSearch();

	// mark and store the start-block
	blockState[startBlocknr].options |= PATHOPT_OPEN;
	blockState[startBlocknr].cost = 0;
	dirtyBlocks.push_back(startBlocknr);

	openBlockBufferIndex = 0;
	// add the starting block to the open-blocks-queue
	OpenBlock* ob = &openBlockBuffer[openBlockBufferIndex];
		ob->cost = 0;
		ob->currentCost = 0;
		ob->block = startBlock;
		ob->blocknr = startBlocknr;
	openBlocks.push(ob);

	// mark starting point as best found position
	goalBlock = startBlock;
	goalHeuristic = peDef.Heuristic(xSquare, zSquare);

	// get the goal square offset
	goalSqrOffset = peDef.GoalSquareOffset(BLOCK_SIZE);

	// perform the search
	SearchResult result = DoSearch(moveData, peDef);

	// if no improvements are found, then return CantGetCloser instead
	if (goalBlock.x == startBlock.x && goalBlock.y == startBlock.y)
		return CantGetCloser;
	else
		return result;
}
/*
Setting up the starting point of the search.
*/
IPath::SearchResult CPathFinder::InitSearch(const MoveData& moveData, const CPathFinderDef& pfDef) {
    //If exact path is reqired and the goal is blocked, then no search is needed.
    if(exactPath && pfDef.GoalIsBlocked(moveData, (CMoveMath::BLOCK_STRUCTURE | CMoveMath::BLOCK_TERRAIN)))
        return CantGetCloser;

    //If the starting position is a goal position, then no search need to be performed.
    if(pfDef.IsGoal(startxSqr, startzSqr))
        return CantGetCloser;

    //Clearing the system from last search.
    ResetSearch();

    //Marks and store the start-square.
    squareState[startSquare].status = (PATHOPT_START | PATHOPT_OPEN);
    squareState[startSquare].cost = 0;
    dirtySquares.push_back(startSquare);

    //Make the beginning the fest square found.
    goalSquare = startSquare;
    goalHeuristic = pfDef.Heuristic(startxSqr, startzSqr);

    //Adding the start-square to the queue.
    openSquareBufferPointer = &openSquareBuffer[0];
    OpenSquare *os = openSquareBufferPointer;	//Taking first OpenSquare in buffer.
    os->currentCost = 0;
    os->cost = 0;
    os->square.x = startxSqr;
    os->square.y = startzSqr;
    os->sqr = startSquare;
    openSquares.push(os);

    //Performs the search.
    SearchResult result = DoSearch(moveData, pfDef);

    //If no improvement has been found then return CantGetCloser instead.
    if(goalSquare == startSquare || goalSquare == 0) {
        return CantGetCloser;
    } else
        return result;
}
SpotifyService::SpotifyService(InternetModel* parent)
    : InternetService(kServiceName, parent, parent),
      server_(NULL),
      url_handler_(new SpotifyUrlHandler(this, this)),
      blob_process_(NULL),
      root_(NULL),
      search_(NULL),
      starred_(NULL),
      inbox_(NULL),
      login_task_id_(0),
      pending_search_playlist_(NULL),
      context_menu_(NULL),
      search_delay_(new QTimer(this)),
      login_state_(LoginState_OtherError) {
  // Build the search path for the binary blob.
  // Look for one distributed alongside clementine first, then check in the
  // user's home directory for any that have been downloaded.
#ifdef Q_OS_MAC
  system_blob_path_ = QCoreApplication::applicationDirPath() +
      "/../PlugIns/clementine-spotifyblob";
#else
  system_blob_path_ = QCoreApplication::applicationDirPath() +
      "/clementine-spotifyblob" CMAKE_EXECUTABLE_SUFFIX;
#endif

  local_blob_version_ = QString("version%1-%2bit").arg(SPOTIFY_BLOB_VERSION).arg(sizeof(void*) * 8);
  local_blob_path_    = Utilities::GetConfigPath(Utilities::Path_LocalSpotifyBlob) +
                        "/" + local_blob_version_ + "/blob";

  qLog(Debug) << "Spotify system blob path:" << system_blob_path_;
  qLog(Debug) << "Spotify local blob path:" << local_blob_path_;

  model()->player()->RegisterUrlHandler(url_handler_);
  model()->player()->playlists()->RegisterSpecialPlaylistType(
        new SpotifySearchPlaylistType(this));

  search_delay_->setInterval(kSearchDelayMsec);
  search_delay_->setSingleShot(true);
  connect(search_delay_, SIGNAL(timeout()), SLOT(DoSearch()));
}
Beispiel #8
0
// Search for a string
void MainWindow::Search(bool ask)
{
    long position;

    if (ask || m_searchString.empty())
    {
        wxString s = wxGetTextFromUser( wxT("Enter search string"), wxT("Search"), m_searchString);
        if (!s.empty())
        {
            s.MakeLower();
            m_searchString = s;
            search_ok = true;
        }
        else
        {
            search_ok = false;
        }
    }
    else
    {
        same_search = true;
        search_ok = true;
    }

    if (!m_searchString.empty() && search_ok)
    {
        position = DoSearch();
        if (position > -1)
        {
            loaded_ok = LoadPoem(data_filename, position);
            Resize();
        }
        else
        {
            last_poem_start = 0;
            PoetryNotify(wxT("Search string not found."));
        }
    }
}
/*
Making some initial calculations and preparations.
*/
IPath::SearchResult CPathEstimator::InitSearch(const MoveData& moveData, const CPathFinderDef& peDef) {
	//Starting square is inside goal area?
	int xSquare = blockState[startBlocknr].sqrCenter[moveData.pathType].x;
	int zSquare = blockState[startBlocknr].sqrCenter[moveData.pathType].y;
	if(peDef.IsGoal(xSquare, zSquare))
		return CantGetCloser;

	//Cleaning the system from last search.
	ResetSearch();

	//Marks and store the start-block.
	blockState[startBlocknr].options |= PATHOPT_OPEN;
	blockState[startBlocknr].cost = 0;
	dirtyBlocks.push_back(startBlocknr);

	//Adding the starting block to the open-blocks-queue.
	OpenBlock* ob = openBlockBufferPointer = openBlockBuffer;
	ob->cost = 0;
	ob->currentCost = 0;
	ob->block = startBlock;
	ob->blocknr = startBlocknr;
	openBlocks.push(ob);

	//Mark starting point as best found position.
	goalBlock = startBlock;
	goalHeuristic = peDef.Heuristic(xSquare, zSquare);

	//Gets goal square offset.
	goalSqrOffset = peDef.GoalSquareOffset(BLOCK_SIZE);

	//Performs the search.
	SearchResult result = DoSearch(moveData, peDef);

	//If no improvements are found, then return CantGetCloser instead.
	if(goalBlock.x == startBlock.x && goalBlock.y == startBlock.y)
		return CantGetCloser;
	else
		return result;
}
Beispiel #10
0
SoundCloudService::SoundCloudService(Application* app, InternetModel* parent)
    : InternetService(kServiceName, app, parent, parent),
      root_(nullptr),
      search_(nullptr),
      user_tracks_(nullptr),
      user_playlists_(nullptr),
      user_activities_(nullptr),
      network_(new NetworkAccessManager(this)),
      context_menu_(nullptr),
      search_box_(new SearchBoxWidget(this)),
      search_delay_(new QTimer(this)),
      next_pending_search_id_(0) {
  search_delay_->setInterval(kSearchDelayMsec);
  search_delay_->setSingleShot(true);
  connect(search_delay_, SIGNAL(timeout()), SLOT(DoSearch()));

  SoundCloudSearchProvider* search_provider =
      new SoundCloudSearchProvider(app_, this);
  search_provider->Init(this);
  app_->global_search()->AddProvider(search_provider);

  connect(search_box_, SIGNAL(TextChanged(QString)), SLOT(Search(QString)));
}
Beispiel #11
0
void SearchThread::SearchDir(const wxString& path, const SearchInfo& si, ProjectInfoHandler& infoHandler) {
    MMapBuffer buf;
    wxFileName filepath;
    vector<FileMatch> matches;

    wxArrayString dirs;
    wxArrayString filenames;
    infoHandler.GetDirAndFileLists(path, dirs, filenames);

    for (size_t f = 0; f < filenames.size(); ++f) {
        if (!m_isSearching) return;
        m_outputCrit.Enter();
        m_currentPath = path + filenames[f];
        m_outputCrit.Leave();
        filepath = m_currentPath;

        // Map the file to memory
        buf.Open(filepath);
        if (!buf.IsMapped()) {
            wxLogDebug(wxT(" Mapping failed!"));
            continue;
        }

        // Search the file
        DoSearch(buf, si, matches);
        if (matches.empty()) continue;

        // Show matches
        WriteResult(buf, filepath, matches);
        matches.clear();
    }

    for (size_t d = 0; d < dirs.size(); ++d) {
        const wxString dirpath = path + dirs[d] + wxFILE_SEP_PATH;
        SearchDir(dirpath, si, infoHandler);
    }
}
Beispiel #12
0
void Styler_Syntax::Style(StyleRun& sr) {
	if (!HaveActiveSyntax()) return;

	unsigned int sr_end = sr.GetRunEnd();

	// Check if we need to do a new search
	if (sr_end > m_syntax_end) {
		// Make sure the extended position is valid and extends
		// from start-of-line to end-of-line
		unsigned int sr_start;
		cxLOCKDOC_READ(m_doc)
			sr_start = doc.GetLineStart(m_syntax_end);
		cxENDLOCK

		// Extend stylerun to get better search results (round up to whole EXTSIZEs)
		const unsigned int ext = ((sr_end / EXTSIZE) + 1) * EXTSIZE;
		sr_end =  ext < m_lines.GetLength() ? ext : m_lines.GetLength();
		sr_end = m_lines.GetLineEndFromPos(sr_end);

		DoSearch(sr_start, sr_end, sr_end);
	}

	// Apply base style
	if (m_topStyle) {
		const unsigned int start =  sr.GetRunStart();
		const unsigned int end = sr.GetRunEnd();
		if (m_topStyle->foregroundcolor != wxNullColour) sr.SetForegroundColor(start, end, m_topStyle->foregroundcolor);
		if (m_topStyle->backgroundcolor != wxNullColour) {
			sr.SetBackgroundColor(start, end, m_topStyle->backgroundcolor);
			sr.SetExtendBgColor(m_topStyle->backgroundcolor);
		}
		if (m_topStyle->fontflags != wxFONTFLAG_DEFAULT) sr.SetFontStyle(start, end, m_topStyle->fontflags);
	}

	// Style the run
	DoStyle(sr, 0, m_topMatches.matches);
}
Beispiel #13
0
int StartSearch(
  HWND hWnd,
  WPARAM wParam,
  LPARAM lParam)
  {  
   FINDREPLACE FAR *lpfr;

   lpfr = (FINDREPLACE FAR *) lParam;

   /*==========================================*/
   /* Terminate Find/Replace Dialog if needed. */
   /*==========================================*/
   
   if (lpfr->Flags & FR_DIALOGTERM)
     {  
      HMENU hMenu = GetMenu(hMainFrame);

      EnableMenuItem(hMenu,ID_BUFFER_FIND,MF_ENABLED);
      EnableMenuItem(hMenu,ID_BUFFER_REPLACE,MF_ENABLED);
      SearchActive = FALSE;
      return 0;
	 }

   /*===========================================*/
   /* Perform the actual search and/or Replace. */
   /*===========================================*/
   
   ShowWindow (SearchDlg,SW_HIDE );
   DoSearch(hWnd,
		    ((lpfr->Flags & FR_REPLACE) || (lpfr->Flags & FR_REPLACEALL)),
            (int) (lpfr->Flags & FR_REPLACEALL),
            (int) (lpfr->Flags & FR_MATCHCASE) );
   ShowWindow(SearchDlg,SW_SHOW);
   SetFocus(hWnd);
   return 0;
  }
Beispiel #14
0
/*ARGSUSED*/
static void 
SearchButton(Widget w, XtPointer closure, XtPointer call_data)
{
    (void)DoSearch((struct SearchAndReplace *)closure);
}
Beispiel #15
0
void Styler_SearchHL::Style(StyleRun& sr) {
	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();

	// Style the run with search ranges
	for (vector<interval>::const_iterator r = m_searchRanges.begin(); r != m_searchRanges.end(); ++r) {
		if (r->end > rstart && r->start < rend) {
			unsigned int start = wxMax(rstart, r->start);
			unsigned int end   = wxMin(rend, r->end);
			sr.SetBackgroundColor(start, end, m_rangeColor);
		}
	}

	// No need for more styling if no search text
	if (m_text.empty()) return;

	// Extend stylerun start/end to get better search results (round up to whole EXTSIZEs)
	unsigned int sr_start = rstart> 100 ? rstart - 100 : 0;
	const unsigned int ext_end = ((rend/EXTSIZE) * EXTSIZE) + EXTSIZE;
	unsigned int sr_end = ext_end < m_lines.GetLength() ? ext_end : m_lines.GetLength();

	// Make sure the extended positions are valid
	cxLOCKDOC_READ(m_doc)
		sr_start = doc.GetValidCharPos(sr_start);
		if (sr_end != m_lines.GetLength()) sr_end = doc.GetValidCharPos(sr_end);
	cxENDLOCK

	//wxLogDebug("Style %u %u", rstart, rend);
	//wxLogDebug(" %u %u - %u %u", sr_start, sr_end, m_search_start, m_search_end);
	// Check if we need to do a new search
	if (sr_start < m_search_start || m_search_end < sr_end) {
		// Check if there is overlap so we can just extend the search area
		if (sr_end > m_search_start && sr_start < m_search_end) {
			sr_start = wxMin(sr_start, m_search_start);
			sr_end = wxMax(sr_end, m_search_end);
		}
		else {
			// Else we have to move it
			m_matches.clear();
			m_search_start = 0;
			m_search_end = 0;
		}

		// Do the search
		if (sr_start < m_search_start) {
			// Search from top
			DoSearch(sr_start, sr_end);
		}
		else if (sr_end > m_search_end) {
			// Search from bottom
			DoSearch(sr_start, sr_end, true);
		}
		else wxASSERT(false);

		m_search_start = sr_start;
		m_search_end = sr_end;
	}

	// Style the run with matches
	for (vector<interval>::iterator p = m_matches.begin(); p != m_matches.end(); ++p) {
		if (p->start > rend) break;

		// Check for overlap (or zero-length sel at start-of-line)
		if ((p->end > rstart && p->start < rend) || (p->start == p->end && p->end == rstart)) {
			unsigned int start = wxMax(rstart, p->start);
			unsigned int end   = wxMin(rend, p->end);

			// Only draw it if it is in range
			if (!m_searchRanges.empty()) {
				bool inRange = false;
				for (vector<interval>::const_iterator s = m_searchRanges.begin(); s != m_searchRanges.end(); ++s) {
					if (start >= s->start && start < s->end) {
						inRange = true;
						break;
					}
				}
				if (!inRange) continue;
			}
			
			ApplyStyle(sr, start, end);
		}
	}
}
Beispiel #16
0
void Styler_SearchHL::Delete(unsigned int start_pos, unsigned int end_pos) {
	wxASSERT(0 <= start_pos && start_pos <= m_doc.GetLength());
	if (m_text.empty()) return;

	if (start_pos == end_pos) return;
	wxASSERT(end_pos > start_pos);

	// Check if we have deleted the entire document
	if (m_doc.GetLength() == 0) {
		Invalidate();
		return;
	}

	// Adjust start & end
	unsigned int length = end_pos - start_pos;
	if (m_search_start >= start_pos) {
		if (m_search_start > end_pos) m_search_start -= length;
		else m_search_start = start_pos;
	}
	if (m_search_end > start_pos) {
		if (m_search_end > end_pos) m_search_end -= length;
		else m_search_end = start_pos;
	}
	else return; // Change after search area, no need to re-search

	unsigned int search_start = m_search_start;

	if (!m_matches.empty()) {
		if (start_pos >= m_matches.back().end) {
			// Do a new search from end of last match
			DoSearch(search_start, m_search_end, true);
			return;
		}

		// Find matches touched by deletion and remove those. Update all following
		bool is_first = true;
		vector<interval>::iterator p = m_matches.begin();
		while (p != m_matches.end()) {
			if (p->end > start_pos) {
				// Remember first valid match before pos
				if (is_first) {
					if (p != m_matches.begin()) search_start = (p-1)->end;
					is_first = false;
				}

				if (p->start < end_pos) {
					// pos inside match. Delete and continue
					p = m_matches.erase(p);
					if (p != m_matches.end()) continue; // new iterator
					else break;
				}
				else {
					// Move match to correct position
					p->start -= length;
					p->end -= length;
				}
			}
			++p;
		}
	}

	// Do a new search starting from end of first match before pos
	DoSearch(search_start, m_search_end, false);
}
/**
Search for a node by directory path

@param	aPath		the path as the key to search in the tree
@param	aNodeFound	in return, the node found 
@param	aDirPos		the location of the directory
@return	KErrNone 	if a node found
		KErrNotFound if no node is found
*/
TInt CLeafDirTree::Search(const TDesC& aPath, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos)
	{
	return (DoSearch(aPath, iRoot, aNodeFound, aDirPos));
	}
Beispiel #18
0
void CContactPage::OnTimer(wxTimerEvent& e)
{
  DoSearch();
}
Beispiel #19
0
void CContactPage::OnSearch(wxCommandEvent&)
{
  DoSearch();
}
Beispiel #20
0
bool GreedyBestFirst::DoSearch(Tree::Node* currNode)
{
	if (currNode == NULL)
		currNode = m_searchTree->getHead();

	m_path.push_back(currNode->vert);
	currNode->path = m_path;

	// Add to closed list
	m_closedList.insert(make_pair(currNode->vert, currNode));

	// Return true if dest has been reached
	if (currNode->vert == m_end)
		return true;

	// fetch edges connected to current vertex
	list<Graph::Edge*> conns = m_searchSpace->getConnectedEdges(currNode->vert);

	// create a node for each connection if one of following is true:
	//	- The vertex has not been visited
	for (list<Graph::Edge*>::iterator itr = conns.begin(); itr != conns.end(); ++itr)
	{
		// Compute cost of this path
		int nextCost = currNode->cost + (*itr)->cost;

		Graph::Vertex* endVert;
		if ((*itr)->ends[0] == currNode->vert)
			endVert = (*itr)->ends[1];
		else
			endVert = (*itr)->ends[0];

		// Figure out which end is the start, add child accordingly if not already visited
		if (!endVert->visited)
			m_searchTree->addAsChild(nextCost, endVert, currNode, &m_path);
	}

	// fetch children of current node
	list<Tree::Node*> currChildren = currNode->getChildren();

	// if no children and not at dest, not on correct path
	if (currChildren.empty())
	{
		return false;
	}

	// append to open list
	m_openList.insert(m_openList.end(), currChildren.begin(), currChildren.end());
	sort(m_openList.begin(), m_openList.end(), CompareFunc);
	if( m_verbose )
		displayOpenList();

	// mark current vertex visited
	currNode->vert->visited = true;

	Tree::Node* nextNode;
	// get first entry in open list and remove from open list
	do
	{
		if (m_openList.empty())
			return false;
		nextNode = *m_openList.begin();
		m_openList.pop_front();
	}
	while( nextNode->vert->visited );

	// set path to next node's path
	m_path = nextNode->path;

	if (m_verbose)
	{
		displayPath(currNode);
		cout << "Expanding node " << nextNode->vert->id << endl;
	}

	if (DoSearch(nextNode))
		return true;
	

	// default case, no path found
	m_path.clear();
	return false;
}
Beispiel #21
0
void QuickFindBar::OnReplace(wxCommandEvent& event)
{
    wxUnusedVar(event);
    if(!m_sci) return;

    wxString findwhat = m_findWhat->GetValue();
    if(findwhat.IsEmpty()) return;

    wxString findWhatSciVersion = findwhat;
    DoFixRegexParen(findWhatSciVersion);

    // No selection?
    if(m_sci->GetSelections() == 0) {
        DoSearch(kSearchForward);
        return;
    }

    // No selection?
    if(m_sci->GetSelections() != 1) {
        DoSearch(kSearchForward);
        return;
    }

    // did we got a match?
    if(m_sci->GetSelections() != 1) return;

    int selStart, selEnd;
    m_sci->GetSelection(&selStart, &selEnd);
    if(selStart == selEnd) {
        // not a real selection
        DoSearch(kSearchForward);
        return;
    }

    // Ensure that the selection matches our search pattern
    size_t searchFlags = DoGetSearchFlags();
    if(m_sci->FindText(selStart, selEnd, searchFlags & wxSTC_FIND_REGEXP ? findWhatSciVersion : findwhat,
           searchFlags) == wxNOT_FOUND) {
        // we got a selection, but it does not match our search
        return;
    }

    wxString selectedText = m_sci->GetTextRange(selStart, selEnd);

#ifndef __WXMAC__
    int re_flags = wxRE_ADVANCED;
#else
    int re_flags = wxRE_DEFAULT;
#endif

    wxString replaceWith = m_replaceWith->GetValue();
    if(!replaceWith.IsEmpty()) {
        clConfig::Get().AddQuickFindReplaceItem(replaceWith);
        DoUpdateReplaceHistory();
    }

    size_t replacementLen = replaceWith.length();
    if(searchFlags & wxSTC_FIND_REGEXP) {

        // Regular expresson search
        if(!(searchFlags & wxSTC_FIND_MATCHCASE)) {
            re_flags |= wxRE_ICASE;
        }

        wxRegEx re(findwhat, re_flags);
        if(re.IsValid() && re.Matches(selectedText)) {
            re.Replace(&selectedText, replaceWith);

            // Keep the replacement length
            replacementLen = selectedText.length();

            // update the view
            m_sci->Replace(selStart, selEnd, selectedText);
        } else {
            return;
        }

    } else {
        // Normal search and replace
        m_sci->Replace(selStart, selEnd, replaceWith);
    }

    // Clear the selection
    m_sci->ClearSelections();
    m_sci->SetCurrentPos(selStart + replacementLen);

    // Trigger another search
    DoSearch(kSearchForward);
}
Beispiel #22
0
/**
 * Search with several start positions
 */
IPath::SearchResult CPathFinder::GetPath(
	const MoveData& moveData,
	const std::vector<float3>& startPos,
	const CPathFinderDef& pfDef,
	IPath::Path& path,
	int ownerId,
	bool synced
) {
	// Clear the given path.
	path.path.clear();
	path.squares.clear();
	path.pathCost = PATHCOST_INFINITY;

	// Store som basic data.
	maxSquaresToBeSearched = MAX_SEARCHED_NODES_PF - 8U;
	testMobile = false;
	exactPath = true;
	needPath = true;

	// If exact path is reqired and the goal is blocked, then no search is needed.
	if (exactPath && pfDef.GoalIsBlocked(moveData, (CMoveMath::BLOCK_STRUCTURE | CMoveMath::BLOCK_TERRAIN)))
		return IPath::CantGetCloser;

	// If the starting position is a goal position, then no search need to be performed.
	if (pfDef.IsGoal(startxSqr, startzSqr))
		return IPath::CantGetCloser;

	// Clearing the system from last search.
	ResetSearch();

	openSquareBuffer.SetSize(0);

	for (std::vector<float3>::const_iterator si = startPos.begin(); si != startPos.end(); ++si) {
		start = *si;
		startxSqr = (int(start.x) / SQUARE_SIZE) | 1;
		startzSqr = (int(start.z) / SQUARE_SIZE) | 1;
		startSquare = startxSqr + startzSqr * gs->mapx;
		goalSquare = startSquare;

		squareStates[startSquare].nodeMask = (PATHOPT_START | PATHOPT_OPEN);
		squareStates[startSquare].fCost = 0.0f;
		squareStates[startSquare].gCost = 0.0f;
		dirtySquares.push_back(startSquare);

		if (openSquareBuffer.GetSize() >= MAX_SEARCHED_NODES_PF) {
			continue;
		}

		PathNode* os = openSquareBuffer.GetNode(openSquareBuffer.GetSize());
			os->fCost     = 0.0f;
			os->gCost     = 0.0f;
			os->nodePos.x = startxSqr;
			os->nodePos.y = startzSqr;
			os->nodeNum   = startSquare;
		openSquareBuffer.SetSize(openSquareBuffer.GetSize() + 1);
		openSquares.push(os);
	}

	// note: DoSearch, not InitSearch
	IPath::SearchResult result = DoSearch(moveData, pfDef, ownerId, synced);

	// Respond to the success of the search.
	if (result == IPath::Ok) {
		FinishSearch(moveData, path);
		if (PATHDEBUG) {
			LogObject() << "Path found.\n";
			LogObject() << "Nodes tested: " << testedNodes << "\n";
			LogObject() << "Open squares: " << openSquareBuffer.GetSize() << "\n";
			LogObject() << "Path nodes: " << path.path.size() << "\n";
			LogObject() << "Path cost: " << path.pathCost << "\n";
		}
	} else {
		if (PATHDEBUG) {
			LogObject() << "No path found!\n";
			LogObject() << "Nodes tested: " << testedNodes << "\n";
			LogObject() << "Open squares: " << openSquareBuffer.GetSize() << "\n";
		}
	}
	return result;
}
Beispiel #23
0
void CContactPage::OnSearchCancel(wxCommandEvent&)
{
  m_searchCtrl->Clear();
  DoSearch();
}
Beispiel #24
0
int main ()
{
    // threads should be initialized before memory allocations
    char cTopOfMainStack;
    sphThreadInit();
    MemorizeStack ( &cTopOfMainStack );

    CSphString sError;
    CSphDictSettings tDictSettings;

    ISphTokenizer * pTok = sphCreateUTF8Tokenizer();
    CSphDict * pDict = sphCreateDictionaryCRC ( tDictSettings, pTok, sError, "rt1" );
    CSphSource * pSrc = SpawnSource ( "SELECT id, channel_id, UNIX_TIMESTAMP(published) published, title, UNCOMPRESS(content) content FROM posting WHERE id<=10000 AND id%2=0", pTok, pDict );

    ISphTokenizer * pTok2 = sphCreateUTF8Tokenizer();
    CSphDict * pDict2 = sphCreateDictionaryCRC ( tDictSettings, pTok, sError, "rt2" );
    CSphSource * pSrc2 = SpawnSource ( "SELECT id, channel_id, UNIX_TIMESTAMP(published) published, title, UNCOMPRESS(content) content FROM posting WHERE id<=10000 AND id%2=1", pTok2, pDict2 );

    CSphSchema tSrcSchema;
    if ( !pSrc->UpdateSchema ( &tSrcSchema, sError ) )
        sphDie ( "update-schema failed: %s", sError.cstr() );

    CSphSchema tSchema; // source schema must be all dynamic attrs; but index ones must be static
    tSchema.m_dFields = tSrcSchema.m_dFields;
    for ( int i=0; i<tSrcSchema.GetAttrsCount(); i++ )
        tSchema.AddAttr ( tSrcSchema.GetAttr(i), false );

    CSphConfigSection tRTConfig;
    sphRTInit();
    sphRTConfigure ( tRTConfig, true );
    SmallStringHash_T< CSphIndex * > dTemp;
    sphReplayBinlog ( dTemp, 0 );
    ISphRtIndex * pIndex = sphCreateIndexRT ( tSchema, "testrt", 32*1024*1024, "data/dump", false );
    pIndex->SetTokenizer ( pTok ); // index will own this pair from now on
    pIndex->SetDictionary ( pDict );
    if ( !pIndex->Prealloc ( false, false, sError ) )
        sphDie ( "prealloc failed: %s", pIndex->GetLastError().cstr() );
    g_pIndex = pIndex;

    // initial indexing
    int64_t tmStart = sphMicroTimer();

    SphThread_t t1, t2;
    sphThreadCreate ( &t1, IndexingThread, pSrc );
    sphThreadCreate ( &t2, IndexingThread, pSrc2 );
    sphThreadJoin ( &t1 );
    sphThreadJoin ( &t2 );

#if 0
    // update
    tParams.m_sQuery = "SELECT id, channel_id, UNIX_TIMESTAMP(published) published, title, UNCOMPRESS(content) content FROM rt2 WHERE id<=10000";
    SetupIndexing ( pSrc, tParams );
    DoIndexing ( pSrc, pIndex );
#endif

    // search
    DoSearch ( pIndex );

    // shutdown index (should cause dump)
    int64_t tmShutdown = sphMicroTimer();

#if SPH_ALLOCS_PROFILER
    printf ( "pre-shutdown allocs=%d, bytes="INT64_FMT"\n", sphAllocsCount(), sphAllocBytes() );
#endif
    SafeDelete ( pIndex );
#if SPH_ALLOCS_PROFILER
    printf ( "post-shutdown allocs=%d, bytes="INT64_FMT"\n", sphAllocsCount(), sphAllocBytes() );
#endif

    int64_t tmEnd = sphMicroTimer();
    printf ( "shutdown done in %d.%03d sec\n", (int)((tmEnd-tmShutdown)/1000000), (int)(((tmEnd-tmShutdown)%1000000)/1000) );
    printf ( "total with shutdown %d.%03d sec, %.2f MB/sec\n",
             (int)((tmEnd-tmStart)/1000000), (int)(((tmEnd-tmStart)%1000000)/1000),
             g_fTotalMB*1000000.0f/(tmEnd-tmStart) );

#if SPH_DEBUG_LEAKS || SPH_ALLOCS_PROFILER
    sphAllocsStats();
#endif
#if USE_WINDOWS
    PROCESS_MEMORY_COUNTERS pmc;
    HANDLE hProcess = OpenProcess ( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId() );
    if ( hProcess && GetProcessMemoryInfo ( hProcess, &pmc, sizeof(pmc)) )
    {
        printf ( "--- peak-wss=%d, peak-pagefile=%d\n", (int)pmc.PeakWorkingSetSize, (int)pmc.PeakPagefileUsage );
    }
#endif

    SafeDelete ( pIndex );
    sphRTDone ();
}
Beispiel #25
0
void FindInFilesDialog::OnFind(wxCommandEvent& event)
{
    wxUnusedVar(event);
    DoSearch();
}
Beispiel #26
0
void DoIndexing ( CSphSource * pSrc, ISphRtIndex * pIndex )
{
    CSphString sError;
    CSphVector<DWORD> dMvas;

    int64_t tmStart = sphMicroTimer ();
    int64_t tmAvgCommit = 0;
    int64_t tmMaxCommit = 0;
    int iCommits = 0;
    for ( ;; )
    {
        if ( !pSrc->IterateDocument ( sError ) )
            sphDie ( "iterate-document failed: %s", sError.cstr() );
        ISphHits * pHitsNext = pSrc->IterateHits ( sError );
        if ( !sError.IsEmpty() )
            sphDie ( "iterate-hits failed: %s", sError.cstr() );

        if ( pSrc->m_tDocInfo.m_iDocID )
            pIndex->AddDocument ( pHitsNext, pSrc->m_tDocInfo, NULL, dMvas, sError );

        if ( ( pSrc->GetStats().m_iTotalDocuments % COMMIT_STEP )==0 || !pSrc->m_tDocInfo.m_iDocID )
        {
            int64_t tmCommit = sphMicroTimer();
            pIndex->Commit ();
            tmCommit = sphMicroTimer()-tmCommit;

            iCommits++;
            tmAvgCommit += tmCommit;
            tmMaxCommit = Max ( tmMaxCommit, tmCommit );

            if ( !pSrc->m_tDocInfo.m_iDocID )
            {
                tmAvgCommit /= iCommits;
                break;
            }
        }

        if (!( pSrc->GetStats().m_iTotalDocuments % 100 ))
            printf ( "%d docs\r", (int)pSrc->GetStats().m_iTotalDocuments );

        static bool bOnce = true;
        if ( iCommits*COMMIT_STEP>=5000 && bOnce )
        {
            printf ( "\n" );
            DoSearch ( pIndex );
            bOnce = false;
        }
    }

    pSrc->Disconnect();

    int64_t tmEnd = sphMicroTimer ();
    float fTotalMB = (float)pSrc->GetStats().m_iTotalBytes/1000000.0f;
    printf ( "commit-step %d, %d docs, %d bytes, %d.%03d sec, %.2f MB/sec\n",
             COMMIT_STEP,
             (int)pSrc->GetStats().m_iTotalDocuments,
             (int)pSrc->GetStats().m_iTotalBytes,
             (int)((tmEnd-tmStart)/1000000), (int)(((tmEnd-tmStart)%1000000)/1000),
             fTotalMB*1000000.0f/(tmEnd-tmStart) );
    printf ( "commit-docs %d, avg %d.%03d msec, max %d.%03d msec\n", COMMIT_STEP,
             (int)(tmAvgCommit/1000), (int)(tmAvgCommit%1000),
             (int)(tmMaxCommit/1000), (int)(tmMaxCommit%1000) );
    g_fTotalMB += fTotalMB;
}
Beispiel #27
0
void Styler_Syntax::ParseAll() {
	const unsigned int len = m_doc.GetLength();
	if (m_syntax_end < len) {
		DoSearch(m_syntax_end, len, len);
	}
}
Beispiel #28
0
void CDlgManualTask::OnBnClickedBtnSearch()
{
	// TODO: 在此添加控件通知处理程序代码
	DoSearch();
}
Beispiel #29
0
void *SearchForAddressOfSpecialSymbol(const char *SymbolName) {
  return DoSearch(SymbolName); // DynamicLibrary.inc
}
void CFindReplaceDlg::DoSearch(CEditorEvent* pEvent, int& Number)
{
	int i, j;

	
	if (m_Conditions.GetCheck() == BST_CHECKED)
	{
		for (j = 0; j < pEvent->m_Conditions.size(); j++)
		{
			CString Match = pEvent->m_Conditions[j]->m_Text;
			Match.MakeLower();

			// Matches?
			if (Match.Find(m_Text) != -1)
			{
				CString ItemN;
				ItemN.Format("%d", Number + 1);
				int Item = m_List.InsertItem(m_List.GetItemCount(), ItemN);

				CString Text = pEvent->m_Conditions[j]->m_Text;
				Text = StripHTML(Text);
				CString Add = "Condition: ";
				Add += Text;

				m_List.SetItemText(Item, 1, Add);

				m_List.SetItemData(Item, (DWORD)pEvent);
			}
		}
	}

	if (m_Actions.GetCheck() == BST_CHECKED)
	{
		for (j = 0; j < pEvent->m_Actions.size(); j++)
		{
			CString Match = pEvent->m_Actions[j]->m_Text;
			Match.MakeLower();
		
			// Matches?
			if (Match.Find(m_Text) != -1)
			{
				CString ItemN;
				ItemN.Format("%d", Number + 1);
				int Item = m_List.InsertItem(m_List.GetItemCount(), ItemN);

				CString Text = pEvent->m_Actions[j]->m_Text;
				Text = StripHTML(Text);
				CString Add = "Action: ";
				Add += Text;

				m_List.SetItemText(Item, 1, Add);

				m_List.SetItemData(Item, (DWORD)pEvent);
			}
		}
	}

	// Loop sub events
	for (i = 0; i < pEvent->m_EventList.size(); i++)
	{
		CEditorEvent* pSubEvent = pEvent->m_EventList[i];

		// Comments etc dont increment number
		if (pSubEvent->m_type == 0 || pSubEvent->m_type == 4)
			Number++;

		DoSearch(pSubEvent, Number);
	}
}