"Fossies" - the Fresh Open Source Software Archive

Member "regexxer-0.10/src/filebufferundo.cc" (6 Oct 2011, 3249 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "filebufferundo.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2002-2007  Daniel Elstner  <daniel.kitta@gmail.com>
    3  *
    4  * This file is part of regexxer.
    5  *
    6  * regexxer is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * regexxer is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with regexxer; if not, write to the Free Software Foundation,
   18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19  */
   20 
   21 #include "filebufferundo.h"
   22 #include "filebuffer.h"
   23 
   24 #include <glib.h>
   25 
   26 
   27 namespace Regexxer
   28 {
   29 
   30 /**** Regexxer::FileBufferActionInsert *************************************/
   31 
   32 FileBufferActionInsert::FileBufferActionInsert(FileBuffer& filebuffer, int offset,
   33                                                const Glib::ustring& text)
   34 :
   35   FileBufferAction(filebuffer),
   36   text_           (text),
   37   offset_         (offset)
   38 {
   39   buffer().increment_stamp();
   40 }
   41 
   42 FileBufferActionInsert::~FileBufferActionInsert()
   43 {}
   44 
   45 bool FileBufferActionInsert::do_undo(const sigc::slot<bool>&)
   46 {
   47   g_return_val_if_fail(!buffer().in_user_action(), false);
   48 
   49   const FileBuffer::iterator text_begin = buffer().get_iter_at_offset(offset_);
   50 
   51   FileBuffer::iterator text_end = text_begin;
   52   text_end.forward_chars(text_.length());
   53 
   54   text_end = buffer().erase(text_begin, text_end);
   55   buffer().place_cursor(text_end);
   56 
   57   buffer().decrement_stamp();
   58 
   59   return false;
   60 }
   61 
   62 
   63 /**** Regexxer::FileBufferActionErase **************************************/
   64 
   65 FileBufferActionErase::FileBufferActionErase(FileBuffer& filebuffer, int offset,
   66                                              const Glib::ustring& text)
   67 :
   68   FileBufferAction(filebuffer),
   69   text_           (text),
   70   offset_         (offset)
   71 {
   72   buffer().increment_stamp();
   73 }
   74 
   75 FileBufferActionErase::~FileBufferActionErase()
   76 {}
   77 
   78 bool FileBufferActionErase::do_undo(const sigc::slot<bool>&)
   79 {
   80   g_return_val_if_fail(!buffer().in_user_action(), false);
   81 
   82   FileBuffer::iterator pos = buffer().get_iter_at_offset(offset_);
   83 
   84   pos = buffer().insert(pos, text_);
   85   buffer().place_cursor(pos);
   86 
   87   buffer().decrement_stamp();
   88 
   89   return false;
   90 }
   91 
   92 
   93 /**** Regexxer::FileBufferActionRemoveMatch ********************************/
   94 
   95 FileBufferActionRemoveMatch::FileBufferActionRemoveMatch(
   96     FileBuffer& filebuffer, int offset, const MatchDataPtr& match)
   97 :
   98   FileBufferAction(filebuffer),
   99   match_          (match),
  100   offset_         (offset)
  101 {
  102   if (match_)
  103     buffer().undo_add_weak(this);
  104 }
  105 
  106 FileBufferActionRemoveMatch::~FileBufferActionRemoveMatch()
  107 {
  108   if (match_)
  109     buffer().undo_remove_weak(this);
  110 }
  111 
  112 void FileBufferActionRemoveMatch::weak_notify()
  113 {
  114   match_.reset();
  115 }
  116 
  117 bool FileBufferActionRemoveMatch::do_undo(const sigc::slot<bool>&)
  118 {
  119   if (match_)
  120   {
  121     g_return_val_if_fail(!buffer().in_user_action(), true);
  122 
  123     buffer().undo_remove_match(match_, offset_);
  124   }
  125   return true;
  126 }
  127 
  128 } // namespace Regexxer