LMMS
Loading...
Searching...
No Matches
juce_FileSearchPathListComponent.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 : addButton ("+"),
31 removeButton ("-"),
32 changeButton (TRANS ("change...")),
34 downButton ({}, DrawableButton::ImageOnButtonBackground)
35{
36 listBox.setModel (this);
37 addAndMakeVisible (listBox);
38 listBox.setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
39 listBox.setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
40 listBox.setOutlineThickness (1);
41
42 addAndMakeVisible (addButton);
43 addButton.onClick = [this] { addPath(); };
44 addButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
45
46 addAndMakeVisible (removeButton);
47 removeButton.onClick = [this] { deleteSelected(); };
48 removeButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
49
50 addAndMakeVisible (changeButton);
51 changeButton.onClick = [this] { editSelected(); };
52
53 addAndMakeVisible (upButton);
54 upButton.onClick = [this] { moveSelection (-1); };
55
56 auto arrowColour = findColour (ListBox::textColourId);
57
58 {
59 Path arrowPath;
60 arrowPath.addArrow ({ 50.0f, 100.0f, 50.0f, 0.0f }, 40.0f, 100.0f, 50.0f);
61 DrawablePath arrowImage;
62 arrowImage.setFill (arrowColour);
63 arrowImage.setPath (arrowPath);
64
65 upButton.setImages (&arrowImage);
66 }
67
68 addAndMakeVisible (downButton);
69 downButton.onClick = [this] { moveSelection (1); };
70
71 {
72 Path arrowPath;
73 arrowPath.addArrow ({ 50.0f, 0.0f, 50.0f, 100.0f }, 40.0f, 100.0f, 50.0f);
74 DrawablePath arrowImage;
75 arrowImage.setFill (arrowColour);
76 arrowImage.setPath (arrowPath);
77
78 downButton.setImages (&arrowImage);
79 }
80
81 updateButtons();
82}
83
85{
86 const bool anythingSelected = listBox.getNumSelectedRows() > 0;
87
88 removeButton.setEnabled (anythingSelected);
89 changeButton.setEnabled (anythingSelected);
90 upButton.setEnabled (anythingSelected);
91 downButton.setEnabled (anythingSelected);
92}
93
95{
96 listBox.updateContent();
97 listBox.repaint();
99}
100
101//==============================================================================
103{
104 if (newPath.toString() != path.toString())
105 {
106 path = newPath;
107 changed();
108 }
109}
110
112{
113 defaultBrowseTarget = newDefaultDirectory;
114}
115
116//==============================================================================
118{
119 return path.getNumPaths();
120}
121
122void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
123{
124 if (rowIsSelected)
126
127 g.setColour (findColour (ListBox::textColourId));
128 Font f ((float) height * 0.7f);
129 f.setHorizontalScale (0.9f);
130 g.setFont (f);
131
132 g.drawText (path[rowNumber].getFullPathName(),
133 4, 0, width - 6, height,
135}
136
138{
139 if (isPositiveAndBelow (row, path.getNumPaths()))
140 {
141 path.remove (row);
142 changed();
143 }
144}
145
147{
148 chooser = std::make_unique<FileChooser> (TRANS("Change folder..."), path[row], "*");
150
151 chooser->launchAsync (chooserFlags, [this, row] (const FileChooser& fc)
152 {
153 if (fc.getResult() == File{})
154 return;
155
156 path.remove (row);
157 path.add (fc.getResult(), row);
158 changed();
159 });
160}
161
166
171
176
178{
179 const int buttonH = 22;
180 const int buttonY = getHeight() - buttonH - 4;
181 listBox.setBounds (2, 2, getWidth() - 4, buttonY - 5);
182
183 addButton.setBounds (2, buttonY, buttonH, buttonH);
184 removeButton.setBounds (addButton.getRight(), buttonY, buttonH, buttonH);
185
186 changeButton.changeWidthToFitText (buttonH);
187 downButton.setSize (buttonH * 2, buttonH);
188 upButton.setSize (buttonH * 2, buttonH);
189
190 downButton.setTopRightPosition (getWidth() - 2, buttonY);
191 upButton.setTopRightPosition (downButton.getX() - 4, buttonY);
192 changeButton.setTopRightPosition (upButton.getX() - 8, buttonY);
193}
194
199
200void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
201{
202 for (int i = filenames.size(); --i >= 0;)
203 {
204 const File f (filenames[i]);
205
206 if (f.isDirectory())
207 {
208 auto row = listBox.getRowContainingPosition (0, mouseY - listBox.getY());
209 path.add (f, row);
210 changed();
211 }
212 }
213}
214
216{
218
219 if (start == File())
220 start = path[0];
221
222 if (start == File())
224
225 chooser = std::make_unique<FileChooser> (TRANS("Add a folder..."), start, "*");
227
228 chooser->launchAsync (chooserFlags, [this] (const FileChooser& fc)
229 {
230 if (fc.getResult() == File{})
231 return;
232
233 path.add (fc.getResult(), listBox.getSelectedRow());
234 changed();
235 });
236}
237
239{
240 deleteKeyPressed (listBox.getSelectedRow());
241 changed();
242}
243
245{
246 returnKeyPressed (listBox.getSelectedRow());
247 changed();
248}
249
251{
252 jassert (delta == -1 || delta == 1);
253 auto currentRow = listBox.getSelectedRow();
254
255 if (isPositiveAndBelow (currentRow, path.getNumPaths()))
256 {
257 auto newRow = jlimit (0, path.getNumPaths() - 1, currentRow + delta);
258
259 if (currentRow != newRow)
260 {
261 auto f = path[currentRow];
262 path.remove (currentRow);
263 path.add (f, newRow);
264 listBox.selectRow (newRow);
265 changed();
266 }
267 }
268}
269
270
271} // namespace juce
static File getCurrentWorkingDirectory()
Definition File.cpp:1395
int getHeight() const noexcept
Definition juce_Component.h:274
Colour findColour(int colourID, bool inheritFromParent=false) const
Definition juce_Component.cpp:2219
int getWidth() const noexcept
Definition juce_Component.h:271
@ ImageOnButtonBackground
Definition juce_DrawableButton.h:50
@ canSelectDirectories
Definition juce_FileBrowserComponent.h:60
@ openMode
Definition juce_FileBrowserComponent.h:54
Definition juce_FileChooser.h:56
File getResult() const
Definition juce_FileChooser.cpp:240
Definition juce_File.h:45
Definition juce_FileSearchPath.h:35
String toString() const
Definition juce_FileSearchPath.cpp:69
void deleteKeyPressed(int lastRowSelected) override
Definition juce_FileSearchPathListComponent.cpp:137
DrawableButton upButton
Definition juce_FileSearchPathListComponent.h:104
bool isInterestedInFileDrag(const StringArray &) override
Definition juce_FileSearchPathListComponent.cpp:195
int getNumRows() override
Definition juce_FileSearchPathListComponent.cpp:117
@ backgroundColourId
Definition juce_FileSearchPathListComponent.h:70
void setPath(const FileSearchPath &newPath)
Definition juce_FileSearchPathListComponent.cpp:102
void deleteSelected()
Definition juce_FileSearchPathListComponent.cpp:238
void resized() override
Definition juce_FileSearchPathListComponent.cpp:177
void changed()
Definition juce_FileSearchPathListComponent.cpp:94
TextButton changeButton
Definition juce_FileSearchPathListComponent.h:103
void paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected) override
Definition juce_FileSearchPathListComponent.cpp:122
DrawableButton downButton
Definition juce_FileSearchPathListComponent.h:104
std::unique_ptr< FileChooser > chooser
Definition juce_FileSearchPathListComponent.h:100
FileSearchPathListComponent()
Definition juce_FileSearchPathListComponent.cpp:29
void selectedRowsChanged(int lastRowSelected) override
Definition juce_FileSearchPathListComponent.cpp:167
void setDefaultBrowseTarget(const File &newDefaultDirectory)
Definition juce_FileSearchPathListComponent.cpp:111
void listBoxItemDoubleClicked(int row, const MouseEvent &) override
Definition juce_FileSearchPathListComponent.cpp:162
void updateButtons()
Definition juce_FileSearchPathListComponent.cpp:84
TextButton addButton
Definition juce_FileSearchPathListComponent.h:103
void addPath()
Definition juce_FileSearchPathListComponent.cpp:215
void moveSelection(int)
Definition juce_FileSearchPathListComponent.cpp:250
FileSearchPath path
Definition juce_FileSearchPathListComponent.h:98
void returnKeyPressed(int lastRowSelected) override
Definition juce_FileSearchPathListComponent.cpp:146
void paint(Graphics &) override
Definition juce_FileSearchPathListComponent.cpp:172
File defaultBrowseTarget
Definition juce_FileSearchPathListComponent.h:99
void editSelected()
Definition juce_FileSearchPathListComponent.cpp:244
ListBox listBox
Definition juce_FileSearchPathListComponent.h:102
void filesDropped(const StringArray &files, int, int) override
Definition juce_FileSearchPathListComponent.cpp:200
TextButton removeButton
Definition juce_FileSearchPathListComponent.h:103
Definition juce_Font.h:42
Definition juce_GraphicsContext.h:45
@ centredLeft
Definition juce_Justification.h:143
@ textColourId
Definition juce_ListBox.h:498
Definition juce_MouseEvent.h:39
Definition juce_StringArray.h:35
int size() const noexcept
Definition juce_StringArray.h:136
@ highlightColourId
Definition juce_TextEditor.h:217
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
virtual ASIOError start()=0
#define TRANS(stringLiteral)
Definition juce_LocalisedStrings.h:208
#define jassert(expression)
Definition carla_juce.cpp:31
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
@ row
Definition juce_AccessibilityRole.h:53