2.5 file browser
authorAndrea Weikert <elubie@gmx.net>
Mon, 29 Jun 2009 22:16:48 +0000 (22:16 +0000)
committerAndrea Weikert <elubie@gmx.net>
Mon, 29 Jun 2009 22:16:48 +0000 (22:16 +0000)
* bookmark operators: add and delete bookmark
* first start at menus in file browser: Directory and Bookmarks
* Adding a bookmark via menu or via CTRL+B
* Remove a bookmark with the X button next to it.

release/ui/space_filebrowser.py
source/blender/editors/space_file/file_intern.h
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/file_panels.c
source/blender/editors/space_file/space_file.c

index f81f45ff530dbdc7cd798f3e14ce8c4de9bf6193..d23cc0f276c2cb812bc46ceeeb48d122acfed179 100644 (file)
@@ -13,6 +13,11 @@ class FILEBROWSER_HT_header(bpy.types.Header):
                params = st.params 
                layout.template_header(context)
 
+               if context.area.show_menus:
+                       row = layout.row()
+                       row.itemM("FILEBROWSER_MT_directory")
+                       row.itemM("FILEBROWSER_MT_bookmarks")
+                       
                row = layout.row(align=True)
                row.itemO("FILE_OT_parent", text="", icon='ICON_FILE_PARENT')
                row.itemO("FILE_OT_refresh", text="", icon='ICON_FILE_REFRESH')
@@ -38,6 +43,26 @@ class FILEBROWSER_HT_header(bpy.types.Header):
                else: 
                        row.active = False
                        
-bpy.types.register(FILEBROWSER_HT_header)
+class FILEBROWSER_MT_directory(bpy.types.Menu):
+       __space_type__ = "FILE_BROWSER"
+       __label__ = "Directory"
+
+       def draw(self, context):
+               layout = self.layout
+
+               layout.itemO("FILE_OT_refresh", text="Refresh", icon='ICON_FILE_REFRESH')
+               layout.itemO("FILE_OT_parent", text="Parent", icon='ICON_FILE_PARENT')
+               
+class FILEBROWSER_MT_bookmarks(bpy.types.Menu):
+       __space_type__ = "FILE_BROWSER"
+       __label__ = "Bookmarks"
 
+       def draw(self, context):
+               layout = self.layout
 
+               layout.itemO("FILE_OT_add_bookmark", text="Add current directory", icon='ICON_BOOKMARKS')
+
+               
+bpy.types.register(FILEBROWSER_HT_header)
+bpy.types.register(FILEBROWSER_MT_directory)
+bpy.types.register(FILEBROWSER_MT_bookmarks)
index 6ce30bb48cbf41d49296cc98f95c88ee3dca8f95..fd37bb756858b0f63baf0ca847613ff6fafe0c2c 100644 (file)
@@ -58,6 +58,8 @@ void FILE_OT_select(struct wmOperatorType *ot);
 void FILE_OT_select_all_toggle(struct wmOperatorType *ot);
 void FILE_OT_select_border(struct wmOperatorType *ot);
 void FILE_OT_select_bookmark(struct wmOperatorType *ot);
+void FILE_OT_add_bookmark(struct wmOperatorType *ot);
+void FILE_OT_delete_bookmark(struct wmOperatorType *ot);
 void FILE_OT_loadimages(struct wmOperatorType *ot);
 void FILE_OT_exec(struct wmOperatorType *ot);
 void FILE_OT_cancel(struct wmOperatorType *ot);
index ebece6dd5e65e195feb127d218cc03f5bff616e2..dd20c8e822454f6a44afe819784d0f27f9098303 100644 (file)
@@ -336,6 +336,71 @@ void FILE_OT_select_bookmark(wmOperatorType *ot)
        RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
 }
 
