Skip to content

Commit

Permalink
Preference window resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
robertklep committed Aug 25, 2017
1 parent 90e9d2e commit da08d85
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions quotefix/preferences.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding:utf-8 -*-
from AppKit import NSPreferencesModule, NSNib, NSBox, NSNibTopLevelObjects, NSNibOwner, NSObject, NSPreferences, NSWorkspace, NSURL, NSBundle, NSImage, NSDateFormatter, NSLocale, NSDateFormatterMediumStyle, NSColor, MessageViewer
from AppKit import NSPreferencesModule, NSNib, NSBox, NSNibTopLevelObjects, NSNibOwner, NSObject, NSPreferences, NSWorkspace, NSURL, NSBundle, NSImage, NSDateFormatter, NSLocale, NSDateFormatterMediumStyle, NSColor, MessageViewer, NSSize
from Foundation import NSLog
from quotefix.utils import swizzle, htmlunescape
from quotefix.attribution import CustomizedAttribution
Expand All @@ -8,6 +8,10 @@
from logger import logger
import objc, random, re

PREF_WIDTH = 723
PREF_HEIGHT = 485
TAB_ITEM_HEIGHT = 78

class QuoteFixPreferencesModule(NSPreferencesModule):

def init(self):
Expand All @@ -29,8 +33,9 @@ def isResizable(self):

try:
# High Sierra
MailPreferences = objc.lookUpClass('MailPreferences')
MailApp = objc.lookUpClass('MailApp')
MailPreferences = objc.lookUpClass('MailPreferences')
MailApp = objc.lookUpClass('MailApp')
MailTabViewController = objc.lookUpClass('MailTabViewController');

class QuoteFixPreferences(MailPreferences):

Expand All @@ -44,12 +49,35 @@ class QuoteFixMailApp(MailApp):

@swizzle(MailApp, 'showPreferencesPanel:')
def showPreferencesPanel_(self, original, id):
# inject preferences module
prefs = NSPreferences.sharedPreferences()
if prefs: QuoteFixPreferences.injectPreferencesModule(prefs)
if prefs:
QuoteFixPreferences.injectPreferencesModule(prefs)

# call original
original(self, id)

except:
class QuoteFixMailTabViewController(MailTabViewController):

@swizzle(MailTabViewController, 'setSelectedTabViewItemIndex:')
def setSelectedTabViewItemIndex_(self, original, idx):
prefWindow = self.tabView().window()
original(self, idx)
if not prefWindow:
return

# Is the selected item ours?
newTabItem = self.tabViewItems().objectAtIndex_(idx)
if not newTabItem or newTabItem.label() != 'QuoteFix':
return

# Adjust width and height of preferences window to our preferred values
frame = prefWindow.frame()
frame.size.height = PREF_HEIGHT + TAB_ITEM_HEIGHT
frame.size.width = PREF_WIDTH
prefWindow.setFrame_display_(frame, False)

except:
class QuoteFixPreferences(NSPreferences):

@classmethod
Expand Down Expand Up @@ -84,10 +112,6 @@ class QuoteFixPreferencesController(NSObject):
@classmethod
def registerQuoteFixApplication(cls, app):
cls.app = app
# inject preferences module
#prefs = NSPreferences.sharedPreferences()
#if prefs:
# QuoteFixPreferences.injectPreferencesModule(prefs)

@objc.IBAction
def changeDebugging_(self, sender):
Expand Down

0 comments on commit da08d85

Please sign in to comment.