21 #include "kateapp.moc" 23 #include "katedocmanager.h" 24 #include "katepluginmanager.h" 25 #include "kateviewmanager.h" 26 #include "kateappIface.h" 27 #include "katesession.h" 28 #include "katemainwindow.h" 30 #include "../interfaces/application.h" 32 #include <tdeversion.h> 33 #include <tdecmdlineargs.h> 34 #include <dcopclient.h> 35 #include <tdeconfig.h> 39 #include <klibloader.h> 40 #include <tdemessagebox.h> 41 #include <tdelocale.h> 42 #include <ksimpleconfig.h> 43 #include <tdestartupinfo.h> 48 #include <tqtextcodec.h> 52 #include <sys/types.h> 57 , m_shouldExit (false)
60 dcopClient()->suspend();
63 TDEGlobal::locale()->insertCatalogue(
"katepart");
66 Kate::Document::setFileChangedDialogsActivated (
true);
72 m_docManager =
new KateDocManager (TQT_TQOBJECT(
this));
75 m_pluginManager =
new KatePluginManager (TQT_TQOBJECT(
this));
78 m_sessionManager =
new KateSessionManager (TQT_TQOBJECT(
this));
81 m_obj =
new KateAppDCOPIface (
this);
83 kdDebug()<<
"Setting KATE_PID: '"<<getpid()<<
"'"<<endl;
84 ::setenv(
"KATE_PID", TQString(TQString(
"%1").arg(getpid())).latin1(), 1 );
103 dcopClient()->resume();
112 delete m_pluginManager;
125 return m_application;
139 return fullVersion ? TQString (
"2.5.%1").arg(KDE::versionMajor()) : TQString (
"%1.%2").arg(2.5);
142 void KateApp::restoreKate ()
145 Kate::Document::setOpenErrorDialogsActivated (
false);
148 sessionConfig()->setGroup(
"General");
149 TQString lastSession (sessionConfig()->readEntry (
"Last Session",
"default.katesession"));
152 m_docManager->restoreDocumentList (sessionConfig());
154 Kate::Document::setOpenErrorDialogsActivated (
true);
157 for (
int n=1; TDEMainWindow::canBeRestored(n); n++)
168 bool KateApp::startupKate ()
171 if (m_args->isSet (
"start"))
181 TDEStartupInfo::appStarted (startupId());
193 TQTextCodec *codec = m_args->isSet(
"encoding") ? TQTextCodec::codecForName(m_args->getOption(
"encoding")) : 0;
195 bool tempfileSet = TDECmdLineArgs::isTempFileSet();
197 Kate::Document::setOpenErrorDialogsActivated (
false);
199 for (
int z=0; z<m_args->count(); z++)
202 bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists();
208 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(),
false, tempfileSet );
210 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null,
false, tempfileSet );
214 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).url()) );
217 Kate::Document::setOpenErrorDialogsActivated (
true);
220 if( m_args->isSet(
"stdin" ) )
222 TQTextIStream input(stdin);
226 input.setCodec (codec);
233 line = input.readLine();
234 text.append( line +
"\n" );
235 }
while( !line.isNull() );
243 activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber());
249 if (m_args->isSet (
"line"))
251 line = m_args->getOption (
"line").toInt();
255 if (m_args->isSet (
"column"))
257 column = m_args->getOption (
"column").toInt();
262 activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column);
272 if (!win->queryClose_internal())
278 dcopClient()->detach();
281 while (!m_mainWindows.isEmpty())
282 delete m_mainWindows[0];
289 return m_pluginManager;
299 return m_sessionManager;
309 TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1());
311 kdDebug () <<
"OPEN URL "<< encoding << endl;
314 bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists();
320 mainWindow->viewManager()->openURL( url, codec->name(),
true, isTempFile );
322 mainWindow->viewManager()->openURL( url, TQString::null,
true, isTempFile );
325 KMessageBox::sorry( mainWindow,
326 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.url()) );
338 mainWindow->viewManager()->activeView ()->setCursorPosition (line, column);
357 KateMainWindow *
mainWindow =
new KateMainWindow (sconfig, sgroup);
358 m_mainWindows.push_back (mainWindow);
360 if ((
mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView())
361 mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() );
362 else if ((
mainWindows() > 1) && (m_docManager->documents() > 0))
363 mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() );
364 else if ((
mainWindows() > 1) && (m_docManager->documents() < 1))
365 mainWindow->viewManager()->openURL ( KURL() );
374 m_mainWindows.remove (mainWindow);
379 if (m_mainWindows.isEmpty())
382 int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow());
387 return m_mainWindows[n];
392 return m_mainWindows.size();
397 if (n < m_mainWindows.size())
398 return m_mainWindows[n];
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
~KateApp()
application destructor
KateApp(TDECmdLineArgs *args)
constructors & accessor to app object + plugin interface for it
bool openInput(const TQString &text)
helper to handle stdin input open a new document/view, fill it with the text given ...
Kate::Application * application()
accessor to the Kate::Application plugin interface
KateMainWindow * newMainWindow(TDEConfig *sconfig=0, const TQString &sgroup="")
window management
static TQString kateVersion(bool fullVersion=true)
Returns the current Kate version (X.Y) or (X.Y.Z)
KateDocManager * documentManager()
accessor to document manager
void shutdownKate(KateMainWindow *win)
kate shutdown
KateMainWindow * mainWindow(uint n)
give back the window you want
KateSessionManager * sessionManager()
accessor to session manager
uint mainWindows() const
give back number of existing main windows
KatePluginManager * pluginManager()
other accessors for global unique instances
Kate Application This class represents the core kate application object.
bool openURL(const KURL &url, const TQString &encoding, bool isTempFile)
some stuff for the dcop API
static KateApp * self()
static accessor to avoid casting ;)
void removeMainWindow(KateMainWindow *mainWindow)
removes the mainwindow given, DOES NOT DELETE IT
bool setCursor(int line, int column)
position cursor in current active view
Interface to the application, beside some global methodes to access other objects like document/proje...