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 (
this);
75 m_pluginManager =
new KatePluginManager (
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();
109 delete m_pluginManager;
110 delete m_sessionManager;
121 return m_application;
135 return fullVersion ? TQString (
"2.5.%1").arg(KDE::versionMajor()) : TQString (
"%1.%2").arg(2.5);
138 void KateApp::restoreKate()
141 Kate::Document::setOpenErrorDialogsActivated(
false);
145 m_docManager->restoreDocumentList(sessionConfig());
147 Kate::Document::setOpenErrorDialogsActivated(
true);
157 bool KateApp::startupKate()
159 if (m_args->isSet(
"start"))
163 TQCString sessName = m_args->getOption(
"start");
165 if (sessId != KateSessionManager::INVALID_SESSION)
178 if (startupOption == KateSessionManager::STARTUP_NEW)
182 else if (startupOption == KateSessionManager::STARTUP_LAST)
188 KateSessionChooser *chooser =
new KateSessionChooser(NULL);
189 int result = chooser->exec();
192 case KateSessionChooser::RESULT_OPEN_NEW:
196 case KateSessionChooser::RESULT_OPEN_EXISTING:
197 if (!m_sessionManager->
activateSession(chooser->getSelectedSessionId()))
206 TDEStartupInfo::appStarted(startupId());
221 TQTextCodec *codec = m_args->isSet(
"encoding") ? TQTextCodec::codecForName(m_args->getOption(
"encoding")) : 0;
223 bool tempfileSet = TDECmdLineArgs::isTempFileSet();
225 Kate::Document::setOpenErrorDialogsActivated (
false);
227 for (
int z=0; z<m_args->count(); z++)
230 bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists();
236 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(),
false, tempfileSet );
238 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null,
false, tempfileSet );
242 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).pathOrURL()) );
245 Kate::Document::setOpenErrorDialogsActivated (
true);
248 if( m_args->isSet(
"stdin" ) )
250 TQTextIStream input(stdin);
254 input.setCodec (codec);
261 line = input.readLine();
262 text.append( line +
"\n" );
263 }
while( !line.isNull() );
271 activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber());
277 if (m_args->isSet (
"line"))
279 line = m_args->getOption (
"line").toInt();
283 if (m_args->isSet (
"column"))
285 column = m_args->getOption (
"column").toInt();
290 activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column);
300 if (!win->queryClose_internal())
304 dcopClient()->detach();
307 while (!m_mainWindows.isEmpty())
308 delete m_mainWindows[0];
315 bool saveSessions =
false;
317 if (switchOption == KateSessionManager::SWITCH_SAVE)
321 else if (switchOption == KateSessionManager::SWITCH_ASK)
323 KDialogBase *dlg =
new KDialogBase(i18n(
"Save Sessions"),
324 KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
325 KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL,
true,
false,
326 KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
327 bool dontAgain =
false;
328 int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
329 i18n(
"<p>Do you want to save the existing sessions?<p>!!NOTE!!"
330 "<p>All existing sessions will be removed "
331 "if you choose \"Delete\""), TQStringList(),
332 i18n(
"Do not ask again"), &dontAgain, KMessageBox::Notify);
333 if (res == KDialogBase::Cancel)
339 if (res == KDialogBase::No)
348 if (res == KDialogBase::Yes)
369 return m_pluginManager;
379 return m_sessionManager;
389 TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1());
391 kdDebug () <<
"OPEN URL "<< encoding << endl;
394 bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists();
400 mainWindow->viewManager()->openURL( url, codec->name(),
true, isTempFile );
402 mainWindow->viewManager()->openURL( url, TQString::null,
true, isTempFile );
406 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.pathOrURL()) );
418 mainWindow->viewManager()->activeView ()->setCursorPosition (line, column);
437 KateMainWindow *
mainWindow =
new KateMainWindow (sconfig, sgroup);
440 if ((
mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView())
441 mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() );
442 else if ((
mainWindows() > 1) && (m_docManager->documents() > 0))
443 mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() );
444 else if ((
mainWindows() > 1) && (m_docManager->documents() < 1))
445 mainWindow->viewManager()->openURL ( KURL() );
459 if (m_mainWindows.isEmpty())
462 int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow());
467 return m_mainWindows[n];
472 return m_mainWindows.size();
477 if (n < m_mainWindows.size())
478 return m_mainWindows[n];
Kate Application This class represents the core kate application object.
bool query_session_close()
to be called when the application is about to quit
void optionsChanged()
Emitted when the configuration has or may have been changed.
void reparse_config()
called after the config dialog has been closed.
Kate::Application * application()
accessor to the Kate::Application plugin interface
KateMainWindow * newMainWindow(TDEConfig *sconfig=0, const TQString &sgroup="")
window management
void shutdownKate(KateMainWindow *win)
kate shutdown
KateMainWindow * mainWindow(uint n)
give back the window you want
~KateApp()
application destructor
static KateApp * self()
static accessor to avoid casting ;)
KateDocManager * documentManager()
accessor to document manager
static TQString kateVersion(bool fullVersion=true)
Returns the current Kate version (X.Y) or (X.Y.Z)
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
KatePluginManager * pluginManager()
other accessors for global unique instances
bool openURL(const KURL &url, const TQString &encoding, bool isTempFile)
some stuff for the dcop API
KateApp(TDECmdLineArgs *args)
constructors & accessor to app object + plugin interface for it
uint mainWindows() const
give back number of existing main windows
bool setCursor(int line, int column)
position cursor in current active view
bool openInput(const TQString &text)
helper to handle stdin input open a new document/view, fill it with the text given
KateSessionManager * sessionManager()
accessor to session manager
void removeMainWindow(KateMainWindow *mainWindow)
removes the mainwindow given, DOES NOT DELETE IT
The Kate session manager.
int getSessionIdFromName(const TQString &name)
Return the session id of the first session whose name matches the provided one.
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
int newSession(const TQString &sessionName=TQString::null, bool saveCurr=true)
bool restoreLastSession()
Restore the last saved session.
const int getSwitchOption()
void saveConfig(bool saveSessions)
Save session manager info.
const int getStartupOption()
bool activateSession(int sessionId, bool saveCurr=true)
Activate the selected session.
void setSwitchOption(int option)
Set the new session switch preference.
Interface to the application, beside some global methodes to access other objects like document/proje...