Ejemplo n.º 1
0
void CursorEnd::execute(EditorModel& model){
	// Set old column position to be current position
	oldCursorColumnPosition = model.cursorColumn();
	const std::string& currentString = model.line(model.cursorLine());

	// Move cursor to the end of the line
	model.setCursorColumn(currentString.length()+1);
}
Ejemplo n.º 2
0
void DeleteLine::execute(EditorModel& model)
{
    backup_line = model.cursorLine();
    backup_column = model.cursorColumn();

    model.deleteLine();

    backup_text = model.getBackupText();
}
Ejemplo n.º 3
0
int EditAreaTabWidget::addEditAreaTab(EditAreaWidget *tab, const QIcon &icon, const QString &label)
{
    EditorModel em = tab->getEditorModel();
    if(em.getEditorType()==EditorModel::MARKDOWN){
        return addMarkdownTab(qobject_cast<MarkdownEditAreaWidget *>(tab), icon, label);
    } else {
        Q_ASSERT(0 && "this should not be happen");
        return addTab(tab, icon, label);
    }
}
Ejemplo n.º 4
0
void InsertChar::execute(EditorModel& model)
{   
    RightCtrl right;
    int insertCol = model.cursorColumn() - 1;

    std::string& temp = model.line(model.cursorLine());
    temp = temp.substr(0, insertCol) + character + temp.substr(insertCol);

    right.execute(model);
}
Ejemplo n.º 5
0
void DeleteLine::execute(EditorModel& model)
{
    row_ = model.cursorLine();
    col_ = model.cursorColumn();
    lines_ = model.lineCount();

    deletedLine_ = model.line(row_);

    if (model.lineCount() == 1)
    {
        if (model.line(1) == "")
        {
            throw EditorException("Already Empty");
        }
        else
        {
            model.line(1) = "";
            model.setCursorHome();
        }
        return;
    }

    model.deleteLine();
    setCursorAfterDelete(model, col_);
}
Ejemplo n.º 6
0
void DeleteLine::undo(EditorModel& model){

	// Handling deletion of line if cursor is not in the first line
	if(lineNumber != firstLine){
		model.insertString(lineNumber, oldString);
		model.incrementLineCount();	

		// If previous line was at the end of the text
		if(lineNumber == model.lineCount()){
			model.incrementCursorLine();
		}
	}

	// Handling deletion of first line of text
	else{

		// If first line contained either empty string or was not the last line of text
		if (oldString == emptyString || lineCount != 1){
			model.incrementLineCount();
			model.insertString(lineNumber, oldString);
		} 

		// Initializes first line of text if it was the only line left
		else{
			model.setLineString(lineNumber, oldString);
		}
	}

	// Fix cursor positioning
	model.setCursorColumn(cursorPos);
}
Ejemplo n.º 7
0
void RightCtrl::execute(EditorModel& model)
{
    int max = model.line(model.cursorLine()).size();

    if (model.cursorColumn() <= max)
    {
        model.moveCursorRight();
    }
    else if (model.cursorColumn() == max + 1)
    {
        if (model.cursorLine() != model.lineCount())
        {    
            model.moveCursorDown();
            model.setCursorHome(); 
        }
        else
        {
            throw EditorException("Already at end");
        }
    }
}
Ejemplo n.º 8
0
void DeleteLine::undo(EditorModel& model)
{
    if (lines_ == 1 && model.line(1) == "")
    {
        model.line(1) = deletedLine_;
    }
    else
    {
        model.setRow(row_ - 1);
        model.insertLine(deletedLine_);
    }
    model.setRow(row_);
    model.setCol(col_);
}
Ejemplo n.º 9
0
 virtual void execute(EditorModel& editor)
 {
     editor.moveColumn(editor.cursorColumn() + 1);
 }
Ejemplo n.º 10
0
 virtual void undo(EditorModel& editor)
 {
     editor.moveColumn(editor.cursorColumn() - 1);
 }
Ejemplo n.º 11
0
void DeleteLine::undo(EditorModel& model)
{
    model.movePosition(backup_line, backup_column);
    model.insertLine(backup_text);
}
Ejemplo n.º 12
0
void Character::undo(EditorModel& model){
	// Delete character and decrement column value for cursor
	model.deleteChar();
	model.decrementCursorColumn();
}
Ejemplo n.º 13
0
void CursorEnd::undo(EditorModel& model){

	// Move cursor back to former position
	model.setCursorColumn(oldCursorColumnPosition);
}
Ejemplo n.º 14
0
void DeleteLine::execute(EditorModel& model){
	
	// Obtain previous values of pre-deletion for line
	oldString = model.line(model.cursorLine());
	lineNumber = model.cursorLine();
	cursorPos = model.cursorColumn();
	lineCount = model.lineCount();

	// Throw error if text is empty
	if (lineNumber == firstLine && model.line(lineNumber) == emptyString && model.lineCount() == 1){
		model.setErrorMessage( deleteLineError.getReason() );
		throw deleteLineError;
	}

	// Empty the first line if that is the only line in the text (there should be at least one line in the text)
	if (model.lineCount() == firstLine){
		model.setLineString(firstLine, emptyString);
		model.setCursorColumn(1);
	}

	// Delete the line and move the curser up if you are at the end of the page
	else{
		// Set boolean variables for cursor line placement
		const bool atBeginningOfPage = model.cursorAtBeginningOfPage();
		const bool atEndOfPage = model.cursorAtEndOfPage();
		const bool previousColumnPlacementTooFar = model.cursorColumn() > model.line(model.cursorLine()).length();

		// Only initialize this boolean if you are not at the end of the page
		const bool nextColumnPlacementTooFar = !atEndOfPage ? model.cursorColumn() > model.line(model.cursorLine()+1).length() : false;

		// Deletes current line from text
		model.deleteLine(model.cursorLine());

		// Move cursor up if at the end of the page
		if (atEndOfPage){
			CursorUp c;
			c.execute(model);
		}

		// Fix cursor column placement if cursor is at the beginning of text, 
		else if (atBeginningOfPage && previousColumnPlacementTooFar){
			model.setCursorColumn(model.line(model.cursorLine()).length()+1);
		}
		else if (nextColumnPlacementTooFar){
			model.setCursorColumn(model.line(model.cursorLine()).length()+1);
		}
		// Decrement the current line count
		model.decrementLineCount();
	}
}
Ejemplo n.º 15
0
void HomeCtrl::undo(EditorModel& model)
{
    model.setCol(col_);
}
Ejemplo n.º 16
0
void HomeCtrl::execute(EditorModel& model)
{
    col_ = model.cursorColumn();

    model.setCursorHome();
}
Ejemplo n.º 17
0
void Character::execute(EditorModel& model){

	// Place character on line and increment column value for cursor
	model.insert(characterPressed);
	model.incrementCursorColumn();
}