+static int bookmark_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+       struct FSMenu* fsmenu = fsmenu_get();
+       struct FileSelectParams* params= ED_fileselect_get_params(sfile);
+
+       if (params->dir[0] != '\0') {
+               char name[FILE_MAX];
+       
+               fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
+               BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
+               fsmenu_write_file(fsmenu, name);
+       }
+
+       ED_area_tag_redraw(sa);
+       return OPERATOR_FINISHED;
+}
+
+void FILE_OT_add_bookmark(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Bookmark";
+       ot->idname= "FILE_OT_add_bookmark";
+       
+       /* api callbacks */
+       ot->invoke= bookmark_add_invoke;
+       ot->poll= ED_operator_file_active;
+}
+
+static int bookmark_delete_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+       struct FSMenu* fsmenu = fsmenu_get();
+       int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
+       if(RNA_struct_find_property(op->ptr, "index")) {
+               int index = RNA_int_get(op->ptr, "index");
+               if ( (index >-1) && (index < nentries)) {
+                       char name[FILE_MAX];
+                       
+                       fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
+                       BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
+                       fsmenu_write_file(fsmenu, name);
+                       ED_area_tag_redraw(sa);
+               }
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+void FILE_OT_delete_bookmark(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Delete Bookmark";
+       ot->idname= "FILE_OT_delete_bookmark";
+       
+       /* api callbacks */
+       ot->invoke= bookmark_delete_invoke;
+       ot->poll= ED_operator_file_active;
+
+       RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
+}
+
+
 static int loadimages_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        ScrArea *sa= CTX_wm_area(C);
index 815345f34c89eaa4a1545f400fb5000bf6e26493..b370624d312a8520a6dde0c5c2487885d783f2f1 100644 (file)
@@ -26,7 +26,7 @@ static void do_file_panel_events(bContext *C, void *arg, int event)
 
 }
 
-static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, int icon)
+static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, int icon, int allow_delete)
 {
        uiBlock *block;
        uiStyle *style= U.uistyles.first;
@@ -41,26 +41,29 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat
        uiBlockSetEmboss(block, UI_EMBOSSP);
        uiBlockBeginAlign(block);
        for (i=0; i< nentries;++i) {
+               uiLayout* layout = uiLayoutRow(pa->layout, UI_LAYOUT_ALIGN_LEFT);
                char *fname = fsmenu_get_entry(fsmenu, category, i);
-               uiItemStringO(pa->layout, fname, icon, "FILE_OT_select_bookmark", "dir", fname);
+               uiItemStringO(layout, fname, icon, "FILE_OT_select_bookmark", "dir", fname);
+               if (allow_delete)
+                       uiItemIntO(layout, "", ICON_X, "FILE_OT_delete_bookmark", "index", i);
        }
        uiBlockEndAlign(block);
 }
 
 static void file_panel_system(const bContext *C, Panel *pa)
 {
-       file_panel_category(C, pa, FS_CATEGORY_SYSTEM, ICON_DISK_DRIVE);
+       file_panel_category(C, pa, FS_CATEGORY_SYSTEM, ICON_DISK_DRIVE, 0);
 }
 
 static void file_panel_bookmarks(const bContext *C, Panel *pa)
 {
-       file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, ICON_BOOKMARKS);
+       file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, ICON_BOOKMARKS, 1);
 }
 
 
 static void file_panel_recent(const bContext *C, Panel *pa)
 {
-       file_panel_category(C, pa, FS_CATEGORY_RECENT, ICON_FILE_FOLDER);
+       file_panel_category(C, pa, FS_CATEGORY_RECENT, ICON_FILE_FOLDER, 0);
 }
 
 
index 4ed92d3f5d93ea2ce28162f9a71548f35d5e3adf..3824c23cb4836694cbd9bd9e4b2b2f38e47d5777 100644 (file)
@@ -292,6 +292,8 @@ void file_operatortypes(void)
        WM_operatortype_append(FILE_OT_parent);
        WM_operatortype_append(FILE_OT_refresh);
        WM_operatortype_append(FILE_OT_bookmark_toggle);
+       WM_operatortype_append(FILE_OT_add_bookmark);
+       WM_operatortype_append(FILE_OT_delete_bookmark);
 }
 
 /* NOTE: do not add .blend file reading on this level */
@@ -304,7 +306,7 @@ void file_keymap(struct wmWindowManager *wm)
        WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, 0, 0);
        WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0);
-       
+       WM_keymap_add_item(keymap, "FILE_OT_add_bookmark", BKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "FILE_OT_loadimages", TIMER1, KM_ANY, KM_ANY, 0);
 
        keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0);