diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-18 23:17:18 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-22 01:18:05 +0100 |
commit | 753dacacbcc2d45d35a044bfe2512fc4cd564b5c (patch) | |
tree | 0836f965a306b33449d60c4c7b579eab06f6bc2b /src/document.h | |
parent | e0a47e8fcd592585030384faf6d42a2bf74f43ad (diff) | |
download | sciteco-753dacacbcc2d45d35a044bfe2512fc4cd564b5c.tar.gz |
clean up QRegister vs. Buffer redundancies using TECODocument class
* also encapsulates data properly (previously there were many public
attributes to avoid permission issues)
* new class also cares about saving/and restoring scroll state.
now, buffer/q-reg edits and temporary accesses do not reset
the scroll state anymore.
Diffstat (limited to 'src/document.h')
-rw-r--r-- | src/document.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/document.h b/src/document.h new file mode 100644 index 0000000..2ef71ba --- /dev/null +++ b/src/document.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2012-2013 Robin Haberkorn + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __DOCUMENT_H +#define __DOCUMENT_H + +#include <glib.h> + +#include <Scintilla.h> + +#include "sciteco.h" +#include "interface.h" +#include "undo.h" + +/* + * Classes + */ + +/* + * NOTE: The only reason this is called TECODocument + * is to prevent a nameclash with Scintilla which + * does not use a proper namespace for its public + * symbols... + */ +class TECODocument { + typedef const void *SciDoc; + SciDoc doc; + + /* updated/restored only when required */ + gint dot; + gint first_line; + gint xoffset; + +public: + TECODocument() : doc(NULL) + { + reset(); + } + virtual ~TECODocument() + { + if (is_initialized()) + interface.ssm(SCI_RELEASEDOCUMENT, 0, (sptr_t)doc); + } + + inline bool + is_initialized(void) + { + return doc != NULL; + } + + void edit(void); + void undo_edit(void); + + void update(void); + inline void + update(const TECODocument &from) + { + dot = from.dot; + first_line = from.first_line; + xoffset = from.xoffset; + } + + inline void + reset(void) + { + dot = first_line = xoffset = 0; + } + inline void + undo_reset(void) + { + undo.push_var(dot); + undo.push_var(first_line); + undo.push_var(xoffset); + } + + void exchange(TECODocument &other); + inline void + undo_exchange(void) + { + undo.push_var(doc); + undo_reset(); + } +}; + +#endif |