File: paths.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (120 lines) | stat: -rw-r--r-- 3,735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#if defined(PLATFORM_MACOS)
#define ELLIPSIS "\u2026"
#else
#define ELLIPSIS " ..."
#endif

auto PathSettings::construct() -> void {
  setCollapsible();
  setVisible(false);

  homeLabel.setText("Home").setFont(Font().setBold());
  homeLayout.setPadding(12_sx, 0);
  homePath.setEditable(false);
  homeAssign.setText("Assign" ELLIPSIS).onActivate([&] {
    BrowserDialog dialog;
    dialog.setTitle("Select Home Path");
    dialog.setPath(Path::desktop());
    dialog.setAlignment(settingsWindow);
    if(auto location = program.selectFolder(dialog)) {
      settings.paths.home = location;
      refresh();
    }
  });
  homeReset.setText("Reset").onActivate([&] {
    settings.paths.home = "";
    refresh();
  });

  savesLabel.setText("Saves").setFont(Font().setBold());
  savesLayout.setPadding(12_sx, 0);
  savesPath.setEditable(false);
  savesAssign.setText("Assign" ELLIPSIS).onActivate([&] {
    BrowserDialog dialog;
    dialog.setTitle("Select Saves Path");
    dialog.setPath(Path::desktop());
    dialog.setAlignment(settingsWindow);
    if(auto location = program.selectFolder(dialog)) {
      settings.paths.saves = location;
      refresh();
    }
  });
  savesReset.setText("Reset").onActivate([&] {
    settings.paths.saves = "";
    refresh();
  });

  screenshotsLabel.setText("Screenshots").setFont(Font().setBold());
  screenshotsLayout.setPadding(12_sx, 0);
  screenshotsPath.setEditable(false);
  screenshotsAssign.setText("Assign" ELLIPSIS).onActivate([&] {
    BrowserDialog dialog;
    dialog.setTitle("Select Screenshots Path");
    dialog.setPath(Path::desktop());
    dialog.setAlignment(settingsWindow);
    if(auto location = program.selectFolder(dialog)) {
      settings.paths.screenshots = location;
      refresh();
    }
  });
  screenshotsReset.setText("Reset").onActivate([&] {
    settings.paths.screenshots = "";
    refresh();
  });

  debuggingLabel.setText("Debugging Files").setFont(Font().setBold());
  debuggingLayout.setPadding(12_sx, 0);
  debuggingPath.setEditable(false);
  debuggingAssign.setText("Assign" ELLIPSIS).onActivate([&] {
    BrowserDialog dialog;
    dialog.setTitle("Select Debugging Path");
    dialog.setPath(Path::desktop());
    dialog.setAlignment(settingsWindow);
    if(auto location = program.selectFolder(dialog)) {
      settings.paths.debugging = location;
      refresh();
    }
  });
  debuggingReset.setText("Reset").onActivate([&] {
    settings.paths.debugging = "";
    refresh();
  });

  refresh();
}

auto PathSettings::refresh() -> void {
  //simplifies pathnames by abbreviating the home folder and trailing slash
  auto pathname = [](string name) -> string {
    if(name.beginsWith(Path::user())) {
      name.trimLeft(Path::user(), 1L);
      name.prepend("~/");
    }
    if(name != "/") name.trimRight("/", 1L);
    return name;
  };

  if(settings.paths.home) {
    homePath.setText(pathname(settings.paths.home)).setForegroundColor();
  } else {
    homePath.setText(pathname(mia::homeLocation())).setForegroundColor(SystemColor::PlaceholderText);
  }

  if(settings.paths.saves) {
    savesPath.setText(pathname(settings.paths.saves)).setForegroundColor();
  } else {
    savesPath.setText("(same as game path)").setForegroundColor(SystemColor::PlaceholderText);
  }

  if(settings.paths.screenshots) {
    screenshotsPath.setText(pathname(settings.paths.screenshots)).setForegroundColor();
  } else {
    screenshotsPath.setText("(same as game path)").setForegroundColor(SystemColor::PlaceholderText);
  }

  if(settings.paths.debugging) {
    debuggingPath.setText(pathname(settings.paths.debugging)).setForegroundColor();
  } else {
    debuggingPath.setText("(same as game path)").setForegroundColor(SystemColor::PlaceholderText);
  }
}