Browse Source

mac: Add app.addRecentDocument API

Cheng Zhao 10 years ago
parent
commit
c23ba7b504

+ 2 - 0
atom/browser/api/atom_api_app.cc

@@ -158,6 +158,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
       .SetMethod("getName", base::Bind(&Browser::GetName, browser))
       .SetMethod("setName", base::Bind(&Browser::SetName, browser))
       .SetMethod("isReady", base::Bind(&Browser::is_ready, browser))
+      .SetMethod("addRecentDocument",
+                 base::Bind(&Browser::AddRecentDocument, browser))
       .SetMethod("getDataPath", &App::GetDataPath)
       .SetMethod("resolveProxy", &App::ResolveProxy)
       .SetMethod("setDesktopName", &App::SetDesktopName);

+ 7 - 0
atom/browser/browser.h

@@ -13,6 +13,10 @@
 #include "atom/browser/browser_observer.h"
 #include "atom/browser/window_list_observer.h"
 
+namespace base {
+class FilePath;
+}
+
 namespace ui {
 class MenuModel;
 }
@@ -48,6 +52,9 @@ class Browser : public WindowListObserver {
   // Overrides the application name.
   void SetName(const std::string& name);
 
+  // Add the |path| to recent documents list.
+  void AddRecentDocument(const base::FilePath& path);
+
 #if defined(OS_MACOSX)
   // Bounce the dock icon.
   enum BounceType {

+ 3 - 0
atom/browser/browser_linux.cc

@@ -24,6 +24,9 @@ void Browser::Focus() {
   }
 }
 
+void Browser::AddRecentDocument(const base::FilePath& path) {
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   return ATOM_VERSION_STRING;
 }

+ 6 - 0
atom/browser/browser_mac.mm

@@ -9,6 +9,7 @@
 #include "atom/browser/native_window.h"
 #include "atom/browser/window_list.h"
 #import "base/mac/bundle_locations.h"
+#import "base/mac/foundation_util.h"
 #include "base/strings/sys_string_conversions.h"
 
 namespace atom {
@@ -17,6 +18,11 @@ void Browser::Focus() {
   [[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
 }
 
+void Browser::AddRecentDocument(const base::FilePath& path) {
+  NSURL* u = [NSURL fileURLWithPath:base::mac::FilePathToNSString(path)];
+  [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   NSDictionary* infoDictionary = base::mac::OuterBundle().infoDictionary;
   NSString *version = [infoDictionary objectForKey:@"CFBundleVersion"];

+ 3 - 0
atom/browser/browser_win.cc

@@ -39,6 +39,9 @@ void Browser::Focus() {
   EnumWindows(&WindowsEnumerationHandler, reinterpret_cast<LPARAM>(&pid));
 }
 
+void Browser::AddRecentDocument(const base::FilePath& path) {
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   base::FilePath path;
   if (PathService::Get(base::FILE_EXE, &path)) {