add missing GPL information in guicast program files
[goodguy/cinelerra.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, _("New Media"), 0));
52         submenu->add_submenuitem(new FolderListNew(mwindow, this, _("New Clips"), 1));
53         submenu->add_submenuitem(new FolderListModify(mwindow, this));
54         submenu->add_submenuitem(new FolderListDelete(mwindow, this));
55         update_titles();
56 }
57
58 void FolderListMenu::update_titles()
59 {
60         format->set_text(mwindow->edl->session->folderlist_format == FOLDERS_TEXT ?
61                 (char*)_("Display icons") : (char*)_("Display text"));
62 }
63
64
65 FolderListFormat::FolderListFormat(MWindow *mwindow, FolderListMenu *menu)
66  : BC_MenuItem("")
67 {
68         this->mwindow = mwindow;
69         this->menu = menu;
70 }
71
72 int FolderListFormat::handle_event()
73 {
74         switch(mwindow->edl->session->folderlist_format) {
75         case FOLDERS_TEXT:
76                 mwindow->edl->session->folderlist_format = FOLDERS_ICONS;
77                 break;
78         case FOLDERS_ICONS:
79                 mwindow->edl->session->folderlist_format = FOLDERS_TEXT;
80                 break;
81         }
82
83         mwindow->awindow->gui->folder_list->update_format(
84                 mwindow->edl->session->folderlist_format, 1);
85         menu->update_titles();
86
87         return 1;
88 }
89
90
91 FolderListSort::FolderListSort(MWindow *mwindow, FolderListMenu *menu)
92  : BC_MenuItem(_("Sort items"))
93 {
94         this->mwindow = mwindow;
95         this->menu = menu;
96 }
97
98 int FolderListSort::handle_event()
99 {
100         mwindow->awindow->gui->sort_folders();
101         return 1;
102 }
103
104 FolderListNew::FolderListNew(MWindow *mwindow, FolderListMenu *menu,
105                 const char *text, int is_clips)
106  : BC_MenuItem(text)
107 {
108         this->mwindow = mwindow;
109         this->menu = menu;
110         this->is_clips = is_clips;
111 }
112
113 int FolderListNew::handle_event()
114 {
115         int cx, cy, cw = 320, ch = 120;
116         menu->gui->get_abs_cursor(cx, cy);
117         if( (cx-=cw/2) < 50 ) cx = 50;
118         if( (cy-=ch/2) < 50 ) cy = 50;
119         menu->gui->new_folder_thread->start(cx, cy, cw, ch, is_clips);
120         return 1;
121 }
122
123 FolderListModify::FolderListModify(MWindow *mwindow, FolderListMenu *menu)
124  : BC_MenuItem(_("Modify folder"))
125 {
126         this->mwindow = mwindow;
127         this->menu = menu;
128 }
129
130 int FolderListModify::handle_event()
131 {
132         int awindow_folder = mwindow->edl->session->awindow_folder;
133         BinFolder *folder = mwindow->edl->get_folder(awindow_folder);
134         if( folder ) {
135                 int bw = mwindow->session->bwindow_w;
136                 int bh = mwindow->session->bwindow_h;
137                 int cx, cy;
138                 menu->gui->get_abs_cursor(cx, cy);
139                 if( (cx-=bw/2) < 50 ) cx = 50;
140                 if( (cy-=bh/2) < 50 ) cy = 50;
141                 menu->gui->modify_folder_thread->start(folder, cx, cy, bw, bh);
142         }
143         return 1;
144 }
145
146 FolderListDelete::FolderListDelete(MWindow *mwindow, FolderListMenu *menu)
147  : BC_MenuItem(_("Delete folder"))
148 {
149         this->mwindow = mwindow;
150         this->menu = menu;
151 }
152
153 int FolderListDelete::handle_event()
154 {
155         AssetPicon *picon = (AssetPicon *)menu->gui->folder_list->get_selection(0, 0);
156         if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
157                 int foldernum = picon->foldernum;
158                 BinFolder *folder = mwindow->edl->get_folder(foldernum);
159                 mwindow->delete_folder(folder->title);
160                 if( mwindow->edl->session->awindow_folder == foldernum )
161                         mwindow->edl->session->awindow_folder = AW_MEDIA_FOLDER;
162                 mwindow->awindow->gui->async_update_assets();
163         }
164         return 1;
165 }
166