|
1 // mainfshell.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 #include <fshell/ioutils.h> |
|
13 #include "fed.h" |
|
14 #include <e32cons.h> |
|
15 #include <BADESCA.H> |
|
16 #include <fshell/descriptorutils.h> |
|
17 |
|
18 using namespace IoUtils; |
|
19 |
|
20 class CCmdFed : public CCommandBase |
|
21 { |
|
22 public: |
|
23 static CCommandBase* NewLC(); |
|
24 ~CCmdFed(); |
|
25 CConsoleBase* Console() { return iConsole; } |
|
26 TInt TabWidth() const { return iTabWidth; } |
|
27 void ShowHelpL(); |
|
28 private: |
|
29 CCmdFed(); |
|
30 |
|
31 private: // From CCommandBase. |
|
32 virtual const TDesC& Name() const; |
|
33 virtual void DoRunL(); |
|
34 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
35 virtual void OptionsL(RCommandOptionList& aOptions); |
|
36 virtual void StdinChange(TUint aChange); |
|
37 private: |
|
38 RArray<TFileName2> iFiles; |
|
39 CColorConsoleBase* iConsole; |
|
40 CFed* iFed; |
|
41 TInt iTabWidth; |
|
42 }; |
|
43 |
|
44 CCmdFed* gCmd = NULL; // Only used for the assertion handler and tab fns |
|
45 |
|
46 CCommandBase* CCmdFed::NewLC() |
|
47 { |
|
48 CCmdFed* self = new(ELeave) CCmdFed(); |
|
49 CleanupStack::PushL(self); |
|
50 self->BaseConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 CCmdFed::~CCmdFed() |
|
55 { |
|
56 iFiles.Close(); |
|
57 delete iFed; |
|
58 delete iConsole; |
|
59 } |
|
60 |
|
61 CCmdFed::CCmdFed() |
|
62 : CCommandBase(EManualComplete | ENotifyStdinChanges), iTabWidth(4) |
|
63 { |
|
64 } |
|
65 |
|
66 const TDesC& CCmdFed::Name() const |
|
67 { |
|
68 _LIT(KName, "fed"); |
|
69 return KName; |
|
70 } |
|
71 |
|
72 void CCmdFed::ArgumentsL(RCommandArgumentList& aArguments) |
|
73 { |
|
74 aArguments.AppendFileNameL(iFiles, _L("file")); |
|
75 } |
|
76 |
|
77 void CCmdFed::OptionsL(RCommandOptionList& aOptions) |
|
78 { |
|
79 aOptions.AppendIntL(iTabWidth, _L("tab-width")); |
|
80 } |
|
81 |
|
82 EXE_BOILER_PLATE(CCmdFed) |
|
83 |
|
84 void CCmdFed::DoRunL() |
|
85 { |
|
86 iConsole = GetColorConsoleBaseL(); |
|
87 gCmd = this; |
|
88 |
|
89 // Set the console title - nice for when using win32cons |
|
90 // Not so nice - fshell doesn't reset it when fed exits... -TomS |
|
91 /* |
|
92 _LIT(KFed, "fed "); |
|
93 RBuf cmdLine; |
|
94 cmdLine.CreateL(User::CommandLineLength() + KFed().Length()); |
|
95 User::CommandLine(cmdLine); |
|
96 cmdLine.Insert(0, KFed); |
|
97 iConsole->SetTitle(cmdLine); |
|
98 cmdLine.Close(); |
|
99 */ |
|
100 |
|
101 // Capture CTRL-C so we can (a) use it and (b) prevent users from accidentally nuking their work |
|
102 User::LeaveIfError(Stdin().CaptureKey(CTRL('c'), 0, 0)); |
|
103 |
|
104 iFed = CFed::NewL(*iConsole, FsL()); |
|
105 CDesC16ArrayFlat* argsBuf = new(ELeave) CDesC16ArrayFlat(Max(1, iFiles.Count())); |
|
106 CleanupStack::PushL(argsBuf); |
|
107 for (TInt i = 0; i < iFiles.Count(); i++) |
|
108 { |
|
109 argsBuf->AppendL(iFiles[i]); |
|
110 } |
|
111 CleanupStack::Pop(argsBuf); |
|
112 iFed->StartL(argsBuf); |
|
113 } |
|
114 |
|
115 void CCmdFed::StdinChange(TUint aChange) |
|
116 { |
|
117 if (aChange & RIoReadHandle::EGainedForeground) |
|
118 { |
|
119 iFed->RedrawEverythingL(); |
|
120 } |
|
121 } |
|
122 |
|
123 void AssertionFail(const char* aAssertion, const char* aFile, TInt aLine) |
|
124 { |
|
125 __DEBUGGER(); |
|
126 TBuf8<256> buf; |
|
127 TOverflowTruncate8 o; |
|
128 buf.AppendFormat(_L8("Assertion failed: \"%s\" in %s:%i\n"), &o, aAssertion, aFile, aLine); |
|
129 if (buf.Length()*2>buf.MaxLength()) buf.SetLength(buf.MaxLength()/2); |
|
130 gCmd->Console()->Write(buf.Expand()); |
|
131 User::Panic(_L("Fed"), aLine); |
|
132 } |
|
133 |
|
134 TInt KConsoleWidthCorrection = 0; |
|
135 TInt KConsoleHeightCorrection = 0; |
|
136 |
|
137 TInt TabWidth() |
|
138 { |
|
139 return gCmd->TabWidth(); |
|
140 } |
|
141 |
|
142 void ShowHelpL() |
|
143 { |
|
144 gCmd->ShowHelpL(); |
|
145 } |
|
146 |
|
147 void CCmdFed::ShowHelpL() |
|
148 { |
|
149 LtkUtils::RLtkBuf helpText; |
|
150 CleanupClosePushL(helpText); |
|
151 helpText.AppendL(_L("\ |
|
152 Fed Help\r\n\ |
|
153 ========\ |
|
154 ")); |
|
155 _LIT(KStart, "Console text editor."); |
|
156 CTextBuffer* helpBuf = const_cast<CTextBuffer*>(GetHelpTextL()); // nasty cast... GetHelpTextL shouldn't return a const obj... |
|
157 CleanupStack::PushL(helpBuf); |
|
158 TInt found = helpBuf->Descriptor().Find(KStart); |
|
159 helpText.AppendL(helpBuf->Descriptor().Mid(found + KStart().Length())); |
|
160 iFed->ShowHelpL(helpText.ToHBuf()); |
|
161 CleanupStack::PopAndDestroy(2, &helpText); // helpBuf, helpText |
|
162 } |