/////////////////////////////////////////////////////////////
//			Modification by mitsu	1.25-jx8
/////////////////////////////////////////////////////////////

This is a brief explanation on the additions and modification 
I made to TeXShop 1.25.  

Additions and changes in the source codes are marked like 
// added by mitsu --(*) explanation
and 
// end addition
So you can simply search "mitsu" in an editor to locate where 
they are.  

Here is the list of changes I made:

(A) Key filtering for backslash and yen
(B) Support for other Japanese encodings
(C) Pasteboard conversion for backslash and yen
(D) Tags menu with yen character in MacJapanese
(E) LaTeX panel conversion in MacJapanese
(F) Yen in Cosole window
(G) A class EncodingSupport

(H) MacroMenu and MacroEditor
(I) Magnifying glass in Preview Window
(J) Command-T for Typeset and program popup button
(K) The name of new documents: "Unititled-n"
(L) TeX Input in Console window
(M) Path Settings on "okButtonPressed:" in TSPreferences
(N) Support for .def, .fd, .ltx, .clo files

The items (A)-(G) are related to Japanese encodings.  
In MacJapanese encoding, yen symbol was used as the TeX character 
instead of backslash.  I wrote in a separate text "backslash and 
yen.txt" a background information on this problem.  
TeXShop addresses this problem by translating files using MacJapanese 
encoding and dealing separately in coloring and tag routines.  However 
we still experienced several problems and I am proposing some fixes.  

/////////////////////////////////////////////////////////////
(A) Key filtering for backslash and yen
With JIS keyboard, which is common in Japan, the backslash key was 
replaced by yen key and it produces Unicode yen symbol in MacOS X.  
On the other hand, Japanese users with US keyboard could not enter yen symbol 
from keyboard.  The keyboard produces backslash, which is OK with other 
encoding but not with MacJapanese.  (It was actually possible through 
"1 byte English mode" of Japanese Input Methods. But many users including 
me switch Japanese and English environment by switching the Keyboard 
(command+space), so we had this problem.) As I mention in (B), I also 
added other Japanese encodings (see (B) below) which uses backslash 
as TeX character. This time Japanese users with JIS keyboard have 
problems in the other way.  I also added a support for this problem.  

The problem occurred in three places: Main TeX Window, Find Panel and 
TeX Input field of Console Window.  I added filters which convert 
backslash and yen in Japanese encodings. 

// In source codes
In Main TeX Window, I added "insertText:" to "MyTextView.m" in order to 
intercept the input.  (This overrides "insertText:" of NSTextView.)
In Find Panel and TeX Input field of Console Window, I assigned a delegate 
"EncodingSupport" (see (G)) which implements 
- (void)controlTextDidChange:(NSNotification *)note;
and whenever the text is changed in those fields, it converts the tex 
character.  
Actual filtering for both cases is done by the C-functions 
"filterBackslashToYen" and "filterYenToBackslash" in 
"EncodingSupport.m". 
 
/////////////////////////////////////////////////////////////
(B) Support for other Japanese encodings
There are three Japanese encodings ShiftJIS, EUC and JIS.  
ShiftJIS is used by Mac and Windows, EUC and JIS by UNIX.  There are 
Japanese TeX (called pTeX) distributions for each encoding. 
So I added the support for EUC and JIS. Also I learned that 
another ShiftJIS encoding on MacOS X, called "DOSJapanese" has an 
advantage that the backslash in the data is not converted to yen.  
I also added a support for this encoding.  So there are four Japanese 
encodings: 
Japanese(ShiftJIS yen), 
Japanese(ShiftJIS backslash), 
Japanese(EUC), 
Japanese(JIS).  
The first one is equal to the original MacJapanese and uses yen as 
TeX characters, others use backslash as TeX character.  The second one 
is equal to DOSJapanese.  By the change of the name, the popup button 
for encodings in Preferences dialog become a bit too narrow, so I 
widened it a little.  

