use ICON_NULL define rather then 0, makes UI calls less confusing. (no functional...
[blender.git] / source / blender / editors / space_text / text_header.c
index 83c144d88c53de7f40e8ea31db0d52f7c08b0226..8ad4d6fa89067f226e38b0c9ca0ed97d589d5004 100644 (file)
@@ -15,7 +15,7 @@
  *
  * 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.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008 Blender Foundation.
  * All rights reserved.
 #include "BLI_winstuff.h"
 #endif
 
-#include "DNA_space_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_text_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
 
 #include "BKE_context.h"
-#include "BKE_global.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_scene.h"
-#include "BKE_screen.h"
-#include "BKE_text.h"
 
 #include "ED_screen.h"
-#include "ED_types.h"
-#include "ED_util.h"
 
-#include "WM_api.h"
 #include "WM_types.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
 
-#include "UI_interface.h"
-#include "UI_resources.h"
-#include "UI_view2d.h"
 
-#include "RNA_access.h"
 
-#ifndef DISABLE_PYTHON
-#include "BPY_extern.h"
+#ifdef WITH_PYTHON
 // XXX #include "BPY_menus.h"
 #endif
 
 
 /* ************************ header area region *********************** */
 
-#ifndef DISABLE_PYTHON
-static void do_text_template_scriptsmenu(bContext *C, void *arg, int event)
-{
-       // XXX BPY_menu_do_python(PYMENU_SCRIPTTEMPLATE, event);
-}
-
-static uiBlock *text_template_scriptsmenu(bContext *C, void *args_unused)
-{
-       ARegion *ar= CTX_wm_region(C);
-       uiBlock *block;
-       // XXX BPyMenu *pym;
-       // int i= 0;
-       // short yco = 20, menuwidth = 120;
-       
-       block= uiBeginBlock(C, ar, "text_template_scriptsmenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_text_template_scriptsmenu, NULL);
-       
-       /* note that we acount for the N previous entries with i+20: */
-       /* XXX for (pym = BPyMenuTable[PYMENU_SCRIPTTEMPLATE]; pym; pym = pym->next, i++) {
-               
-               uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
-                                                NULL, 0.0, 0.0, 1, i, 
-                                                pym->tooltip?pym->tooltip:pym->filename);
-       }*/
-       
-       uiBlockSetDirection(block, UI_RIGHT);
-       uiTextBoundsBlock(block, 60);
-
-       uiEndBlock(C, block);
-       uiDrawBlock(C, block);
-       
-       return block;
-}
-
-static void do_text_plugin_scriptsmenu(bContext *C, void *arg, int event)
-{
-       // XXX BPY_menu_do_python(PYMENU_TEXTPLUGIN, event);
-}
-
-static uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused)
-{
-       ARegion *ar= CTX_wm_region(C);
-       uiBlock *block;
-       // XXX BPyMenu *pym;
-       // int i= 0;
-       // short yco = 20, menuwidth = 120;
-       
-       block= uiBeginBlock(C, ar, "text_plugin_scriptsmenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_text_plugin_scriptsmenu, NULL);
-       
-       /* note that we acount for the N previous entries with i+20: */
-       /* XXX for (pym = BPyMenuTable[PYMENU_TEXTPLUGIN]; pym; pym = pym->next, i++) {
-               
-               uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
-                                                NULL, 0.0, 0.0, 1, i, 
-                                                pym->tooltip?pym->tooltip:pym->filename);
-       }*/
-       
-       uiBlockSetDirection(block, UI_RIGHT);
-       uiTextBoundsBlock(block, 60);
-
-       uiEndBlock(C, block);
-       uiDrawBlock(C, block);
-
-       return block;
-}
-#endif
-
-static void text_editmenu_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemEnumO(layout, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP);
-       uiItemEnumO(layout, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM);
-}
-
-static void text_editmenu_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemO(layout, NULL, 0, "TEXT_OT_select_all");
-       uiItemO(layout, NULL, 0, "TEXT_OT_select_line");
-}
-
-static void text_editmenu_markermenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemO(layout, NULL, 0, "TEXT_OT_markers_clear");
-       uiItemO(layout, NULL, 0, "TEXT_OT_next_marker");
-       uiItemO(layout, NULL, 0, "TEXT_OT_previous_marker");
-}
-
-static void text_formatmenu(const bContext *C, Menu *menu)
-{
-       uiLayout *layout= menu->layout;
-
-       uiItemO(layout, NULL, 0, "TEXT_OT_indent");
-       uiItemO(layout, NULL, 0, "TEXT_OT_unindent");
-
-       uiItemS(layout);
-
-       uiItemO(layout, NULL, 0, "TEXT_OT_comment");
-       uiItemO(layout, NULL, 0, "TEXT_OT_uncomment");
-
-       uiItemS(layout);
-
-       uiItemMenuEnumO(layout, NULL, 0, "TEXT_OT_convert_whitespace", "type");
-}
-
-static void text_editmenu_to3dmenu(bContext *C, uiLayout *layout, void *arg_unused)
-{
-       uiItemBooleanO(layout, "One Object", 0, "TEXT_OT_to_3d_object", "split_lines", 0);
-       uiItemBooleanO(layout, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1);
-}
-
-static int text_menu_edit_poll(bContext *C)
-{
-       return (CTX_data_edit_text(C) != NULL);
-}
-
-static void text_editmenu(const bContext *C, Menu *menu)
-{
-       uiLayout *layout= menu->layout;
-
-       uiItemO(layout, NULL, 0, "ED_OT_undo");
-       uiItemO(layout, NULL, 0, "ED_OT_redo");
-
-       uiItemS(layout);
-
-       uiItemO(layout, NULL, 0, "TEXT_OT_cut");
-       uiItemO(layout, NULL, 0, "TEXT_OT_copy");
-       uiItemO(layout, NULL, 0, "TEXT_OT_paste");
-
-       uiItemS(layout);
-
-       uiItemMenuF(layout, "View", 0, text_editmenu_viewmenu);
-       uiItemMenuF(layout, "Select", 0, text_editmenu_selectmenu);
-       uiItemMenuF(layout, "Markers", 0, text_editmenu_markermenu);
-
-       uiItemS(layout);
-
-       uiItemO(layout, NULL, 0, "TEXT_OT_jump");
-       uiItemO(layout, NULL, 0, "TEXT_OT_properties");
-
-       uiItemS(layout);
-
-       uiItemMenuF(layout, "Text to 3D Object", 0, text_editmenu_to3dmenu);
-}
-
-/********************** header buttons ***********************/
-
-void text_header_register(ARegionType *art)
-{
-       MenuType *mt;
-
-       mt= MEM_callocN(sizeof(MenuType), "spacetype text menu edit");
-       strcpy(mt->idname, "TEXT_MT_edit");
-       strcpy(mt->label, "Edit");
-       mt->draw= text_editmenu;
-       BLI_addhead(&art->menutypes, mt);
-
-       mt= MEM_callocN(sizeof(MenuType), "spacetype text menu format");
-       strcpy(mt->idname, "TEXT_MT_format");
-       strcpy(mt->label, "Format");
-       mt->draw= text_formatmenu;
-       BLI_addhead(&art->menutypes, mt);
-}
-
 /************************** properties ******************************/
 
 ARegion *text_has_properties_region(ScrArea *sa)
