コード例 #1
0
void WrappingTextView::SetText(const char *text, const text_run_array *runs)
{
	m_modified_disabled = true;
	BTextView::SetText(text,runs);
	ResetUndoBuffer();
	m_modified_disabled = false;
}
コード例 #2
0
void WrappingTextView::SetText(BFile *file, int32 offset, int32 length, const text_run_array *runs)
{
	m_modified_disabled = true;
	BTextView::SetText(file,offset,length,runs);
	ResetUndoBuffer();
	m_modified_disabled = false;
}
コード例 #3
0
ファイル: ImportText.c プロジェクト: amiga-mui/texteditor
///
/// ReimportText
// export and reimport the current text with modified TAB size or TAB conversion
BOOL ReimportText(struct IClass *cl, Object *obj)
{
  struct InstData *data = INST_DATA(cl, obj);
  BOOL result = FALSE;
  struct Hook *ExportHookCopy;
  char *buff;

  ENTER();

  // use the plain export hook
  ExportHookCopy = data->ExportHook;
  data->ExportHook = &ExportHookPlain;

  if((buff = (char *)mExportText(cl, obj, NULL)) != NULL)
  {
    struct MinList newlines;

    if(ImportText(data, buff, data->ImportHook, data->ImportWrap, &newlines) == TRUE)
    {
	  FreeTextMem(data, &data->linelist);
      MoveLines(&data->linelist, &newlines);
	  ResetDisplay(data);
      ResetUndoBuffer(data);
      result = TRUE;
    }

    FreeVec(buff);
  }

  // restore the former export hook
  data->ExportHook = ExportHookCopy;

  RETURN(result);
  return result;
}
コード例 #4
0
void ResizeUndoBuffer(struct InstData *data, ULONG level)
{
    ENTER();

    if(data->undolevel != level)
    {
        D(DBF_UNDO, "resizing undo buffer for %ld undo levels", level);

        if(data->undobuffer != NULL)
        {
            ResetUndoBuffer(data);
            MyFreePooled(data->mypool, data->undobuffer);
        }

        data->undobuffer = NULL;
        data->undopointer = NULL;
        data->undosize = 0;
        data->undofill = 0;
        data->undocur = 0;
        data->undolevel = level;

        if(level > 0)
        {
            ULONG newSize;

            // calculate number of bytes from number of undo levels
            newSize = (level * sizeof(struct UserAction));

            // allocate a new undo buffer
            if((data->undobuffer = MyAllocPooled(data->mypool, newSize)) != NULL)
            {
                data->undopointer = data->undobuffer;
                data->undosize = newSize;
            }
        }
    }

    LEAVE();
}
コード例 #5
0
long AddToUndoBuffer(enum EventType eventtype, char *eventdata, struct InstData *data)
{
    ENTER();

    D(DBF_UNDO, "undolevel: %ld undocur: %ld undofill: %ld", data->undolevel, data->undocur, data->undofill);

    if(data->undolevel > 0)
    {
        struct UserAction *buffer;

        // check if there is still enough space in our undo buffer
        // and if not we clean it up a bit (10 entries)
        if(data->undofill+1 > data->undolevel)
        {
            ULONG c;
            char *t_undobuffer = (char *)data->undobuffer;

            // cleanup at most the first 10 entries in our undobuffer
            for(c=0; c < 10 && data->undofill > 0; c++)
            {
                struct UserAction *t_buffer = (struct UserAction *)t_undobuffer;

                if(t_buffer->type == ET_DELETEBLOCK)
                    MyFreePooled(data->mypool, t_buffer->clip);

                t_undobuffer += sizeof(struct UserAction);

                data->undocur--;
                data->undofill--;
            }

            D(DBF_UNDO, "undobuffer was filled up, cleaned up the first %ld entries", c+1);

            if(data->undofill > 0)
            {
                // copy everything from t_undobuffer to our start of the
                // undobuffer and set the undopointer accordingly.
                memcpy(data->undobuffer, t_undobuffer, data->undosize-(t_undobuffer-(char *)data->undobuffer));
                data->undopointer = (APTR)(t_undobuffer - (char *)data->undopointer);
            }

            // signal the user that something in the
            // undo buffer was lost.
            data->flags |= FLG_UndoLost;
        }

        buffer = data->undopointer;

        // as we are about to set something new for an undo
        // operation we have to signal that redo operation
        // is cleared now.
        if(data->undocur < data->undofill)
        {
            char *t_undobuffer = (char *)data->undopointer;

            D(DBF_UNDO, "cleaning up %ld dropped undo nodes", data->undofill-data->undocur);

            // we have to first cleanup each buffer of the ET_PASTEBLOCK
            // event or otherwise we lost some memory.
            while(data->undofill > data->undocur)
            {
                struct UserAction *t_buffer = (struct UserAction *)t_undobuffer;

                if(t_buffer->type == ET_PASTEBLOCK)
                {
                    D(DBF_UNDO, "cleaning uf paste buffer of user action %08lx", t_buffer);
                    MyFreePooled(data->mypool, t_buffer->clip);
                }

                t_undobuffer += sizeof(struct UserAction);
                data->undofill--;
            }

            set(data->object, MUIA_TextEditor_RedoAvailable, FALSE);
        }

        // if undocur is zero we have to send the undoavailable
        // signal
        if(data->undocur == 0)
            set(data->object, MUIA_TextEditor_UndoAvailable, TRUE);

        data->undopointer = (APTR)((char *)data->undopointer + sizeof(struct UserAction));
        data->undocur++;
        data->undofill = data->undocur;

        buffer->x  = data->CPos_X;
        buffer->y  = LineNr(data->actualline, data);
        buffer->type = eventtype;

        switch(eventtype)
        {
        case ET_BACKSPACEMERGE:
        case ET_MERGELINES:
        {
            buffer->del.style = data->actualline->next->line.Color;
            buffer->del.flow = data->actualline->next->line.Flow;
            buffer->del.separator = data->actualline->next->line.Separator;
        }
        break;

        case ET_DELETECHAR:
        case ET_BACKSPACECHAR:
        {
            buffer->del.character = *eventdata;
            buffer->del.style = GetStyle(data->CPos_X, data->actualline);
            buffer->del.flow = data->actualline->line.Flow;
            buffer->del.separator = data->actualline->line.Separator;
        }
        break;

        case ET_PASTEBLOCK:
        {
            struct marking *block = (struct marking *)eventdata;

            buffer->x  = block->startx;
            buffer->y  = LineNr(block->startline, data);
            buffer->blk.x = block->stopx;
            buffer->blk.y = LineNr(block->stopline, data);
        }
        break;

        case ET_DELETEBLOCK:
        {
            char *text;
            struct marking *block = (struct marking *)eventdata;

            if((text = GetBlock((struct marking *)eventdata, data)))
            {
                buffer->x = block->startx;
                buffer->y = LineNr(block->startline, data);
                buffer->clip = (unsigned char *)text;

                if(data->flags & FLG_FreezeCrsr)
                    buffer->type = ET_DELETEBLOCK_NOMOVE;
            }
            else
            {
                ResetUndoBuffer(data);
                DoMethod(data->object, MUIM_TextEditor_HandleError, Error_NotEnoughUndoMem);
            }
        }
        break;

        default:
            // nothing to do
            break;
        }
    }

    RETURN(TRUE);
    return(TRUE);
}