예제 #1
0
void text_editor::cb_save(Fl_Widget *widget, void *v)
{
	extern std::list<std::string> whitelist;

	text_editor *editor = (text_editor*)v;
	Fl_Text_Buffer *buffer = editor->buffer;
	
	int buff_length = buffer->length();
	int buff_lines = buffer->count_lines(0, buff_length);
	
	if (buff_lines > 0)
	{
		int pos = 0;
		whitelist.clear();
		
		for (int i = 0; i <= buff_lines; i++)
		{
			char* line_text = buffer->line_text(pos);
			std::string line(line_text);
			free(line_text);

			if(line.length() > 3)
				whitelist.push_back(line);

			pos = min(buffer->line_end(pos) + 1, buff_length);
		}
	}

	editor->hide();
}
예제 #2
0
void ModelViewController::Print()
{
	if( !serial->isConnected() )
	{
		fl_alert ("Not connected to printer.\nCannot start printing");
		return;
	}

	gui->ContinueButton->value(0);
	gui->ContinueButton->activate();
	gui->ContinueButton->label("Pause");
	gui->PrintButton->value(1);
	gui->PrintButton->label("Print");
	gui->PrintButton->deactivate();

	// Snack one line at a time from the Gcode view, and buffer it.
/*
	if(gui->PrintButton->value() == 0)	// Turned off print, cancel buffer and flush
	{
		m_bPrinting = false;
		return;
	}
*/
	serial->Clear();	// resets line nr and buffer
	serial->m_bPrinting = false;
	serial->SetDebugMask();
	serial->SetLineNr(-1);	// Reset LineNr Count
	gui->CommunationLog->clear();
	Fl_Text_Buffer* buffer = gui->GCodeResult->buffer();
	char* pText = buffer->text();
	uint length = buffer->length();

	uint pos = 2;
	while(pos < length)
		{
		char* line = buffer->line_text(pos);
		if(line[0] == ';')
			{
			pos = buffer->line_end(pos)+1;	// skip newline
			continue;
			}
		serial->AddToBuffer(line);
		pos = buffer->line_end(pos)+1;	// find end of line
		}

	gui->ProgressBar->maximum(serial->Length());
	gui->ProgressBar->label("Printing");
	gui->ProgressBar->value(0);
	free(pText);
	serial->StartPrint();
}
예제 #3
0
void CFLTKEditor::UnIndent()
{
	bool bChangedBuffer = false;
	int iSelStart = 0, iSelEnd = 0, iCurPos = 0, iTabSize, i;
	char *pcLine;
	Fl_Text_Buffer *pBuffer = GetTextBuffer();

	pBuffer->selection_position(&iSelStart, &iSelEnd);
	if (iSelEnd > iSelStart)
	{
		iCurPos = pBuffer->line_start(iSelStart);
		iTabSize = pBuffer->tab_distance();

		while (pBuffer->line_end(iCurPos) < iSelEnd)
		{
			pcLine = pBuffer->line_text(iCurPos);
			if (pcLine[0] == '\t')
			{
				bChangedBuffer = true;
				pBuffer->remove(iCurPos, iCurPos+1);
				--iSelEnd;
			}
			else if (pcLine[0] == ' ')
			{
				for (i = 1; i < iTabSize; i++)
				{
					if (pcLine[i] != ' ')
						break;
				}

				if (i == iTabSize) // same number of spaces as a tab
				{
					bChangedBuffer = true;
					pBuffer->remove(iCurPos, iCurPos + iTabSize);
					iSelEnd -= iTabSize;
				}
			}
			iCurPos = pBuffer->skip_lines(iCurPos, 1);
			free(pcLine);
		}

		if (bChangedBuffer)
			pBuffer->select(pBuffer->line_start(iSelStart), iSelEnd);
	}
}