@@ -281,24 +98,16 @@ ARegion *text_has_properties_region(ScrArea *sa)
 
 static int properties_poll(bContext *C)
 {
-       SpaceText *st= CTX_wm_space_text(C);
-       Text *text= CTX_data_edit_text(C);
-
-       return (st && text);
+       return (CTX_wm_space_text(C) != NULL);
 }
 
-static int properties_exec(bContext *C, wmOperator *op)
+static int properties_exec(bContext *C, wmOperator *UNUSED(op))
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= text_has_properties_region(sa);
        
-       if(ar) {
-               ar->flag ^= RGN_FLAG_HIDDEN;
-               ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
-               
-               ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
-               ED_area_tag_redraw(sa);
-       }
+       if(ar)
+               ED_region_toggle_hidden(C, ar);
 
        return OPERATOR_FINISHED;
 }
@@ -307,6 +116,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Properties";
+       ot->description= "Toggle text properties panel";
        ot->idname= "TEXT_OT_properties";
        
        /* api callbacks */
@@ -323,23 +133,23 @@ void TEXT_OT_properties(wmOperatorType *ot)
        uiPopupMenu *pup;
 
        if(text) {
-               pup= uiPupMenuBegin("Text", 0);
+               pup= uiPupMenuBegin(C, "Text", ICON_NULL);
                if(txt_has_sel(text)) {
-                       uiItemO(layout, NULL, 0, "TEXT_OT_cut");
-                       uiItemO(layout, NULL, 0, "TEXT_OT_copy");
+                       uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_cut");
+                       uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_copy");
                }
-               uiItemO(layout, NULL, 0, "TEXT_OT_paste");
-               uiItemO(layout, NULL, 0, "TEXT_OT_new");
-               uiItemO(layout, NULL, 0, "TEXT_OT_open");
-               uiItemO(layout, NULL, 0, "TEXT_OT_save");
-               uiItemO(layout, NULL, 0, "TEXT_OT_save_as");
-               uiItemO(layout, NULL, 0, "TEXT_OT_run_script");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_paste");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save_as");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_run_script");
                uiPupMenuEnd(C, pup);
        }
        else {
-               pup= uiPupMenuBegin("File", 0);
-               uiItemO(layout, NULL, 0, "TEXT_OT_new");
-               uiItemO(layout, NULL, 0, "TEXT_OT_open");
+               pup= uiPupMenuBegin(C, "File", ICON_NULL);
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
                uiPupMenuEnd(C, pup);
        }
 }
