operator macro playback (run operator reports in the console)
authorCampbell Barton <ideasman42@gmail.com>
Sun, 19 Jul 2009 00:49:44 +0000 (00:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 19 Jul 2009 00:49:44 +0000 (00:49 +0000)
- reports can be selected with RMB, Border (bkey) and (de)select all.
- delete reports (X key)
- run operators in the console (R key)
- copy reports (Ctrl+C), can be pasted in the text editor an run with alt+p

Details
- Added "selected_editable_objects" and "selected_editable_bases" to screen_context.c, use the scene layers, this was needed for duplicate to run outside the 3D view.
- RNA_property_as_string converted an array of 1 into "(num)" need a comma so python sees it as a tuple - "(num,)"
- add flag to reports, use for seletion atm.

opens a new world of context bugs :)

15 files changed:
release/ui/space_console.py
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/object.c
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_edit.c
source/blender/editors/screen/screen_context.c
source/blender/editors/space_console/console_draw.c
source/blender/editors/space_console/console_intern.h
source/blender/editors/space_console/console_ops.c
source/blender/editors/space_console/console_report.c [new file with mode: 0644]
source/blender/editors/space_console/space_console.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/intern/rna_access.c

index b92e3b7d51c67033e39dfa4a3595ed56d5cbc57c..189943520346615d2d112c4c00071e60b316cbec 100644 (file)
@@ -15,19 +15,29 @@ class CONSOLE_HT_header(bpy.types.Header):
 
                layout.template_header()
 
-               if context.area.show_menus:
-                       row = layout.row()
-                       row.itemM("CONSOLE_MT_console")
-               
                row = layout.row()
-               row.scale_x = 0.9
                row.itemR(sc, "type", expand=True)
+
                if sc.type == 'REPORT':
-                       row.itemR(sc, "show_report_debug")
-                       row.itemR(sc, "show_report_info")
-                       row.itemR(sc, "show_report_operator")
-                       row.itemR(sc, "show_report_warn")
-                       row.itemR(sc, "show_report_error")
+                       
+                       if context.area.show_menus:
+                               row = layout.row()
+                               row.itemM("CONSOLE_MT_report")
+                       
+                       row.itemR(sc, "show_report_debug", text="Debug")
+                       row.itemR(sc, "show_report_info", text="Info")
+                       row.itemR(sc, "show_report_operator", text="Operators")
+                       row.itemR(sc, "show_report_warn", text="Warnings")
+                       row.itemR(sc, "show_report_error", text="Errors")
+                       
+                       row = layout.row()
+                       row.enabled = sc.show_report_operator
+                       row.itemO("console.report_replay")
+               
+               else:
+                       if context.area.show_menus:
+                               row = layout.row()
+                               row.itemM("CONSOLE_MT_console")
 
 
 class CONSOLE_MT_console(bpy.types.Menu):
@@ -41,6 +51,20 @@ class CONSOLE_MT_console(bpy.types.Menu):
                layout.column()
                layout.itemO("console.clear")
 
+class CONSOLE_MT_report(bpy.types.Menu):
+       __space_type__ = "CONSOLE"
+       __label__ = "Report"
+
+       def draw(self, context):
+               layout = self.layout
+               sc = context.space_data
+
+               layout.column()
+               layout.itemO("console.select_all_toggle")
+               layout.itemO("console.select_border")
+               layout.itemO("console.report_delete")
+               layout.itemO("console.report_copy")
+
 def add_scrollback(text, text_type):
        for l in text.split('\n'):
                bpy.ops.console.scrollback_append(text=l.replace('\t', '    '), type=text_type)
@@ -97,7 +121,7 @@ class CONSOLE_OT_exec(bpy.types.Operator):
        Operator documentatuon text, will be used for the operator tooltip and python docs.
        '''
        __label__ = "Console Execute"
-       __register__ = True
+       __register__ = False
        
        # Both prompts must be the same length
        PROMPT = '>>> ' 
@@ -373,7 +397,7 @@ class CONSOLE_OT_autocomplete(bpy.types.Operator):
        Operator documentatuon text, will be used for the operator tooltip and python docs.
        '''
        __label__ = "Console Autocomplete"
-       __register__ = True
+       __register__ = False
        
        def poll(self, context):
                return context.space_data.type == 'PYTHON'
@@ -423,6 +447,7 @@ class CONSOLE_OT_autocomplete(bpy.types.Operator):
 
 bpy.types.register(CONSOLE_HT_header)
 bpy.types.register(CONSOLE_MT_console)
+bpy.types.register(CONSOLE_MT_report)
 
 bpy.ops.add(CONSOLE_OT_exec)
 bpy.ops.add(CONSOLE_OT_autocomplete)
