2008-12-30 19:01:12 +00:00
|
|
|
/**
|
|
|
|
* $Id:
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2004 Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
#include "BKE_blender.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_object.h"
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
#include "BKE_text.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_editVert.h"
|
|
|
|
#include "BLI_dynstr.h"
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
2009-01-24 13:45:24 +00:00
|
|
|
#include "ED_armature.h"
|
2009-02-20 20:39:27 +00:00
|
|
|
#include "ED_particle.h"
|
2009-01-24 13:45:24 +00:00
|
|
|
#include "ED_curve.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
#include "ED_mesh.h"
|
2009-01-24 13:45:24 +00:00
|
|
|
#include "ED_object.h"
|
2008-12-31 18:52:15 +00:00
|
|
|
#include "ED_screen.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "ED_sculpt.h"
|
2008-12-31 18:52:15 +00:00
|
|
|
#include "ED_util.h"
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
#include "ED_text.h"
|
2008-12-31 18:52:15 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
/* ***************** generic undo system ********************* */
|
|
|
|
|
|
|
|
/* ********* XXX **************** */
|
|
|
|
static void undo_push_mball() {}
|
|
|
|
static void sound_initialize_sounds() {}
|
|
|
|
/* ********* XXX **************** */
|
|
|
|
|
|
|
|
void ED_undo_push(bContext *C, char *str)
|
|
|
|
{
|
2009-02-18 13:29:54 +00:00
|
|
|
wmWindowManager *wm= CTX_wm_manager(C);
|
2009-01-02 19:10:35 +00:00
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
|
|
|
|
|
|
|
if(obedit) {
|
2008-12-30 19:01:12 +00:00
|
|
|
if (U.undosteps == 0) return;
|
|
|
|
|
2009-01-02 19:10:35 +00:00
|
|
|
if(obedit->type==OB_MESH)
|
2009-01-01 13:15:35 +00:00
|
|
|
undo_push_mesh(C, str);
|
2009-01-02 19:10:35 +00:00
|
|
|
else if ELEM(obedit->type, OB_CURVE, OB_SURF)
|
2009-01-24 13:45:24 +00:00
|
|
|
undo_push_curve(C, str);
|
2009-01-02 19:10:35 +00:00
|
|
|
else if (obedit->type==OB_FONT)
|
2009-01-24 13:45:24 +00:00
|
|
|
undo_push_font(C, str);
|
2009-01-02 19:10:35 +00:00
|
|
|
else if (obedit->type==OB_MBALL)
|
2008-12-30 19:01:12 +00:00
|
|
|
undo_push_mball(str);
|
2009-01-02 19:10:35 +00:00
|
|
|
else if (obedit->type==OB_LATTICE)
|
2009-01-24 13:45:24 +00:00
|
|
|
undo_push_lattice(C, str);
|
2009-01-02 19:10:35 +00:00
|
|
|
else if (obedit->type==OB_ARMATURE)
|
2009-01-24 13:45:24 +00:00
|
|
|
undo_push_armature(C, str);
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
else if(G.f & G_PARTICLEEDIT) {
|
|
|
|
if (U.undosteps == 0) return;
|
|
|
|
|
2009-01-24 13:45:24 +00:00
|
|
|
PE_undo_push(CTX_data_scene(C), str);
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(U.uiflag & USER_GLOBALUNDO)
|
|
|
|
BKE_write_undo(C, str);
|
|
|
|
}
|
2009-02-18 13:29:54 +00:00
|
|
|
|
|
|
|
if(wm->file_saved) {
|
|
|
|
wm->file_saved= 0;
|
|
|
|
WM_event_add_notifier(C, NC_WM|ND_DATACHANGED, NULL);
|
|
|
|
}
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
void ED_undo_push_op(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
/* in future, get undo string info? */
|
|
|
|
ED_undo_push(C, op->type->name);
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:52:16 +00:00
|
|
|
static int ed_undo_step(bContext *C, int step)
|
2008-12-30 19:01:12 +00:00
|
|
|
{
|
2009-01-02 19:10:35 +00:00
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
2008-12-30 19:01:12 +00:00
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
if(sa && sa->spacetype==SPACE_TEXT) {
|
|
|
|
ED_text_undo_step(C, step);
|
|
|
|
}
|
|
|
|
else if(obedit) {
|
2009-01-02 19:10:35 +00:00
|
|
|
if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
|
2009-01-01 13:15:35 +00:00
|
|
|
undo_editmode_step(C, step);
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-01 13:15:35 +00:00
|
|
|
int do_glob_undo= 0;
|
|
|
|
|
2008-12-30 19:01:12 +00:00
|
|
|
if(G.f & G_TEXTUREPAINT)
|
2009-01-01 13:15:35 +00:00
|
|
|
undo_imagepaint_step(step);
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
else if(sa && sa->spacetype==SPACE_IMAGE) {
|
2008-12-30 19:01:12 +00:00
|
|
|
SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
|
|
|
|
if(sima->flag & SI_DRAWTOOL)
|
2009-01-01 13:15:35 +00:00
|
|
|
undo_imagepaint_step(step);
|
|
|
|
else
|
|
|
|
do_glob_undo= 1;
|
|
|
|
}
|
|
|
|
else if(G.f & G_PARTICLEEDIT) {
|
|
|
|
if(step==1)
|
2009-01-24 13:45:24 +00:00
|
|
|
PE_undo(CTX_data_scene(C));
|
2008-12-30 19:01:12 +00:00
|
|
|
else
|
2009-01-24 13:45:24 +00:00
|
|
|
PE_redo(CTX_data_scene(C));
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-01 13:15:35 +00:00
|
|
|
do_glob_undo= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(do_glob_undo) {
|
|
|
|
if(U.uiflag & USER_GLOBALUNDO) {
|
|
|
|
#ifndef DISABLE_PYTHON
|
|
|
|
// XXX BPY_scripts_clear_pyobjects();
|
|
|
|
#endif
|
|
|
|
BKE_undo_step(C, step);
|
|
|
|
sound_initialize_sounds();
|
|
|
|
}
|
|
|
|
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-31 18:52:15 +00:00
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 11:52:16 +00:00
|
|
|
void ED_undo_pop(bContext *C)
|
|
|
|
{
|
|
|
|
ed_undo_step(C, 1);
|
|
|
|
}
|
2009-04-15 17:53:12 +00:00
|
|
|
void ED_undo_redo(bContext *C)
|
|
|
|
{
|
|
|
|
ed_undo_step(C, -1);
|
|
|
|
}
|
2009-02-04 11:52:16 +00:00
|
|
|
|
2009-01-01 13:15:35 +00:00
|
|
|
static int ed_undo_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2009-02-04 11:52:16 +00:00
|
|
|
return ed_undo_step(C, 1);
|
2009-01-01 13:15:35 +00:00
|
|
|
}
|
2008-12-31 18:52:15 +00:00
|
|
|
static int ed_redo_exec(bContext *C, wmOperator *op)
|
2008-12-30 19:01:12 +00:00
|
|
|
{
|
2009-02-04 11:52:16 +00:00
|
|
|
return ed_undo_step(C, -1);
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ED_undo_menu(bContext *C)
|
|
|
|
{
|
2009-01-02 19:10:35 +00:00
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
|
|
|
|
|
|
|
if(obedit) {
|
|
|
|
//if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
|
2008-12-31 18:52:15 +00:00
|
|
|
// undo_editmode_menu();
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(G.f & G_PARTICLEEDIT)
|
2009-02-20 20:39:27 +00:00
|
|
|
PE_undo_menu(CTX_data_scene(C), CTX_data_active_object(C));
|
2008-12-30 19:01:12 +00:00
|
|
|
else if(U.uiflag & USER_GLOBALUNDO) {
|
|
|
|
char *menu= BKE_undo_menu_string();
|
|
|
|
if(menu) {
|
|
|
|
short event= 0; // XXX pupmenu_col(menu, 20);
|
|
|
|
MEM_freeN(menu);
|
|
|
|
if(event>0) {
|
|
|
|
BKE_undo_number(C, event);
|
|
|
|
sound_initialize_sounds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
/* ********************** */
|
|
|
|
|
|
|
|
void ED_OT_undo(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Undo";
|
|
|
|
ot->idname= "ED_OT_undo";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= ed_undo_exec;
|
|
|
|
ot->poll= ED_operator_screenactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_OT_redo(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Redo";
|
|
|
|
ot->idname= "ED_OT_redo";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= ed_redo_exec;
|
|
|
|
ot->poll= ED_operator_screenactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
|