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));
81 m_obj =
new KateAppDCOPIface (
this);
83 kdDebug()<<
"Setting KATE_PID: '"<<getpid()<<
"'"<<endl;
84 ::setenv(
"KATE_PID", TQString(TQString(
"%1").arg(getpid())).latin1(), 1 );
86 connect(
this, TQT_SIGNAL(aboutToQuit()),
this, TQT_SLOT(slotAboutToQuit()));
105 dcopClient()->resume();
111 delete m_pluginManager;
112 delete m_sessionManager;
123 return m_application;
137 return fullVersion ? TQString (
"2.5.%1").arg(KDE::versionMajor()) : TQString (
"%1.%2").arg(2.5);
140 void KateApp::restoreKate()
143 Kate::Document::setOpenErrorDialogsActivated(
false);
147 m_docManager->restoreDocumentList(sessionConfig());
149 Kate::Document::setOpenErrorDialogsActivated(
true);
159 bool KateApp::startupKate()
161 if (m_args->isSet(
"start"))
165 TQCString sessName = m_args->getOption(
"start");
167 if (sessId != KateSessionManager::INVALID_SESSION)
180 if (startupOption == KateSessionManager::STARTUP_NEW)
184 else if (startupOption == KateSessionManager::STARTUP_LAST)
190 KateSessionChooser *chooser =
new KateSessionChooser(NULL);
191 int result = chooser->exec();
194 case KateSessionChooser::RESULT_OPEN_NEW:
198 case KateSessionChooser::RESULT_OPEN_EXISTING:
199 if (!m_sessionManager->
activateSession(chooser->getSelectedSessionId()))
208 TDEStartupInfo::appStarted(startupId());
223 TQTextCodec *codec = m_args->isSet(
"encoding") ? TQTextCodec::codecForName(m_args->getOption(
"encoding")) : 0;
225 bool tempfileSet = TDECmdLineArgs::isTempFileSet();
227 Kate::Document::setOpenErrorDialogsActivated (
false);
229 for (
int z=0; z<m_args->count(); z++)
232 bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists();
238 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(),
false, tempfileSet );
240 id =
activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null,
false, tempfileSet );
244 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).url()) );
247 Kate::Document::setOpenErrorDialogsActivated (
true);
250 if( m_args->isSet(
"stdin" ) )
252 TQTextIStream input(stdin);
256 input.setCodec (codec);
263 line = input.readLine();
264 text.append( line +
"\n" );
265 }
while( !line.isNull() );
273 activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber());
279 if (m_args->isSet (
"line"))
281 line = m_args->getOption (
"line").toInt();
285 if (m_args->isSet (
"column"))
287 column = m_args->getOption (
"column").toInt();
292 activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column);
306 dcopClient()->detach();
309 while (!m_mainWindows.isEmpty())
310 delete m_mainWindows[0];
317 bool saveSessions =
false;
319 if (switchOption == KateSessionManager::SWITCH_SAVE)
323 else if (switchOption == KateSessionManager::SWITCH_ASK)
325 KDialogBase *dlg =
new KDialogBase(i18n(
"Save Sessions"),
326 KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
327 KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL,
true,
false,
328 KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
329 bool dontAgain =
false;
330 int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
331 i18n(
"<p>Do you want to save the existing sessions?<p>!!NOTE!!" 332 "<p>All existing sessions will be removed " 333 "if you choose \"Delete\""), TQStringList(),
334 i18n(
"Do not ask again"), &dontAgain, KMessageBox::Notify);
335 if (res == KDialogBase::Cancel)
341 if (res == KDialogBase::No)
350 if (res == KDialogBase::Yes)
371 return m_pluginManager;
381 return m_sessionManager;
391 TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1());
393 kdDebug () <<
"OPEN URL "<< encoding << endl;
396 bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists();
402 mainWindow->viewManager()->openURL( url, codec->name(),
true, isTempFile );
404 mainWindow->viewManager()->openURL( url, TQString::null,
true, isTempFile );
407 KMessageBox::sorry( mainWindow,
408 i18n(
"The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.url()) );
420 mainWindow->viewManager()->activeView ()->setCursorPosition (line, column);
439 KateMainWindow *
mainWindow =
new KateMainWindow (sconfig, sgroup);
440 m_mainWindows.push_back (mainWindow);
442 if ((
mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView())
443 mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() );
444 else if ((
mainWindows() > 1) && (m_docManager->documents() > 0))
445 mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() );
446 else if ((
mainWindows() > 1) && (m_docManager->documents() < 1))
447 mainWindow->viewManager()->openURL ( KURL() );
456 m_mainWindows.remove (mainWindow);
461 if (m_mainWindows.isEmpty())
464 int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow());
469 return m_mainWindows[n];
474 return m_mainWindows.size();
479 if (n < m_mainWindows.size())
480 return m_mainWindows[n];
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
int getSessionIdFromName(const TQString &name)
Return the session id of the first session whose name matches the provided one.
~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 ...
void saveActiveSession()
Saves the active session sessionSaved (through invoked "void saveSession(int)" method) ...
bool activateSession(int sessionId, bool saveCurr=true)
Activate the selected session.
Kate::Application * application()
accessor to the Kate::Application plugin interface
KateMainWindow * newMainWindow(TDEConfig *sconfig=0, const TQString &sgroup="")
window management
The Kate session manager.
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
const int getSwitchOption()
KateSessionManager * sessionManager()
accessor to session manager
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
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 setSwitchOption(int option)
Set the new session switch preference.
void removeMainWindow(KateMainWindow *mainWindow)
removes the mainwindow given, DOES NOT DELETE IT
bool setCursor(int line, int column)
position cursor in current active view
void reparse_config()
called after the config dialog has been closed.
Interface to the application, beside some global methodes to access other objects like document/proje...
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.
int newSession(const TQString &sessionName=TQString::null, bool saveCurr=true)
Create a new session and activate it.
const int getStartupOption()
void saveConfig(bool saveSessions)
Save session manager info.
uint mainWindows() const
give back number of existing main windows
bool restoreLastSession()
Restore the last saved session.