add bins/folders, fix listbox bad wdw ref, hide vicons fix, remove sort by time
[goodguy/history.git] / cinelerra-5.1 / cinelerra / folderlistmenu.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "awindow.h"
23 #include "awindowgui.h"
24 #include "folderlistmenu.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "mainsession.h"
29 #include "mwindow.h"
30
31
32 FolderListMenu::FolderListMenu(MWindow *mwindow, AWindowGUI *gui)
33  : BC_PopupMenu(0, 0, 0, "", 0)
34 {
35         this->mwindow = mwindow;
36         this->gui = gui;
37 }
38
39 FolderListMenu::~FolderListMenu()
40 {
41 }
42
43 void FolderListMenu::create_objects()
44 {
45         BC_MenuItem *menu_item;
46         BC_SubMenu *submenu;
47         add_item(format = new FolderListFormat(mwindow, this));
48         add_item(new FolderListSort(mwindow, this));
49         add_item(menu_item = new BC_MenuItem(_("Folder...")));
50         menu_item->add_submenu(submenu = new BC_SubMenu());
51         submenu->add_submenuitem(new FolderListNew(mwindow, this));
52         submenu->add_submenuitem(new FolderListModify(mwindow, this));
53         submenu->add_submenuitem(new FolderListDelete(mwindow, this));
54         update_titles();
55 }
56
57 void FolderListMenu::update_titles()
58 {
59         format->set_text(mwindow->edl->session->folderlist_format == FOLDERS_TEXT ?
60                 (char*)_("Display icons") : (char*)_("Display text"));
61 }
62
63
64 FolderListFormat::FolderListFormat(MWindow *mwindow, FolderListMenu *menu)
65  : BC_MenuItem("")
66 {
67         this->mwindow = mwindow;
68         this->menu = menu;
69 }
70
71 int FolderListFormat::handle_event()
72 {
73         switch(mwindow->edl->session->folderlist_format) {
74         case FOLDERS_TEXT:
75                 mwindow->edl->session->folderlist_format = FOLDERS_ICONS;
76                 break;
77         case FOLDERS_ICONS:
78                 mwindow->edl->session->folderlist_format = FOLDERS_TEXT;
79                 break;
80         }
81
82         mwindow->awindow->gui->folder_list->update_format(
83                 mwindow->edl->session->folderlist_format, 1);
84         menu->update_titles();
85
86         return 1;
87 }
88
89
90 FolderListSort::FolderListSort(MWindow *mwindow, FolderListMenu *menu)
91  : BC_MenuItem(_("Sort items"))
92 {
93         this->mwindow = mwindow;
94         this->menu = menu;
95 }
96
97 int FolderListSort::handle_event()
98 {
99         mwindow->awindow->gui->sort_folders();
100         return 1;
101 }
102
103 FolderListNew::FolderListNew(MWindow *mwindow, FolderListMenu *menu)
104  : BC_MenuItem(_("New folder"))
105 {
106         this->mwindow = mwindow;
107         this->menu = menu;
108 }
109
110 int FolderListNew::handle_event()
111 {
112         int cx, cy, cw = 320, ch = 120;
113         menu->gui->get_abs_cursor(cx, cy);
114         if( (cx-=cw/2) < 50 ) cx = 50;
115         if( (cy-=ch/2) < 50 ) cy = 50;
116         menu->gui->new_folder_thread->start(cx, cy, cw, ch);
117         return 1;
118 }
119
120 FolderListModify::FolderListModify(MWindow *mwindow, FolderListMenu *menu)
121  : BC_MenuItem(_("Modify folder"))
122 {
123         this->mwindow = mwindow;
124         this->menu = menu;
125 }
126
127 int FolderListModify::handle_event()
128 {
129         int awindow_folder = mwindow->edl->session->awindow_folder;
130         BinFolder *folder = mwindow->edl->get_folder(awindow_folder);
131         if( folder ) {
132                 int bw = mwindow->session->bwindow_w;
133                 int bh = mwindow->session->bwindow_h;
134                 int cx, cy;
135                 menu->gui->get_abs_cursor(cx, cy);
136                 if( (cx-=bw/2) < 50 ) cx = 50;
137                 if( (cy-=bh/2) < 50 ) cy = 50;
138                 menu->gui->modify_folder_thread->start(folder, cx, cy, bw, bh);
139         }
140         return 1;
141 }
142
143 FolderListDelete::FolderListDelete(MWindow *mwindow, FolderListMenu *menu)
144  : BC_MenuItem(_("Delete folder"))
145 {
146         this->mwindow = mwindow;
147         this->menu = menu;
148 }
149
150 int FolderListDelete::handle_event()
151 {
152         AssetPicon *picon = (AssetPicon *)menu->gui->folder_list->get_selection(0, 0);
153         if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
154                 int foldernum = picon->foldernum;
155                 BinFolder *folder = mwindow->edl->get_folder(foldernum);
156                 mwindow->delete_folder(folder->title);
157                 if( mwindow->edl->session->awindow_folder == foldernum )
158                         mwindow->edl->session->awindow_folder = AW_MEDIA_FOLDER;
159                 mwindow->awindow->gui->async_update_assets();
160         }
161         return 1;
162 }
163