コード例 #1
0
ファイル: svnblameeditor.cpp プロジェクト: 292388900/codelite
void SvnBlameEditor::SetText(const wxString& text)
{
    // Define some colors
    int xx, yy;
    int marginWidth(0);

    int s_style(MARGIN_FIRST_STYLE);
    std::map<wxString, int> authorsColorsMap;

    wxFont defFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
    wxFont font(defFont.GetPointSize(), wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);

    wxArrayString lines = wxStringTokenize(text, wxT("\n"), wxTOKEN_RET_DELIMS);
    for (size_t i=0; i<lines.GetCount(); i++) {
        wxString revision;
        wxString author;
        wxString text;

        wxString line = lines.Item(i);
        line.Trim(false);

        revision = line.BeforeFirst(wxT(' '));
        revision.Trim().Trim(false);
        line = line.AfterFirst(wxT(' '));
        line.Trim(false);

        author = line.BeforeFirst(wxT(' '));
        author.Trim().Trim(false);

        int style;
        std::map<wxString, int>::iterator iter = authorsColorsMap.find(author);
        if (iter != authorsColorsMap.end()) {
            // Create new random color and use it
            style = (*iter).second;
        } else {
            style = s_style;
            s_style ++;
            if (s_style > (MARGIN_STYLE_START+9) )
                s_style = MARGIN_FIRST_STYLE;
            authorsColorsMap[author] = style;
        }

        line = line.AfterFirst(wxT(' '));

        wxString marginText = wxString::Format(wxT("% 8s: %s"), revision.c_str(), author.c_str());
        wxWindow::GetTextExtent(marginText, &xx, &yy, NULL, NULL, &font);

        marginWidth = wxMax(marginWidth, xx);
        AppendText(line);
        MarginSetText((int)i, marginText);
        MarginSetStyle((int)i, style);

        // Keep the revision on in array
        BlameLineInfo info;
        info.revision = revision;
        info.style    = style;
        m_lineInfo.push_back(info);
    }

    SetMarginWidth(0, marginWidth);
    SetReadOnly(true);
}
コード例 #2
0
ファイル: sourceview.cpp プロジェクト: doneykoo/verysleepy
void SourceView::showFile(std::wstring path, int proclinenum, const std::vector<double> &linecounts)
{
	currentfile = path;

	// Don't show error messages with CPP highlighting
	setPlainMode();
	if (path == "[hint KiFastSystemCallRet]")
	{
		updateText(
			" Hint: KiFastSystemCallRet often means the thread was waiting for something else to finish.\n"
			" \n"
			" Possible causes might be disk I/O, waiting for an event, or maybe just calling Sleep().\n"
			);
		return;
	}

	if (path == "" || path == "[unknown]")
	{
		updateText("[ No source file available for this location. ]");
		return;
	}


	FILE *file = _wfopen(path.c_str(),L"r, ccs=UNICODE");
	if(!file)
	{
		wchar_t *crtSub = L"\\crt\\src\\";
		wchar_t *crt = wcsstr((wchar_t *)path.c_str(), crtSub);
		if(crt) {
			for(size_t i=0;i<msDevPaths.size();i++) {
				std::wstring newPath(msDevPaths[i]);
				newPath += crt+wcslen(crtSub);
				path = newPath;
				file = _wfopen(path.c_str(),L"r");
				if(file)
					break;
			}
		}
	}

	if(!file)
	{
		updateText(std::wstring("[ Could not open file '" + path + "'. ]").c_str());
		return;
	}

	std::wstring displaytext;
	wchar_t line[1024];
	while(fgetws(line,countof(line),file))
	{
		displaytext += line;
	}

	fclose(file);

	setCppMode();

	updateText(displaytext);

	// Show line counts in margin
	for (int line=1,lineCount=linecounts.size(); line<lineCount; ++line)
	{
		if (linecounts[line])
		{
			wchar_t currCount[32];
			swprintf(currCount, countof(currCount), L"%0.2fs ", linecounts[line]);
			MarginSetText (line-1, currCount);
			MarginSetStyle(line-1, MARGIN_TEXT_STYLE);
		}
	}

	SetYCaretPolicy(wxSTC_CARET_STRICT|wxSTC_CARET_EVEN, 0);
	GotoLine(proclinenum);
	SetYCaretPolicy(wxSTC_CARET_EVEN, 0);

	MarkerDefine(1, wxSTC_MARK_BACKGROUND, wxNullColour, *wxYELLOW);
	MarkerAdd(proclinenum-1, 1);
}