/////////////////////////////////////////////////////////////
(C) Pasteboard coversion for backslash and yen
The problem of backslash and yen is also reflected in copying 
and pasting.  forexample, when one copies text to/from other softwares 
such as Japanese Text Editors or Mail Softwares, it may be 
preferable to use yen symbol because they can treat it 
as if it was a backslash.  I added the following conversion 
feature: 
Pasting to TeXShop:
backslash and yen are converted to the correct TeX character, i.e. 
yen in Japanese(ShiftJIS yen), and backslash in three other encodings.  
Copying from TeXShop:
The TeX charcater can be converted into backslash or yen.  While in 
a Japanese encoding, a menu item appears at the bottom of Edit Menu, 
which allows you to choose this option.  
In Japanese(ShiftJIS yen), the item is "Convert yen to backslash in 
Pasteboard" and the default is off.  In the other encodings, it is 
"Convert backslash to yen in Pasteboard" and the default is on.  
aka MacJapanese encoding:
backslashes in the pasteboard will be converted to yens when pasted.
In DOSJapanese and EUC Japanese encoding: 
backslashes in the selected text will be converted to yens when copied/cut.
yens in the pasteboard will be converted to backslashes when pasted.
Tthe option is useless for non-Japanese users and can be confusing.  
(The author may be bothered by questions about it.)  Hence I made it 
so that it only appears when Japanese encodings are selected.  

// In source codes
I added "writeSelectionToPasteboard:type:" and 
"readSelectionFromPasteboard:type:" to "MyTextView.m" to filter 
the string to be copied and pasted.  (They override the same 
methods of NSTextView.) 
Adding and deleting the menu item is handled in "EncodingSupport.m"

/////////////////////////////////////////////////////////////
(D) Tags menu with yen character in MacJapanese
Although you switched tex characters in "doTag" and "fixTags", 
you did not change "kTaggedTeXSections".  Therefore the tags 
menu did not work in MacJapanese, except for "#:".  

// In source code 
"texChar" and "kTaggedTeXSections" are initialized in "EncodingSupport" 
and they will be reset when the encoding is changed. "fixTags" 
will also be called after an encoding change, via notification.  
An alternative is to call filter functions before "kTaggedTeXSections" 
are being used.  I think my way is simpler and produces less problem 
when you want to modify the routine for the tags in the future.  
// and more...
I wonder if Tags menu can be changed so that 
other tags such as "\tag{}", "\label{}", not necessarily at 
the beginning of lines, are also listed.  
Does it consume too much time?

/////////////////////////////////////////////////////////////
(E) LaTeX panel conversion
I made it so that Japanese users do not have to replace the 
LaTeX Panel.  
// In source code
insertText is called in "doCompletion:" in "MyDocument.m".  
MyTextView's insertText: will convert TeX characters.  
// by the way, 
You mentioned in "ReadMe.rtf" for Japanese that the Templates 
files should be replaced, but this is not correct.  You already 
have a code which translates encoding when reading Templates files.  
So English templates files can be used wihout changes.  

/////////////////////////////////////////////////////////////
(F) Yen in Cosole window
When a tex input in console window is required, 
yen symbol in MacJapanese was not recognized.  (For example, 
when compiling an incomplete tex document, one needs to input 
"\end".)
// In source code 
A filter function is called in "doTexCommand:" in 
"MyDocument.m".  

/////////////////////////////////////////////////////////////
(G) A class EncodingSupport
This class concentrates the handling of encoding and filtering 
which are required in (A)-(F).  It provides:
--Initialization of yenString which is used in filters
--Filter functions, filterBackslashToYen and filterYenToBackslash, 
which do not belong to this class, merely in the source file
--Set up a flag "shouldFilter" which is used in various places, 
in order to judge whether or not to filter backslash and yen
--Set up global variables "texChar" and "kTaggedTeXSections" 
which are used in Coloring and Tags menu routines
--Set up menu item "Convert backslash to yen in Pasteboard" 
or "Convert yen to backslash in Pasteboard" mentioned in (C)
--A delegate method "controlTextDidChange:" for text fields 
mentioned in (A)
--Set up a global variable "currentEncodingID" which is used in 
"dataRepresentationOfType:", "readFromFile:ofType:", "doTemplate" 
and "writeTexOutput", for encoding/decoding.

