Example #1
0
void
CConsoleWindow::SetScriptStyles()
{
  static const COLORREF black   = 0x000000;
  static const COLORREF white   = 0xFFFFFF;
  static const COLORREF red     = RGB(0xFF, 0, 0);
  static const COLORREF blue    = RGB(0, 0, 0xFF);
  static const COLORREF purple  = RGB(0xFF, 0, 0xFF);
  static const COLORREF yellow  = RGB(0xFF, 0xFF, 0);
  static const COLORREF brown   = RGB(0xB5, 0x6F, 0x32);
  static const COLORREF darkred = RGB(0x80, 0, 0);
  static const COLORREF orange  = RGB(0xFF, 128, 0);
  static const COLORREF green = RGB(0, 0x80, 0x32);
  static const COLORREF darkgreen = RGB(0, 0x80, 0);
  // set default style
  SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, black);
  SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, white);
  SendEditor(SCI_STYLECLEARALL);
  // set all margins to zero width
  SendEditor(SCI_SETMARGINWIDTHN, 0, 0);
  SendEditor(SCI_SETMARGINWIDTHN, 1, 0);
  SendEditor(SCI_SETMARGINWIDTHN, 2, 0);
  // set all margin types
  SendEditor(SCI_SETMARGINTYPEN,  0, SC_MARGIN_NUMBER);
  SendEditor(SCI_SETMARGINWIDTHN, 1, SC_MARGIN_SYMBOL);
  SendEditor(SCI_SETMARGINWIDTHN, 2, SC_MARGIN_SYMBOL);
  // set wrap modes
  if (1) {
    SendEditor(SCI_SETWRAPMODE, SC_WRAP_WORD);
  }
  if (1) {
    SendInputBar(SCI_SETWRAPMODE, SC_WRAP_WORD);
  }
}
Example #2
0
CharacterRange ScintillaEditor::GetSelection()
{
	CharacterRange crange;
	crange.cpMin = SendEditor(SCI_GETSELECTIONSTART);
	crange.cpMax = SendEditor(SCI_GETSELECTIONEND);
	return crange;
}
Example #3
0
BOOL
CConsoleWindow::IsToolAvailable(UINT id)
{
  BOOL available = FALSE;
  
  switch (id) {
    case ID_FILE_COPY:
      if (::GetFocus() == __m_Editor__) {
        if (SendEditor(SCI_GETSELECTIONSTART) - SendEditor(SCI_GETSELECTIONEND)) available = TRUE;
      }
      else
      if (::GetFocus() == __m_InputBar__) {
        if (SendInputBar(SCI_GETSELECTIONSTART) - SendInputBar(SCI_GETSELECTIONEND)) available = TRUE;
      }
    break;
    case ID_FILE_PASTE:
      if (::GetFocus() == __m_Editor__) {
        //if (SendEditor(SCI_CANPASTE) != 0) available = TRUE;
      }
      if (::GetFocus() == __m_InputBar__) {
        if (SendInputBar(SCI_CANPASTE) != 0) available = TRUE;
      }
    break;
  }
  return available;
}
Example #4
0
LRESULT CMainWindow::DoCommand(int id)
{
	switch (id) 
	{
	case ID_FILE_EXIT:
		::PostQuitMessage(0);
		return 0;
	case IDM_SHOWFINDBAR:
		{
			m_bShowFindBar = true;
			::ShowWindow(m_FindBar, SW_SHOW);
			RECT rect;
			GetClientRect(*this, &rect);
			::SetWindowPos(m_hWndEdit, HWND_TOP, 
				rect.left, rect.top,
				rect.right-rect.left, rect.bottom-rect.top-30,
				SWP_SHOWWINDOW);
			::SetWindowPos(m_FindBar, HWND_TOP,
				rect.left, rect.bottom-30,
				rect.right-rect.left, 30,
				SWP_SHOWWINDOW);
			::SetFocus(m_FindBar);
			SendEditor(SCI_SETSELECTIONSTART, 0);
			SendEditor(SCI_SETSELECTIONEND, 0);
			SendEditor(SCI_SEARCHANCHOR);
		}
		break;
	case IDM_FINDNEXT:
		SendEditor(SCI_CHARRIGHT);
		SendEditor(SCI_SEARCHANCHOR);
		SendEditor(SCI_SEARCHNEXT, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
		SendEditor(SCI_SCROLLCARET);
		break;
	case IDM_FINDPREV:
		SendEditor(SCI_SEARCHANCHOR);
		SendEditor(SCI_SEARCHPREV, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
		SendEditor(SCI_SCROLLCARET);
		break;
	case IDM_FINDEXIT:
		{
			if (IsWindowVisible(m_FindBar))
			{
				RECT rect;
				GetClientRect(*this, &rect);
				m_bShowFindBar = false;
				::ShowWindow(m_FindBar, SW_HIDE);
				::SetWindowPos(m_hWndEdit, HWND_TOP, 
					rect.left, rect.top,
					rect.right-rect.left, rect.bottom-rect.top,
					SWP_SHOWWINDOW);
			}
			else
				PostQuitMessage(0);
		}
		break;
	default:
		break;
	};
	return 1;
}
Example #5
0
void DMApp::SetAStyle(int style, COLORREF fore, COLORREF back, int size, const char *face) {
	SendEditor(SCI_STYLESETFORE, style, fore);
	SendEditor(SCI_STYLESETBACK, style, back);
	if (size >= 1)
		SendEditor(SCI_STYLESETSIZE, style, size);
	if (face) 
		SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(face));
}
Example #6
0
void DMApp::New() {
	SendEditor(SCI_CLEARALL);
	SendEditor(EM_EMPTYUNDOBUFFER);
	fullPath[0] = '\0';
	SetTitle();
	isDirty = false;
	SendEditor(SCI_SETSAVEPOINT);
}
Example #7
0
void ScintillaEditor::EnsureRangeVisible(int posStart, int posEnd)
{
	int lineStart = SendEditor(SCI_LINEFROMPOSITION, min(posStart, posEnd));
	int lineEnd = SendEditor(SCI_LINEFROMPOSITION, max(posStart, posEnd));
	for (int line = lineStart; line <= lineEnd; line++)
	{
		SendEditor(SCI_ENSUREVISIBLE, line);
	}
}
Example #8
0
void DMApp::InitialiseEditor() {
	SendEditor(SCI_SETLEXER, SCLEX_HTML);
	SendEditor(SCI_SETSTYLEBITS, 7);


	// Set up the global default style. These attributes are used wherever no explicit choices are made.
	SetAStyle(STYLE_DEFAULT, black, white, 12, "Courier New");
	SendEditor(SCI_STYLECLEARALL);	// Copies global style to all others
	
}
Example #9
0
void SciTECom::FoldAll() {
	SendEditor(SCI_COLOURISE, 0, -1);
	int maxLine = SendEditor(SCI_GETLINECOUNT);
	bool expanding = true;
	for (int lineSeek = 0; lineSeek < maxLine; lineSeek++) {
		if (SendEditor(SCI_GETFOLDLEVEL, lineSeek) & SC_FOLDLEVELHEADERFLAG) {
			expanding = !SendEditor(SCI_GETFOLDEXPANDED, lineSeek);
			break;
		}
	}
	for (int line = 0; line < maxLine; line++) {
		int level = SendEditor(SCI_GETFOLDLEVEL, line);
		if ((level & SC_FOLDLEVELHEADERFLAG) &&
		        (SC_FOLDLEVELBASE == (level & SC_FOLDLEVELNUMBERMASK))) {
			if (expanding) {
				SendEditor(SCI_SETFOLDEXPANDED, line, 1);
				Expand(line, true, false, 0, level);
				line--;
			} else {
				int lineMaxSubord = SendEditor(SCI_GETLASTCHILD, line, -1);
				SendEditor(SCI_SETFOLDEXPANDED, line, 0);
				if (lineMaxSubord > line)
					SendEditor(SCI_HIDELINES, line + 1, lineMaxSubord);
			}
		}
	}
}
Example #10
0
void ScintillaEditor::CenterPosition(int position)
{
	int numLines = SendEditor(SCI_LINESONSCREEN);
	int line = SendEditor(SCI_LINEFROMPOSITION, position);
	line -= numLines / 2;
	int lastLine = line + numLines - 1;
	for (; line <= lastLine; line++)
	{
		SendEditor(SCI_ENSUREVISIBLE, line);
	}
}
Example #11
0
void SciTECom::ToggleFoldRecursive(int line, int level) {
	if (SendEditor(SCI_GETFOLDEXPANDED, line)) {
		// Contract this line and all children
		SendEditor(SCI_SETFOLDEXPANDED, line, 0);
		Expand(line, false, true, 0, level);
	} else {
		// Expand this line and all children
		SendEditor(SCI_SETFOLDEXPANDED, line, 1);
		Expand(line, true, true, 100, level);
	}
}
Example #12
0
void
CConsoleWindow::GetEditorText(CString& text)
{
  int length = SendEditor(SCI_GETLENGTH);
  char* str = new char[length + 1];
  if (str) {
    str[length] = 0;
    SendEditor(SCI_GETTEXT, length + 1, (LPARAM)str);
    text = str;
    delete[] str;
  }
}
Example #13
0
void CDialogEdit::InitialiseEditor() 
{
	// Punt if we already have a window
	if (::IsWindow(m_hwndEditor))
		return;

	// Create editor window
	m_hwndEditor = CreateWindowEx(0, "Scintilla", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN,
		0, 0, 500, 400, GetSafeHwnd(), NULL /*(HMENU)GuiID*/, AfxGetApp()->m_hInstance, NULL);	

	// Did we get the editor window?
	if (!::IsWindow(m_hwndEditor))
	{	
		TRACE( "Unable to create editor window\n" );
		return;
	}

	// CPP lexer
	SendEditor(SCI_SETLEXER, SCLEX_CPP);

	// Set number of style bits to use
	SendEditor(SCI_SETSTYLEBITS, 5);

	// Set tab width
	SendEditor(SCI_SETTABWIDTH, 4);

	// Use CPP keywords
	SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)g_cppKeyWords);

	// Set up the global default style. These attributes are used wherever no explicit choices are made.
	SetAStyle(STYLE_DEFAULT, black, white, 10, "Courier New");

	// Set caret foreground color
	//SendEditor(SCI_SETCARETFORE, RGB(255, 255, 255));

	// Set all styles
	SendEditor(SCI_STYLECLEARALL);

	// Set selection color
	SendEditor(SCI_SETSELBACK, TRUE, RGB(240, 240, 240));

	// Set syntax colors
	for ( long i = 0; g_rgbSyntaxCpp[i].iItem != -1; i++ )
	{
		SendEditor(SCI_STYLESETFORE, g_rgbSyntaxCpp[i].iItem, g_rgbSyntaxCpp[i].rgb);
	}

	SendEditor(SCI_SETHSCROLLBAR, false);
	//SendEditor(SCI_SETVIEWWS, SCWS_VISIBLEALWAYS);
	SendEditor(SCI_SETMARGINWIDTHN, 0, 32);
	SendEditor(SCI_SETMARGINWIDTHN, 1, 0);
}
Example #14
0
void ScintillaEditor::ReadPropertiesInitial()
{
	ScintillaPropertiesFile& props = *m_props;

	int indentationWSVisible = props.GetInt("view.indentation.whitespace", 1);
//	ViewWhitespace(props.GetInt("view.whitespace"));
	SendEditor(SCI_SETINDENTATIONGUIDES, props.GetInt("view.indentation.guides"));
	SendEditor(SCI_SETVIEWEOL, props.GetInt("view.eol"));

//	sbVisible = props.GetInt("statusbar.visible");
//	tbVisible = props.GetInt("toolbar.visible");
//	tabVisible = props.GetInt("tabbar.visible");
//	tabMultiLine = props.GetInt("tabbar.multiline");
#if PLAT_WIN
//	if (tabMultiLine) {	// Windows specific!
//		long wl = ::GetWindowLong(wTabBar.GetID(), GWL_STYLE);
//		::SetWindowLong(wTabBar.GetID(), GWL_STYLE, wl | TCS_MULTILINE);
//	}
#endif

	lineNumbersWidth = 0;
	CStringA linenums = props.Get("line.numbers");
	if (linenums.GetLength())
		lineNumbersWidth = value(linenums);
	int lineNumbers = lineNumbersWidth;
	if (lineNumbersWidth == 0)
		lineNumbersWidth = lineNumbersWidthDefault;

	marginWidth = 0;
	CStringA margwidth = props.Get("margin.width");
	if (margwidth.GetLength())
		marginWidth = value(margwidth);
	margin = marginWidth != 0;
	if (marginWidth == 0)
		marginWidth = marginWidthDefault;

	foldMarginWidth = props.GetInt("fold.margin.width", foldMarginWidthDefault);
	foldMargin = foldMarginWidth != 0;
	if (foldMarginWidth == 0)
		foldMarginWidth = foldMarginWidthDefault;

/*	char homepath[MAX_PATH + 20];
	if (GetSciteDefaultHome(homepath, sizeof(homepath))) {
		props.Set("SciteDefaultHome", homepath);
	}
	if (GetSciteUserHome(homepath, sizeof(homepath))) {
		props.Set("SciteUserHome", homepath);
	}
*/
}
Example #15
0
void CMainWindow::SetupWindow(bool bUTF8)
{
	SendEditor(SCI_SETCODEPAGE, bUTF8 ? SC_CP_UTF8 : GetACP());

	SendEditor(SCI_SETUNDOCOLLECTION, 1);
	::SetFocus(m_hWndEdit);
	SendEditor(EM_EMPTYUNDOBUFFER);
	SendEditor(SCI_SETSAVEPOINT);
	SendEditor(SCI_GOTOPOS, 0);

	SetupColors(true);

	::ShowWindow(m_hWndEdit, SW_SHOW);
}
Example #16
0
CString ScintillaEditor::GetWord()
{
	int savePos = GetCurrentPos();
	SendEditor(SCI_WORDLEFT);
	DWORD startPos = GetCurrentPos();
	SendEditor(SCI_WORDRIGHTEXTEND);
	DWORD endPos = GetCurrentPos();
	CStringA str;
	LPSTR buf = str.GetBufferSetLength(endPos - startPos);
	GetSelText(buf);
	str.ReleaseBuffer(endPos - startPos);
	SendEditor(SCI_SETCURRENTPOS, savePos);

	return CString(str);
}
Example #17
0
bool CMainWindow::SaveFile(LPCTSTR filename)
{
    FILE *fp = NULL;
    _tfopen_s(&fp, filename, L"w+b");
    if (!fp)
        return false;

    LRESULT len = SendEditor(SCI_GETTEXT, 0, 0);
    auto data = std::make_unique<char[]>(len + 1);
    SendEditor(SCI_GETTEXT, len, reinterpret_cast<LPARAM>(static_cast<char *>(data.get())));
    fwrite(data.get(), sizeof(char), len-1, fp);
    fclose(fp);

    SendEditor(SCI_SETSAVEPOINT);
    ::ShowWindow(m_hWndEdit, SW_SHOW);
    return true;
}
Example #18
0
void CDialogEdit::OnCancel()
{
	// Get text length
	UINT uSize = (UINT)SendEditor(SCI_GETLENGTH, 0, 0L);
	if (uSize)
	{
		char *pBuf = new char[uSize + 1 + 8];
		if (pBuf)
		{
			SendEditor(SCI_GETTEXT, uSize + 1, (LPARAM)pBuf);
			pBuf[uSize] = '\0';
			Text = pBuf;
			delete pBuf;
		}
	}
	CDialogEx::OnCancel();
}
Example #19
0
void
CConsoleWindow::SetStyle(
  int style,
  COLORREF fore,
  COLORREF back,
  int size,
  const char* face)
{
  SendEditor(SCI_STYLESETFORE, style, fore);
  SendEditor(SCI_STYLESETBACK, style, back);
  if (size >= 1) {
    SendEditor(SCI_STYLESETSIZE, style, size);
  }
  if (face) {
    SendEditor(SCI_STYLESETFONT, style, (LPARAM)face);
  }
}
Example #20
0
BOOL CDialogEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	CWnd* pWnd = GetDesktopWindow();
	CenterWindow(pWnd);

	SetWindowText(Title);
	// Create the Scintilla editor	
	InitialiseEditor();
	SendEditor(SCI_SETTEXT, 0, (WPARAM)Text.GetBuffer());
	ShowWindow(SW_NORMAL);
	SizeEditor();
	SendEditor(SCI_SETSEL, 0, 0);

	return FALSE;  // return TRUE unless you set the focus to a control
}
Example #21
0
void ScintillaEditor::GetRange(int start, int end, char* text)
{
	TextRange tr;
	tr.chrg.cpMin = start;
	tr.chrg.cpMax = end;
	tr.lpstrText = text;
	SendEditor(SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
}
Example #22
0
bool CMainWindow::SaveFile(LPCTSTR filename)
{
	FILE *fp = NULL;
	_tfopen_s(&fp, filename, _T("w+b"));
	if (!fp)
		return false;

	int len = SendEditor(SCI_GETTEXT, 0, 0);
	char * data = new char[len+1];
	SendEditor(SCI_GETTEXT, len, (LPARAM)data);
	fwrite(data, sizeof(char), len-1, fp);
	fclose(fp);

	SendEditor(SCI_SETSAVEPOINT);
	::ShowWindow(m_hWndEdit, SW_SHOW);
	return true;
}
Example #23
0
void DMApp::OpenFile(const char *fileName) {
	New();
	SendEditor(SCI_CANCEL);
	SendEditor(SCI_SETUNDOCOLLECTION, 0);

	strcpy(fullPath, fileName);
	FILE *fp = fopen(fullPath, "rb");
	if (fp) {
		SetTitle();
		char data[blockSize];
		int lenFile = fread(data, 1, sizeof(data), fp);
		while (lenFile > 0) {
			SendEditor(SCI_ADDTEXT, lenFile,
					   reinterpret_cast<LPARAM>(static_cast<char *>(data)));
			lenFile = fread(data, 1, sizeof(data), fp);
		}
		fclose(fp);
	} else {
		char msg[MAX_PATH + 100];
		strcpy(msg, "Could not open file \"");
		strcat(msg, fullPath);
		strcat(msg, "\".");
		::MessageBox(wMain, msg, appName, MB_OK);
	}
	SendEditor(SCI_SETUNDOCOLLECTION, 1);
	::SetFocus(wEditor);
	SendEditor(EM_EMPTYUNDOBUFFER);
	SendEditor(SCI_SETSAVEPOINT);
	SendEditor(SCI_GOTOPOS, 0);
}
Example #24
0
CString
CConsoleWindow::GetSelection()
{
  int start = SendEditor(SCI_GETSELECTIONSTART);
  int end   = SendEditor(SCI_GETSELECTIONEND);
  if (end < start) {
    end = start;
  }
  int length = end - start;
  char* str = new char[length + 1];
  if (str) {
    str[length] = 0;
    SendEditor(SCI_GETSELTEXT, 0, (LPARAM)str);
    CString result(str);
    delete[] str;
    return result;
  }
  return "";
}
Example #25
0
afx_msg void
CConsoleWindow::OnCopy()
{
  if (::GetFocus() == __m_Editor__) {
    SendEditor(SCI_COPY);
  }
  else
  if (::GetFocus() == __m_InputBar__) {
    SendInputBar(SCI_COPY);
  }
}
Example #26
0
bool ScintillaEditor::OpenFile(const CString& fileName, const CString& forcedExt)
{
	ReadProperties(fileName, forcedExt);

	SendEditor(SCI_CLEARALL);

	CFile file;
	if (!file.Open(fileName, CFile::modeRead))
		return false;

	DWORD size = (DWORD)file.GetLength();
	char* buffer = new char[size];
	file.Read(buffer, size);
	file.Close();

	SendEditor(SCI_ADDTEXT, size, (LPARAM)buffer);

	delete [] buffer;

	return true;
}
Example #27
0
bool SciTECom::MarginClick(int position, int modifiers) {
	int lineClick = SendEditor(SCI_LINEFROMPOSITION, position);
	//Platform::DebugPrintf("Margin click %d %d %x\n", position, lineClick,
	//	SendEditor(SCI_GETFOLDLEVEL, lineClick) & SC_FOLDLEVELHEADERFLAG);
	if ((modifiers & SCMOD_SHIFT) && (modifiers & SCMOD_CTRL)) {
		FoldAll();
	} else {
		int levelClick = SendEditor(SCI_GETFOLDLEVEL, lineClick);
		if (levelClick & SC_FOLDLEVELHEADERFLAG) {
			if (modifiers & SCMOD_SHIFT) {
				EnsureAllChildrenVisible(lineClick, levelClick);
			} else if (modifiers & SCMOD_CTRL) {
				ToggleFoldRecursive(lineClick, levelClick);
			} else {
				// Toggle this line
				SendEditor(SCI_TOGGLEFOLD, lineClick);
			}
		}
	}
	return true;
}
Example #28
0
void DMApp::SaveFile(const char *fileName) {
	FILE *fp = fopen(fullPath, "wb");
	if (fp) {
		char data[blockSize + 1];
		int lengthDoc = SendEditor(SCI_GETLENGTH);
		for (int i = 0; i < lengthDoc; i += blockSize) {
			int grabSize = lengthDoc - i;
			if (grabSize > blockSize)
				grabSize = blockSize;
			GetRange(i, i + grabSize, data);
			fwrite(data, grabSize, 1, fp);
		}
		fclose(fp);
		SendEditor(SCI_SETSAVEPOINT);
	} else {
		char msg[MAX_PATH + 100];
		strcpy(msg, "Could not save file \"");
		strcat(msg, fullPath);
		strcat(msg, "\".");
		MessageBox(wMain, msg, appName, MB_OK);
	}
}
Example #29
0
void CMainWindow::InitEditor()
{
    SendEditor(SCI_SETREADONLY, FALSE);
    SendEditor(SCI_CLEARALL);
    SendEditor(EM_EMPTYUNDOBUFFER);
    SendEditor(SCI_SETSAVEPOINT);
    SendEditor(SCI_CANCEL);
    SendEditor(SCI_SETUNDOCOLLECTION, 0);
}
Example #30
0
bool CMainWindow::SaveFile(LPCTSTR filename)
{
	FILE* fp = nullptr;
	_wfopen_s(&fp, filename, L"w+b");
	if (!fp)
	{
		TCHAR fmt[1024] = { 0 };
		LoadString(::hResource, IDS_ERRORSAVE, fmt, _countof(fmt));
		TCHAR error[1024] = { 0 };
		_snwprintf_s(error, _countof(error), fmt, filename, static_cast<LPCTSTR>(CFormatMessageWrapper()));
		MessageBox(*this, error, L"TortoiseGitUDiff", MB_OK);
		return false;
	}

	auto len = static_cast<int>(SendEditor(SCI_GETTEXT, 0, 0));
	auto data = std::make_unique<char[]>(len + 1);
	SendEditor(SCI_GETTEXT, len, reinterpret_cast<LPARAM>(static_cast<char *>(data.get())));
	fwrite(data.get(), sizeof(char), len-1, fp);
	fclose(fp);

	SendEditor(SCI_SETSAVEPOINT);
	::ShowWindow(m_hWndEdit, SW_SHOW);
	return true;
}