Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit f759e16

Browse files
committed
Save file on close. Uses patched CEF build. See http://code.google.com/p/chromiumembedded/issues/detail?id=780
1 parent c18b322 commit f759e16

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

appshell/appshell_extensions_gtk.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
int ConvertLinuxErrorCode(int errorCode, bool isReading = true);
3636

37+
extern bool isReallyClosing;
38+
3739
static const char* GetPathToLiveBrowser()
3840
{
3941
//#TODO Use execlp and be done with it! No need to reinvent the wheel; so badly that too!
@@ -325,7 +327,13 @@ int DeleteFileOrDirectory(ExtensionString filename)
325327
void CloseWindow(CefRefPtr<CefBrowser> browser)
326328
{
327329
if (browser.get()) {
328-
browser->GetHost()->CloseBrowser();
330+
isReallyClosing = true;
331+
// //# Hack because CEF's CloseBrowser() is bad. Should emit delete_event instead of directly destroying widget
332+
// GtkWidget* hwnd = gtk_widget_get_toplevel (browser->GetHost()->GetWindowHandle() );
333+
// if(gtk_widget_is_toplevel (hwnd))
334+
// gtk_signal_emit_by_name(GTK_OBJECT(hwnd), "delete_event");
335+
// else
336+
browser->GetHost()->CloseBrowser();
329337
}
330338
}
331339

appshell/cefclient_gtk.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
char szWorkingDir[512]; // The current working directory
1919
std:: string szInitialUrl;
2020
std:: string szRunningDir;
21+
bool isReallyClosing = false;
2122

2223
// The global ClientHandler reference.
2324
extern CefRefPtr<ClientHandler> g_handler;
@@ -26,14 +27,23 @@ extern CefRefPtr<ClientHandler> g_handler;
2627
time_t g_appStartupTime;
2728

2829
void destroy(void) {
29-
printf("Gonna die! \n");
3030
CefQuitMessageLoop();
3131
}
3232

3333
void TerminationSignalHandler(int signatl) {
3434
destroy();
3535
}
3636

37+
static gboolean HandleQuit(int signatl) {
38+
if (!isReallyClosing && g_handler.get() && g_handler->GetBrowserId()) {
39+
CefRefPtr<CommandCallback> callback = new CloseWindowCommandCallback(g_handler->GetBrowser());
40+
41+
g_handler->SendJSCommand(g_handler->GetBrowser(), FILE_CLOSE_WINDOW, callback);
42+
return TRUE;
43+
}
44+
destroy();
45+
}
46+
3747
int GetInitialUrl() {
3848
GtkWidget *dialog;
3949
const char* dialog_title = "Please select the index.html file";
@@ -76,7 +86,6 @@ std::string AppGetRunningDirectory() {
7686
if(buf[len] == '/'){
7787
buf[len] = '\0';
7888
szRunningDir.append(buf);
79-
printf("szRunningDir: %s\n", szRunningDir.c_str());
8089
return szRunningDir;
8190
}
8291
}
@@ -150,10 +159,12 @@ int main(int argc, char* argv[]) {
150159

151160
GtkWidget* m_editWnd = gtk_entry_new();
152161

162+
g_signal_connect(G_OBJECT(window), "delete_event",
163+
G_CALLBACK(HandleQuit), NULL);
153164
g_signal_connect(G_OBJECT(window), "destroy",
154165
G_CALLBACK(gtk_widget_destroyed), &window);
155-
g_signal_connect(G_OBJECT(window), "destroy",
156-
G_CALLBACK(destroy), NULL);
166+
// g_signal_connect(G_OBJECT(window), "destroy",
167+
// G_CALLBACK(destroy), NULL);
157168

158169
// Create the handler.
159170
g_handler = new ClientHandler();

0 commit comments

Comments
 (0)