Plugins/Dual Window Interface/AIJumpControlPlugin.m
author Zachary West <zacw@adium.im>
Mon Nov 02 18:30:22 2009 -0500 (2009-11-02)
changeset 2728 bb4935318350
parent 1946 866f1f27b315
permissions -rw-r--r--
Instead of inserting a <hr/> when we lose focus, which ends up breaking more than you'd expect, add a message class for the next message. Fixes #13300.

This removes the "Show Focus Lines" preference (always a good thing), and always inserts the mark in the scrollbar. It will be up to the style to implement the "focus" class to show the location. All previous messages of class "focus" will have "focus" removed when focus is lost again.
     1 //
     2 //  AIJumpControlPlugin.m
     3 //  Adium
     4 //
     5 //  Created by Zachary West on 2009-04-04.
     6 //
     7 
     8 #import "AIJumpControlPlugin.h"
     9 #import <AIUtilities/AIMenuAdditions.h>
    10 #import <AIUtilities/JVMarkedScroller.h>
    11 #import <AIUtilities/AIWindowAdditions.h>
    12 #import <Adium/AIInterfaceControllerProtocol.h>
    13 #import <Adium/AIMenuControllerProtocol.h>
    14 #import <Adium/AIChat.h>
    15 #import "AIMessageViewController.h"
    16 #import "AIMessageTabViewItem.h"
    17 
    18 #define PREF_KEY_FOCUS_LINE	@"Draw Focus Lines"
    19 
    20 @interface AIJumpControlPlugin()
    21 - (NSObject<AIMessageDisplayController> *)currentController;
    22 @end
    23 
    24 @implementation AIJumpControlPlugin
    25 - (void)installPlugin
    26 {
    27 	menuItem_previous = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Jump to Previous Mark", "Jump to the previous mark in the message window")
    28 															   target:self
    29 															   action:@selector(jumpToPrevious)
    30 														keyEquivalent:@"["
    31 															  keyMask:NSAlternateKeyMask | NSCommandKeyMask];
    32 	
    33 	[adium.menuController addMenuItem:menuItem_previous toLocation:LOC_Display_Jump];
    34 	
    35 	menuItem_next = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Jump to Next Mark", "Jump to the next mark in the message window")
    36 														   target:self
    37 														   action:@selector(jumpToNext)
    38 													keyEquivalent:@"]"
    39 														  keyMask:NSAlternateKeyMask | NSCommandKeyMask];
    40 	
    41 	[adium.menuController addMenuItem:menuItem_next toLocation:LOC_Display_Jump];
    42 	
    43 	menuItem_focus = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Jump to Focus Mark", "Jump to the next location in the message window where the user last saw content")
    44 															target:self
    45 															action:@selector(jumpToFocus)
    46 													 keyEquivalent:@""];
    47 	
    48 	[adium.menuController addMenuItem:menuItem_focus toLocation:LOC_Display_Jump];
    49 	
    50 	menuItem_add = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Add Mark", "Inserts a custom mark into the message window")
    51 														  target:self
    52 														  action:@selector(addMark)
    53 												   keyEquivalent:@""];
    54 	
    55 	[adium.menuController addMenuItem:menuItem_add toLocation:LOC_Display_Jump];
    56 }
    57 
    58 - (void)uninstallPlugin
    59 {
    60 	[adium.menuController removeMenuItem:menuItem_previous];
    61 	[adium.menuController removeMenuItem:menuItem_next];
    62 	[adium.menuController removeMenuItem:menuItem_focus];
    63 	[adium.menuController removeMenuItem:menuItem_add];
    64 }
    65 
    66 #pragma mark Jump handling
    67 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
    68 {
    69 	if (menuItem == menuItem_previous) {
    70 		return [self.currentController previousMarkExists];
    71 	} else if (menuItem == menuItem_next) {
    72 		return [self.currentController nextMarkExists];
    73 	} else if (menuItem == menuItem_focus) {
    74 		return [self.currentController focusMarkExists];
    75 	}
    76 	
    77 	return (nil != adium.interfaceController.activeChat);
    78 }
    79 
    80 - (NSObject<AIMessageDisplayController> *)currentController
    81 {
    82 	return adium.interfaceController.activeChat.chatContainer.messageViewController.messageDisplayController;
    83 }
    84 
    85 - (void)jumpToPrevious
    86 {
    87 	[self.currentController jumpToPreviousMark];
    88 }
    89 
    90 - (void)jumpToNext
    91 {
    92 	[self.currentController jumpToNextMark];
    93 }
    94 
    95 - (void)jumpToFocus
    96 {
    97 	[self.currentController jumpToFocusMark];
    98 }
    99 
   100 - (void)addMark
   101 {
   102 	[self.currentController addMark];
   103 }
   104 
   105 @end