PdLibrary.hpp
1 #pragma once
2 #include <Process/Drop/ProcessDropHandler.hpp>
3 
4 #include <Library/LibraryInterface.hpp>
5 #include <Library/LibrarySettings.hpp>
6 #include <Library/ProcessesItemModel.hpp>
7 #include <Pd/PdProcess.hpp>
8 
9 #include <QFileInfo>
10 #include <QTimer>
11 
12 namespace Pd
13 {
14 class LibraryHandler final
15  : public QObject
17 {
18  SCORE_CONCRETE("01ffc109-9cb3-4c5a-9cdd-d9fd38fe5e17")
19 
20  QSet<QString> acceptedFiles() const noexcept override { return {"pd"}; }
21 
22  Library::Subcategories categories;
23 
24  void setup(Library::ProcessesItemModel& model, const score::GUIApplicationContext& ctx)
25  override
26  {
27  // TODO relaunch whenever library path changes...
29  QModelIndex node = model.find(key);
30  if(node == QModelIndex{})
31  return;
32 
33  categories.init(node, ctx);
34  }
35 
36  void addPath(std::string_view path) override
37  {
38  QFileInfo file{QString::fromUtf8(path.data(), path.length())};
40  pdata.prettyName = file.completeBaseName();
42  pdata.customData = [&] { return file.absoluteFilePath(); }();
43 
44  categories.add(file, std::move(pdata));
45  }
46 };
47 
49 {
50  SCORE_CONCRETE("3c4379ce-a5b9-456f-b1d6-09f3f02cc67e")
51 
52  QSet<QString> fileExtensions() const noexcept override { return {"pd"}; }
53 
54  void dropPath(
55  std::vector<ProcessDrop>& vec, const score::FilePath& filename,
56  const score::DocumentContext& ctx) const noexcept override
57  {
60  p.creation.prettyName = filename.basename;
61  p.creation.customData = filename.relative;
62 
63  vec.push_back(std::move(p));
64  }
65 };
66 
67 }
Definition: LibraryInterface.hpp:22
Definition: ProcessesItemModel.hpp:45
Definition: PdLibrary.hpp:49
Definition: PdLibrary.hpp:17
Definition: ProcessDropHandler.hpp:25
Definition: ProcessesItemModel.hpp:32
Definition: ProcessesItemModel.hpp:86
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
Definition: ProcessDropHandler.hpp:29
Definition: DocumentContext.hpp:18
Definition: FilePath.hpp:25
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15