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

Add support for specifying and remembering the brackets index.html location #4

Merged
merged 3 commits into from
Jun 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion appshell/cefclient_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

char szWorkingDir[512]; // The current working directory

NSURL* startupUrl = [NSURL URLWithString:@""];

#ifdef SHOW_TOOLBAR_UI
// Sizes for URL bar layout
#define BUTTON_HEIGHT 22
Expand Down Expand Up @@ -300,7 +302,7 @@ - (void)createApp:(id)object {

window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
CefBrowserHost::CreateBrowser(window_info, g_handler.get(),
"http://www.google.com", settings);
[[startupUrl absoluteString] UTF8String], settings);

// Show the window.
[mainWnd makeKeyAndOrderFront: nil];
Expand Down Expand Up @@ -365,6 +367,24 @@ int main(int argc, char* argv[]) {
// Initialize CEF.
CefInitialize(main_args, settings, app.get());

// Load the startup path from prefs
CGEventRef event = CGEventCreate(NULL);
CGEventFlags modifiers = CGEventGetFlags(event);
CFRelease(event);

// Only load the prefs if the shift key isn't down
if ((modifiers & kCGEventFlagMaskShift) != kCGEventFlagMaskShift)
startupUrl = [[NSUserDefaults standardUserDefaults] URLForKey:@"initialUrl"];

if ([[startupUrl absoluteString] isEqualToString:@""]) {
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setTitle:@"Choose startup file"];
if ([openPanel runModal] == NSOKButton) {
startupUrl = [NSURL fileURLWithPath:[[openPanel filenames] objectAtIndex:0]];
[[NSUserDefaults standardUserDefaults] setURL:startupUrl forKey:@"initialUrl"];
}
}

// Create the application delegate and window.
NSObject* delegate = [[ClientAppDelegate alloc] init];
[delegate performSelectorOnMainThread:@selector(createApp:) withObject:nil
Expand Down
34 changes: 33 additions & 1 deletion appshell/cefclient_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
char szWorkingDir[MAX_PATH]; // The current working directory

TCHAR szInitialUrl[MAX_PATH] = {0};

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
Expand Down Expand Up @@ -89,6 +91,36 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

HKEY hKey;
DWORD lResult;
#define PREF_NAME L"Software\\Brackets\\InitialURL"

// Don't read the prefs if the shift key is down
if (GetAsyncKeyState(VK_SHIFT) == 0) {
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, KEY_READ, &hKey)) {
DWORD length = MAX_PATH;
RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)szInitialUrl, &length);
RegCloseKey(hKey);
}
}

if (!wcslen(szInitialUrl)) {
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szInitialUrl;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER;

if (GetOpenFileName(&ofn)) {
lResult = RegCreateKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (lResult == ERROR_SUCCESS) {
RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)szInitialUrl, (wcslen(szInitialUrl) + 1) * 2);
RegCloseKey(hKey);
}
}
}

// Perform application initialization
if (!InitInstance (hInstance, nCmdShow))
Expand Down Expand Up @@ -302,7 +334,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
// Creat the new child browser window
CefBrowserHost::CreateBrowser(info,
static_cast<CefRefPtr<CefClient> >(g_handler),
"http://www.google.com", settings);
szInitialUrl, settings);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion appshell/config.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SHOW_TOOLBAR_UI
// #define SHOW_TOOLBAR_UI