summaryrefslogtreecommitdiff
path: root/fluid/proj
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2026-01-04 20:43:26 +0100
committerMatthias Melcher <github@matthiasm.com>2026-01-04 20:43:34 +0100
commit7306b66d99fb529d65ddda1ea8e093454d7005e1 (patch)
tree13803f53b2e921985abe54804b8d9131c46b9c3d /fluid/proj
parent811a188bbf276841365f2ad4b11197f5820fe571 (diff)
Fluid: Add automated MergeBack
Diffstat (limited to 'fluid/proj')
-rw-r--r--fluid/proj/mergeback.cxx51
-rw-r--r--fluid/proj/mergeback.h6
2 files changed, 44 insertions, 13 deletions
diff --git a/fluid/proj/mergeback.cxx b/fluid/proj/mergeback.cxx
index d9e5b0136..4ddb86f10 100644
--- a/fluid/proj/mergeback.cxx
+++ b/fluid/proj/mergeback.cxx
@@ -617,14 +617,24 @@ int Mergeback::merge_back(const std::string &s, const std::string &p, Task task)
0 if MergeBack is not enabled,
or the result of the merge_back function.
*/
-int mergeback_code_files(Project &proj)
+int mergeback_code_files(Project &proj, Mergeback::Feedback feedback)
{
+ static bool recursion_lock = false;
+ if (recursion_lock) return;
+ recursion_lock = true;
+
Fluid.flush_text_widgets();
- if (!proj.proj_filename) return 1;
+ if (!proj.proj_filename) {
+ recursion_lock = false;
+ return 1;
+ }
if (!proj.write_mergeback_data) {
- fl_message("MergeBack is not enabled for this project.\n"
- "Please enable MergeBack in the project settings\n"
- "dialog and re-save the project file and the code.");
+ if (feedback & Mergeback::CHATTY) {
+ fl_message("MergeBack is not enabled for this project.\n"
+ "Please enable MergeBack in the project settings\n"
+ "dialog and re-save the project file and the code.");
+ }
+ recursion_lock = false;
return 0;
}
@@ -633,7 +643,7 @@ int mergeback_code_files(Project &proj)
#if 1
if (!Fluid.batch_mode) {
// Depending on the workflow in interactive mode, an external copy of
- // Fluid may have written the source code elswhere (e.g. in a CMake setup).
+ // Fluid may have written the source code elsewhere (e.g. in a CMake setup).
// Fluid tries to keep track of the last write location of a source file
// matching a project, and uses that location instead.
// TODO: this is not working as expected yet.
@@ -656,15 +666,32 @@ int mergeback_code_files(Project &proj)
}
if (!Fluid.batch_mode) proj.leave_project_dir();
- if (c==0) fl_message("Comparing\n \"%s\"\nto\n \"%s\"\n\n"
- "MergeBack found no external modifications\n"
- "in the source code.",
- code_filename.c_str(), proj_filename.c_str());
- if (c==-2) fl_message("No corresponding source code file found.");
+ if (feedback & Mergeback::CHATTY) {
+ if (c==0) fl_message("Comparing\n \"%s\"\nto\n \"%s\"\n\n"
+ "MergeBack found no external modifications\n"
+ "in the source code.",
+ code_filename.c_str(), proj_filename.c_str());
+ if (c==-2) fl_message("No corresponding source code file found.");
+ }
+ recursion_lock = false;
return c;
}
void mergeback_cb(Fl_Widget *, void *) {
- mergeback_code_files(Fluid.proj);
+ mergeback_code_files(Fluid.proj, Mergeback::CHATTY);
+}
+
+void mergeback_on_load() {
+ mergeback_code_files(Fluid.proj, Mergeback::QUIET);
+}
+
+static int app_event_handler(int event) {
+ if (event == FL_APP_ACTIVATE) {
+ mergeback_code_files(Fluid.proj, Mergeback::QUIET);
+ }
+ return 0;
}
+void start_auto_mergeback() {
+ Fl::add_handler(app_event_handler);
+}
diff --git a/fluid/proj/mergeback.h b/fluid/proj/mergeback.h
index f395717f8..a515b1815 100644
--- a/fluid/proj/mergeback.h
+++ b/fluid/proj/mergeback.h
@@ -35,13 +35,14 @@ namespace proj {
*/
class Mergeback
{
- public:
+public:
enum class Tag {
GENERIC = 0, CODE, MENU_CALLBACK, WIDGET_CALLBACK, UNUSED_
};
enum class Task {
ANALYSE = 0, INTERACTIVE, APPLY, APPLY_IF_SAFE = 3
};
+ enum Feedback { QUIET = 0, CHATTY = 1 };
protected:
/// Apply mergeback for this project.
Project &proj_;
@@ -88,5 +89,8 @@ extern int merge_back(const std::string &s, const std::string &p, int task);
} // namespace proj
} // namespace fld
+extern void start_auto_mergeback();
+extern void mergeback_on_load();
+
#endif // FLUID_PROJ_MERGEBACK_H