summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2016-08-16 21:20:06 +0000
committerGreg Ercolano <erco@seriss.com>2016-08-16 21:20:06 +0000
commit4e7603f26e90ef341925e2344a328ce4c01e0fe7 (patch)
treefb3e13c4e399476c47b895f8257eb460ad6a4702 /fluid
parent5f445ab306211bbca6c676a1fbbcf33678d74f61 (diff)
Bringing over fix [11878+11879] from 1.3 current to the porting branch.
Solves STR #3318: options for how to handle external editors on fluid quit git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11880 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'fluid')
-rw-r--r--fluid/ExternalCodeEditor_UNIX.cxx31
-rw-r--r--fluid/ExternalCodeEditor_UNIX.h1
-rw-r--r--fluid/ExternalCodeEditor_WIN32.cxx31
-rw-r--r--fluid/ExternalCodeEditor_WIN32.h1
4 files changed, 62 insertions, 2 deletions
diff --git a/fluid/ExternalCodeEditor_UNIX.cxx b/fluid/ExternalCodeEditor_UNIX.cxx
index 58225fc88..06de7f503 100644
--- a/fluid/ExternalCodeEditor_UNIX.cxx
+++ b/fluid/ExternalCodeEditor_UNIX.cxx
@@ -54,7 +54,7 @@ ExternalCodeEditor::~ExternalCodeEditor() {
if ( G_debug )
printf("ExternalCodeEditor() DTOR CALLED (this=%p, pid=%ld)\n",
(void*)this, (long)pid_);
- kill_editor(); // Kill open editor, deletes tmp file
+ close_editor(); // close editor, delete tmp file
set_filename(0); // free()s filename
}
@@ -71,6 +71,35 @@ int ExternalCodeEditor::is_editing() {
return( (pid_ != -1) ? 1 : 0 );
}
+// [Protected] Wait for editor to close
+void ExternalCodeEditor::close_editor() {
+ if ( G_debug ) printf("close_editor() called: pid=%ld\n", long(pid_));
+ // Wait until editor is closed + reaped
+ while ( is_editing() ) {
+ switch ( reap_editor() ) {
+ case -1: // error
+ fl_alert("Error reaping external editor\n"
+ "pid=%ld file=%s", long(pid_), filename());
+ break;
+ case 0: // process still running
+ switch ( fl_choice("Please close external editor\npid=%ld file=%s",
+ "Force Close", // button 0
+ "Closed", // button 1
+ 0, // button 2
+ long(pid_), filename() ) ) {
+ case 0: // Force Close
+ kill_editor();
+ continue;
+ case 1: // Closed? try to reap
+ continue;
+ }
+ break;
+ default: // process reaped
+ return;
+ }
+ }
+}
+
// [Protected] Kill the running editor (if any)
// Kills the editor, reaps the process, and removes the tmp file.
// The dtor calls this to ensure no editors remain running when fluid exits.
diff --git a/fluid/ExternalCodeEditor_UNIX.h b/fluid/ExternalCodeEditor_UNIX.h
index 3ebaeb6ff..e983c5cfa 100644
--- a/fluid/ExternalCodeEditor_UNIX.h
+++ b/fluid/ExternalCodeEditor_UNIX.h
@@ -32,6 +32,7 @@ public:
~ExternalCodeEditor();
int is_editing();
pid_t reap_editor();
+ void close_editor();
const char *filename() { return filename_; }
int open_editor(const char *editor_cmd, const char *code);
int handle_changes(const char **code, int force=0);
diff --git a/fluid/ExternalCodeEditor_WIN32.cxx b/fluid/ExternalCodeEditor_WIN32.cxx
index 53170b643..ba7a2775c 100644
--- a/fluid/ExternalCodeEditor_WIN32.cxx
+++ b/fluid/ExternalCodeEditor_WIN32.cxx
@@ -72,7 +72,7 @@ ExternalCodeEditor::ExternalCodeEditor() {
// DTOR
ExternalCodeEditor::~ExternalCodeEditor() {
- kill_editor(); // Kill any open editors, deletes tmp file
+ close_editor(); // close editor, delete tmp file
set_filename(0); // free()s filename
}
@@ -132,6 +132,35 @@ static int terminate_app(DWORD pid, DWORD msecTimeout) {
return ret;
}
+// [Protected] Wait for editor to close
+void ExternalCodeEditor::close_editor() {
+ if ( G_debug ) printf("close_editor() called: pid=%ld\n", long(pinfo_.dwProcessId));
+ // Wait until editor is closed + reaped
+ while ( is_editing() ) {
+ switch ( reap_editor() ) {
+ case -1: // error
+ fl_alert("Error reaping external editor\n"
+ "pid=%ld file=%s", long(pinfo_.dwProcessId), filename());
+ break;
+ case 0: // process still running
+ switch ( fl_choice("Please close external editor\npid=%ld file=%s",
+ "Force Close", // button 0
+ "Closed", // button 1
+ 0, // button 2
+ long(pinfo_.dwProcessId), filename() ) ) {
+ case 0: // Force Close
+ kill_editor();
+ continue;
+ case 1: // Closed? try to reap
+ continue;
+ }
+ break;
+ default: // process reaped
+ return;
+ }
+ }
+}
+
// [Protected] Kill the running editor (if any) and cleanup
// Kills the editor, reaps the process, and removes the tmp file.
// The dtor calls this to ensure no editors remain running when fluid exits.
diff --git a/fluid/ExternalCodeEditor_WIN32.h b/fluid/ExternalCodeEditor_WIN32.h
index 96a3f7f4f..90b272cae 100644
--- a/fluid/ExternalCodeEditor_WIN32.h
+++ b/fluid/ExternalCodeEditor_WIN32.h
@@ -44,6 +44,7 @@ public:
~ExternalCodeEditor();
int is_editing();
DWORD reap_editor();
+ void close_editor();
const char *filename() { return filename_; }
int open_editor(const char *editor_cmd, const char *code);
int handle_changes(const char **code, int force=0);