You've already forked lazarus-ccr
Improves pascocoa and texteditor example
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@586 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -29,6 +29,7 @@ type
|
||||
class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
|
||||
class procedure doOpenFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
|
||||
class procedure doSaveFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
|
||||
class procedure doSaveAsFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
|
||||
class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
|
||||
_cmd: SEL; theApplication: objc.id): cbool; cdecl; {$ifndef VER2_2_2}static;{$endif}
|
||||
end;
|
||||
@ -37,6 +38,7 @@ const
|
||||
Str_doClose = 'doClose:';
|
||||
Str_doOpenFile = 'doOpenFile:';
|
||||
Str_doSaveFile = 'doSaveFile:';
|
||||
Str_doSaveAsFile = 'doSaveAsFile:';
|
||||
Str_applicationShouldTerminateAfterLastWindowClosed = 'applicationShouldTerminateAfterLastWindowClosed:';
|
||||
|
||||
var
|
||||
@ -46,7 +48,7 @@ var
|
||||
|
||||
implementation
|
||||
|
||||
uses view;
|
||||
uses view, model;
|
||||
|
||||
{ TMyController }
|
||||
|
||||
@ -64,6 +66,7 @@ begin
|
||||
AddMethod(Str_doClose, 'v@:@', Pointer(doClose));
|
||||
AddMethod(Str_doOpenFile, 'v@:@', Pointer(doOpenFile));
|
||||
AddMethod(Str_doSaveFile, 'v@:@', Pointer(doSaveFile));
|
||||
AddMethod(Str_doSaveAsFile, 'v@:@', Pointer(doSaveAsFile));
|
||||
AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'B@:@',
|
||||
Pointer(applicationShouldTerminateAfterLastWindowClosed));
|
||||
end;
|
||||
@ -97,9 +100,11 @@ begin
|
||||
|
||||
if OpenPanel.runModal = NSFileHandlingPanelOKButton then
|
||||
begin
|
||||
CFStringGetPascalString(OpenPanel.filename, @myModel.DocumentName, 255, kCFStringEncodingUTF8);
|
||||
|
||||
{ Now move the contents of the edit control to the file }
|
||||
|
||||
FileContents := NSString.CreateWithHandle(objc.id(myView.TextField.StringValue));
|
||||
FileContents := NSString.initWithContentsOfFile(OpenPanel.filename);
|
||||
|
||||
myView.TextField.setStringValue(CFStringRef(FileContents.Handle));
|
||||
end;
|
||||
@ -109,16 +114,34 @@ class procedure TMyController.doSaveFile(_self: objc.id; _cmd: SEL;
|
||||
sender: objc.id); cdecl;
|
||||
var
|
||||
FileContents: NSString;
|
||||
begin
|
||||
if myModel.DocumentName = Str_Untitled then doSaveAsFile(_self, _cmd, sender)
|
||||
else
|
||||
begin
|
||||
{ Now move the contents of the file to the edit control }
|
||||
|
||||
FileContents := NSString.CreateWithHandle(objc.id(myView.TextField.StringValue));
|
||||
|
||||
FileContents.writeToFile_atomically(CFStringCreateWithPascalString(nil, myModel.DocumentName, kCFStringEncodingUTF8), False);
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TMyController.doSaveAsFile(_self: objc.id; _cmd: SEL;
|
||||
sender: objc.id); cdecl;
|
||||
var
|
||||
FileContents: NSString;
|
||||
begin
|
||||
{ Show dialog }
|
||||
|
||||
if SavePanel.runModal = NSFileHandlingPanelOKButton then
|
||||
begin
|
||||
CFStringGetPascalString(SavePanel.filename, @myModel.DocumentName, 255, kCFStringEncodingUTF8);
|
||||
|
||||
{ Now move the contents of the file to the edit control }
|
||||
|
||||
FileContents := NSString.initWithContentsOfFile(OpenPanel.filename);
|
||||
FileContents := NSString.CreateWithHandle(objc.id(myView.TextField.StringValue));
|
||||
|
||||
FileContents.writeToFile_atomically(SavePanel.filename, False);
|
||||
FileContents.writeToFile_atomically(CFStringCreateWithPascalString(nil, myModel.DocumentName, kCFStringEncodingUTF8), False);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -29,9 +29,13 @@ type
|
||||
{ Routines and variables for program resources }
|
||||
imgOpen, imgSave, imgClose: NSImage;
|
||||
ResourcesDir: string;
|
||||
DocumentName: shortstring;
|
||||
constructor Create;
|
||||
end;
|
||||
|
||||
const
|
||||
Str_Untitled = 'Untitled /1';
|
||||
|
||||
var
|
||||
myModel: TMyModel;
|
||||
|
||||
@ -74,6 +78,8 @@ begin
|
||||
ResourcesDir := GetResourcesDir;
|
||||
|
||||
LoadImages;
|
||||
|
||||
DocumentName := Str_Untitled;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -6,7 +6,7 @@
|
||||
<General>
|
||||
<MainUnit Value="0"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<ActiveEditorIndexAtStart Value="1"/>
|
||||
<ActiveEditorIndexAtStart Value="7"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
@ -38,47 +38,47 @@
|
||||
<CursorPos X="9" Y="15"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="37"/>
|
||||
<UsageCount Value="38"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="model.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="model"/>
|
||||
<CursorPos X="1" Y="4"/>
|
||||
<TopLine Value="1"/>
|
||||
<CursorPos X="24" Y="32"/>
|
||||
<TopLine Value="27"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<UsageCount Value="37"/>
|
||||
<UsageCount Value="38"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="view.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="view"/>
|
||||
<CursorPos X="1" Y="221"/>
|
||||
<TopLine Value="74"/>
|
||||
<CursorPos X="49" Y="158"/>
|
||||
<TopLine Value="146"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<UsageCount Value="37"/>
|
||||
<UsageCount Value="38"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="controller.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="controller"/>
|
||||
<CursorPos X="19" Y="98"/>
|
||||
<TopLine Value="85"/>
|
||||
<CursorPos X="1" Y="145"/>
|
||||
<TopLine Value="130"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<UsageCount Value="37"/>
|
||||
<UsageCount Value="38"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="mytoolbar"/>
|
||||
<CursorPos X="51" Y="126"/>
|
||||
<TopLine Value="115"/>
|
||||
<CursorPos X="28" Y="123"/>
|
||||
<TopLine Value="107"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="32"/>
|
||||
<UsageCount Value="33"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
@ -115,7 +115,7 @@
|
||||
<CursorPos X="13" Y="60"/>
|
||||
<TopLine Value="46"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<UsageCount Value="11"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit9>
|
||||
<Unit10>
|
||||
@ -136,123 +136,123 @@
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="76" Column="1" TopLine="64"/>
|
||||
<Caret Line="65" Column="1" TopLine="58"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="78" Column="1" TopLine="66"/>
|
||||
<Caret Line="20" Column="34" TopLine="8"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="72" Column="1" TopLine="67"/>
|
||||
<Caret Line="37" Column="22" TopLine="28"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="74" Column="92" TopLine="61"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="99" Column="12" TopLine="80"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="8" Column="12" TopLine="1"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="108" Column="1" TopLine="85"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="126" Column="30" TopLine="115"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="20" Column="22" TopLine="9"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="21" Column="55" TopLine="2"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="178" Column="5" TopLine="155"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="101" Column="111" TopLine="92"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="181" Column="5" TopLine="158"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="75" Column="5" TopLine="52"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="23" Column="27" TopLine="13"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="101" Column="20" TopLine="90"/>
|
||||
<Caret Line="219" Column="1" TopLine="210"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="102" Column="13" TopLine="89"/>
|
||||
<Caret Line="23" Column="8" TopLine="14"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="65" Column="1" TopLine="58"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="218" Column="1" TopLine="209"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="20" Column="34" TopLine="8"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="131" Column="1" TopLine="114"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="37" Column="22" TopLine="28"/>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="116" Column="44" TopLine="104"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="99" Column="12" TopLine="80"/>
|
||||
<Caret Line="192" Column="35" TopLine="180"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="108" Column="1" TopLine="85"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="74" Column="15" TopLine="59"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="20" Column="22" TopLine="9"/>
|
||||
<Filename Value="../../../objc/objc.pas"/>
|
||||
<Caret Line="27" Column="12" TopLine="19"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="178" Column="5" TopLine="155"/>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="149" Column="9" TopLine="134"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="181" Column="5" TopLine="158"/>
|
||||
<Caret Line="218" Column="77" TopLine="200"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="23" Column="27" TopLine="13"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="132" Column="5" TopLine="109"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="219" Column="1" TopLine="210"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="108" Column="1" TopLine="94"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="23" Column="8" TopLine="14"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="51" Column="17" TopLine="39"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="218" Column="1" TopLine="209"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="123" Column="35" TopLine="118"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="131" Column="1" TopLine="114"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="125" Column="61" TopLine="113"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="116" Column="44" TopLine="104"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="103" Column="38" TopLine="91"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="192" Column="35" TopLine="180"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="126" Column="32" TopLine="113"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="74" Column="15" TopLine="59"/>
|
||||
<Caret Line="125" Column="1" TopLine="108"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="../../../objc/objc.pas"/>
|
||||
<Caret Line="27" Column="12" TopLine="19"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="139" Column="1" TopLine="122"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="149" Column="9" TopLine="134"/>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="144" Column="44" TopLine="132"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="218" Column="77" TopLine="200"/>
|
||||
<Caret Line="158" Column="29" TopLine="138"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
|
@ -97,6 +97,7 @@ begin
|
||||
end;
|
||||
|
||||
{@@
|
||||
Attaches event handlers for the menu
|
||||
}
|
||||
procedure TMyView.AttachEventHandlers();
|
||||
begin
|
||||
@ -106,11 +107,15 @@ begin
|
||||
SaveItem.setTarget(myController.Handle);
|
||||
SaveItem.setAction(sel_registerName(PChar('doSaveFile:')));
|
||||
|
||||
SaveAsItem.setTarget(myController.Handle);
|
||||
SaveAsItem.setAction(sel_registerName(PChar('doSaveAsFile:')));
|
||||
|
||||
ExitItem.setTarget(myController.Handle);
|
||||
ExitItem.setAction(sel_registerName(PChar('doClose:')));
|
||||
end;
|
||||
|
||||
{@@
|
||||
Creates the Apple submenu
|
||||
}
|
||||
function TMyView.CreateAppleMenu(): NSMenu;
|
||||
var
|
||||
@ -130,6 +135,7 @@ begin
|
||||
end;
|
||||
|
||||
{@@
|
||||
Creates the File submenu
|
||||
}
|
||||
function TMyView.CreateFileMenu(): NSMenu;
|
||||
var
|
||||
@ -145,13 +151,21 @@ begin
|
||||
|
||||
OpenItem := CreateMenuItem('Open');
|
||||
Result.addItem(OpenItem.Handle);
|
||||
|
||||
SaveItem := CreateMenuItem('Save');
|
||||
Result.addItem(SaveItem.Handle);
|
||||
|
||||
SaveAsItem := CreateMenuItem('Save As');
|
||||
Result.addItem(SaveAsItem.Handle);
|
||||
|
||||
Result.addItem(NSMenuItem.separatorItem.Handle);
|
||||
|
||||
ExitItem := CreateMenuItem('Exit');
|
||||
Result.addItem(ExitItem.Handle);
|
||||
end;
|
||||
|
||||
{@@
|
||||
Adds a submenu to the main menu
|
||||
}
|
||||
procedure TMyView.AddToMenubar(menu: NSMenu);
|
||||
var
|
||||
@ -164,6 +178,7 @@ begin
|
||||
end;
|
||||
|
||||
{@@
|
||||
Creates the toolbar object. Setting the items is done in the controller.
|
||||
}
|
||||
function TMyView.CreateToolbar(AOwnerView: NSView; AX, AY, AWidth,
|
||||
AHeight: Double): NSToolbar;
|
||||
@ -174,6 +189,7 @@ begin
|
||||
end;
|
||||
|
||||
{@@
|
||||
Creates the main menu
|
||||
}
|
||||
procedure TMyView.CreateMainMenu();
|
||||
begin
|
||||
@ -190,6 +206,7 @@ begin
|
||||
end;
|
||||
|
||||
{@@
|
||||
Creates a new menu item from a title
|
||||
}
|
||||
function TMyView.CreateMenuItem(ATitle: shortstring): NSMenuItem;
|
||||
var
|
||||
|
Reference in New Issue
Block a user