// In source code
I added the class "EncodingSupport".  It is in fact not absolutely 
necessary to concentrate all the functionality.  You can also 
scatter them around in the source codes, but it will make 
the codes more difficult to read.  In "TSPreferences", I added 
handler for "encodingTouched" and "Encoding Changed" notification.  

/////////////////////////////////////////////////////////////
(H) MacroMenu and MacroEditor
A lot of people were discussing about how to extend the LaTeX panel 
or an alternative helper tool for tex command inputs.  This is 
my answer to the question.  "MacroMenu" is a menu on the menu bar 
and also on the toolbar of each window, and it enables you to enter 
predefined macros.  Features:
--hierarchical menu
--key equivalents
--#SEL# in the macro text will be replaced by the selection in 
the window, the insertion point will come to the place where #INS# is. 
("doCompletion:" style)

"MacroEditor" is an associated editor for "MacroMenu".  Within the 
editor window, there is an outline view, in which you can manage 
the hierarchy of the menu.  You can add/delete macro items/submenu/
separator.  If you use the window as a macro launcher by double click, 
for example by making the window narrow and tall.  You can drag and 
drop macro texts to and from the outline view.  From "Macros" menu, 
you can add macros from a file and save selected macros to a file.  
This way, you can distribute and share your favorite macros with other 
people.  
If the macro text starts with "--AppleScript", then it is considered 
and executed as an AppleScript.  If the return value is a text, 
it will be displayed in a dialog.  Other types of return value 
are ignored.  

// In source code
There are four classes related to MacroMenu and MacroEditer.  
"MacroMenuController" implements MacroMenu, and is more or less 
idependent from other three classes.  (If you prepare 
~/Library/TeXShop/Macros/Macros.plist for macro definition.)
"OutlineViewController" and "MyTreeNode" are the classes that 
implement outlineView for hierarchical macro data and its 
tree structure.  "MacroEditor" handles the editor window.  
Some codes are also added to support macroButton in toolbar.  

// In Interface Builder
MyDocument.nib
	add macroButton (popup button of type pulldown) in View for toolbar items
	connect File's Owner(MyDocument, outlet: macroButton) to the macroButton
MainMenu.nib
	instantiate MacroMenuController and MacroEditor
	connect MacroMenuController(outlet: macroMenu) to MacrosMenu  (koch: menu, not menuitem)
	connect "Open Macro Editor" item in Macros menu to MacroEditor(action: openMacroPanel) (koch: openMacroEditor)
	
ToolbarItems.strings
	tiLabelMacros			= "Macros";
	tiPaletteLabelMacros	= "Macros";
	tiToolTipMacros			= "Insert macros";
	
MacroEditor.nib
	create MacroEditor.nib

/////////////////////////////////////////////////////////////
(I) Magnifying glass in Preview Window
If you press and hold the mouse in Preview Window 
the area around the cursor will be magnified.  
// In source code
I added "mouseDown:" in "MyView.m".  
// more...
You may want to set an option so that command key or option key 
is required to invoke the magnifying glass.  You can also 
change the constants defined at the beginning of the method.  
Currently the scale is 0.4, i.e. it is magnified 2.5 times.  

/////////////////////////////////////////////////////////////
(J) Command-T for Typeset and program popup button
This may be controversial.  I always wanted to typeset all kinds 
of documents with the same key equivalent. So I created a menu item 
"Typeset" within "Typseset" menu with key equivalent command-T, 
which was dismissed from "Show Fonts".  Then it is natural to 
indicate in "Typeset" menu which program is active (with check mark).  
Additionally from the point of view of human interface, it seems more 
narural to have the "Program" popup button in the toolbar indicate 
the name of Program (TeX, LaTeX,...) itself, not by the button 
on the side.  So the chages consist of three parts:
(J) Typeset command (and remembering current program)
(J+) Check mark in "Typeset" menu and "Program" popup button
(J++) "Program" popup button indicating Program name
This change of interface depends on the taste of a person.  You can 
implement it only if you agree.  You may also stop at (J+) if you 
don't like (J++).  