index 5def910ddef28a7a4bd3da2f75c01c8af9f226da..22a471f65219c49481fcd792962b167925966e81 100644 (file)
@@ -101,7 +101,7 @@ void multiresModifier_join(Object *ob)
        /* First find the highest level of subdivision */
        base = FIRSTBASE;
        while(base) {
-               if(TESTBASELIB_BGMODE(base) && base->object->type==OB_MESH) {
+               if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
                        ModifierData *md;
                        for(md = base->object->modifiers.first; md; md = md->next) {
                                if(md->type == eModifierType_Multires) {
@@ -124,7 +124,7 @@ void multiresModifier_join(Object *ob)
        /* Subdivide all the displacements to the highest level */
        base = FIRSTBASE;
        while(base) {
-               if(TESTBASELIB_BGMODE(base) && base->object->type==OB_MESH) {
+               if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
                        ModifierData *md = NULL;
                        MultiresModifierData *mmd = NULL;
 
index b8ea042455f1f475fb19560ac3aee87b1952efb2..65043abe5181d63977d89f107e7422e0e7721149 100644 (file)
@@ -1323,7 +1323,18 @@ void make_local_object(Object *ob)
        expand_local_object(ob);
 }
 
-/* returns true if the Object data is a from an external blend file (libdata) */
+/*
+ * Returns true if the Object is a from an external blend file (libdata)
+ */
+int object_is_libdata(Object *ob)
+{
+       if (!ob) return 0;
+       if (ob->proxy) return 0;
+       if (ob->id.lib) return 1;
+       return 0;
+}
+
+/* Returns true if the Object data is a from an external blend file (libdata) */
 int object_data_is_libdata(Object *ob)
 {
        if(!ob) return 0;
index ab718aca81f494741bb09ec4f06e534c7b1e33ab..8d4819d2d71015385cbe0137811dc899939f4679 100644 (file)
@@ -70,6 +70,7 @@ void ED_object_enter_editmode(struct bContext *C, int flag);
 void ED_object_base_init_from_view(struct bContext *C, struct Base *base);
 
 /* cleanup */
+int object_is_libdata(struct Object *ob);
 int object_data_is_libdata(struct Object *ob);
 
 /* constraints */
index 26a8999947514639e51eb024434495376cd5a490..5ad41bd82f87ca2871d8043f951020cb48e090b4 100644 (file)
@@ -747,7 +747,7 @@ static void copy_object_set_idnew(Scene *scene, View3D *v3d, int dupflag)
        
        /* XXX check object pointers */
        for(base= FIRSTBASE; base; base= base->next) {
-               if(TESTBASELIB(v3d, base)) {
+               if(TESTBASELIB_BGMODE(v3d, base)) {
                        ob= base->object;
                        relink_constraints(&ob->constraints);
                        if (ob->pose){
index 1ea6f8baceb05e1e4a2b48989541b39fd0d21fff..e9a979aa134e5e87bd17d5037669ffa1f9b83832 100644 (file)
@@ -44,7 +44,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 
        if(CTX_data_dir(member)) {
                static const char *dir[] = {
-                       "scene", "selected_objects", "selected_bases", "active_base",
+                       "scene", "selected_objects", "selected_bases",
+                       "selected_editable_objects", "selected_editable_bases"
+                       "active_base",
                        "active_object", "edit_object", NULL};
 
                CTX_data_dir_set(result, dir);
@@ -68,6 +70,24 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 
                return 1;
        }
+       else if(CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
+               int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
+
+               for(base=scene->base.first; base; base=base->next) {
+                       if((base->flag & SELECT) && (base->lay & scene->lay)) {
+                               if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
+                                       if(0==object_is_libdata(base->object)) {
+                                               if(selected_editable_objects)
+                                                       CTX_data_id_list_add(result, &base->object->id);
+                                               else
+                                                       CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
+                                       }
+                               }
+                       }
+               }
+
+               return 1;
+       }
        else if(CTX_data_equals(member, "active_base")) {
                if(scene->basact)
                        CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, &scene->basact);
index 65e18beabbcb3d155ff6f0b36b97fcf94504f383..68cb1cc4a01057e2aec42139f72e371aeae13f96 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <limits.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -53,6 +54,8 @@
 #include "BIF_glutil.h"
 
 #include "ED_datafiles.h"
+#include "ED_types.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -89,7 +92,7 @@ static void console_line_color(unsigned char *fg, int type)
        }
 }
 
-static void console_report_color(unsigned char *fg, int type)
+static void console_report_color(unsigned char *fg, unsigned char *bg, Report *report, int bool)
 {
        /*
        if              (type & RPT_ERROR_ALL)          { fg[0]=220; fg[1]=0; fg[2]=0; }
@@ -99,8 +102,30 @@ static void console_report_color(unsigned char *fg, int type)
        else if (type & RPT_DEBUG_ALL)          { fg[0]=196; fg[1]=196; fg[2]=196; }
        else                                                            { fg[0]=196; fg[1]=196; fg[2]=196; }
        */
+       if(report->flag & SELECT) {
+               fg[0]=255; fg[1]=255; fg[2]=255;
+               if(bool) {
+                       bg[0]=96; bg[1]=128; bg[2]=255;
+               }
+               else {
+                       bg[0]=90; bg[1]=122; bg[2]=249;
+               }
+       }
+
+       else {
+               fg[0]=0; fg[1]=0; fg[2]=0;
+
+               if(bool) {
+                       bg[0]=120; bg[1]=120; bg[2]=120;
+               }
+               else {
+                       bg[0]=114; bg[1]=114; bg[2]=114;
+               }
+
+       }
+
+
 
-       fg[0]=0; fg[1]=0; fg[2]=0;
 }
 
 
@@ -180,14 +205,14 @@ static int console_draw_string(   char *str, int str_len,
 #define CONSOLE_DRAW_MARGIN 4
 #define CONSOLE_DRAW_SCROLL 16
 
-static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int draw)
+static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int draw, int mouse_y, void **mouse_pick)
 {
        View2D *v2d= &ar->v2d;
 
        ConsoleLine *cl= sc->history.last;
        
        int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
-       int x,y;
+       int x,y, y_prev;
        int cwidth;
        int console_width; /* number of characters that fit into the width of the console (fixed width) */
        unsigned char fg[3];
@@ -200,6 +225,10 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
        
        x= x_orig; y= y_orig;
        
+       if(mouse_y != INT_MAX)
+               mouse_y += (v2d->cur.ymin+CONSOLE_DRAW_MARGIN);
+
+
        if(sc->type==CONSOLE_TYPE_PYTHON) {
                int prompt_len;
                
@@ -228,6 +257,7 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
                y += sc->lheight;
                
                for(cl= sc->scrollback.last; cl; cl= cl->prev) {
+                       y_prev= y;
 
                        if(draw)
                                console_line_color(fg, cl->type);
@@ -235,7 +265,7 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
                        if(!console_draw_string(        cl->line, cl->len,
                                                                                console_width, sc->lheight,
                                                                                fg, NULL,
-                                                                               ar->winx-CONSOLE_DRAW_MARGIN,
+                                                                               ar->winx-(CONSOLE_DRAW_MARGIN+CONSOLE_DRAW_SCROLL),
                                                                                v2d->cur.ymin, v2d->cur.ymax,
                                                                                &x, &y, draw))
                        {
@@ -244,37 +274,39 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
                                        break; /* past the y limits */
                                }
                        }
+
+                       if((mouse_y != INT_MAX) && (mouse_y >= y_prev && mouse_y <= y)) {
+                               *mouse_pick= (void *)cl;
+                               break;
+                       }
                }
        }
        else { 
                Report *report;
                int report_mask= 0;
                int bool= 0;
-               unsigned char bg[3] = {114, 114, 114};
-               
+               unsigned char bg[3];
+
                if(draw) {
                        glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
                        glClear(GL_COLOR_BUFFER_BIT);
                }
 
                /* convert our display toggles into a flag compatible with BKE_report flags */
-               if(sc->rpt_mask & CONSOLE_RPT_DEBUG)    report_mask |= RPT_DEBUG_ALL;
-               if(sc->rpt_mask & CONSOLE_RPT_INFO)             report_mask |= RPT_INFO_ALL;
-               if(sc->rpt_mask & CONSOLE_RPT_OP)               report_mask |= RPT_OPERATOR_ALL;
-               if(sc->rpt_mask & CONSOLE_RPT_WARN)             report_mask |= RPT_WARNING_ALL;
-               if(sc->rpt_mask & CONSOLE_RPT_ERR)              report_mask |= RPT_ERROR_ALL;
+               report_mask= console_report_mask(sc);
                
                for(report=reports->list.last; report; report=report->prev) {
                        
                        if(report->type & report_mask) {
+                               y_prev= y;
 
                                if(draw)
-                                       console_report_color(fg, report->type);
+                                       console_report_color(fg, bg, report, bool);
 
                                if(!console_draw_string(        report->message, report->len,
                                                                                        console_width, sc->lheight,
-                                                                                       fg, bool?bg:NULL,
-                                                                                       ar->winx-CONSOLE_DRAW_MARGIN,
+                                                                                       fg, bg,
+                                                                                       ar->winx-(CONSOLE_DRAW_MARGIN+CONSOLE_DRAW_SCROLL),
                                                                                        v2d->cur.ymin, v2d->cur.ymax,
                                                                                        &x, &y, draw))
                                {
@@ -283,6 +315,10 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
                                                break; /* past the y limits */
                                        }
                                }
+                               if((mouse_y != INT_MAX) && (mouse_y >= y_prev && mouse_y <= y)) {
+                                       *mouse_pick= (void *)report;
+                                       break;
+                               }
 
                                bool = !(bool);
                        }
@@ -296,10 +332,17 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
 
 void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
 {
-       console_text_main__internal(sc, ar, reports, 1);
+       console_text_main__internal(sc, ar, reports, 1,  INT_MAX, NULL);
 }
 
 int console_text_height(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
 {
-       return console_text_main__internal(sc, ar, reports, 0);
+       return console_text_main__internal(sc, ar, reports, 0,  INT_MAX, NULL);
+}
+
+void *console_text_pick(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int mouse_y)
+{
+       void *mouse_pick= NULL;
+       console_text_main__internal(sc, ar, reports, 0, mouse_y, &mouse_pick);
+       return (void *)mouse_pick;
 }
index 0a911fb546a9c80f4b7baa846b9c8c40b23aa6a1..3c6eeb63505e6885b114611ba505fb4f644bd244 100644 (file)
@@ -40,6 +40,7 @@ struct ReportList;
 /* console_draw.c */
 void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, struct ReportList *reports);
 int console_text_height(struct SpaceConsole *sc, struct ARegion *ar, struct ReportList *reports); /* needed to calculate the scrollbar */
+void *console_text_pick(struct SpaceConsole *sc, struct ARegion *ar, struct ReportList *reports, int mouse_y); /* needed for selection */
 
 /* console_ops.c */
 void console_history_free(SpaceConsole *sc, ConsoleLine *cl);
@@ -49,6 +50,8 @@ ConsoleLine *console_scrollback_add_str(const bContext *C, char *str, int own);
 
 ConsoleLine *console_history_verify(const bContext *C);
 
+int console_report_mask(SpaceConsole *sc);
+
 
 void CONSOLE_OT_move(wmOperatorType *ot);
 void CONSOLE_OT_delete(wmOperatorType *ot);
@@ -61,9 +64,16 @@ void CONSOLE_OT_clear(wmOperatorType *ot);
 void CONSOLE_OT_history_cycle(wmOperatorType *ot);
 void CONSOLE_OT_zoom(wmOperatorType *ot);
 
-/* DUMMY OPS. python will replace */
-void CONSOLE_OT_exec(wmOperatorType *ot);
-void CONSOLE_OT_autocomplete(wmOperatorType *ot);
+/* console_report.c */
+void CONSOLE_OT_select_pick(wmOperatorType *ot); /* report selection */
+void CONSOLE_OT_select_all_toggle(wmOperatorType *ot);
+void CONSOLE_OT_select_border(wmOperatorType *ot);
+
+void CONSOLE_OT_report_replay(wmOperatorType *ot);
+void CONSOLE_OT_report_delete(wmOperatorType *ot);
+void CONSOLE_OT_report_copy(wmOperatorType *ot);
+
+
 
 enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD };
 enum { DEL_ALL, DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_SELECTION, DEL_NEXT_SEL, DEL_PREV_SEL };
index 359202ba022dd8da380fa3dcf5099dd993fa5e83..ca6e3983eacb24fe9304af6efb77b8f557fdd74f 100644 (file)
@@ -22,7 +22,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Campbell Barton
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
-// #include "BKE_suggestions.h"
-//#include "BKE_text.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "ED_screen.h"
+#include "ED_types.h"
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -210,8 +209,8 @@ static int console_edit_poll(bContext *C)
        return 1;
 }
 
-/* static funcs for text editing */
 
+/* static funcs for text editing */
 
 /* similar to the text editor, with some not used. keep compatible */
 static EnumPropertyItem move_type_items[]= {
@@ -579,17 +578,3 @@ void CONSOLE_OT_zoom(wmOperatorType *ot)
        /* properties */
        RNA_def_int(ot->srna, "delta", 0, 0, INT_MAX, "Delta", "Scale the view font.", 0, 1000);
 }
-
-/* Dummy operators, python will replace these, so blender can start without any errors */
-void CONSOLE_OT_exec(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "CONSOLE_OT_exec dummy";
-       ot->idname= "CONSOLE_OT_exec";
-}
-void CONSOLE_OT_autocomplete(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "CONSOLE_OT_autocomplete dummy";
-       ot->idname= "CONSOLE_OT_autocomplete";
-}
diff --git a/source/blender/editors/space_console/console_report.c b/source/blender/editors/space_console/console_report.c
new file mode 100644 (file)
index 0000000..9707af5
--- /dev/null
@@ -0,0 +1,414 @@
+/**
+ * $Id: console_ops.c 21679 2009-07-18 16:27:25Z campbellbarton $
+ *
+ * ***** 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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_dynstr.h"
+#include "PIL_time.h"
+
+#include "BKE_utildefines.h"
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_types.h"
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "console_intern.h"
+
+int console_report_mask(SpaceConsole *sc)
+{
+       int report_mask = 0;
+
+       if(sc->rpt_mask & CONSOLE_RPT_DEBUG)    report_mask |= RPT_DEBUG_ALL;
+       if(sc->rpt_mask & CONSOLE_RPT_INFO)             report_mask |= RPT_INFO_ALL;
+       if(sc->rpt_mask & CONSOLE_RPT_OP)               report_mask |= RPT_OPERATOR_ALL;
+       if(sc->rpt_mask & CONSOLE_RPT_WARN)             report_mask |= RPT_WARNING_ALL;
+       if(sc->rpt_mask & CONSOLE_RPT_ERR)              report_mask |= RPT_ERROR_ALL;
+
+       return report_mask;
+}
+
+static int console_report_poll(bContext *C)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+
+       if(!sc || sc->type != CONSOLE_TYPE_REPORT)
+               return 0;
+
+       return 1;
+}
+
+static int report_replay_exec(bContext *C, wmOperator *op)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ReportList *reports= CTX_wm_reports(C);
+       int report_mask= console_report_mask(sc);
+       Report *report;
+
+       sc->type= CONSOLE_TYPE_PYTHON;
+
+       for(report=reports->list.last; report; report=report->prev) {
+               if((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL) && (report->flag & SELECT)) {
+                       console_history_add_str(C, report->message, 0);
+                       WM_operator_name_call(C, "CONSOLE_OT_exec", WM_OP_EXEC_DEFAULT, NULL);
+
+                       ED_area_tag_redraw(CTX_wm_area(C));
+               }
+       }
+
+       sc->type= CONSOLE_TYPE_REPORT;
+
+       ED_area_tag_redraw(CTX_wm_area(C));
+
+       return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_report_replay(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Replay Operators";
+       ot->idname= "CONSOLE_OT_report_replay";
+
+       /* api callbacks */
+       ot->poll= console_report_poll;
+       ot->exec= report_replay_exec;
+
+       /* flags */
+       /* ot->flag= OPTYPE_REGISTER; */
+
+       /* properties */
+}
+
+static int select_report_pick_exec(bContext *C, wmOperator *op)
+{
+       int report_index= RNA_int_get(op->ptr, "report_index");
+       Report *report= BLI_findlink(&CTX_wm_reports(C)->list, report_index);
+
+       if(!report)
+               return OPERATOR_CANCELLED;
+
+       report->flag ^= SELECT; /* toggle */
+
+       ED_area_tag_redraw(CTX_wm_area(C));
+
+       return OPERATOR_FINISHED;
+}
+
+static int select_report_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ARegion *ar= CTX_wm_region(C);
+       ReportList *reports= CTX_wm_reports(C);
+       Report *report;
+
+       report= console_text_pick(sc, ar, reports, event->mval[1]);
+
+       RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
+
+       return select_report_pick_exec(C, op);
+}
+
+
+void CONSOLE_OT_select_pick(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select report";
+       ot->idname= "CONSOLE_OT_select_pick";
+
+       /* api callbacks */
+       ot->poll= console_report_poll;
+       ot->invoke= select_report_pick_invoke;
+       ot->exec= select_report_pick_exec;
+
+       /* flags */
+       /* ot->flag= OPTYPE_REGISTER; */
+
+       /* properties */
+       RNA_def_int(ot->srna, "report_index", 0, 0, INT_MAX, "Report", "The index of the report.", 0, INT_MAX);
+}
+
+
+
+static int report_select_all_toggle_exec(bContext *C, wmOperator *op)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ReportList *reports= CTX_wm_reports(C);
+       int report_mask= console_report_mask(sc);
+       int deselect= 0;
+
+       Report *report;
+
+       for(report=reports->list.last; report; report=report->prev) {
+               if((report->type & report_mask) && (report->flag & SELECT)) {
+                       deselect= 1;
+                       break;
+               }
+       }
+
+
+       if(deselect) {
+               for(report=reports->list.last; report; report=report->prev)
+                       if(report->type & report_mask)
+                               report->flag &= ~SELECT;
+       }
+       else {
+               for(report=reports->list.last; report; report=report->prev)
+                       if(report->type & report_mask)
+                               report->flag |= SELECT;
+       }
+
+       ED_area_tag_redraw(CTX_wm_area(C));
+
+       return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_select_all_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "(De)Select All";
+       ot->idname= "CONSOLE_OT_select_all_toggle";
+
+       /* api callbacks */
+       ot->poll= console_report_poll;
+       ot->exec= report_select_all_toggle_exec;
+
+       /* flags */
+       /*ot->flag= OPTYPE_REGISTER;*/
+
+       /* properties */
+}
+
+/* borderselect operator */
+static int borderselect_exec(bContext *C, wmOperator *op)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ARegion *ar= CTX_wm_region(C);
+       ReportList *reports= CTX_wm_reports(C);
+       int report_mask= console_report_mask(sc);
+       Report *report_min, *report_max, *report;
+
+       //View2D *v2d= UI_view2d_fromcontext(C);
+
+
+       rcti rect;
+       //rctf rectf, rq;
+       int val;
+       //short mval[2];
+
+       val= RNA_int_get(op->ptr, "event_type");
+       rect.xmin= RNA_int_get(op->ptr, "xmin");
+       rect.ymin= RNA_int_get(op->ptr, "ymin");
+       rect.xmax= RNA_int_get(op->ptr, "xmax");
+       rect.ymax= RNA_int_get(op->ptr, "ymax");
+
+       /*
+       mval[0]= rect.xmin;
+       mval[1]= rect.ymin;
+       UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
+       mval[0]= rect.xmax;
+       mval[1]= rect.ymax;
+       UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
+*/
+
+       report_min= console_text_pick(sc, ar, reports, rect.ymax);
+       report_max= console_text_pick(sc, ar, reports, rect.ymin);
+
+       /* get the first report if none found */
+       if(report_min==NULL) {
+               printf("find_min\n");
+               for(report=reports->list.first; report; report=report->next) {
+                       if(report->type & report_mask) {
+                               report_min= report;
+                               break;
+                       }
+               }
+       }
+
+       if(report_max==NULL) {
+               printf("find_max\n");
+               for(report=reports->list.last; report; report=report->prev) {
+                       if(report->type & report_mask) {
+                               report_max= report;
+                               break;
+                       }
+               }
+       }
+
+       if(report_min==NULL || report_max==NULL)
+               return OPERATOR_CANCELLED;
+
+       for(report= report_min; (report != report_max->next); report= report->next) {
+
+               if((report->type & report_mask)==0)
+                       continue;
+
+               if(val==LEFTMOUSE)      report->flag |= SELECT;
+               else                            report->flag &= ~SELECT;
+       }
+
+       ED_area_tag_redraw(CTX_wm_area(C));
+
+       return OPERATOR_FINISHED;
+}
+
+
+/* ****** Border Select ****** */
+void CONSOLE_OT_select_border(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Border Select";
+       ot->idname= "CONSOLE_OT_select_border";
+
+       /* api callbacks */
+       ot->invoke= WM_border_select_invoke;
+       ot->exec= borderselect_exec;
+       ot->modal= WM_border_select_modal;
+
+       ot->poll= console_report_poll;
+
+       /* flags */
+       /* ot->flag= OPTYPE_REGISTER; */
+
+       /* rna */
+       RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
+}
+
+
+
+static int report_delete_exec(bContext *C, wmOperator *op)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ReportList *reports= CTX_wm_reports(C);
+       int report_mask= console_report_mask(sc);
+
+
+       Report *report, *report_next;
+
+       for(report=reports->list.first; report; ) {
+
+               report_next=report->next;
+
+               if((report->type & report_mask) && (report->flag & SELECT)) {
+                       BLI_remlink(&reports->list, report);
+                       MEM_freeN(report->message);
+                       MEM_freeN(report);
+               }
+
+               report= report_next;
+       }
+
+       ED_area_tag_redraw(CTX_wm_area(C));
+
+       return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_report_delete(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Delete Reports";
+       ot->idname= "CONSOLE_OT_report_delete";
+
+       /* api callbacks */
+       ot->poll= console_report_poll;
+       ot->exec= report_delete_exec;
+
+       /* flags */
+       /*ot->flag= OPTYPE_REGISTER;*/
+
+       /* properties */
+}
+
+
+static int report_copy_exec(bContext *C, wmOperator *op)
+{
+       SpaceConsole *sc= CTX_wm_space_console(C);
+       ReportList *reports= CTX_wm_reports(C);
+       int report_mask= console_report_mask(sc);
+
+       Report *report;
+
+       DynStr *buf_dyn= BLI_dynstr_new();
+       char *buf_str;
+
+       for(report=reports->list.first; report; report= report->next) {
+               if((report->type & report_mask) && (report->flag & SELECT)) {
+                       BLI_dynstr_append(buf_dyn, report->message);
+                       BLI_dynstr_append(buf_dyn, "\n");
+               }
+       }
+
+       buf_str= BLI_dynstr_get_cstring(buf_dyn);
+       BLI_dynstr_free(buf_dyn);
+
+       WM_clipboard_text_set(buf_str, 0);
+
+       MEM_freeN(buf_str);
+       return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_report_copy(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Copy Reports to Clipboard";
+       ot->idname= "CONSOLE_OT_report_copy";
+
+       /* api callbacks */
+       ot->poll= console_report_poll;
+       ot->exec= report_copy_exec;
+
+       /* flags */
+       /*ot->flag= OPTYPE_REGISTER;*/
+
+       /* properties */
+}
index 5551a303ead0959da6c045d49500ed18ff9a9575..763be0392dccbc06b8f8c015a17fcab644b6fa2a 100644 (file)
@@ -203,6 +203,7 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
 
 void console_operatortypes(void)
 {
+       /* console_ops.c */
        WM_operatortype_append(CONSOLE_OT_move);
        WM_operatortype_append(CONSOLE_OT_delete);
        WM_operatortype_append(CONSOLE_OT_insert);
@@ -211,14 +212,19 @@ void console_operatortypes(void)
        WM_operatortype_append(CONSOLE_OT_history_append); 
        WM_operatortype_append(CONSOLE_OT_scrollback_append);
        
-       
        WM_operatortype_append(CONSOLE_OT_clear); 
        WM_operatortype_append(CONSOLE_OT_history_cycle);
        WM_operatortype_append(CONSOLE_OT_zoom);
 
-       /* Dummy, defined in space_console.py */
-       WM_operatortype_append(CONSOLE_OT_exec);
-       WM_operatortype_append(CONSOLE_OT_autocomplete);
+
+       /* console_report.c */
+       WM_operatortype_append(CONSOLE_OT_select_pick);
+       WM_operatortype_append(CONSOLE_OT_select_all_toggle);
+       WM_operatortype_append(CONSOLE_OT_select_border);
+
+       WM_operatortype_append(CONSOLE_OT_report_replay);
+       WM_operatortype_append(CONSOLE_OT_report_delete);
+       WM_operatortype_append(CONSOLE_OT_report_copy);
 }
 
 void console_keymap(struct wmWindowManager *wm)
@@ -275,6 +281,21 @@ void console_keymap(struct wmWindowManager *wm)
        WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", RETKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */
 #endif
 
+       /* report selection */
+       WM_keymap_add_item(keymap, "CONSOLE_OT_select_pick", SELECTMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CONSOLE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CONSOLE_OT_select_border", BKEY, KM_PRESS, 0, 0);
+
+       WM_keymap_add_item(keymap, "CONSOLE_OT_report_replay", RKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CONSOLE_OT_report_delete", XKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CONSOLE_OT_report_delete", DELKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CONSOLE_OT_report_copy", CKEY, KM_PRESS, KM_CTRL, 0);
+
+
+
+
+
+
        RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", "    "); /* fake tabs */
        WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_PRESS, KM_ANY, 0); // last!
 }
index 387468f716040ed3e6f81f54e57ac181fdad2f76..a8abdf4132ec14ea5bfdeaf7b1c47916b958379c 100644 (file)
@@ -591,24 +591,12 @@ static void view3d_tools_area_draw(const bContext *C, ARegion *ar)
        ED_region_panels(C, ar, 1, view3d_context_string(C));
 }
 
-/*
- * Returns true if the Object is a from an external blend file (libdata)
- */
-static int object_is_libdata(Object *ob)
-{
-       if (!ob) return 0;
-       if (ob->proxy) return 0;
-       if (ob->id.lib) return 1;
-       return 0;
-}
-
 static int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
 {
        View3D *v3d= CTX_wm_view3d(C);
        Scene *scene= CTX_data_scene(C);
        Base *base;
-
-       if(v3d==NULL) return 0;
+       int lay = v3d ? v3d->lay:scene->lay; /* fallback to the scene layer, allows duplicate and other oject operators to run outside the 3d view */
 
        if(CTX_data_dir(member)) {
                static const char *dir[] = {
@@ -624,7 +612,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
                int selected_objects= CTX_data_equals(member, "selected_objects");
 
                for(base=scene->base.first; base; base=base->next) {
-                       if((base->flag & SELECT) && (base->lay & v3d->lay)) {
+                       if((base->flag & SELECT) && (base->lay & lay)) {
                                if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
                                        if(selected_objects)
                                                CTX_data_id_list_add(result, &base->object->id);
@@ -640,7 +628,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
                int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
 
                for(base=scene->base.first; base; base=base->next) {
-                       if((base->flag & SELECT) && (base->lay & v3d->lay)) {
+                       if((base->flag & SELECT) && (base->lay & lay)) {
                                if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
                                        if(0==object_is_libdata(base->object)) {
                                                if(selected_editable_objects)
@@ -658,7 +646,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
                int visible_objects= CTX_data_equals(member, "visible_objects");
 
                for(base=scene->base.first; base; base=base->next) {
-                       if(base->lay & v3d->lay) {
+                       if(base->lay & lay) {
                                if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
                                        if(visible_objects)
                                                CTX_data_id_list_add(result, &base->object->id);
@@ -674,7 +662,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
                int selectable_objects= CTX_data_equals(member, "selectable_objects");
 
                for(base=scene->base.first; base; base=base->next) {
-                       if(base->lay & v3d->lay) {
+                       if(base->lay & lay) {
                                if((base->object->restrictflag & OB_RESTRICT_VIEW)==0 && (base->object->restrictflag & OB_RESTRICT_SELECT)==0) {
                                        if(selectable_objects)
                                                CTX_data_id_list_add(result, &base->object->id);
@@ -687,14 +675,14 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
                return 1;
        }
        else if(CTX_data_equals(member, "active_base")) {
-               if(scene->basact && (scene->basact->lay & v3d->lay))
+               if(scene->basact && (scene->basact->lay & lay))
                        if((scene->basact->object->restrictflag & OB_RESTRICT_VIEW)==0)
                                CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, scene->basact);
                
                return 1;
        }
        else if(CTX_data_equals(member, "active_object")) {
-               if(scene->basact && (scene->basact->lay & v3d->lay))
+               if(scene->basact && (scene->basact->lay & lay))
                        if((scene->basact->object->restrictflag & OB_RESTRICT_VIEW)==0)
                                CTX_data_id_pointer_set(result, &scene->basact->object->id);
                
index b21b127554f8b4fc912172f5f0049e789c09068f..572913f10d0a833369c7e19b6f0dfacbaa8c0498 100644 (file)
@@ -801,7 +801,7 @@ typedef struct Scene {
 /* depricate this! */
 #define TESTBASE(v3d, base)    ( ((base)->flag & SELECT) && ((base)->lay & v3d->lay) && (((base)->object->restrictflag & OB_RESTRICT_VIEW)==0) )
 #define TESTBASELIB(v3d, base) ( ((base)->flag & SELECT) && ((base)->lay & v3d->lay) && ((base)->object->id.lib==0) && (((base)->object->restrictflag & OB_RESTRICT_VIEW)==0))
-#define TESTBASELIB_BGMODE(base)   ( ((base)->flag & SELECT) && ((base)->lay & (v3d ? v3d->lay : scene->lay)) && ((base)->object->id.lib==0) && (((base)->object->restrictflag & OB_RESTRICT_VIEW)==0))
+#define TESTBASELIB_BGMODE(v3d, base)   ( ((base)->flag & SELECT) && ((base)->lay & (v3d ? v3d->lay : scene->lay)) && ((base)->object->id.lib==0) && (((base)->object->restrictflag & OB_RESTRICT_VIEW)==0))
 #define BASE_SELECTABLE(v3d, base)      ((base->lay & v3d->lay) && (base->object->restrictflag & (OB_RESTRICT_SELECT|OB_RESTRICT_VIEW))==0)
 #define FIRSTBASE              scene->base.first
 #define LASTBASE               scene->base.last
index 126b6c47b63572563e0776dfed18195dec4dc215..9d36882058e5b36f128a334e782321c6212c7183 100644 (file)
@@ -77,7 +77,8 @@ enum ReportListFlags {
 };
 typedef struct Report {
        struct Report *next, *prev;
-       int type; /* ReportType */
+       short type; /* ReportType */
+       short flag;
        int len; /* strlen(message), saves some time calculating the word wrap  */
        char *typestr;
        char *message;
index b55df31640f7fdbc2aa6ce225c0beb54ef70c0d1..d9d4852a72cf3d5fa1904fcfd4164bb366f855b6 100644 (file)
@@ -2647,6 +2647,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %s":"%s", RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;
@@ -2659,6 +2661,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;
@@ -2671,6 +2675,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;