Show last 5 history items in the menu bar for quick access
This commit is contained in:
parent
94b6c4ac7e
commit
8046fb8af2
|
@ -19,9 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#import "NetsurfCallback.h"
|
||||
#import "Website.h"
|
||||
|
||||
#define TAG_MENU_REMOVE 5
|
||||
#define TAG_MENU_CANCEL 3
|
||||
#define TAG_MENU_OPEN 12
|
||||
#define TAG_MENU_REMOVE 206
|
||||
#define TAG_MENU_CANCEL 204
|
||||
#define TAG_MENU_OPEN 103
|
||||
#define TAG_SUBMENU_HISTORY 500
|
||||
|
||||
@interface AppDelegate: NSResponder<NSApplicationDelegate> {
|
||||
@private
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#import "DownloadsWindowController.h"
|
||||
#import "FindPanelController.h"
|
||||
#import "HistoryWindowController.h"
|
||||
#import "Website.h"
|
||||
|
||||
/**
|
||||
* Set option defaults for (taken from the cocoa frontend)
|
||||
|
@ -39,11 +40,38 @@ static nserror set_defaults(struct nsoption_s *defaults)
|
|||
-(void)applicationDidFinishLaunching: (NSNotification*)aNotification {
|
||||
NSLog(@"NSApp did finish launching..");
|
||||
[NSBundle loadNibNamed: @"Menu" owner: NSApp];
|
||||
[self didTapNewWindow: self];
|
||||
}
|
||||
|
||||
-(void)historyUpdated: (NSNotification*)aNotification {
|
||||
NSLog(@"history updated...");
|
||||
NSArray *history = [Website historicWebsites];
|
||||
NSMenu *historyMenu = [[[NSApp menu] itemWithTag: TAG_SUBMENU_HISTORY] submenu];
|
||||
for (NSInteger i = [historyMenu numberOfItems] - 1; i > 0; i--) {
|
||||
[historyMenu removeItemAtIndex: i];
|
||||
}
|
||||
Website *website;
|
||||
NSMenuItem *menuItem;
|
||||
for (NSInteger i = 0; i < [history count] && i < 5; i++) {
|
||||
website = [history objectAtIndex: i];
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle: [website name]
|
||||
action: @selector(open) keyEquivalent: nil] autorelease];
|
||||
[menuItem setTarget: website];
|
||||
[historyMenu addItem: menuItem];
|
||||
}
|
||||
[historyMenu update];
|
||||
}
|
||||
|
||||
-(void)awakeFromNib {
|
||||
NSLog(@"App awake from nib");
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector(historyUpdated:)
|
||||
name: WebsiteHistoryUpdatedNotificationName
|
||||
object: nil];
|
||||
[self historyUpdated: nil];
|
||||
}
|
||||
|
||||
-(void)didTapNewWindow: (id)sender {
|
||||
NSLog(@"Will create a new window");
|
||||
NSLog(@"Will create a new window %@", self);
|
||||
struct nsurl *url;
|
||||
nserror error;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@interface FindPanelController : NSWindowController {
|
||||
id previousButton;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
#include "FindPanelController.h"
|
||||
#include "BrowserWindowController.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
#import "FindPanelController.h"
|
||||
#import "BrowserWindowController.h"
|
||||
|
||||
@implementation FindPanelController
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
-(void)registerForHistoryNotifications {
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector(updateItems:)
|
||||
name: HISTORY_UPDATED_NOTIFICATION
|
||||
name: WebsiteHistoryUpdatedNotificationName
|
||||
object: nil];
|
||||
}
|
||||
-(void)showWindow: (id)sender {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@interface PlotView: NSView {
|
||||
void *browser;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#define HISTORY_UPDATED_NOTIFICATION @"history_updated"
|
||||
#define WebsiteHistoryUpdatedNotificationName @"WebsiteHistoryUpdatedNotification"
|
||||
|
||||
@class BookmarkFolder;
|
||||
@interface Website: NSObject {
|
||||
|
@ -13,6 +13,8 @@
|
|||
-(NSString*)name;
|
||||
-(NSURL*)url;
|
||||
|
||||
-(void)open;
|
||||
|
||||
-(void)addToHistory;
|
||||
-(void)removeFromHistory;
|
||||
+(NSArray*)historicWebsites;
|
||||
|
|
|
@ -33,6 +33,10 @@ static NSMutableArray *history;
|
|||
return url;
|
||||
}
|
||||
|
||||
-(void)open {
|
||||
[[NSApp delegate] openWebsite: self];
|
||||
}
|
||||
|
||||
// MARK: - History implementation
|
||||
|
||||
+(id)websiteWithDictionary: (NSDictionary*)dictionary {
|
||||
|
@ -103,7 +107,7 @@ static NSMutableArray *history;
|
|||
NSLog(@"remove self from history");
|
||||
[history removeObject: self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
HISTORY_UPDATED_NOTIFICATION object: nil];
|
||||
WebsiteHistoryUpdatedNotificationName object: nil];
|
||||
}
|
||||
|
||||
-(void)addToHistory {
|
||||
|
@ -113,7 +117,7 @@ static NSMutableArray *history;
|
|||
[history insertObject: self atIndex: 0];
|
||||
NSLog(@"Added %@ , %@ to history!", [self name], [self url]);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
HISTORY_UPDATED_NOTIFICATION object: nil];
|
||||
WebsiteHistoryUpdatedNotificationName object: self];
|
||||
}
|
||||
|
||||
+(NSArray*)historicWebsites {
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue