[Bf-blender-cvs] [2c7ee72] asset-experiments: Add moving around bookmarks (same system as for vgroups etc.).

Bastien Montagne noreply at git.blender.org
Wed Jan 7 21:14:26 CET 2015


Commit: 2c7ee72167bfe9e42fda64f29ba37ee24ef00925
Author: Bastien Montagne
Date:   Wed Jan 7 21:13:45 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB2c7ee72167bfe9e42fda64f29ba37ee24ef00925

Add moving around bookmarks (same system as for vgroups etc.).

===================================================================

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/editors/space_file/space_file.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index b029505..0af5d10 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Header, Panel
+from bpy.types import Header, Panel, Menu
 
 
 class FILEBROWSER_HT_header(Header):
@@ -150,6 +150,16 @@ class FILEBROWSER_PT_system_bookmarks(Panel):
                               space, "system_bookmarks_active", rows=1, maxrows=6)
 
 
+class FILEBROWSER_MT_bookmarks_specials(Menu):
+    bl_label = "Bookmarks Specials"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("file.bookmark_move", icon='TRIA_UP_BAR', text="Move To Top").direction = 'TOP'
+        layout.operator("file.bookmark_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").direction = 'BOTTOM'
+
+
 class FILEBROWSER_PT_bookmarks(Panel):
     bl_space_type = 'FILE_BROWSER'
     bl_region_type = 'CHANNELS'
@@ -161,12 +171,19 @@ class FILEBROWSER_PT_bookmarks(Panel):
 
         if space.bookmarks:
             row = layout.row()
+            num_rows = len(space.bookmarks)
             row.template_list("FILEBROWSER_UL_dir", "bookmarks", space, "bookmarks",
-                              space, "bookmarks_active", rows=1, maxrows=6)
+                              space, "bookmarks_active", rows=(2 if num_rows < 2 else 4), maxrows=6)
 
             col = row.column(align=True)
             col.operator("file.bookmark_add", icon='ZOOMIN', text="")
             col.operator("file.bookmark_delete", icon='ZOOMOUT', text="")
+            col.menu("FILEBROWSER_MT_bookmarks_specials", icon='DOWNARROW_HLT', text="")
+
+            if num_rows > 1:
+                col.separator()
+                col.operator("file.bookmark_move", icon='TRIA_UP', text="").direction = 'UP'
+                col.operator("file.bookmark_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 
 
 class FILEBROWSER_PT_recent_folders(Panel):
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 4abfb65..bcbdb1a 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -129,6 +129,7 @@ struct FSMenuEntry;
 
 struct FSMenu *fsmenu_get(void);
 struct FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category);
+void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, struct FSMenuEntry *fsm_head);
 
 /** Returns the number of entries in the Fileselect Menu */
 int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category);
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 7147353..4f29dd3 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -66,6 +66,7 @@ void FILE_OT_select_border(struct wmOperatorType *ot);
 void FILE_OT_select_bookmark(struct wmOperatorType *ot);
 void FILE_OT_bookmark_add(struct wmOperatorType *ot);
 void FILE_OT_bookmark_delete(struct wmOperatorType *ot);