// In source code
In "MyDocument.m", there were two kinds of ID which indicate programs:
the first is for whichEngine=type in "doJob:" 
0 = tex, 1 = latex, 2 = context, 3 = omega, 4 = megapost, 5 = bibtex, 6 = makeindex
the second in "ChooseProgram", as the tags of menu items of "Program" popup button
0 = TeX, 1 = LaTeX, 2 = BibTex, 3 = MakeIndex, 4 = MetaPost, 5 = ConTeXt
I think it better to unify them in order to avoid confusion.  So in my 
modified version, I adopted the former and changed the assignment of the tags.  
ID of the program used will be stored in the instance variable "whichEngine", 
and used in "doTypeset:".  
For (J+), it seems to be the simplest to let "TSWindowManager" handle the 
job. (I first tried with "validateMenuItems:" but there was a problem when 
there is no window.)  "TSWindowManager" will be notified when windows 
are being activated/deactivated, then it will check/unckeck the corresponding 
menu items.  It is also necessary to check/uncheck the items when the typeset 
jobs are run.  
For (J++), the title of "Program" popup button itself is set instead of 
"typesetButton".

// In interface Builder
MainMenu.nib
	add a menu item "Typeset" with key equivalent 't' in Typeset menu
	add a separater item after "Typeset"
	add action "doTypeset:" to FirstResponder
	make a connection from Typeset menu item to FirstResponder.doTypeset
	remove key equivalent 't' from item "Show Fonts" in Format->Font menu.
	set tags of menu items in "Typeset" menu 
		0 = TeX, 1 = LaTeX, 5 = BibTex, 6 = MakeIndex, 4 = MetaPost, 2 = ConTeXt
		-1 = Typeset, -1000 = separator

MyDocument.nib
	set tags of menu items in "Program" popup button
		0 = TeX, 1 = LaTeX, 5 = BibTex, 6 = MakeIndex, 4 = MetaPost, 2 = ConTeXt
For (J++):
	ProgramButton
		set the attribute  to type "Popup"
		deleted "Program" item
		enlarged the width to 105
	TypesetButton and TypesetButtonEE
		set the name to "Typeset"

/////////////////////////////////////////////////////////////
(K) The name of new documents: "Unititled-n"
You mentioned in windowControllerDidLoadNib in "MyDocument.m" :
/* this code is an attempt to make "untitled-1" be a name without spaces,
        but it does not work */	
It is simply enough to override "displayName:" in "MyDocument.m".

/////////////////////////////////////////////////////////////
(L) TeX Input in Console window
The text you entered in "TeX Input" field on Console Window will be 
reflected in red in "TeX message" field.  The input will be cleared 
after this, in order to make it easy to enter next text.  
// In source code
A simple addition in "doTeXCommand:" in in "MyDocument.m".  

/////////////////////////////////////////////////////////////
(M) Path Settings on "okButtonPressed:" in TSPreferences
As you mention in the source code, when OK button is pressed in 
the Preference dialog, the changes in the currently edited text 
field is not reflected.  You called [self tabsChanged: self] etc. 
but you forgot to add [self tetexBinPathChanged: self] and 
[self gsBinPathChanged: self].  I think there is a better way to 
do the job with the same effect.  
[_prefsWindow makeFirstResponder: _prefsWindow];
will let hilited controls to resign FirstResponder, which causes 
the changes to be reflected.  
// to test 
Add the above line in "okButtonPressed:" and make a break point 
in "tetexBinPathChanged:".  Press "OK" while you are editing 
"tetexBinPath".  You can see that "tetexBinPathChanged:" is 
called and the change is reflected.  

/////////////////////////////////////////////////////////////
(N) Support for .def, .fd, .ltx, .clo files
I was asked to add support for these types of files.  
// In source code 
I added them in "windowControllerDidLoadNib:" in "MyDocument.m"
// In Target tab of Project Builder
I added them as supported file types.  

/////////////////////////////////////////////////////////////
