1 /* -----------------------------------------------------------------------------
2  *
3  * Giada - Your Hardcore Loopmachine
4  *
5  * -----------------------------------------------------------------------------
6  *
7  * Copyright (C) 2010-2020 Giovanni A. Zuliani | Monocasual
8  *
9  * This file is part of Giada - Your Hardcore Loopmachine.
10  *
11  * Giada - Your Hardcore Loopmachine is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation, either
14  * version 3 of the License, or (at your option) any later version.
15  *
16  * Giada - Your Hardcore Loopmachine is distributed in the hope that it
17  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
18  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with Giada - Your Hardcore Loopmachine. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  * -------------------------------------------------------------------------- */
26 
27 
28 #include "utils/fs.h"
29 #include "gui/elems/browser.h"
30 #include "gui/elems/basics/button.h"
31 #include "gui/elems/basics/input.h"
32 #include "browserDir.h"
33 
34 
35 namespace giada {
36 namespace v
37 {
gdBrowserDir(const std::string & title,const std::string & path,std::function<void (void *)> cb)38 gdBrowserDir::gdBrowserDir(const std::string& title, const std::string& path,
39 	std::function<void(void*)> cb)
40 : gdBrowserBase(title, path, cb, 0)
41 {
42 	where->size(groupTop->w()-updir->w()-8, 20);
43 
44 	browser->callback(cb_down, (void*) this);
45 
46 	ok->label("Select");
47 	ok->callback(cb_load, (void*) this);
48 	ok->shortcut(FL_ENTER);
49 
50 	/* On OS X the 'where' input doesn't get resized properly on startup. Let's
51 	force it. */
52 
53 	where->redraw();
54 }
55 
56 
57 /* -------------------------------------------------------------------------- */
58 
59 
cb_load(Fl_Widget *,void * p)60 void gdBrowserDir::cb_load(Fl_Widget* /*v*/, void* p) { ((gdBrowserDir*)p)->cb_load(); }
cb_down(Fl_Widget *,void * p)61 void gdBrowserDir::cb_down(Fl_Widget* /*v*/, void* p) { ((gdBrowserDir*)p)->cb_down(); }
62 
63 
64 /* -------------------------------------------------------------------------- */
65 
66 
cb_load()67 void gdBrowserDir::cb_load()
68 {
69 	fireCallback();
70 }
71 
72 
73 /* -------------------------------------------------------------------------- */
74 
75 
cb_down()76 void gdBrowserDir::cb_down()
77 {
78 	std::string path = browser->getSelectedItem();
79 
80 	if (path.empty() || !u::fs::isDir(path)) // when click on an empty area or not a dir
81 		return;
82 
83 	browser->loadDir(path);
84 	where->value(browser->getCurrentDir().c_str());
85 }
86 
87 }} // giada::v::
88