+void FILE_OT_bookmark_move(struct wmOperatorType *ot);
 void FILE_OT_reset_recent(wmOperatorType *ot);
 void FILE_OT_hidedot(struct wmOperatorType *ot);
 void FILE_OT_execute(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index f03b552..c72810b 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -577,6 +577,136 @@ void FILE_OT_bookmark_delete(wmOperatorType *ot)
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
+enum {
+	FILE_BOOKMARK_MOVE_TOP = -2,
+	FILE_BOOKMARK_MOVE_UP = -1,
+	FILE_BOOKMARK_MOVE_DOWN = 1,
+	FILE_BOOKMARK_MOVE_BOTTOM = 2,
+};
+
+static int bookmark_move_exec(bContext *C, wmOperator *op)
+{
+	ScrArea *sa = CTX_wm_area(C);
+	SpaceFile *sfile = CTX_wm_space_file(C);
+	struct FSMenu *fsmenu = fsmenu_get();
+	struct FSMenuEntry *fsmentry = fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS);
+	struct FSMenuEntry *fsme_psrc, *fsme_pdst, *fsme;
+
+	char fname[FILE_MAX];
+
+	const int direction = RNA_enum_get(op->ptr, "direction");
+	const int totitems = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
+	const int act_index = sfile->bookmarknr;
+	int new_index, i;
+
+	switch (direction) {
+		case FILE_BOOKMARK_MOVE_TOP:
+			new_index = 0;
+			break;
+		case FILE_BOOKMARK_MOVE_BOTTOM:
+			new_index = totitems - 1;
+			break;
+		case FILE_BOOKMARK_MOVE_UP:
+		case FILE_BOOKMARK_MOVE_DOWN:
+		default:
+			new_index = (totitems + act_index + direction) % totitems;
+			break;
+	}
+
+	if (new_index == act_index) {
+		return OPERATOR_CANCELLED;
+	}
+
+	fsme_psrc = fsme_pdst = NULL;
+
+	if (new_index < act_index) {
+		for (fsme = fsmentry, i = 0; fsme; fsme = fsme->next, i++) {
+			if (i == new_index - 1) {
+				fsme_pdst = fsme;
+			}
+			else if (i == act_index - 1) {
+				fsme_psrc = fsme;
+				break;
+			}
+		}
+
+		BLI_assert(fsme_psrc && fsme_psrc->next && (!fsme_pdst || fsme_pdst->next));
+
+		fsme = fsme_psrc->next;
+		fsme_psrc->next = fsme->next;
+		if (fsme_pdst) {
+			fsme->next = fsme_pdst->next;
+			fsme_pdst->next = fsme;
+		}
+		else {
+			/* destination is first element of the list... */
+			fsme->next = fsmentry;
+			fsmentry = fsme;
+			fsmenu_set_category(fsmenu, FS_CATEGORY_BOOKMARKS, fsmentry);
+		}
+	}
+	else {
+		for (fsme = fsmentry, i = 0; fsme; fsme = fsme->next, i++) {
+			if (i == new_index) {
+				fsme_pdst = fsme;
+				break;
+			}
+			else if (i == act_index - 1) {
+				fsme_psrc = fsme;
+			}
+		}
+
+		BLI_assert(fsme_pdst && (!fsme_psrc || fsme_psrc->next));
+
+		if (fsme_psrc) {
+			fsme = fsme_psrc->next;
+			fsme_psrc->next = fsme->next;
+		}
+		else {
+			/* source is first element of the list... */
+			fsme = fsmentry;
+			fsmentry = fsme->next;
+			fsmenu_set_category(fsmenu, FS_CATEGORY_BOOKMARKS, fsmentry);
+		}
+		fsme->next = fsme_pdst->next;
+		fsme_pdst->next = fsme;
+	}
+
+	/* Need to update active bookmark number. */
+	sfile->bookmarknr = new_index;
+
+	BLI_make_file_string("/", fname, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
+	fsmenu_write_file(fsmenu, fname);
+
+	ED_area_tag_redraw(sa);
+	return OPERATOR_FINISHED;
+}
+
+void FILE_OT_bookmark_move(wmOperatorType *ot)
+{
+	static EnumPropertyItem slot_move[] = {
+	    {FILE_BOOKMARK_MOVE_TOP, "TOP", 0, "Top", "Top of the list"},
+		{FILE_BOOKMARK_MOVE_UP, "UP", 0, "Up", ""},
+		{FILE_BOOKMARK_MOVE_DOWN, "DOWN", 0, "Down", ""},
+		{FILE_BOOKMARK_MOVE_BOTTOM, "BOTTOM", 0, "Bottom", "Bottom of the list"},
+		{ 0, NULL, 0, NULL, NULL }
+	};
+
+	/* identifiers */
+	ot->name = "Move Bookmark";
+	ot->idname = "FILE_OT_bookmark_move";
+	ot->description = "Move the active bookmark up/down in the list";
+
+	/* api callbacks */
+	ot->poll = ED_operator_file_active;
+	ot->exec = bookmark_move_exec;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER;  /* No undo! */
+
+	RNA_def_enum(ot->srna, "direction", slot_move, 0, "Direction", "Direction to move, UP or DOWN");
+}
+
 static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	ScrArea *sa = CTX_wm_area(C);
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index fd17fa4..73e7b85 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -105,7 +105,7 @@ struct FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory ca
 	return fsm_head;
 }
 
-static void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
+void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
 {
 	switch (category) {
 		case FS_CATEGORY_SYSTEM:
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 779bf18..d1c0049 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -398,6 +398,7 @@ static void file_operatortypes(void)
 	WM_operatortype_append(FILE_OT_bookmark_toggle);
 	WM_operatortype_append(FILE_OT_bookmark_add);
 	WM_operatortype_append(FILE_OT_bookmark_delete);
+	WM_operatortype_append(FILE_OT_bookmark_move);
 	WM_operatortype_append(FILE_OT_reset_recent);
 	WM_operatortype_append(FILE_OT_hidedot);
 	WM_operatortype_append(FILE_OT_filenum);




More information about the Bf-blender-cvs mailing list