@@ -349,10 +159,10 @@ void TEXT_OT_properties(wmOperatorType *ot)
 
        uiPopupMenu *pup;
 
-       pup= uiPupMenuBegin("Edit", 0);
-       uiItemO(layout, NULL, 0, "TEXT_OT_cut");
-       uiItemO(layout, NULL, 0, "TEXT_OT_copy");
-       uiItemO(layout, NULL, 0, "TEXT_OT_paste");
+       pup= uiPupMenuBegin(C, "Edit", ICON_NULL);
+       uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_cut");
+       uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_copy");
+       uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_paste");
        uiPupMenuEnd(C, pup);
 }
 
@@ -362,18 +172,18 @@ void TEXT_OT_properties(wmOperatorType *ot)
        uiPopupMenu *pup;
 
        if(text) {
-               pup= uiPupMenuBegin("Text", 0);
-               uiItemO(layout, NULL, 0, "TEXT_OT_new");
-               uiItemO(layout, NULL, 0, "TEXT_OT_open");
-               uiItemO(layout, NULL, 0, "TEXT_OT_save");
-               uiItemO(layout, NULL, 0, "TEXT_OT_save_as");
-               uiItemO(layout, NULL, 0, "TEXT_OT_run_script");
+               pup= uiPupMenuBegin(C, "Text", ICON_NULL);
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save_as");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_run_script");
                uiPupMenuEnd(C, pup);
        }
        else {
-               pup= uiPupMenuBegin("File", 0);
-               uiItemO(layout, NULL, 0, "TEXT_OT_new");
-               uiItemO(layout, NULL, 0, "TEXT_OT_open");
+               pup= uiPupMenuBegin(C, "File", ICON_NULL);
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
+               uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
                uiPupMenuEnd(C, pup);
        }
 }
@@ -383,11 +193,11 @@ void TEXT_OT_properties(wmOperatorType *ot)
 
        uiPopupMenu *pup;
 
-       pup= uiPupMenuBegin("Text", 0);
-       uiItemEnumO(layout, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP);
-       uiItemEnumO(layout, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM);
-       uiItemEnumO(layout, "Page Up", 0, "TEXT_OT_move", "type", PREV_PAGE);
-       uiItemEnumO(layout,  "Page Down", 0, "TEXT_OT_move", "type", NEXT_PAGE);
+       pup= uiPupMenuBegin(C, "Text", ICON_NULL);
+       uiItemEnumO(layout, "TEXT_OT_move", "Top of File", 0, "type", FILE_TOP);
+       uiItemEnumO(layout, "TEXT_OT_move", "Bottom of File", 0, "type", FILE_BOTTOM);
+       uiItemEnumO(layout, "TEXT_OT_move", "Page Up", 0, "type", PREV_PAGE);
+       uiItemEnumO(layout, "TEXT_OT_move", "Page Down", 0, "type", NEXT_PAGE);
        uiPupMenuEnd(C, pup);
 }
 #endif