diff options
author | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-01 11:40:19 +0000 |
---|---|---|
committer | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-01 11:40:19 +0000 |
commit | d12c20503e90d74b61d3839b655add031ebf2c0a (patch) | |
tree | 636a9bf78f85f073326342ec1677a8615cbbfac4 /third_party | |
parent | dd54b3db1a03892b9d1faecbe3fc9504234cd54f (diff) | |
download | chromium_src-d12c20503e90d74b61d3839b655add031ebf2c0a.zip chromium_src-d12c20503e90d74b61d3839b655add031ebf2c0a.tar.gz chromium_src-d12c20503e90d74b61d3839b655add031ebf2c0a.tar.bz2 |
Use undoview from deps/third_party/
BUG=111334
Review URL: https://chromiumcodereview.appspot.com/9293016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/undoview/LICENSE | 502 | ||||
-rw-r--r-- | third_party/undoview/README.chromium | 13 | ||||
-rw-r--r-- | third_party/undoview/undo_manager.c | 1110 | ||||
-rw-r--r-- | third_party/undoview/undo_manager.h | 86 | ||||
-rw-r--r-- | third_party/undoview/undo_view.c | 83 | ||||
-rw-r--r-- | third_party/undoview/undo_view.h | 50 | ||||
-rw-r--r-- | third_party/undoview/undoview.gyp | 22 |
7 files changed, 0 insertions, 1866 deletions
diff --git a/third_party/undoview/LICENSE b/third_party/undoview/LICENSE deleted file mode 100644 index 4362b49..0000000 --- a/third_party/undoview/LICENSE +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - <one line to give the library's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - <signature of Ty Coon>, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/third_party/undoview/README.chromium b/third_party/undoview/README.chromium deleted file mode 100644 index 032e2b3..0000000 --- a/third_party/undoview/README.chromium +++ /dev/null @@ -1,13 +0,0 @@ -Name: undoview -Short Name: undoview -URL: http://projects.gnome.org/gtksourceview, http://www.gtk.org -Version: unknown -License: LGPL 2.1 -Security Critical: yes - -This directory provides a new class, GtkUndoView. It is based on GtkTextView -from the GTK+ project, but with undo/redo support added. The code to add this -support is borrowed from the GtkSourceView project. Since GtkSourceView has a -lot of other stuff we don't want, we borrow only the undo/redo support and add -it to GtkTextView to create GtkUndoView. - diff --git a/third_party/undoview/undo_manager.c b/third_party/undoview/undo_manager.c deleted file mode 100644 index 6efba9c..0000000 --- a/third_party/undoview/undo_manager.c +++ /dev/null @@ -1,1110 +0,0 @@ -/* - * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002-2005 Paolo Maggi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <stdlib.h> -#include <string.h> - -#include "undo_manager.h" - -#define DEFAULT_MAX_UNDO_LEVELS 25 - -typedef struct _GtkSourceUndoAction GtkSourceUndoAction; -typedef struct _GtkSourceUndoInsertAction GtkSourceUndoInsertAction; -typedef struct _GtkSourceUndoDeleteAction GtkSourceUndoDeleteAction; - -typedef enum { - GTK_SOURCE_UNDO_ACTION_INSERT, - GTK_SOURCE_UNDO_ACTION_DELETE, -} GtkSourceUndoActionType; - -/* - * We use offsets instead of GtkTextIters because the last ones - * require to much memory in this context without giving us any advantage. - */ - -struct _GtkSourceUndoInsertAction { - gint pos; - gchar *text; - gint length; - gint chars; -}; - -struct _GtkSourceUndoDeleteAction { - gint start; - gint end; - gchar *text; - gboolean forward; -}; - -struct _GtkSourceUndoAction { - GtkSourceUndoActionType action_type; - - union { - GtkSourceUndoInsertAction insert; - GtkSourceUndoDeleteAction delete; - } action; - - gint order_in_group; - - /* It is TRUE whether the action can be merged with the following action. */ - guint mergeable : 1; - - /* It is TRUE whether the action is marked as "modified". - * An action is marked as "modified" if it changed the - * state of the buffer from "not modified" to "modified". Only the first - * action of a group can be marked as modified. - * There can be a single action marked as "modified" in the actions list. - */ - guint modified : 1; -}; - -/* INVALID is a pointer to an invalid action */ -#define INVALID ((void *) "IA") - -struct _GtkSourceUndoManagerPrivate { - GtkTextBuffer *document; - - GList* actions; - gint next_redo; - - gint actions_in_current_group; - - gint running_not_undoable_actions; - - gint num_of_groups; - - gint max_undo_levels; - - guint can_undo : 1; - guint can_redo : 1; - - /* It is TRUE whether, while undoing an action of the current group (with order_in_group > 1), - * the state of the buffer changed from "not modified" to "modified". - */ - guint modified_undoing_group : 1; - - /* Pointer to the action (in the action list) marked as "modified". - * It is NULL when no action is marked as "modified". - * It is INVALID when the action marked as "modified" has been removed - * from the action list (freeing the list or resizing it) */ - GtkSourceUndoAction *modified_action; -}; - -enum { - CAN_UNDO, - CAN_REDO, - LAST_SIGNAL -}; - -#if !defined(NDEBUG) -static void -print_state(GtkSourceUndoManager* um) -{ - fprintf(stderr, "\n***\n"); - GList* actions = um->priv->actions; - - for (; actions; actions = g_list_next(actions)) { - GtkSourceUndoAction* act = actions->data; - fprintf(stderr, "* type = %s\n", act->action_type == GTK_SOURCE_UNDO_ACTION_DELETE ? - "delete" : "insert"); - - fprintf(stderr, "\ttext = %s\n", act->action_type == GTK_SOURCE_UNDO_ACTION_DELETE - ? act->action.delete.text : act->action.insert.text); - fprintf(stderr, "\torder = %d\n", act->order_in_group); - } - - fprintf(stderr, "* next redo: %d\n", um->priv->next_redo); - fprintf(stderr, "* num of groups: %d\n", um->priv->num_of_groups); - fprintf(stderr, "* actions in group: %d\n", um->priv->actions_in_current_group); -} -#endif - -static void gtk_source_undo_manager_class_init(GtkSourceUndoManagerClass *klass); -static void gtk_source_undo_manager_init(GtkSourceUndoManager *um); -static void gtk_source_undo_manager_finalize(GObject *object); - -static void gtk_source_undo_manager_insert_text_handler(GtkTextBuffer *buffer, - GtkTextIter *pos, - const gchar *text, - gint length, - GtkSourceUndoManager *um); -static void gtk_source_undo_manager_delete_range_handler(GtkTextBuffer *buffer, - GtkTextIter *start, - GtkTextIter *end, - GtkSourceUndoManager *um); -static void gtk_source_undo_manager_begin_user_action_handler(GtkTextBuffer *buffer, - GtkSourceUndoManager *um); -static void gtk_source_undo_manager_modified_changed_handler(GtkTextBuffer *buffer, - GtkSourceUndoManager *um); - -static void gtk_source_undo_manager_free_action_list(GtkSourceUndoManager *um); - -static void gtk_source_undo_manager_add_action(GtkSourceUndoManager *um, - const GtkSourceUndoAction *undo_action); -static void gtk_source_undo_manager_free_first_n_actions(GtkSourceUndoManager *um, - gint n); -static void gtk_source_undo_manager_check_list_size(GtkSourceUndoManager *um); - -static gboolean gtk_source_undo_manager_merge_action(GtkSourceUndoManager *um, - const GtkSourceUndoAction *undo_action); - -static GObjectClass *parent_class = NULL; -static guint undo_manager_signals [LAST_SIGNAL] = { 0 }; - -GType -gtk_source_undo_manager_get_type(void) { - static GType undo_manager_type = 0; - - if(undo_manager_type == 0) - { - static const GTypeInfo our_info = - { - sizeof(GtkSourceUndoManagerClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gtk_source_undo_manager_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(GtkSourceUndoManager), - 0, /* n_preallocs */ - (GInstanceInitFunc) gtk_source_undo_manager_init, - NULL /* value_table */ - }; - - undo_manager_type = g_type_register_static(G_TYPE_OBJECT, - "GtkSourceUndoManager", - &our_info, - 0); - } - - return undo_manager_type; -} - -static void -gtk_source_undo_manager_class_init(GtkSourceUndoManagerClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - object_class->finalize = gtk_source_undo_manager_finalize; - - klass->can_undo = NULL; - klass->can_redo = NULL; - - undo_manager_signals[CAN_UNDO] = - g_signal_new("can_undo", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GtkSourceUndoManagerClass, can_undo), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, - 1, - G_TYPE_BOOLEAN); - - undo_manager_signals[CAN_REDO] = - g_signal_new("can_redo", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GtkSourceUndoManagerClass, can_redo), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, - 1, - G_TYPE_BOOLEAN); -} - -static void -gtk_source_undo_manager_init(GtkSourceUndoManager *um) { - um->priv = g_new0(GtkSourceUndoManagerPrivate, 1); - - um->priv->actions = NULL; - um->priv->next_redo = 0; - - um->priv->can_undo = FALSE; - um->priv->can_redo = FALSE; - - um->priv->running_not_undoable_actions = 0; - - um->priv->num_of_groups = 0; - - um->priv->max_undo_levels = DEFAULT_MAX_UNDO_LEVELS; - - um->priv->modified_action = NULL; - - um->priv->modified_undoing_group = FALSE; -} - -static void -gtk_source_undo_manager_finalize(GObject *object) { - GtkSourceUndoManager *um; - - g_return_if_fail(object != NULL); - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(object)); - - um = GTK_SOURCE_UNDO_MANAGER(object); - - g_return_if_fail(um->priv != NULL); - - if(um->priv->actions != NULL) - gtk_source_undo_manager_free_action_list(um); - - g_signal_handlers_disconnect_by_func(G_OBJECT(um->priv->document), - G_CALLBACK(gtk_source_undo_manager_delete_range_handler), - um); - - g_signal_handlers_disconnect_by_func(G_OBJECT(um->priv->document), - G_CALLBACK(gtk_source_undo_manager_insert_text_handler), - um); - - g_signal_handlers_disconnect_by_func(G_OBJECT(um->priv->document), - G_CALLBACK(gtk_source_undo_manager_begin_user_action_handler), - um); - - g_signal_handlers_disconnect_by_func(G_OBJECT(um->priv->document), - G_CALLBACK(gtk_source_undo_manager_modified_changed_handler), - um); - - g_free(um->priv); - - G_OBJECT_CLASS(parent_class)->finalize(object); -} - -GtkSourceUndoManager* -gtk_source_undo_manager_new(GtkTextBuffer* buffer) { - GtkSourceUndoManager *um; - - um = GTK_SOURCE_UNDO_MANAGER(g_object_new(GTK_SOURCE_TYPE_UNDO_MANAGER, NULL)); - - g_return_val_if_fail(um->priv != NULL, NULL); - um->priv->document = buffer; - - g_signal_connect(G_OBJECT(buffer), "insert_text", - G_CALLBACK(gtk_source_undo_manager_insert_text_handler), - um); - - g_signal_connect(G_OBJECT(buffer), "delete_range", - G_CALLBACK(gtk_source_undo_manager_delete_range_handler), - um); - - g_signal_connect(G_OBJECT(buffer), "begin_user_action", - G_CALLBACK(gtk_source_undo_manager_begin_user_action_handler), - um); - - g_signal_connect(G_OBJECT(buffer), "modified_changed", - G_CALLBACK(gtk_source_undo_manager_modified_changed_handler), - um); - return um; -} - -void -gtk_source_undo_manager_begin_not_undoable_action(GtkSourceUndoManager *um) { - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - ++um->priv->running_not_undoable_actions; -} - -static void -gtk_source_undo_manager_end_not_undoable_action_internal(GtkSourceUndoManager *um) { - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - g_return_if_fail(um->priv->running_not_undoable_actions > 0); - - --um->priv->running_not_undoable_actions; -} - -void -gtk_source_undo_manager_end_not_undoable_action(GtkSourceUndoManager *um) { - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - gtk_source_undo_manager_end_not_undoable_action_internal(um); - - if(um->priv->running_not_undoable_actions == 0) - { - gtk_source_undo_manager_free_action_list(um); - - um->priv->next_redo = -1; - - if(um->priv->can_undo) - { - um->priv->can_undo = FALSE; - g_signal_emit(G_OBJECT(um), - undo_manager_signals [CAN_UNDO], - 0, - FALSE); - } - - if(um->priv->can_redo) - { - um->priv->can_redo = FALSE; - g_signal_emit(G_OBJECT(um), - undo_manager_signals [CAN_REDO], - 0, - FALSE); - } - } -} - -gboolean -gtk_source_undo_manager_can_undo(const GtkSourceUndoManager *um) { - g_return_val_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um), FALSE); - g_return_val_if_fail(um->priv != NULL, FALSE); - - return um->priv->can_undo; -} - -gboolean -gtk_source_undo_manager_can_redo(const GtkSourceUndoManager *um) { - g_return_val_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um), FALSE); - g_return_val_if_fail(um->priv != NULL, FALSE); - - return um->priv->can_redo; -} - -static void -set_cursor(GtkTextBuffer *buffer, gint cursor) { - GtkTextIter iter; - - /* Place the cursor at the requested position */ - gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor); - gtk_text_buffer_place_cursor(buffer, &iter); -} - -static void -insert_text(GtkTextBuffer *buffer, gint pos, const gchar *text, gint len) { - GtkTextIter iter; - - gtk_text_buffer_get_iter_at_offset(buffer, &iter, pos); - gtk_text_buffer_insert(buffer, &iter, text, len); -} - -static void -delete_text(GtkTextBuffer *buffer, gint start, gint end) { - GtkTextIter start_iter; - GtkTextIter end_iter; - - gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start); - - if(end < 0) - gtk_text_buffer_get_end_iter(buffer, &end_iter); - else - gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end); - - gtk_text_buffer_delete(buffer, &start_iter, &end_iter); -} - -static gchar* -get_chars(GtkTextBuffer *buffer, gint start, gint end) { - GtkTextIter start_iter; - GtkTextIter end_iter; - - gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start); - - if(end < 0) - gtk_text_buffer_get_end_iter(buffer, &end_iter); - else - gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end); - - return gtk_text_buffer_get_slice(buffer, &start_iter, &end_iter, TRUE); -} - -void -gtk_source_undo_manager_undo(GtkSourceUndoManager *um) { - GtkSourceUndoAction *undo_action; - gboolean modified = FALSE; - - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - g_return_if_fail(um->priv->can_undo); - - um->priv->modified_undoing_group = FALSE; - - gtk_source_undo_manager_begin_not_undoable_action(um); - - do - { - undo_action = g_list_nth_data(um->priv->actions, um->priv->next_redo + 1); - g_return_if_fail(undo_action != NULL); - - /* undo_action->modified can be TRUE only if undo_action->order_in_group <= 1 */ - g_return_if_fail((undo_action->order_in_group <= 1) || - ((undo_action->order_in_group > 1) && !undo_action->modified)); - - if(undo_action->order_in_group <= 1) - { - /* Set modified to TRUE only if the buffer did not change its state from - * "not modified" to "modified" undoing an action(with order_in_group > 1) - * in current group. */ - modified =(undo_action->modified && !um->priv->modified_undoing_group); - } - - switch(undo_action->action_type) - { - case GTK_SOURCE_UNDO_ACTION_DELETE: - insert_text( - um->priv->document, - undo_action->action.delete.start, - undo_action->action.delete.text, - strlen(undo_action->action.delete.text)); - - if(undo_action->action.delete.forward) - set_cursor( - um->priv->document, - undo_action->action.delete.start); - else - set_cursor( - um->priv->document, - undo_action->action.delete.end); - - break; - - case GTK_SOURCE_UNDO_ACTION_INSERT: - delete_text( - um->priv->document, - undo_action->action.insert.pos, - undo_action->action.insert.pos + - undo_action->action.insert.chars); - - set_cursor( - um->priv->document, - undo_action->action.insert.pos); - break; - - default: - /* Unknown action type. */ - g_return_if_reached(); - } - - ++um->priv->next_redo; - - } while(undo_action->order_in_group > 1); - - if(modified) - { - --um->priv->next_redo; - gtk_text_buffer_set_modified(um->priv->document, FALSE); - ++um->priv->next_redo; - } - - gtk_source_undo_manager_end_not_undoable_action_internal(um); - - um->priv->modified_undoing_group = FALSE; - - if(!um->priv->can_redo) - { - um->priv->can_redo = TRUE; - g_signal_emit(G_OBJECT(um), - undo_manager_signals [CAN_REDO], - 0, - TRUE); - } - - if(um->priv->next_redo >=(gint)(g_list_length(um->priv->actions) - 1)) - { - um->priv->can_undo = FALSE; - g_signal_emit(G_OBJECT(um), - undo_manager_signals [CAN_UNDO], - 0, - FALSE); - } -} - -void -gtk_source_undo_manager_redo(GtkSourceUndoManager *um) { - GtkSourceUndoAction *undo_action; - gboolean modified = FALSE; - - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - g_return_if_fail(um->priv->can_redo); - - undo_action = g_list_nth_data(um->priv->actions, um->priv->next_redo); - g_return_if_fail(undo_action != NULL); - - gtk_source_undo_manager_begin_not_undoable_action(um); - - do - { - if(undo_action->modified) - { - g_return_if_fail(undo_action->order_in_group <= 1); - modified = TRUE; - } - - --um->priv->next_redo; - - switch(undo_action->action_type) - { - case GTK_SOURCE_UNDO_ACTION_DELETE: - delete_text( - um->priv->document, - undo_action->action.delete.start, - undo_action->action.delete.end); - - set_cursor( - um->priv->document, - undo_action->action.delete.start); - - break; - - case GTK_SOURCE_UNDO_ACTION_INSERT: - set_cursor( - um->priv->document, - undo_action->action.insert.pos); - - insert_text( - um->priv->document, - undo_action->action.insert.pos, - undo_action->action.insert.text, - undo_action->action.insert.length); - - break; - - default: - /* Unknown action type */ - ++um->priv->next_redo; - g_return_if_reached(); - } - - if(um->priv->next_redo < 0) - undo_action = NULL; - else - undo_action = g_list_nth_data(um->priv->actions, um->priv->next_redo); - - } while((undo_action != NULL) &&(undo_action->order_in_group > 1)); - - if(modified) - { - ++um->priv->next_redo; - gtk_text_buffer_set_modified(um->priv->document, FALSE); - --um->priv->next_redo; - } - - gtk_source_undo_manager_end_not_undoable_action_internal(um); - - if(um->priv->next_redo < 0) - { - um->priv->can_redo = FALSE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_REDO], 0, FALSE); - } - - if(!um->priv->can_undo) - { - um->priv->can_undo = TRUE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_UNDO], 0, TRUE); - } -} - -static void -gtk_source_undo_action_free(GtkSourceUndoAction *action) { - if(action == NULL) - return; - - if(action->action_type == GTK_SOURCE_UNDO_ACTION_INSERT) - g_free(action->action.insert.text); - else if(action->action_type == GTK_SOURCE_UNDO_ACTION_DELETE) - g_free(action->action.delete.text); - else - g_return_if_reached(); - - g_free(action); -} - -static void -gtk_source_undo_manager_free_action_list(GtkSourceUndoManager *um) { - GList *l; - - l = um->priv->actions; - - while(l != NULL) - { - GtkSourceUndoAction *action = l->data; - - if(action->order_in_group == 1) - --um->priv->num_of_groups; - um->priv->actions_in_current_group = action->order_in_group - 1; - - if(action->modified) - um->priv->modified_action = INVALID; - - gtk_source_undo_action_free(action); - - l = g_list_next(l); - } - - g_list_free(um->priv->actions); - um->priv->actions = NULL; -} - -static void -gtk_source_undo_manager_insert_text_handler(GtkTextBuffer *buffer, - GtkTextIter *pos, - const gchar *text, - gint length, - GtkSourceUndoManager *um) { - GtkSourceUndoAction undo_action; - - if(um->priv->running_not_undoable_actions > 0) - return; - - undo_action.action_type = GTK_SOURCE_UNDO_ACTION_INSERT; - - undo_action.action.insert.pos = gtk_text_iter_get_offset(pos); - undo_action.action.insert.text =(gchar*) text; - undo_action.action.insert.length = length; - undo_action.action.insert.chars = g_utf8_strlen(text, length); - - if((undo_action.action.insert.chars > 1) ||(g_utf8_get_char(text) == '\n')) - - undo_action.mergeable = FALSE; - else - undo_action.mergeable = TRUE; - - undo_action.modified = FALSE; - - gtk_source_undo_manager_add_action(um, &undo_action); -} - -static void -gtk_source_undo_manager_delete_range_handler(GtkTextBuffer *buffer, - GtkTextIter *start, - GtkTextIter *end, - GtkSourceUndoManager *um) { - GtkSourceUndoAction undo_action; - GtkTextIter insert_iter; - - if(um->priv->running_not_undoable_actions > 0) - return; - - undo_action.action_type = GTK_SOURCE_UNDO_ACTION_DELETE; - - gtk_text_iter_order(start, end); - - undo_action.action.delete.start = gtk_text_iter_get_offset(start); - undo_action.action.delete.end = gtk_text_iter_get_offset(end); - - undo_action.action.delete.text = get_chars( - buffer, - undo_action.action.delete.start, - undo_action.action.delete.end); - - /* figure out if the user used the Delete or the Backspace key */ - gtk_text_buffer_get_iter_at_mark(buffer, &insert_iter, - gtk_text_buffer_get_insert(buffer)); - if(gtk_text_iter_get_offset(&insert_iter) <= undo_action.action.delete.start) - undo_action.action.delete.forward = TRUE; - else - undo_action.action.delete.forward = FALSE; - - if(((undo_action.action.delete.end - undo_action.action.delete.start) > 1) || - (g_utf8_get_char(undo_action.action.delete.text ) == '\n')) - undo_action.mergeable = FALSE; - else - undo_action.mergeable = TRUE; - - undo_action.modified = FALSE; - - gtk_source_undo_manager_add_action(um, &undo_action); - - g_free(undo_action.action.delete.text); - -} - -static void -gtk_source_undo_manager_begin_user_action_handler(GtkTextBuffer *buffer, GtkSourceUndoManager *um) { - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - if(um->priv->running_not_undoable_actions > 0) - return; - - um->priv->actions_in_current_group = 0; -} - -static void -gtk_source_undo_manager_add_action(GtkSourceUndoManager *um, - const GtkSourceUndoAction *undo_action) { - GtkSourceUndoAction* action; - - if(um->priv->next_redo >= 0) - { - gtk_source_undo_manager_free_first_n_actions(um, um->priv->next_redo + 1); - } - - um->priv->next_redo = -1; - - if(!gtk_source_undo_manager_merge_action(um, undo_action)) - { - action = g_new(GtkSourceUndoAction, 1); - *action = *undo_action; - - if(action->action_type == GTK_SOURCE_UNDO_ACTION_INSERT) - action->action.insert.text = g_strndup(undo_action->action.insert.text, undo_action->action.insert.length); - else if(action->action_type == GTK_SOURCE_UNDO_ACTION_DELETE) - action->action.delete.text = g_strdup(undo_action->action.delete.text); - else - { - g_free(action); - g_return_if_reached(); - } - - ++um->priv->actions_in_current_group; - action->order_in_group = um->priv->actions_in_current_group; - - if(action->order_in_group == 1) - ++um->priv->num_of_groups; - - um->priv->actions = g_list_prepend(um->priv->actions, action); - } - - gtk_source_undo_manager_check_list_size(um); - - if(!um->priv->can_undo) - { - um->priv->can_undo = TRUE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_UNDO], 0, TRUE); - } - - if(um->priv->can_redo) - { - um->priv->can_redo = FALSE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_REDO], 0, FALSE); - } -} - -static void -gtk_source_undo_manager_free_first_n_actions(GtkSourceUndoManager *um, - gint n) { - gint i; - - if(um->priv->actions == NULL) - return; - - for(i = 0; i < n; i++) - { - GtkSourceUndoAction *action = g_list_first(um->priv->actions)->data; - - if(action->order_in_group == 1) - --um->priv->num_of_groups; - um->priv->actions_in_current_group = action->order_in_group - 1; - - if(action->modified) - um->priv->modified_action = INVALID; - - gtk_source_undo_action_free(action); - - um->priv->actions = g_list_delete_link(um->priv->actions, - um->priv->actions); - - if(um->priv->actions == NULL) - return; - } -} - -static void -gtk_source_undo_manager_check_list_size(GtkSourceUndoManager *um) { - gint undo_levels; - - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - undo_levels = gtk_source_undo_manager_get_max_undo_levels(um); - - if(undo_levels < 1) - return; - - if(um->priv->num_of_groups > undo_levels) - { - GtkSourceUndoAction *undo_action; - GList *last; - - last = g_list_last(um->priv->actions); - undo_action =(GtkSourceUndoAction*) last->data; - - do - { - GList *tmp; - - if(undo_action->order_in_group == 1) - --um->priv->num_of_groups; - um->priv->actions_in_current_group = undo_action->order_in_group - 1; - - if(undo_action->modified) - um->priv->modified_action = INVALID; - - gtk_source_undo_action_free(undo_action); - - tmp = g_list_previous(last); - um->priv->actions = g_list_delete_link(um->priv->actions, last); - last = tmp; - g_return_if_fail(last != NULL); - - undo_action =(GtkSourceUndoAction*) last->data; - - } while((undo_action->order_in_group > 1) || - (um->priv->num_of_groups > undo_levels)); - } -} - -/** - * gtk_source_undo_manager_merge_action: - * @um: a #GtkSourceUndoManager. - * @undo_action: a #GtkSourceUndoAction. - * - * This function tries to merge the undo action at the top of - * the stack with a new undo action. So when we undo for example - * typing, we can undo the whole word and not each letter by itself. - * - * Return Value: %TRUE is merge was successful, %FALSE otherwise. - **/ -static gboolean -gtk_source_undo_manager_merge_action(GtkSourceUndoManager *um, - const GtkSourceUndoAction *undo_action) { - GtkSourceUndoAction *last_action; - - g_return_val_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um), FALSE); - g_return_val_if_fail(um->priv != NULL, FALSE); - - if(um->priv->actions == NULL) - return FALSE; - - last_action =(GtkSourceUndoAction*) g_list_nth_data(um->priv->actions, 0); - - if(!last_action->mergeable) - return FALSE; - - if((!undo_action->mergeable) || - (undo_action->action_type != last_action->action_type)) - { - last_action->mergeable = FALSE; - return FALSE; - } - - if(undo_action->action_type == GTK_SOURCE_UNDO_ACTION_DELETE) - { - if((last_action->action.delete.forward != undo_action->action.delete.forward) || - ((last_action->action.delete.start != undo_action->action.delete.start) && - (last_action->action.delete.start != undo_action->action.delete.end))) - { - last_action->mergeable = FALSE; - return FALSE; - } - - if(last_action->action.delete.start == undo_action->action.delete.start) - { - gchar *str; - -#define L (last_action->action.delete.end - last_action->action.delete.start - 1) -#define g_utf8_get_char_at(p,i) g_utf8_get_char(g_utf8_offset_to_pointer((p),(i))) - - /* Deleted with the delete key */ - if((g_utf8_get_char(undo_action->action.delete.text) != ' ') && - (g_utf8_get_char(undo_action->action.delete.text) != '\t') && - ((g_utf8_get_char_at(last_action->action.delete.text, L) == ' ') || - (g_utf8_get_char_at(last_action->action.delete.text, L) == '\t'))) - { - last_action->mergeable = FALSE; - return FALSE; - } - - str = g_strdup_printf("%s%s", last_action->action.delete.text, - undo_action->action.delete.text); - - g_free(last_action->action.delete.text); - last_action->action.delete.end +=(undo_action->action.delete.end - - undo_action->action.delete.start); - last_action->action.delete.text = str; - } - else - { - gchar *str; - - /* Deleted with the backspace key */ - if((g_utf8_get_char(undo_action->action.delete.text) != ' ') && - (g_utf8_get_char(undo_action->action.delete.text) != '\t') && - ((g_utf8_get_char(last_action->action.delete.text) == ' ') || - (g_utf8_get_char(last_action->action.delete.text) == '\t'))) - { - last_action->mergeable = FALSE; - return FALSE; - } - - str = g_strdup_printf("%s%s", undo_action->action.delete.text, - last_action->action.delete.text); - - g_free(last_action->action.delete.text); - last_action->action.delete.start = undo_action->action.delete.start; - last_action->action.delete.text = str; - } - } - else if(undo_action->action_type == GTK_SOURCE_UNDO_ACTION_INSERT) - { - gchar* str; - -#define I (last_action->action.insert.chars - 1) - - if((undo_action->action.insert.pos != - (last_action->action.insert.pos + last_action->action.insert.chars)) || - ((g_utf8_get_char(undo_action->action.insert.text) != ' ') && - (g_utf8_get_char(undo_action->action.insert.text) != '\t') && - ((g_utf8_get_char_at(last_action->action.insert.text, I) == ' ') || - (g_utf8_get_char_at(last_action->action.insert.text, I) == '\t'))) - ) - { - last_action->mergeable = FALSE; - return FALSE; - } - - str = g_strdup_printf("%s%s", last_action->action.insert.text, - undo_action->action.insert.text); - - g_free(last_action->action.insert.text); - last_action->action.insert.length += undo_action->action.insert.length; - last_action->action.insert.text = str; - last_action->action.insert.chars += undo_action->action.insert.chars; - - } - else - /* Unknown action inside undo merge encountered */ - g_return_val_if_reached(TRUE); - - return TRUE; -} - -gint -gtk_source_undo_manager_get_max_undo_levels(GtkSourceUndoManager *um) { - g_return_val_if_fail(um != NULL, 0); - g_return_val_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um), 0); - - return um->priv->max_undo_levels; -} - -void -gtk_source_undo_manager_set_max_undo_levels(GtkSourceUndoManager *um, - gint max_undo_levels) { - gint old_levels; - - g_return_if_fail(um != NULL); - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - - old_levels = um->priv->max_undo_levels; - um->priv->max_undo_levels = max_undo_levels; - - if(max_undo_levels < 1) - return; - - if(old_levels > max_undo_levels) - { - /* strip redo actions first */ - while(um->priv->next_redo >= 0 &&(um->priv->num_of_groups > max_undo_levels)) - { - gtk_source_undo_manager_free_first_n_actions(um, 1); - um->priv->next_redo--; - } - - /* now remove undo actions if necessary */ - gtk_source_undo_manager_check_list_size(um); - - /* emit "can_undo" and/or "can_redo" if appropiate */ - if(um->priv->next_redo < 0 && um->priv->can_redo) - { - um->priv->can_redo = FALSE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_REDO], 0, FALSE); - } - - if(um->priv->can_undo && - um->priv->next_redo >=(gint)(g_list_length(um->priv->actions) - 1)) - { - um->priv->can_undo = FALSE; - g_signal_emit(G_OBJECT(um), undo_manager_signals [CAN_UNDO], 0, FALSE); - } - } -} - -static void -gtk_source_undo_manager_modified_changed_handler(GtkTextBuffer *buffer, - GtkSourceUndoManager *um) { - GtkSourceUndoAction *action; - GList *list; - - g_return_if_fail(GTK_SOURCE_IS_UNDO_MANAGER(um)); - g_return_if_fail(um->priv != NULL); - - if(um->priv->actions == NULL) - return; - - list = g_list_nth(um->priv->actions, um->priv->next_redo + 1); - - if(list != NULL) - action =(GtkSourceUndoAction*) list->data; - else - action = NULL; - - if(gtk_text_buffer_get_modified(buffer) == FALSE) - { - if(action != NULL) - action->mergeable = FALSE; - - if(um->priv->modified_action != NULL) - { - if(um->priv->modified_action != INVALID) - um->priv->modified_action->modified = FALSE; - - um->priv->modified_action = NULL; - } - - return; - } - - if(action == NULL) - { - g_return_if_fail(um->priv->running_not_undoable_actions > 0); - - return; - } - - /* gtk_text_buffer_get_modified(buffer) == TRUE */ - - g_return_if_fail(um->priv->modified_action == NULL); - - if(action->order_in_group > 1) - um->priv->modified_undoing_group = TRUE; - - while(action->order_in_group > 1) - { - list = g_list_next(list); - g_return_if_fail(list != NULL); - - action =(GtkSourceUndoAction*) list->data; - g_return_if_fail(action != NULL); - } - - action->modified = TRUE; - um->priv->modified_action = action; -} - diff --git a/third_party/undoview/undo_manager.h b/third_party/undoview/undo_manager.h deleted file mode 100644 index 5a18829..0000000 --- a/third_party/undoview/undo_manager.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002, 2003 Paolo Maggi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef UNDOVIEW_UNDO_MANAGER_H_ -#define UNDOVIEW_UNDO_MANAGER_H_ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GTK_SOURCE_TYPE_UNDO_MANAGER (gtk_source_undo_manager_get_type()) - -#define GTK_SOURCE_UNDO_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_SOURCE_TYPE_UNDO_MANAGER, GtkSourceUndoManager)) - -#define GTK_SOURCE_UNDO_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GTK_SOURCE_TYPE_UNDO_MANAGER, GtkSourceUndoManagerClass)) - -#define GTK_SOURCE_IS_UNDO_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_SOURCE_TYPE_UNDO_MANAGER)) - -#define GTK_SOURCE_IS_UNDO_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_SOURCE_TYPE_UNDO_MANAGER)) - -#define GTK_SOURCE_UNDO_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_SOURCE_TYPE_UNDO_MANAGER, GtkSourceUndoManagerClass)) - -typedef struct _GtkSourceUndoManager GtkSourceUndoManager; -typedef struct _GtkSourceUndoManagerClass GtkSourceUndoManagerClass; - -typedef struct _GtkSourceUndoManagerPrivate GtkSourceUndoManagerPrivate; - -struct _GtkSourceUndoManager -{ - GObject base; - - GtkSourceUndoManagerPrivate *priv; -}; - -struct _GtkSourceUndoManagerClass -{ - GObjectClass parent_class; - - /* Signals */ - void (*can_undo)(GtkSourceUndoManager *um, gboolean can_undo); - void (*can_redo)(GtkSourceUndoManager *um, gboolean can_redo); -}; - -GType gtk_source_undo_manager_get_type(void) G_GNUC_CONST; - -GtkSourceUndoManager* gtk_source_undo_manager_new(GtkTextBuffer *buffer); - -gboolean gtk_source_undo_manager_can_undo(const GtkSourceUndoManager *um); -gboolean gtk_source_undo_manager_can_redo(const GtkSourceUndoManager *um); - -void gtk_source_undo_manager_undo(GtkSourceUndoManager *um); -void gtk_source_undo_manager_redo(GtkSourceUndoManager *um); - -void gtk_source_undo_manager_begin_not_undoable_action(GtkSourceUndoManager *um); -void gtk_source_undo_manager_end_not_undoable_action(GtkSourceUndoManager *um); - -gint gtk_source_undo_manager_get_max_undo_levels(GtkSourceUndoManager *um); -void gtk_source_undo_manager_set_max_undo_levels(GtkSourceUndoManager *um, - gint undo_levels); - -G_END_DECLS - -#endif // UNDOVIEW_UNDO_MANAGER_H_ - diff --git a/third_party/undoview/undo_view.c b/third_party/undoview/undo_view.c deleted file mode 100644 index 03ea16a..0000000 --- a/third_party/undoview/undo_view.c +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Boilerplate code was generated by http://burtonini.com/cgi/gobject.py - -#include <gdk/gdkkeysyms.h> - -#include "undo_view.h" - -G_DEFINE_TYPE (GtkUndoView, gtk_undo_view, GTK_TYPE_TEXT_VIEW) - -static void -gtk_undo_view_dispose(GObject *object) { - GtkUndoView *uview = GTK_UNDO_VIEW(object); - - if(uview->undo_manager_) { - g_object_unref(G_OBJECT(uview->undo_manager_)); - uview->undo_manager_ = NULL; - } - G_OBJECT_CLASS(gtk_undo_view_parent_class)->dispose(object); -} - -static void -gtk_undo_view_undo(GtkUndoView *uview) { - if(gtk_source_undo_manager_can_undo(uview->undo_manager_)) - gtk_source_undo_manager_undo(uview->undo_manager_); -} - -static void -gtk_undo_view_redo(GtkUndoView *uview) { - if(gtk_source_undo_manager_can_redo(uview->undo_manager_)) - gtk_source_undo_manager_redo(uview->undo_manager_); -} - -static void -gtk_undo_view_class_init(GtkUndoViewClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkBindingSet *binding_set; - - g_signal_new("undo", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(GtkUndoViewClass, undo), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - g_signal_new("redo", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(GtkUndoViewClass, redo), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - klass->undo = gtk_undo_view_undo; - klass->redo = gtk_undo_view_redo; - - binding_set = gtk_binding_set_by_class(klass); - gtk_binding_entry_add_signal(binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0); - gtk_binding_entry_add_signal(binding_set, GDK_y, GDK_CONTROL_MASK, "redo", 0); - gtk_binding_entry_add_signal(binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0); - gtk_binding_entry_add_signal(binding_set, GDK_F14, 0, "undo", 0); - - object_class->dispose = gtk_undo_view_dispose; -} - -static void -gtk_undo_view_init(GtkUndoView *self) { -} - -GtkWidget* -gtk_undo_view_new(GtkTextBuffer *buffer) { - GtkWidget *ret = g_object_new(GTK_TYPE_UNDO_VIEW, "buffer", buffer, NULL); - GTK_UNDO_VIEW(ret)->undo_manager_ = gtk_source_undo_manager_new(GTK_TEXT_BUFFER(buffer)); - - return ret; -} - diff --git a/third_party/undoview/undo_view.h b/third_party/undoview/undo_view.h deleted file mode 100644 index 7fccf87..0000000 --- a/third_party/undoview/undo_view.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Boilerplate code was generated by http://burtonini.com/cgi/gobject.py - -#ifndef UNDOVIEW_UNDO_VIEW_H_ -#define UNDOVIEW_UNDO_VIEW_H_ - -#include <gtk/gtk.h> -#include "undo_manager.h" - -G_BEGIN_DECLS - -#define GTK_TYPE_UNDO_VIEW gtk_undo_view_get_type() - -#define GTK_UNDO_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_UNDO_VIEW, GtkUndoView)) - -#define GTK_UNDO_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_UNDO_VIEW, GtkUndoViewClass)) - -#define GTK_IS_UNDO_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_UNDO_VIEW)) - -#define GTK_IS_UNDO_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_UNDO_VIEW)) - -#define GTK_UNDO_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_UNDO_VIEW, GtkUndoViewClass)) - -typedef struct { - GtkTextView parent; - GtkSourceUndoManager *undo_manager_; -} GtkUndoView; - -typedef struct { - GtkTextViewClass parent_class; - - void (*undo)(GtkUndoView *); - void (*redo)(GtkUndoView *); -} GtkUndoViewClass; - -GType gtk_undo_view_get_type(void); - -GtkWidget* gtk_undo_view_new(GtkTextBuffer *buffer); - -G_END_DECLS - -#endif // UNDOVIEW_UNDO_VIEW_H_ diff --git a/third_party/undoview/undoview.gyp b/third_party/undoview/undoview.gyp deleted file mode 100644 index 424ffcb..0000000 --- a/third_party/undoview/undoview.gyp +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2010 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'undoview', - 'type': 'static_library', - 'sources': [ - 'undo_manager.h', - 'undo_manager.c', - 'undo_view.h', - 'undo_view.c', - ], - - 'dependencies' : [ - '../../build/linux/system.gyp:gtk', - ], - }, - ], -} |