Skip to content

Commit e8af32a

Browse files
author
Gin
committed
add runtime base folder button in settings panel
1 parent b93f9a8 commit e8af32a

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

Common/Cpp/Options/ButtonOption.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ class ButtonOption : public ButtonCell{
7878
~ButtonOption();
7979
ButtonOption(const ButtonOption& x) = delete;
8080
ButtonOption(
81-
std::string label,
82-
std::string text,
81+
std::string label, // the description of the button, shown on the left side of the button
82+
std::string text, // the text appearing on the button
8383
int button_height = 0,
8484
int text_size = 0
8585
);
8686
ButtonOption(
87-
std::string label,
87+
std::string label, // the description of the button, shown on the left side of the button
8888
Enabled state,
89-
std::string text,
89+
std::string text, // the text appearing on the button
9090
int button_height = 0,
9191
int text_size = 0
9292
);

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Set the minimum cmake version required
22
cmake_minimum_required(VERSION 3.18.0)
3-
3+
44
# Tell CMake to re-run configuration when these files change (get around Qt issues with stale CMake files)
55
set(_cmake_files_to_watch
66
"${CMAKE_SOURCE_DIR}/CMakeLists.txt"
@@ -77,7 +77,6 @@ else()
7777
set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch")
7878
set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts")
7979
set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources")
80-
8180
if(PACKAGE_BUILD)
8281
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Output")
8382
set(DEPLOY_DIR "${DEST_DIR}/Binaries64")
@@ -88,7 +87,6 @@ else()
8887

8988
set(DEPLOY_FILES TRUE)
9089
endif()
91-
9290
#Find threads library
9391
set(THREADS_PREFER_PTHREAD_FLAG ON)
9492
find_package(Threads REQUIRED)
@@ -99,7 +97,7 @@ if(NOT QT_MAJOR)
9997
endif()
10098

10199
# Make sure CI builds work without going overboard with per-platform directory shenanigans
102-
if(NOT DEPLOY_FILES)
100+
if(NOT WIN32 OR NOT DEPLOY_FILES)
103101
find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
104102
endif()
105103

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <set>
99
#include <QStandardPaths>
1010
#include <QCryptographicHash>
11+
#include <QDesktopServices>
12+
#include <QUrl>
1113
#include "Common/Cpp/Containers/Pimpl.tpp"
1214
#include "Common/Cpp/LifetimeSanitizer.h"
1315
#include "Common/Cpp/Json/JsonValue.h"
@@ -99,10 +101,15 @@ GlobalSettings& GlobalSettings::instance(){
99101
}
100102
GlobalSettings::~GlobalSettings(){
101103
ENABLE_LIFETIME_SANITIZER0.remove_listener(*this);
104+
OPEN_BASE_FOLDER_BUTTON.remove_listener(static_cast<ButtonListener&>(*this));
102105
}
103106
GlobalSettings::GlobalSettings()
104107
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
105108
, CHECK_FOR_UPDATES(CONSTRUCT_TOKEN)
109+
, OPEN_BASE_FOLDER_BUTTON(
110+
"<b>Runtime Base Folder:</b>",
111+
"Open Folder"
112+
)
106113
, STATS_FILE(
107114
false,
108115
"<b>Stats File:</b><br>Use the stats file here. Multiple instances of the program can use the same file.",
@@ -211,6 +218,7 @@ GlobalSettings::GlobalSettings()
211218
"", ""
212219
)
213220
{
221+
PA_ADD_OPTION(OPEN_BASE_FOLDER_BUTTON);
214222
PA_ADD_OPTION(CHECK_FOR_UPDATES);
215223
PA_ADD_OPTION(STATS_FILE);
216224
PA_ADD_OPTION(TEMP_FOLDER);
@@ -257,6 +265,7 @@ GlobalSettings::GlobalSettings()
257265

258266
GlobalSettings::on_config_value_changed(this);
259267
ENABLE_LIFETIME_SANITIZER0.add_listener(*this);
268+
OPEN_BASE_FOLDER_BUTTON.add_listener(static_cast<ButtonListener&>(*this));
260269
}
261270

262271
void GlobalSettings::load_json(const JsonValue& json){
@@ -382,6 +391,11 @@ void GlobalSettings::on_config_value_changed(void* object){
382391
}
383392
}
384393

394+
void GlobalSettings::on_press(){
395+
// Open the runtime base folder in the system file manager
396+
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(RUNTIME_BASE_PATH())));
397+
}
398+
385399

386400

387401

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Common/Cpp/Options/ConfigOption.h"
1313
#include "Common/Cpp/Options/StaticTextOption.h"
1414
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
15+
#include "Common/Cpp/Options/ButtonOption.h"
1516
//#include "Common/Cpp/Options/SimpleIntegerOption.h"
1617
#include "Common/Cpp/Options/StringOption.h"
1718
#include "CommonFramework/Panels/SettingsPanel.h"
@@ -76,7 +77,7 @@ class PreloadSettings{
7677

7778

7879

79-
class GlobalSettings : public BatchOption, private ConfigOption::Listener{
80+
class GlobalSettings : public BatchOption, private ConfigOption::Listener, private ButtonListener{
8081
~GlobalSettings();
8182
GlobalSettings();
8283
public:
@@ -87,10 +88,12 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
8788

8889
private:
8990
virtual void on_config_value_changed(void* object) override;
91+
virtual void on_press() override;
9092

9193
public:
9294
Pimpl<CheckForUpdatesOption> CHECK_FOR_UPDATES;
9395

96+
ButtonOption OPEN_BASE_FOLDER_BUTTON;
9497
StringOption STATS_FILE;
9598
FolderInputOption TEMP_FOLDER;
9699

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ std::string get_runtime_base_path(){
147147
return "./";
148148
}
149149

150-
const std::string& RUNTIME_BASE_PATH(){
151-
static std::string path = get_runtime_base_path();
152-
return path;
153-
}
154-
155150
std::string get_setting_path(){
156151
return RUNTIME_BASE_PATH() + "UserSettings/";
157152
}
@@ -170,6 +165,11 @@ std::string get_user_file_path(){
170165

171166
} // anonymous namespace
172167

168+
const std::string& RUNTIME_BASE_PATH(){
169+
static std::string path = get_runtime_base_path();
170+
return path;
171+
}
172+
173173
const std::string& SETTINGS_PATH(){
174174
static std::string path = get_setting_path();
175175
return path;

SerialPrograms/Source/CommonFramework/Globals.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
5+
* Defines basic program related const values (version numbers, program names, URLs, etc.)
6+
* and paths to various folders (setting folder, screenshot folder, etc.).
7+
* CAUTION: since the program's runtime base path is initialized only after Qt is initialized,
8+
* do not call any path functions defined here until after Qt is initialized in the main function.
9+
*
10+
* Also defines program state enum and program feedback type enum.
511
*/
612

713
#ifndef PokemonAutomation_Globals_H
@@ -37,6 +43,9 @@ extern const std::string COMPILER_VERSION;
3743

3844
extern const size_t LOG_HISTORY_LINES;
3945

46+
// Path to the parent folder that holds all other folders, e.g. settings folder, screenshot folder, etc.
47+
const std::string& RUNTIME_BASE_PATH();
48+
4049
// Folder path (end with "/") to hold program setting files.
4150
const std::string& SETTINGS_PATH();
4251
// The setting JSON file path. This path is a child of the folder SETTINGS_PATH().

0 commit comments

Comments
 (0)