- console remove doubles with command history
authorCampbell Barton <ideasman42@gmail.com>
Wed, 29 Jul 2009 00:37:37 +0000 (00:37 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 29 Jul 2009 00:37:37 +0000 (00:37 +0000)
- povray file removal was uncommented

release/io/engine_render_pov.py
release/ui/space_console.py
source/blender/editors/space_console/console_ops.c

index 31fa9f17e9584b06dc8394cf91752661abe7702e..186118246b8656e89bf94116d6687b8d016fcd53 100644 (file)
@@ -502,9 +502,8 @@ class PovrayRenderEngine(bpy.types.RenderEngine):
        
        def _cleanup(self):
                for f in (self.temp_file_in, self.temp_file_ini, self.temp_file_out):
-                       #try:           os.remove(f)
-                       #except:        pass
-                       pass
+                       try:            os.remove(f)
+                       except: pass
                
                self.update_stats("", "")
        
index 264203d74e561869279ad0f9922739d697d7c8c3..a5662fa3db311e9c1b4bd25e13e7f2edf47b12ae 100644 (file)
@@ -182,7 +182,7 @@ class CONSOLE_OT_exec(bpy.types.Operator):
                else:                           sc.prompt = self.PROMPT
                
                # insert a new blank line
-               bpy.ops.console.history_append(text="", current_character=0)
+               bpy.ops.console.history_append(text="", current_character=0, remove_duplicates= True)
                
                # Insert the output into the editor
                # not quite correct because the order might have changed, but ok 99% of the time.
index 37f16f3d88a25343812098c0e8c9ae3d7e21a8e6..2637a4fb1a9b11575b1b229b32d87a6f5dd9fde8 100644 (file)
@@ -88,6 +88,21 @@ void console_scrollback_limit(SpaceConsole *sc)
                console_scrollback_free(sc, sc->scrollback.first);
 }
 
+static ConsoleLine * console_history_find(SpaceConsole *sc, const char *str, ConsoleLine *cl_ignore)
+{
+       ConsoleLine *cl;
+
+       for(cl= sc->history.last; cl; cl= cl->prev) {
+               if (cl==cl_ignore)
+                       continue;
+
+               if(strcmp(str, cl->line)==0)
+                       return cl;
+       }
+
+       return NULL;
+}
+
 /* return 0 if no change made, clamps the range */
 static int console_line_cursor_set(ConsoleLine *cl, int cursor)
 {
@@ -476,11 +491,23 @@ void CONSOLE_OT_history_cycle(wmOperatorType *ot)
 static int history_append_exec(bContext *C, wmOperator *op)
 {
        ConsoleLine *ci= console_history_verify(C);
-       
-       
        char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
        int cursor= RNA_int_get(op->ptr, "current_character");
-       
+       short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
+
+       if(rem_dupes) {
+               SpaceConsole *sc= CTX_wm_space_console(C);
+               ConsoleLine *cl;
+
+               while((cl= console_history_find(sc, ci->line, ci)))
+                       console_history_free(sc, cl);
+
+               if(strcmp(str, ci->line)==0) {
+                       MEM_freeN(str);
+                       return OPERATOR_FINISHED;
+               }
+       }
+
        ci= console_history_add_str(C, str, 1); /* own the string */
        console_line_cursor_set(ci, cursor);
        
@@ -505,6 +532,7 @@ void CONSOLE_OT_history_append(wmOperatorType *ot)
        /* properties */
        RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");      
        RNA_def_int(ot->srna, "current_character", 0, 0, INT_MAX, "Cursor", "The index of the cursor.", 0, 10000);
+       RNA_def_boolean(ot->srna, "remove_duplicates", 0, "Remove Duplicates", "Remove duplicate items in the history");
 }