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 <tdecmdlineargs.h>
33#include <dcopclient.h>
38#include <klibloader.h>
39#include <tdemessagebox.h>
41#include <ksimpleconfig.h>
42#include <tdestartupinfo.h>
47#include <tqtextcodec.h>
56 , m_shouldExit (false)
59 dcopClient()->suspend();
62 TDEGlobal::locale()->insertCatalogue(
"katepart");
65 Kate::Document::setFileChangedDialogsActivated (
true);
71 m_docManager =
new KateDocManager (
this);
74 m_pluginManager =
new KatePluginManager (
this);
80 m_obj =
new KateAppDCOPIface (
this);
82 kdDebug()<<
"Setting KATE_PID: '"<<getpid()<<
"'"<<endl;
83 ::setenv(
"KATE_PID", TQString(TQString(
"%1").arg(getpid())).latin1(), 1 );
102 dcopClient()->resume();
108 delete m_pluginManager;
109 delete m_sessionManager;
120 return m_application;
134 return fullVersion ? TQString (
"2.5.%1").arg(KDE::versionMajor()) : TQString (
"%1.%2").arg(2.5);
137void KateApp::restoreKate()
140 Kate::Document::setOpenErrorDialogsActivated(
false);
144 m_docManager->restoreDocumentList(sessionConfig());
146 Kate::Document::setOpenErrorDialogsActivated(
true);
156bool KateApp::startupKate()
158 if (m_args->isSet(
"start"))
162 TQCString sessName = m_args->getOption(
"start");
164 if (sessId != KateSessionManager::INVALID_SESSION)
177 if (startupOption == KateSessionManager::STARTUP_NEW)
181 else if (startupOption == KateSessionManager::STARTUP_LAST)
187 KateSessionChooser *chooser =
new KateSessionChooser(NULL);
188 int result = chooser->exec();
191 case KateSessionChooser::RESULT_OPEN_NEW:
195 case KateSessionChooser::RESULT_OPEN_EXISTING:
196 if (!m_sessionManager->
activateSession(chooser->getSelectedSessionId()))
205 TDEStartupInfo::appStarted(startupId());
220 TQTextCodec *codec = m_args->isSet(
"encoding") ? TQTextCodec::codecForName(m_args->getOption(
"encoding")) : 0;
222 bool tempfileSet = TDECmdLineArgs::isTempFileSet();
224 Kate::Document::setOpenErrorDialogsActivated (
false);
226 for (
int z=0; z<m_args->count(); z++)
229 bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists();
235 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(),
false, tempfileSet );
237 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null,
false, tempfileSet );
241 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).pathOrURL()) );
244 Kate::Document::setOpenErrorDialogsActivated (
true);
247 if( m_args->isSet(
"stdin" ) )
249 TQTextIStream input(stdin);
253 input.setCodec (codec);
260 line = input.readLine();
261 text.append( line +
"\n" );
262 }
while( !line.isNull() );
270 activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber());
276 if (m_args->isSet (
"line"))
278 line = m_args->getOption (
"line").toInt();
282 if (m_args->isSet (
"column"))
284 column = m_args->getOption (
"column").toInt();
289 activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column);
299 if (!win->queryClose_internal())
303 dcopClient()->detach();
306 while (!m_mainWindows.isEmpty())
307 delete m_mainWindows[0];
314 bool saveSessions =
false;
316 if (switchOption == KateSessionManager::SWITCH_SAVE)
320 else if (switchOption == KateSessionManager::SWITCH_ASK)
322 KDialogBase *dlg =
new KDialogBase(i18n(
"Save Sessions"),
323 KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
324 KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL,
true,
false,
325 KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
326 bool dontAgain =
false;
327 int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
328 i18n(
"<p>Do you want to save the existing sessions?<p>!!NOTE!!"
329 "<p>All existing sessions will be removed "
330 "if you choose \"Delete\""), TQStringList(),
331 i18n(
"Do not ask again"), &dontAgain, KMessageBox::Notify);
332 if (res == KDialogBase::Cancel)
338 if (res == KDialogBase::No)
347 if (res == KDialogBase::Yes)
368 return m_pluginManager;
378 return m_sessionManager;
388 TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1());
390 kdDebug () <<
"OPEN URL "<< encoding << endl;
393 bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists();
399 mainWindow->viewManager()->openURL( url, codec->name(),
true, isTempFile );
401 mainWindow->viewManager()->openURL( url, TQString::null,
true, isTempFile );
405 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.pathOrURL()) );
417 mainWindow->viewManager()->activeView ()->setCursorPosition (line, column);
436 KateMainWindow *
mainWindow =
new KateMainWindow (sconfig, sgroup);
439 if ((
mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView())
440 mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() );
441 else if ((
mainWindows() > 1) && (m_docManager->documents() > 0))
442 mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() );
443 else if ((
mainWindows() > 1) && (m_docManager->documents() < 1))
444 mainWindow->viewManager()->openURL ( KURL() );
458 if (m_mainWindows.isEmpty())
461 int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow());
466 return m_mainWindows[n];
471 return m_mainWindows.size();
476 if (n < m_mainWindows.size())
477 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...