diff options
Diffstat (limited to 'kate/app')
54 files changed, 15224 insertions, 0 deletions
diff --git a/kate/app/CMakeLists.txt b/kate/app/CMakeLists.txt new file mode 100644 index 000000000..7adea8ea3 --- /dev/null +++ b/kate/app/CMakeLists.txt @@ -0,0 +1,71 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_definitions( + -include tqt.h +) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### kateinterfaces (shared lib) ############### + +set( target kateinterfaces ) + +set( ${target}_SRCS + kateapp.cpp kateconfigdialog.cpp kateconfigplugindialogpage.cpp + kateconsole.cpp katedocmanager.cpp katefilelist.cpp + katefileselector.cpp katemainwindow.cpp katepluginmanager.cpp + kateviewmanager.cpp kateviewspace.cpp katemainwindowiface.skel + katemainwindowiface.cpp kategrepdialog.cpp katemailfilesdialog.cpp + kbookmarkhandler.cpp katedocmanageriface.skel kateappIface.cpp + kateappIface.skel katedocmanageriface.cpp kateexternaltools.cpp + katesavemodifieddialog.cpp kateviewspacecontainer.cpp + katemwmodonhddialog.cpp katesession.cpp katemdi.cpp + katetabwidget.cpp +) + +tde_add_library( ${target} SHARED AUTOMOC + SOURCES ${${target}_SRCS} + VERSION 0.0.0 + EMBED kateinterfacesprivate-static + LINK tdeutils-shared + DESTINATION ${LIB_INSTALL_DIR} +) + + +##### kate (tdeinit) ############################ + +set( target kate ) + +tde_add_tdeinit_executable( ${target} + SOURCES katemain.cpp + LINK kateinterfaces-shared +) + + +##### kwrite (tdeinit) ########################## + +set( target kwrite ) + +tde_add_tdeinit_executable( ${target} AUTOMOC + SOURCES kwritemain.cpp + LINK kateinterfaces-shared katepartinterfaces-shared +) diff --git a/kate/app/Makefile.am b/kate/app/Makefile.am new file mode 100644 index 000000000..de2258630 --- /dev/null +++ b/kate/app/Makefile.am @@ -0,0 +1,29 @@ +lib_LTLIBRARIES = libkateinterfaces.la +bin_PROGRAMS = +tdeinit_LTLIBRARIES = kate.la kwrite.la + +libkateinterfaces_la_SOURCES = kateapp.cpp kateconfigdialog.cpp kateconfigplugindialogpage.cpp \ + kateconsole.cpp katedocmanager.cpp katefilelist.cpp katefileselector.cpp \ + katemainwindow.cpp katepluginmanager.cpp \ + kateviewmanager.cpp kateviewspace.cpp \ + katemainwindowiface.skel katemainwindowiface.cpp kategrepdialog.cpp \ + katemailfilesdialog.cpp kbookmarkhandler.cpp \ + katedocmanageriface.skel kateappIface.cpp kateappIface.skel katedocmanageriface.cpp \ + kateexternaltools.cpp katesavemodifieddialog.cpp kateviewspacecontainer.cpp \ + katemwmodonhddialog.cpp katesession.cpp katemdi.cpp katetabwidget.cpp + +libkateinterfaces_la_LIBADD = ../interfaces/libkateinterfacesprivate.la $(LIB_TDEUTILS) ../utils/libkateutils.la + +libkateinterfaces_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined + +kate_la_SOURCES = katemain.cpp +kate_la_LIBADD = libkateinterfaces.la +kate_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -module -avoid-version + +kwrite_la_SOURCES = kwritemain.cpp +kwrite_la_LIBADD = -lkatepartinterfaces ../utils/libkateutils.la +kwrite_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -module -avoid-version + +METASOURCES = AUTO + +INCLUDES= -I../interfaces -I$(srcdir)/../lib $(all_includes) diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp new file mode 100644 index 000000000..9cba61cc6 --- /dev/null +++ b/kate/app/kateapp.cpp @@ -0,0 +1,403 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateapp.h" +#include "kateapp.moc" + +#include "katedocmanager.h" +#include "katepluginmanager.h" +#include "kateviewmanager.h" +#include "kateappIface.h" +#include "katesession.h" +#include "katemainwindow.h" + +#include "../interfaces/application.h" + +#include <tdeversion.h> +#include <tdecmdlineargs.h> +#include <dcopclient.h> +#include <tdeconfig.h> +#include <twin.h> +#include <ktip.h> +#include <kdebug.h> +#include <klibloader.h> +#include <tdemessagebox.h> +#include <tdelocale.h> +#include <ksimpleconfig.h> +#include <tdestartupinfo.h> + +#include <tqfile.h> +#include <tqtimer.h> +#include <tqdir.h> +#include <tqtextcodec.h> + +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> + +KateApp::KateApp (TDECmdLineArgs *args) + : TDEApplication () + , m_args (args) + , m_shouldExit (false) +{ + // Don't handle DCOP requests yet + dcopClient()->suspend(); + + // insert right translations for the katepart + TDEGlobal::locale()->insertCatalogue("katepart"); + + // some global default + Kate::Document::setFileChangedDialogsActivated (true); + + // application interface + m_application = new Kate::Application (this); + + // doc + project man + m_docManager = new KateDocManager (TQT_TQOBJECT(this)); + + // init all normal plugins + m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this)); + + // session manager up + m_sessionManager = new KateSessionManager (TQT_TQOBJECT(this)); + + // application dcop interface + m_obj = new KateAppDCOPIface (this); + + kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl; + ::setenv( "KATE_PID", TQString(TQString("%1").arg(getpid())).latin1(), 1 ); + + // handle restore different + if (isRestored()) + { + restoreKate (); + } + else + { + // let us handle our command line args and co ;) + // we can exit here if session chooser decides + if (!startupKate ()) + { + m_shouldExit = true; + return; + } + } + + // Ok. We are ready for DCOP requests. + dcopClient()->resume(); +} + +KateApp::~KateApp () +{ + // cu dcop interface + delete m_obj; + + // cu plugin manager + delete m_pluginManager; + + // delete this now, or we crash + delete m_docManager; +} + +KateApp *KateApp::self () +{ + return (KateApp *) kapp; +} + +Kate::Application *KateApp::application () +{ + return m_application; +} + +/** + * Has always been the Kate Versioning Scheme: + * KDE X.Y.Z contains Kate X-1.Y.Z + */ +TQString KateApp::kateVersion (bool fullVersion) +{ +// return fullVersion ? TQString ("%1.%2.%3").arg(KDE::versionMajor() - 1).arg(KDE::versionMinor()).arg(KDE::versionRelease()) +// : TQString ("%1.%2").arg(KDE::versionMajor() - 1).arg(KDE::versionMinor()); + /** The previous version computation scheme (commented out above) worked fine in the 3.5.x days. + With the new Trinity Rx.y.z scheme the version number gets weird. + We now hard-code the first two numbers to match the 3.5.x days and only update the last number. */ + return fullVersion ? TQString ("2.5.%1").arg(KDE::versionMajor()) : TQString ("%1.%2").arg(2.5); +} + +void KateApp::restoreKate () +{ + // restore the nice files ;) we need it + Kate::Document::setOpenErrorDialogsActivated (false); + + // activate again correct session!!! + sessionConfig()->setGroup("General"); + TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession")); + sessionManager()->activateSession (new KateSession (sessionManager(), lastSession, ""), false, false, false); + + m_docManager->restoreDocumentList (sessionConfig()); + + Kate::Document::setOpenErrorDialogsActivated (true); + + // restore all windows ;) + for (int n=1; TDEMainWindow::canBeRestored(n); n++) + newMainWindow(sessionConfig(), TQString ("%1").arg(n)); + + // oh, no mainwindow, create one, should not happen, but make sure ;) + if (mainWindows() == 0) + newMainWindow (); + + // Do not notify about start there: this makes kicker crazy and kate go to a wrong desktop. + // TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId()); +} + +bool KateApp::startupKate () +{ + // user specified session to open + if (m_args->isSet ("start")) + { + sessionManager()->activateSession (sessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false); + } + else + { + // let the user choose session if possible + if (!sessionManager()->chooseSession ()) + { + // we will exit kate now, notify the rest of the world we are done + TDEStartupInfo::appStarted (startupId()); + return false; + } + } + + // oh, no mainwindow, create one, should not happen, but make sure ;) + if (mainWindows() == 0) + newMainWindow (); + + // notify about start + TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId()); + + TQTextCodec *codec = m_args->isSet("encoding") ? TQTextCodec::codecForName(m_args->getOption("encoding")) : 0; + + bool tempfileSet = TDECmdLineArgs::isTempFileSet(); + + Kate::Document::setOpenErrorDialogsActivated (false); + uint id = 0; + for (int z=0; z<m_args->count(); z++) + { + // this file is no local dir, open it, else warn + bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists(); + + if (noDir) + { + // open a normal file + if (codec) + id = activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(), false, tempfileSet ); + else + id = activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null, false, tempfileSet ); + } + else + KMessageBox::sorry( activeMainWindow(), + i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).url()) ); + } + + Kate::Document::setOpenErrorDialogsActivated (true); + + // handle stdin input + if( m_args->isSet( "stdin" ) ) + { + TQTextIStream input(stdin); + + // set chosen codec + if (codec) + input.setCodec (codec); + + TQString line; + TQString text; + + do + { + line = input.readLine(); + text.append( line + "\n" ); + } while( !line.isNull() ); + + openInput (text); + } + else if ( id ) + activeMainWindow()->viewManager()->activateView( id ); + + if ( activeMainWindow()->viewManager()->viewCount () == 0 ) + activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber()); + + int line = 0; + int column = 0; + bool nav = false; + + if (m_args->isSet ("line")) + { + line = m_args->getOption ("line").toInt(); + nav = true; + } + + if (m_args->isSet ("column")) + { + column = m_args->getOption ("column").toInt(); + nav = true; + } + + if (nav) + activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column); + + // show the nice tips + KTipDialog::showTip(activeMainWindow()); + + return true; +} + +void KateApp::shutdownKate (KateMainWindow *win) +{ + if (!win->queryClose_internal()) + return; + + sessionManager()->saveActiveSession(true, true); + + // detach the dcopClient + dcopClient()->detach(); + + // cu main windows + while (!m_mainWindows.isEmpty()) + delete m_mainWindows[0]; + + quit (); +} + +KatePluginManager *KateApp::pluginManager() +{ + return m_pluginManager; +} + +KateDocManager *KateApp::documentManager () +{ + return m_docManager; +} + +KateSessionManager *KateApp::sessionManager () +{ + return m_sessionManager; +} + +bool KateApp::openURL (const KURL &url, const TQString &encoding, bool isTempFile) +{ + KateMainWindow *mainWindow = activeMainWindow (); + + if (!mainWindow) + return false; + + TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1()); + + kdDebug () << "OPEN URL "<< encoding << endl; + + // this file is no local dir, open it, else warn + bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists(); + + if (noDir) + { + // open a normal file + if (codec) + mainWindow->viewManager()->openURL( url, codec->name(), true, isTempFile ); + else + mainWindow->viewManager()->openURL( url, TQString::null, true, isTempFile ); + } + else + KMessageBox::sorry( mainWindow, + i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.url()) ); + + return true; +} + +bool KateApp::setCursor (int line, int column) +{ + KateMainWindow *mainWindow = activeMainWindow (); + + if (!mainWindow) + return false; + + mainWindow->viewManager()->activeView ()->setCursorPosition (line, column); + + return true; +} + +bool KateApp::openInput (const TQString &text) +{ + activeMainWindow()->viewManager()->openURL( "", "", true ); + + if (!activeMainWindow()->viewManager()->activeView ()) + return false; + + activeMainWindow()->viewManager()->activeView ()->getDoc()->setText (text); + + return true; +} + +KateMainWindow *KateApp::newMainWindow (TDEConfig *sconfig, const TQString &sgroup) +{ + KateMainWindow *mainWindow = new KateMainWindow (sconfig, sgroup); + m_mainWindows.push_back (mainWindow); + + if ((mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()) + mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() ); + else if ((mainWindows() > 1) && (m_docManager->documents() > 0)) + mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() ); + else if ((mainWindows() > 1) && (m_docManager->documents() < 1)) + mainWindow->viewManager()->openURL ( KURL() ); + + mainWindow->show (); + + return mainWindow; +} + +void KateApp::removeMainWindow (KateMainWindow *mainWindow) +{ + m_mainWindows.remove (mainWindow); +} + +KateMainWindow *KateApp::activeMainWindow () +{ + if (m_mainWindows.isEmpty()) + return 0; + + int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow()); + + if (n < 0) + n=0; + + return m_mainWindows[n]; +} + +uint KateApp::mainWindows () const +{ + return m_mainWindows.size(); +} + +KateMainWindow *KateApp::mainWindow (uint n) +{ + if (n < m_mainWindows.size()) + return m_mainWindows[n]; + + return 0; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h new file mode 100644 index 000000000..05d09a7fe --- /dev/null +++ b/kate/app/kateapp.h @@ -0,0 +1,243 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_APP_H__ +#define __KATE_APP_H__ + +#include "katemain.h" + +#include <tdeapplication.h> + +#include <tqvaluelist.h> + +class KateSessionManager; +class KateAppDCOPIface; + +namespace Kate { + class Application; +} + +class TDECmdLineArgs; + +/** + * Kate Application + * This class represents the core kate application object + */ +class KDE_EXPORT KateApp : public TDEApplication +{ + Q_OBJECT + + /** + * constructors & accessor to app object + plugin interface for it + */ + public: + /** + * application constructor + * @param args parsed command line args + */ + KateApp (TDECmdLineArgs *args); + + /** + * application destructor + */ + ~KateApp (); + + /** + * static accessor to avoid casting ;) + * @return app instance + */ + static KateApp *self (); + + /** + * accessor to the Kate::Application plugin interface + * @return application plugin interface + */ + Kate::Application *application (); + + /** + * Returns the current Kate version (X.Y) or (X.Y.Z) + * @param fullVersion should full version be returned? + * @return Kate version + */ + static TQString kateVersion (bool fullVersion = true); + + /** + * kate init + */ + private: + /** + * restore a old kate session + */ + void restoreKate (); + + /** + * try to start kate + * @return success, if false, kate should exit + */ + bool startupKate (); + + /** + * kate shutdown + */ + public: + /** + * shutdown kate application + * @param win mainwindow which is used for dialogs + */ + void shutdownKate (KateMainWindow *win); + + /** + * application should exit + * @return should we exit? + */ + bool shouldExit () { return m_shouldExit; } + + /** + * other accessors for global unique instances + */ + public: + /** + * accessor to plugin manager + * @return plugin manager instance + */ + KatePluginManager *pluginManager(); + + /** + * accessor to document manager + * @return document manager instance + */ + KateDocManager *documentManager (); + + /** + * accessor to session manager + * @return session manager instance + */ + KateSessionManager *sessionManager (); + + /** + * window management + */ + public: + /** + * create a new main window, use given config if any for restore + * @param sconfig session config object + * @param sgroup session group for this window + * @return new constructed main window + */ + KateMainWindow *newMainWindow (TDEConfig *sconfig = 0, const TQString &sgroup = ""); + + /** + * removes the mainwindow given, DOES NOT DELETE IT + * @param mainWindow window to remove + */ + void removeMainWindow (KateMainWindow *mainWindow); + + /** + * give back current active main window + * can only be 0 at app start or exit + * @return current active main window + */ + KateMainWindow *activeMainWindow (); + + /** + * give back number of existing main windows + * @return number of main windows + */ + uint mainWindows () const; + + /** + * give back the window you want + * @param n window index + * @return requested main window + */ + KateMainWindow *mainWindow (uint n); + + /** + * some stuff for the dcop API + */ + public: + /** + * open url with given encoding + * used by kate if --use given + * @param url filename + * @param encoding encoding name + * @param isTempFile if set to true and the file is a local file, it will be deleted when the document is closed. + * @return success + */ + bool openURL (const KURL &url, const TQString &encoding, bool isTempFile ); + + /** + * position cursor in current active view + * @param line line to set + * @param column column to set + * @return success + */ + bool setCursor (int line, int column); + + /** + * helper to handle stdin input + * open a new document/view, fill it with the text given + * @param text text to fill in the new doc/view + * @return success + */ + bool openInput (const TQString &text); + + private: + /** + * kate's command line args + */ + TDECmdLineArgs *m_args; + + /** + * plugin interface + */ + Kate::Application *m_application; + + /** + * document manager + */ + KateDocManager *m_docManager; + + /** + * plugin manager + */ + KatePluginManager *m_pluginManager; + + /** + * session manager + */ + KateSessionManager *m_sessionManager; + + /** + * known main windows + */ + TQValueList<KateMainWindow*> m_mainWindows; + + /** + * dcop interface + */ + KateAppDCOPIface *m_obj; + + /** + * should exit flag + */ + bool m_shouldExit; +}; + +#endif diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp new file mode 100644 index 000000000..259e48b89 --- /dev/null +++ b/kate/app/kateappIface.cpp @@ -0,0 +1,104 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateappIface.h" + +#include "kateapp.h" +#include "katesession.h" +#include "katedocmanager.h" +#include "katemainwindow.h" + +KateAppDCOPIface::KateAppDCOPIface (KateApp *app) : DCOPObject ("KateApplication") + , m_app (app) +{ +} + +DCOPRef KateAppDCOPIface::documentManager () +{ + return DCOPRef (m_app->documentManager()->dcopObject ()); +} + +DCOPRef KateAppDCOPIface::activeMainWindow () +{ + KateMainWindow *win = m_app->activeMainWindow(); + + if (win) + return DCOPRef (win->dcopObject ()); + + return DCOPRef (); +} + +uint KateAppDCOPIface::activeMainWindowNumber () +{ + KateMainWindow *win = m_app->activeMainWindow(); + + if (win) + return win->mainWindowNumber (); + + return 0; +} + + +uint KateAppDCOPIface::mainWindows () +{ + return m_app->mainWindows (); +} + +DCOPRef KateAppDCOPIface::mainWindow (uint n) +{ + KateMainWindow *win = m_app->mainWindow(n); + + if (win) + return DCOPRef (win->dcopObject ()); + + return DCOPRef (); +} + +bool KateAppDCOPIface::openURL (KURL url, TQString encoding) +{ + return m_app->openURL (url, encoding, false); +} + +bool KateAppDCOPIface::openURL (KURL url, TQString encoding, bool isTempFile) +{ + return m_app->openURL (url, encoding, isTempFile); +} + +bool KateAppDCOPIface::setCursor (int line, int column) +{ + return m_app->setCursor (line, column); +} + +bool KateAppDCOPIface::openInput (TQString text) +{ + return m_app->openInput (text); +} + +bool KateAppDCOPIface::activateSession (TQString session) +{ + m_app->sessionManager()->activateSession (m_app->sessionManager()->giveSession (session)); + + return true; +} + +const TQString & KateAppDCOPIface::session() const +{ + return m_app->sessionManager()->activeSession()->sessionName(); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateappIface.h b/kate/app/kateappIface.h new file mode 100644 index 000000000..c57e788c8 --- /dev/null +++ b/kate/app/kateappIface.h @@ -0,0 +1,94 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _kateapp_Iface_h_ +#define _kateapp_Iface_h_ + +#include <dcopobject.h> +#include <dcopref.h> +#include <kurl.h> + +class KateApp; + +class KateAppDCOPIface : public DCOPObject +{ + K_DCOP + + public: + KateAppDCOPIface (KateApp *app); + + k_dcop: + DCOPRef documentManager (); + + DCOPRef activeMainWindow (); + + uint activeMainWindowNumber (); + + uint mainWindows (); + DCOPRef mainWindow (uint n = 0); + + /** + * open a file with given url and encoding + * will get view created + * @param url url of the file + * @param encoding encoding name + * @return success + */ + bool openURL (KURL url, TQString encoding); + + /** + * Like the above, but adds an option to let the documentManager know + * if the file should be deleted when closed. + * @p isTempFile should be set to true with the --tempfile option set ONLY, + * files opened with this set to true will be deleted when closed. + */ + bool openURL(KURL url, TQString encoding, bool isTempFile); + + /** + * set cursor of active view in active main window + * @param line line for cursor + * @param column column for cursor + * @return success + */ + bool setCursor (int line, int column); + + /** + * helper to handle stdin input + * open a new document/view, fill it with the text given + * @param text text to fill in the new doc/view + * @return success + */ + bool openInput (TQString text); + + /** + * activate a given session + * @param session session name + * @return success + */ + bool activateSession (TQString session); + + /** + * @return the name of the active session + */ + const TQString & session() const; + + private: + KateApp *m_app; +}; + +#endif diff --git a/kate/app/kateconfigdialog.cpp b/kate/app/kateconfigdialog.cpp new file mode 100644 index 000000000..697e46644 --- /dev/null +++ b/kate/app/kateconfigdialog.cpp @@ -0,0 +1,476 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateconfigdialog.h" +#include "kateconfigdialog.moc" + +#include "katemainwindow.h" + +#include "kateconsole.h" +#include "katedocmanager.h" +#include "katepluginmanager.h" +#include "kateconfigplugindialogpage.h" +#include "kateviewmanager.h" +#include "kateapp.h" +#include "katefileselector.h" +#include "katefilelist.h" +#include "kateexternaltools.h" + +#include <tqbuttongroup.h> +#include <tqcheckbox.h> +#include <tqhbox.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqpushbutton.h> +#include <tqradiobutton.h> +#include <tqspinbox.h> +#include <tqvbox.h> +#include <tqwhatsthis.h> +#include <tqcombobox.h> + +#include <kinstance.h> +#include <kdebug.h> +#include <kdialogbase.h> +#include <kglobalaccel.h> +#include <tdeglobal.h> +#include <tdeglobalsettings.h> +#include <kiconloader.h> +#include <kkeydialog.h> +#include <tdelistbox.h> +#include <tdelocale.h> +#include <ksimpleconfig.h> +#include <kstdaction.h> +#include <kstandarddirs.h> +#include <twin.h> +#include <kseparator.h> + +KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view ) + : KDialogBase ( KDialogBase::TreeList, + i18n("Configure"), + KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help, + KDialogBase::Ok, + parent, + "configdialog" ) +{ + TDEConfig *config = KateApp::self()->config(); + + KWin::setIcons( winId(), KateApp::self()->icon(), KateApp::self()->miniIcon() ); + + actionButton( KDialogBase::Apply)->setEnabled( false ); + + mainWindow = parent; + + setMinimumSize(600,400); + + v = view; + + pluginPages.setAutoDelete (false); + editorPages.setAutoDelete (false); + + TQStringList path; + + setShowIconsInTreeList(true); + + path.clear(); + path << i18n("Application"); + setFolderIcon (path, SmallIcon("kate", TDEIcon::SizeSmall)); + + path.clear(); + + //BEGIN General page + path << i18n("Application") << i18n("General"); + TQFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", TDEIcon::SizeSmall)); + + TQVBoxLayout *lo = new TQVBoxLayout( frGeneral ); + lo->setSpacing(KDialog::spacingHint()); + config->setGroup("General"); + + // GROUP with the one below: "Appearance" + TQButtonGroup *bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Appearance"), frGeneral ); + lo->addWidget( bgStartup ); + + // show full path in title + config->setGroup("General"); + cb_fullPath = new TQCheckBox( i18n("&Show full path in title"), bgStartup); + cb_fullPath->setChecked( mainWindow->viewManager()->getShowFullPath() ); + TQWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption.")); + connect( cb_fullPath, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + // sort filelist if desired + cb_sortFiles = new TQCheckBox(bgStartup); + cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list")); + cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName); + TQWhatsThis::add( cb_sortFiles, i18n( + "If this is checked, the files in the file list will be sorted alphabetically.") ); + connect( cb_sortFiles, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + // GROUP with the one below: "Behavior" + bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral ); + lo->addWidget( bgStartup ); + + // number of recent files + TQHBox *hbNrf = new TQHBox( bgStartup ); + TQLabel *lNrf = new TQLabel( i18n("&Number of recent files:"), hbNrf ); + sb_numRecentFiles = new TQSpinBox( 0, 1000, 1, hbNrf ); + sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() ); + lNrf->setBuddy( sb_numRecentFiles ); + TQString numRecentFileHelpString ( i18n( + "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>" + "If you set this lower than the current value, the list will be truncated and " + "some items forgotten.</qt>") ); + TQWhatsThis::add( lNrf, numRecentFileHelpString ); + TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString ); + connect( sb_numRecentFiles, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); + + // Use only one instance of kate (MDI) ? + cb_useInstance = new TQCheckBox(bgStartup); + cb_useInstance->setText(i18n("Always use the current instance of kate to open new files")); + cb_useInstance->setChecked(parent->useInstance); + TQWhatsThis::add( cb_useInstance, i18n( + "When checked, all files opened from outside of Kate will only use the " + "currently opened instance of Kate.") ); + connect( cb_useInstance, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + // sync the konsole ? + cb_syncKonsole = new TQCheckBox(bgStartup); + cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document")); + cb_syncKonsole->setChecked(parent->syncKonsole); + TQWhatsThis::add( cb_syncKonsole, i18n( + "If this is checked, the built in Konsole will <code>cd</code> to the directory " + "of the active document when started and whenever the active document changes, " + "if the document is a local file.") ); + connect( cb_syncKonsole, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + // modified files notification + cb_modNotifications = new TQCheckBox( + i18n("Wa&rn about files modified by foreign processes"), bgStartup ); + cb_modNotifications->setChecked( parent->modNotification ); + TQWhatsThis::add( cb_modNotifications, i18n( + "If enabled, when Kate receives focus you will be asked what to do with " + "files that have been modified on the hard disk. If not enabled, you will " + "be asked what to do with a file that has been modified on the hard disk only " + "when that file gains focus inside Kate.") ); + connect( cb_modNotifications, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( slotChanged() ) ); + + // GROUP with the one below: "Meta-informations" + bgStartup = new TQButtonGroup( 2, Qt::Horizontal, i18n("Meta-Information"), frGeneral ); + lo->addWidget( bgStartup ); + + // save meta infos + cb_saveMetaInfos = new TQCheckBox( bgStartup ); + cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions")); + cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos()); + TQWhatsThis::add(cb_saveMetaInfos, i18n( + "Check this if you want document configuration like for example " + "bookmarks to be saved past editor sessions. The configuration will be " + "restored if the document has not changed when reopened.")); + connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + // meta infos days + TQHBox *hbDmf = new TQHBox( bgStartup ); + hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos()); + TQLabel *lDmf = new TQLabel( i18n("&Delete unused meta-information after:"), hbDmf ); + sb_daysMetaInfos = new TQSpinBox( 0, 180, 1, hbDmf ); + sb_daysMetaInfos->setSpecialValueText(i18n("(never)")); + sb_daysMetaInfos->setSuffix(i18n(" day(s)")); + sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() ); + lDmf->setBuddy( sb_daysMetaInfos ); + connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), hbDmf, TQT_SLOT( setEnabled( bool ) ) ); + connect( sb_daysMetaInfos, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) ); + + lo->addStretch(1); // :-] works correct without autoadd + //END General page + + path.clear(); + + //BEGIN Session page + path << i18n("Application") << i18n("Sessions"); + TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", TDEIcon::SizeSmall)); + + lo = new TQVBoxLayout( frSessions ); + lo->setSpacing(KDialog::spacingHint()); + + // GROUP with the one below: "Startup" + bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions ); + lo->addWidget( bgStartup ); + + // restore view config + cb_restoreVC = new TQCheckBox( bgStartup ); + cb_restoreVC->setText(i18n("Include &window configuration")); + config->setGroup("General"); + cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) ); + TQWhatsThis::add(cb_restoreVC, i18n( + "Check this if you want all your views and frames restored each time you open Kate")); + connect( cb_restoreVC, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) ); + + TQRadioButton *rb1, *rb2, *rb3; + + sessions_start = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions ); + lo->add (sessions_start); + + sessions_start->setRadioButtonExclusive( true ); + sessions_start->insert( rb1=new TQRadioButton( i18n("&Start new session"), sessions_start ), 0 ); + sessions_start->insert( rb2=new TQRadioButton( i18n("&Load last-used session"), sessions_start ), 1 ); + sessions_start->insert( rb3=new TQRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 ); + + config->setGroup("General"); + TQString sesStart (config->readEntry ("Startup Session", "manual")); + if (sesStart == "new") + sessions_start->setButton (0); + else if (sesStart == "last") + sessions_start->setButton (1); + else + sessions_start->setButton (2); + + connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + + sessions_exit = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions ); + lo->add (sessions_exit); + + sessions_exit->setRadioButtonExclusive( true ); + sessions_exit->insert( rb1=new TQRadioButton( i18n("&Do not save session"), sessions_exit ), 0 ); + sessions_exit->insert( rb2=new TQRadioButton( i18n("&Save session"), sessions_exit ), 1 ); + sessions_exit->insert( rb3=new TQRadioButton( i18n("&Ask user"), sessions_exit ), 2 ); + + config->setGroup("General"); + TQString sesExit (config->readEntry ("Session Exit", "save")); + if (sesExit == "discard") + sessions_exit->setButton (0); + else if (sesExit == "save") + sessions_exit->setButton (1); + else + sessions_exit->setButton (2); + + connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged())); + + lo->addStretch(1); // :-] works correct without autoadd + //END Session page + + path.clear(); + + // file selector page + path << i18n("Application") << i18n("File Selector"); + + TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"), + BarIcon("fileopen", TDEIcon::SizeSmall) ); + fileSelConfigPage = new KFSConfigPage( page, "file selector config page", + mainWindow->fileselector ); + connect( fileSelConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); + path.clear(); + + path << i18n("Application") << i18n("Document List"); + page = addVBoxPage( path, i18n("Document List Settings"), + BarIcon("view_text", TDEIcon::SizeSmall) ); + filelistConfigPage = new KFLConfigPage( page, "file list config page", + mainWindow->filelist ); + connect( filelistConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); + path.clear(); + + path << i18n("Application") << i18n("Plugins"); + /*TQVBox **/page=addVBoxPage(path,i18n("Plugin Manager"), + BarIcon("connect_established",TDEIcon::SizeSmall)); + KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this); + connect( configPluginPage, TQT_SIGNAL( changed() ), TQT_TQOBJECT(this), TQT_SLOT( slotChanged() ) ); + + // Tools->External Tools menu + path.clear(); + path << i18n("Application") << i18n("External Tools"); + page = addVBoxPage( path, i18n("External Tools"), + BarIcon("configure", TDEIcon::SizeSmall) ); + configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page"); + connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(this), TQT_SLOT(slotChanged()) ); + + // editor widgets from kwrite/kwdialog + path.clear(); + path << i18n("Editor"); + setFolderIcon (path, SmallIcon("edit", TDEIcon::SizeSmall)); + + for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++) + { + path.clear(); + path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i); + /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i), + KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, TDEIcon::SizeSmall) ); + + KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page); + connect( cPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); + editorPages.append (cPage); + } + + KatePluginList &pluginList (KatePluginManager::self()->pluginList()); + for (unsigned int i=0; i < pluginList.size(); ++i) + { + if ( pluginList[i].load + && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) ) + addPluginPage (pluginList[i].plugin); + } + + enableButtonSeparator(true); + dataChanged = false; + unfoldTreeList (); +} + +KateConfigDialog::~KateConfigDialog() +{ +} + +void KateConfigDialog::addPluginPage (Kate::Plugin *plugin) +{ + if (!Kate::pluginConfigInterfaceExtension(plugin)) + return; + + for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++) + { + TQStringList path; + path.clear(); + path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i); + TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, TDEIcon::SizeSmall)); + + PluginPageListItem *info=new PluginPageListItem; + info->plugin = plugin; + info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page); + connect( info->page, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) ); + pluginPages.append(info); + } +} + +void KateConfigDialog::removePluginPage (Kate::Plugin *plugin) +{ + if (!Kate::pluginConfigInterfaceExtension(plugin)) + return; + + for (uint i=0; i<pluginPages.count(); i++) + { + if ( pluginPages.at(i)->plugin == plugin ) + { + TQWidget *w = pluginPages.at(i)->page->parentWidget(); + delete pluginPages.at(i)->page; + delete w; + pluginPages.remove(pluginPages.at(i)); + i--; + } + } +} + +void KateConfigDialog::slotOk() +{ + slotApply(); + accept(); +} + +void KateConfigDialog::slotApply() +{ + TDEConfig *config = KateApp::self()->config(); + + // if data changed apply the kate app stuff + if( dataChanged ) + { + config->setGroup("General"); + + config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked()); + + int bu = sessions_start->id (sessions_start->selected()); + + if (bu == 0) + config->writeEntry ("Startup Session", "new"); + else if (bu == 1) + config->writeEntry ("Startup Session", "last"); + else + config->writeEntry ("Startup Session", "manual"); + + bu = sessions_exit->id (sessions_exit->selected()); + + if (bu == 0) + config->writeEntry ("Session Exit", "discard"); + else if (bu == 1) + config->writeEntry ("Session Exit", "save"); + else + config->writeEntry ("Session Exit", "ask"); + + config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked()); + KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked()); + + config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() ); + KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value()); + + config->writeEntry("Modified Notification", cb_modNotifications->isChecked()); + mainWindow->modNotification = cb_modNotifications->isChecked(); + + mainWindow->syncKonsole = cb_syncKonsole->isChecked(); + mainWindow->useInstance = cb_useInstance->isChecked(); + mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID); + + config->writeEntry( "Number of recent files", sb_numRecentFiles->value() ); + mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() ); + + fileSelConfigPage->apply(); + + filelistConfigPage->apply(); + + configExternalToolsPage->apply(); + KateExternalToolsCommand::self()->reload(); + for (uint i=0; i < KateApp::self()->mainWindows(); i++) + { + KateMainWindow *win = KateApp::self()->mainWindow (i); + win->externalTools->reload(); + } + //mainWindow->externalTools->reload(); + + mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :( + + mainWindow->saveOptions (); + + // save plugin config !! + KateApp::self()->pluginManager()->writeConfig (); + } + + // + // editor config ! (the apply() methode will check the changed state internally) + // + for (uint i=0; i<editorPages.count(); i++) + { + editorPages.at(i)->apply(); + } + + v->getDoc()->writeConfig(config); + + // + // plugins config ! (the apply() methode SHOULD check the changed state internally) + // + for (uint i=0; i<pluginPages.count(); i++) + { + pluginPages.at(i)->page->apply(); + } + + config->sync(); + + dataChanged = false; + actionButton( KDialogBase::Apply)->setEnabled( false ); +} + +void KateConfigDialog::slotChanged() +{ + dataChanged = true; + actionButton( KDialogBase::Apply)->setEnabled( true ); +} diff --git a/kate/app/kateconfigdialog.h b/kate/app/kateconfigdialog.h new file mode 100644 index 000000000..5bbfc526d --- /dev/null +++ b/kate/app/kateconfigdialog.h @@ -0,0 +1,85 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __kate_configdialog_h__ +#define __kate_configdialog_h__ + +#include "katemain.h" + +#include "../interfaces/plugin.h" +#include "../interfaces/pluginconfiginterface.h" +#include "../interfaces/pluginconfiginterfaceextension.h" + +#include <kate/document.h> +#include <tdetexteditor/configinterfaceextension.h> + +#include <kdialogbase.h> + +class TQCheckBox; +class TQSpinBox; +class TQButtonGroup; + +struct PluginPageListItem +{ + Kate::Plugin *plugin; + Kate::PluginConfigPage *page; +}; + +class KateConfigDialog : public KDialogBase +{ + Q_OBJECT + + public: + KateConfigDialog (KateMainWindow *parent, Kate::View *view); + ~KateConfigDialog (); + + public: + void addPluginPage (Kate::Plugin *plugin); + void removePluginPage (Kate::Plugin *plugin); + + protected slots: + void slotOk(); + void slotApply(); + void slotChanged(); + + private: + KateMainWindow *mainWindow; + + Kate::View* v; + bool dataChanged; + + TQCheckBox *cb_fullPath; + TQCheckBox *cb_syncKonsole; + TQCheckBox *cb_useInstance; + TQCheckBox *cb_sortFiles; + TQSpinBox *sb_numRecentFiles; + TQCheckBox *cb_modNotifications; + TQCheckBox *cb_saveMetaInfos; + TQSpinBox *sb_daysMetaInfos; + TQCheckBox* cb_restoreVC; + TQButtonGroup *sessions_start; + TQButtonGroup *sessions_exit; + Kate::ConfigPage *fileSelConfigPage; + Kate::ConfigPage *filelistConfigPage; + Kate::ConfigPage *configExternalToolsPage; + TQPtrList<PluginPageListItem> pluginPages; + TQPtrList<KTextEditor::ConfigPage> editorPages; +}; + +#endif diff --git a/kate/app/kateconfigplugindialogpage.cpp b/kate/app/kateconfigplugindialogpage.cpp new file mode 100644 index 000000000..90d7262e5 --- /dev/null +++ b/kate/app/kateconfigplugindialogpage.cpp @@ -0,0 +1,121 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateconfigplugindialogpage.h" +#include "kateconfigplugindialogpage.moc" + +#include "katepluginmanager.h" +#include "kateconfigdialog.h" +#include <tdelistbox.h> +#include "kateapp.h" +#include <tqstringlist.h> +#include <tqhbox.h> +#include <tqlabel.h> +#include <tdelocale.h> +#include <tqpushbutton.h> +#include <tqtooltip.h> +#include <kiconloader.h> +#include <tqwhatsthis.h> + +class KatePluginListItem : public TQCheckListItem +{ + public: + KatePluginListItem(bool checked, KatePluginInfo *info, TQListView *parent); + KatePluginInfo *info() const { return mInfo; } + + protected: + void stateChange(bool); + + private: + KatePluginInfo *mInfo; + bool silentStateChange; +}; + +KatePluginListItem::KatePluginListItem(bool checked, KatePluginInfo *info, TQListView *parent) + : TQCheckListItem(parent, info->service->name(), CheckBox) + , mInfo(info) + , silentStateChange(false) +{ + silentStateChange = true; + setOn(checked); + silentStateChange = false; +} + +void KatePluginListItem::stateChange(bool b) +{ + if(!silentStateChange) + static_cast<KatePluginListView *>(listView())->stateChanged(this, b); +} + +KatePluginListView::KatePluginListView(TQWidget *parent, const char *name) + : TDEListView(parent, name) +{ +} + +void KatePluginListView::stateChanged(KatePluginListItem *item, bool b) +{ + emit stateChange(item, b); +} + +KateConfigPluginPage::KateConfigPluginPage(TQWidget *parent, KateConfigDialog *dialog):TQVBox(parent) +{ + myDialog=dialog; + + KatePluginListView* listView = new KatePluginListView(this); + listView->addColumn(i18n("Name")); + listView->addColumn(i18n("Comment")); + TQWhatsThis::add(listView,i18n("Here you can see all available Kate plugins. Those with a check mark are loaded, and will be loaded again the next time Kate is started.")); + + connect(listView, TQT_SIGNAL(stateChange(KatePluginListItem *, bool)), this, TQT_SLOT(stateChange(KatePluginListItem *, bool))); + + KatePluginList &pluginList (KatePluginManager::self()->pluginList()); + for (unsigned int i=0; i < pluginList.size(); ++i) + { + KatePluginListItem *item = new KatePluginListItem(pluginList[i].load, &pluginList[i], listView); + item->setText(0, pluginList[i].service->name()); + item->setText(1, pluginList[i].service->comment()); + } +} + + void KateConfigPluginPage::stateChange(KatePluginListItem *item, bool b) +{ + if(b) + loadPlugin(item); + else + unloadPlugin(item); + + emit changed(); +} + +void KateConfigPluginPage::loadPlugin (KatePluginListItem *item) +{ + KatePluginManager::self()->loadPlugin (item->info()); + KatePluginManager::self()->enablePluginGUI (item->info()); + myDialog->addPluginPage (item->info()->plugin); + + item->setOn(true); +} + +void KateConfigPluginPage::unloadPlugin (KatePluginListItem *item) +{ + myDialog->removePluginPage (item->info()->plugin); + KatePluginManager::self()->unloadPlugin (item->info()); + + item->setOn(false); +} diff --git a/kate/app/kateconfigplugindialogpage.h b/kate/app/kateconfigplugindialogpage.h new file mode 100644 index 000000000..009f30739 --- /dev/null +++ b/kate/app/kateconfigplugindialogpage.h @@ -0,0 +1,69 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_CONFIGPLUGINDIALOGPAGE_H__ +#define __KATE_CONFIGPLUGINDIALOGPAGE_H__ + +#include "katemain.h" +#include "katepluginmanager.h" + +#include <tdelistview.h> + +#include <tqvbox.h> + +class KatePluginListItem; + +class KatePluginListView : public TDEListView +{ + Q_OBJECT + + friend class KatePluginListItem; + + public: + KatePluginListView (TQWidget *parent = 0, const char *name = 0); + + signals: + void stateChange(KatePluginListItem *, bool); + + private: + void stateChanged(KatePluginListItem *, bool); +}; + +class KateConfigPluginPage: public TQVBox +{ + Q_OBJECT + + public: + KateConfigPluginPage(TQWidget *parent, class KateConfigDialog *dialog); + ~KateConfigPluginPage(){;}; + + private: + class KateConfigDialog *myDialog; + + signals: + void changed(); + + private slots: + void stateChange(KatePluginListItem *, bool); + + void loadPlugin (KatePluginListItem *); + void unloadPlugin (KatePluginListItem *); +}; + +#endif diff --git a/kate/app/kateconsole.cpp b/kate/app/kateconsole.cpp new file mode 100644 index 000000000..cb49ef16e --- /dev/null +++ b/kate/app/kateconsole.cpp @@ -0,0 +1,143 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateconsole.h" +#include "kateconsole.moc" + +#include "katemain.h" +#include "katemdi.h" +#include "katemainwindow.h" +#include "kateviewmanager.h" + +#include <kate/view.h> +#include <kate/document.h> + +#include <kde_terminal_interface.h> + +#include <tdeparts/part.h> + +#include <kurl.h> +#include <klibloader.h> +#include <tdelocale.h> +#include <kdebug.h> +#include <tdemessagebox.h> + +KateConsole::KateConsole (KateMainWindow *mw, KateMDI::ToolView* parent) + : TQVBox (parent) + , m_part (0) + , m_mw (mw) + , m_toolView (parent) +{ +} + +KateConsole::~KateConsole () +{ + if (m_part) + disconnect ( m_part, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); +} + +void KateConsole::loadConsoleIfNeeded() +{ + if (m_part) return; + + if (!topLevelWidget() || !parentWidget()) return; + if (!topLevelWidget() || !isVisibleTo(topLevelWidget())) return; + + KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart"); + + if (!factory) return; + + m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(TQT_TQOBJECT(this),"libkonsolepart", "KParts::ReadOnlyPart")); + + if (!m_part) return; + + setFocusProxy(m_part->widget()); + + TDEGlobal::locale()->insertCatalogue("konsole"); + + m_part->widget()->show(); + + connect ( m_part, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); + + if (m_mw->viewManager()->activeView()) + if (m_mw->viewManager()->activeView()->getDoc()->url().isValid()) + cd(KURL( m_mw->viewManager()->activeView()->getDoc()->url().path() )); +} + +void KateConsole::slotDestroyed () +{ + m_part = 0; + + // hide the dockwidget + if (parentWidget()) + { + m_mw->hideToolView (m_toolView); + m_mw->centralWidget()->setFocus (); + } +} + +void KateConsole::showEvent(TQShowEvent *) +{ + if (m_part) return; + + loadConsoleIfNeeded(); +} + +void KateConsole::cd (const KURL &url) +{ + loadConsoleIfNeeded(); + + if (!m_part) return; + + m_part->openURL (url); +} + +void KateConsole::sendInput( const TQString& text ) +{ + loadConsoleIfNeeded(); + + if (!m_part) return; + + TerminalInterface *t = static_cast<TerminalInterface*>( m_part->tqt_cast( "TerminalInterface" ) ); + + if (!t) return; + + t->sendInput (text); +} + +void KateConsole::slotPipeToConsole () +{ + if (KMessageBox::warningContinueCancel + (m_mw + , i18n ("Do you really want to pipe the text to the console? This will execute any contained commands with your user rights.") + , i18n ("Pipe to Console?") + , i18n("Pipe to Console"), "Pipe To Console Warning") != KMessageBox::Continue) + return; + + Kate::View *v = m_mw->viewManager()->activeView(); + + if (!v) + return; + + if (v->getDoc()->hasSelection ()) + sendInput (v->getDoc()->selection()); + else + sendInput (v->getDoc()->text()); +} diff --git a/kate/app/kateconsole.h b/kate/app/kateconsole.h new file mode 100644 index 000000000..dabfda38d --- /dev/null +++ b/kate/app/kateconsole.h @@ -0,0 +1,116 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_CONSOLE_H__ +#define __KATE_CONSOLE_H__ + +#include "katemain.h" + +#include <kurl.h> + +#include <tqvbox.h> + +namespace KParts { + class ReadOnlyPart; +} + +namespace KateMDI { + class ToolView; +} + +class KateMainWindow; + +/** + * KateConsole + * This class is used for the internal terminal emulator + * It uses internally the konsole part, thx to konsole devs :) + */ +class KateConsole : public TQVBox +{ + Q_OBJECT + + public: + /** + * construct us + * @param mw main window + * @param parent toolview + */ + KateConsole (KateMainWindow *mw, KateMDI::ToolView* parent); + + /** + * destruct us + */ + ~KateConsole (); + + /** + * cd to dir + * @param url given dir + */ + void cd (const KURL &url); + + /** + * send given text to console + * @param text commands for console + */ + void sendInput( const TQString& text ); + + public slots: + /** + * pipe current document to console + */ + void slotPipeToConsole (); + + private slots: + /** + * the konsole exited ;) + * handle that, hide the dock + */ + void slotDestroyed (); + + /** + * construct console if needed + */ + void loadConsoleIfNeeded(); + + protected: + /** + * the konsole get shown + * @param ev show event + */ + void showEvent(TQShowEvent *ev); + + private: + /** + * console part + */ + KParts::ReadOnlyPart *m_part; + + /** + * main window of this console + */ + KateMainWindow *m_mw; + + /** + * toolview for this console + */ + KateMDI::ToolView *m_toolView; +}; + +#endif diff --git a/kate/app/katedocmanager.cpp b/kate/app/katedocmanager.cpp new file mode 100644 index 000000000..6cca9efe0 --- /dev/null +++ b/kate/app/katedocmanager.cpp @@ -0,0 +1,612 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katedocmanager.h" +#include "katedocmanager.moc" +#include "kateapp.h" +#include "katemainwindow.h" +#include "kateviewmanager.h" +#include "katedocmanageriface.h" +#include "kateexternaltools.h" +#include "kateviewspacecontainer.h" + +#include <kate/view.h> + +#include <tdetexteditor/encodinginterface.h> + +#include <tdeparts/factory.h> + +#include <tdelocale.h> +#include <kdebug.h> +#include <tdeconfig.h> +#include <klibloader.h> +#include <kmdcodec.h> +#include <tdemessagebox.h> +#include <kencodingfiledialog.h> +#include <tdeio/job.h> +#include <twin.h> + +#include <tqdatetime.h> +#include <tqtextcodec.h> +#include <tqprogressdialog.h> + +KateDocManager::KateDocManager (TQObject *parent) + : TQObject (parent) + , m_saveMetaInfos(true) + , m_daysMetaInfos(0) +{ + m_factory = (KParts::Factory *) KLibLoader::self()->factory ("libkatepart"); + + m_documentManager = new Kate::DocumentManager (this); + m_docList.setAutoDelete(true); + m_docDict.setAutoDelete(false); + m_docInfos.setAutoDelete(true); + + m_dcop = new KateDocManagerDCOPIface (this); + + m_metaInfos = new TDEConfig("metainfos", false, false, "appdata"); + + createDoc (); +} + +KateDocManager::~KateDocManager () +{ + // save config + if (!m_docList.isEmpty()) + m_docList.at(0)->writeConfig(KateApp::self()->config()); + + if (m_saveMetaInfos) + { + // saving meta-infos when file is saved is not enough, we need to do it once more at the end + for (Kate::Document *doc = m_docList.first(); doc; doc = m_docList.next()) + saveMetaInfos(doc); + + // purge saved filesessions + if (m_daysMetaInfos > 0) + { + TQStringList groups = m_metaInfos->groupList(); + TQDateTime *def = new TQDateTime(TQDate(1970, 1, 1)); + for (TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it) + { + m_metaInfos->setGroup(*it); + TQDateTime last = m_metaInfos->readDateTimeEntry("Time", def); + if (last.daysTo(TQDateTime::currentDateTime()) > m_daysMetaInfos) + m_metaInfos->deleteGroup(*it); + } + delete def; + } + } + + delete m_dcop; + delete m_metaInfos; +} + +KateDocManager *KateDocManager::self () +{ + return KateApp::self()->documentManager (); +} + +Kate::Document *KateDocManager::createDoc () +{ + KTextEditor::Document *doc = (KTextEditor::Document *) m_factory->createPart (0, "", this, "", "KTextEditor::Document"); + + m_docList.append((Kate::Document *)doc); + m_docDict.insert (doc->documentNumber(), (Kate::Document *)doc); + m_docInfos.insert (doc, new KateDocumentInfo ()); + + if (m_docList.count() < 2) + ((Kate::Document *)doc)->readConfig(KateApp::self()->config()); + + emit documentCreated ((Kate::Document *)doc); + emit m_documentManager->documentCreated ((Kate::Document *)doc); + + connect(doc,TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)),this,TQT_SLOT(slotModifiedOnDisc(Kate::Document *, bool, unsigned char))); + return (Kate::Document *)doc; +} + +void KateDocManager::deleteDoc (Kate::Document *doc) +{ + uint id = doc->documentNumber(); + uint activeId = 0; + if (m_currentDoc) + activeId = m_currentDoc->documentNumber (); + + if (m_docList.count() < 2) + doc->writeConfig(KateApp::self()->config()); + + m_docInfos.remove (doc); + m_docDict.remove (id); + m_docList.remove (doc); + + emit documentDeleted (id); + emit m_documentManager->documentDeleted (id); + + // ohh, current doc was deleted + if (activeId == id) + { + // special case of documentChanged, no longer any doc here ! + m_currentDoc = 0; + + emit documentChanged (); + emit m_documentManager->documentChanged (); + } +} + +Kate::Document *KateDocManager::document (uint n) +{ + return m_docList.at(n); +} + +Kate::Document *KateDocManager::activeDocument () +{ + return m_currentDoc; +} + +void KateDocManager::setActiveDocument (Kate::Document *doc) +{ + if (!doc) + return; + + if (m_currentDoc && (m_currentDoc->documentNumber() == doc->documentNumber())) + return; + + m_currentDoc = doc; + + emit documentChanged (); + emit m_documentManager->documentChanged (); +} + +Kate::Document *KateDocManager::firstDocument () +{ + return m_docList.first(); +} + +Kate::Document *KateDocManager::nextDocument () +{ + return m_docList.next(); +} + +Kate::Document *KateDocManager::documentWithID (uint id) +{ + return m_docDict[id]; +} + +const KateDocumentInfo *KateDocManager::documentInfo (Kate::Document *doc) +{ + return m_docInfos[doc]; +} + +int KateDocManager::findDocument (Kate::Document *doc) +{ + return m_docList.find (doc); +} + +uint KateDocManager::documents () +{ + return m_docList.count (); +} + +int KateDocManager::findDocument ( KURL url ) +{ + TQPtrListIterator<Kate::Document> it(m_docList); + + for (; it.current(); ++it) + { + if ( it.current()->url() == url) + return it.current()->documentNumber(); + } + return -1; +} + +Kate::Document *KateDocManager::findDocumentByUrl( KURL url ) +{ + for (TQPtrListIterator<Kate::Document> it(m_docList); it.current(); ++it) + { + if ( it.current()->url() == url) + return it.current(); + } + + return 0L; +} + +bool KateDocManager::isOpen(KURL url) +{ + // return just if we found some document with this url + return findDocumentByUrl (url) != 0; +} + +Kate::Document *KateDocManager::openURL (const KURL& url,const TQString &encoding, uint *id, bool isTempFile) +{ + // special handling if still only the first initial doc is there + if (!documentList().isEmpty() && (documentList().count() == 1) && (!documentList().at(0)->isModified() && documentList().at(0)->url().isEmpty())) + { + Kate::Document* doc = documentList().getFirst(); + + doc->setEncoding(encoding); + + if (!loadMetaInfos(doc, url)) + doc->openURL (url); + + if (id) + *id=doc->documentNumber(); + + if ( isTempFile && !url.isEmpty() && url.isLocalFile() ) + { + TQFileInfo fi( url.path() ); + if ( fi.exists() ) + { + m_tempFiles[ doc->documentNumber() ] = qMakePair(url, fi.lastModified()); + kdDebug(13001)<<"temporary file will be deleted after use unless modified: "<<url.prettyURL()<<endl; + } + } + + connect(doc, TQT_SIGNAL(modStateChanged(Kate::Document *)), this, TQT_SLOT(slotModChanged(Kate::Document *))); + + emit initialDocumentReplaced(); + + return doc; + } + + Kate::Document *doc = findDocumentByUrl (url); + if ( !doc ) + { + doc = (Kate::Document *)createDoc (); + + doc->setEncoding(encoding.isNull() ? Kate::Document::defaultEncoding() : encoding); + + if (!loadMetaInfos(doc, url)) + doc->openURL (url); + } + + if (id) + *id=doc->documentNumber(); + + if ( isTempFile && !url.isEmpty() && url.isLocalFile() ) + { + TQFileInfo fi( url.path() ); + if ( fi.exists() ) + { + m_tempFiles[ doc->documentNumber() ] = qMakePair(url, fi.lastModified()); + kdDebug(13001)<<"temporary file will be deleted after use unless modified: "<<url.prettyURL()<<endl; + } + } + + return doc; +} + +bool KateDocManager::closeDocument(class Kate::Document *doc,bool closeURL) +{ + if (!doc) return false; + + saveMetaInfos(doc); + if (closeURL) + if (!doc->closeURL()) return false; + + TQPtrList<Kate::View> closeList; + uint documentNumber = doc->documentNumber(); + + for (uint i=0; i < KateApp::self()->mainWindows (); i++ ) + { + KateApp::self()->mainWindow(i)->viewManager()->closeViews(documentNumber); + } + + if ( closeURL && m_tempFiles.contains( documentNumber ) ) + { + TQFileInfo fi( m_tempFiles[ documentNumber ].first.path() ); + if ( fi.lastModified() <= m_tempFiles[ documentNumber ].second /*|| + KMessageBox::questionYesNo( KateApp::self()->activeMainWindow(), + i18n("The supposedly temporary file %1 has been modified. " + "Do you want to delete it anyway?").arg(m_tempFiles[ documentNumber ].first.prettyURL()), + i18n("Delete File?") ) == KMessageBox::Yes*/ ) + { + TDEIO::del( m_tempFiles[ documentNumber ].first, false, false ); + kdDebug(13001)<<"Deleted temporary file "<<m_tempFiles[ documentNumber ].first<<endl; + m_tempFiles.remove( documentNumber ); + } + else + kdWarning(13001)<<"The supposedly temporary file "<<m_tempFiles[ documentNumber ].first.prettyURL()<<" have been modified since loaded, and has not been deleted."<<endl; + } + + deleteDoc (doc); + + // never ever empty the whole document list + if (m_docList.isEmpty()) + createDoc (); + + return true; +} + +bool KateDocManager::closeDocument(uint n) +{ + return closeDocument(document(n)); +} + +bool KateDocManager::closeDocumentWithID(uint id) +{ + return closeDocument(documentWithID(id)); +} + +bool KateDocManager::closeAllDocuments(bool closeURL) +{ + bool res = true; + + TQPtrList<Kate::Document> docs = m_docList; + + for (uint i=0; i < KateApp::self()->mainWindows (); i++ ) + { + KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(true); + } + + while (!docs.isEmpty() && res) + if (! closeDocument(docs.at(0),closeURL) ) + res = false; + else + docs.remove ((uint)0); + + for (uint i=0; i < KateApp::self()->mainWindows (); i++ ) + { + KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(false); + + for (uint s=0; s < KateApp::self()->mainWindow(i)->viewManager()->containers()->count(); s++) + KateApp::self()->mainWindow(i)->viewManager()->containers()->at(s)->activateView (m_docList.at(0)->documentNumber()); + } + + return res; +} + +TQPtrList<Kate::Document> KateDocManager::modifiedDocumentList() { + TQPtrList<Kate::Document> modified; + for (TQPtrListIterator<Kate::Document> it(m_docList); it.current(); ++it) { + Kate::Document *doc = it.current(); + if (doc->isModified()) { + modified.append(doc); + } + } + return modified; +} + + +bool KateDocManager::queryCloseDocuments(KateMainWindow *w) +{ + uint docCount = m_docList.count(); + for (TQPtrListIterator<Kate::Document> it(m_docList); it.current(); ++it) + { + Kate::Document *doc = it.current(); + + if (doc->url().isEmpty() && doc->isModified()) + { + int msgres=KMessageBox::warningYesNoCancel( w, + i18n("<p>The document '%1' has been modified, but not saved." + "<p>Do you want to save your changes or discard them?").arg( doc->docName() ), + i18n("Close Document"), KStdGuiItem::save(), KStdGuiItem::discard() ); + + if (msgres==KMessageBox::Cancel) + return false; + + if (msgres==KMessageBox::Yes) + { + KEncodingFileDialog::Result r=KEncodingFileDialog::getSaveURLAndEncoding( + KTextEditor::encodingInterface(doc)->encoding(),TQString::null,TQString::null,w,i18n("Save As")); + + doc->setEncoding( r.encoding ); + + if (!r.URLs.isEmpty()) + { + KURL tmp = r.URLs.first(); + + if ( !doc->saveAs( tmp ) ) + return false; + } + else + return false; + } + } + else + { + if (!doc->queryClose()) + return false; + } + } + + // document count changed while queryClose, abort and notify user + if (m_docList.count() > docCount) + { + KMessageBox::information (w, + i18n ("New file opened while trying to close Kate, closing aborted."), + i18n ("Closing Aborted")); + return false; + } + + return true; +} + + +void KateDocManager::saveAll() +{ + for (TQPtrListIterator<Kate::Document> it(m_docList); it.current(); ++it) + if ( it.current()->isModified() && it.current()->views().count() ) + ((Kate::View*)it.current()->views().first())->save(); +} + +void KateDocManager::saveDocumentList (TDEConfig* config) +{ + TQString prevGrp=config->group(); + config->setGroup ("Open Documents"); + TQString grp = config->group(); + + config->writeEntry ("Count", m_docList.count()); + + int i=0; + for ( Kate::Document *doc = m_docList.first(); doc; doc = m_docList.next() ) + { + long docListPos = doc->documentListPosition(); + config->setGroup(TQString("Document %1").arg((docListPos<0)?i:docListPos)); + doc->writeSessionConfig(config); + config->setGroup(grp); + + i++; + } + + config->setGroup(prevGrp); +} + +void KateDocManager::restoreDocumentList (TDEConfig* config) +{ + TQString prevGrp=config->group(); + config->setGroup ("Open Documents"); + TQString grp = config->group(); + + unsigned int count = config->readUnsignedNumEntry("Count", 0); + + if (count == 0) + { + config->setGroup(prevGrp); + return; + } + + TQProgressDialog *pd = new TQProgressDialog( + i18n("Reopening files from the last session..."), + TQString::null, + count, + 0, + "openprog"); + + KWin::setOnDesktop(pd->winId(), KWin::currentDesktop()); + pd->setCaption (KateApp::self()->makeStdCaption(i18n("Starting Up"))); + + bool first = true; + for (unsigned int i=0; i < count; i++) + { + config->setGroup(TQString("Document %1").arg(i)); + Kate::Document *doc = 0; + + if (first) + { + first = false; + doc = document (0); + } + else + doc = createDoc (); + + doc->readSessionConfig(config); + config->setGroup (grp); + + pd->setProgress(pd->progress()+1); + KateApp::self()->processEvents(); + } + + delete pd; + + config->setGroup(prevGrp); +} + +void KateDocManager::slotModifiedOnDisc (Kate::Document *doc, bool b, unsigned char reason) +{ + if (m_docInfos[doc]) + { + m_docInfos[doc]->modifiedOnDisc = b; + m_docInfos[doc]->modifiedOnDiscReason = reason; + } +} + +void KateDocManager::slotModChanged(Kate::Document *doc) +{ + saveMetaInfos(doc); +} + +/** + * Load file and file' meta-informations iif the MD5 didn't change since last time. + */ +bool KateDocManager::loadMetaInfos(Kate::Document *doc, const KURL &url) +{ + if (!m_saveMetaInfos) + return false; + + if (!m_metaInfos->hasGroup(url.prettyURL())) + return false; + + TQCString md5; + bool ok = true; + + if (computeUrlMD5(url, md5)) + { + m_metaInfos->setGroup(url.prettyURL()); + TQString old_md5 = m_metaInfos->readEntry("MD5"); + + if ((const char *)md5 == old_md5) + doc->readSessionConfig(m_metaInfos); + else + { + m_metaInfos->deleteGroup(url.prettyURL()); + ok = false; + } + + m_metaInfos->sync(); + } + + return ok && doc->url() == url; +} + +/** + * Save file' meta-informations iif doc is in 'unmodified' state + */ +void KateDocManager::saveMetaInfos(Kate::Document *doc) +{ + TQCString md5; + + if (!m_saveMetaInfos) + return; + + if (doc->isModified()) + { +// kdDebug (13020) << "DOC MODIFIED: no meta data saved" << endl; + return; + } + + if (computeUrlMD5(doc->url(), md5)) + { + m_metaInfos->setGroup(doc->url().prettyURL()); + doc->writeSessionConfig(m_metaInfos); + m_metaInfos->writeEntry("MD5", (const char *)md5); + m_metaInfos->writeEntry("Time", TQDateTime::currentDateTime()); + m_metaInfos->sync(); + } +} + +bool KateDocManager::computeUrlMD5(const KURL &url, TQCString &result) +{ + TQFile f(url.path()); + + if (f.open(IO_ReadOnly)) + { + KMD5 md5; + + if (!md5.update(TQT_TQIODEVICE_OBJECT(f))) + return false; + + md5.hexDigest(result); + f.close(); + } + else + return false; + + return true; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katedocmanager.h b/kate/app/katedocmanager.h new file mode 100644 index 000000000..1eaef7f99 --- /dev/null +++ b/kate/app/katedocmanager.h @@ -0,0 +1,157 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_DOCMANAGER_H__ +#define __KATE_DOCMANAGER_H__ + +#include "katemain.h" +#include "../interfaces/documentmanager.h" + +#include <kate/document.h> + +#include <tqdatetime.h> +#include <tqguardedptr.h> +#include <tqptrlist.h> +#include <tqobject.h> +#include <tqptrdict.h> +#include <tqintdict.h> +#include <tqmap.h> +#include <tqpair.h> + +namespace KParts { class Factory; } + +class TDEConfig; +class DCOPObject; + +class KateDocumentInfo +{ + public: + KateDocumentInfo () + : modifiedOnDisc (false), + modifiedOnDiscReason (0) + { + } + + bool modifiedOnDisc; + unsigned char modifiedOnDiscReason; +}; + +typedef QPair<KURL,TQDateTime> TPair; + +class KateDocManager : public TQObject +{ + Q_OBJECT + + public: + KateDocManager (TQObject *parent); + ~KateDocManager (); + + static KateDocManager *self (); + + Kate::DocumentManager *documentManager () { return m_documentManager; }; + + Kate::Document *createDoc (); + void deleteDoc (Kate::Document *doc); + + Kate::Document *document (uint n); + + Kate::Document *activeDocument (); + void setActiveDocument (Kate::Document *doc); + + Kate::Document *firstDocument (); + Kate::Document *nextDocument (); + + // search document with right documentNumber() + Kate::Document *documentWithID (uint id); + + const KateDocumentInfo *documentInfo (Kate::Document *doc); + + int findDocument (Kate::Document *doc); + /** Returns the documentNumber of the doc with url URL or -1 if no such doc is found */ + int findDocument (KURL url); + // Anders: The above is not currently stable ? + Kate::Document *findDocumentByUrl( KURL url ); + + bool isOpen(KURL url); + + uint documents (); + + TQPtrList<Kate::Document> &documentList () { return m_docList; }; + + Kate::Document *openURL(const KURL&,const TQString &encoding=TQString::null,uint *id =0,bool isTempFile=false); + + bool closeDocument(class Kate::Document *,bool closeURL=true); + bool closeDocument(uint); + bool closeDocumentWithID(uint); + bool closeAllDocuments(bool closeURL=true); + + TQPtrList<Kate::Document> modifiedDocumentList(); + bool queryCloseDocuments(KateMainWindow *w); + + void saveDocumentList (class TDEConfig *config); + void restoreDocumentList (class TDEConfig *config); + + DCOPObject *dcopObject () { return m_dcop; }; + + inline bool getSaveMetaInfos() { return m_saveMetaInfos; }; + inline void setSaveMetaInfos(bool b) { m_saveMetaInfos = b; }; + + inline int getDaysMetaInfos() { return m_daysMetaInfos; }; + inline void setDaysMetaInfos(int i) { m_daysMetaInfos = i; }; + + public slots: + /** + * saves all documents that has at least one view. + * documents with no views are ignored :P + */ + void saveAll(); + + signals: + void documentCreated (Kate::Document *doc); + void documentDeleted (uint documentNumber); + void documentChanged (); + void initialDocumentReplaced (); + + private slots: + void slotModifiedOnDisc (Kate::Document *doc, bool b, unsigned char reason); + void slotModChanged(Kate::Document *doc); + + private: + bool loadMetaInfos(Kate::Document *doc, const KURL &url); + void saveMetaInfos(Kate::Document *doc); + bool computeUrlMD5(const KURL &url, TQCString &result); + + Kate::DocumentManager *m_documentManager; + TQPtrList<Kate::Document> m_docList; + TQIntDict<Kate::Document> m_docDict; + TQPtrDict<KateDocumentInfo> m_docInfos; + TQMap<uint,TPair> m_tempFiles; + TQGuardedPtr<Kate::Document> m_currentDoc; + TDEConfig *m_metaInfos; + bool m_saveMetaInfos; + int m_daysMetaInfos; + + DCOPObject *m_dcop; + + KParts::Factory *m_factory; + +}; + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katedocmanageriface.cpp b/kate/app/katedocmanageriface.cpp new file mode 100644 index 000000000..034c5aa03 --- /dev/null +++ b/kate/app/katedocmanageriface.cpp @@ -0,0 +1,131 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser <geiseri@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katedocmanageriface.h" + +#include "katedocmanager.h" + +#include <kdebug.h> + +KateDocManagerDCOPIface::KateDocManagerDCOPIface (KateDocManager *dm) : DCOPObject ("KateDocumentManager"), m_dm (dm) +{ + +} + +// bit more error save than the forcing c cast ;() +DCOPRef KateDocManagerDCOPIface::document (uint n) +{ + Kate::Document *doc = m_dm->document(n); + + if (!doc) + return DCOPRef (); + + DCOPObject *obj = static_cast<DCOPObject*>(doc->tqt_cast("DCOPObject")); + + if (!obj) + return DCOPRef (); + + return DCOPRef (obj); +} + +DCOPRef KateDocManagerDCOPIface::activeDocument () +{ + Kate::Document *doc = m_dm->activeDocument(); + + if (!doc) + return DCOPRef (); + + DCOPObject *obj = static_cast<DCOPObject*>(doc->tqt_cast("DCOPObject")); + + if (!obj) + return DCOPRef (); + + return DCOPRef (obj); +} + +uint KateDocManagerDCOPIface::activeDocumentNumber () +{ + Kate::Document *doc = m_dm->activeDocument(); + + if (doc) + return doc->documentNumber (); + + return 0; +} + +DCOPRef KateDocManagerDCOPIface::documentWithID (uint id) +{ + Kate::Document *doc = m_dm->documentWithID (id); + + if (!doc) + return DCOPRef (); + + DCOPObject *obj = static_cast<DCOPObject*>(doc->tqt_cast("DCOPObject")); + + if (!obj) + return DCOPRef (); + + return DCOPRef (obj); +} + +DCOPRef KateDocManagerDCOPIface::openURL (KURL url, TQString encoding) +{ + Kate::Document *doc = m_dm->openURL (url, encoding); + + if (!doc) + return DCOPRef (); + + DCOPObject *obj = static_cast<DCOPObject*>(doc->tqt_cast("DCOPObject")); + + if (!obj) + return DCOPRef (); + + return DCOPRef (obj); +} + +bool KateDocManagerDCOPIface::closeDocument(uint n) +{ + return m_dm->closeDocument(n); +} + +bool KateDocManagerDCOPIface::closeDocumentWithID(uint id) +{ + return m_dm->closeDocumentWithID (id); +} + +bool KateDocManagerDCOPIface::closeAllDocuments() +{ + return m_dm->closeAllDocuments(); +} + +bool KateDocManagerDCOPIface::isOpen(KURL url) +{ + return m_dm->isOpen (url); +} + +uint KateDocManagerDCOPIface::documents () +{ + return m_dm->documents(); +} + +int KateDocManagerDCOPIface::findDocument (KURL url) +{ + return m_dm->findDocument (url); +} + + diff --git a/kate/app/katedocmanageriface.h b/kate/app/katedocmanageriface.h new file mode 100644 index 000000000..353818c03 --- /dev/null +++ b/kate/app/katedocmanageriface.h @@ -0,0 +1,62 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser <geiseri@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _katedocmanager_Iface_h_ +#define _katedocmanager_Iface_h_ + +#include <dcopobject.h> +#include <dcopref.h> + +#include <kurl.h> + +class KateDocManager; + +class KateDocManagerDCOPIface : public DCOPObject +{ + K_DCOP + + public: + KateDocManagerDCOPIface (KateDocManager *dm); + + k_dcop: + DCOPRef document (uint n); + + DCOPRef activeDocument (); + + uint activeDocumentNumber (); + + DCOPRef documentWithID (uint id); + + int findDocument (KURL url); + + bool isOpen (KURL url); + + uint documents (); + + DCOPRef openURL (KURL url, TQString encoding); + + bool closeDocument (uint n); + + bool closeDocumentWithID (uint id); + + bool closeAllDocuments (); + + private: + KateDocManager *m_dm; +}; +#endif diff --git a/kate/app/kateexternaltools.cpp b/kate/app/kateexternaltools.cpp new file mode 100644 index 000000000..e0057fb2c --- /dev/null +++ b/kate/app/kateexternaltools.cpp @@ -0,0 +1,873 @@ +/* + This file is part of the Kate text editor of the KDE project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2004, Anders Lund <anders@alweb.dk> +*/ +// TODO +// Icons +// Direct shortcut setting +//BEGIN Includes +#include "kateexternaltools.h" +#include "kateexternaltools.moc" +#include "katedocmanager.h" +#include "kateviewmanager.h" +#include "kateapp.h" + +#include "katemainwindow.h" + +#include <kate/view.h> +#include <kate/document.h> + +#include <tdelistbox.h> +#include <tdelocale.h> +#include <kiconloader.h> +#include <tdemessagebox.h> +#include <kmimetypechooser.h> +#include <tdeconfig.h> +#include <krun.h> +#include <kicondialog.h> +#include <tdepopupmenu.h> +#include <kdebug.h> + +#include <tqbitmap.h> +#include <tqcombobox.h> +#include <tqfile.h> +#include <tqpushbutton.h> +#include <tqlineedit.h> +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqlistbox.h> +#include <tqmap.h> +#include <tqregexp.h> +#include <tqtextedit.h> +#include <tqtoolbutton.h> +#include <tqwhatsthis.h> + +#include <stdlib.h> +#include <unistd.h> +//END Includes + +KateExternalToolsCommand *KateExternalToolsCommand::s_self=0; + +//BEGIN KateExternalTool +KateExternalTool::KateExternalTool( const TQString &name, + const TQString &command, + const TQString &icon, + const TQString &tryexec, + const TQStringList &mimetypes, + const TQString &acname, + const TQString &cmdname, + int save ) + : name ( name ), + command ( command ), + icon ( icon ), + tryexec ( tryexec ), + mimetypes ( mimetypes ), + acname ( acname ), + cmdname ( cmdname ), + save ( save ) +{ + //if ( ! tryexec.isEmpty() ) + hasexec = checkExec(); +} + +bool KateExternalTool::checkExec() +{ + // if tryexec is empty, it is the first word of command + if ( tryexec.isEmpty() ) + tryexec = command.section( " ", 0, 0, TQString::SectionSkipEmpty ); + + // NOTE this code is modified taken from kdesktopfile.cpp, from KDesktopFile::tryExec() + if (!tryexec.isEmpty()) { + if (tryexec[0] == '/') { + if (::access(TQFile::encodeName(tryexec), R_OK | X_OK)) + return false; + + m_exec = tryexec; + } else { + // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!! + // Environment PATH may contain filenames in 8bit locale cpecified + // encoding (Like a filenames). + TQStringList dirs = TQStringList::split(':', TQFile::decodeName(::getenv("PATH"))); + TQStringList::Iterator it(dirs.begin()); + bool match = false; + for (; it != dirs.end(); ++it) + { + TQString fName = *it + "/" + tryexec; + if (::access(TQFile::encodeName(fName), R_OK | X_OK) == 0) + { + match = true; + m_exec = fName; + break; + } + } + // didn't match at all + if (!match) + return false; + } + return true; + } + return false; +} + +bool KateExternalTool::valid( const TQString &mt ) const +{ + return mimetypes.isEmpty() || mimetypes.contains( mt ); +} +//END KateExternalTool + +//BEGIN KateExternalToolsCommand +KateExternalToolsCommand::KateExternalToolsCommand() : Kate::Command() { + m_inited=false; + reload(); +} + +TQStringList KateExternalToolsCommand::cmds () { + return m_list; +} + +KateExternalToolsCommand *KateExternalToolsCommand::self () { + if (s_self) return s_self; + s_self=new KateExternalToolsCommand; + return s_self; +} + +void KateExternalToolsCommand::reload () { + m_list.clear(); + m_map.clear(); + + TDEConfig config("externaltools", false, false, "appdata"); + config.setGroup("Global"); + TQStringList tools = config.readListEntry("tools"); + + + for( TQStringList::Iterator it = tools.begin(); it != tools.end(); ++it ) + { + if ( *it == "---" ) + continue; + + + config.setGroup( *it ); + + KateExternalTool t = KateExternalTool( + config.readEntry( "name", "" ), + config.readEntry( "command", ""), + config.readEntry( "icon", ""), + config.readEntry( "executable", ""), + config.readListEntry( "mimetypes" ), + config.readEntry( "acname", "" ), + config.readEntry( "cmdname", "" ) ); + // FIXME test for a command name first! + if ( t.hasexec && (!t.cmdname.isEmpty())) { + m_list.append("exttool-"+t.cmdname); + m_map.insert("exttool-"+t.cmdname,t.acname); + } + } + if (m_inited) { + Kate::Document::unregisterCommand(this); + Kate::Document::registerCommand(this); + } + else m_inited=true; +} + +bool KateExternalToolsCommand::exec (Kate::View *view, const TQString &cmd, TQString &) { + TQWidget *wv=tqt_dynamic_cast<TQWidget*>(view); + if (!wv) { +// kdDebug(13001)<<"KateExternalToolsCommand::exec: Could not get view widget"<<endl; + return false; + } + KateMDI::MainWindow *dmw=tqt_dynamic_cast<KateMDI::MainWindow*>(wv->topLevelWidget()); + if (!dmw) { +// kdDebug(13001)<<"KateExternalToolsCommand::exec: Could not get main window"<<endl; + return false; + } +// kdDebug(13001)<<"cmd="<<cmd.stripWhiteSpace()<<endl; + TQString actionName=m_map[cmd.stripWhiteSpace()]; + if (actionName.isEmpty()) return false; +// kdDebug(13001)<<"actionName is not empty:"<<actionName<<endl; + KateExternalToolsMenuAction *a= + tqt_dynamic_cast<KateExternalToolsMenuAction*>(dmw->action("tools_external")); + if (!a) return false; +// kdDebug(13001)<<"trying to find action"<<endl; + TDEAction *a1=a->actionCollection()->action(static_cast<const char *>(actionName.utf8())); + if (!a1) return false; +// kdDebug(13001)<<"activating action"<<endl; + a1->activate(); + return true; +} + +bool KateExternalToolsCommand::help (Kate::View *, const TQString &, TQString &) { + return false; +} +//END KateExternalToolsCommand + +//BEGIN KateExternalToolAction +KateExternalToolAction::KateExternalToolAction( TQObject *parent, + const char *name, KateExternalTool *t) + : TDEAction( parent, name ), + tool ( t ) +{ + setText( t->name ); + if ( ! t->icon.isEmpty() ) + setIconSet( SmallIconSet( t->icon ) ); + + connect( this ,TQT_SIGNAL(activated()), this, TQT_SLOT(slotRun()) ); +} + +bool KateExternalToolAction::expandMacro( const TQString &str, TQStringList &ret ) +{ + KateMainWindow *mw = (KateMainWindow*)parent()->parent(); + + Kate::View *view = mw->viewManager()->activeView(); + if ( ! view ) return false; + + + if ( str == "URL" ) + ret += mw->activeDocumentUrl().url(); + else if ( str == "directory" ) // directory of current doc + ret += mw->activeDocumentUrl().directory(); + else if ( str == "filename" ) + ret += mw->activeDocumentUrl().fileName(); + else if ( str == "line" ) // cursor line of current doc + ret += TQString::number( view->cursorLine() ); + else if ( str == "col" ) // cursor col of current doc + ret += TQString::number( view->cursorColumn() ); + else if ( str == "selection" ) // selection of current doc if any + ret += view->getDoc()->selection(); + else if ( str == "text" ) // text of current doc + ret += view->getDoc()->text(); + else if ( str == "URLs" ) { + for( Kate::Document *doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() ) + if ( ! doc->url().isEmpty() ) + ret += doc->url().url(); + } else + return false; + return true; +} + +KateExternalToolAction::~KateExternalToolAction() { + delete(tool); +} + +void KateExternalToolAction::slotRun() +{ + // expand the macros in command if any, + // and construct a command with an absolute path + TQString cmd = tool->command; + + if ( ! expandMacrosShellQuote( cmd ) ) + { + KMessageBox::sorry( (KateMainWindow*)parent()->parent(), + i18n("Failed to expand the command '%1'.").arg( cmd ), + i18n( "Kate External Tools") ); + return; + } + kdDebug(13001)<<"externaltools: Running command: "<<cmd<<endl; + + // save documents if requested + KateMainWindow *mw = (KateMainWindow*)parent()->parent(); + if ( tool->save == 1 ) + mw->viewManager()->activeView()->document()->save(); + else if ( tool->save == 2 ) + mw->actionCollection()->action("file_save_all")->activate(); + + KRun::runCommand( cmd, tool->tryexec, tool->icon ); +} +//END KateExternalToolAction + +//BEGIN KateExternalToolsMenuAction +KateExternalToolsMenuAction::KateExternalToolsMenuAction( const TQString &text, + TQObject *parent, + const char* name, + KateMainWindow *mw ) + : TDEActionMenu( text, parent, name ), + mainwindow( mw ) +{ + + m_actionCollection = new TDEActionCollection( mainwindow ); + + connect(KateDocManager::self(),TQT_SIGNAL(documentChanged()),this,TQT_SLOT(slotDocumentChanged())); + + reload(); +} + +void KateExternalToolsMenuAction::reload() +{ + m_actionCollection->clear (); + popupMenu()->clear(); + + // load all the tools, and create a action for each of them + TDEConfig *config = new TDEConfig( "externaltools", false, false, "appdata" ); + config->setGroup( "Global" ); + TQStringList tools = config->readListEntry( "tools" ); + + // if there are tools that are present but not explicitly removed, + // add them to the end of the list + config->setReadDefaults( true ); + TQStringList dtools = config->readListEntry( "tools" ); + int gver = config->readNumEntry( "version", 1 ); + config->setReadDefaults( false ); + + int ver = config->readNumEntry( "version" ); + if ( ver <= gver ) + { + TQStringList removed = config->readListEntry( "removed" ); + bool sepadded = false; + for (TQStringList::iterator itg = dtools.begin(); itg != dtools.end(); ++itg ) + { + if ( ! tools.contains( *itg ) && + ! removed.contains( *itg ) ) + { + if ( ! sepadded ) + { + tools << "---"; + sepadded = true; + } + tools << *itg; + } + } + + config->writeEntry( "tools", tools ); + config->sync(); + config->writeEntry( "version", gver ); + } + + for( TQStringList::Iterator it = tools.begin(); it != tools.end(); ++it ) + { + if ( *it == "---" ) + { + popupMenu()->insertSeparator(); + // a separator + continue; + } + + config->setGroup( *it ); + + KateExternalTool *t = new KateExternalTool( + config->readEntry( "name", "" ), + config->readEntry( "command", ""), + config->readEntry( "icon", ""), + config->readEntry( "executable", ""), + config->readListEntry( "mimetypes" ), + config->readEntry( "acname", "" ), + config->readEntry( "cmdname", "" ), + config->readNumEntry( "save", 0 ) ); + + if ( t->hasexec ) + insert( new KateExternalToolAction( m_actionCollection, t->acname.ascii(), t ) ); + } + + m_actionCollection->readShortcutSettings( "Shortcuts", config ); + slotDocumentChanged(); + delete config; +} + +void KateExternalToolsMenuAction::slotDocumentChanged() +{ + // try to enable/disable to match current mime type + Kate::DocumentExt *de = documentExt( KateDocManager::self()->activeDocument() ); + if ( de ) + { + TQString mt = de->mimeType(); + TQStringList l; + bool b; + + TDEActionPtrList actions = m_actionCollection->actions(); + for (TDEActionPtrList::iterator it = actions.begin(); it != actions.end(); ++it ) + { + KateExternalToolAction *action = tqt_dynamic_cast<KateExternalToolAction*>(*it); + if ( action ) + { + l = action->tool->mimetypes; + b = ( ! l.count() || l.contains( mt ) ); + action->setEnabled( b ); + } + } + } +} +//END KateExternalToolsMenuAction + +//BEGIN ToolItem +/** + * This is a TQListBoxItem, that has a KateExternalTool. The text is the Name + * of the tool. + */ +class ToolItem : public TQListBoxPixmap +{ + public: + ToolItem( TQListBox *lb, const TQPixmap &icon, KateExternalTool *tool ) + : TQListBoxPixmap( lb, icon, tool->name ), + tool ( tool ) + {;} + + ~ToolItem() {}; + + KateExternalTool *tool; +}; +//END ToolItem + +//BEGIN KateExternalToolServiceEditor +KateExternalToolServiceEditor::KateExternalToolServiceEditor( KateExternalTool *tool, + TQWidget *parent, const char *name ) + : KDialogBase( parent, name, true, i18n("Edit External Tool"), KDialogBase::Ok|KDialogBase::Cancel ), + tool( tool ) +{ + // create a entry for each property + // fill in the values from the service if available + TQWidget *w = new TQWidget( this ); + setMainWidget( w ); + TQGridLayout *lo = new TQGridLayout( w ); + lo->setSpacing( KDialogBase::spacingHint() ); + + TQLabel *l; + + leName = new TQLineEdit( w ); + lo->addWidget( leName, 1, 2 ); + l = new TQLabel( leName, i18n("&Label:"), w ); + l->setAlignment( l->alignment()|Qt::AlignRight ); + lo->addWidget( l, 1, 1 ); + if ( tool ) leName->setText( tool->name ); + TQWhatsThis::add( leName, i18n( + "The name will be displayed in the 'Tools->External' menu") ); + + btnIcon = new TDEIconButton( w ); + btnIcon->setIconSize( TDEIcon::SizeSmall ); + lo->addWidget( btnIcon, 1, 3 ); + if ( tool && !tool->icon.isEmpty() ) + btnIcon->setIcon( tool->icon ); + + teCommand = new TQTextEdit( w ); + lo->addMultiCellWidget( teCommand, 2, 2, 2, 3 ); + l = new TQLabel( teCommand, i18n("S&cript:"), w ); + l->setAlignment( Qt::AlignTop|Qt::AlignRight ); + lo->addWidget( l, 2, 1 ); + if ( tool ) teCommand->setText( tool->command ); + TQWhatsThis::add( teCommand, i18n( + "<p>The script to execute to invoke the tool. The script is passed " + "to /bin/sh for execution. The following macros " + "will be expanded:</p>" + "<ul><li><code>%URL</code> - the URL of the current document." + "<li><code>%URLs</code> - a list of the URLs of all open documents." + "<li><code>%directory</code> - the URL of the directory containing " + "the current document." + "<li><code>%filename</code> - the filename of the current document." + "<li><code>%line</code> - the current line of the text cursor in the " + "current view." + "<li><code>%column</code> - the column of the text cursor in the " + "current view." + "<li><code>%selection</code> - the selected text in the current view." + "<li><code>%text</code> - the text of the current document.</ul>" ) ); + + + leExecutable = new TQLineEdit( w ); + lo->addMultiCellWidget( leExecutable, 3, 3, 2, 3 ); + l = new TQLabel( leExecutable, i18n("&Executable:"), w ); + l->setAlignment( l->alignment()|Qt::AlignRight ); + lo->addWidget( l, 3, 1 ); + if ( tool ) leExecutable->setText( tool->tryexec ); + TQWhatsThis::add( leExecutable, i18n( + "The executable used by the command. This is used to check if a tool " + "should be displayed; if not set, the first word of <em>command</em> " + "will be used.") ); + + leMimetypes = new TQLineEdit( w ); + lo->addWidget( leMimetypes, 4, 2 ); + l = new TQLabel( leMimetypes, i18n("&Mime types:"), w ); + l->setAlignment( l->alignment()|Qt::AlignRight ); + lo->addWidget( l, 4, 1 ); + if ( tool ) leMimetypes->setText( tool->mimetypes.join("; ") ); + TQWhatsThis::add( leMimetypes, i18n( + "A semicolon-separated list of mime types for which this tool should " + "be available; if this is left empty, the tool is always available. " + "To choose from known mimetypes, press the button on the right.") ); + + TQToolButton *btnMTW = new TQToolButton(w); + lo->addWidget( btnMTW, 4, 3 ); + btnMTW->setIconSet(TQIconSet(SmallIcon("wizard"))); + connect(btnMTW, TQT_SIGNAL(clicked()), this, TQT_SLOT(showMTDlg())); + TQWhatsThis::add( btnMTW, i18n( + "Click for a dialog that can help you creating a list of mimetypes.") ); + + cmbSave = new TQComboBox(w); + lo->addMultiCellWidget( cmbSave, 5, 5, 2, 3 ); + l = new TQLabel( cmbSave, i18n("&Save:"), w ); + l->setAlignment( l->alignment()|Qt::AlignRight ); + lo->addWidget( l, 5, 1 ); + TQStringList sl; + sl << i18n("None") << i18n("Current Document") << i18n("All Documents"); + cmbSave->insertStringList( sl ); + if ( tool ) cmbSave->setCurrentItem( tool->save ); + TQWhatsThis::add( cmbSave, i18n( + "You can elect to save the current or all [modified] documents prior to " + "running the command. This is helpful if you want to pass URLs to " + "an application like, for example, an FTP client.") ); + + + leCmdLine = new TQLineEdit( w ); + lo->addMultiCellWidget( leCmdLine, 6, 6, 2, 3 ); + l = new TQLabel( leCmdLine, i18n("&Command line name:"), w ); + l->setAlignment( l->alignment()|Qt::AlignRight ); + lo->addWidget( l, 6, 1 ); + if ( tool ) leCmdLine->setText( tool->cmdname ); + TQWhatsThis::add( leCmdLine, i18n( + "If you specify a name here, you can invoke the command from the view " + "command lines with exttool-the_name_you_specified_here. " + "Please do not use spaces or tabs in the name.")); + +} + +void KateExternalToolServiceEditor::slotOk() +{ + if ( leName->text().isEmpty() || + teCommand->text().isEmpty() ) + { + KMessageBox::information( this, i18n("You must specify at least a name and a command") ); + return; + } + + KDialogBase::slotOk(); +} + +void KateExternalToolServiceEditor::showMTDlg() +{ + TQString text = i18n("Select the MimeTypes for which to enable this tool."); + TQStringList list = TQStringList::split( TQRegExp("\\s*;\\s*"), leMimetypes->text() ); + KMimeTypeChooserDialog d( i18n("Select Mime Types"), text, list, "text", this ); + if ( d.exec() == KDialogBase::Accepted ) { + leMimetypes->setText( d.chooser()->mimeTypes().join(";") ); + } +} +//END KateExternalToolServiceEditor + +//BEGIN KateExternalToolsConfigWidget +KateExternalToolsConfigWidget::KateExternalToolsConfigWidget( TQWidget *parent, const char* name ) + : Kate::ConfigPage( parent, name ), + m_changed( false ) +{ + TQGridLayout *lo = new TQGridLayout( this, 5, 5, 0, KDialog::spacingHint() ); + + lbTools = new TDEListBox( this ); + lo->addMultiCellWidget( lbTools, 1, 4, 0, 3 ); + connect( lbTools, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged()) ); + + btnNew = new TQPushButton( i18n("&New..."), this ); + lo->addWidget( btnNew, 5, 0 ); + connect( btnNew, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNew()) ); + + btnRemove = new TQPushButton( i18n("&Remove"), this ); + lo->addWidget( btnRemove, 5, 2 ); + connect( btnRemove, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotRemove()) ); + + btnEdit = new TQPushButton( i18n("&Edit..."), this ); + lo->addWidget( btnEdit, 5, 1 ); + connect( btnEdit, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotEdit()) ); + + TQPushButton *b = new TQPushButton( i18n("Insert &Separator"), this ); + lo->addWidget( b, 5, 3 ); + connect( b, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotInsertSeparator()) ); + + btnMoveUp = new TQPushButton( SmallIconSet("up"), "", this ); + lo->addWidget( btnMoveUp, 2, 4 ); + connect( btnMoveUp, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotMoveUp()) ); + + btnMoveDwn = new TQPushButton( SmallIconSet("down"), "", this ); + lo->addWidget( btnMoveDwn, 3, 4 ); + connect( btnMoveDwn, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotMoveDown()) ); + + connect( lbTools, TQT_SIGNAL( doubleClicked ( TQListBoxItem * ) ), this, TQT_SLOT( slotEdit() ) ); + + lo->setRowStretch( 1, 1 ); + lo->setRowStretch( 4, 1 ); + lo->setColStretch( 0, 1 ); + lo->setColStretch( 1, 1 ); + lo->setColStretch( 2, 1 ); + + + TQWhatsThis::add( lbTools, i18n( + "This list shows all the configured tools, represented by their menu text.") ); + + config = new TDEConfig("externaltools", false, false, "appdata"); + reload(); + slotSelectionChanged(); +} + +KateExternalToolsConfigWidget::~KateExternalToolsConfigWidget() +{ + delete config; +} + +void KateExternalToolsConfigWidget::reload() +{ + //m_tools.clear(); + lbTools->clear(); + + // load the files from a TDEConfig + config->setGroup( "Global" ); + TQStringList tools = config->readListEntry("tools"); + + for( TQStringList::Iterator it = tools.begin(); it != tools.end(); ++it ) + { + if ( *it == "---" ) + { + new TQListBoxText( lbTools, "---" ); + } + else + { + config->setGroup( *it ); + + KateExternalTool *t = new KateExternalTool( + config->readEntry( "name", "" ), + config->readEntry( "command", ""), + config->readEntry( "icon", ""), + config->readEntry( "executable", ""), + config->readListEntry( "mimetypes" ), + config->readEntry( "acname" ), + config->readEntry( "cmdname"), + config->readNumEntry( "save", 0 ) ); + + if ( t->hasexec ) // we only show tools that are also in the menu. + new ToolItem( lbTools, t->icon.isEmpty() ? blankIcon() : SmallIcon( t->icon ), t ); + } + } + m_changed = false; +} + +TQPixmap KateExternalToolsConfigWidget::blankIcon() +{ + TQPixmap pm( TDEIcon::SizeSmall, TDEIcon::SizeSmall ); + pm.fill(); + pm.setMask( pm.createHeuristicMask() ); + return pm; +} + +void KateExternalToolsConfigWidget::apply() +{ + if ( ! m_changed ) + return; + m_changed = false; + + // save a new list + // save each item + TQStringList tools; + for ( uint i = 0; i < lbTools->count(); i++ ) + { + if ( lbTools->text( i ) == "---" ) + { + tools << "---"; + continue; + } + KateExternalTool *t = ((ToolItem*)lbTools->item( i ))->tool; +// kdDebug(13001)<<"adding tool: "<<t->name<<endl; + tools << t->acname; + + config->setGroup( t->acname ); + config->writeEntry( "name", t->name ); + config->writeEntry( "command", t->command ); + config->writeEntry( "icon", t->icon ); + config->writeEntry( "executable", t->tryexec ); + config->writeEntry( "mimetypes", t->mimetypes ); + config->writeEntry( "acname", t->acname ); + config->writeEntry( "cmdname", t->cmdname ); + config->writeEntry( "save", t->save ); + } + + config->setGroup("Global"); + config->writeEntry( "tools", tools ); + + // if any tools was removed, try to delete their groups, and + // add the group names to the list of removed items. + if ( m_removed.count() ) + { + for ( TQStringList::iterator it = m_removed.begin(); it != m_removed.end(); ++it ) + { + if ( config->hasGroup( *it ) ) + config->deleteGroup( *it ); + } + TQStringList removed = config->readListEntry( "removed" ); + removed += m_removed; + + // clean up the list of removed items, so that it does not contain + // non-existing groups (we can't remove groups from a non-owned global file). + config->sync(); + TQStringList::iterator it1 = removed.begin(); + while( it1 != removed.end() ) + { + if ( ! config->hasGroup( *it1 ) ) + it1 = removed.remove( it1 ); + else + ++it1; + } + config->writeEntry( "removed", removed ); + } + + config->sync(); +} + +void KateExternalToolsConfigWidget::slotSelectionChanged() +{ + // update button state + bool hs = lbTools->selectedItem() != 0; + btnEdit->setEnabled( hs && dynamic_cast<ToolItem*>(lbTools->selectedItem()) ); + btnRemove->setEnabled( hs ); + btnMoveUp->setEnabled( ( lbTools->currentItem() > 0 ) && hs ); + btnMoveDwn->setEnabled( ( lbTools->currentItem() < (int)lbTools->count()-1 )&&hs ); +} + +void KateExternalToolsConfigWidget::slotNew() +{ + // display a editor, and if it is OK'd, create a new tool and + // create a listbox item for it + KateExternalToolServiceEditor editor( 0, this ); + + if ( editor.exec() ) + { + KateExternalTool *t = new KateExternalTool( + editor.leName->text(), + editor.teCommand->text(), + editor.btnIcon->icon(), + editor.leExecutable->text(), + TQStringList::split( TQRegExp("\\s*;\\s*"), editor.leMimetypes->text() ) ); + + // This is sticky, it does not change again, so that shortcuts sticks + // TODO check for dups + t->acname = "externaltool_" + TQString(t->name).replace( TQRegExp("\\W+"), "" ); + + new ToolItem ( lbTools, t->icon.isEmpty() ? blankIcon() : SmallIcon( t->icon ), t ); + + slotChanged(); + m_changed = true; + } +} + +void KateExternalToolsConfigWidget::slotRemove() +{ + // add the tool action name to a list of removed items, + // remove the current listbox item + if ( lbTools->currentItem() > -1 ) { + ToolItem *i = dynamic_cast<ToolItem*>(lbTools->selectedItem()); + if ( i ) + m_removed << i->tool->acname; + + lbTools->removeItem( lbTools->currentItem() ); + slotChanged(); + m_changed = true; + } +} + +void KateExternalToolsConfigWidget::slotEdit() +{ + if( !dynamic_cast<ToolItem*>(lbTools->selectedItem()) ) return; + // show the item in an editor + KateExternalTool *t = ((ToolItem*)lbTools->selectedItem())->tool; + KateExternalToolServiceEditor editor( t, this); + config->setGroup( "Editor" ); + editor.resize( config->readSizeEntry( "Size" ) ); + if ( editor.exec() /*== KDialogBase::Ok*/ ) + { + + bool elementChanged = ( ( editor.btnIcon->icon() != t->icon ) || (editor.leName->text() != t->name ) ) ; + + t->name = editor.leName->text(); + t->cmdname = editor.leCmdLine->text(); + t->command = editor.teCommand->text(); + t->icon = editor.btnIcon->icon(); + t->tryexec = editor.leExecutable->text(); + t->mimetypes = TQStringList::split( TQRegExp("\\s*;\\s*"), editor.leMimetypes->text() ); + t->save = editor.cmbSave->currentItem(); + + //if the icon has changed or name changed, I have to renew the listbox item :S + if ( elementChanged ) + { + int idx = lbTools->index( lbTools->selectedItem() ); + lbTools->removeItem( idx ); + lbTools->insertItem( new ToolItem( 0, t->icon.isEmpty() ? blankIcon() : SmallIcon( t->icon ), t ), idx ); + } + + slotChanged(); + m_changed = true; + } + + config->setGroup( "Editor" ); + config->writeEntry( "Size", editor.size() ); + config->sync(); +} + +void KateExternalToolsConfigWidget::slotInsertSeparator() +{ + lbTools->insertItem( "---", lbTools->currentItem()+1 ); + slotChanged(); + m_changed = true; +} + +void KateExternalToolsConfigWidget::slotMoveUp() +{ + // move the current item in the listbox upwards if possible + TQListBoxItem *item = lbTools->selectedItem(); + if ( ! item ) return; + + int idx = lbTools->index( item ); + + if ( idx < 1 ) return; + + if ( dynamic_cast<ToolItem*>(item) ) + { + KateExternalTool *tool = ((ToolItem*)item)->tool; + lbTools->removeItem( idx ); + lbTools->insertItem( new ToolItem( 0, tool->icon.isEmpty() ? blankIcon() : SmallIcon( tool->icon ), tool ), idx-1 ); + } + else // a separator! + { + lbTools->removeItem( idx ); + lbTools->insertItem( new TQListBoxText( 0, "---" ), idx-1 ); + } + + lbTools->setCurrentItem( idx - 1 ); + slotSelectionChanged(); + slotChanged(); + m_changed = true; +} + +void KateExternalToolsConfigWidget::slotMoveDown() +{ + // move the current item in the listbox downwards if possible + TQListBoxItem *item = lbTools->selectedItem(); + if ( ! item ) return; + + uint idx = lbTools->index( item ); + + if ( idx > lbTools->count()-1 ) return; + + if ( dynamic_cast<ToolItem*>(item) ) + { + KateExternalTool *tool = ((ToolItem*)item)->tool; + lbTools->removeItem( idx ); + lbTools->insertItem( new ToolItem( 0, tool->icon.isEmpty() ? blankIcon() : SmallIcon( tool->icon ), tool ), idx+1 ); + } + else // a separator! + { + lbTools->removeItem( idx ); + lbTools->insertItem( new TQListBoxText( 0, "---" ), idx+1 ); + } + + lbTools->setCurrentItem( idx+1 ); + slotSelectionChanged(); + slotChanged(); + m_changed = true; +} +//END KateExternalToolsConfigWidget +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateexternaltools.h b/kate/app/kateexternaltools.h new file mode 100644 index 000000000..ef3a9e9fd --- /dev/null +++ b/kate/app/kateexternaltools.h @@ -0,0 +1,229 @@ +/* + This file is part of the Kate text editor of the KDE project. + It describes a "external tools" action for kate and provides a dialog + page to configure that. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2004, Anders Lund <anders@alweb.dk> +*/ + +#ifndef _KATE_EXTERNAL_TOOLS_H_ +#define _KATE_EXTERNAL_TOOLS_H_ + +#include <tdeaction.h> +#include <kdialogbase.h> +#include <kate/document.h> +#include <kmacroexpander.h> +#include <tqpixmap.h> + +/** + * The external tools action + * This action creates a menu, in which each item will launch a process + * with the provided arguments, which may include the following macros: + * - %URLS: the URLs of all open documents. + * - %URL: The URL of the active document. + * - %filedir: The directory of the current document, if that is a local file. + * - %selection: The selection of the active document. + * - %text: The text of the active document. + * - %line: The line number of the cursor in the active view. + * - %column: The column of the cursor in the active view. + * + * Each item has the following properties: + * - Name: The friendly text for the menu + * - Exec: The command to execute, including arguments. + * - TryExec: the name of the executable, if not available, the + * item will not be displayed. + * - MimeTypes: An optional list of mimetypes. The item will be disabled or + * hidden if the current file is not of one of the indicated types. + * + */ +class KateExternalToolsMenuAction : public TDEActionMenu +{ + friend class KateExternalToolAction; + + Q_OBJECT + public: + KateExternalToolsMenuAction( const TQString &text=TQString::null, TQObject *parent=0, const char* name=0, class KateMainWindow *mw=0 ); + ~KateExternalToolsMenuAction() {}; + + /** + * This will load all the confiured services. + */ + void reload(); + + class TDEActionCollection *actionCollection() { return m_actionCollection; } + + private slots: + void slotDocumentChanged(); + + private: + class TDEActionCollection *m_actionCollection; + class KateMainWindow *mainwindow; // for the actions to access view/doc managers +}; + +/** + * This Action contains a KateExternalTool + */ +class KateExternalToolAction : public TDEAction, public KWordMacroExpander +{ + Q_OBJECT + public: + KateExternalToolAction( TQObject *parent, const char *name, class KateExternalTool *t ); + ~KateExternalToolAction(); + protected: + virtual bool expandMacro( const TQString &str, TQStringList &ret ); + + private slots: + void slotRun(); + + public: + class KateExternalTool *tool; +}; + +/** + * This class defines a single external tool. + */ +class KateExternalTool +{ + public: + KateExternalTool( const TQString &name=TQString::null, + const TQString &command=TQString::null, + const TQString &icon=TQString::null, + const TQString &tryexec=TQString::null, + const TQStringList &mimetypes=TQStringList(), + const TQString &acname=TQString::null, + const TQString &cmdname=TQString::null, + int save=0 ); + ~KateExternalTool() {}; + + TQString name; ///< The name used in the menu. + TQString command; ///< The command to execute. + TQString icon; ///< the icon to use in the menu. + TQString tryexec; ///< The name or path of the executable. + TQStringList mimetypes; ///< Optional list of mimetypes for which this action is valid. + bool hasexec; ///< This is set by the constructor by calling checkExec(), if a value is present. + TQString acname; ///< The name for the action. This is generated first time the action is is created. + TQString cmdname; ///< The name for the commandline. + int save; ///< We can save documents prior to activating the tool command: 0 = nothing, 1 = current document, 2 = all documents. + + /** + * @return true if mimetypes is empty, or the @p mimetype matches. + */ + bool valid( const TQString &mimetype ) const; + /** + * @return true if "tryexec" exists and has the executable bit set, or is + * empty. + * This is run at least once, and the tool is disabled if it fails. + */ + bool checkExec(); + + private: + TQString m_exec; ///< The fully qualified path of the executable. +}; + +/** + * The config widget. + * The config widget allows the user to view a list of services of the type + * "Kate/ExternalTool" and add, remove or edit them. + */ +class KateExternalToolsConfigWidget : public Kate::ConfigPage +{ + Q_OBJECT + public: + KateExternalToolsConfigWidget( TQWidget *parent, const char* name); + virtual ~KateExternalToolsConfigWidget(); + + virtual void apply(); + virtual void reload(); + virtual void reset() { reload(); } // sigh + virtual void defaults() { reload(); } // double sigh + + private slots: + void slotNew(); + void slotEdit(); + void slotRemove(); + void slotInsertSeparator(); + + void slotMoveUp(); + void slotMoveDown(); + + void slotSelectionChanged(); + + private: + TQPixmap blankIcon(); + + TQStringList m_removed; + + class TDEListBox *lbTools; + class TQPushButton *btnNew, *btnRemove, *btnEdit, *btnMoveUp, *btnMoveDwn; + + class TDEConfig *config; + + bool m_changed; +}; + +/** + * A Singleton class for invoking external tools with the view command line + */ + class KateExternalToolsCommand : public Kate::Command { + public: + KateExternalToolsCommand (); + virtual ~KateExternalToolsCommand () {}; + static KateExternalToolsCommand *self(); + void reload(); + public: + virtual TQStringList cmds (); + virtual bool exec (Kate::View *view, const TQString &cmd, TQString &msg); + virtual bool help (Kate::View *view, const TQString &cmd, TQString &msg); + private: + static KateExternalToolsCommand *s_self; + TQStringList m_list; + TQMap<TQString,TQString> m_map; + bool m_inited; + }; + +/** + * A Dialog to edit a single KateExternalTool object + */ +class KateExternalToolServiceEditor : public KDialogBase +{ + Q_OBJECT + + public: + + KateExternalToolServiceEditor( KateExternalTool *tool=0, + TQWidget *parent=0, const char *name=0 ); + + class TQLineEdit *leName, *leExecutable, *leMimetypes,*leCmdLine; + class TQTextEdit *teCommand; + class TDEIconButton *btnIcon; + class TQComboBox *cmbSave; + + private slots: + /** + * Run when the OK button is clicked, to ensure critical values are provided + */ + void slotOk(); + /** + * show a mimetype chooser dialog + */ + void showMTDlg(); + + private: + KateExternalTool *tool; +}; +#endif //_KATE_EXTERNAL_TOOLS_H_ diff --git a/kate/app/katefilelist.cpp b/kate/app/katefilelist.cpp new file mode 100644 index 000000000..98857b3c3 --- /dev/null +++ b/kate/app/katefilelist.cpp @@ -0,0 +1,749 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "katefilelist.h" +#include "katefilelist.moc" + +#include "katedocmanager.h" +#include "kateviewmanager.h" +#include "katemainwindow.h" + +#include <tqapplication.h> +#include <tqpainter.h> +#include <tqpopupmenu.h> +#include <tqheader.h> +#include <tqcolor.h> +#include <tqcheckbox.h> +#include <tqhbox.h> +#include <tqlayout.h> +#include <tqgroupbox.h> +#include <tqlabel.h> +#include <tqwhatsthis.h> + +#include <kiconloader.h> +#include <tdeconfig.h> +#include <tdelocale.h> +#include <tdeglobalsettings.h> +#include <kpassivepopup.h> +#include <kdebug.h> +#include <tdeapplication.h> +#include <kstringhandler.h> +#include <kcolorbutton.h> +#include <kdialog.h> +//END Includes + +//BEGIN ToolTip +class ToolTip : public TQToolTip +{ + public: + ToolTip( TQWidget *parent, KateFileList *lv ) + : TQToolTip( parent ), + m_listView( lv ) + { + } + virtual ~ToolTip() {}; + + void maybeTip( const TQPoint &pos ) + { + TQListViewItem *i = m_listView->itemAt( pos ); + if ( ! i ) return; + + KateFileListItem *item = ((KateFileListItem*)i); + if ( ! item ) return; + + tip( m_listView->itemRect( i ), m_listView->tooltip( item, 0 ) ); + + } + + private: + KateFileList *m_listView; +}; + +//END ToolTip + +//BEGIN KateFileList +KateFileList::KateFileList (KateMainWindow *main, + KateViewManager *_viewManager, + TQWidget * parent, const char * name ) + : TDEListView (parent, name) + , m_sort( KateFileList::sortByID ) +{ + m_main = main; + m_tooltip = new ToolTip( viewport(), this ); + + // default colors + m_viewShade = TQColor( 51, 204, 255 ); + m_editShade = TQColor( 255, 102, 153 ); + m_enableBgShading = false; + + setFocusPolicy ( TQ_NoFocus ); + + viewManager = _viewManager; + + header()->hide(); + addColumn("Document Name"); + + setSelectionMode( TQListView::Single ); + setSortType(KateFileList::sortByID); + setShowToolTips( false ); + + setupActions (); + + connect(this,TQT_SIGNAL(moved()),this,TQT_SLOT(updateFileListLocations())); + + for (uint i = 0; i < KateDocManager::self()->documents(); i++) + { + slotDocumentCreated (KateDocManager::self()->document(i)); + slotModChanged (KateDocManager::self()->document(i)); + } + + connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)), + this,TQT_SLOT(slotDocumentCreated(Kate::Document *))); + connect(KateDocManager::self(),TQT_SIGNAL(documentDeleted(uint)), + this,TQT_SLOT(slotDocumentDeleted(uint))); + + // don't Honour KDE single/double click setting, this files are already open, + // no need for hassle of considering double-click + connect(this,TQT_SIGNAL(selectionChanged(TQListViewItem *)), + this,TQT_SLOT(slotActivateView(TQListViewItem *))); + connect(viewManager,TQT_SIGNAL(viewChanged()), this,TQT_SLOT(slotViewChanged())); + connect(this,TQT_SIGNAL(contextMenuRequested( TQListViewItem *, const TQPoint &, int )), + this,TQT_SLOT(slotMenu ( TQListViewItem *, const TQPoint &, int ))); +} + +KateFileList::~KateFileList () +{ + delete m_tooltip; +} + +void KateFileList::setupActions () +{ + windowNext = KStdAction::back(TQT_TQOBJECT(this), TQT_SLOT(slotPrevDocument()), m_main->actionCollection()); + windowPrev = KStdAction::forward(TQT_TQOBJECT(this), TQT_SLOT(slotNextDocument()), m_main->actionCollection()); + sortAction = new TDESelectAction( i18n("Sort &By"), 0, + m_main->actionCollection(), "filelist_sortby" ); + listMoveFileUp = new TDEAction( i18n("Move File Up"), 0, m_main->actionCollection(), "filelist_move_up" ); + //listMoveFileUp->setShortcut(TDEShortcut(CTRL + SHIFT + Key_Comma)); + listMoveFileDown = new TDEAction( i18n("Move File Down"), 0, m_main->actionCollection(), "filelist_move_down" ); + //listMoveFileDown->setShortcut(TDEShortcut(CTRL + SHIFT + Key_Period)); + connect( listMoveFileUp, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileUp()) ); + connect( listMoveFileDown, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileDown()) ); + TQStringList l; + l << i18n("Opening Order") << i18n("Document Name") << i18n("URL") << i18n("Manual Placement"); + sortAction->setItems( l ); + connect( sortAction, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(setSortType(int)) ); +} + +void KateFileList::updateActions () +{ + windowNext->setEnabled(KateDocManager::self()->documents() > 1); + windowPrev->setEnabled(KateDocManager::self()->documents() > 1); +} + +void KateFileList::keyPressEvent(TQKeyEvent *e) { + if ( ( e->key() == Key_Return ) || ( e->key() == Key_Enter ) ) + { + e->accept(); + slotActivateView( currentItem() ); + } + else + { + TDEListView::keyPressEvent(e); + } +} + +// Protect single mode selection: don't let them +// leftclick outside items. +// ### if we get to accept keyboard navigation, set focus before +// returning +void KateFileList::contentsMousePressEvent( TQMouseEvent *e ) +{ + if ( ! itemAt( contentsToViewport( e->pos() ) ) ) + return; + + TDEListView::contentsMousePressEvent( e ); +} + +void KateFileList::resizeEvent( TQResizeEvent *e ) +{ + TDEListView::resizeEvent( e ); + + // ### We may want to actually calculate the widest field, + // since it's not automatically scrinked. If I add support for + // tree or marks, the changes of the required width will vary + // a lot with opening/closing of files and display changes for + // the mark branches. + int w = viewport()->width(); + if ( columnWidth( 0 ) < w ) + setColumnWidth( 0, w ); +} + +void KateFileList::slotNextDocument() +{ + if ( ! currentItem() || childCount() == 0 ) + return; + + // ### more checking once more item types are added + + if ( currentItem()->nextSibling() ) + viewManager->activateView( ((KateFileListItem*)currentItem()->nextSibling())->documentNumber() ); + else + viewManager->activateView( ((KateFileListItem *)firstChild())->documentNumber() ); +} + +void KateFileList::slotPrevDocument() +{ + if ( ! currentItem() || childCount() == 0 ) + return; + + // ### more checking once more item types are added + + if ( currentItem()->itemAbove() ) + viewManager->activateView( ((KateFileListItem*)currentItem()->itemAbove())->documentNumber() ); + else + viewManager->activateView( ((KateFileListItem *)lastItem())->documentNumber() ); +} + +void KateFileList::slotDocumentCreated (Kate::Document *doc) +{ + new KateFileListItem( this, doc/*, doc->documentNumber()*/ ); + connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(slotModChanged(Kate::Document *))); + connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *))); + connect(doc,TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)),this,TQT_SLOT(slotModifiedOnDisc(Kate::Document *, bool, unsigned char))); + + sort(); + updateFileListLocations(); + updateActions (); +} + +void KateFileList::slotDocumentDeleted (uint documentNumber) +{ + TQListViewItem * item = firstChild(); + while( item ) { + if ( ((KateFileListItem *)item)->documentNumber() == documentNumber ) + { +// m_viewHistory.removeRef( (KateFileListItem *)item ); +// m_editHistory.removeRef( (KateFileListItem *)item ); + + removeItem( item ); + + break; + } + item = item->nextSibling(); + } + + updateFileListLocations(); + updateActions (); +} + +void KateFileList::slotActivateView( TQListViewItem *item ) +{ + if ( ! item || item->rtti() != RTTI_KateFileListItem ) + return; + + viewManager->activateView( ((KateFileListItem *)item)->documentNumber() ); +} + +void KateFileList::slotModChanged (Kate::Document *doc) +{ + if (!doc) return; + + TQListViewItem * item = firstChild(); + while( item ) + { + if ( ((KateFileListItem *)item)->documentNumber() == doc->documentNumber() ) + break; + + item = item->nextSibling(); + } + + if ( ((KateFileListItem *)item)->document()->isModified() ) + { + m_editHistory.removeRef( (KateFileListItem *)item ); + m_editHistory.prepend( (KateFileListItem *)item ); + + for ( uint i=0; i < m_editHistory.count(); i++ ) + { + m_editHistory.at( i )->setEditHistPos( i+1 ); + repaintItem( m_editHistory.at( i ) ); + } + } + else + repaintItem( item ); +} + +void KateFileList::slotModifiedOnDisc (Kate::Document *doc, bool, unsigned char) +{ + slotModChanged( doc ); +} + +void KateFileList::slotNameChanged (Kate::Document *doc) +{ + if (!doc) return; + + // ### using nextSibling to *only* look at toplevel items. + // child items could be marks for example + TQListViewItem * item = firstChild(); + while( item ) { + if ( ((KateFileListItem*)item)->document() == doc ) + { + item->setText( 0, doc->docName() ); + repaintItem( item ); + break; + } + item = item->nextSibling(); + } + updateSort(); +} + +void KateFileList::slotViewChanged () +{ + if (!viewManager->activeView()) return; + + Kate::View *view = viewManager->activeView(); + uint dn = view->getDoc()->documentNumber(); + + TQListViewItem * i = firstChild(); + while( i ) { + if ( ((KateFileListItem *)i)->documentNumber() == dn ) + { + break; + } + i = i->nextSibling(); + } + + if ( ! i ) + return; + + KateFileListItem *item = (KateFileListItem*)i; + setCurrentItem( item ); + + // ### During load of file lists, all the loaded views gets active. + // Do something to avoid shading them -- maybe not creating views, just + // open the documents??? + + +// int p = 0; +// if ( m_viewHistory.count() ) +// { +// int p = m_viewHistory.findRef( item ); // only repaint items that needs it +// } + + m_viewHistory.removeRef( item ); + m_viewHistory.prepend( item ); + + for ( uint i=0; i < m_viewHistory.count(); i++ ) + { + m_viewHistory.at( i )->setViewHistPos( i+1 ); + repaintItem( m_viewHistory.at( i ) ); + } + + updateFileListLocations(); +} + +void KateFileList::updateFileListLocations() +{ + TQListViewItem* item = firstChild(); + int i=0; + while (item) { + Kate::Document* itemDocument = ((KateFileListItem *)item)->document(); + if (m_sort == KateFileList::sortManual) { + if (KateDocManager::self()->findDocument(itemDocument) >= 0) { + itemDocument->setDocumentListPosition(i); + } + } + else { + if (KateDocManager::self()->findDocument(itemDocument) >= 0) { + itemDocument->setDocumentListPosition(-1); + } + } + item = item->itemBelow(); + i++; + } +} + +void KateFileList::slotMenu ( TQListViewItem *item, const TQPoint &p, int /*col*/ ) +{ + if (!item) + return; + + m_clickedMenuItem = item; + if (m_clickedMenuItem->itemAbove()) { + listMoveFileUp->setEnabled(true); + } + else { + listMoveFileUp->setEnabled(false); + } + if (m_clickedMenuItem->itemBelow()) { + listMoveFileDown->setEnabled(true); + } + else { + listMoveFileDown->setEnabled(false); + } + + TQPopupMenu *menu = (TQPopupMenu*) ((viewManager->mainWindow())->factory()->container("filelist_popup", viewManager->mainWindow())); + + if (menu) { + menu->exec(p); + } +} + +TQString KateFileList::tooltip( TQListViewItem *item, int ) +{ + KateFileListItem *i = ((KateFileListItem*)item); + if ( ! i ) return TQString::null; + + TQString str; + const KateDocumentInfo *info = KateDocManager::self()->documentInfo(i->document()); + + if (info && info->modifiedOnDisc) + { + if (info->modifiedOnDiscReason == 1) + str += i18n("<b>This file was changed (modified) on disk by another program.</b><br />"); + else if (info->modifiedOnDiscReason == 2) + str += i18n("<b>This file was changed (created) on disk by another program.</b><br />"); + else if (info->modifiedOnDiscReason == 3) + str += i18n("<b>This file was changed (deleted) on disk by another program.</b><br />"); + } + + str += i->document()->url().prettyURL(); + return str; +} + + +void KateFileList::setSortType (int s) +{ + m_sort = s; + if (m_sort == KateFileList::sortManual) { + setSorting( -1, true ); + setDragEnabled(true); + setAcceptDrops(true); + } + else { + setSorting( 0, true ); + setDragEnabled(false); + setAcceptDrops(false); + updateSort (); + } +} + +void KateFileList::moveFileUp() +{ + if (m_clickedMenuItem) { + sortAction->setCurrentItem(KateFileList::sortManual); + setSortType(KateFileList::sortManual); + TQListViewItem* nitemabove = m_clickedMenuItem->itemAbove(); + if (nitemabove) { + nitemabove = nitemabove->itemAbove(); + if (nitemabove) { + m_clickedMenuItem->moveItem(nitemabove); + } + else { + // Qt made this hard + nitemabove = m_clickedMenuItem->itemAbove(); + nitemabove->moveItem(m_clickedMenuItem); + } + } + } + updateFileListLocations(); +} + +void KateFileList::moveFileDown() +{ + if (m_clickedMenuItem) { + sortAction->setCurrentItem(KateFileList::sortManual); + setSortType(KateFileList::sortManual); + TQListViewItem* nitemabove = m_clickedMenuItem->itemBelow(); + if (nitemabove) { + m_clickedMenuItem->moveItem(nitemabove); + } + } + updateFileListLocations(); +} + +void KateFileList::updateSort () +{ + sort (); + updateFileListLocations(); +} + +void KateFileList::readConfig( TDEConfig *config, const TQString &group ) +{ + TQString oldgroup = config->group(); + config->setGroup( group ); + + setSortType( config->readNumEntry( "Sort Type", sortByID ) ); + m_viewShade = config->readColorEntry( "View Shade", &m_viewShade ); + m_editShade = config->readColorEntry( "Edit Shade", &m_editShade ); + m_enableBgShading = config->readBoolEntry( "Shading Enabled", &m_enableBgShading ); + + sortAction->setCurrentItem( sortType() ); + + config->setGroup( oldgroup ); +} + +void KateFileList::writeConfig( TDEConfig *config, const TQString &group ) +{ + TQString oldgroup = config->group(); + config->setGroup( group ); + + config->writeEntry( "Sort Type", m_sort ); + config->writeEntry( "View Shade", m_viewShade ); + config->writeEntry( "Edit Shade", m_editShade ); + config->writeEntry( "Shading Enabled", m_enableBgShading ); + + config->setGroup( oldgroup ); +} + +void KateFileList::takeItem( TQListViewItem *item ) +{ + if ( item->rtti() == RTTI_KateFileListItem ) + { + m_editHistory.removeRef( (KateFileListItem*)item ); + m_viewHistory.removeRef( (KateFileListItem*)item ); + } + TQListView::takeItem( item ); +} +//END KateFileList + +//BEGIN KateFileListItem +KateFileListItem::KateFileListItem( TQListView* lv, + Kate::Document *_doc ) + : TQListViewItem( lv, _doc->docName() ), + doc( _doc ), + m_viewhistpos( 0 ), + m_edithistpos( 0 ), + m_docNumber( _doc->documentNumber() ) +{ + // Move this document to the end of the list where it belongs + TQListViewItem* lastitem = lv->lastItem(); + if (lastitem) { + moveItem(lastitem); + } +} + +KateFileListItem::~KateFileListItem() +{ +} + +const TQPixmap *KateFileListItem::pixmap ( int column ) const +{ + if ( column == 0) { + static TQPixmap noPm = SmallIcon ("null"); + static TQPixmap modPm = SmallIcon("modified"); + static TQPixmap discPm = SmallIcon("modonhd"); + static TQPixmap modmodPm = SmallIcon("modmod"); + + const KateDocumentInfo *info = KateDocManager::self()->documentInfo(doc); + + if (info && info->modifiedOnDisc) + return doc->isModified() ? &modmodPm : &discPm; + else + return doc->isModified() ? &modPm : &noPm; + } + + return 0; +} + +void KateFileListItem::paintCell( TQPainter *painter, const TQColorGroup & cg, int column, int width, int align ) +{ + KateFileList *fl = (KateFileList*)listView(); + if ( ! fl ) return; + + if ( column == 0 ) + { + TQColorGroup cgNew = cg; + + // replace the base color with a different shading if necessary... + if ( fl->shadingEnabled() && m_viewhistpos > 1 ) + { + TQColor b( cg.base() ); + + TQColor shade = fl->viewShade(); + TQColor eshade = fl->editShade(); + int hc = fl->histCount(); + // If this file is in the edit history, blend in the eshade + // color. The blend is weighted by the position in the editing history + if ( fl->shadingEnabled() && m_edithistpos > 0 ) + { + int ec = fl->editHistCount(); + int v = hc-m_viewhistpos; + int e = ec-m_edithistpos+1; + e = e*e; + int n = TQMAX(v + e, 1); + shade.setRgb( + ((shade.red()*v) + (eshade.red()*e))/n, + ((shade.green()*v) + (eshade.green()*e))/n, + ((shade.blue()*v) + (eshade.blue()*e))/n + ); + } + // blend in the shade color. + // max transperancy < .5, latest is most colored. + float t = (0.5/hc)*(hc-m_viewhistpos+1); + b.setRgb( + (int)((b.red()*(1-t)) + (shade.red()*t)), + (int)((b.green()*(1-t)) + (shade.green()*t)), + (int)((b.blue()*(1-t)) + (shade.blue()*t)) + ); + + cgNew.setColor(TQColorGroup::Base, b); + } + + TQListViewItem::paintCell( painter, cgNew, column, width, align ); + } + else + TQListViewItem::paintCell( painter, cg, column, width, align ); +} + +int KateFileListItem::compare ( TQListViewItem * i, int col, bool ascending ) const +{ + if ( i->rtti() == RTTI_KateFileListItem ) + { + switch( ((KateFileList*)listView())->sortType() ) + { + case KateFileList::sortByID: + { + + int d = (int)doc->documentNumber() - ((KateFileListItem*)i)->documentNumber(); + return ascending ? d : -d; + break; + } + case KateFileList::sortByURL: + return doc->url().prettyURL().compare( ((KateFileListItem*)i)->document()->url().prettyURL() ); + break; + default: + return TQListViewItem::compare( i, col, ascending ); + } + } + return 0; +} +//END KateFileListItem + +//BEGIN KFLConfigPage +KFLConfigPage::KFLConfigPage( TQWidget* parent, const char *name, KateFileList *fl ) + : Kate::ConfigPage( parent, name ), + m_filelist( fl ), + m_changed( false ) +{ + TQVBoxLayout *lo1 = new TQVBoxLayout( this ); + int spacing = KDialog::spacingHint(); + lo1->setSpacing( spacing ); + + TQGroupBox *gb = new TQGroupBox( 1, Qt::Horizontal, i18n("Background Shading"), this ); + lo1->addWidget( gb ); + + TQWidget *g = new TQWidget( gb ); + TQGridLayout *lo = new TQGridLayout( g, 2, 2 ); + lo->setSpacing( KDialog::spacingHint() ); + cbEnableShading = new TQCheckBox( i18n("&Enable background shading"), g ); + lo->addMultiCellWidget( cbEnableShading, 1, 1, 0, 1 ); + + kcbViewShade = new KColorButton( g ); + lViewShade = new TQLabel( kcbViewShade, i18n("&Viewed documents' shade:"), g ); + lo->addWidget( lViewShade, 2, 0 ); + lo->addWidget( kcbViewShade, 2, 1 ); + + kcbEditShade = new KColorButton( g ); + lEditShade = new TQLabel( kcbEditShade, i18n("&Modified documents' shade:"), g ); + lo->addWidget( lEditShade, 3, 0 ); + lo->addWidget( kcbEditShade, 3, 1 ); + + // sorting + TQHBox *hbSorting = new TQHBox( this ); + lo1->addWidget( hbSorting ); + lSort = new TQLabel( i18n("&Sort by:"), hbSorting ); + cmbSort = new TQComboBox( hbSorting ); + lSort->setBuddy( cmbSort ); + TQStringList l; + l << i18n("Opening Order") << i18n("Document Name") << i18n("URL"); + cmbSort->insertStringList( l ); + + lo1->insertStretch( -1, 10 ); + + TQWhatsThis::add( cbEnableShading, i18n( + "When background shading is enabled, documents that have been viewed " + "or edited within the current session will have a shaded background. " + "The most recent documents have the strongest shade.") ); + TQWhatsThis::add( kcbViewShade, i18n( + "Set the color for shading viewed documents.") ); + TQWhatsThis::add( kcbEditShade, i18n( + "Set the color for modified documents. This color is blended into " + "the color for viewed files. The most recently edited documents get " + "most of this color.") ); + + TQWhatsThis::add( cmbSort, i18n( + "Set the sorting method for the documents.") ); + + reload(); + + slotEnableChanged(); + connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotMyChanged()) ); + connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableChanged()) ); + connect( kcbViewShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) ); + connect( kcbEditShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) ); + connect( cmbSort, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMyChanged()) ); +} + +void KFLConfigPage::apply() +{ + if ( ! m_changed ) + return; + m_changed = false; + + // Change settings in the filelist + m_filelist->m_viewShade = kcbViewShade->color(); + m_filelist->m_editShade = kcbEditShade->color(); + m_filelist->m_enableBgShading = cbEnableShading->isChecked(); + m_filelist->setSortType( cmbSort->currentItem() ); + // repaint the affected items + m_filelist->triggerUpdate(); +} + +void KFLConfigPage::reload() +{ + // read in from config file + TDEConfig *config = kapp->config(); + config->setGroup( "Filelist" ); + cbEnableShading->setChecked( config->readBoolEntry("Shading Enabled", &m_filelist->m_enableBgShading ) ); + kcbViewShade->setColor( config->readColorEntry("View Shade", &m_filelist->m_viewShade ) ); + kcbEditShade->setColor( config->readColorEntry("Edit Shade", &m_filelist->m_editShade ) ); + cmbSort->setCurrentItem( m_filelist->sortType() ); + m_changed = false; +} + +void KFLConfigPage::slotEnableChanged() +{ + kcbViewShade->setEnabled( cbEnableShading->isChecked() ); + kcbEditShade->setEnabled( cbEnableShading->isChecked() ); + lViewShade->setEnabled( cbEnableShading->isChecked() ); + lEditShade->setEnabled( cbEnableShading->isChecked() ); +} + +void KFLConfigPage::slotMyChanged() +{ + m_changed = true; + slotChanged(); +} + +//END KFLConfigPage + + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katefilelist.h b/kate/app/katefilelist.h new file mode 100644 index 000000000..49987edd1 --- /dev/null +++ b/kate/app/katefilelist.h @@ -0,0 +1,199 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_FILELIST_H__ +#define __KATE_FILELIST_H__ + +#include "katemain.h" + +#include <kate/document.h> + +#include <tdelistview.h> + +#include <tqtooltip.h> +#include <tqcolor.h> +#include <tqptrlist.h> + +#define RTTI_KateFileListItem 1001 + +class KateMainWindow; + +class TDEAction; +class TDESelectAction; + +class KateFileListItem : public TQListViewItem +{ + public: + KateFileListItem( TQListView *lv, + Kate::Document *doc ); + ~KateFileListItem(); + + inline uint documentNumber () { return m_docNumber; } + inline Kate::Document * document() { return doc; } + + int rtti() const { return RTTI_KateFileListItem; } + + /** + * Sets the view history position. + */ + void setViewHistPos( int p ) { m_viewhistpos = p; } + /** + * Sets the edit history position. + */ + void setEditHistPos( int p ) { m_edithistpos = p; } + + protected: + virtual const TQPixmap *pixmap ( int column ) const; + void paintCell( TQPainter *painter, const TQColorGroup & cg, int column, int width, int align ); + /** + * Reimplemented so we can sort by a number of different document properties. + */ + int compare ( TQListViewItem * i, int col, bool ascending ) const; + + private: + Kate::Document *doc; + int m_viewhistpos; ///< this gets set by the list as needed + int m_edithistpos; ///< this gets set by the list as needed + uint m_docNumber; +}; + +class KateFileList : public TDEListView +{ + Q_OBJECT + + friend class KFLConfigPage; + + public: + KateFileList (KateMainWindow *main, KateViewManager *_viewManager, TQWidget * parent = 0, const char * name = 0 ); + ~KateFileList (); + + int sortType () const { return m_sort; }; + void updateSort (); + + enum sorting { + sortByID = 0, + sortByName = 1, + sortByURL = 2, + sortManual = 3 + }; + + TQString tooltip( TQListViewItem *item, int ); + + uint histCount() const { return m_viewHistory.count(); } + uint editHistCount() const { return m_editHistory.count(); } + TQColor editShade() const { return m_editShade; } + TQColor viewShade() const { return m_viewShade; } + bool shadingEnabled() { return m_enableBgShading; } + + void readConfig( class TDEConfig *config, const TQString &group ); + void writeConfig( class TDEConfig *config, const TQString &group ); + + /** + * reimplemented to remove the item from the history stacks + */ + void takeItem( TQListViewItem * ); + + public slots: + void setSortType (int s); + void moveFileUp(); + void moveFileDown(); + void slotNextDocument(); + void slotPrevDocument(); + + private slots: + void slotDocumentCreated (Kate::Document *doc); + void slotDocumentDeleted (uint documentNumber); + void slotActivateView( TQListViewItem *item ); + void slotModChanged (Kate::Document *doc); + void slotModifiedOnDisc (Kate::Document *doc, bool b, unsigned char reason); + void slotNameChanged (Kate::Document *doc); + void slotViewChanged (); + void slotMenu ( TQListViewItem *item, const TQPoint &p, int col ); + void updateFileListLocations(); + + protected: + virtual void keyPressEvent( TQKeyEvent *e ); + /** + * Reimplemented to force Single mode for real: + * don't let a mouse click outside items deselect. + */ + virtual void contentsMousePressEvent( TQMouseEvent *e ); + /** + * Reimplemented to make sure the first (and only) column is at least + * the width of the viewport + */ + virtual void resizeEvent( TQResizeEvent *e ); + + private: + void setupActions (); + void updateActions (); + + private: + KateMainWindow *m_main; + KateViewManager *viewManager; + + int m_sort; + bool notify; + + TDEAction* windowNext; + TDEAction* windowPrev; + TDESelectAction* sortAction; + TDEAction* listMoveFileUp; + TDEAction* listMoveFileDown; + + TQPtrList<KateFileListItem> m_viewHistory; + TQPtrList<KateFileListItem> m_editHistory; + + TQColor m_viewShade, m_editShade; + bool m_enableBgShading; + + TQListViewItem *m_clickedMenuItem; + + class ToolTip *m_tooltip; +}; + +class KFLConfigPage : public Kate::ConfigPage { + Q_OBJECT + public: + KFLConfigPage( TQWidget* parent=0, const char *name=0, KateFileList *fl=0 ); + virtual ~KFLConfigPage() {}; + + virtual void apply(); + virtual void reload(); + + public slots: + void slotEnableChanged(); + + private slots: + void slotMyChanged(); + + private: + class TQCheckBox *cbEnableShading; + class KColorButton *kcbViewShade, *kcbEditShade; + class TQLabel *lEditShade, *lViewShade, *lSort; + class TQComboBox *cmbSort; + KateFileList *m_filelist; + + bool m_changed; +}; + + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katefileselector.cpp b/kate/app/katefileselector.cpp new file mode 100644 index 000000000..c4b107912 --- /dev/null +++ b/kate/app/katefileselector.cpp @@ -0,0 +1,722 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "katefileselector.h" +#include "katefileselector.moc" + +#include "katemainwindow.h" +#include "kateviewmanager.h" +#include "kbookmarkhandler.h" + +#include "tdeactionselector.h" + +#include <tqlayout.h> +#include <tqtoolbutton.h> +#include <tqhbox.h> +#include <tqvbox.h> +#include <tqlabel.h> +#include <tqstrlist.h> +#include <tqtooltip.h> +#include <tqwhatsthis.h> +#include <tqapplication.h> +#include <tqlistbox.h> +#include <tqscrollbar.h> +#include <tqspinbox.h> +#include <tqgroupbox.h> +#include <tqcheckbox.h> +#include <tqregexp.h> +#include <tqdockarea.h> +#include <tqtimer.h> +#include <tqdir.h> + +#include <tdeapplication.h> +#include <kiconloader.h> +#include <kurlcombobox.h> +#include <kurlcompletion.h> +#include <kprotocolinfo.h> +#include <tdediroperator.h> +#include <tdeconfig.h> +#include <tdelocale.h> +#include <kcombobox.h> +#include <tdeaction.h> +#include <tdemessagebox.h> +#include <tdetoolbarbutton.h> +#include <tqtoolbar.h> +#include <tdepopupmenu.h> +#include <kdialog.h> +#include <kdebug.h> +//END Includes + +//BEGIN Toolbar + // from tdefiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors) +static void silenceQToolBar(TQtMsgType, const char *){} + +// helper classes to be able to have a toolbar without move handle +KateFileSelectorToolBar::KateFileSelectorToolBar(TQWidget *parent) + : TDEToolBar( parent, "Kate FileSelector Toolbar", true ) +{ + setMinimumWidth(10); +} + +KateFileSelectorToolBar::~KateFileSelectorToolBar(){} + +void KateFileSelectorToolBar::setMovingEnabled( bool) +{ + TDEToolBar::setMovingEnabled(false); +} + + +KateFileSelectorToolBarParent::KateFileSelectorToolBarParent(TQWidget *parent) + :TQFrame(parent),m_tb(0){} +KateFileSelectorToolBarParent::~KateFileSelectorToolBarParent(){} +void KateFileSelectorToolBarParent::setToolBar(KateFileSelectorToolBar *tb) +{ + m_tb=tb; +} + +void KateFileSelectorToolBarParent::resizeEvent ( TQResizeEvent * ) +{ + if (m_tb) + { + setMinimumHeight(m_tb->sizeHint().height()); + m_tb->resize(width(),height()); + } +} +//END + +//BEGIN Constructor/destructor + +KateFileSelector::KateFileSelector( KateMainWindow *mainWindow, + KateViewManager *viewManager, + TQWidget * parent, const char * name ) + : TQVBox (parent, name), + mainwin(mainWindow), + viewmanager(viewManager) +{ + mActionCollection = new TDEActionCollection( this ); + + TQtMsgHandler oldHandler = tqInstallMsgHandler( silenceQToolBar ); + + KateFileSelectorToolBarParent *tbp=new KateFileSelectorToolBarParent(this); + toolbar = new KateFileSelectorToolBar(tbp); + tbp->setToolBar(toolbar); + toolbar->setMovingEnabled(false); + toolbar->setFlat(true); + tqInstallMsgHandler( oldHandler ); + + cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" ); + cmbPath->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); + KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion); + cmbPath->setCompletionObject( cmpl ); + cmbPath->setAutoDeleteCompletionObject( true ); + cmbPath->listBox()->installEventFilter( this ); + + dir = new KDirOperator(KURL(), this, "operator"); + dir->setView(KFile::/* Simple */Detail); + dir->view()->setSelectionMode(KFile::Extended); + connect ( dir, TQT_SIGNAL( viewChanged(KFileView *) ), + this, TQT_SLOT( selectorViewChanged(KFileView *) ) ); + setStretchFactor(dir, 2); + + TDEActionCollection *coll = dir->actionCollection(); + // some shortcuts of diroperator that clashes with Kate + coll->action( "delete" )->setShortcut( TDEShortcut( ALT + Key_Delete ) ); + coll->action( "reload" )->setShortcut( TDEShortcut( ALT + Key_F5 ) ); + coll->action( "back" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Left ) ); + coll->action( "forward" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Right ) ); + // some consistency - reset up for dir too + coll->action( "up" )->setShortcut( TDEShortcut( ALT + SHIFT + Key_Up ) ); + coll->action( "home" )->setShortcut( TDEShortcut( CTRL + ALT + Key_Home ) ); + + // bookmarks action! + TDEActionMenu *acmBookmarks = new TDEActionMenu( i18n("Bookmarks"), "bookmark", + mActionCollection, "bookmarks" ); + acmBookmarks->setDelayed( false ); + bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() ); + TQHBox* filterBox = new TQHBox(this); + + btnFilter = new TQToolButton( filterBox ); + btnFilter->setIconSet( SmallIconSet("filter" ) ); + btnFilter->setToggleButton( true ); + filter = new KHistoryCombo( true, filterBox, "filter"); + filter->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); + filterBox->setStretchFactor(filter, 2); + connect( btnFilter, TQT_SIGNAL( clicked() ), this, TQT_SLOT( btnFilterClick() ) ); + + connect( filter, TQT_SIGNAL( activated(const TQString&) ), + TQT_SLOT( slotFilterChange(const TQString&) ) ); + connect( filter, TQT_SIGNAL( returnPressed(const TQString&) ), + filter, TQT_SLOT( addToHistory(const TQString&) ) ); + + // tdeaction for the dir sync method + acSyncDir = new TDEAction( i18n("Current Document Folder"), "curfiledir", 0, + TQT_TQOBJECT(this), TQT_SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" ); + toolbar->setIconText( TDEToolBar::IconOnly ); + toolbar->setIconSize( 16 ); + toolbar->setEnableContextMenu( false ); + + connect( cmbPath, TQT_SIGNAL( urlActivated( const KURL& )), + this, TQT_SLOT( cmbPathActivated( const KURL& ) )); + connect( cmbPath, TQT_SIGNAL( returnPressed( const TQString& )), + this, TQT_SLOT( cmbPathReturnPressed( const TQString& ) )); + connect(dir, TQT_SIGNAL(urlEntered(const KURL&)), + this, TQT_SLOT(dirUrlEntered(const KURL&)) ); + + connect(dir, TQT_SIGNAL(finishedLoading()), + this, TQT_SLOT(dirFinishedLoading()) ); + + // enable dir sync button if current doc has a valid URL + connect ( viewmanager, TQT_SIGNAL( viewChanged() ), + this, TQT_SLOT( kateViewChanged() ) ); + + // Connect the bookmark handler + connect( bookmarkHandler, TQT_SIGNAL( openURL( const TQString& )), + this, TQT_SLOT( setDir( const TQString& ) ) ); + + waitingUrl = TQString::null; + + // whatsthis help + TQWhatsThis::add( cmbPath, + i18n("<p>Here you can enter a path for a folder to display." + "<p>To go to a folder previously entered, press the arrow on " + "the right and choose one. <p>The entry has folder " + "completion. Right-click to choose how completion should behave.") ); + TQWhatsThis::add( filter, + i18n("<p>Here you can enter a name filter to limit which files are displayed." + "<p>To clear the filter, toggle off the filter button to the left." + "<p>To reapply the last filter used, toggle on the filter button." ) ); + TQWhatsThis::add( btnFilter, + i18n("<p>This button clears the name filter when toggled off, or " + "reapplies the last filter used when toggled on.") ); + +} + +KateFileSelector::~KateFileSelector() +{ +} +//END Constroctor/Destrctor + +//BEGIN Public Methods + +void KateFileSelector::readConfig(TDEConfig *config, const TQString & name) +{ + dir->setViewConfig( config, name + ":view" ); + dir->readConfig(config, name + ":dir"); + dir->setView( KFile::Default ); + dir->view()->setSelectionMode(KFile::Extended); + config->setGroup( name ); + + // set up the toolbar + setupToolbar( config ); + + cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) ); + cmbPath->setURLs( config->readPathListEntry( "dir history" ) ); + // if we restore history + if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() ) { + TQString loc( config->readPathEntry( "location" ) ); + if ( ! loc.isEmpty() ) { +// waitingDir = loc; +// TQTimer::singleShot(0, this, TQT_SLOT(initialDirChangeHack())); + setDir( loc ); + } + } + + // else is automatic, as cmpPath->setURL is called when a location is entered. + + filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) ); + filter->setHistoryItems( config->readListEntry("filter history"), true ); + lastFilter = config->readEntry( "last filter" ); + TQString flt(""); + if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() ) + flt = config->readEntry("current filter"); + filter->lineEdit()->setText( flt ); + slotFilterChange( flt ); + + autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 ); +} + +void KateFileSelector::initialDirChangeHack() +{ + setDir( waitingDir ); +} + +void KateFileSelector::setupToolbar( TDEConfig *config ) +{ + toolbar->clear(); + TQStringList tbactions = config->readListEntry( "toolbar actions", ',' ); + if ( tbactions.isEmpty() ) { + // reasonable collection for default toolbar + tbactions << "up" << "back" << "forward" << "home" << + "short view" << "detailed view" << + "bookmarks" << "sync_dir"; + } + TDEAction *ac; + for ( TQStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) { + if ( *it == "bookmarks" || *it == "sync_dir" ) + ac = mActionCollection->action( (*it).latin1() ); + else + ac = dir->actionCollection()->action( (*it).latin1() ); + if ( ac ) + ac->plug( toolbar ); + } +} + +void KateFileSelector::writeConfig(TDEConfig *config, const TQString & name) +{ + dir->writeConfig(config,name + ":dir"); + + config->setGroup( name ); + config->writeEntry( "pathcombo history len", cmbPath->maxItems() ); + TQStringList l; + for (int i = 0; i < cmbPath->count(); i++) { + l.append( cmbPath->text( i ) ); + } + config->writePathEntry( "dir history", l ); + config->writePathEntry( "location", cmbPath->currentText() ); + + config->writeEntry( "filter history len", filter->maxCount() ); + config->writeEntry( "filter history", filter->historyItems() ); + config->writeEntry( "current filter", filter->currentText() ); + config->writeEntry( "last filter", lastFilter ); + config->writeEntry( "AutoSyncEvents", autoSyncEvents ); +} + +void KateFileSelector::setView(KFile::FileView view) +{ + dir->setView(view); + dir->view()->setSelectionMode(KFile::Extended); +} + +//END Public Methods + +//BEGIN Public Slots + +void KateFileSelector::slotFilterChange( const TQString & nf ) +{ + TQString f = nf.stripWhiteSpace(); + bool empty = f.isEmpty() || f == "*"; + TQToolTip::remove( btnFilter ); + if ( empty ) { + dir->clearFilter(); + filter->lineEdit()->setText( TQString::null ); + TQToolTip::add( btnFilter, + TQString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) ); + } + else { + dir->setNameFilter( f ); + lastFilter = f; + TQToolTip::add( btnFilter, i18n("Clear filter") ); + } + btnFilter->setOn( !empty ); + dir->updateDir(); + // this will be never true after the filter has been used;) + btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) ); + +} + +bool kateFileSelectorIsReadable ( const KURL& url ) +{ + if ( !url.isLocalFile() ) + return true; // what else can we say? + + TQDir dir (url.path()); + return dir.exists (); +} + +void KateFileSelector::setDir( KURL u ) +{ + KURL newurl; + + if ( !u.isValid() ) + newurl.setPath( TQDir::homeDirPath() ); + else + newurl = u; + + TQString pathstr = newurl.path(+1); + newurl.setPath(pathstr); + + if ( !kateFileSelectorIsReadable ( newurl ) ) + newurl.cd(TQString::fromLatin1("..")); + + if ( !kateFileSelectorIsReadable (newurl) ) + newurl.setPath( TQDir::homeDirPath() ); + + dir->setURL(newurl, true); +} + +//END Public Slots + +//BEGIN Private Slots + +void KateFileSelector::cmbPathActivated( const KURL& u ) +{ + cmbPathReturnPressed( u.url() ); +} + +void KateFileSelector::cmbPathReturnPressed( const TQString& u ) +{ + KURL typedURL( u ); + if ( typedURL.hasPass() ) + typedURL.setPass( TQString::null ); + + TQStringList urls = cmbPath->urls(); + urls.remove( typedURL.url() ); + urls.prepend( typedURL.url() ); + cmbPath->setURLs( urls, KURLComboBox::RemoveBottom ); + dir->setFocus(); + dir->setURL( KURL(u), true ); +} + +void KateFileSelector::dirUrlEntered( const KURL& u ) +{ + cmbPath->setURL( u ); +} + +void KateFileSelector::dirFinishedLoading() +{ +} + + +/* + When the button in the filter box toggles: + If off: + If the name filer is anything but "" or "*", reset it. + If on: + Set last filter. +*/ +void KateFileSelector::btnFilterClick() +{ + if ( !btnFilter->isOn() ) { + slotFilterChange( TQString::null ); + } + else { + filter->lineEdit()->setText( lastFilter ); + slotFilterChange( lastFilter ); + } +} + +//FIXME crash on shutdown +void KateFileSelector::setActiveDocumentDir() +{ +// kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl; + KURL u = mainwin->activeDocumentUrl(); +// kdDebug(13001)<<"URL: "<<u.prettyURL()<<endl; + if (!u.isEmpty()) + setDir( u.upURL() ); +// kdDebug(13001)<<"... setActiveDocumentDir() DONE!"<<endl; +} + +void KateFileSelector::kateViewChanged() +{ + if ( autoSyncEvents & DocumentChanged ) + { +// kdDebug(13001)<<"KateFileSelector::do a sync ()"<<endl; + // if visible, sync + if ( isVisible() ) { + setActiveDocumentDir(); + waitingUrl = TQString::null; + } + // else set waiting url + else { + KURL u = mainwin->activeDocumentUrl(); + if (!u.isEmpty()) + waitingUrl = u.directory(); + } + } + + // TODO: make sure the button is disabled if the directory is unreadable, eg + // the document URL has protocol http + acSyncDir->setEnabled( ! mainwin->activeDocumentUrl().directory().isEmpty() ); +} + +void KateFileSelector::selectorViewChanged( KFileView * newView ) +{ + newView->setSelectionMode(KFile::Extended); +} + +//END Private Slots + +//BEGIN Protected + +void KateFileSelector::focusInEvent( TQFocusEvent * ) +{ + dir->setFocus(); +} + +void KateFileSelector::showEvent( TQShowEvent * ) +{ + // sync if we should + if ( autoSyncEvents & GotVisible ) { +// kdDebug(13001)<<"syncing fs on show"<<endl; + setActiveDocumentDir(); + waitingUrl = TQString::null; + } + // else, if we have a waiting URL set it + else if ( ! waitingUrl.isEmpty() ) { + setDir( waitingUrl ); + waitingUrl = TQString::null; + } +} + +bool KateFileSelector::eventFilter( TQObject* o, TQEvent *e ) +{ + /* + This is rather unfortunate, but: + TQComboBox does not support setting the size of the listbox to something + reasonable. Even using listbox->setVariableWidth() does not yield a + satisfying result, something is wrong with the handling of the sizehint. + And the popup is rather useless, if the paths are only partly visible. + */ + TQListBox *lb = cmbPath->listBox(); + if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(lb) && e->type() == TQEvent::Show ) { + int add = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0; + int w = TQMIN( mainwin->width(), lb->contentsWidth() + add ); + lb->resize( w, lb->height() ); + // TODO - move the listbox to a suitable place if nessecary + // TODO - decide if it is worth caching the size while untill the contents + // are changed. + } + // TODO - same thing for the completion popup? + return TQWidget::eventFilter( o, e ); +} + +//END Protected + +//BEGIN ACtionLBItem +/* + QListboxItem that can store and return a string, + used for the toolbar action selector. +*/ +class ActionLBItem : public TQListBoxPixmap { + public: + ActionLBItem( TQListBox *lb=0, + const TQPixmap &pm = TQPixmap(), + const TQString &text=TQString::null, + const TQString &str=TQString::null ) : + TQListBoxPixmap( lb, pm, text ), + _str(str) {}; + TQString idstring() { return _str; }; + private: + TQString _str; +}; +//END ActionLBItem + +//BEGIN KFSConfigPage +//////////////////////////////////////////////////////////////////////////////// +// KFSConfigPage implementation +//////////////////////////////////////////////////////////////////////////////// +KFSConfigPage::KFSConfigPage( TQWidget *parent, const char *name, KateFileSelector *kfs ) + : Kate::ConfigPage( parent, name ), + fileSelector( kfs ), + m_changed( false ) +{ + TQVBoxLayout *lo = new TQVBoxLayout( this ); + int spacing = KDialog::spacingHint(); + lo->setSpacing( spacing ); + + // Toolbar - a lot for a little... + TQGroupBox *gbToolbar = new TQGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this ); + acSel = new TDEActionSelector( gbToolbar ); + acSel->setAvailableLabel( i18n("A&vailable actions:") ); + acSel->setSelectedLabel( i18n("S&elected actions:") ); + lo->addWidget( gbToolbar ); + connect( acSel, TQT_SIGNAL( added( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) ); + connect( acSel, TQT_SIGNAL( removed( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) ); + connect( acSel, TQT_SIGNAL( movedUp( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) ); + connect( acSel, TQT_SIGNAL( movedDown( TQListBoxItem * ) ), this, TQT_SLOT( slotMyChanged() ) ); + + // Sync + TQGroupBox *gbSync = new TQGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this ); + cbSyncActive = new TQCheckBox( i18n("When a docu&ment becomes active"), gbSync ); + cbSyncShow = new TQCheckBox( i18n("When the file selector becomes visible"), gbSync ); + lo->addWidget( gbSync ); + connect( cbSyncActive, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) ); + connect( cbSyncShow, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) ); + + // Histories + TQHBox *hbPathHist = new TQHBox ( this ); + TQLabel *lbPathHist = new TQLabel( i18n("Remember &locations:"), hbPathHist ); + sbPathHistLength = new TQSpinBox( hbPathHist ); + lbPathHist->setBuddy( sbPathHistLength ); + lo->addWidget( hbPathHist ); + connect( sbPathHistLength, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotMyChanged() ) ); + + TQHBox *hbFilterHist = new TQHBox ( this ); + TQLabel *lbFilterHist = new TQLabel( i18n("Remember &filters:"), hbFilterHist ); + sbFilterHistLength = new TQSpinBox( hbFilterHist ); + lbFilterHist->setBuddy( sbFilterHistLength ); + lo->addWidget( hbFilterHist ); + connect( sbFilterHistLength, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotMyChanged() ) ); + + // Session + TQGroupBox *gbSession = new TQGroupBox( 1, Qt::Horizontal, i18n("Session"), this ); + cbSesLocation = new TQCheckBox( i18n("Restore loca&tion"), gbSession ); + cbSesFilter = new TQCheckBox( i18n("Restore last f&ilter"), gbSession ); + lo->addWidget( gbSession ); + connect( cbSesLocation, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) ); + connect( cbSesFilter, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotMyChanged() ) ); + + // make it look nice + lo->addStretch( 1 ); + + // be helpfull + /* + TQWhatsThis::add( lbAvailableActions, i18n( + "<p>Available actions for the toolbar. To add an action, select it here " + "and press the add (<strong>-></strong>) button" ) ); + TQWhatsThis::add( lbUsedActions, i18n( + "<p>Actions used in the toolbar. To remove an action, select it and " + "press the remove (<strong><-</strong>) button." + "<p>To change the order of the actions, use the Up and Down buttons to " + "move the selected action.") ); + */ + TQString lhwt( i18n( + "<p>Decides how many locations to keep in the history of the location " + "combo box.") ); + TQWhatsThis::add( lbPathHist, lhwt ); + TQWhatsThis::add( sbPathHistLength, lhwt ); + TQString fhwt( i18n( + "<p>Decides how many filters to keep in the history of the filter " + "combo box.") ); + TQWhatsThis::add( lbFilterHist, fhwt ); + TQWhatsThis::add( sbFilterHistLength, fhwt ); + TQString synwt( i18n( + "<p>These options allow you to have the File Selector automatically " + "change location to the folder of the active document on certain " + "events." + "<p>Auto synchronization is <em>lazy</em>, meaning it will not take " + "effect until the file selector is visible." + "<p>None of these are enabled by default, but you can always sync the " + "location by pressing the sync button in the toolbar.") ); + TQWhatsThis::add( gbSync, synwt ); + TQWhatsThis::add( cbSesLocation, i18n( + "<p>If this option is enabled (default), the location will be restored " + "when you start Kate.<p><strong>Note</strong> that if the session is " + "handled by the TDE session manager, the location is always restored.") ); + TQWhatsThis::add( cbSesFilter, i18n( + "<p>If this option is enabled (default), the current filter will be " + "restored when you start Kate.<p><strong>Note</strong> that if the " + "session is handled by the TDE session manager, the filter is always " + "restored." + "<p><strong>Note</strong> that some of the autosync settings may " + "override the restored location if on.") ); + + init(); + +} + +void KFSConfigPage::apply() +{ + if ( ! m_changed ) + return; + + m_changed = false; + + TDEConfig *config = kapp->config(); + config->setGroup( "fileselector" ); + // toolbar + TQStringList l; + TQListBoxItem *item = acSel->selectedListBox()->firstItem(); + ActionLBItem *aItem; + while ( item ) + { + aItem = (ActionLBItem*)item; + if ( aItem ) + { + l << aItem->idstring(); + } + item = item->next(); + } + config->writeEntry( "toolbar actions", l ); + fileSelector->setupToolbar( config ); + // sync + int s = 0; + if ( cbSyncActive->isChecked() ) + s |= KateFileSelector::DocumentChanged; + if ( cbSyncShow->isChecked() ) + s |= KateFileSelector::GotVisible; + fileSelector->autoSyncEvents = s; + + // histories + fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() ); + fileSelector->filter->setMaxCount( sbFilterHistLength->value() ); + // session - theese are read/written directly to the app config, + // as they are not needed during operation. + config->writeEntry( "restore location", cbSesLocation->isChecked() ); + config->writeEntry( "restore last filter", cbSesFilter->isChecked() ); +} + +void KFSConfigPage::reload() +{ + // hmm, what is this supposed to do, actually?? + init(); + m_changed = false; +} +void KFSConfigPage::init() +{ + TDEConfig *config = kapp->config(); + config->setGroup( "fileselector" ); + // toolbar + TQStringList l = config->readListEntry( "toolbar actions", ',' ); + if ( l.isEmpty() ) // default toolbar + l << "up" << "back" << "forward" << "home" << + "short view" << "detailed view" << + "bookmarks" << "sync_dir"; + + // actions from diroperator + two of our own + TQStringList allActions; + allActions << "up" << "back" << "forward" << "home" << + "reload" << "mkdir" << "delete" << + "short view" << "detailed view" /*<< "view menu" << + "show hidden" << "properties"*/ << + "bookmarks" << "sync_dir"; + TQRegExp re("&(?=[^&])"); + TDEAction *ac; + TQListBox *lb; + for ( TQStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it ) { + lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox(); + if ( *it == "bookmarks" || *it == "sync_dir" ) + ac = fileSelector->actionCollection()->action( (*it).latin1() ); + else + ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() ); + if ( ac ) + new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it ); + } + + // sync + int s = fileSelector->autoSyncEvents; + cbSyncActive->setChecked( s & KateFileSelector::DocumentChanged ); + cbSyncShow->setChecked( s & KateFileSelector::GotVisible ); + // histories + sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() ); + sbFilterHistLength->setValue( fileSelector->filter->maxCount() ); + // session + cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) ); + cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) ); +} + +void KFSConfigPage::slotMyChanged() +{ + m_changed = true; + slotChanged(); +} +//END KFSConfigPage +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katefileselector.h b/kate/app/katefileselector.h new file mode 100644 index 000000000..33482faba --- /dev/null +++ b/kate/app/katefileselector.h @@ -0,0 +1,172 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_FILESELECTOR_H__ +#define __KATE_FILESELECTOR_H__ + +#include "katemain.h" +#include "katedocmanager.h" +#include <kate/document.h> + +#include <tqvbox.h> +#include <tdefile.h> +#include <kurl.h> +#include <tdetoolbar.h> +#include <tqframe.h> + +class KateMainWindow; +class KateViewManager; +class TDEActionCollection; +class TDEActionSelector; +class KFileView; + +/* + The kate file selector presents a directory view, in which the default action is + to open the activated file. + Additinally, a toolbar for managing the kdiroperator widget + sync that to + the directory of the current file is available, as well as a filter widget + allowing to filter the displayed files using a name filter. +*/ + +/* I think this fix for not moving toolbars is better */ +class KateFileSelectorToolBar: public TDEToolBar +{ + Q_OBJECT +public: + KateFileSelectorToolBar(TQWidget *parent); + virtual ~KateFileSelectorToolBar(); + + virtual void setMovingEnabled( bool b ); +}; + +class KateFileSelectorToolBarParent: public TQFrame +{ + Q_OBJECT +public: + KateFileSelectorToolBarParent(TQWidget *parent); + ~KateFileSelectorToolBarParent(); + void setToolBar(KateFileSelectorToolBar *tb); +private: + KateFileSelectorToolBar *m_tb; +protected: + virtual void resizeEvent ( TQResizeEvent * ); +}; + +class KateFileSelector : public TQVBox +{ + Q_OBJECT + + friend class KFSConfigPage; + + public: + /* When to sync to current document directory */ + enum AutoSyncEvent { DocumentChanged=1, GotVisible=2 }; + + KateFileSelector( KateMainWindow *mainWindow=0, KateViewManager *viewManager=0, + TQWidget * parent = 0, const char * name = 0 ); + ~KateFileSelector(); + + void readConfig( TDEConfig *, const TQString & ); + void writeConfig( TDEConfig *, const TQString & ); + void setupToolbar( TDEConfig * ); + void setView( KFile::FileView ); + KDirOperator *dirOperator(){ return dir; } + TDEActionCollection *actionCollection() { return mActionCollection; }; + + public slots: + void slotFilterChange(const TQString&); + void setDir(KURL); + void setDir( const TQString& url ) { setDir( KURL( url ) ); }; + void kateViewChanged(); + void selectorViewChanged( KFileView * ); + + private slots: + void cmbPathActivated( const KURL& u ); + void cmbPathReturnPressed( const TQString& u ); + void dirUrlEntered( const KURL& u ); + void dirFinishedLoading(); + void setActiveDocumentDir(); + void btnFilterClick(); + + protected: + void focusInEvent( TQFocusEvent * ); + void showEvent( TQShowEvent * ); + bool eventFilter( TQObject *, TQEvent * ); + void initialDirChangeHack(); + + private: + class KateFileSelectorToolBar *toolbar; + TDEActionCollection *mActionCollection; + class KBookmarkHandler *bookmarkHandler; + KURLComboBox *cmbPath; + KDirOperator * dir; + class TDEAction *acSyncDir; + KHistoryCombo * filter; + class TQToolButton *btnFilter; + + KateMainWindow *mainwin; + KateViewManager *viewmanager; + + TQString lastFilter; + int autoSyncEvents; // enabled autosync events + TQString waitingUrl; // maybe display when we gets visible + TQString waitingDir; +}; + +/* TODO anders + KFSFilterHelper + A popup widget presenting a listbox with checkable items + representing the mime types available in the current directory, and + providing a name filter based on those. +*/ + +/* + Config page for file selector. + Allows for configuring the toolbar, the history length + of the path and file filter combos, and how to handle + user closed session. +*/ +class KFSConfigPage : public Kate::ConfigPage { + Q_OBJECT + public: + KFSConfigPage( TQWidget* parent=0, const char *name=0, KateFileSelector *kfs=0); + virtual ~KFSConfigPage() {}; + + virtual void apply(); + virtual void reload(); + + private slots: + void slotMyChanged(); + + private: + void init(); + + KateFileSelector *fileSelector; + TDEActionSelector *acSel; + class TQSpinBox *sbPathHistLength, *sbFilterHistLength; + class TQCheckBox *cbSyncActive, *cbSyncShow; + class TQCheckBox *cbSesLocation, *cbSesFilter; + + bool m_changed; +}; + + +#endif //__KATE_FILESELECTOR_H__ +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kategrepdialog.cpp b/kate/app/kategrepdialog.cpp new file mode 100644 index 000000000..b180fd516 --- /dev/null +++ b/kate/app/kategrepdialog.cpp @@ -0,0 +1,544 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001, 2004 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kategrepdialog.h" +#include "katemainwindow.h" + +#include <tqobject.h> +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqcheckbox.h> +#include <tqevent.h> +#include <tqlistbox.h> +#include <tqregexp.h> +#include <tqwhatsthis.h> +#include <tqcursor.h> + +#include <tdeapplication.h> +#include <tdeaccelmanager.h> +#include <kbuttonbox.h> +#include <tdefiledialog.h> +#include <kprocess.h> +#include <tdeapplication.h> +#include <tdelocale.h> +#include <kiconloader.h> +#include <tdemessagebox.h> +#include <kpushbutton.h> +#include <kurlrequester.h> +#include <kurlcompletion.h> +#include <kcombobox.h> +#include <klineedit.h> + +const char *template_desc[] = { + "normal", + "assignment", + "->MEMBER(", + "class::MEMBER(", + "OBJECT->member(", + 0 +}; + +const char *strTemplate[] = { + "%s", + "\\<%s\\>[\t ]*=[^=]", + "\\->[\\t ]*\\<%s\\>[\\t ]*(", + "[a-z0-9_$]\\+[\\t ]*::[\\t ]*\\<%s\\>[\\t ]*(", + "\\<%s\\>[\\t ]*\\->[\\t ]*[a-z0-9_$]\\+[\\t ]*(", + 0 +}; + + +GrepTool::GrepTool(TQWidget *parent, const char *name) + : TQWidget(parent, name/*, false*/), m_fixFocus(true), childproc(0) +{ + setCaption(i18n("Find in Files")); + config = TDEGlobal::config(); + config->setGroup("GrepTool"); + lastSearchItems = config->readListEntry("LastSearchItems"); + lastSearchPaths = config->readListEntry("LastSearchPaths"); + lastSearchFiles = config->readListEntry("LastSearchFiles"); + + if( lastSearchFiles.isEmpty() ) + { + // if there are no entries, most probably the first Kate start. + // Initialize with default values. + lastSearchFiles << "*.h,*.hxx,*.cpp,*.cc,*.C,*.cxx,*.idl,*.c" + << "*.cpp,*.cc,*.C,*.cxx,*.c" + << "*.h,*.hxx,*.idl" + << "*"; + } + + TQGridLayout *layout = new TQGridLayout(this, 6, 3, 4, 4); + layout->setColStretch(0, 10); + layout->addColSpacing(1, 10); + layout->setColStretch(1, 0); + layout->setColStretch(2, 1); + layout->setRowStretch(1, 0); + layout->setRowStretch(2, 10); + layout->setRowStretch(4, 0); + + TQGridLayout *loInput = new TQGridLayout(4, 2, 4); + layout->addLayout(loInput, 0, 0); + loInput->setColStretch(0, 0); + loInput->setColStretch(1, 20); + + TQLabel *lPattern = new TQLabel(i18n("Pattern:"), this); + lPattern->setFixedSize(lPattern->sizeHint()); + loInput->addWidget(lPattern, 0, 0, Qt::AlignRight | Qt::AlignVCenter); + + TQBoxLayout *loPattern = new TQHBoxLayout( 4 ); + loInput->addLayout( loPattern, 0, 1 ); + cmbPattern = new KComboBox(true, this); + cmbPattern->setDuplicatesEnabled(false); + cmbPattern->insertStringList(lastSearchItems); + cmbPattern->setEditText(TQString::null); + cmbPattern->setInsertionPolicy(TQComboBox::NoInsertion); + lPattern->setBuddy(cmbPattern); + cmbPattern->setFocus(); + cmbPattern->setMinimumSize(cmbPattern->sizeHint()); + loPattern->addWidget( cmbPattern ); + + cbCasesensitive = new TQCheckBox(i18n("Case sensitive"), this); + cbCasesensitive->setMinimumWidth(cbCasesensitive->sizeHint().width()); + cbCasesensitive->setChecked(config->readBoolEntry("CaseSensitive", true)); + loPattern->addWidget(cbCasesensitive); + + cbRegex = new TQCheckBox( i18n("Regular expression"), this ); + cbRegex->setMinimumWidth( cbRegex->sizeHint().width() ); + cbRegex->setChecked( config->readBoolEntry( "Regex", true ) ); + loPattern->addWidget( cbRegex ); + loPattern->setStretchFactor( cmbPattern, 100 ); + + TQLabel *lTemplate = new TQLabel(i18n("Template:"), this); + lTemplate->setFixedSize(lTemplate->sizeHint()); + loInput->addWidget(lTemplate, 1, 0, Qt::AlignRight | Qt::AlignVCenter); + + TQBoxLayout *loTemplate = new TQHBoxLayout(4); + loInput->addLayout(loTemplate, 1, 1); + + leTemplate = new KLineEdit(this); + lTemplate->setBuddy(leTemplate); + leTemplate->setText(strTemplate[0]); + leTemplate->setMinimumSize(leTemplate->sizeHint()); + loTemplate->addWidget(leTemplate); + + KComboBox *cmbTemplate = new KComboBox(false, this); + cmbTemplate->insertStrList(template_desc); + cmbTemplate->adjustSize(); + cmbTemplate->setFixedSize(cmbTemplate->size()); + loTemplate->addWidget(cmbTemplate); + + TQLabel *lFiles = new TQLabel(i18n("Files:"), this); + lFiles->setFixedSize(lFiles->sizeHint()); + loInput->addWidget(lFiles, 2, 0, Qt::AlignRight | Qt::AlignVCenter); + + cmbFiles = new KComboBox(true, this); + lFiles->setBuddy(TQT_TQWIDGET(cmbFiles->focusProxy())); + cmbFiles->setMinimumSize(cmbFiles->sizeHint()); + cmbFiles->setInsertionPolicy(TQComboBox::NoInsertion); + cmbFiles->setDuplicatesEnabled(false); + cmbFiles->insertStringList(lastSearchFiles); + loInput->addWidget(cmbFiles, 2, 1); + + TQLabel *lDir = new TQLabel(i18n("Folder:"), this); + lDir->setFixedSize(lDir->sizeHint()); + loInput->addWidget(lDir, 3, 0, Qt::AlignRight | Qt::AlignVCenter); + + TQBoxLayout *loDir = new TQHBoxLayout(3); + loInput->addLayout(loDir, 3, 1); + + KComboBox* cmbUrl = new KComboBox(true, this); + cmbUrl->setMinimumWidth(80); // make sure that 800x600 res works + cmbUrl->setDuplicatesEnabled(false); + cmbUrl->setInsertionPolicy(TQComboBox::NoInsertion); + cmbDir = new KURLRequester( cmbUrl, this, "dir combo" ); + cmbDir->completionObject()->setMode(KURLCompletion::DirCompletion); + cmbDir->comboBox()->insertStringList(lastSearchPaths); + cmbDir->setMode( KFile::Directory|KFile::LocalOnly ); + loDir->addWidget(cmbDir, 1); + lDir->setBuddy(cmbDir); + + cbRecursive = new TQCheckBox(i18n("Recursive"), this); + cbRecursive->setMinimumWidth(cbRecursive->sizeHint().width()); + cbRecursive->setChecked(config->readBoolEntry("Recursive", true)); + loDir->addWidget(cbRecursive); + + KButtonBox *actionbox = new KButtonBox(this, Qt::Vertical); + layout->addWidget(actionbox, 0, 2); + actionbox->addStretch(); + btnSearch = static_cast<KPushButton*>(actionbox->addButton(KGuiItem(i18n("Find"),"find"))); + btnSearch->setDefault(true); + btnClear = static_cast<KPushButton*>(actionbox->addButton( KStdGuiItem::clear() )); + actionbox->addStretch(); + actionbox->layout(); + + lbResult = new TQListBox(this); + TQFontMetrics rb_fm(lbResult->fontMetrics()); + layout->addMultiCellWidget(lbResult, 2, 2, 0, 2); + + layout->activate(); + + TDEAcceleratorManager::manage( this ); + + TQWhatsThis::add(lPattern, + i18n("<p>Enter the expression you want to search for here." + "<p>If 'regular expression' is unchecked, any non-space letters in your " + "expression will be escaped with a backslash character." + "<p>Possible meta characters are:<br>" + "<b>.</b> - Matches any character<br>" + "<b>^</b> - Matches the beginning of a line<br>" + "<b>$</b> - Matches the end of a line<br>" + "<b>\\<</b> - Matches the beginning of a word<br>" + "<b>\\></b> - Matches the end of a word" + "<p>The following repetition operators exist:<br>" + "<b>?</b> - The preceding item is matched at most once<br>" + "<b>*</b> - The preceding item is matched zero or more times<br>" + "<b>+</b> - The preceding item is matched one or more times<br>" + "<b>{<i>n</i>}</b> - The preceding item is matched exactly <i>n</i> times<br>" + "<b>{<i>n</i>,}</b> - The preceding item is matched <i>n</i> or more times<br>" + "<b>{,<i>n</i>}</b> - The preceding item is matched at most <i>n</i> times<br>" + "<b>{<i>n</i>,<i>m</i>}</b> - The preceding item is matched at least <i>n</i>, " + "but at most <i>m</i> times." + "<p>Furthermore, backreferences to bracketed subexpressions are available " + "via the notation <code>\\#</code>." + "<p>See the grep(1) documentation for the full documentation." + )); + TQWhatsThis::add(lFiles, + i18n("Enter the file name pattern of the files to search here.\n" + "You may give several patterns separated by commas.")); + TQWhatsThis::add(lTemplate, + i18n("You can choose a template for the pattern from the combo box\n" + "and edit it here. The string %s in the template is replaced\n" + "by the pattern input field, resulting in the regular expression\n" + "to search for.")); + TQWhatsThis::add(lDir, + i18n("Enter the folder which contains the files in which you want to search.")); + TQWhatsThis::add(cbRecursive, + i18n("Check this box to search in all subfolders.")); + TQWhatsThis::add(cbCasesensitive, + i18n("If this option is enabled (the default), the search will be case sensitive.")); + TQWhatsThis::add( cbRegex, i18n( + "<p>If this is enabled, your pattern will be passed unmodified to " + "<em>grep(1)</em>. Otherwise, all characters that are not letters will be " + "escaped using a backslash character to prevent grep from interpreting " + "them as part of the expression.") ); + TQWhatsThis::add(lbResult, + i18n("The results of the grep run are listed here. Select a\n" + "filename/line number combination and press Enter or doubleclick\n" + "on the item to show the respective line in the editor.")); + + // event filter, do something relevant for RETURN + cmbPattern->installEventFilter( this ); + leTemplate->installEventFilter( this ); + cmbFiles->installEventFilter( this ); + cmbDir->comboBox()->installEventFilter( this ); + + connect( cmbTemplate, TQT_SIGNAL(activated(int)), + TQT_SLOT(templateActivated(int)) ); + connect( lbResult, TQT_SIGNAL(selected(const TQString&)), + TQT_SLOT(itemSelected(const TQString&)) ); + connect( btnSearch, TQT_SIGNAL(clicked()), + TQT_SLOT(slotSearch()) ); + connect( btnClear, TQT_SIGNAL(clicked()), + TQT_SLOT(slotClear()) ); + connect( cmbPattern->lineEdit(), TQT_SIGNAL(textChanged ( const TQString & )), + TQT_SLOT( patternTextChanged( const TQString & ))); + + patternTextChanged( cmbPattern->lineEdit()->text()); +} + + +GrepTool::~GrepTool() +{ + delete childproc; +} + +void GrepTool::patternTextChanged( const TQString & _text) +{ + btnSearch->setEnabled( !_text.isEmpty() ); +} + +void GrepTool::templateActivated(int index) +{ + leTemplate->setText(strTemplate[index]); +} + +void GrepTool::itemSelected(const TQString& item) +{ + int pos; + TQString filename, linenumber; + + TQString str = item; + if ( (pos = str.find(':')) != -1) + { + filename = str.left(pos); + str = str.mid(pos+1); + if ( (pos = str.find(':')) != -1) + { + filename = m_workingDir + TQDir::separator() + filename; + linenumber = str.left(pos); + emit itemSelected(filename,linenumber.toInt()-1); + } + } +} + +void GrepTool::processOutput() +{ + int pos; + while ( (pos = buf.find('\n')) != -1) + { + TQString item = buf.mid(2,pos-2); + if (!item.isEmpty()) + lbResult->insertItem(item); + buf = buf.mid(pos+1); + } + kapp->processEvents(); +} + +void GrepTool::slotSearch() +{ + if ( cmbPattern->currentText().isEmpty() ) + { + cmbPattern->setFocus(); + return; + } + + if ( cmbDir->url().isEmpty() || ! TQDir(cmbDir->url()).exists() ) + { + cmbDir->setFocus(); + KMessageBox::information( this, i18n( + "You must enter an existing local folder in the 'Folder' entry."), + i18n("Invalid Folder"), "Kate grep tool: invalid folder" ); + return; + } + + if ( ! leTemplate->text().contains("%s") ) + { + leTemplate->setFocus(); + return; + } + + if ( childproc && childproc->isRunning() ) + { + childproc->kill(); + return; + } + + slotClear (); + + m_workingDir = cmbDir->url(); + + TQString s = cmbPattern->currentText(); + if ( ! cbRegex->isChecked() ) + s.replace( TQRegExp( "([^\\w'()<>])" ), "\\\\1" ); + TQString pattern = leTemplate->text(); + pattern.replace( "%s", s ); + + childproc = new TDEProcess(); + childproc->setWorkingDirectory( m_workingDir ); + *childproc << "find" << "."; + if (!cbRecursive->isChecked()) + *childproc << "-maxdepth" << "1"; + if (!cmbFiles->currentText().isEmpty() ) + { + TQStringList files = TQStringList::split ( ",", cmbFiles->currentText(), FALSE ); + *childproc << "("; + bool first = true; + for ( TQStringList::Iterator it = files.begin(); it != files.end(); ++it ) + { + if (!first) + *childproc << "-o"; + *childproc << "-name" << (*it); + first = false; + } + *childproc << ")"; + } + *childproc << "-exec" << "grep"; + if (!cbCasesensitive->isChecked()) + *childproc << "-i"; + *childproc << "-n" << "-e" << pattern << "{}"; + *childproc << "/dev/null"; //trick to have grep always display the filename + *childproc << ";"; + + connect( childproc, TQT_SIGNAL(processExited(TDEProcess *)), + TQT_SLOT(childExited()) ); + connect( childproc, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int)), + TQT_SLOT(receivedOutput(TDEProcess *, char *, int)) ); + connect( childproc, TQT_SIGNAL(receivedStderr(TDEProcess *, char *, int)), + TQT_SLOT(receivedErrOutput(TDEProcess *, char *, int)) ); + + // actually it should be checked whether the process was started successfully + lbResult->setCursor( TQCursor(Qt::WaitCursor) ); + btnClear->setEnabled( false ); + btnSearch->setGuiItem( KGuiItem(i18n("Cancel"), "button_cancel")); + childproc->start(TDEProcess::NotifyOnExit, TDEProcess::AllOutput); +} + +void GrepTool::slotSearchFor(const TQString &pattern) +{ + slotClear(); + cmbPattern->setEditText(pattern); + slotSearch(); +} + +void GrepTool::finish() +{ + btnSearch->setEnabled( !cmbPattern->lineEdit()->text().isEmpty() ); + + buf += '\n'; + processOutput(); + delete childproc; + childproc = 0; + + config->setGroup("GrepTool"); + + TQString cmbText = cmbPattern->currentText(); + bool itemsRemoved = lastSearchItems.remove(cmbText) > 0; + lastSearchItems.prepend(cmbText); + if (itemsRemoved) + { + cmbPattern->removeItem(cmbPattern->currentItem()); + } + cmbPattern->insertItem(cmbText, 0); + cmbPattern->setCurrentItem(0); + if (lastSearchItems.count() > 10) { + lastSearchItems.pop_back(); + cmbPattern->removeItem(cmbPattern->count() - 1); + } + config->writeEntry("LastSearchItems", lastSearchItems); + + + cmbText = cmbDir->url(); + itemsRemoved = lastSearchPaths.remove(cmbText) > 0; + lastSearchPaths.prepend(cmbText); + if (itemsRemoved) + { + cmbDir->comboBox()->removeItem(cmbDir->comboBox()->currentItem()); + } + cmbDir->comboBox()->insertItem(cmbText, 0); + cmbDir->comboBox()->setCurrentItem(0); + if (lastSearchPaths.count() > 10) + { + lastSearchPaths.pop_back(); + cmbDir->comboBox()->removeItem(cmbDir->comboBox()->count() - 1); + } + config->writeEntry("LastSearchPaths", lastSearchPaths); + + + cmbText = cmbFiles->currentText(); + itemsRemoved = lastSearchFiles.remove(cmbText) > 0; + lastSearchFiles.prepend(cmbText); + if (itemsRemoved) + { + cmbFiles->removeItem(cmbFiles->currentItem()); + } + cmbFiles->insertItem(cmbText, 0); + cmbFiles->setCurrentItem(0); + if (lastSearchFiles.count() > 10) { + lastSearchFiles.pop_back(); + cmbFiles->removeItem(cmbFiles->count() - 1); + } + config->writeEntry("LastSearchFiles", lastSearchFiles); + + config->writeEntry("Recursive", cbRecursive->isChecked()); + config->writeEntry("CaseSensitive", cbCasesensitive->isChecked()); + config->writeEntry("Regex", cbRegex->isChecked()); +} + +void GrepTool::slotCancel() +{ + finish(); +} + +void GrepTool::childExited() +{ +// int status = childproc->exitStatus(); + lbResult->unsetCursor(); + btnClear->setEnabled( true ); + btnSearch->setGuiItem( KGuiItem(i18n("Find"), "find") ); + + if ( ! errbuf.isEmpty() ) + { + KMessageBox::information( parentWidget(), i18n("<strong>Error:</strong><p>") + errbuf, i18n("Grep Tool Error") ); + errbuf.truncate(0); + } + else + finish(); +} + +void GrepTool::receivedOutput(TDEProcess */*proc*/, char *buffer, int buflen) +{ + buf += TQCString(buffer, buflen+1); + processOutput(); +} + +void GrepTool::receivedErrOutput(TDEProcess */*proc*/, char *buffer, int buflen) +{ + errbuf += TQCString( buffer, buflen + 1 ); +} + +void GrepTool::slotClear() +{ + finish(); + lbResult->clear(); +} + +void GrepTool::updateDirName(const TQString &dir) +{ + if (m_lastUpdatedDir != dir) + { + setDirName (dir); + m_lastUpdatedDir = dir; + } +} + +void GrepTool::setDirName(const TQString &dir){ + cmbDir->setURL(dir); +} + +bool GrepTool::eventFilter( TQObject *o, TQEvent *e ) +{ + if ( e->type() == TQEvent::KeyPress && ( + ((TQKeyEvent*)e)->key() == Qt::Key_Return || + ((TQKeyEvent*)e)->key() == Qt::Key_Enter ) ) + { + slotSearch(); + return true; + } + + return TQWidget::eventFilter( o, e ); +} + +void GrepTool::focusInEvent ( TQFocusEvent * ev ) +{ + TQWidget::focusInEvent(ev); + if (m_fixFocus) { + m_fixFocus = false; + cmbPattern->setFocus(); + } +} + +void GrepTool::showEvent( TQShowEvent * ev ) +{ + TQWidget::showEvent(ev); + m_fixFocus = true; +} + +#include "kategrepdialog.moc" diff --git a/kate/app/kategrepdialog.h b/kate/app/kategrepdialog.h new file mode 100644 index 000000000..a3cbbc871 --- /dev/null +++ b/kate/app/kategrepdialog.h @@ -0,0 +1,97 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _GREPDIALOG_H_ +#define _GREPDIALOG_H_ + +#include <kdialog.h> +#include <tqstringlist.h> + +class TQLineEdit; +class KComboBox; +class TQCheckBox; +class TQListBox; +class KPushButton; +class TQLabel; +class TDEProcess; +class TDEConfig; +class KURLRequester; +class TQEvent; + +class GrepTool : public TQWidget +{ + Q_OBJECT + +public: + GrepTool(TQWidget *parent, const char *name=0); + ~GrepTool(); + + // only updates if the dir you give to it differs from the last one given to it ! + void updateDirName(const TQString &); + + void setDirName(const TQString &); + + +signals: + void itemSelected(const TQString &abs_filename, int line); + +public slots: + void slotSearchFor(const TQString &pattern); + +protected: + bool eventFilter( TQObject *, TQEvent * ); + void focusInEvent ( TQFocusEvent * ); + void showEvent( TQShowEvent * ); + bool m_fixFocus; + +private slots: + void templateActivated(int index); + void childExited(); + void receivedOutput(TDEProcess *proc, char *buffer, int buflen); + void receivedErrOutput(TDEProcess *proc, char *buffer, int buflen); + void itemSelected(const TQString&); + void slotSearch(); + void slotCancel(); + void slotClear(); + void patternTextChanged( const TQString &); +private: + void processOutput(); + void finish(); + + TQLineEdit *leTemplate; + KComboBox *cmbFiles, *cmbPattern; + KURLRequester *cmbDir; + TQCheckBox *cbRecursive; + TQCheckBox *cbCasesensitive, *cbRegex; + TQListBox *lbResult; + KPushButton *btnSearch, *btnClear; + TDEProcess *childproc; + TQString buf; + TQString errbuf; + TDEConfig* config; + TQStringList lastSearchItems; + TQStringList lastSearchPaths; + TQStringList lastSearchFiles; + TQString m_lastUpdatedDir; + TQString m_workingDir; +}; + + +#endif diff --git a/kate/app/katemailfilesdialog.cpp b/kate/app/katemailfilesdialog.cpp new file mode 100644 index 000000000..858caa5f1 --- /dev/null +++ b/kate/app/katemailfilesdialog.cpp @@ -0,0 +1,112 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katemailfilesdialog.h" +#include "katemainwindow.h" +#include "kateviewmanager.h" +#include "katedocmanager.h" + +#include <tdelistview.h> +#include <tdelocale.h> +#include <kurl.h> + +#include <tqevent.h> +#include <tqlabel.h> +#include <tqstringlist.h> +#include <tqvbox.h> + +/* a private check list item, that can store a Kate::Document*. */ +class KateDocCheckItem : public TQCheckListItem { + public: + KateDocCheckItem( TQListView *parent, const TQString& text, Kate::Document *d ) + : TQCheckListItem( parent, text, TQCheckListItem::CheckBox ), mdoc(d) {}; + Kate::Document *doc() { return mdoc; }; + private: + Kate::Document *mdoc; +}; + +/////////////////////////////////////////////////////////////////////////// +// KateMailDialog implementation +/////////////////////////////////////////////////////////////////////////// +KateMailDialog::KateMailDialog( TQWidget *parent, KateMainWindow *mainwin ) + : KDialogBase( parent, "kate mail dialog", true, i18n("Email Files"), + Ok|Cancel|User1, Ok, false, + KGuiItem( i18n("&Show All Documents >>") ) ), + mainWindow( mainwin ) +{ + setButtonGuiItem( KDialogBase::Ok, KGuiItem( i18n("&Mail..."), "mail_send") ); + mw = makeVBoxMainWidget(); + mw->installEventFilter( this ); + + lInfo = new TQLabel( i18n( + "<p>Press <strong>Mail...</strong> to email the current document." + "<p>To select more documents to send, press <strong>Show All Documents >></strong>."), mw ); + // TODO avoid untill needed - later + list = new TDEListView( mw ); + list->addColumn( i18n("Name") ); + list->addColumn( i18n("URL") ); + Kate::Document *currentDoc = mainWindow->viewManager()->activeView()->getDoc(); + uint n = KateDocManager::self()->documents(); + uint i = 0; + TQCheckListItem *item; + while ( i < n ) { + Kate::Document *doc = KateDocManager::self()->document( i ); + if ( doc ) { + item = new KateDocCheckItem( list, doc->docName(), doc ); + item->setText( 1, doc->url().prettyURL() ); + if ( doc == currentDoc ) { + item->setOn( true ); + item->setSelected( true ); + } + } + i++; + } + list->hide(); + connect( this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(slotShowButton()) ); + mw->setMinimumSize( lInfo->sizeHint() ); +} + +TQPtrList<Kate::Document> KateMailDialog::selectedDocs() +{ + TQPtrList<Kate::Document> l; + TQListViewItem *item = list->firstChild(); + while ( item ) { + if ( ((KateDocCheckItem*)item)->isOn() ) + l.append( ((KateDocCheckItem*)item)->doc() ); + item = item->nextSibling(); + } + return l; +} + +void KateMailDialog::slotShowButton() +{ + if ( list->isVisible() ) { + setButtonText( User1, i18n("&Show All Documents >>") ); + list->hide(); + } + else { + list->show(); + setButtonText( User1, i18n("&Hide Document List <<") ); + lInfo->setText( i18n("Press <strong>Mail...</strong> to send selected documents") ); + + } + mw->setMinimumSize( TQSize( lInfo->sizeHint().width(), mw->sizeHint().height()) ); + setMinimumSize( calculateSize( mw->minimumSize().width(), mw->sizeHint().height() ) ); + resize( width(), minimumHeight() ); +} +#include "katemailfilesdialog.moc" diff --git a/kate/app/katemailfilesdialog.h b/kate/app/katemailfilesdialog.h new file mode 100644 index 000000000..a2de4e504 --- /dev/null +++ b/kate/app/katemailfilesdialog.h @@ -0,0 +1,59 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KATE_MAILFILES_DIALOG_H_ +#define _KATE_MAILFILES_DIALOG_H_ + +#include <kate/document.h> + +#include <kdialogbase.h> +#include <kurl.h> +#include <tqptrlist.h> + +class TQString; +class TQStringList; +class KateMainWindow; + +/** + This is a dialog for choosing which of the open files to mail. + The current file is selected by default, the dialog can be expanded + to display all the files if required. + +*/ +class KateMailDialog : public KDialogBase { + Q_OBJECT + public: + KateMailDialog( TQWidget *parent=0, + KateMainWindow *mainwin=0 ); + ~KateMailDialog() {}; + + /** + @return a list of the selected docs. + */ + TQPtrList<Kate::Document> selectedDocs(); + private slots: + void slotShowButton(); + private: + class TDEListView *list; + class TQLabel *lInfo; + KateMainWindow *mainWindow; + class TQVBox *mw; + +}; + +#endif // _KATE_MAILFILES_DIALOG_H_ diff --git a/kate/app/katemain.cpp b/kate/app/katemain.cpp new file mode 100644 index 000000000..7b9903d5e --- /dev/null +++ b/kate/app/katemain.cpp @@ -0,0 +1,267 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateapp.h" + +#include <kstandarddirs.h> +#include <tdelocale.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> +#include <tdeglobal.h> +#include <tdeconfig.h> +#include <kinstance.h> +#include <tdestartupinfo.h> +#include <dcopclient.h> +#include <dcopref.h> +#include <kdebug.h> + +#include <tqtextcodec.h> + +#include <stdlib.h> + +static TDECmdLineOptions options[] = +{ + { "s", 0 , 0 }, + { "start <name>", I18N_NOOP("Start Kate with a given session"), 0 }, + { "u", 0, 0 }, + { "use", I18N_NOOP("Use a already running kate instance (if possible)"), 0 }, + { "f", 0, 0 }, + { "force-sdi", I18N_NOOP("Force single document mode if the MDI setting is enabled."), 0 }, + { "p", 0, 0 }, + { "pid <pid>", I18N_NOOP("Only try to reuse kate instance with this pid"), 0 }, + { "e", 0, 0 }, + { "encoding <name>", I18N_NOOP("Set encoding for the file to open"), 0 }, + { "l", 0, 0 }, + { "line <line>", I18N_NOOP("Navigate to this line"), 0 }, + { "c", 0, 0 }, + { "column <column>", I18N_NOOP("Navigate to this column"), 0 }, + { "i", 0, 0 }, + { "stdin", I18N_NOOP("Read the contents of stdin"), 0 }, + { "+[URL]", I18N_NOOP("Document to open"), 0 }, + TDECmdLineLastOption +}; + +extern "C" KDE_EXPORT int kdemain( int argc, char **argv ) +{ + TDEConfig * config = NULL; + bool alwaysUseInstance; + // here we go, construct the Kate version + TQString kateVersion = KateApp::kateVersion(); + + TDEAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(), + I18N_NOOP( "Kate - Advanced Text Editor" ), TDEAboutData::License_LGPL_V2, + I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org"); + + aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de"); + aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk"); + aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371"); + aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org"); + aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" ); + aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org"); + aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com"); + aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at"); + aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz"); + aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" ); + aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org"); + aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" ); + aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" ); + aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com"); + aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net"); + aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org"); + aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de"); + + aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it"); + aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu"); + aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),""); + aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),""); + aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),""); + aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),""); + aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),""); + aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),""); + aboutData.addCredit ("Daniel Naber","",""); + aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),""); + aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),""); + aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), ""); + aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"",""); + + aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails")); + + TDEInstance instance( &aboutData ); + + // command line args init and co + TDECmdLineArgs::init (argc, argv, &aboutData); + TDECmdLineArgs::addCmdLineOptions (options); + TDECmdLineArgs::addTempFileOption(); + KateApp::addCmdLineOptions (); + + // get our command line args ;) + TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs(); + + config = TDEGlobal::config(); + config->setGroup("General"); + alwaysUseInstance = config->readBoolEntry("UseInstance"); + +// now, first try to contact running kate instance if needed + if ( ((args->isSet("use") || alwaysUseInstance) && + !(args->isSet("force-sdi"))) || (::getenv("KATE_PID")!=0) ) + { + DCOPClient client; + client.attach (); + + // get all attached clients ;) + QCStringList allClients = client.registeredApplications(); + + // search for a kate app client, use the first found + TQCString kateApp; + + if ( args->isSet("start") ) + { + for (unsigned int i=0; i < allClients.count(); i++) + { + if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") + { + DCOPRef ref( allClients[i], "KateApplication" ); + TQString s = ref.call( "session" ); + if ( TQString(args->getOption("start")) == s ) + { + kateApp = allClients[i]; + break; + } + } + } + } + else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) ) + { + TQCString tryApp; + if ( args->isSet("pid") ) + tryApp = args->getOption("pid"); + else + tryApp = ::getenv("KATE_PID"); + + if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) ) + kateApp = tryApp; + } + else + { + for (unsigned int i=0; i < allClients.count(); ++i) + { + if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") + { + kateApp = allClients[i]; + break; + } + } + } + + // found a matching kate client ;) + if (!kateApp.isEmpty()) + { + kdDebug () << "kate app: " << kateApp << endl; + // make tdeinit happy + client.registerAs( "kate" ); + + DCOPRef kRef (kateApp, "KateApplication"); + + if (args->isSet ("start")) + kRef.call( "activateSession", TQString (args->getOption("start")) ); + + TQString enc = args->isSet("encoding") ? args->getOption("encoding") : TQCString(""); + + bool tempfileSet = TDECmdLineArgs::isTempFileSet(); + + for (int z=0; z<args->count(); z++) + kRef.call( "openURL", args->url(z), enc, tempfileSet ); + + if( args->isSet( "stdin" ) ) + { + TQTextIStream input(stdin); + + // set chosen codec + TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0; + + if (codec) + input.setCodec (codec); + + TQString line; + TQString text; + + do + { + line = input.readLine(); + text.append( line + "\n" ); + } while( !line.isNull() ); + + kRef.call( "openInput", text ); + } + + int line = 0; + int column = 0; + bool nav = false; + + if (args->isSet ("line")) + { + line = args->getOption ("line").toInt(); + nav = true; + } + + if (args->isSet ("column")) + { + column = args->getOption ("column").toInt(); + nav = true; + } + + if (nav) + kRef.call( "setCursor", line, column ); + + // since the user tried to open a document, let us assume [s]he + // wants to see that document. + // ### what to do about the infamous focus stealing prevention? + uint mwn = kRef.call("activeMainWindowNumber"); + TQCString smwn; + DCOPRef wRef( kateApp, TQCString( "__KateMainWindow#") + smwn.setNum(mwn) ); + if ( wRef.call("minimized") ) + { + if ( wRef.call( "maximized" ) ) + wRef.call( "maximize" ); + else + wRef.call("restore"); + } + wRef.call( "setActiveWindowFocused" ); + + // stop startup notification + TDEStartupInfo::appStarted( ); + + return 0; + } + } + + // construct the real kate app object ;) + KateApp app (args); + + // app execution should already end :) + if (app.shouldExit()) + { + return 0; + } + + // execute ourself ;) + return app.exec(); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katemain.h b/kate/app/katemain.h new file mode 100644 index 000000000..374b834cc --- /dev/null +++ b/kate/app/katemain.h @@ -0,0 +1,70 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_MAIN_H__ +#define __KATE_MAIN_H__ + +#include <config.h> + +class TQComboBox; +class TQDateTime; +class TQEvent; +class TQFileInfo; +class TQGridLayout; +class TQLabel; +class TQListBox; +class TQObject; +class TQPixmap; +class TQVBoxLayout; +class TQString; +class TQWidgetStack; + +class TDEAction; +class TDEActionMenu; +class TDEConfig; +class KDirOperator; +class KEditToolbar; +class KFileViewItem; +class KHistoryCombo; +class KLineEdit; +class TDEListBox; +class TDEProcess; +class KPushButton; +class TDERecentFilesAction; +class TDESelectAction; +class KStatusBar; +class TDEToggleAction; +class KURL; +class KURLComboBox; + +class KateApp; +class KateConfigDlg; +class KateConsole; +class KateDocManager; +class KateFileList; +class KateFileSelector; +class KateMainWindow; +class KatePluginIface; +class KatePluginManager; +class KateSidebar; +class KateViewManager; +class KateViewSpace; + +#endif diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp new file mode 100644 index 000000000..4cd3c358e --- /dev/null +++ b/kate/app/katemainwindow.cpp @@ -0,0 +1,860 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "katemainwindow.h" +#include "katemainwindow.moc" + +#include "kateconfigdialog.h" +#include "kateconsole.h" +#include "katedocmanager.h" +#include "katepluginmanager.h" +#include "kateconfigplugindialogpage.h" +#include "kateviewmanager.h" +#include "kateapp.h" +#include "katefileselector.h" +#include "katefilelist.h" +#include "kategrepdialog.h" +#include "katemailfilesdialog.h" +#include "katemainwindowiface.h" +#include "kateexternaltools.h" +#include "katesavemodifieddialog.h" +#include "katemwmodonhddialog.h" +#include "katesession.h" +#include "katetabwidget.h" + +#include "../interfaces/mainwindow.h" +#include "../interfaces/toolviewmanager.h" + +#include <dcopclient.h> +#include <kinstance.h> +#include <tdeaboutdata.h> +#include <tdeaction.h> +#include <tdecmdlineargs.h> +#include <kdebug.h> +#include <kdialogbase.h> +#include <tdediroperator.h> +#include <kdockwidget.h> +#include <kedittoolbar.h> +#include <tdefiledialog.h> +#include <kglobalaccel.h> +#include <tdeglobal.h> +#include <tdeglobalsettings.h> +#include <kiconloader.h> +#include <kkeydialog.h> +#include <tdelocale.h> +#include <tdemessagebox.h> +#include <kmimetype.h> +#include <kopenwith.h> +#include <tdepopupmenu.h> +#include <ksimpleconfig.h> +#include <kstatusbar.h> +#include <kstdaction.h> +#include <kstandarddirs.h> +#include <ktrader.h> +#include <kuniqueapplication.h> +#include <kurldrag.h> +#include <kdesktopfile.h> +#include <khelpmenu.h> +#include <tdemultitabbar.h> +#include <ktip.h> +#include <tdemenubar.h> +#include <kstringhandler.h> +#include <tqlayout.h> +#include <tqptrvector.h> + +#include <assert.h> +#include <unistd.h> +//END + +uint KateMainWindow::uniqueID = 1; + +KateMainWindow::KateMainWindow (TDEConfig *sconfig, const TQString &sgroup) + : KateMDI::MainWindow (0,(TQString(TQString("__KateMainWindow#%1").arg(uniqueID))).latin1()) +{ + // first the very important id + myID = uniqueID; + uniqueID++; + + m_modignore = false; + + console = 0; + greptool = 0; + + // here we go, set some usable default sizes + if (!initialGeometrySet()) + { + int scnum = TQApplication::desktop()->screenNumber(parentWidget()); + TQRect desk = TQApplication::desktop()->screenGeometry(scnum); + + TQSize size; + + // try to load size + if (sconfig) + { + sconfig->setGroup (sgroup); + size.setWidth (sconfig->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 )); + size.setHeight (sconfig->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 )); + } + + // if thats fails, try to reuse size + if (size.isEmpty()) + { + // first try to reuse size known from current or last created main window ;=) + if (KateApp::self()->mainWindows () > 0) + { + KateMainWindow *win = KateApp::self()->activeMainWindow (); + + if (!win) + win = KateApp::self()->mainWindow (KateApp::self()->mainWindows ()-1); + + size = win->size(); + } + else // now fallback to hard defaults ;) + { + // first try global app config + KateApp::self()->config()->setGroup ("MainWindow"); + size.setWidth (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 )); + size.setHeight (KateApp::self()->config()->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 )); + + if (size.isEmpty()) + size = TQSize (kMin (700, desk.width()), kMin(480, desk.height())); + } + + resize (size); + } + } + + // start session restore if needed + startRestore (sconfig, sgroup); + + m_mainWindow = new Kate::MainWindow (this); + m_toolViewManager = new Kate::ToolViewManager (this); + + m_dcop = new KateMainWindowDCOPIface (this); + + // setup the most important widgets + setupMainWindow(); + + // setup the actions + setupActions(); + + setStandardToolBarMenuEnabled( true ); + setXMLFile( "kateui.rc" ); + createShellGUI ( true ); + + KatePluginManager::self()->enableAllPluginsGUI (this); + + if ( KateApp::self()->authorize("shell_access") ) + Kate::Document::registerCommand(KateExternalToolsCommand::self()); + + // connect documents menu aboutToshow + documentMenu = (TQPopupMenu*)factory()->container("documents", this); + connect(documentMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(documentMenuAboutToShow())); + + // caption update + for (uint i = 0; i < KateDocManager::self()->documents(); i++) + slotDocumentCreated (KateDocManager::self()->document(i)); + + connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),this,TQT_SLOT(slotDocumentCreated(Kate::Document *))); + + readOptions(); + + if (sconfig) + m_viewManager->restoreViewConfiguration (sconfig, sgroup); + + finishRestore (); + + setAcceptDrops(true); +} + +KateMainWindow::~KateMainWindow() +{ + // first, save our fallback window size ;) + KateApp::self()->config()->setGroup ("MainWindow"); + saveWindowSize (KateApp::self()->config()); + + // save other options ;=) + saveOptions(); + + KateApp::self()->removeMainWindow (this); + + KatePluginManager::self()->disableAllPluginsGUI (this); + + delete m_dcop; +} + +void KateMainWindow::setupMainWindow () +{ + setToolViewStyle( KMultiTabBar::KDEV3ICON ); + + m_tabWidget = new KateTabWidget (centralWidget()); + + m_viewManager = new KateViewManager (this); + + KateMDI::ToolView *ft = createToolView("kate_filelist", KMultiTabBar::Left, SmallIcon("tdemultiple"), i18n("Documents")); + filelist = new KateFileList (this, m_viewManager, ft, "filelist"); + filelist->readConfig(KateApp::self()->config(), "Filelist"); + + KateMDI::ToolView *t = createToolView("kate_fileselector", KMultiTabBar::Left, SmallIcon("fileopen"), i18n("Filesystem Browser")); + fileselector = new KateFileSelector( this, m_viewManager, t, "operator"); + connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*))); + + // ONLY ALLOW SHELL ACCESS IF ALLOWED ;) + if (KateApp::self()->authorize("shell_access")) + { + t = createToolView("kate_greptool", KMultiTabBar::Bottom, SmallIcon("filefind"), i18n("Find in Files") ); + greptool = new GrepTool( t, "greptool" ); + connect(greptool, TQT_SIGNAL(itemSelected(const TQString &,int)), this, TQT_SLOT(slotGrepToolItemSelected(const TQString &,int))); + connect(t,TQT_SIGNAL(visibleChanged(bool)),this, TQT_SLOT(updateGrepDir (bool))); + // WARNING HACK - anders: showing the greptool seems to make the menu accels work + greptool->show(); + + t = createToolView("kate_console", KMultiTabBar::Bottom, SmallIcon("konsole"), i18n("Terminal")); + console = new KateConsole (this, t); + } + + // make per default the filelist visible, if we are in session restore, katemdi will skip this ;) + showToolView (ft); +} + +void KateMainWindow::setupActions() +{ + TDEAction *a; + + KStdAction::openNew( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentNew() ), actionCollection(), "file_new" )->setWhatsThis(i18n("Create a new document")); + KStdAction::open( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Open an existing document for editing")); + + fileOpenRecent = KStdAction::openRecent (TQT_TQOBJECT(m_viewManager), TQT_SLOT(openURL (const KURL&)), actionCollection()); + fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again.")); + + a=new TDEAction( i18n("Save A&ll"),"save_all", CTRL+Key_L, KateDocManager::self(), TQT_SLOT( saveAll() ), actionCollection(), "file_save_all" ); + a->setWhatsThis(i18n("Save all open, modified documents to disk.")); + + KStdAction::close( TQT_TQOBJECT(m_viewManager), TQT_SLOT( slotDocumentClose() ), actionCollection(), "file_close" )->setWhatsThis(i18n("Close the current document.")); + + a=new TDEAction( i18n( "Clos&e All" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotDocumentCloseAll() ), actionCollection(), "file_close_all" ); + a->setWhatsThis(i18n("Close all open documents.")); + + KStdAction::mail( TQT_TQOBJECT(this), TQT_SLOT(slotMail()), actionCollection() )->setWhatsThis(i18n("Send one or more of the open documents as email attachments.")); + + KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( slotFileQuit() ), actionCollection(), "file_quit" )->setWhatsThis(i18n("Close this window")); + + a=new TDEAction(i18n("&New Window"), "window_new", 0, TQT_TQOBJECT(this), TQT_SLOT(newWindow()), actionCollection(), "view_new_view"); + a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list).")); + + if ( KateApp::self()->authorize("shell_access") ) + { + externalTools = new KateExternalToolsMenuAction( i18n("External Tools"), actionCollection(), "tools_external", this ); + externalTools->setWhatsThis( i18n("Launch external helper applications") ); + } + + TDEToggleAction* showFullScreenAction = KStdAction::fullScreen( 0, 0, actionCollection(),this); + connect( showFullScreenAction,TQT_SIGNAL(toggled(bool)), this,TQT_SLOT(slotFullScreen(bool))); + + documentOpenWith = new TDEActionMenu(i18n("Open W&ith"), actionCollection(), "file_open_with"); + documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice.")); + connect(documentOpenWith->popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(mSlotFixOpenWithMenu())); + connect(documentOpenWith->popupMenu(), TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotOpenWithMenuAction(int))); + + a=KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(editKeys()), actionCollection()); + a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments.")); + + a=KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotEditToolbars()), actionCollection()); + a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s).")); + + TDEAction* settingsConfigure = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), actionCollection(), "settings_configure"); + settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component.")); + + // pipe to terminal action + if (KateApp::self()->authorize("shell_access")) + new TDEAction(i18n("&Pipe to Console"), "pipe", 0, TQT_TQOBJECT(console), TQT_SLOT(slotPipeToConsole()), actionCollection(), "tools_pipe_to_terminal"); + + // tip of the day :-) + KStdAction::tipOfDay( TQT_TQOBJECT(this), TQT_SLOT( tipOfTheDay() ), actionCollection() )->setWhatsThis(i18n("This shows useful tips on the use of this application.")); + + if (KatePluginManager::self()->pluginList().count() > 0) + { + a=new TDEAction(i18n("&Plugins Handbook"), 0, TQT_TQOBJECT(this), TQT_SLOT(pluginHelp()), actionCollection(), "help_plugins_contents"); + a->setWhatsThis(i18n("This shows help files for various available plugins.")); + } + + connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotWindowActivated())); + connect(m_viewManager,TQT_SIGNAL(viewChanged()),TQT_TQOBJECT(this),TQT_SLOT(slotUpdateOpenWith())); + + slotWindowActivated (); + + // session actions + new TDEAction(i18n("Menu entry Session->New", "&New"), "filenew", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); + new TDEAction(i18n("&Open..."), "fileopen", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); + new TDEAction(i18n("&Save"), "filesave", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); + new TDEAction(i18n("Save &As..."), "filesaveas", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); + new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage"); + + // quick open menu ;) + new KateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); +} + +KateTabWidget *KateMainWindow::tabWidget () +{ + return m_tabWidget; +} + +void KateMainWindow::slotDocumentCloseAll() { + if (queryClose_internal()) + KateDocManager::self()->closeAllDocuments(false); +} + +bool KateMainWindow::queryClose_internal() { + uint documentCount=KateDocManager::self()->documents(); + + if ( ! showModOnDiskPrompt() ) + return false; + + TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList(); + bool shutdown=(modifiedDocuments.count()==0); + + if (!shutdown) { + shutdown=KateSaveModifiedDialog::queryClose(this,modifiedDocuments); + } + + if ( KateDocManager::self()->documents() > documentCount ) { + KMessageBox::information (this, + i18n ("New file opened while trying to close Kate, closing aborted."), + i18n ("Closing Aborted")); + shutdown=false; + } + + return shutdown; +} + +/** + * queryClose(), take care that after the last mainwindow the stuff is closed + */ +bool KateMainWindow::queryClose() +{ + // session saving, can we close all views ? + // just test, not close them actually + if (KateApp::self()->sessionSaving()) + { + return queryClose_internal (); + } + + // normal closing of window + // allow to close all windows until the last without restrictions + if ( KateApp::self()->mainWindows () > 1 ) + return true; + + // last one: check if we can close all documents, try run + // and save docs if we really close down ! + if ( queryClose_internal () ) + { + KateApp::self()->sessionManager()->saveActiveSession(true, true); + + // detach the dcopClient + KateApp::self()->dcopClient()->detach(); + + return true; + } + + return false; +} + +void KateMainWindow::newWindow () +{ + KateApp::self()->newMainWindow (); +} + +void KateMainWindow::slotEditToolbars() +{ + saveMainWindowSettings( KateApp::self()->config(), "MainWindow" ); + KEditToolbar dlg( factory() ); + connect( &dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) ); + dlg.exec(); +} + +void KateMainWindow::slotNewToolbarConfig() +{ + applyMainWindowSettings( KateApp::self()->config(), "MainWindow" ); +} + +void KateMainWindow::slotFileQuit() +{ + KateApp::self()->shutdownKate (this); +} + +void KateMainWindow::readOptions () +{ + TDEConfig *config = KateApp::self()->config (); + + config->setGroup("General"); + syncKonsole = config->readBoolEntry("Sync Konsole", true); + useInstance = config->readBoolEntry("UseInstance", false); + modNotification = config->readBoolEntry("Modified Notification", false); + KateDocManager::self()->setSaveMetaInfos(config->readBoolEntry("Save Meta Infos", true)); + KateDocManager::self()->setDaysMetaInfos(config->readNumEntry("Days Meta Infos", 30)); + + m_viewManager->setShowFullPath(config->readBoolEntry("Show Full Path in Title", false)); + + fileOpenRecent->setMaxItems( config->readNumEntry("Number of recent files", fileOpenRecent->maxItems() ) ); + fileOpenRecent->loadEntries(config, "Recent Files"); + + fileselector->readConfig(config, "fileselector"); +} + +void KateMainWindow::saveOptions () +{ + TDEConfig *config = KateApp::self()->config (); + config->setGroup("General"); + + if (console) + config->writeEntry("Show Console", console->isVisible()); + else + config->writeEntry("Show Console", false); + + config->writeEntry("Save Meta Infos", KateDocManager::self()->getSaveMetaInfos()); + config->writeEntry("Days Meta Infos", KateDocManager::self()->getDaysMetaInfos()); + config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath()); + config->writeEntry("Sync Konsole", syncKonsole); + config->writeEntry("UseInstance", useInstance); + + fileOpenRecent->saveEntries(config, "Recent Files"); + fileselector->writeConfig(config, "fileselector"); + filelist->writeConfig(config, "Filelist"); + + config->sync(); +} + +void KateMainWindow::slotWindowActivated () +{ + if (m_viewManager->activeView()) + { + if (console && syncKonsole) + { + static TQString path; + TQString newPath = m_viewManager->activeView()->getDoc()->url().directory(); + + if ( newPath != path ) + { + path = newPath; + console->cd (KURL( path )); + } + } + + updateCaption (m_viewManager->activeView()->getDoc()); + } + + // update proxy + centralWidget()->setFocusProxy (m_viewManager->activeView()); +} + +void KateMainWindow::slotUpdateOpenWith() +{ + if (m_viewManager->activeView()) + documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty()); + else + documentOpenWith->setEnabled(false); +} + +void KateMainWindow::documentMenuAboutToShow() +{ + // remove documents + while (documentMenu->count() > 3) + documentMenu->removeItemAt (3); + + TQListViewItem * item = filelist->firstChild(); + while( item ) { + // would it be saner to use the screen width as a limit that some random number?? + TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ); + Kate::Document* doc = ((KateFileListItem *)item)->document(); + documentMenu->insertItem ( + doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name, + m_viewManager, TQT_SLOT (activateView (int)), 0, + ((KateFileListItem *)item)->documentNumber () ); + + item = item->nextSibling(); + } + if (m_viewManager->activeView()) + documentMenu->setItemChecked ( m_viewManager->activeView()->getDoc()->documentNumber(), true); +} + +void KateMainWindow::slotGrepToolItemSelected(const TQString &filename,int linenumber) +{ + KURL fileURL; + fileURL.setPath( filename ); + m_viewManager->openURL( fileURL ); + if ( m_viewManager->activeView() == 0 ) return; + m_viewManager->activeView()->gotoLineNumber( linenumber ); + raise(); + setActiveWindow(); +} + +void KateMainWindow::dragEnterEvent( TQDragEnterEvent *event ) +{ + event->accept(KURLDrag::canDecode(event)); +} + +void KateMainWindow::dropEvent( TQDropEvent *event ) +{ + slotDropEvent(event); +} + +void KateMainWindow::slotDropEvent( TQDropEvent * event ) +{ + KURL::List textlist; + if (!KURLDrag::decode(event, textlist)) return; + + for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i) + { + m_viewManager->openURL (*i); + } +} + +void KateMainWindow::editKeys() +{ + KKeyDialog dlg ( false, this ); + + TQPtrList<KXMLGUIClient> clients = guiFactory()->clients(); + + for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it ) + dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() ); + + dlg.insert( externalTools->actionCollection(), i18n("External Tools") ); + + dlg.configure(); + + TQPtrList<Kate::Document> l=KateDocManager::self()->documentList(); + for (uint i=0;i<l.count();i++) { +// kdDebug(13001)<<"reloading Keysettings for document "<<i<<endl; + l.at(i)->reloadXML(); + TQPtrList<class KTextEditor::View> l1=l.at(i)->views ();//KTextEditor::Document + for (uint i1=0;i1<l1.count();i1++) { + l1.at(i1)->reloadXML(); +// kdDebug(13001)<<"reloading Keysettings for view "<<i<<"/"<<i1<<endl; + } + } + + externalTools->actionCollection()->writeShortcutSettings( "Shortcuts", new TDEConfig("externaltools", false, false, "appdata") ); +} + +void KateMainWindow::openURL (const TQString &name) +{ + m_viewManager->openURL (KURL(name)); +} + +void KateMainWindow::slotConfigure() +{ + if (!m_viewManager->activeView()) + return; + + KateConfigDialog* dlg = new KateConfigDialog (this, m_viewManager->activeView()); + dlg->exec(); + + delete dlg; +} + +KURL KateMainWindow::activeDocumentUrl() +{ + // anders: i make this one safe, as it may be called during + // startup (by the file selector) + Kate::View *v = m_viewManager->activeView(); + if ( v ) + return v->getDoc()->url(); + return KURL(); +} + +void KateMainWindow::fileSelected(const KFileItem * /*file*/) +{ + const KFileItemList *list=fileselector->dirOperator()->selectedItems(); + KFileItem *tmp; + for (KFileItemListIterator it(*list); (tmp = it.current()); ++it) + { + m_viewManager->openURL(tmp->url()); + fileselector->dirOperator()->view()->setSelected(tmp,false); + } +} + +// TODO make this work +void KateMainWindow::mSlotFixOpenWithMenu() +{ + //kdDebug(13001)<<"13000"<<"fixing open with menu"<<endl; + documentOpenWith->popupMenu()->clear(); + // get a list of appropriate services. + KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); + //kdDebug(13001)<<"13000"<<"url: "<<m_viewManager->activeView()->getDoc()->url().prettyURL()<<"mime type: "<<mime->name()<<endl; + // some checking goes here... + TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), "Type == 'Application'"); + // for each one, insert a menu item... + for(TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it) { + if ((*it)->name() == "Kate") continue; + documentOpenWith->popupMenu()->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() ); + } + // append "Other..." to call the TDE "open with" dialog. + documentOpenWith->popupMenu()->insertItem(i18n("&Other...")); +} + +void KateMainWindow::slotOpenWithMenuAction(int idx) +{ + KURL::List list; + list.append( m_viewManager->activeView()->getDoc()->url() ); + TQString appname = documentOpenWith->popupMenu()->text(idx); + + appname = appname.remove('&'); //Remove a possible accelerator ... otherwise the application might not get found. + if ( appname.compare(i18n("Other...")) == 0 ) { + // display "open with" dialog + KOpenWithDlg dlg(list); + if (dlg.exec()) + KRun::run(*dlg.service(), list); + return; + } + + TQString qry = TQString("((Type == 'Application') and (Name == '%1'))").arg( appname.latin1() ); + KMimeType::Ptr mime = KMimeType::findByURL( m_viewManager->activeView()->getDoc()->url() ); + TDETrader::OfferList offers = TDETrader::self()->query(mime->name(), qry); + + if (!offers.isEmpty()) { + KService::Ptr app = offers.first(); + KRun::run(*app, list); + } + else + KMessageBox::error(this, i18n("Application '%1' not found!").arg(appname.latin1()), i18n("Application Not Found!")); +} + +void KateMainWindow::pluginHelp() +{ + KateApp::self()->invokeHelp (TQString::null, "kate-plugins"); +} + +void KateMainWindow::slotMail() +{ + KateMailDialog *d = new KateMailDialog(this, this); + if ( ! d->exec() ) + { + delete d; + return; + } + TQPtrList<Kate::Document> attDocs = d->selectedDocs(); + delete d; + // Check that all selected files are saved (or shouldn't be) + TQStringList urls; // to atthatch + Kate::Document *doc; + TQPtrListIterator<Kate::Document> it(attDocs); + for ( ; it.current(); ++it ) { + doc = it.current(); + if (!doc) continue; + if ( doc->url().isEmpty() ) { + // unsaved document. back out unless it gets saved + int r = KMessageBox::questionYesNo( this, + i18n("<p>The current document has not been saved, and " + "cannot be attached to an email message." + "<p>Do you want to save it and proceed?"), + i18n("Cannot Send Unsaved File"),KStdGuiItem::saveAs(),KStdGuiItem::cancel() ); + if ( r == KMessageBox::Yes ) { + Kate::View *v = (Kate::View*)doc->views().first(); + int sr = v->saveAs(); + if ( sr == Kate::View::SAVE_OK ) { ; + } + else { + if ( sr != Kate::View::SAVE_CANCEL ) // ERROR or RETRY(?) + KMessageBox::sorry( this, i18n("The file could not be saved. Please check " + "if you have write permission.") ); + continue; + } + } + else + continue; + } + if ( doc->isModified() ) { + // warn that document is modified and offer to save it before proceeding. + int r = KMessageBox::warningYesNoCancel( this, + i18n("<p>The current file:<br><strong>%1</strong><br>has been " + "modified. Modifications will not be available in the attachment." + "<p>Do you want to save it before sending it?").arg(doc->url().prettyURL()), + i18n("Save Before Sending?"), KStdGuiItem::save(), i18n("Do Not Save") ); + switch ( r ) { + case KMessageBox::Cancel: + continue; + case KMessageBox::Yes: + doc->save(); + if ( doc->isModified() ) { // read-only docs ends here, if modified. Hmm. + KMessageBox::sorry( this, i18n("The file could not be saved. Please check " + "if you have write permission.") ); + continue; + } + break; + default: + break; + } + } + // finally call the mailer + urls << doc->url().url(); + } // check selected docs done + if ( ! urls.count() ) + return; + KateApp::self()->invokeMailer( TQString::null, // to + TQString::null, // cc + TQString::null, // bcc + TQString::null, // subject + TQString::null, // body + TQString::null, // msgfile + urls // urls to atthatch + ); +} +void KateMainWindow::tipOfTheDay() +{ + KTipDialog::showTip( /*0*/this, TQString::null, true ); +} + +void KateMainWindow::slotFullScreen(bool t) +{ + if (t) + showFullScreen(); + else + showNormal(); +} + +void KateMainWindow::updateGrepDir (bool visible) +{ + // grepdlg gets hidden + if (!visible) + return; + + if ( m_viewManager->activeView() ) + { + if ( m_viewManager->activeView()->getDoc()->url().isLocalFile() ) + { + greptool->updateDirName( m_viewManager->activeView()->getDoc()->url().directory() ); + } + } +} + +bool KateMainWindow::event( TQEvent *e ) +{ + uint type = e->type(); + if ( type == TQEvent::WindowActivate && modNotification ) + { + showModOnDiskPrompt(); + } + return KateMDI::MainWindow::event( e ); +} + +bool KateMainWindow::showModOnDiskPrompt() +{ + Kate::Document *doc; + + DocVector list( KateDocManager::self()->documents() ); + uint cnt = 0; + for( doc = KateDocManager::self()->firstDocument(); doc; doc = KateDocManager::self()->nextDocument() ) + { + if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDisc ) + { + list.insert( cnt, doc ); + cnt++; + } + } + + if ( cnt && !m_modignore ) + { + list.resize( cnt ); + KateMwModOnHdDialog mhdlg( list, this ); + m_modignore = true; + bool res = mhdlg.exec(); + m_modignore = false; + + return res; + } + return true; +} + +void KateMainWindow::slotDocumentCreated (Kate::Document *doc) +{ + connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(updateCaption(Kate::Document *))); + connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *))); + connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotUpdateOpenWith())); + + updateCaption (doc); +} + +void KateMainWindow::slotNameChanged(Kate::Document *doc) +{ + updateCaption(doc); + if (!doc->url().isEmpty()) + fileOpenRecent->addURL(doc->url()); +} + +void KateMainWindow::updateCaption (Kate::Document *doc) +{ + if (!m_viewManager->activeView()) + { + setCaption ("", false); + return; + } + + if (!(m_viewManager->activeView()->getDoc() == doc)) + return; + + TQString c; + if (m_viewManager->activeView()->getDoc()->url().isEmpty() || (!m_viewManager->getShowFullPath())) + { + c = m_viewManager->activeView()->getDoc()->docName(); + } + else + { + c = m_viewManager->activeView()->getDoc()->url().prettyURL(); + } + + TQString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName(); + if ( !sessName.isEmpty() ) + sessName = TQString("%1: ").arg( sessName ); + + setCaption( sessName + KStringHandler::lsqueeze(c,64), + m_viewManager->activeView()->getDoc()->isModified()); +} + +void KateMainWindow::saveProperties(TDEConfig *config) +{ + TQString grp=config->group(); + + saveSession(config, grp); + m_viewManager->saveViewConfiguration (config, grp); + + config->setGroup(grp); +} + +void KateMainWindow::readProperties(TDEConfig *config) +{ + TQString grp=config->group(); + + startRestore(config, grp); + finishRestore (); + m_viewManager->restoreViewConfiguration (config, grp); + + config->setGroup(grp); +} + +void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) +{ + KateDocManager::self()->saveDocumentList (sessionConfig); + + sessionConfig->setGroup("General"); + sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative()); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindow.h b/kate/app/katemainwindow.h new file mode 100644 index 000000000..157b4e57d --- /dev/null +++ b/kate/app/katemainwindow.h @@ -0,0 +1,218 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_MAINWINDOW_H__ +#define __KATE_MAINWINDOW_H__ + +#include "katemain.h" +#include "katemdi.h" + +#include <kate/view.h> +#include <kate/document.h> + +#include <tdeparts/part.h> + +#include <tdeaction.h> + +class KateTabWidget; +class GrepTool; + +namespace Kate { + class MainWindow; + class ToolViewManager; +} + +class KFileItem; +class TDERecentFilesAction; +class DCOPObject; + +class KateExternalToolsMenuAction; + +class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBase +{ + Q_OBJECT + + friend class KateConfigDialog; + friend class KateViewManager; + + public: + /** + * Construct the window and restore it's state from given config if any + * @param sconfig session config for this window, 0 if none + * @param sgroup session config group to use + */ + KateMainWindow (TDEConfig *sconfig, const TQString &sgroup); + + /** + * Destruct the nice window + */ + ~KateMainWindow(); + + /** + * Accessor methodes for interface and child objects + */ + public: + Kate::MainWindow *mainWindow () { return m_mainWindow; } + Kate::ToolViewManager *toolViewManager () { return m_toolViewManager; } + + KateViewManager *viewManager () { return m_viewManager; } + + DCOPObject *dcopObject () { return m_dcop; } + + /** + * various methodes to get some little info out of this + */ + public: + /** Returns the URL of the current document. + * anders: I add this for use from the file selector. */ + KURL activeDocumentUrl(); + + uint mainWindowNumber () const { return myID; } + + /** + * Prompts the user for what to do with files that are modified on disk if any. + * This is optionally run when the window receives focus, and when the last + * window is closed. + * @return true if no documents are modified on disk, or all documents were + * handled by the dialog; otherwise (the dialog was canceled) false. + */ + bool showModOnDiskPrompt(); + + /** + * central tabwidget ;) + * @return tab widget + */ + KateTabWidget *tabWidget (); + + public: + void readProperties(TDEConfig *config); + void saveProperties(TDEConfig *config); + void saveGlobalProperties( TDEConfig* sessionConfig ); + + public: + bool queryClose_internal(); + + private: + void setupMainWindow(); + void setupActions(); + bool queryClose(); + + /** + * read some global options from katerc + */ + void readOptions(); + + /** + * save some global options to katerc + */ + void saveOptions(); + + void dragEnterEvent( TQDragEnterEvent * ); + void dropEvent( TQDropEvent * ); + + /** + * slots used for actions in the menus/toolbars + * or internal signal connections + */ + private slots: + void newWindow (); + + void slotConfigure(); + + void slotOpenWithMenuAction(int idx); + + void slotGrepToolItemSelected ( const TQString &filename, int linenumber ); + void slotMail(); + + void slotFileQuit(); + void slotEditToolbars(); + void slotNewToolbarConfig(); + void slotWindowActivated (); + void slotUpdateOpenWith(); + void documentMenuAboutToShow(); + void slotDropEvent(TQDropEvent *); + void editKeys(); + void mSlotFixOpenWithMenu(); + + void fileSelected(const KFileItem *file); + + void tipOfTheDay(); + + /* to update the caption */ + void slotDocumentCreated(Kate::Document *doc); + void slotNameChanged(Kate::Document *doc); + void updateCaption(Kate::Document *doc); + + void pluginHelp(); + void slotFullScreen(bool); + + public: + void openURL (const TQString &name=0L); + + private slots: + void updateGrepDir (bool visible); + + protected: + bool event( TQEvent * ); + + private slots: + void slotDocumentCloseAll(); + + private: + static uint uniqueID; + uint myID; + + Kate::MainWindow *m_mainWindow; + Kate::ToolViewManager *m_toolViewManager; + + bool syncKonsole; + bool useInstance; + bool modNotification; + + DCOPObject *m_dcop; + + // console + KateConsole *console; + + // management items + KateViewManager *m_viewManager; + + TDERecentFilesAction *fileOpenRecent; + + KateFileList *filelist; + KateFileSelector *fileselector; + + TDEActionMenu* documentOpenWith; + + TQPopupMenu *documentMenu; + + TDEToggleAction* settingsShowFilelist; + TDEToggleAction* settingsShowFileselector; + + KateExternalToolsMenuAction *externalTools; + GrepTool * greptool; + bool m_modignore, m_grrr; + + KateTabWidget *m_tabWidget; +}; + +#endif + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindowiface.cpp b/kate/app/katemainwindowiface.cpp new file mode 100644 index 000000000..af3c74ed2 --- /dev/null +++ b/kate/app/katemainwindowiface.cpp @@ -0,0 +1,27 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser <geiseri@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katemainwindowiface.h" + +#include "katemainwindow.h" + +#include <kdebug.h> + +KateMainWindowDCOPIface::KateMainWindowDCOPIface (KateMainWindow *w) : DCOPObject (TQString(TQString("KateMainWindow#%1").arg(w->mainWindowNumber())).latin1()), m_w (w) +{ +} diff --git a/kate/app/katemainwindowiface.h b/kate/app/katemainwindowiface.h new file mode 100644 index 000000000..3292d1b15 --- /dev/null +++ b/kate/app/katemainwindowiface.h @@ -0,0 +1,41 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser <geiseri@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _katemainwindow_Iface_h_ +#define _katemainwindow_Iface_h_ + +#include <dcopobject.h> +#include <dcopref.h> + +#include <kurl.h> + +class KateMainWindow; + +class KateMainWindowDCOPIface : public DCOPObject +{ + K_DCOP + + public: + KateMainWindowDCOPIface (KateMainWindow *w); + + k_dcop: + + private: + KateMainWindow *m_w; +}; +#endif diff --git a/kate/app/katemdi.cpp b/kate/app/katemdi.cpp new file mode 100644 index 000000000..a6c657e2c --- /dev/null +++ b/kate/app/katemdi.cpp @@ -0,0 +1,970 @@ +/* This file is part of the KDE libraries + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org> + + GUIClient partly based on tdetoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katemdi.h" +#include "katemdi.moc" + +#include <tdeaction.h> +#include <kdebug.h> +#include <tdeglobal.h> +#include <tdeglobalsettings.h> +#include <tdeapplication.h> +#include <tdelocale.h> +#include <tdeconfig.h> +#include <kiconloader.h> +#include <tdepopupmenu.h> +#include <tdemessagebox.h> + +#include <tqvbox.h> +#include <tqhbox.h> +#include <tqevent.h> + +namespace KateMDI { + +//BEGIN SPLITTER + +Splitter::Splitter(Orientation o, TQWidget* parent, const char* name) + : TQSplitter(o, parent, name) +{ +} + +Splitter::~Splitter() +{ +} + +bool Splitter::isLastChild(TQWidget* w) const +{ + return ( idAfter( w ) == 0 ); +} + +int Splitter::idAfter ( TQWidget * w ) const +{ + return TQSplitter::idAfter (w); +} + +//END SPLITTER + + +//BEGIN TOGGLETOOLVIEWACTION + +ToggleToolViewAction::ToggleToolViewAction ( const TQString& text, const TDEShortcut& cut, ToolView *tv, + TQObject* parent, const char* name ) + : TDEToggleAction(text,cut,parent,name) + , m_tv(tv) +{ + connect(this,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotToggled(bool))); + connect(m_tv,TQT_SIGNAL(visibleChanged(bool)),this,TQT_SLOT(visibleChanged(bool))); + + setChecked(m_tv->visible()); +} + +ToggleToolViewAction::~ToggleToolViewAction() +{ + unplugAll(); +} + +void ToggleToolViewAction::visibleChanged(bool) +{ + if (isChecked() != m_tv->visible()) + setChecked (m_tv->visible()); +} + +void ToggleToolViewAction::slotToggled(bool t) +{ + if (t) + { + m_tv->mainWindow()->showToolView (m_tv); + m_tv->setFocus (); + } + else + { + m_tv->mainWindow()->hideToolView (m_tv); + m_tv->mainWindow()->centralWidget()->setFocus (); + } +} + +//END TOGGLETOOLVIEWACTION + + +//BEGIN GUICLIENT + +static const char *actionListName = "kate_mdi_window_actions"; + +static const char *guiDescription = "" + "<!DOCTYPE kpartgui><kpartgui name=\"kate_mdi_window_actions\">" + "<MenuBar>" + " <Menu name=\"window\">" + " <ActionList name=\"%1\" />" + " </Menu>" + "</MenuBar>" + "</kpartgui>"; + +GUIClient::GUIClient ( MainWindow *mw ) + : TQObject ( mw ) + , KXMLGUIClient ( mw ) + , m_mw (mw) +{ + connect( m_mw->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ), + this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) ); + + if ( domDocument().documentElement().isNull() ) + { + TQString completeDescription = TQString::fromLatin1( guiDescription ) + .arg( actionListName ); + + setXML( completeDescription, false /*merge*/ ); + } + + if (actionCollection()->tdeaccel()==0) + actionCollection()->setWidget(m_mw); + + m_toolMenu = new TDEActionMenu(i18n("Tool &Views"),actionCollection(),"kate_mdi_toolview_menu"); + m_showSidebarsAction = new TDEToggleAction( i18n("Show Side&bars"), + CTRL|ALT|SHIFT|Key_F, actionCollection(), "kate_mdi_sidebar_visibility" ); + m_showSidebarsAction->setCheckedState(i18n("Hide Side&bars")); + m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() ); + connect( m_showSidebarsAction, TQT_SIGNAL( toggled( bool ) ), + m_mw, TQT_SLOT( setSidebarsVisible( bool ) ) ); + + m_toolMenu->insert( m_showSidebarsAction ); + m_toolMenu->insert( new TDEActionSeparator( m_toolMenu ) ); + + // read shortcuts + actionCollection()->readShortcutSettings( "Shortcuts", kapp->config() ); +} + +GUIClient::~GUIClient() +{ +} + +void GUIClient::updateSidebarsVisibleAction() +{ + m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() ); +} + +void GUIClient::registerToolView (ToolView *tv) +{ + TQString aname = TQString("kate_mdi_toolview_") + tv->id; + + // try to read the action shortcut + TDEShortcut sc; + TDEConfig *cfg = kapp->config(); + TQString _grp = cfg->group(); + cfg->setGroup("Shortcuts"); + sc = TDEShortcut( cfg->readEntry( aname, "" ) ); + cfg->setGroup( _grp ); + + TDEToggleAction *a = new ToggleToolViewAction(i18n("Show %1").arg(tv->text), + sc,tv, actionCollection(), aname.latin1() ); + + a->setCheckedState(TQString(i18n("Hide %1").arg(tv->text))); + + m_toolViewActions.append(a); + m_toolMenu->insert(a); + + m_toolToAction.insert (tv, a); + + updateActions(); +} + +void GUIClient::unregisterToolView (ToolView *tv) +{ + TDEAction *a = m_toolToAction[tv]; + + if (!a) + return; + + m_toolViewActions.remove(a); + delete a; + + m_toolToAction.remove (tv); + + updateActions(); +} + +void GUIClient::clientAdded( KXMLGUIClient *client ) +{ + if ( client == this ) + updateActions(); +} + +void GUIClient::updateActions() +{ + if ( !factory() ) + return; + + unplugActionList( actionListName ); + + TQPtrList<TDEAction> addList; + addList.append(m_toolMenu); + + plugActionList( actionListName, addList ); +} + +//END GUICLIENT + + +//BEGIN TOOLVIEW + +ToolView::ToolView (MainWindow *mainwin, Sidebar *sidebar, TQWidget *parent) + : TQVBox (parent) + , m_mainWin (mainwin) + , m_sidebar (sidebar) + , m_visible (false) + , persistent (false) +{ +} + +ToolView::~ToolView () +{ + m_mainWin->toolViewDeleted (this); +} + +void ToolView::setVisible (bool vis) +{ + if (m_visible == vis) + return; + + m_visible = vis; + emit visibleChanged (m_visible); +} + +bool ToolView::visible () const +{ + return m_visible; +} + +void ToolView::childEvent ( TQChildEvent *ev ) +{ + // set the widget to be focus proxy if possible + if (ev->inserted() && ev->child() && TQT_TQOBJECT(ev->child())->tqt_cast(TQWIDGET_OBJECT_NAME_STRING)) { + setFocusProxy (::tqqt_cast<QWidget*>(TQT_TQOBJECT(ev->child()))); +} + + TQVBox::childEvent (ev); +} + +//END TOOLVIEW + + +//BEGIN SIDEBAR + +Sidebar::Sidebar (KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, TQWidget *parent) + : KMultiTabBar ((pos == KMultiTabBar::Top || pos == KMultiTabBar::Bottom) ? KMultiTabBar::Horizontal : KMultiTabBar::Vertical, parent) + , m_mainWin (mainwin) + , m_splitter (0) + , m_ownSplit (0) + , m_lastSize (0) +{ + setPosition( pos ); + hide (); +} + +Sidebar::~Sidebar () +{ +} + +void Sidebar::setSplitter (Splitter *sp) +{ + m_splitter = sp; + m_ownSplit = new Splitter ((position() == KMultiTabBar::Top || position() == KMultiTabBar::Bottom) ? Qt::Horizontal : Qt::Vertical, m_splitter); + m_ownSplit->setOpaqueResize( TDEGlobalSettings::opaqueResize() ); + m_ownSplit->setChildrenCollapsible( false ); + m_splitter->setResizeMode( m_ownSplit, TQSplitter::KeepSize ); + m_ownSplit->hide (); +} + +ToolView *Sidebar::addWidget (const TQPixmap &icon, const TQString &text, ToolView *widget) +{ + static int id = 0; + + if (widget) + { + if (widget->sidebar() == this) + return widget; + + widget->sidebar()->removeWidget (widget); + } + + int newId = ++id; + + appendTab (icon, newId, text); + + if (!widget) + { + widget = new ToolView (m_mainWin, this, m_ownSplit); + widget->hide (); + widget->icon = icon; + widget->text = text; + } + else + { + widget->hide (); + widget->reparent (m_ownSplit, 0, TQPoint()); + widget->m_sidebar = this; + } + + // save it's pos ;) + widget->persistent = false; + + m_idToWidget.insert (newId, widget); + m_widgetToId.insert (widget, newId); + m_toolviews.push_back (widget); + + show (); + + connect(tab(newId),TQT_SIGNAL(clicked(int)),this,TQT_SLOT(tabClicked(int))); + tab(newId)->installEventFilter(this); + + return widget; +} + +bool Sidebar::removeWidget (ToolView *widget) +{ + if (!m_widgetToId.contains(widget)) + return false; + + removeTab(m_widgetToId[widget]); + + m_idToWidget.remove (m_widgetToId[widget]); + m_widgetToId.remove (widget); + m_toolviews.remove (widget); + + bool anyVis = false; + TQIntDictIterator<ToolView> it( m_idToWidget ); + for ( ; it.current(); ++it ) + { + if (!anyVis) + anyVis = it.current()->isVisible(); + } + + if (m_idToWidget.isEmpty()) + { + m_ownSplit->hide (); + hide (); + } + else if (!anyVis) + m_ownSplit->hide (); + + return true; +} + +bool Sidebar::showWidget (ToolView *widget) +{ + if (!m_widgetToId.contains(widget)) + return false; + + // hide other non-persistent views + TQIntDictIterator<ToolView> it( m_idToWidget ); + for ( ; it.current(); ++it ) + if ((it.current() != widget) && !it.current()->persistent) + { + it.current()->hide(); + setTab (it.currentKey(), false); + it.current()->setVisible(false); + } + + setTab (m_widgetToId[widget], true); + + m_ownSplit->show (); + widget->show (); + + widget->setVisible (true); + + return true; +} + +bool Sidebar::hideWidget (ToolView *widget) +{ + if (!m_widgetToId.contains(widget)) + return false; + + bool anyVis = false; + + updateLastSize (); + + for ( TQIntDictIterator<ToolView> it( m_idToWidget ); it.current(); ++it ) + { + if (it.current() == widget) + { + it.current()->hide(); + continue; + } + + if (!anyVis) + anyVis = it.current()->isVisible(); + } + + // lower tab + setTab (m_widgetToId[widget], false); + + if (!anyVis) + m_ownSplit->hide (); + + widget->setVisible (false); + + return true; +} + +void Sidebar::tabClicked(int i) +{ + ToolView *w = m_idToWidget[i]; + + if (!w) + return; + + if (isTabRaised(i)) + { + showWidget (w); + w->setFocus (); + } + else + { + hideWidget (w); + m_mainWin->centralWidget()->setFocus (); + } +} + +bool Sidebar::eventFilter(TQObject *obj, TQEvent *ev) +{ + if (ev->type()==TQEvent::ContextMenu) + { + TQContextMenuEvent *e = (TQContextMenuEvent *) ev; + KMultiTabBarTab *bt = tqt_dynamic_cast<KMultiTabBarTab*>(obj); + if (bt) + { + kdDebug()<<"Request for popup"<<endl; + + m_popupButton = bt->id(); + + ToolView *w = m_idToWidget[m_popupButton]; + + if (w) + { + TDEPopupMenu *p = new TDEPopupMenu (this); + + p->insertTitle(SmallIcon("view_remove"), i18n("Behavior"), 50); + + p->insertItem(w->persistent ? SmallIconSet("window_nofullscreen") : SmallIconSet("window_fullscreen"), w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent"), 10); + + p->insertTitle(SmallIcon("move"), i18n("Move To"), 51); + + if (position() != 0) + p->insertItem(SmallIconSet("back"), i18n("Left Sidebar"),0); + + if (position() != 1) + p->insertItem(SmallIconSet("forward"), i18n("Right Sidebar"),1); + + if (position() != 2) + p->insertItem(SmallIconSet("up"), i18n("Top Sidebar"),2); + + if (position() != 3) + p->insertItem(SmallIconSet("down"), i18n("Bottom Sidebar"),3); + + connect(p, TQT_SIGNAL(activated(int)), + this, TQT_SLOT(buttonPopupActivate(int))); + + p->exec(e->globalPos()); + delete p; + + return true; + } + } + } + + return false; +} + +void Sidebar::show() +{ + if (m_idToWidget.isEmpty() || !m_mainWin->sidebarsVisible() ) + return; + + KMultiTabBar::show( ); +} + +void Sidebar::buttonPopupActivate (int id) +{ + ToolView *w = m_idToWidget[m_popupButton]; + + if (!w) + return; + + // move ids + if (id < 4) + { + // move + show ;) + m_mainWin->moveToolView (w, (KMultiTabBar::KMultiTabBarPosition) id); + m_mainWin->showToolView (w); + } + + // toggle persistent + if (id == 10) + w->persistent = !w->persistent; +} + +void Sidebar::updateLastSize () +{ + TQValueList<int> s = m_splitter->sizes (); + + int i = 0; + if ((position() == KMultiTabBar::Right || position() == KMultiTabBar::Bottom)) + i = 2; + + // little threshold + if (s[i] > 2) + m_lastSize = s[i]; +} + +class TmpToolViewSorter +{ + public: + ToolView *tv; + unsigned int pos; +}; + +void Sidebar::restoreSession (TDEConfig *config) +{ + // get the last correct placed toolview + unsigned int firstWrong = 0; + for ( ; firstWrong < m_toolviews.size(); ++firstWrong ) + { + ToolView *tv = m_toolviews[firstWrong]; + + unsigned int pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), firstWrong); + + if (pos != firstWrong) + break; + } + + // we need to reshuffle, ahhh :( + if (firstWrong < m_toolviews.size()) + { + // first: collect the items to reshuffle + TQValueList<TmpToolViewSorter> toSort; + for (unsigned int i=firstWrong; i < m_toolviews.size(); ++i) + { + TmpToolViewSorter s; + s.tv = m_toolviews[i]; + s.pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(m_toolviews[i]->id), i); + toSort.push_back (s); + } + + // now: sort the stuff we need to reshuffle + for (unsigned int m=0; m < toSort.size(); ++m) + for (unsigned int n=m+1; n < toSort.size(); ++n) + if (toSort[n].pos < toSort[m].pos) + { + TmpToolViewSorter tmp = toSort[n]; + toSort[n] = toSort[m]; + toSort[m] = tmp; + } + + // then: remove this items from the button bar + // do this backwards, to minimize the relayout efforts + for (int i=m_toolviews.size()-1; i >= (int)firstWrong; --i) + { + removeTab (m_widgetToId[m_toolviews[i]]); + } + + // insert the reshuffled things in order :) + for (unsigned int i=0; i < toSort.size(); ++i) + { + ToolView *tv = toSort[i].tv; + + m_toolviews[firstWrong+i] = tv; + + // readd the button + int newId = m_widgetToId[tv]; + appendTab (tv->icon, newId, tv->text); + connect(tab(newId),TQT_SIGNAL(clicked(int)),this,TQT_SLOT(tabClicked(int))); + tab(newId)->installEventFilter(this); + + // reshuffle in splitter + m_ownSplit->moveToLast (tv); + } + } + + // update last size if needed + updateLastSize (); + + // restore the own splitter sizes + TQValueList<int> s = config->readIntListEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position())); + m_ownSplit->setSizes (s); + + // show only correct toolviews, remember persistent values ;) + bool anyVis = false; + for ( unsigned int i=0; i < m_toolviews.size(); ++i ) + { + ToolView *tv = m_toolviews[i]; + + tv->persistent = config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), false); + tv->setVisible (config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), false)); + + if (!anyVis) + anyVis = tv->visible(); + + setTab (m_widgetToId[tv],tv->visible()); + + if (tv->visible()) + tv->show(); + else + tv->hide (); + } + + if (anyVis) + m_ownSplit->show(); + else + m_ownSplit->hide(); +} + +void Sidebar::saveSession (TDEConfig *config) +{ + // store the own splitter sizes + TQValueList<int> s = m_ownSplit->sizes(); + config->writeEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()), s); + + // store the data about all toolviews in this sidebar ;) + for ( unsigned int i=0; i < m_toolviews.size(); ++i ) + { + ToolView *tv = m_toolviews[i]; + + config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(tv->id), tv->sidebar()->position()); + config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), i); + config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), tv->visible()); + config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), tv->persistent); + } +} + +//END SIDEBAR + + +//BEGIN MAIN WINDOW + +MainWindow::MainWindow (TQWidget* parentWidget, const char* name) + : KParts::MainWindow( parentWidget, name) + , m_sidebarsVisible(true) + , m_restoreConfig (0) + , m_guiClient (new GUIClient (this)) +{ + // init the internal widgets + TQHBox *hb = new TQHBox (this); + setCentralWidget(hb); + + m_sidebars[KMultiTabBar::Left] = new Sidebar (KMultiTabBar::Left, this, hb); + + m_hSplitter = new Splitter (Qt::Horizontal, hb); + m_hSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() ); + + m_sidebars[KMultiTabBar::Left]->setSplitter (m_hSplitter); + + TQVBox *vb = new TQVBox (m_hSplitter); + m_hSplitter->setCollapsible(vb, false); + + m_sidebars[KMultiTabBar::Top] = new Sidebar (KMultiTabBar::Top, this, vb); + + m_vSplitter = new Splitter (Qt::Vertical, vb); + m_vSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() ); + + m_sidebars[KMultiTabBar::Top]->setSplitter (m_vSplitter); + + m_centralWidget = new TQVBox (m_vSplitter); + m_vSplitter->setCollapsible(m_centralWidget, false); + + m_sidebars[KMultiTabBar::Bottom] = new Sidebar (KMultiTabBar::Bottom, this, vb); + m_sidebars[KMultiTabBar::Bottom]->setSplitter (m_vSplitter); + + m_sidebars[KMultiTabBar::Right] = new Sidebar (KMultiTabBar::Right, this, hb); + m_sidebars[KMultiTabBar::Right]->setSplitter (m_hSplitter); +} + +MainWindow::~MainWindow () +{ + // cu toolviews + while (!m_toolviews.isEmpty()) + delete m_toolviews[0]; + + // seems like we really should delete this by hand ;) + delete m_centralWidget; + + for (unsigned int i=0; i < 4; ++i) + delete m_sidebars[i]; +} + +TQWidget *MainWindow::centralWidget () const +{ + return m_centralWidget; +} + +ToolView *MainWindow::createToolView (const TQString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const TQPixmap &icon, const TQString &text) +{ + if (m_idToWidget[identifier]) + return 0; + + // try the restore config to figure out real pos + if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) + { + m_restoreConfig->setGroup (m_restoreGroup); + pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(identifier), pos); + } + + ToolView *v = m_sidebars[pos]->addWidget (icon, text, 0); + v->id = identifier; + + m_idToWidget.insert (identifier, v); + m_toolviews.push_back (v); + + // register for menu stuff + m_guiClient->registerToolView (v); + + return v; +} + +ToolView *MainWindow::toolView (const TQString &identifier) const +{ + return m_idToWidget[identifier]; +} + +void MainWindow::toolViewDeleted (ToolView *widget) +{ + if (!widget) + return; + + if (widget->mainWindow() != this) + return; + + // unregister from menu stuff + m_guiClient->unregisterToolView (widget); + + widget->sidebar()->removeWidget (widget); + + m_idToWidget.remove (widget->id); + m_toolviews.remove (widget); +} + +void MainWindow::setSidebarsVisible( bool visible ) +{ + m_sidebarsVisible = visible; + + m_sidebars[0]->setShown(visible); + m_sidebars[1]->setShown(visible); + m_sidebars[2]->setShown(visible); + m_sidebars[3]->setShown(visible); + + m_guiClient->updateSidebarsVisibleAction(); + + // show information message box, if the users hides the sidebars + if( !m_sidebarsVisible ) + { + KMessageBox::information( this, + i18n("<qt>You are about to hide the sidebars. With " + "hidden sidebars it is not possible to directly " + "access the tool views with the mouse anymore, " + "so if you need to access the sidebars again " + "invoke <b>Window > Tool Views > Show Sidebars</b> " + "in the menu. It is still possible to show/hide " + "the tool views with the assigned shortcuts.</qt>"), + TQString::null, "Kate hide sidebars notification message" ); + } +} + +bool MainWindow::sidebarsVisible() const +{ + return m_sidebarsVisible; +} + +void MainWindow::setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style) +{ + m_sidebars[0]->setStyle(style); + m_sidebars[1]->setStyle(style); + m_sidebars[2]->setStyle(style); + m_sidebars[3]->setStyle(style); +} + +KMultiTabBar::KMultiTabBarStyle MainWindow::toolViewStyle () const +{ + // all sidebars have the same style, so just take Top + return m_sidebars[KMultiTabBar::Top]->tabStyle(); +} + +bool MainWindow::moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos) +{ + if (!widget || widget->mainWindow() != this) + return false; + + // try the restore config to figure out real pos + if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) + { + m_restoreConfig->setGroup (m_restoreGroup); + pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(widget->id), pos); + } + + m_sidebars[pos]->addWidget (widget->icon, widget->text, widget); + + return true; +} + +bool MainWindow::showToolView (ToolView *widget) +{ + if (!widget || widget->mainWindow() != this) + return false; + + // skip this if happens during restoring, or we will just see flicker + if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) + return true; + + return widget->sidebar()->showWidget (widget); +} + +bool MainWindow::hideToolView (ToolView *widget) +{ + if (!widget || widget->mainWindow() != this) + return false; + + // skip this if happens during restoring, or we will just see flicker + if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) + return true; + + return widget->sidebar()->hideWidget (widget); +} + +void MainWindow::startRestore (TDEConfig *config, const TQString &group) +{ + // first save this stuff + m_restoreConfig = config; + m_restoreGroup = group; + + if (!m_restoreConfig || !m_restoreConfig->hasGroup (m_restoreGroup)) + { + // set sane default sizes + TQValueList<int> hs; + hs << 200 << 100 << 200; + TQValueList<int> vs; + vs << 150 << 100 << 200; + + m_sidebars[0]->setLastSize (hs[0]); + m_sidebars[1]->setLastSize (hs[2]); + m_sidebars[2]->setLastSize (vs[0]); + m_sidebars[3]->setLastSize (vs[2]); + + m_hSplitter->setSizes(hs); + m_vSplitter->setSizes(vs); + return; + } + + // apply size once, to get sizes ready ;) + m_restoreConfig->setGroup (m_restoreGroup); + restoreWindowSize (m_restoreConfig); + + m_restoreConfig->setGroup (m_restoreGroup); + + // get main splitter sizes ;) + TQValueList<int> hs = m_restoreConfig->readIntListEntry ("Kate-MDI-H-Splitter"); + TQValueList<int> vs = m_restoreConfig->readIntListEntry ("Kate-MDI-V-Splitter"); + + m_sidebars[0]->setLastSize (hs[0]); + m_sidebars[1]->setLastSize (hs[2]); + m_sidebars[2]->setLastSize (vs[0]); + m_sidebars[3]->setLastSize (vs[2]); + + m_hSplitter->setSizes(hs); + m_vSplitter->setSizes(vs); + + setToolViewStyle( (KMultiTabBar::KMultiTabBarStyle)m_restoreConfig->readNumEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()) ); + + // after reading m_sidebarsVisible, update the GUI toggle action + m_sidebarsVisible = m_restoreConfig->readBoolEntry ("Kate-MDI-Sidebar-Visible", true ); + m_guiClient->updateSidebarsVisibleAction(); +} + +void MainWindow::finishRestore () +{ + if (!m_restoreConfig) + return; + + if (m_restoreConfig->hasGroup (m_restoreGroup)) + { + // apply all settings, like toolbar pos and more ;) + applyMainWindowSettings(m_restoreConfig, m_restoreGroup); + + // reshuffle toolviews only if needed + m_restoreConfig->setGroup (m_restoreGroup); + for ( unsigned int i=0; i < m_toolviews.size(); ++i ) + { + KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->id), m_toolviews[i]->sidebar()->position()); + + if (m_toolviews[i]->sidebar()->position() != newPos) + { + moveToolView (m_toolviews[i], newPos); + } + } + + // restore the sidebars + m_restoreConfig->setGroup (m_restoreGroup); + for (unsigned int i=0; i < 4; ++i) + m_sidebars[i]->restoreSession (m_restoreConfig); + } + + // clear this stuff, we are done ;) + m_restoreConfig = 0; + m_restoreGroup = ""; +} + +void MainWindow::saveSession (TDEConfig *config, const TQString &group) +{ + if (!config) + return; + + saveMainWindowSettings (config, group); + + config->setGroup (group); + + // save main splitter sizes ;) + TQValueList<int> hs = m_hSplitter->sizes(); + TQValueList<int> vs = m_vSplitter->sizes(); + + if (hs[0] <= 2 && !m_sidebars[0]->splitterVisible ()) + hs[0] = m_sidebars[0]->lastSize(); + if (hs[2] <= 2 && !m_sidebars[1]->splitterVisible ()) + hs[2] = m_sidebars[1]->lastSize(); + if (vs[0] <= 2 && !m_sidebars[2]->splitterVisible ()) + vs[0] = m_sidebars[2]->lastSize(); + if (vs[2] <= 2 && !m_sidebars[3]->splitterVisible ()) + vs[2] = m_sidebars[3]->lastSize(); + + config->writeEntry ("Kate-MDI-H-Splitter", hs); + config->writeEntry ("Kate-MDI-V-Splitter", vs); + + // save sidebar style + config->writeEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()); + config->writeEntry ("Kate-MDI-Sidebar-Visible", m_sidebarsVisible ); + + // save the sidebars + for (unsigned int i=0; i < 4; ++i) + m_sidebars[i]->saveSession (config); +} + +//END MAIN WINDOW + +} // namespace KateMDI + +// kate: space-indent on; indent-width 2; diff --git a/kate/app/katemdi.h b/kate/app/katemdi.h new file mode 100644 index 000000000..a291ebb8c --- /dev/null +++ b/kate/app/katemdi.h @@ -0,0 +1,448 @@ +/* This file is part of the KDE libraries + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_MDI_H__ +#define __KATE_MDI_H__ + +#include <tdeparts/mainwindow.h> + +#include <tdemultitabbar.h> +#include <kxmlguiclient.h> +#include <tdeaction.h> + +#include <tqdict.h> +#include <tqintdict.h> +#include <tqmap.h> +#include <tqsplitter.h> +#include <tqpixmap.h> +#include <tqptrlist.h> + +namespace KateMDI { + + +/** This class is needed because TQSplitter cant return an index for a widget. */ +class Splitter : public TQSplitter +{ + Q_OBJECT + + + public: + Splitter(Orientation o, TQWidget* parent=0, const char* name=0); + ~Splitter(); + + /** Since there is supposed to be only 2 childs of a katesplitter, + * any child other than the last is the first. + * This method uses TQSplitter::idAfter(widget) which + * returns 0 if there is no widget after this one. + * This results in an error if widget is not a child + * in this splitter */ + bool isLastChild(TQWidget* w) const; + + int idAfter ( TQWidget * w ) const; +}; + +class ToggleToolViewAction : public TDEToggleAction +{ + Q_OBJECT + + + public: + ToggleToolViewAction ( const TQString& text, const TDEShortcut& cut, + class ToolView *tv, TQObject* parent = 0, const char* name = 0 ); + + virtual ~ToggleToolViewAction(); + + protected slots: + void slotToggled(bool); + void visibleChanged(bool); + + private: + ToolView *m_tv; +}; + +class GUIClient : public TQObject, public KXMLGUIClient +{ + Q_OBJECT + + + public: + GUIClient ( class MainWindow *mw ); + virtual ~GUIClient(); + + void registerToolView (ToolView *tv); + void unregisterToolView (ToolView *tv); + void updateSidebarsVisibleAction(); + + private slots: + void clientAdded( KXMLGUIClient *client ); + void updateActions(); + + private: + MainWindow *m_mw; + TDEToggleAction *m_showSidebarsAction; + TQPtrList<TDEAction> m_toolViewActions; + TQMap<ToolView*, TDEAction*> m_toolToAction; + TDEActionMenu *m_toolMenu; +}; + +class ToolView : public TQVBox +{ + Q_OBJECT + + + friend class Sidebar; + friend class MainWindow; + friend class GUIClient; + friend class ToggleToolViewAction; + + protected: + /** + * ToolView + * Objects of this clas represent a toolview in the mainwindow + * you should only add one widget as child to this toolview, it will + * be automatically set to be the focus proxy of the toolview + * @param mainwin main window for this toolview + * @param sidebar sidebar of this toolview + * @param parent parent widget, e.g. the splitter of one of the sidebars + */ + ToolView (class MainWindow *mainwin, class Sidebar *sidebar, TQWidget *parent); + + public: + /** + * destuct me, this is allowed for all, will care itself that the toolview is removed + * from the mainwindow and sidebar + */ + virtual ~ToolView (); + + signals: + /** + * toolview hidden or shown + * @param bool is this toolview made visible? + */ + void visibleChanged (bool visible); + + /** + * some internal methodes needed by the main window and the sidebars + */ + protected: + MainWindow *mainWindow () { return m_mainWin; } + + Sidebar *sidebar () { return m_sidebar; } + + void setVisible (bool vis); + + public: + bool visible () const; + + protected: + void childEvent ( TQChildEvent *ev ); + + private: + MainWindow *m_mainWin; + Sidebar *m_sidebar; + + /** + * unique id + */ + TQString id; + + /** + * is visible in sidebar + */ + bool m_visible; + + /** + * is this view persistent? + */ + bool persistent; + + TQPixmap icon; + TQString text; +}; + +class Sidebar : public KMultiTabBar +{ + Q_OBJECT + + + public: + Sidebar (KMultiTabBar::KMultiTabBarPosition pos, class MainWindow *mainwin, TQWidget *parent); + virtual ~Sidebar (); + + void setSplitter (Splitter *sp); + + public: + ToolView *addWidget (const TQPixmap &icon, const TQString &text, ToolView *widget); + bool removeWidget (ToolView *widget); + + bool showWidget (ToolView *widget); + bool hideWidget (ToolView *widget); + + void setLastSize (int s) { m_lastSize = s; } + int lastSize () const { return m_lastSize; } + void updateLastSize (); + + bool splitterVisible () const { return m_ownSplit->isVisible(); } + + void restoreSession (); + + /** + * restore the current session config from given object, use current group + * @param config config object to use + */ + void restoreSession (TDEConfig *config); + + /** + * save the current session config to given object, use current group + * @param config config object to use + */ + void saveSession (TDEConfig *config); + + public slots: + // reimplemented, to block a show() call if we have no children or if + // all sidebars are forced hidden. + virtual void show(); + + private slots: + void tabClicked(int); + + protected: + bool eventFilter(TQObject *obj, TQEvent *ev); + + private slots: + void buttonPopupActivate (int id); + + private: + MainWindow *m_mainWin; + + KMultiTabBar::KMultiTabBarPosition m_pos; + Splitter *m_splitter; + KMultiTabBar *m_tabBar; + Splitter *m_ownSplit; + + TQIntDict<ToolView> m_idToWidget; + TQMap<ToolView*, int> m_widgetToId; + + /** + * list of all toolviews around in this sidebar + */ + TQValueList<ToolView*> m_toolviews; + + int m_lastSize; + + int m_popupButton; +}; + +class MainWindow : public KParts::MainWindow +{ + Q_OBJECT + + + friend class ToolView; + + // + // Constructor area + // + public: + /** + * Constructor + */ + MainWindow (TQWidget* parentWidget = 0, const char* name = 0); + + /** + * Destructor + */ + virtual ~MainWindow (); + + // + // public interfaces + // + public: + /** + * central widget ;) + * use this as parent for your content + * this widget will get focus if a toolview is hidden + * @return central widget + */ + TQWidget *centralWidget () const; + + /** + * add a given widget to the given sidebar if possible, name is very important + * @param identifier unique identifier for this toolview + * @param pos position for the toolview, if we are in session restore, this is only a preference + * @param icon icon to use for the toolview + * @param text text to use in addition to icon + * @return created toolview on success or 0 + */ + ToolView *createToolView (const TQString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const TQPixmap &icon, const TQString &text); + + /** + * give you handle to toolview for the given name, 0 if no toolview around + * @param identifier toolview name + * @return toolview if existing, else 0 + */ + ToolView *toolView (const TQString &identifier) const; + + /** + * set the toolview's tabbar style. + * @param style the tabbar style. + */ + void setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style); + + /** + * get the toolview's tabbar style. Call this before @p startRestore(), + * otherwise you overwrite the usersettings. + * @return toolview's tabbar style + */ + KMultiTabBar::KMultiTabBarStyle toolViewStyle () const; + + /** + * get the sidebars' visibility. + * @return false, if the sidebars' visibility is forced hidden, otherwise true + */ + bool sidebarsVisible() const; + + public slots: + /** + * set the sidebars' visibility to @p visible. If false, the sidebars + * are @e always hidden. Usually you do not have to call this because + * the user can set this in the menu. + * @param visible sidebars visibility + */ + void setSidebarsVisible( bool visible ); + + protected: + /** + * called by toolview destructor + * @param widget toolview which is destroyed + */ + void toolViewDeleted (ToolView *widget); + + /** + * modifiers for existing toolviews + */ + public: + /** + * move a toolview around + * @param widget toolview to move + * @param pos position to move too, during session restore, only preference + * @return success + */ + bool moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos); + + /** + * show given toolview, discarded while session restore + * @param widget toolview to show + * @return success + */ + bool showToolView (ToolView *widget); + + /** + * hide given toolview, discarded while session restore + * @param widget toolview to hide + * @return success + */ + bool hideToolView (ToolView *widget); + + /** + * session saving and restore stuff + */ + public: + /** + * start the restore + * @param config config object to use + * @param group config group to use + */ + void startRestore (TDEConfig *config, const TQString &group); + + /** + * finish the restore + */ + void finishRestore (); + + /** + * save the current session config to given object and group + * @param config config object to use + * @param group config group to use + */ + void saveSession (TDEConfig *config, const TQString &group); + + /** + * internal data ;) + */ + private: + /** + * map identifiers to widgets + */ + TQDict<ToolView> m_idToWidget; + + /** + * list of all toolviews around + */ + TQValueList<ToolView*> m_toolviews; + + /** + * widget, which is the central part of the + * main window ;) + */ + TQWidget *m_centralWidget; + + /** + * horizontal splitter + */ + Splitter *m_hSplitter; + + /** + * vertical splitter + */ + Splitter *m_vSplitter; + + /** + * sidebars for the four sides + */ + Sidebar *m_sidebars[4]; + + /** + * sidebars state. + */ + bool m_sidebarsVisible; + + /** + * config object for session restore, only valid between + * start and finish restore calls + */ + TDEConfig *m_restoreConfig; + + /** + * restore group + */ + TQString m_restoreGroup; + + /** + * out guiclient + */ + GUIClient *m_guiClient; +}; + +} + +#endif + +// kate: space-indent on; indent-width 2; diff --git a/kate/app/katemwmodonhddialog.cpp b/kate/app/katemwmodonhddialog.cpp new file mode 100644 index 000000000..ab1418477 --- /dev/null +++ b/kate/app/katemwmodonhddialog.cpp @@ -0,0 +1,281 @@ +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2004, Anders Lund <anders@alweb.dk> +*/ + +#include "katemwmodonhddialog.h" +#include "katemwmodonhddialog.moc" + +#include "katedocmanager.h" + +#include <kate/document.h> + +#include <kiconloader.h> +#include <tdelistview.h> +#include <tdelocale.h> +#include <tdemessagebox.h> +#include <kprocio.h> +#include <krun.h> +#include <tdetempfile.h> +#include <kpushbutton.h> + +#include <tqlabel.h> +#include <tqlistview.h> +#include <tqlayout.h> +#include <tqpushbutton.h> +#include <tqwhatsthis.h> +#include <tqvbox.h> + +class KateDocItem : public TQCheckListItem +{ + public: + KateDocItem( Kate::Document *doc, const TQString &status, TDEListView *lv ) + : TQCheckListItem( lv, doc->url().prettyURL(), CheckBox ), + document( doc ) + { + setText( 1, status ); + if ( ! doc->isModified() ) + setOn( On ); + } + ~KateDocItem() {}; + + Kate::Document *document; +}; + + +KateMwModOnHdDialog::KateMwModOnHdDialog( DocVector docs, TQWidget *parent, const char *name ) + : KDialogBase( parent, name, true, i18n("Documents Modified on Disk"), + User1|User2|User3, User3, false, + KGuiItem (i18n("&Ignore"), "fileclose"), + KGuiItem (i18n("&Overwrite"), "filesave"), + KGuiItem (i18n("&Reload"), "reload") ) +{ + setButtonWhatsThis( User1, i18n( + "Removes the modified flag from the selected documents and closes the " + "dialog if there are no more unhandled documents.") ); + setButtonWhatsThis( User2, i18n( + "Overwrite selected documents, discarding the disk changes and closes the " + "dialog if there are no more unhandled documents.") ); + setButtonWhatsThis( User3, i18n( + "Reloads the selected documents from disk and closes the dialog if there " + "are no more unhandled documents.") ); + + TQVBox *w = makeVBoxMainWidget(); + w->setSpacing( KDialog::spacingHint() ); + + TQHBox *lo1 = new TQHBox( w ); + + // dialog text + TQLabel *icon = new TQLabel( lo1 ); + icon->setPixmap( DesktopIcon("messagebox_warning") ); + + TQLabel *t = new TQLabel( i18n( + "<qt>The documents listed below has changed on disk.<p>Select one " + "or more at the time and press an action button until the list is empty.</qt>"), lo1 ); + lo1->setStretchFactor( t, 1000 ); + + // document list + lvDocuments = new TDEListView( w ); + lvDocuments->addColumn( i18n("Filename") ); + lvDocuments->addColumn( i18n("Status on Disk") ); + lvDocuments->setSelectionMode( TQListView::Single ); + + TQStringList l; + l << "" << i18n("Modified") << i18n("Created") << i18n("Deleted"); + for ( uint i=0; i < docs.size(); i++ ) + new KateDocItem( docs[i], l[ (uint)KateDocManager::self()->documentInfo( docs[i] )->modifiedOnDiscReason ], lvDocuments ); + + connect( lvDocuments, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged()) ); + + // diff button + TQHBox *lo2 = new TQHBox ( w ); + TQWidget *d = new TQWidget (lo2); + lo2->setStretchFactor (d, 2); + btnDiff = new KPushButton( KGuiItem (i18n("&View Difference"), "edit"), lo2 ); + + TQWhatsThis::add( btnDiff, i18n( + "Calculates the difference between the the editor contents and the disk " + "file for the selected document, and shows the difference with the " + "default application. Requires diff(1).") ); + connect( btnDiff, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDiff()) ); + + slotSelectionChanged(); + m_tmpfile = 0; +} + +KateMwModOnHdDialog::~KateMwModOnHdDialog() +{ +} + +void KateMwModOnHdDialog::slotUser1() +{ + handleSelected( Ignore ); +} + +void KateMwModOnHdDialog::slotUser2() +{ + handleSelected( Overwrite ); +} + +void KateMwModOnHdDialog::slotUser3() +{ + handleSelected( Reload ); +} + +void KateMwModOnHdDialog::handleSelected( int action ) +{ + // collect all items we can remove + TQValueList<TQListViewItem *> itemsToDelete; + for ( TQListViewItemIterator it ( lvDocuments ); it.current(); ++it ) + { + KateDocItem *item = static_cast<KateDocItem *>(it.current()); + + if ( item->isOn() ) + { + int reason = (int)KateDocManager::self()->documentInfo( item->document )->modifiedOnDiscReason; + bool succes = true; + + Kate::DocumentExt *dext = documentExt( item->document ); + if ( ! dext ) continue; + + dext->setModifiedOnDisk( 0 ); + switch ( action ) + { + case Overwrite: + succes = item->document->save(); + if ( ! succes ) + { + KMessageBox::sorry( this, + i18n("Could not save the document \n'%1'"). + arg( item->document->url().prettyURL() ) ); + } + break; + + case Reload: + item->document->reloadFile(); + break; + + default: + break; + } + + if ( succes ) + itemsToDelete.append (item); + else + dext->setModifiedOnDisk( reason ); + } + } + + // remove the marked items + for (unsigned int i=0; i < itemsToDelete.count(); ++i) + delete itemsToDelete[i]; + + // any documents left unhandled? + if ( ! lvDocuments->childCount() ) + done( Ok ); +} + +void KateMwModOnHdDialog::slotSelectionChanged() +{ + // set the diff button enabled + btnDiff->setEnabled( lvDocuments->currentItem() && + KateDocManager::self()->documentInfo( ((KateDocItem*)lvDocuments->currentItem())->document )->modifiedOnDiscReason != 3 ); +} + +// ### the code below is slightly modified from tdelibs/kate/part/katedialogs, +// class KateModOnHdPrompt. +void KateMwModOnHdDialog::slotDiff() +{ + if ( m_tmpfile ) // we are allready somewhere in this process. + return; + + if ( ! lvDocuments->currentItem() ) + return; + + Kate::Document *doc = ((KateDocItem*)lvDocuments->currentItem())->document; + + // don't try o diff a deleted file + if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDiscReason == 3 ) + return; + + // Start a TDEProcess that creates a diff + KProcIO *p = new KProcIO(); + p->setComm( TDEProcess::All ); + *p << "diff" << "-u" << "-" << doc->url().path(); + connect( p, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(slotPDone(TDEProcess*)) ); + connect( p, TQT_SIGNAL(readReady(KProcIO*)), this, TQT_SLOT(slotPRead(KProcIO*)) ); + + setCursor( WaitCursor ); + + p->start( TDEProcess::NotifyOnExit, true ); + + uint lastln = doc->numLines(); + for ( uint l = 0; l < lastln; l++ ) + p->writeStdin( doc->textLine( l ), l < lastln ); + + p->closeWhenDone(); +} + +void KateMwModOnHdDialog::slotPRead( KProcIO *p) +{ + // create a file for the diff if we haven't one allready + if ( ! m_tmpfile ) + m_tmpfile = new KTempFile(); + // put all the data we have in it + TQString stmp; + bool dataRead = false; + while ( p->readln( stmp, false ) > -1 ) { + *m_tmpfile->textStream() << stmp << endl; + dataRead = true; + } + + if (dataRead) + p->ackRead(); +} + +void KateMwModOnHdDialog::slotPDone( TDEProcess *p ) +{ + setCursor( ArrowCursor ); + if( ! m_tmpfile ) + { + // dominik: there were only whitespace changes, so that the diff returned by + // diff(1) has 0 bytes. So slotPRead() is never called, as there is + // no data, so that m_tmpfile was never created and thus is NULL. + // NOTE: would be nice, if we could produce a fake-diff, so that kompare + // tells us "The files are identical". Right now, we get an ugly + // "Could not parse diff output". + m_tmpfile = new KTempFile(); + } + m_tmpfile->close(); + + if ( ! p->normalExit() /*|| p->exitStatus()*/ ) + { + KMessageBox::sorry( this, + i18n("The diff command failed. Please make sure that " + "diff(1) is installed and in your PATH."), + i18n("Error Creating Diff") ); + delete m_tmpfile; + m_tmpfile = 0; + return; + } + + KRun::runURL( m_tmpfile->name(), "text/x-diff", true ); + delete m_tmpfile; + m_tmpfile = 0; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemwmodonhddialog.h b/kate/app/katemwmodonhddialog.h new file mode 100644 index 000000000..3ae4d072a --- /dev/null +++ b/kate/app/katemwmodonhddialog.h @@ -0,0 +1,61 @@ +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2004, Anders Lund <anders@alweb.dk> +*/ + +#ifndef _KATE_MW_MODONHD_DIALOG_H_ +#define _KATE_MW_MODONHD_DIALOG_H_ + +#include <kdialogbase.h> +#include <tqptrvector.h> +#include <kate/document.h> + +typedef TQPtrVector<Kate::Document> DocVector; +class KProcIO; +class TDEProcess; +/** + * A dialog for handling multiple documents modified on disk + * from within KateMainWindow + */ +class KateMwModOnHdDialog : public KDialogBase +{ + Q_OBJECT + public: + KateMwModOnHdDialog( DocVector docs, TQWidget *parent=0, const char *name=0 ); + ~KateMwModOnHdDialog(); + + protected slots: + void slotUser1(); + void slotUser2(); + void slotUser3(); + + private slots: + void slotDiff(); + void slotSelectionChanged(); + void slotPRead(KProcIO*); + void slotPDone(TDEProcess*); + + private: + enum Action { Ignore, Overwrite, Reload }; + void handleSelected( int action ); + class TDEListView *lvDocuments; + class TQPushButton *btnDiff; + class KTempFile *m_tmpfile; +}; + +#endif // _KATE_MW_MODONHD_DIALOG_H_ +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katepluginmanager.cpp b/kate/app/katepluginmanager.cpp new file mode 100644 index 000000000..3e0a93f69 --- /dev/null +++ b/kate/app/katepluginmanager.cpp @@ -0,0 +1,220 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katepluginmanager.h" +#include "katepluginmanager.moc" + +#include "kateapp.h" +#include "katemainwindow.h" + +#include "../interfaces/application.h" + +#include <tdeconfig.h> +#include <tqstringlist.h> +#include <tdemessagebox.h> +#include <kdebug.h> +#include <tqfile.h> + +KatePluginManager::KatePluginManager(TQObject *parent) : TQObject (parent) +{ + m_pluginManager = new Kate::PluginManager (this); + setupPluginList (); + + loadConfig (); + loadAllEnabledPlugins (); +} + +KatePluginManager::~KatePluginManager() +{ + // first write config + writeConfig (); + + // than unload the plugins + unloadAllPlugins (); +} + +KatePluginManager *KatePluginManager::self() +{ + return KateApp::self()->pluginManager (); +} + +void KatePluginManager::setupPluginList () +{ + TQValueList<KService::Ptr> traderList= TDETrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))"); + + for(TDETrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it) + { + KService::Ptr ptr = (*it); + + TQString pVersion = ptr->property("X-Kate-Version").toString(); + + if (pVersion == "2.5") + { + KatePluginInfo info; + + info.load = false; + info.service = ptr; + info.plugin = 0L; + + m_pluginList.push_back (info); + } + } +} + +void KatePluginManager::loadConfig () +{ + KateApp::self()->config()->setGroup("Kate Plugins"); + + for (unsigned int i=0; i < m_pluginList.size(); ++i) + m_pluginList[i].load = KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->library(), false) || + KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->property("X-Kate-PluginName").toString(),false); +} + +void KatePluginManager::writeConfig () +{ + KateApp::self()->config()->setGroup("Kate Plugins"); + + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + TQString saveName=m_pluginList[i].service->property("X-Kate-PluginName").toString(); + + if (saveName.isEmpty()) + saveName = m_pluginList[i].service->library(); + + KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load); + } +} + +void KatePluginManager::loadAllEnabledPlugins () +{ + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + if (m_pluginList[i].load) + loadPlugin (&m_pluginList[i]); + else + unloadPlugin (&m_pluginList[i]); + } +} + +void KatePluginManager::unloadAllPlugins () +{ + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + if (m_pluginList[i].plugin) + unloadPlugin (&m_pluginList[i]); + } +} + +void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win) +{ + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + if (m_pluginList[i].load) + enablePluginGUI (&m_pluginList[i], win); + } +} + +void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win) +{ + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + if (m_pluginList[i].load) + disablePluginGUI (&m_pluginList[i], win); + } +} + +void KatePluginManager::loadPlugin (KatePluginInfo *item) +{ + TQString pluginName=item->service->property("X-Kate-PluginName").toString(); + + if (pluginName.isEmpty()) + pluginName=item->service->library(); + + item->load = (item->plugin = Kate::createPlugin (TQFile::encodeName(item->service->library()), Kate::application(), 0, pluginName)); +} + +void KatePluginManager::unloadPlugin (KatePluginInfo *item) +{ + disablePluginGUI (item); + if (item->plugin) delete item->plugin; + item->plugin = 0L; + item->load = false; +} + +void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win) +{ + if (!item->plugin) return; + if (!Kate::pluginViewInterface(item->plugin)) return; + + Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow()); +} + +void KatePluginManager::enablePluginGUI (KatePluginInfo *item) +{ + if (!item->plugin) return; + if (!Kate::pluginViewInterface(item->plugin)) return; + + for (uint i=0; i< KateApp::self()->mainWindows(); i++) + { + Kate::pluginViewInterface(item->plugin)->addView(KateApp::self()->mainWindow(i)->mainWindow()); + } +} + +void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win) +{ + if (!item->plugin) return; + if (!Kate::pluginViewInterface(item->plugin)) return; + + Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow()); +} + +void KatePluginManager::disablePluginGUI (KatePluginInfo *item) +{ + if (!item->plugin) return; + if (!Kate::pluginViewInterface(item->plugin)) return; + + for (uint i=0; i< KateApp::self()->mainWindows(); i++) + { + Kate::pluginViewInterface(item->plugin)->removeView(KateApp::self()->mainWindow(i)->mainWindow()); + } +} + +Kate::Plugin *KatePluginManager::plugin(const TQString &name) +{ + for (unsigned int i=0; i < m_pluginList.size(); ++i) + { + KatePluginInfo *info = &m_pluginList[i]; + TQString pluginName=info->service->property("X-Kate-PluginName").toString(); + if (pluginName.isEmpty()) + pluginName=info->service->library(); + if (pluginName==name) + { + if (info->plugin) + return info->plugin; + else + break; + } + } + return 0; +} + +bool KatePluginManager::pluginAvailable(const TQString &){return false;} +class Kate::Plugin *KatePluginManager::loadPlugin(const TQString &,bool ){return 0;} +void KatePluginManager::unloadPlugin(const TQString &,bool){;} diff --git a/kate/app/katepluginmanager.h b/kate/app/katepluginmanager.h new file mode 100644 index 000000000..1617c5501 --- /dev/null +++ b/kate/app/katepluginmanager.h @@ -0,0 +1,90 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_PLUGINMANAGER_H__ +#define __KATE_PLUGINMANAGER_H__ + +#include "katemain.h" + +#include "../interfaces/plugin.h" +#include "../interfaces/pluginmanager.h" + +#include <ktrader.h> + +#include <tqobject.h> +#include <tqvaluelist.h> + +class KatePluginInfo +{ + public: + bool load; + KService::Ptr service; + Kate::Plugin *plugin; +}; + +typedef TQValueList<KatePluginInfo> KatePluginList; + +class KatePluginManager : public TQObject +{ + Q_OBJECT + + public: + KatePluginManager(TQObject *parent); + ~KatePluginManager(); + + static KatePluginManager *self(); + + Kate::PluginManager *pluginManager () const { return m_pluginManager; }; + + void loadAllEnabledPlugins (); + void unloadAllPlugins (); + + void enableAllPluginsGUI (KateMainWindow *win); + void disableAllPluginsGUI (KateMainWindow *win); + + void loadConfig (); + void writeConfig (); + + void loadPlugin (KatePluginInfo *item); + void unloadPlugin (KatePluginInfo *item); + + void enablePluginGUI (KatePluginInfo *item, KateMainWindow *win); + void enablePluginGUI (KatePluginInfo *item); + + void disablePluginGUI (KatePluginInfo *item, KateMainWindow *win); + void disablePluginGUI (KatePluginInfo *item); + + inline KatePluginList & pluginList () { return m_pluginList; }; + + Kate::Plugin *plugin (const TQString &name); + bool pluginAvailable (const TQString &name); + + Kate::Plugin *loadPlugin (const TQString &name, bool permanent=true); + void unloadPlugin (const TQString &name, bool permanent=true); + + private: + Kate::PluginManager *m_pluginManager; + + void setupPluginList (); + + KatePluginList m_pluginList; +}; + +#endif diff --git a/kate/app/katesavemodifieddialog.cpp b/kate/app/katesavemodifieddialog.cpp new file mode 100644 index 000000000..a89fe57f8 --- /dev/null +++ b/kate/app/katesavemodifieddialog.cpp @@ -0,0 +1,226 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katesavemodifieddialog.h" +#include "katesavemodifieddialog.moc" + +#include <tdelocale.h> +#include <tqlistview.h> +#include <tdelistview.h> +#include <kguiitem.h> +#include <kactivelabel.h> +#include <kstdguiitem.h> +#include <tqvbox.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <kiconloader.h> +#include <tdemessagebox.h> +#include <kdebug.h> +#include <kencodingfiledialog.h> +#include <tdetexteditor/encodinginterface.h> + +class AbstractKateSaveModifiedDialogCheckListItem:public TQCheckListItem { +public: + AbstractKateSaveModifiedDialogCheckListItem(TQListViewItem *parent,const TQString& title, const TQString& url):TQCheckListItem(parent,title,TQCheckListItem::CheckBox) { + setText(1,url); + setOn(true); + setState(InitialState); + } + virtual ~AbstractKateSaveModifiedDialogCheckListItem() { + } + virtual bool synchronousSave(TQWidget *dialogParent)=0; + enum STATE{InitialState,SaveOKState,SaveFailedState}; + STATE state() const { return m_state;} + void setState(enum STATE state) { + m_state=state; + TDEIconLoader *loader = TDEGlobal::instance()->iconLoader(); + switch (state) { + case InitialState: + setPixmap(0,TQPixmap()); + break; + case SaveOKState: + setPixmap(0,loader->loadIcon("ok",TDEIcon::NoGroup,height())); + break; + case SaveFailedState: + setPixmap(0,loader->loadIcon("cancel",TDEIcon::NoGroup,height())); + break; + } + } +private: + STATE m_state; +}; + +class KateSaveModifiedDocumentCheckListItem:public AbstractKateSaveModifiedDialogCheckListItem { +public: + KateSaveModifiedDocumentCheckListItem(TQListViewItem *parent,Kate::Document *document):AbstractKateSaveModifiedDialogCheckListItem(parent,document->docName(),document->url().prettyURL()){ + m_document=document; + } + virtual ~KateSaveModifiedDocumentCheckListItem() { + } + virtual bool synchronousSave(TQWidget *dialogParent) { + if (m_document->url().isEmpty() ) { + KEncodingFileDialog::Result r=KEncodingFileDialog::getSaveURLAndEncoding( + KTextEditor::encodingInterface(m_document)->encoding(),TQString::null,TQString::null,dialogParent,i18n("Save As (%1)").arg(m_document->docName())); + + m_document->setEncoding( r.encoding ); + if (!r.URLs.isEmpty()) { + KURL tmp = r.URLs.first(); + if ( !m_document->saveAs( tmp ) ) { + setState(SaveFailedState); + setText(1,m_document->url().prettyURL()); + return false; + } else { + bool sc=m_document->waitSaveComplete(); + setText(1,m_document->url().prettyURL()); + if (!sc) { + setState(SaveFailedState); + return false; + } else { + setState(SaveOKState); + return true; + } + } + } else { + setState(SaveFailedState); + return false; + } + } else { //document has an exising location + if ( !m_document->save() ) { + setState(SaveFailedState); + setText(1,m_document->url().prettyURL()); + return false; + } else { + bool sc=m_document->waitSaveComplete(); + setText(1,m_document->url().prettyURL()); + if (!sc) { + setState(SaveFailedState); + return false; + } else { + setState(SaveOKState); + return true; + } + } + + } + + return false; + + } +private: + Kate::Document *m_document; +}; + +KateSaveModifiedDialog::KateSaveModifiedDialog(TQWidget *parent, TQPtrList<Kate::Document> documents): + KDialogBase( parent, "KateSaveModifiedDialog", true, i18n("Save Documents"), Yes | No | Cancel) { + + KGuiItem saveItem=KStdGuiItem::save(); + saveItem.setText(i18n("&Save Selected")); + setButtonGuiItem(KDialogBase::Yes,saveItem); + + setButtonGuiItem(KDialogBase::No,KStdGuiItem::dontSave()); + + KGuiItem cancelItem=KStdGuiItem::cancel(); + cancelItem.setText(i18n("&Abort Closing")); + setButtonGuiItem(KDialogBase::Cancel,cancelItem); + + TQVBox *box=makeVBoxMainWidget(); + new KActiveLabel(i18n("<qt>The following documents have been modified. Do you want to save them before closing?</qt>"),box); + m_list=new TDEListView(box); + m_list->addColumn(i18n("Title")); + m_list->addColumn(i18n("Location")); + m_list->setRootIsDecorated(true); + m_list->setResizeMode(TQListView::LastColumn); + if (0) { + m_projectRoot=new TQListViewItem(m_list,i18n("Projects")); + } else m_projectRoot=0; + if (documents.count()>0) { + m_documentRoot=new TQListViewItem(m_list,i18n("Documents")); + const uint docCnt=documents.count(); + for (uint i=0;i<docCnt;i++) { + new KateSaveModifiedDocumentCheckListItem(m_documentRoot,documents.at(i)); + } + m_documentRoot->setOpen(true); + } else m_documentRoot=0; + //FIXME - Is this the best way? + connect(m_list, TQT_SIGNAL(clicked(TQListViewItem *)), TQT_SLOT(slotItemSelected())); + connect(m_list, TQT_SIGNAL(doubleClicked(TQListViewItem *)), TQT_SLOT(slotItemSelected())); + connect(m_list, TQT_SIGNAL(spacePressed(TQListViewItem *)), TQT_SLOT(slotItemSelected())); + if(documents.count()>3) { //For 3 or less, it would be quicker just to tick or untick them yourself, so don't clutter the gui. + connect(new TQPushButton(i18n("Se&lect All"),box),TQT_SIGNAL(clicked()),this,TQT_SLOT(slotSelectAll())); + } +} + +KateSaveModifiedDialog::~KateSaveModifiedDialog() { +} + +void KateSaveModifiedDialog::slotItemSelected() { + kdDebug(13001) << "slotItemSelected()" << endl; + + for(TQListViewItem *it=m_documentRoot->firstChild();it;it=it->nextSibling()) { + if(((TQCheckListItem*)it)->isOn()) { + enableButton(KDialogBase::Yes, true); + return; + } + } + enableButton(KDialogBase::Yes, false); +} + +static void selectItems(TQListViewItem *root) { + if (!root) return; + for (TQListViewItem *it=root->firstChild();it;it=it->nextSibling()) { + ((TQCheckListItem*)it)->setOn(true); + } +} + +void KateSaveModifiedDialog::slotSelectAll() { + selectItems(m_documentRoot); + slotItemSelected(); +} + + +void KateSaveModifiedDialog::slotUser2() { + kdDebug(13001)<<"KateSaveModifiedDialog::slotYes()"<<endl; + if (doSave(m_documentRoot)) done(TQDialog::Accepted); +} + +void KateSaveModifiedDialog::slotUser1() { + done(TQDialog::Accepted); +} + +bool KateSaveModifiedDialog::doSave(TQListViewItem *root) { + if (root) { + for (TQListViewItem *it=root->firstChild();it;it=it->nextSibling()) { + AbstractKateSaveModifiedDialogCheckListItem *cit= (AbstractKateSaveModifiedDialogCheckListItem*)it; + if (cit->isOn() && (cit->state()!=AbstractKateSaveModifiedDialogCheckListItem::SaveOKState)) { + if (!cit->synchronousSave(this /*perhaps that should be the kate mainwindow*/)) { + KMessageBox::sorry( this, i18n("Data you requested to be saved could not be written. Please choose how you want to proceed.")); + return false; + } + } else if ((!cit->isOn()) && (cit->state()==AbstractKateSaveModifiedDialogCheckListItem::SaveFailedState)) { + cit->setState(AbstractKateSaveModifiedDialogCheckListItem::InitialState); + } + + } + } + return true; +} + +bool KateSaveModifiedDialog::queryClose(TQWidget *parent,TQPtrList<Kate::Document> documents) { + KateSaveModifiedDialog d(parent,documents); + return (d.exec()!=TQDialog::Rejected); +} diff --git a/kate/app/katesavemodifieddialog.h b/kate/app/katesavemodifieddialog.h new file mode 100644 index 000000000..92036c63c --- /dev/null +++ b/kate/app/katesavemodifieddialog.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KATE_SAVE_MODIFIED_DIALOG_ +#define _KATE_SAVE_MODIFIED_DIALOG_ + +#include <kdialogbase.h> +#include <kate/document.h> + +class TQListViewItem; +class TDEListView; + +class KateSaveModifiedDialog: public KDialogBase { + Q_OBJECT +public: + KateSaveModifiedDialog(TQWidget *parent, TQPtrList<Kate::Document> documents); + virtual ~KateSaveModifiedDialog(); + static bool queryClose(TQWidget *parent,TQPtrList<Kate::Document> documents); +protected: + virtual void slotUser2(); + virtual void slotUser1(); + bool doSave(TQListViewItem *root); +protected slots: + void slotSelectAll(); + void slotItemSelected(); + +private: + TQListViewItem *m_projectRoot; + TQListViewItem *m_documentRoot; + TDEListView *m_list; +}; + +#endif diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp new file mode 100644 index 000000000..ed6ee3f95 --- /dev/null +++ b/kate/app/katesession.cpp @@ -0,0 +1,920 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katesession.h" +#include "katesession.moc" + +#include "kateapp.h" +#include "katemainwindow.h" +#include "katedocmanager.h" + +#include <kstandarddirs.h> +#include <tdelocale.h> +#include <kdebug.h> +#include <kdirwatch.h> +#include <tdelistview.h> +#include <kinputdialog.h> +#include <kiconloader.h> +#include <tdemessagebox.h> +#include <kmdcodec.h> +#include <kstdguiitem.h> +#include <kpushbutton.h> +#include <tdepopupmenu.h> + +#include <tqdir.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqvbox.h> +#include <tqhbox.h> +#include <tqcheckbox.h> +#include <tqdatetime.h> +#include <tqmap.h> + +#include <unistd.h> +#include <time.h> + +bool operator<( const KateSession::Ptr& a, const KateSession::Ptr& b ) +{ + return a->sessionName().lower() < b->sessionName().lower(); +} + +KateSession::KateSession (KateSessionManager *manager, const TQString &fileName, const TQString &name) + : m_sessionFileRel (fileName) + , m_sessionName (name) + , m_documents (0) + , m_manager (manager) + , m_readConfig (0) + , m_writeConfig (0) +{ + init (); +} + +void KateSession::init () +{ + // given file exists, use it to load some stuff ;) + if (!m_sessionFileRel.isEmpty() && TDEGlobal::dirs()->exists(sessionFile ())) + { + KSimpleConfig config (sessionFile (), true); + + if (m_sessionName.isEmpty()) + { + // get the name out of the file + if (m_sessionFileRel == "default.katesession") + m_sessionName = i18n("Default Session"); + else + { + config.setGroup ("General"); + m_sessionName = config.readEntry ("Name", i18n ("Unnamed Session")); + } + } + + // get the document count + config.setGroup ("Open Documents"); + m_documents = config.readUnsignedNumEntry("Count", 0); + + return; + } + + // filename not empty, create the file + // anders: When will this ever happen??? + if (!m_sessionFileRel.isEmpty()) + { + kdDebug(13001)<<"Kate::Session: initializing unexisting file!"<<endl; + // uhh, no name given + if (m_sessionName.isEmpty()) + { + if (m_sessionFileRel == "default.katesession") + m_sessionName = i18n("Default Session"); + else + m_sessionName = i18n("Session (%1)").arg(TQTime::currentTime().toString(Qt::LocalDate)); + } + + // create the file, write name to it! + KSimpleConfig config (sessionFile ()); + config.setGroup ("General"); + config.writeEntry ("Name", m_sessionName); + + config.sync (); + } +} + +KateSession::~KateSession () +{ + delete m_readConfig; + delete m_writeConfig; +} + +TQString KateSession::sessionFile () const +{ + return m_manager->sessionsDir() + "/" + m_sessionFileRel; +} + +bool KateSession::create (const TQString &name, bool force) +{ + if (!force && (name.isEmpty() || !m_sessionFileRel.isEmpty())) + return false; + + delete m_writeConfig; + m_writeConfig = 0; + + delete m_readConfig; + m_readConfig = 0; + + m_sessionName = name; + + // get a usable filename + int s = time(0); + TQCString tname; + while (true) + { + tname.setNum (s++); + KMD5 md5 (tname); + m_sessionFileRel = TQString ("%1.katesession").arg (md5.hexDigest().data()); + + if (!TDEGlobal::dirs()->exists(sessionFile ())) + break; + } + + // create the file, write name to it! + KSimpleConfig config (sessionFile ()); + config.setGroup ("General"); + config.writeEntry ("Name", m_sessionName); + config.sync (); + + // reinit ourselfs ;) + init (); + + return true; +} + +bool KateSession::rename (const TQString &name) +{ + if (name.isEmpty () || m_sessionFileRel.isEmpty() || m_sessionFileRel == "default.katesession") + return false; + + m_sessionName = name; + + TDEConfig config (sessionFile (), false, false); + config.setGroup ("General"); + config.writeEntry ("Name", m_sessionName); + config.sync (); + + return true; +} + +TDEConfig *KateSession::configRead () +{ + if (m_sessionFileRel.isEmpty()) + return 0; + + if (m_readConfig) + return m_readConfig; + + return m_readConfig = new KSimpleConfig (sessionFile (), true); +} + +TDEConfig *KateSession::configWrite () +{ + if (m_sessionFileRel.isEmpty()) + return 0; + + if (m_writeConfig) + return m_writeConfig; + + m_writeConfig = new KSimpleConfig (sessionFile ()); + m_writeConfig->setGroup ("General"); + m_writeConfig->writeEntry ("Name", m_sessionName); + + return m_writeConfig; +} + +KateSessionManager::KateSessionManager (TQObject *parent) + : TQObject (parent) + , m_sessionsDir (locateLocal( "data", "kate/sessions")) + , m_activeSession (new KateSession (this, "", "")) +{ + kdDebug() << "LOCAL SESSION DIR: " << m_sessionsDir << endl; + + // create dir if needed + TDEGlobal::dirs()->makeDir (m_sessionsDir); +} + +KateSessionManager::~KateSessionManager() +{ +} + +KateSessionManager *KateSessionManager::self() +{ + return KateApp::self()->sessionManager (); +} + +void KateSessionManager::dirty (const TQString &) +{ + updateSessionList (); +} + +void KateSessionManager::updateSessionList () +{ + m_sessionList.clear (); + + // Let's get a list of all session we have atm + TQDir dir (m_sessionsDir, "*.katesession"); + + bool foundDefault = false; + for (unsigned int i=0; i < dir.count(); ++i) + { + KateSession *session = new KateSession (this, dir[i], ""); + m_sessionList.append (session); + + kdDebug () << "FOUND SESSION: " << session->sessionName() << " FILE: " << session->sessionFile() << endl; + + if (!foundDefault && (dir[i] == "default.katesession")) + foundDefault = true; + } + + // add default session, if not there + if (!foundDefault) + m_sessionList.append (new KateSession (this, "default.katesession", i18n("Default Session"))); + + qHeapSort(m_sessionList); +} + +void KateSessionManager::activateSession (KateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew) +{ + // don't reload. + // ### comparing the pointers directly is b0rk3d :( + if ( ! session->sessionName().isEmpty() && session->sessionName() == m_activeSession->sessionName() ) + return; + // try to close last session + if (closeLast) + { + if (KateApp::self()->activeMainWindow()) + { + if (!KateApp::self()->activeMainWindow()->queryClose_internal()) + return; + } + } + + // save last session or not? + if (saveLast) + saveActiveSession (true); + + // really close last + if (closeLast) + { + KateDocManager::self()->closeAllDocuments (); + } + + // set the new session + m_activeSession = session; + + if (loadNew) + { + // open the new session + Kate::Document::setOpenErrorDialogsActivated (false); + + TDEConfig *sc = activeSession()->configRead(); + + if (sc) + KateApp::self()->documentManager()->restoreDocumentList (sc); + + // if we have no session config object, try to load the default + // (anonymous/unnamed sessions) + if ( ! sc ) + sc = new KSimpleConfig( sessionsDir() + "/default.katesession" ); + + // window config + if (sc) + { + TDEConfig *c = KateApp::self()->config(); + c->setGroup("General"); + + if (c->readBoolEntry("Restore Window Configuration", true)) + { + // a new, named session, read settings of the default session. + if ( ! sc->hasGroup("Open MainWindows") ) + sc = new KSimpleConfig( sessionsDir() + "/default.katesession" ); + + sc->setGroup ("Open MainWindows"); + unsigned int wCount = sc->readUnsignedNumEntry("Count", 1); + + for (unsigned int i=0; i < wCount; ++i) + { + if (i >= KateApp::self()->mainWindows()) + { + KateApp::self()->newMainWindow(sc, TQString ("MainWindow%1").arg(i)); + } + else + { + sc->setGroup(TQString ("MainWindow%1").arg(i)); + KateApp::self()->mainWindow(i)->readProperties (sc); + } + } + + if (wCount > 0) + { + while (wCount < KateApp::self()->mainWindows()) + { + KateMainWindow *w = KateApp::self()->mainWindow(KateApp::self()->mainWindows()-1); + KateApp::self()->removeMainWindow (w); + delete w; + } + } + } + } + + Kate::Document::setOpenErrorDialogsActivated (true); + } +} + +KateSession::Ptr KateSessionManager::createSession (const TQString &name) +{ + KateSession::Ptr s = new KateSession (this, "", ""); + s->create (name); + + return s; +} + +KateSession::Ptr KateSessionManager::giveSession (const TQString &name) +{ + if (name.isEmpty()) + return new KateSession (this, "", ""); + + updateSessionList(); + + for (unsigned int i=0; i < m_sessionList.count(); ++i) + { + if (m_sessionList[i]->sessionName() == name) + return m_sessionList[i]; + } + + return createSession (name); +} + +bool KateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) +{ + if (tryAsk) + { + // app config + TDEConfig *c = KateApp::self()->config(); + c->setGroup("General"); + + TQString sesExit (c->readEntry ("Session Exit", "save")); + + if (sesExit == "discard") + return true; + + if (sesExit == "ask") + { + KDialogBase* dlg = new KDialogBase(i18n ("Save Session?") + , KDialogBase::Yes | KDialogBase::No + , KDialogBase::Yes, KDialogBase::No + ); + + bool dontAgain = false; + int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Question, + i18n("Save current session?"), TQStringList(), + i18n("Do not ask again"), &dontAgain, KMessageBox::Notify); + + // remember to not ask again with right setting + if (dontAgain) + { + c->setGroup("General"); + + if (res == KDialogBase::No) + c->writeEntry ("Session Exit", "discard"); + else + c->writeEntry ("Session Exit", "save"); + } + + if (res == KDialogBase::No) + return true; + } + } + + TDEConfig *sc = activeSession()->configWrite(); + + if (!sc) + return false; + + KateDocManager::self()->saveDocumentList (sc); + + sc->setGroup ("Open MainWindows"); + sc->writeEntry ("Count", KateApp::self()->mainWindows ()); + + // save config for all windows around ;) + for (unsigned int i=0; i < KateApp::self()->mainWindows (); ++i ) + { + sc->setGroup(TQString ("MainWindow%1").arg(i)); + KateApp::self()->mainWindow(i)->saveProperties (sc); + } + + sc->sync(); + + if (rememberAsLast) + { + TDEConfig *c = KateApp::self()->config(); + c->setGroup("General"); + c->writeEntry ("Last Session", activeSession()->sessionFileRelative()); + c->sync (); + } + + return true; +} + +bool KateSessionManager::chooseSession () +{ + bool success = true; + + // app config + TDEConfig *c = KateApp::self()->config(); + c->setGroup("General"); + + // get last used session, default to default session + TQString lastSession (c->readEntry ("Last Session", "default.katesession")); + TQString sesStart (c->readEntry ("Startup Session", "manual")); + + // uhh, just open last used session, show no chooser + if (sesStart == "last") + { + activateSession (new KateSession (this, lastSession, ""), false, false); + return success; + } + + // start with empty new session + if (sesStart == "new") + { + activateSession (new KateSession (this, "", ""), false, false); + return success; + } + + KateSessionChooser *chooser = new KateSessionChooser (0, lastSession); + + bool retry = true; + int res = 0; + while (retry) + { + res = chooser->exec (); + + switch (res) + { + case KateSessionChooser::resultOpen: + { + KateSession::Ptr s = chooser->selectedSession (); + + if (!s) + { + KMessageBox::error (chooser, i18n("No session selected to open."), i18n ("No Session Selected")); + break; + } + + activateSession (s, false, false); + retry = false; + break; + } + + // exit the app lateron + case KateSessionChooser::resultQuit: + success = false; + retry = false; + break; + + default: + activateSession (new KateSession (this, "", ""), false, false); + retry = false; + break; + } + } + + // write back our nice boolean :) + if (success && chooser->reopenLastSession ()) + { + c->setGroup("General"); + + if (res == KateSessionChooser::resultOpen) + c->writeEntry ("Startup Session", "last"); + else if (res == KateSessionChooser::resultNew) + c->writeEntry ("Startup Session", "new"); + + c->sync (); + } + + delete chooser; + + return success; +} + +void KateSessionManager::sessionNew () +{ + activateSession (new KateSession (this, "", "")); +} + +void KateSessionManager::sessionOpen () +{ + KateSessionOpenDialog *chooser = new KateSessionOpenDialog (0); + + int res = chooser->exec (); + + if (res == KateSessionOpenDialog::resultCancel) + { + delete chooser; + return; + } + + KateSession::Ptr s = chooser->selectedSession (); + + if (s) + activateSession (s); + + delete chooser; +} + +void KateSessionManager::sessionSave () +{ + // if the active session is valid, just save it :) + if (saveActiveSession ()) + return; + + bool ok = false; + TQString name = KInputDialog::getText (i18n("Specify Name for Current Session"), i18n("Session name:"), "", &ok); + + if (!ok) + return; + + if (name.isEmpty()) + { + KMessageBox::error (0, i18n("To save a new session, you must specify a name."), i18n ("Missing Session Name")); + return; + } + + activeSession()->create (name); + saveActiveSession (); +} + +void KateSessionManager::sessionSaveAs () +{ + bool ok = false; + TQString name = KInputDialog::getText (i18n("Specify New Name for Current Session"), i18n("Session name:"), "", &ok); + + if (!ok) + return; + + if (name.isEmpty()) + { + KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name")); + return; + } + + activeSession()->create (name, true); + saveActiveSession (); +} + + +void KateSessionManager::sessionManage () +{ + KateSessionManageDialog *dlg = new KateSessionManageDialog (0); + + dlg->exec (); + + delete dlg; +} + +//BEGIN CHOOSER DIALOG + +class KateSessionChooserItem : public TQListViewItem +{ + public: + KateSessionChooserItem (TDEListView *lv, KateSession::Ptr s) + : TQListViewItem (lv, s->sessionName()) + , session (s) + { + TQString docs; + docs.setNum (s->documents()); + setText (1, docs); + } + + KateSession::Ptr session; +}; + +KateSessionChooser::KateSessionChooser (TQWidget *parent, const TQString &lastSession) + : KDialogBase ( parent + , "" + , true + , i18n ("Session Chooser") + , KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3 + , KDialogBase::User2 + , true + , KStdGuiItem::quit () + , KGuiItem (i18n ("Open Session"), "fileopen") + , KGuiItem (i18n ("New Session"), "filenew") + ) +{ + TQHBox *page = new TQHBox (this); + page->setMinimumSize (400, 200); + setMainWidget(page); + + TQHBox *hb = new TQHBox (page); + hb->setSpacing (KDialog::spacingHint()); + + TQLabel *label = new TQLabel (hb); + label->setPixmap (UserIcon("sessionchooser")); + label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken); + + TQVBox *vb = new TQVBox (hb); + vb->setSpacing (KDialog::spacingHint()); + + m_sessions = new TDEListView (vb); + m_sessions->addColumn (i18n("Session Name")); + m_sessions->addColumn (i18n("Open Documents")); + m_sessions->setResizeMode (TQListView::AllColumns); + m_sessions->setSelectionMode (TQListView::Single); + m_sessions->setAllColumnsShowFocus (true); + + connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); + connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); + + KateSessionList &slist (KateSessionManager::self()->sessionList()); + for (unsigned int i=0; i < slist.count(); ++i) + { + KateSessionChooserItem *item = new KateSessionChooserItem (m_sessions, slist[i]); + + if (slist[i]->sessionFileRelative() == lastSession) + m_sessions->setSelected (item, true); + } + + m_useLast = new TQCheckBox (i18n ("&Always use this choice"), vb); + + setResult (resultNone); + + // trigger action update + selectionChanged (); +} + +KateSessionChooser::~KateSessionChooser () +{ +} + +KateSession::Ptr KateSessionChooser::selectedSession () +{ + KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + + if (!item) + return 0; + + return item->session; +} + +bool KateSessionChooser::reopenLastSession () +{ + return m_useLast->isChecked (); +} + +void KateSessionChooser::slotUser2 () +{ + done (resultOpen); +} + +void KateSessionChooser::slotUser3 () +{ + done (resultNew); +} + +void KateSessionChooser::slotUser1 () +{ + done (resultQuit); +} + +void KateSessionChooser::selectionChanged () +{ + enableButton (KDialogBase::User2, m_sessions->selectedItem ()); +} + +//END CHOOSER DIALOG + +//BEGIN OPEN DIALOG + +KateSessionOpenDialog::KateSessionOpenDialog (TQWidget *parent) + : KDialogBase ( parent + , "" + , true + , i18n ("Open Session") + , KDialogBase::User1 | KDialogBase::User2 + , KDialogBase::User2 + , false + , KStdGuiItem::cancel () + , KGuiItem( i18n("&Open"), "fileopen") + ) +{ + TQHBox *page = new TQHBox (this); + page->setMinimumSize (400, 200); + setMainWidget(page); + + TQHBox *hb = new TQHBox (page); + + TQVBox *vb = new TQVBox (hb); + + m_sessions = new TDEListView (vb); + m_sessions->addColumn (i18n("Session Name")); + m_sessions->addColumn (i18n("Open Documents")); + m_sessions->setResizeMode (TQListView::AllColumns); + m_sessions->setSelectionMode (TQListView::Single); + m_sessions->setAllColumnsShowFocus (true); + + connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); + + KateSessionList &slist (KateSessionManager::self()->sessionList()); + for (unsigned int i=0; i < slist.count(); ++i) + { + new KateSessionChooserItem (m_sessions, slist[i]); + } + + setResult (resultCancel); +} + +KateSessionOpenDialog::~KateSessionOpenDialog () +{ +} + +KateSession::Ptr KateSessionOpenDialog::selectedSession () +{ + KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + + if (!item) + return 0; + + return item->session; +} + +void KateSessionOpenDialog::slotUser1 () +{ + done (resultCancel); +} + +void KateSessionOpenDialog::slotUser2 () +{ + done (resultOk); +} + +//END OPEN DIALOG + +//BEGIN MANAGE DIALOG + +KateSessionManageDialog::KateSessionManageDialog (TQWidget *parent) + : KDialogBase ( parent + , "" + , true + , i18n ("Manage Sessions") + , KDialogBase::User1 + , KDialogBase::User1 + , false + , KStdGuiItem::close () + ) +{ + TQHBox *page = new TQHBox (this); + page->setMinimumSize (400, 200); + setMainWidget(page); + + TQHBox *hb = new TQHBox (page); + hb->setSpacing (KDialog::spacingHint()); + + m_sessions = new TDEListView (hb); + m_sessions->addColumn (i18n("Session Name")); + m_sessions->addColumn (i18n("Open Documents")); + m_sessions->setResizeMode (TQListView::AllColumns); + m_sessions->setSelectionMode (TQListView::Single); + m_sessions->setAllColumnsShowFocus (true); + + connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); + + updateSessionList (); + + TQWidget *vb = new TQWidget (hb); + TQVBoxLayout *vbl = new TQVBoxLayout (vb); + vbl->setSpacing (KDialog::spacingHint()); + + m_rename = new KPushButton (i18n("&Rename..."), vb); + connect (m_rename, TQT_SIGNAL(clicked()), this, TQT_SLOT(rename())); + vbl->addWidget (m_rename); + + m_del = new KPushButton (KStdGuiItem::del (), vb); + connect (m_del, TQT_SIGNAL(clicked()), this, TQT_SLOT(del())); + vbl->addWidget (m_del); + + vbl->addStretch (); + + // trigger action update + selectionChanged (); +} + +KateSessionManageDialog::~KateSessionManageDialog () +{ +} + +void KateSessionManageDialog::slotUser1 () +{ + done (0); +} + + +void KateSessionManageDialog::selectionChanged () +{ + KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + + m_rename->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); + m_del->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); +} + +void KateSessionManageDialog::rename () +{ + KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + + if (!item || item->session->sessionFileRelative() == "default.katesession") + return; + + bool ok = false; + TQString name = KInputDialog::getText (i18n("Specify New Name for Session"), i18n("Session name:"), item->session->sessionName(), &ok); + + if (!ok) + return; + + if (name.isEmpty()) + { + KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name")); + return; + } + + item->session->rename (name); + updateSessionList (); +} + +void KateSessionManageDialog::del () +{ + KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + + if (!item || item->session->sessionFileRelative() == "default.katesession") + return; + + TQFile::remove (item->session->sessionFile()); + KateSessionManager::self()->updateSessionList (); + updateSessionList (); +} + +void KateSessionManageDialog::updateSessionList () +{ + m_sessions->clear (); + + KateSessionList &slist (KateSessionManager::self()->sessionList()); + for (unsigned int i=0; i < slist.count(); ++i) + { + new KateSessionChooserItem (m_sessions, slist[i]); + } +} + +//END MANAGE DIALOG + + +KateSessionsAction::KateSessionsAction(const TQString& text, TQObject* parent, const char* name ) + : TDEActionMenu(text, parent, name) +{ + connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow())); +} + +void KateSessionsAction::slotAboutToShow() +{ + popupMenu()->clear (); + + KateSessionList &slist (KateSessionManager::self()->sessionList()); + for (unsigned int i=0; i < slist.count(); ++i) + { + popupMenu()->insertItem ( + slist[i]->sessionName(), + this, TQT_SLOT (openSession (int)), 0, + i ); + } +} + +void KateSessionsAction::openSession (int i) +{ + KateSessionList &slist (KateSessionManager::self()->sessionList()); + + if ((uint)i >= slist.count()) + return; + + KateSessionManager::self()->activateSession(slist[(uint)i]); +} +// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katesession.h b/kate/app/katesession.h new file mode 100644 index 000000000..b62e72a48 --- /dev/null +++ b/kate/app/katesession.h @@ -0,0 +1,418 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_SESSION_H__ +#define __KATE_SESSION_H__ + +#include "katemain.h" + +#include <kdialogbase.h> +#include <ksimpleconfig.h> +#include <ksharedptr.h> +#include <tdeaction.h> + +#include <tqobject.h> +#include <tqvaluelist.h> + +class KateSessionManager; + +class KDirWatch; +class TDEListView; +class KPushButton; + +class TQCheckBox; + +class KateSession : public TDEShared +{ + public: + /** + * Define a Shared-Pointer type + */ + typedef TDESharedPtr<KateSession> Ptr; + + public: + /** + * create a session from given file + * @param fileName session filename, relative + * @param name session name + * @param manager pointer to the manager + */ + KateSession (KateSessionManager *manager, const TQString &fileName, const TQString &name); + + /** + * init the session object, after construction or create + */ + void init (); + + /** + * destruct me + */ + ~KateSession (); + + /** + * session filename, absolute, calculated out of relative filename + session dir + * @return absolute path to session file + */ + TQString sessionFile () const; + + /** + * relative session filename + * @return relative filename for this session + */ + const TQString &sessionFileRelative () const { return m_sessionFileRel; } + + /** + * session name + * @return name for this session + */ + const TQString &sessionName () const { return m_sessionName; } + + /** + * is this a valid session? if not, don't use any session if this is + * the active one + */ + bool isNew () const { return m_sessionName.isEmpty(); } + + /** + * create the session file, if not existing + * @param name name for this session + * @param force force to create new file + * @return true if created, false if no creation needed + */ + bool create (const TQString &name, bool force = false); + + /** + * rename this session + * @param name new name + * @return success + */ + bool rename (const TQString &name); + + /** + * config to read + * on first access, will create the config object, delete will be done automagic + * return 0 if we have no file to read config from atm + * @return config to read from + */ + TDEConfig *configRead (); + + /** + * config to write + * on first access, will create the config object, delete will be done automagic + * return 0 if we have no file to write config to atm + * @return config to write from + */ + TDEConfig *configWrite (); + + /** + * count of documents in this session + * @return documents count + */ + unsigned int documents () const { return m_documents; } + + private: + /** + * session filename, in local location we can write to + * relative filename to the session dirs :) + */ + TQString m_sessionFileRel; + + /** + * session name, extracted from the file, to display to the user + */ + TQString m_sessionName; + + /** + * number of document of this session + */ + unsigned int m_documents; + + /** + * KateSessionMananger + */ + KateSessionManager *m_manager; + + /** + * simpleconfig to read from + */ + KSimpleConfig *m_readConfig; + + /** + * simpleconfig to write to + */ + KSimpleConfig *m_writeConfig; +}; + +typedef TQValueList<KateSession::Ptr> KateSessionList; + +class KateSessionManager : public TQObject +{ + Q_OBJECT + + public: + KateSessionManager(TQObject *parent); + ~KateSessionManager(); + + /** + * allow access to this :) + * @return instance of the session manager + */ + static KateSessionManager *self(); + + /** + * allow access to the session list + * kept up to date by watching the dir + */ + inline KateSessionList & sessionList () { updateSessionList (); return m_sessionList; } + + /** + * activate a session + * first, it will look if a session with this name exists in list + * if yes, it will use this session, else it will create a new session file + * @param session session to activate + * @param closeLast try to close last session or not? + * @param saveLast try to save last session or not? + * @param loadNew load new session stuff? + */ + void activateSession (KateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true); + + /** + * create a new session + * @param name session name + */ + KateSession::Ptr createSession (const TQString &name); + + /** + * return session with given name + * if no existing session matches, create new one with this name + * @param name session name + */ + KateSession::Ptr giveSession (const TQString &name); + + /** + * save current session + * for sessions without filename: save nothing + * @param tryAsk should we ask user if needed? + * @param rememberAsLast remember this session as last used? + * @return success + */ + bool saveActiveSession (bool tryAsk = false, bool rememberAsLast = false); + + /** + * return the current active session + * sessionFile == empty means we have no session around for this instance of kate + * @return session active atm + */ + inline KateSession::Ptr activeSession () { return m_activeSession; } + + /** + * session dir + * @return global session dir + */ + inline const TQString &sessionsDir () const { return m_sessionsDir; } + + /** + * initial session chooser, on app start + * @return success, if false, app should exit + */ + bool chooseSession (); + + public slots: + /** + * try to start a new session + * asks user first for name + */ + void sessionNew (); + + /** + * try to open a existing session + */ + void sessionOpen (); + + /** + * try to save current session + */ + void sessionSave (); + + /** + * try to save as current session + */ + void sessionSaveAs (); + + /** + * show dialog to manage our sessions + */ + void sessionManage (); + + private slots: + void dirty (const TQString &path); + + public: + /** + * trigger update of session list + */ + void updateSessionList (); + + private: + /** + * absolute path to dir in home dir where to store the sessions + */ + TQString m_sessionsDir; + + /** + * list of current available sessions + */ + KateSessionList m_sessionList; + + /** + * current active session + */ + KateSession::Ptr m_activeSession; +}; + +class KateSessionChooser : public KDialogBase +{ + Q_OBJECT + + public: + KateSessionChooser (TQWidget *parent, const TQString &lastSession); + ~KateSessionChooser (); + + KateSession::Ptr selectedSession (); + + bool reopenLastSession (); + + enum { + resultQuit = TQDialog::Rejected, + resultOpen, + resultNew, + resultNone + }; + + protected slots: + /** + * open session + */ + void slotUser1 (); + + /** + * new session + */ + void slotUser2 (); + + /** + * quit kate + */ + void slotUser3 (); + + /** + * selection has changed + */ + void selectionChanged (); + + private: + TDEListView *m_sessions; + TQCheckBox *m_useLast; +}; + +class KateSessionOpenDialog : public KDialogBase +{ + Q_OBJECT + + public: + KateSessionOpenDialog (TQWidget *parent); + ~KateSessionOpenDialog (); + + KateSession::Ptr selectedSession (); + + enum { + resultOk, + resultCancel + }; + + protected slots: + /** + * cancel pressed + */ + void slotUser1 (); + + /** + * ok pressed + */ + void slotUser2 (); + + private: + TDEListView *m_sessions; +}; + +class KateSessionManageDialog : public KDialogBase +{ + Q_OBJECT + + public: + KateSessionManageDialog (TQWidget *parent); + ~KateSessionManageDialog (); + + protected slots: + /** + * close pressed + */ + void slotUser1 (); + + /** + * selection has changed + */ + void selectionChanged (); + + /** + * try to rename session + */ + void rename (); + + /** + * try to delete session + */ + void del (); + + private: + /** + * update our list + */ + void updateSessionList (); + + private: + TDEListView *m_sessions; + KPushButton *m_rename; + KPushButton *m_del; +}; + +class KateSessionsAction : public TDEActionMenu +{ + Q_OBJECT + + public: + KateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0); + ~KateSessionsAction (){;}; + + public slots: + void slotAboutToShow(); + + void openSession (int i); +}; + +#endif diff --git a/kate/app/katetabwidget.cpp b/kate/app/katetabwidget.cpp new file mode 100644 index 000000000..e2ac7e8b3 --- /dev/null +++ b/kate/app/katetabwidget.cpp @@ -0,0 +1,161 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katetabwidget.h" +#include "katetabwidget.moc" + +#include <tqtabbar.h> + +//BEGIN KateTabWidget + +KateTabWidget::KateTabWidget(TQWidget* parent, const char* name) + : KTabWidget(parent,name) + , m_visibility (ShowWhenMoreThanOneTab) +{ + tabBar()->hide(); + + setHoverCloseButton(true); + + connect(this, TQT_SIGNAL(closeRequest(TQWidget*)), this, TQT_SLOT(closeTab(TQWidget*))); +} + +KateTabWidget::~KateTabWidget() +{ +} + +void KateTabWidget::closeTab(TQWidget* w) +{ + w->close(); +} + +void KateTabWidget::addTab ( TQWidget * child, const TQString & label ) +{ + KTabWidget::addTab(child,label); + showPage(child); + maybeShow(); +} + +void KateTabWidget::addTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label ) +{ + KTabWidget::addTab(child,iconset,label); + showPage(child); + maybeShow(); +} + +void KateTabWidget::addTab ( TQWidget * child, TQTab * tab ) +{ + KTabWidget::addTab(child,tab); + showPage(child); + maybeShow(); +} + +void KateTabWidget::insertTab ( TQWidget * child, const TQString & label, int index) +{ + KTabWidget::insertTab(child,label,index); + showPage(child); + maybeShow(); + tabBar()->repaint(); +} + +void KateTabWidget::insertTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label, int index ) +{ + KTabWidget::insertTab(child,iconset,label,index); + showPage(child); + maybeShow(); + tabBar()->repaint(); +} + +void KateTabWidget::insertTab ( TQWidget * child, TQTab * tab, int index) +{ + KTabWidget::insertTab(child,tab,index); + showPage(child); + maybeShow(); + tabBar()->repaint(); +} + +void KateTabWidget::removePage ( TQWidget * w ) +{ + KTabWidget::removePage(w); + maybeShow(); +} + +void KateTabWidget::maybeShow() +{ + switch (m_visibility) + { + case AlwaysShowTabs: + tabBar()->show(); + + // show/hide corner widgets + if (count() == 0) + setCornerWidgetVisibility(false); + else + setCornerWidgetVisibility(true); + + break; + + case ShowWhenMoreThanOneTab: + if (count()<2) tabBar()->hide(); + else tabBar()->show(); + + // show/hide corner widgets + if (count() < 2) + setCornerWidgetVisibility(false); + else + setCornerWidgetVisibility(true); + + break; + + case NeverShowTabs: + tabBar()->hide(); + break; + } +} + +void KateTabWidget::setCornerWidgetVisibility(bool visible) +{ + // there are two corner widgets: on TopLeft and on TopTight! + + if (cornerWidget(TQt::TopLeft) ) { + if (visible) + cornerWidget(TQt::TopLeft)->show(); + else + cornerWidget(TQt::TopLeft)->hide(); + } + + if (cornerWidget(TQt::TopRight) ) { + if (visible) + cornerWidget(TQt::TopRight)->show(); + else + cornerWidget(TQt::TopRight)->hide(); + } +} + +void KateTabWidget::setTabWidgetVisibility( TabWidgetVisibility visibility ) +{ + m_visibility = visibility; + maybeShow(); +} + +KateTabWidget::TabWidgetVisibility KateTabWidget::tabWidgetVisibility( ) const +{ + return m_visibility; +} + +//END KateTabWidget diff --git a/kate/app/katetabwidget.h b/kate/app/katetabwidget.h new file mode 100644 index 000000000..7e4327595 --- /dev/null +++ b/kate/app/katetabwidget.h @@ -0,0 +1,69 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_TABWIDGET_H__ +#define __KATE_TABWIDGET_H__ + +#include <ktabwidget.h> + +class KateTabWidget : public KTabWidget +{ + Q_OBJECT + + public: + enum TabWidgetVisibility { + AlwaysShowTabs = 0, + ShowWhenMoreThanOneTab = 1, + NeverShowTabs = 2 + }; + + public: + KateTabWidget(TQWidget* parent, const char* name=0); + virtual ~KateTabWidget(); + + virtual void addTab ( TQWidget * child, const TQString & label ); + + virtual void addTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label ); + + virtual void addTab ( TQWidget * child, TQTab * tab ); + + virtual void insertTab ( TQWidget * child, const TQString & label, int index = -1 ); + + virtual void insertTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label, int index = -1 ); + + virtual void insertTab ( TQWidget * child, TQTab * tab, int index = -1 ); + + virtual void removePage ( TQWidget * w ); + + TabWidgetVisibility tabWidgetVisibility() const; + + void setTabWidgetVisibility( TabWidgetVisibility ); + + private slots: + void closeTab(TQWidget* w); + + private: + void maybeShow(); + void setCornerWidgetVisibility(bool visible); + + private: + TabWidgetVisibility m_visibility; +}; + +#endif diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp new file mode 100644 index 000000000..ca361232a --- /dev/null +++ b/kate/app/kateviewmanager.cpp @@ -0,0 +1,514 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "kateviewmanager.h" +#include "kateviewmanager.moc" + +#include "katemainwindow.h" +#include "katedocmanager.h" +#include "kateviewspacecontainer.h" +#include "katetabwidget.h" + +#include <dcopclient.h> +#include <tdeaction.h> +#include <tdecmdlineargs.h> +#include <kdebug.h> +#include <tdediroperator.h> +#include <kdockwidget.h> +#include <kencodingfiledialog.h> +#include <kiconloader.h> +#include <tdeglobal.h> +#include <tdelocale.h> +#include <tdetoolbar.h> +#include <tdemessagebox.h> +#include <ksimpleconfig.h> +#include <kstdaction.h> +#include <kstandarddirs.h> +#include <tdeglobalsettings.h> +#include <tdestdaccel.h> + +#include <tdetexteditor/encodinginterface.h> + +#include <tqobjectlist.h> +#include <tqstringlist.h> +#include <tqfileinfo.h> +#include <tqtoolbutton.h> +#include <tqtooltip.h> +//END Includes + +KateViewManager::KateViewManager (KateMainWindow *parent) + : TQObject (parent), + showFullPath(false), m_mainWindow(parent) +{ + // while init + m_init=true; + + // some stuff for the tabwidget + m_mainWindow->tabWidget()->setTabReorderingEnabled( true ); + + // important, set them up, as we use them in other methodes + setupActions (); + + guiMergedView=0; + + m_viewManager = new Kate::ViewManager (this); + m_currentContainer=0; + connect(m_mainWindow->tabWidget(),TQT_SIGNAL(currentChanged(TQWidget*)),this,TQT_SLOT(tabChanged(TQWidget*))); + slotNewTab(); + tabChanged(m_mainWindow->tabWidget()->currentPage()); + + // no memleaks + m_viewSpaceContainerList.setAutoDelete(true); + + // init done + m_init=false; +} + +KateViewManager::~KateViewManager () +{ + m_viewSpaceContainerList.setAutoDelete(false); +} + +void KateViewManager::setupActions () +{ + TDEAction *a; + + /** + * tabbing + */ + a=new TDEAction ( i18n("New Tab"),"tab_new", 0, TQT_TQOBJECT(this), TQT_SLOT(slotNewTab()), + m_mainWindow->actionCollection(), "view_new_tab" ); + + m_closeTab = new TDEAction ( i18n("Close Current Tab"),"tab_remove",0,TQT_TQOBJECT(this),TQT_SLOT(slotCloseTab()), + m_mainWindow->actionCollection(),"view_close_tab"); + + m_activateNextTab + = new TDEAction( i18n( "Activate Next Tab" ), + TQApplication::reverseLayout() ? TDEStdAccel::tabPrev() : TDEStdAccel::tabNext(), + TQT_TQOBJECT(this), TQT_SLOT( activateNextTab() ), m_mainWindow->actionCollection(), "view_next_tab" ); + + m_activatePrevTab + = new TDEAction( i18n( "Activate Previous Tab" ), + TQApplication::reverseLayout() ? TDEStdAccel::tabNext() : TDEStdAccel::tabPrev(), + TQT_TQOBJECT(this), TQT_SLOT( activatePrevTab() ), m_mainWindow->actionCollection(), "view_prev_tab" ); + + /** + * view splitting + */ + a=new TDEAction ( i18n("Split Ve&rtical"), "view_right", CTRL+SHIFT+Key_L, TQT_TQOBJECT(this), TQT_SLOT( + slotSplitViewSpaceVert() ), m_mainWindow->actionCollection(), "view_split_vert"); + + a->setWhatsThis(i18n("Split the currently active view vertically into two views.")); + + a=new TDEAction ( i18n("Split &Horizontal"), "view_bottom", CTRL+SHIFT+Key_T, TQT_TQOBJECT(this), TQT_SLOT( + slotSplitViewSpaceHoriz() ), m_mainWindow->actionCollection(), "view_split_horiz"); + + a->setWhatsThis(i18n("Split the currently active view horizontally into two views.")); + + m_closeView = new TDEAction ( i18n("Cl&ose Current View"), "view_remove", CTRL+SHIFT+Key_R, TQT_TQOBJECT(this), + TQT_SLOT( slotCloseCurrentViewSpace() ), m_mainWindow->actionCollection(), + "view_close_current_space" ); + + m_closeView->setWhatsThis(i18n("Close the currently active splitted view")); + + goNext=new TDEAction(i18n("Next View"),Key_F8,TQT_TQOBJECT(this), + TQT_SLOT(activateNextView()),m_mainWindow->actionCollection(),"go_next"); + + goNext->setWhatsThis(i18n("Make the next split view the active one.")); + + goPrev=new TDEAction(i18n("Previous View"),SHIFT+Key_F8, TQT_TQOBJECT(this), TQT_SLOT(activatePrevView()),m_mainWindow->actionCollection(),"go_prev"); + + goPrev->setWhatsThis(i18n("Make the previous split view the active one.")); + + /** + * buttons for tabbing + */ + TQToolButton *b = new TQToolButton( m_mainWindow->tabWidget() ); + connect( b, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotNewTab() ) ); + b->setIconSet( SmallIcon( "tab_new" ) ); + b->adjustSize(); + TQToolTip::add(b, i18n("Open a new tab")); + m_mainWindow->tabWidget()->setCornerWidget( b, TopLeft ); + + b = m_closeTabButton = new TQToolButton( m_mainWindow->tabWidget() ); + connect( b, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotCloseTab() ) ); + b->setIconSet( SmallIcon( "tab_remove" ) ); + b->adjustSize(); + TQToolTip::add(b, i18n("Close the current tab")); + m_mainWindow->tabWidget()->setCornerWidget( b, TopRight ); +} + +void KateViewManager::updateViewSpaceActions () +{ + if (!m_currentContainer) return; + + m_closeView->setEnabled (m_currentContainer->viewSpaceCount() > 1); + goNext->setEnabled (m_currentContainer->viewSpaceCount() > 1); + goPrev->setEnabled (m_currentContainer->viewSpaceCount() > 1); +} + +void KateViewManager::tabChanged(TQWidget* widget) { + KateViewSpaceContainer *container=static_cast<KateViewSpaceContainer*>(widget->tqt_cast("KateViewSpaceContainer")); + Q_ASSERT(container); + m_currentContainer=container; + + if (container) { + container->reactivateActiveView(); + + } + + m_closeTab->setEnabled(m_mainWindow->tabWidget()->count() > 1); + m_activateNextTab->setEnabled(m_mainWindow->tabWidget()->count() > 1); + m_activatePrevTab->setEnabled(m_mainWindow->tabWidget()->count() > 1); + m_closeTabButton->setEnabled (m_mainWindow->tabWidget()->count() > 1); + + updateViewSpaceActions (); +} + +void KateViewManager::slotNewTab() +{ + uint documentNumber=0; + + if (m_currentContainer) + { + if (m_currentContainer->activeView()) + documentNumber = m_currentContainer->activeView()->getDoc()->documentNumber(); + } + + KateViewSpaceContainer *container=new KateViewSpaceContainer (m_mainWindow->tabWidget(), this); + m_viewSpaceContainerList.append(container); + m_mainWindow->tabWidget()->addTab (container, ""); + + connect(container,TQT_SIGNAL(viewChanged()),this,TQT_SIGNAL(viewChanged())); + connect(container,TQT_SIGNAL(viewChanged()),m_viewManager,TQT_SIGNAL(viewChanged())); + + if (!m_init) + { + container->activateView(documentNumber); + container->setShowFullPath(showFullPath); + m_mainWindow->slotWindowActivated (); + } +} + +void KateViewManager::slotCloseTab() +{ + if (m_viewSpaceContainerList.count() <= 1) return; + if (!m_currentContainer) return; + + int pos = m_viewSpaceContainerList.find (m_currentContainer); + + if (pos == -1) + return; + + if (guiMergedView) + m_mainWindow->guiFactory()->removeClient (guiMergedView ); + + m_viewSpaceContainerList.remove (pos); + + if ((uint)pos >= m_viewSpaceContainerList.count()) + pos = m_viewSpaceContainerList.count()-1; + + tabChanged(m_viewSpaceContainerList.at (pos)); +} + +void KateViewManager::activateNextTab() +{ + if( m_mainWindow->tabWidget()->count() <= 1 ) return; + + int iTab = m_mainWindow->tabWidget()->currentPageIndex(); + + iTab++; + + if( iTab == m_mainWindow->tabWidget()->count() ) + iTab = 0; + + m_mainWindow->tabWidget()->setCurrentPage( iTab ); +} + +void KateViewManager::activatePrevTab() +{ + if( m_mainWindow->tabWidget()->count() <= 1 ) return; + + int iTab = m_mainWindow->tabWidget()->currentPageIndex(); + + iTab--; + + if( iTab == -1 ) + iTab = m_mainWindow->tabWidget()->count() - 1; + + m_mainWindow->tabWidget()->setCurrentPage( iTab ); +} + +void KateViewManager::activateSpace (Kate::View* v) +{ + if (m_currentContainer) { + m_currentContainer->activateSpace(v); + } +} + +void KateViewManager::activateView ( Kate::View *view ) { + if (m_currentContainer) { + m_currentContainer->activateView(view); + } +} + +KateViewSpace* KateViewManager::activeViewSpace () +{ + if (m_currentContainer) { + return m_currentContainer->activeViewSpace(); + } + return 0L; +} + +Kate::View* KateViewManager::activeView () +{ + if (m_currentContainer) { + return m_currentContainer->activeView(); + } + return 0L; +} + +void KateViewManager::setActiveSpace ( KateViewSpace* vs ) +{ + if (m_currentContainer) { + m_currentContainer->setActiveSpace(vs); + } + +} + +void KateViewManager::setActiveView ( Kate::View* view ) +{ + if (m_currentContainer) { + m_currentContainer->setActiveView(view); + } + +} + + +void KateViewManager::activateView( uint documentNumber ) +{ + if (m_currentContainer) { + m_currentContainer->activateView(documentNumber); + } +} + +uint KateViewManager::viewCount () +{ + uint viewCount=0; + for (uint i=0;i<m_viewSpaceContainerList.count();i++) { + viewCount+=m_viewSpaceContainerList.at(i)->viewCount(); + } + return viewCount; + +} + +uint KateViewManager::viewSpaceCount () +{ + uint viewSpaceCount=0; + for (uint i=0;i<m_viewSpaceContainerList.count();i++) { + viewSpaceCount+=m_viewSpaceContainerList.at(i)->viewSpaceCount(); + } + return viewSpaceCount; +} + +void KateViewManager::setViewActivationBlocked (bool block) +{ + for (uint i=0;i<m_viewSpaceContainerList.count();i++) + m_viewSpaceContainerList.at(i)->m_blockViewCreationAndActivation=block; +} + +void KateViewManager::activateNextView() +{ + if (m_currentContainer) { + m_currentContainer->activateNextView(); + } +} + +void KateViewManager::activatePrevView() +{ + if (m_currentContainer) { + m_currentContainer->activatePrevView(); + } +} + +void KateViewManager::closeViews(uint documentNumber) +{ + for (uint i=0;i<m_viewSpaceContainerList.count();i++) { + m_viewSpaceContainerList.at(i)->closeViews(documentNumber); + } + tabChanged(m_currentContainer); +} + +void KateViewManager::slotDocumentNew () +{ + if (m_currentContainer) m_currentContainer->createView (); +} + +void KateViewManager::slotDocumentOpen () +{ + Kate::View *cv = activeView(); + + if (cv) { + KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding( + (cv ? KTextEditor::encodingInterface(cv->document())->encoding() : Kate::Document::defaultEncoding()), + (cv ? cv->document()->url().url() : TQString::null), + TQString::null,m_mainWindow,i18n("Open File")); + + uint lastID = 0; + for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i) + lastID = openURL( *i, r.encoding, false ); + + if (lastID > 0) + activateView (lastID); + } +} + +void KateViewManager::slotDocumentClose () +{ + // no active view, do nothing + if (!activeView()) return; + + // prevent close document if only one view alive and the document of + // it is not modified and empty !!! + if ( (KateDocManager::self()->documents() == 1) + && !activeView()->getDoc()->isModified() + && activeView()->getDoc()->url().isEmpty() + && (activeView()->getDoc()->length() == 0) ) + { + activeView()->getDoc()->closeURL(); + return; + } + + // close document + KateDocManager::self()->closeDocument (activeView()->getDoc()); +} + +uint KateViewManager::openURL (const KURL &url, const TQString& encoding, bool activate, bool isTempFile ) +{ + uint id = 0; + Kate::Document *doc = KateDocManager::self()->openURL (url, encoding, &id, isTempFile ); + + if (!doc->url().isEmpty()) + m_mainWindow->fileOpenRecent->addURL( doc->url() ); + + if (activate) + activateView( id ); + + return id; +} + +void KateViewManager::openURL (const KURL &url) +{ + openURL (url, TQString::null); +} + +void KateViewManager::removeViewSpace (KateViewSpace *viewspace) +{ + if (m_currentContainer) { + m_currentContainer->removeViewSpace(viewspace); + } +} + +void KateViewManager::slotCloseCurrentViewSpace() +{ + if (m_currentContainer) { + m_currentContainer->slotCloseCurrentViewSpace(); + } +} + +void KateViewManager::slotSplitViewSpaceVert() +{ + if (m_currentContainer) { + m_currentContainer->slotSplitViewSpaceVert(); + } +} + +void KateViewManager::slotSplitViewSpaceHoriz() +{ + if (m_currentContainer) { + m_currentContainer->slotSplitViewSpaceHoriz(); + } +} + +void KateViewManager::setShowFullPath( bool enable ) +{ + showFullPath=enable; + for (uint i=0;i<m_viewSpaceContainerList.count();i++) { + m_viewSpaceContainerList.at(i)->setShowFullPath(enable); + } + m_mainWindow->slotWindowActivated (); + } + +/** + * session config functions + */ +// FIXME 3.0 - make those config goups more streamlined: "objN:objN..." +void KateViewManager::saveViewConfiguration(TDEConfig *config,const TQString& grp) +{ + // Use the same group name for view configuration as usual for sessions. + // (When called by session manager grp is a 1-based index for the main window) + TQString group = grp; + bool ok = false; + int n = group.toInt( &ok ); + if ( ok ) + group = TQString( "MainWindow%1" ).arg( n-1 ); + + config->setGroup(group); + config->writeEntry("ViewSpaceContainers",m_viewSpaceContainerList.count()); + config->writeEntry("Active ViewSpaceContainer", m_mainWindow->tabWidget()->currentPageIndex()); + for (uint i=0;i<m_viewSpaceContainerList.count();i++) { + m_viewSpaceContainerList.at(i)->saveViewConfiguration(config,group+TQString(":ViewSpaceContainer-%1:").arg(i)); + } +} + +void KateViewManager::restoreViewConfiguration (TDEConfig *config, const TQString& grp) +{ + // Use the same group name for view configuration as usual for sessions. + // (When called by session manager grp is a 1-based index for the main window) + TQString group = grp; + bool ok = false; + int n = group.toInt( &ok ); + if ( ok ) + group = TQString( "MainWindow%1" ).arg( n-1 ); + + config->setGroup(group); + uint tabCount=config->readNumEntry("ViewSpaceContainers",0); + int activeOne=config->readNumEntry("Active ViewSpaceContainer",0); + if (tabCount==0) return; + m_viewSpaceContainerList.at(0)->restoreViewConfiguration(config,group+TQString(":ViewSpaceContainer-0:")); + for (uint i=1;i<tabCount;i++) { + slotNewTab(); + m_viewSpaceContainerList.at(i)->restoreViewConfiguration(config,group+TQString(":ViewSpaceContainer-%1:").arg(i)); + } + + if (activeOne != m_mainWindow->tabWidget()->currentPageIndex()) + m_mainWindow->tabWidget()->setCurrentPage (activeOne); + + updateViewSpaceActions(); +} + +KateMainWindow *KateViewManager::mainWindow() { + return m_mainWindow; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateviewmanager.h b/kate/app/kateviewmanager.h new file mode 100644 index 000000000..d16b59dc2 --- /dev/null +++ b/kate/app/kateviewmanager.h @@ -0,0 +1,154 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_VIEWMANAGER_H__ +#define __KATE_VIEWMANAGER_H__ + +#include "katemain.h" +#include "../interfaces/viewmanager.h" + +#include <kate/view.h> +#include <kate/document.h> +#include <tqguardedptr.h> + +class KateMainWindow; +class KateViewSpaceContainer; + +class TDEConfig; +class TDEAction; + +class TQToolButton; + +class KateViewManager : public TQObject +{ + Q_OBJECT + + public: + KateViewManager (KateMainWindow *parent); + ~KateViewManager (); + + Kate::ViewManager *viewManager () const { return m_viewManager; }; + + KateViewSpaceContainer *activeContainer () { return m_currentContainer; } + + TQPtrList<KateViewSpaceContainer> *containers() { return &m_viewSpaceContainerList; } + + void updateViewSpaceActions (); + + private: + /** + * create all actions needed for the view manager + */ + void setupActions (); + + public: + /* This will save the splitter configuration */ + void saveViewConfiguration(TDEConfig *config,const TQString& group); + + /* restore it */ + void restoreViewConfiguration (TDEConfig *config,const TQString& group); + + uint openURL (const KURL &url, const TQString& encoding, bool activate = true, bool isTempFile=false); + + public slots: + void openURL (const KURL &url); + + private: + void removeViewSpace (KateViewSpace *viewspace); + + bool showFullPath; + + public: + Kate::View* activeView (); + KateViewSpace* activeViewSpace (); + + uint viewCount (); + uint viewSpaceCount (); + + void setViewActivationBlocked (bool block); + + public: + void closeViews(uint documentNumber); + KateMainWindow *mainWindow(); + + private slots: + void activateView ( Kate::View *view ); + void activateSpace ( Kate::View* v ); + + void tabChanged(TQWidget*); + + public slots: + bool getShowFullPath() const { return showFullPath; } + + void activateView ( uint documentNumber ); + void activateView ( int documentNumber ) { activateView((uint) documentNumber); }; + + void slotDocumentNew (); + void slotDocumentOpen (); + void slotDocumentClose (); + + /** Splits the active viewspace horizontally */ + void slotSplitViewSpaceHoriz (); + /** Splits the active viewspace vertically */ + void slotSplitViewSpaceVert (); + + void slotNewTab(); + void slotCloseTab (); + void activateNextTab (); + void activatePrevTab (); + + void slotCloseCurrentViewSpace(); + + void setActiveSpace ( KateViewSpace* vs ); + void setActiveView ( Kate::View* view ); + + void setShowFullPath(bool enable); + + void activateNextView(); + void activatePrevView(); + + protected: + friend class KateViewSpaceContainer; + + TQGuardedPtr<Kate::View> guiMergedView; + + signals: + void statusChanged (Kate::View *, int, int, int, bool, int, const TQString &); + void statChanged (); + void viewChanged (); + + private: + Kate::ViewManager *m_viewManager; + TQPtrList<KateViewSpaceContainer> m_viewSpaceContainerList; + KateViewSpaceContainer *m_currentContainer; + + KateMainWindow *m_mainWindow; + bool m_init; + + TQToolButton *m_closeTabButton; + TDEAction *m_closeView; + TDEAction *m_closeTab; + TDEAction *m_activateNextTab; + TDEAction *m_activatePrevTab; + TDEAction *goNext; + TDEAction *goPrev; +}; + +#endif diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp new file mode 100644 index 000000000..ebc7a3b97 --- /dev/null +++ b/kate/app/kateviewspace.cpp @@ -0,0 +1,423 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001, 2005 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kateviewspace.h" +#include "kateviewspace.moc" + +#include "katemainwindow.h" +#include "kateviewspacecontainer.h" +#include "katedocmanager.h" +#include "kateapp.h" +#include "katesession.h" + +#include <kiconloader.h> +#include <tdelocale.h> +#include <ksqueezedtextlabel.h> +#include <tdeconfig.h> +#include <kdebug.h> + +#include <tqwidgetstack.h> +#include <tqpainter.h> +#include <tqlabel.h> +#include <tqcursor.h> +#include <tqpopupmenu.h> +#include <tqpixmap.h> + +//BEGIN KVSSBSep +/* + "KateViewSpaceStatusBarSeparator" + A 2 px line to separate the statusbar from the view. + It is here to compensate for the lack of a frame in the view, + I think Kate looks very nice this way, as TQScrollView with frame + looks slightly clumsy... + Slight 3D effect. I looked for suitable TQStyle props or methods, + but found none, though maybe it should use TQStyle::PM_DefaultFrameWidth + for height (TRY!). + It does look a bit funny with flat styles (Light, .Net) as is, + but there are on methods to paint panel lines separately. And, + those styles tends to look funny on their own, as a light line + in a 3D frame next to a light contents widget is not functional. + Also, TQStatusBar is up to now completely ignorant to style. + -anders +*/ +class KVSSBSep : public TQWidget { +public: + KVSSBSep( KateViewSpace *parent=0) : TQWidget(parent) + { + setFixedHeight( 2 ); + } +protected: + void paintEvent( TQPaintEvent *e ) + { + TQPainter p( this ); + p.setPen( colorGroup().shadow() ); + p.drawLine( e->rect().left(), 0, e->rect().right(), 0 ); + p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() ); + p.drawLine( e->rect().left(), 1, e->rect().right(), 1 ); + } +}; +//END KVSSBSep + +//BEGIN KateViewSpace +KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager, + TQWidget* parent, const char* name ) + : TQVBox(parent, name), + m_viewManager( viewManager ) +{ + mViewList.setAutoDelete(false); + + stack = new TQWidgetStack( this ); + setStretchFactor(stack, 1); + stack->setFocus(); + //sep = new KVSSBSep( this ); + mStatusBar = new KateVSStatusBar(this); + mIsActiveSpace = false; + mViewCount = 0; + + setMinimumWidth (mStatusBar->minimumWidth()); + m_group = TQString::null; +} + +KateViewSpace::~KateViewSpace() +{ +} + +void KateViewSpace::polish() +{ + mStatusBar->show(); +} + +void KateViewSpace::addView(Kate::View* v, bool show) +{ + // restore the config of this view if possible + if ( !m_group.isEmpty() ) + { + TQString fn = v->getDoc()->url().prettyURL(); + if ( ! fn.isEmpty() ) + { + TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); + + KateSession::Ptr as = KateSessionManager::self()->activeSession (); + if ( as->configRead() && as->configRead()->hasGroup( vgroup ) ) + { + as->configRead()->setGroup( vgroup ); + v->readSessionConfig ( as->configRead() ); + } + } + } + + uint id = mViewList.count(); + stack->addWidget(v, id); + if (show) { + mViewList.append(v); + showView( v ); + } + else { + Kate::View* c = mViewList.current(); + mViewList.prepend( v ); + showView( c ); + } +} + +void KateViewSpace::removeView(Kate::View* v) +{ + disconnect( v->getDoc(), TQT_SIGNAL(modifiedChanged()), + mStatusBar, TQT_SLOT(modifiedChanged()) ); + + bool active = ( v == currentView() ); + + mViewList.remove (v); + stack->removeWidget (v); + + if ( ! active ) + return; + + if (currentView() != 0L) + showView(mViewList.current()); + else if (mViewList.count() > 0) + showView(mViewList.last()); +} + +bool KateViewSpace::showView(Kate::View* v) +{ + return showView( v->getDoc()->documentNumber() ); +} + +bool KateViewSpace::showView(uint documentNumber) +{ + TQPtrListIterator<Kate::View> it (mViewList); + it.toLast(); + for( ; it.current(); --it ) { + if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) { + if ( currentView() ) + disconnect( currentView()->getDoc(), TQT_SIGNAL(modifiedChanged()), + mStatusBar, TQT_SLOT(modifiedChanged()) ); + + Kate::View* kv = it.current(); + connect( kv->getDoc(), TQT_SIGNAL(modifiedChanged()), + mStatusBar, TQT_SLOT(modifiedChanged()) ); + + mViewList.removeRef( kv ); + mViewList.append( kv ); + stack->raiseWidget( kv ); + kv->show(); + mStatusBar->modifiedChanged(); + return true; + } + } + return false; +} + + +Kate::View* KateViewSpace::currentView() +{ + if (mViewList.count() > 0) + return (Kate::View*)stack->visibleWidget(); + + return 0L; +} + +bool KateViewSpace::isActiveSpace() +{ + return mIsActiveSpace; +} + +void KateViewSpace::setActive( bool active, bool ) +{ + mIsActiveSpace = active; + + // change the statusbar palette and make sure it gets updated + TQPalette pal( palette() ); + if ( ! active ) + { + pal.setColor( TQColorGroup::Background, pal.active().mid() ); + pal.setColor( TQColorGroup::Light, pal.active().midlight() ); + } + + mStatusBar->setPalette( pal ); + mStatusBar->update(); + //sep->update(); +} + +bool KateViewSpace::event( TQEvent *e ) +{ + if ( e->type() == TQEvent::PaletteChange ) + { + setActive( mIsActiveSpace ); + return true; + } + return TQVBox::event( e ); +} + +void KateViewSpace::slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const TQString &msg) +{ + if ((TQWidgetStack *)view->parentWidget() != stack) + return; + mStatusBar->setStatus( r, c, ovr, block, mod, msg ); +} + +void KateViewSpace::saveConfig ( TDEConfig* config, int myIndex ,const TQString& viewConfGrp) +{ +// kdDebug()<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"<<endl; + TQString group = TQString(viewConfGrp+"-ViewSpace %1").arg( myIndex ); + + config->setGroup (group); + config->writeEntry ("Count", mViewList.count()); + + if (currentView()) + config->writeEntry( "Active View", currentView()->getDoc()->url().prettyURL() ); + + // Save file list, including cursor position in this instance. + TQPtrListIterator<Kate::View> it(mViewList); + + int idx = 0; + for (; it.current(); ++it) + { + if ( !it.current()->getDoc()->url().isEmpty() ) + { + long docListPos = it.current()->getDoc()->documentListPosition(); + config->setGroup( group ); + config->writeEntry( TQString("View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() ); + + // view config, group: "ViewSpace <n> url" + TQString vgroup = TQString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL()); + config->setGroup( vgroup ); + it.current()->writeSessionConfig( config ); + } + + idx++; + } +} + +void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char) +{ + if ( currentView() ) + mStatusBar->updateMod( currentView()->getDoc()->isModified() ); +} + +void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config, const TQString &group ) +{ + config->setGroup (group); + TQString fn = config->readEntry( "Active View" ); + + if ( !fn.isEmpty() ) + { + Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn)); + + if (doc) + { + // view config, group: "ViewSpace <n> url" + TQString vgroup = TQString("%1 %2").arg(group).arg(fn); + config->setGroup( vgroup ); + + viewMan->createView (doc); + + Kate::View *v = viewMan->activeView (); + + if (v) + v->readSessionConfig( config ); + } + } + + if (mViewList.isEmpty()) + viewMan->createView (KateDocManager::self()->document(0)); + + m_group = group; // used for restroing view configs later +} +//END KateViewSpace + +//BEGIN KateVSStatusBar +KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name ) + : KStatusBar( parent, name ), + m_viewSpace( parent ) +{ + m_lineColLabel = new TQLabel( this ); + addWidget( m_lineColLabel, 0, false ); + m_lineColLabel->setAlignment( Qt::AlignCenter ); + m_lineColLabel->installEventFilter( this ); + + m_modifiedLabel = new TQLabel( TQString(" "), this ); + addWidget( m_modifiedLabel, 0, false ); + m_modifiedLabel->setAlignment( Qt::AlignCenter ); + m_modifiedLabel->installEventFilter( this ); + + m_insertModeLabel = new TQLabel( i18n(" INS "), this ); + addWidget( m_insertModeLabel, 0, false ); + m_insertModeLabel->setAlignment( Qt::AlignCenter ); + m_insertModeLabel->installEventFilter( this ); + + m_selectModeLabel = new TQLabel( i18n(" NORM "), this ); + addWidget( m_selectModeLabel, 0, false ); + m_selectModeLabel->setAlignment( Qt::AlignCenter ); + m_selectModeLabel->installEventFilter( this ); + + m_fileNameLabel=new KSqueezedTextLabel( this ); + addWidget( m_fileNameLabel, 1, true ); + m_fileNameLabel->setMinimumSize( 0, 0 ); + m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed )); + m_fileNameLabel->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft ); + m_fileNameLabel->installEventFilter( this ); + + installEventFilter( this ); + m_modPm = SmallIcon("modified"); + m_modDiscPm = SmallIcon("modonhd"); + m_modmodPm = SmallIcon("modmod"); + m_noPm = SmallIcon("null"); +} + +KateVSStatusBar::~KateVSStatusBar () +{ +} + +void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int, const TQString &msg ) +{ + m_lineColLabel->setText( + i18n(" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0)) + .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) ); + + if (ovr == 0) + m_insertModeLabel->setText( i18n(" R/O ") ); + else if (ovr == 1) + m_insertModeLabel->setText( i18n(" OVR ") ); + else if (ovr == 2) + m_insertModeLabel->setText( i18n(" INS ") ); + +// updateMod( mod ); + + m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") ); + + m_fileNameLabel->setText( msg ); +} + +void KateVSStatusBar::updateMod( bool mod ) +{ + Kate::View *v = m_viewSpace->currentView(); + if ( v ) + { + const KateDocumentInfo *info + = KateDocManager::self()->documentInfo ( v->getDoc() ); + + bool modOnHD = info && info->modifiedOnDisc; + + m_modifiedLabel->setPixmap( + mod ? + info && modOnHD ? + m_modmodPm : + m_modPm : + info && modOnHD ? + m_modDiscPm : + m_noPm + ); + } +} + +void KateVSStatusBar::modifiedChanged() +{ + Kate::View *v = m_viewSpace->currentView(); + if ( v ) + updateMod( v->getDoc()->isModified() ); +} + +void KateVSStatusBar::showMenu() +{ + TDEMainWindow* mainWindow = static_cast<TDEMainWindow*>( topLevelWidget() ); + TQPopupMenu* menu = static_cast<TQPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) ); + + if (menu) + menu->exec(TQCursor::pos()); +} + +bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e) +{ + if (e->type()==TQEvent::MouseButtonPress) + { + if ( m_viewSpace->currentView() ) + m_viewSpace->currentView()->setFocus(); + + if ( ((TQMouseEvent*)e)->button()==Qt::RightButton) + showMenu(); + + return true; + } + + return false; +} +//END KateVSStatusBar +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateviewspace.h b/kate/app/kateviewspace.h new file mode 100644 index 000000000..0407d35fe --- /dev/null +++ b/kate/app/kateviewspace.h @@ -0,0 +1,121 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_VIEWSPACE_H__ +#define __KATE_VIEWSPACE_H__ + +#include "katemain.h" + +#include <kate/view.h> +#include <kate/document.h> + +#include <tqptrlist.h> +#include <tqwidget.h> +#include <tqvbox.h> +#include <kstatusbar.h> + +class KVSSBSep; + +class TDEConfig; +class KSqueezedTextLabel; +class KateViewSpaceContainer; + +class KateVSStatusBar : public KStatusBar +{ + Q_OBJECT + + public: + KateVSStatusBar ( KateViewSpace *parent = 0L, const char *name = 0L ); + virtual ~KateVSStatusBar (); + + public slots: + void setStatus( int r, int c, int ovr, bool block, int mod, const TQString &msg ); + void updateMod( bool ); + /** + * changed the modified icon according to document state. + * @since Kate 2.4 + */ + void modifiedChanged(); + + protected: + virtual bool eventFilter (TQObject*,TQEvent *); + virtual void showMenu (); + + private: + TQLabel* m_lineColLabel; + TQLabel* m_modifiedLabel; + TQLabel* m_insertModeLabel; + TQLabel* m_selectModeLabel; + KSqueezedTextLabel* m_fileNameLabel; + TQPixmap m_modPm, m_modDiscPm, m_modmodPm, m_noPm; + class KateViewSpace *m_viewSpace; +}; + +class KateViewSpace : public TQVBox +{ + friend class KateViewSpaceContainer; + friend class KateVSStatusBar; + + Q_OBJECT + + public: + KateViewSpace(KateViewSpaceContainer *, TQWidget* parent=0, const char* name=0); + ~KateViewSpace(); + bool isActiveSpace(); + void setActive(bool b, bool showled=false); + TQWidgetStack* stack; + void addView(Kate::View* v, bool show=true); + void removeView(Kate::View* v); + bool showView(Kate::View* v); + bool showView(uint docID); + Kate::View* currentView(); + int viewCount() const { return mViewList.count(); } + + void saveConfig (TDEConfig* config, int myIndex,const TQString& viewConfGrp); + void restoreConfig ( class KateViewSpaceContainer *viewMan, TDEConfig* config, const TQString &group ); + + + protected: + /** reimplemented to catch TQEvent::PaletteChange, + since we use a modified palette for the statusbar */ + bool event( TQEvent * ); + + private: + bool mIsActiveSpace; + KateVSStatusBar* mStatusBar; + TQLabel* l; + TQPixmap i_active; + TQPixmap i_empty; + TQPtrList<Kate::View> mViewList; + int mViewCount; + KVSSBSep *sep; + KateViewSpaceContainer *m_viewManager; + TQString m_group; + + private slots: + void slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const TQString &msg); + + public slots: + void polish(); + void modifiedOnDisc(Kate::Document *, bool, unsigned char); +}; + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateviewspacecontainer.cpp b/kate/app/kateviewspacecontainer.cpp new file mode 100644 index 000000000..de9309f5e --- /dev/null +++ b/kate/app/kateviewspacecontainer.cpp @@ -0,0 +1,758 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//BEGIN Includes +#include "kateviewspacecontainer.h" +#include "kateviewspacecontainer.moc" + +#include "katetabwidget.h" +#include "katemainwindow.h" +#include "katedocmanager.h" +#include "kateviewmanager.h" +#include "kateviewspace.h" + +#include <dcopclient.h> +#include <tdeaction.h> +#include <tdecmdlineargs.h> +#include <kdebug.h> +#include <tdediroperator.h> +#include <kdockwidget.h> +#include <kencodingfiledialog.h> +#include <kiconloader.h> +#include <tdeglobal.h> +#include <tdelocale.h> +#include <tdetoolbar.h> +#include <tdemessagebox.h> +#include <ksimpleconfig.h> +#include <kstdaction.h> +#include <kstandarddirs.h> +#include <tdeglobalsettings.h> +#include <kstringhandler.h> + +#include <tdetexteditor/encodinginterface.h> + +#include <tqlayout.h> +#include <tqobjectlist.h> +#include <tqstringlist.h> +#include <tqvbox.h> +#include <tqtimer.h> +#include <tqfileinfo.h> + +//END Includes + +KateViewSpaceContainer::KateViewSpaceContainer (TQWidget *parent, KateViewManager *viewManager) + : TQVBox (parent) + , m_viewManager(viewManager) + , m_blockViewCreationAndActivation (false) + , m_activeViewRunning (false) + , m_pendingViewCreation(false) +{ + // no memleaks + m_viewList.setAutoDelete(true); + m_viewSpaceList.setAutoDelete(true); + + KateViewSpace* vs = new KateViewSpace( this, this ); + connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString&)), vs, TQT_SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const TQString&))); + vs->setActive( true ); + m_viewSpaceList.append(vs); + connect( this, TQT_SIGNAL(viewChanged()), this, TQT_SLOT(slotViewChanged()) ); + connect(KateDocManager::self(), TQT_SIGNAL(initialDocumentReplaced()), this, TQT_SIGNAL(viewChanged())); + + connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)),this,TQT_SLOT(documentCreated(Kate::Document *))); + connect(KateDocManager::self(),TQT_SIGNAL(documentDeleted(uint)),this,TQT_SLOT(documentDeleted(uint))); +} + +KateViewSpaceContainer::~KateViewSpaceContainer () +{ + m_viewList.setAutoDelete(false); + m_viewSpaceList.setAutoDelete(false); +} + +void KateViewSpaceContainer::documentCreated (Kate::Document *doc) +{ + if (m_blockViewCreationAndActivation) return; + + if (!activeView()) + activateView (doc->documentNumber()); +} + +void KateViewSpaceContainer::documentDeleted (uint) +{ + if (m_blockViewCreationAndActivation) return; + + // just for the case we close a document out of many and this was the active one + // if all docs are closed, this will be handled by the documentCreated + if (!activeView() && (KateDocManager::self()->documents() > 0)) + createView (KateDocManager::self()->document(KateDocManager::self()->documents()-1)); +} + +bool KateViewSpaceContainer::createView ( Kate::Document *doc ) +{ + if (m_blockViewCreationAndActivation) return false; + + // create doc + if (!doc) + doc = KateDocManager::self()->createDoc (); + + // create view + Kate::View *view = (Kate::View *) doc->createView (this, 0L); + + m_viewList.append (view); + + // disable settings dialog action + view->actionCollection()->remove (view->actionCollection()->action( "set_confdlg" )); + + // popup menu + view->installPopup ((TQPopupMenu*)(mainWindow()->factory()->container("tdetexteditor_popup", mainWindow())) ); + + connect(view->getDoc(),TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(statusMsg())); + connect(view,TQT_SIGNAL(cursorPositionChanged()),this,TQT_SLOT(statusMsg())); + connect(view,TQT_SIGNAL(newStatus()),this,TQT_SLOT(statusMsg())); + connect(view->getDoc(), TQT_SIGNAL(undoChanged()), this, TQT_SLOT(statusMsg())); + connect(view,TQT_SIGNAL(dropEventPass(TQDropEvent *)), mainWindow(),TQT_SLOT(slotDropEvent(TQDropEvent *))); + connect(view,TQT_SIGNAL(gotFocus(Kate::View *)),this,TQT_SLOT(activateSpace(Kate::View *))); + + activeViewSpace()->addView( view ); + activateView( view ); + connect( doc, TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)), + activeViewSpace(), TQT_SLOT(modifiedOnDisc(Kate::Document *, bool, unsigned char)) ); + + return true; +} + +bool KateViewSpaceContainer::deleteView (Kate::View *view, bool delViewSpace) +{ + if (!view) return true; + + KateViewSpace *viewspace = (KateViewSpace *)view->parentWidget()->parentWidget(); + + viewspace->removeView (view); + + mainWindow()->guiFactory ()->removeClient (view); + + // remove view from list and memory !! + m_viewList.remove (view); + + if (delViewSpace) + if ( viewspace->viewCount() == 0 ) + removeViewSpace( viewspace ); + + return true; +} + +KateViewSpace* KateViewSpaceContainer::activeViewSpace () +{ + TQPtrListIterator<KateViewSpace> it(m_viewSpaceList); + + for (; it.current(); ++it) + { + if ( it.current()->isActiveSpace() ) + return it.current(); + } + + if (m_viewSpaceList.count() > 0) + { + m_viewSpaceList.first()->setActive( true ); + return m_viewSpaceList.first(); + } + + return 0L; +} + +Kate::View* KateViewSpaceContainer::activeView () +{ + if (m_activeViewRunning) + return 0L; + + m_activeViewRunning = true; + + for (TQPtrListIterator<Kate::View> it(m_viewList); it.current(); ++it) + { + if ( it.current()->isActive() ) + { + m_activeViewRunning = false; + return it.current(); + } + } + + // if we get to here, no view isActive() + // first, try to get one from activeViewSpace() + KateViewSpace* vs; + if ( (vs = activeViewSpace()) ) + { + if ( vs->currentView() ) + { + activateView (vs->currentView()); + + m_activeViewRunning = false; + return vs->currentView(); + } + } + + // last attempt: just pick first + if (m_viewList.count() > 0) + { + activateView (m_viewList.first()); + + m_activeViewRunning = false; + return m_viewList.first(); + } + + m_activeViewRunning = false; + + // no views exists! + return 0L; +} + +void KateViewSpaceContainer::setActiveSpace ( KateViewSpace* vs ) +{ + if (activeViewSpace()) + activeViewSpace()->setActive( false ); + + vs->setActive( true, viewSpaceCount() > 1 ); +} + +void KateViewSpaceContainer::setActiveView ( Kate::View* view ) +{ + if (activeView()) + activeView()->setActive( false ); + + view->setActive( true ); +} + +void KateViewSpaceContainer::activateSpace (Kate::View* v) +{ + if (!v) return; + + KateViewSpace* vs = (KateViewSpace*)v->parentWidget()->parentWidget(); + + if (!vs->isActiveSpace()) { + setActiveSpace (vs); + activateView(v); + } +} + +void KateViewSpaceContainer::reactivateActiveView() { + Kate::View *view=activeView(); + if (view) { + view->setActive(false); + activateView(view); + } else if (m_pendingViewCreation) { + m_pendingViewCreation=false; + disconnect(m_pendingDocument,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotPendingDocumentNameChanged())); + createView(m_pendingDocument); + } +} + +void KateViewSpaceContainer::activateView ( Kate::View *view ) +{ + if (!view) return; + + if (!view->isActive()) + { + if ( !activeViewSpace()->showView (view) ) + { + // since it wasn't found, give'em a new one + createView ( view->getDoc() ); + return; + } + + setActiveView (view); + m_viewList.findRef (view); + + mainWindow()->toolBar ()->setUpdatesEnabled (false); + + if (m_viewManager->guiMergedView) + mainWindow()->guiFactory()->removeClient (m_viewManager->guiMergedView ); + + m_viewManager->guiMergedView = view; + + if (!m_blockViewCreationAndActivation) + mainWindow()->guiFactory ()->addClient( view ); + + mainWindow()->toolBar ()->setUpdatesEnabled (true); + + statusMsg(); + + emit viewChanged (); + } + + KateDocManager::self()->setActiveDocument(view->getDoc()); +} + +void KateViewSpaceContainer::activateView( uint documentNumber ) +{ + if ( activeViewSpace()->showView(documentNumber) ) { + activateView( activeViewSpace()->currentView() ); + } + else + { + TQPtrListIterator<Kate::View> it(m_viewList); + for ( ;it.current(); ++it) + { + if ( it.current()->getDoc()->documentNumber() == documentNumber ) + { + createView( it.current()->getDoc() ); + return; + } + } + + Kate::Document *d = (Kate::Document *)KateDocManager::self()->documentWithID(documentNumber); + createView (d); + } +} + +uint KateViewSpaceContainer::viewCount () +{ + return m_viewList.count(); +} + +uint KateViewSpaceContainer::viewSpaceCount () +{ + return m_viewSpaceList.count(); +} + +void KateViewSpaceContainer::slotViewChanged() +{ + if ( activeView() && !activeView()->hasFocus()) + activeView()->setFocus(); +} + +void KateViewSpaceContainer::activateNextView() +{ + uint i = m_viewSpaceList.find (activeViewSpace())+1; + + if (i >= m_viewSpaceList.count()) + i=0; + + setActiveSpace (m_viewSpaceList.at(i)); + activateView(m_viewSpaceList.at(i)->currentView()); +} + +void KateViewSpaceContainer::activatePrevView() +{ + int i = m_viewSpaceList.find (activeViewSpace())-1; + + if (i < 0) + i=m_viewSpaceList.count()-1; + + setActiveSpace (m_viewSpaceList.at(i)); + activateView(m_viewSpaceList.at(i)->currentView()); +} + +void KateViewSpaceContainer::closeViews(uint documentNumber) +{ + TQPtrList<Kate::View> closeList; + + for (uint z=0 ; z < m_viewList.count(); z++) + { + Kate::View* current = m_viewList.at(z); + if ( current->getDoc()->documentNumber() == documentNumber ) + { + closeList.append (current); + } + } + + while ( !closeList.isEmpty() ) + { + Kate::View *view = closeList.first(); + deleteView (view, true); + closeList.removeFirst(); + } + + if (m_blockViewCreationAndActivation) return; + TQTimer::singleShot(0,this,TQT_SIGNAL(viewChanged())); + //emit m_viewManager->viewChanged (); +} + +void KateViewSpaceContainer::slotPendingDocumentNameChanged() { + TQString c; + if (m_pendingDocument->url().isEmpty() || (!showFullPath)) + { + c = m_pendingDocument->docName(); + } + else + { + c = m_pendingDocument->url().prettyURL(); + } + setCaption(KStringHandler::lsqueeze(c,32)); +} + +void KateViewSpaceContainer::statusMsg () +{ + if (!activeView()) return; + + Kate::View* v = activeView(); + + bool readOnly = !v->getDoc()->isReadWrite(); + uint config = v->getDoc()->configFlags(); + + int ovr = 0; + if (readOnly) + ovr = 0; + else + { + if (config & Kate::Document::cfOvr) + { + ovr=1; + } + else + { + ovr=2; + } + } + + int mod = (int)v->getDoc()->isModified(); + bool block=v->getDoc()->blockSelectionMode(); + + TQString c; + if (v->getDoc()->url().isEmpty() || (!showFullPath)) + { + c = v->getDoc()->docName(); + } + else + { + c = v->getDoc()->url().prettyURL(); + } + + m_viewManager->mainWindow()->tabWidget()->changeTab (this, KStringHandler::lsqueeze(c,32)); + emit statusChanged (v, v->cursorLine(), v->cursorColumn(), ovr,block, mod, KStringHandler::lsqueeze(c,64)); + emit statChanged (); +} + +void KateViewSpaceContainer::splitViewSpace( KateViewSpace* vs, + bool isHoriz, + bool atTop) +{ +// kdDebug(13001)<<"splitViewSpace()"<<endl; + + if (!activeView()) return; + if (!vs) vs = activeViewSpace(); + + bool isFirstTime = vs->parentWidget() == this; + + TQValueList<int> psizes; + if ( ! isFirstTime ) + if ( TQSplitter *ps = static_cast<TQSplitter*>(vs->parentWidget()->tqt_cast(TQSPLITTER_OBJECT_NAME_STRING)) ) + psizes = ps->sizes(); + + Qt::Orientation o = isHoriz ? Qt::Vertical : Qt::Horizontal; + KateMDI::Splitter* s = new KateMDI::Splitter(o, vs->parentWidget()); + s->setOpaqueResize( TDEGlobalSettings::opaqueResize() ); + + if (! isFirstTime) { + // anders: make sure the split' viewspace is always + // correctly positioned. + // If viewSpace is the first child, the new splitter must be moveToFirst'd + if ( !((KateMDI::Splitter*)vs->parentWidget())->isLastChild( vs ) ) + ((KateMDI::Splitter*)s->parentWidget())->moveToFirst( s ); + } + vs->reparent( s, 0, TQPoint(), true ); + KateViewSpace* vsNew = new KateViewSpace( this, s ); + + if (atTop) + s->moveToFirst( vsNew ); + + if (!isFirstTime) + if (TQSplitter *ps = static_cast<TQSplitter*>(s->parentWidget()->tqt_cast(TQSPLITTER_OBJECT_NAME_STRING)) ) + ps->setSizes( psizes ); + + s->show(); + + TQValueList<int> sizes; + int space = 50;//isHoriz ? s->parentWidget()->height()/2 : s->parentWidget()->width()/2; + sizes << space << space; + s->setSizes( sizes ); + + connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString &)), vsNew, TQT_SLOT(slotStatusChanged(Kate::View *, int, int,int, bool, int, const TQString &))); + m_viewSpaceList.append( vsNew ); + activeViewSpace()->setActive( false ); + vsNew->setActive( true, true ); + vsNew->show(); + + createView (activeView()->getDoc()); + + if (this == m_viewManager->activeContainer()) + m_viewManager->updateViewSpaceActions (); + +// kdDebug(13001)<<"splitViewSpace() - DONE!"<<endl; +} + +void KateViewSpaceContainer::removeViewSpace (KateViewSpace *viewspace) +{ + // abort if viewspace is 0 + if (!viewspace) return; + + // abort if this is the last viewspace + if (m_viewSpaceList.count() < 2) return; + + KateMDI::Splitter* p = (KateMDI::Splitter*)viewspace->parentWidget(); + + // find out if it is the first child for repositioning + // see below + bool pIsFirst = false; + + // save some size information + KateMDI::Splitter* pp=0L; + TQValueList<int> ppsizes; + if (m_viewSpaceList.count() > 2 && p->parentWidget() != this) + { + pp = (KateMDI::Splitter*)p->parentWidget(); + ppsizes = pp->sizes(); + pIsFirst = !pp->isLastChild( p ); // simple logic, right- + } + + // Figure out where to put views that are still needed + KateViewSpace* next; + if (m_viewSpaceList.find(viewspace) == 0) + next = m_viewSpaceList.next(); + else + next = m_viewSpaceList.prev(); + + // Reparent views in viewspace that are last views, delete the rest. + int vsvc = viewspace->viewCount(); + while (vsvc > 0) + { + if (viewspace->currentView()) + { + Kate::View* v = viewspace->currentView(); + + if (v->isLastView()) + { + viewspace->removeView(v); + next->addView( v, false ); + } + else + { + deleteView( v, false ); + } + } + vsvc = viewspace->viewCount(); + } + + m_viewSpaceList.remove( viewspace ); + + // reparent the other sibling of the parent. + while (!p->childrenListObject().isEmpty()) + { + TQWidget* other = ((TQWidget *)(( TQPtrList<TQObject>)p->childrenListObject()).first()); + + other->reparent( p->parentWidget(), 0, TQPoint(), true ); + // We also need to find the right viewspace to become active + if (pIsFirst) + ((KateMDI::Splitter*)p->parentWidget())->moveToFirst( other ); + if ( other->isA("KateViewSpace") ) { + setActiveSpace( (KateViewSpace*)other ); + } + else { + TQObjectList* l = other->queryList( "KateViewSpace" ); + if ( l->first() != 0 ) { // I REALLY hope so! + setActiveSpace( (KateViewSpace*)l->first() ); + } + delete l; + } + } + + delete p; + + if (!ppsizes.isEmpty()) + pp->setSizes( ppsizes ); + + // find the view that is now active. + Kate::View* v = activeViewSpace()->currentView(); + if ( v ) + activateView( v ); + + if (this == m_viewManager->activeContainer()) + m_viewManager->updateViewSpaceActions (); + + emit viewChanged(); +} + +void KateViewSpaceContainer::slotCloseCurrentViewSpace() +{ + removeViewSpace(activeViewSpace()); +} + +void KateViewSpaceContainer::setShowFullPath( bool enable ) +{ + showFullPath = enable; + statusMsg (); + //m_mainWindow->slotWindowActivated (); +} + +/** + * session config functions + */ + +void KateViewSpaceContainer::saveViewConfiguration(TDEConfig *config,const TQString& group) +{ + bool weHaveSplittersAlive (viewSpaceCount() > 1); + + config->setGroup (group); //"View Configuration"); + config->writeEntry ("Splitters", weHaveSplittersAlive); + + // no splitters around + if (!weHaveSplittersAlive) + { + config->writeEntry("Active Viewspace", 0); + m_viewSpaceList.first()->saveConfig ( config, 0,group ); + + return; + } + + // I need the first splitter, the one which has this as parent. + KateMDI::Splitter* s; + TQObjectList *l = queryList("KateMDI::Splitter", 0, false, false); + TQObjectListIt it( *l ); + + if ( (s = (KateMDI::Splitter*)it.current()) != 0 ) + saveSplitterConfig( s, 0, config , group); + + delete l; +} + +void KateViewSpaceContainer::restoreViewConfiguration (TDEConfig *config, const TQString& group) +{ + config->setGroup(group); + //config->setGroup ("View Configuration"); + + // no splitters around, ohhh :() + if (!config->readBoolEntry ("Splitters")) + { + // only add the new views needed, let the old stay, won't hurt if one around + m_viewSpaceList.first ()->restoreConfig (this, config, TQString(group+"-ViewSpace 0")); + } + else + { + // send all views + their gui to **** ;) + for (uint i=0; i < m_viewList.count(); i++) + mainWindow()->guiFactory ()->removeClient (m_viewList.at(i)); + + m_viewList.clear (); + + // cu viewspaces + m_viewSpaceList.clear(); + + // call restoreSplitter for Splitter 0 + restoreSplitter( config, TQString(group+"-Splitter 0"), this,group ); + } + + // finally, make the correct view active. + config->setGroup (group); +/* + KateViewSpace *vs = m_viewSpaceList.at( config->readNumEntry("Active ViewSpace") ); + if ( vs ) + activateSpace( vs->currentView() ); + */ +} + + +void KateViewSpaceContainer::saveSplitterConfig( KateMDI::Splitter* s, int idx, TDEConfig* config, const TQString& viewConfGrp ) +{ + TQString grp = TQString(viewConfGrp+"-Splitter %1").arg(idx); + config->setGroup(grp); + + // Save sizes, orient, children for this splitter + config->writeEntry( "Sizes", s->sizes() ); + config->writeEntry( "Orientation", s->orientation() ); + + TQStringList childList; + // a katesplitter has two children, of which one may be a KateSplitter. + const TQObjectList l = s->childrenListObject(); + TQObjectListIt it( l ); + TQObject* obj; + for (; it.current(); ++it) { + obj = it.current(); + TQString n; // name for child list, see below + // For KateViewSpaces, ask them to save the file list. + if ( obj->isA("KateViewSpace") ) { + n = TQString(viewConfGrp+"-ViewSpace %1").arg( m_viewSpaceList.find((KateViewSpace*)obj) ); + ((KateViewSpace*)obj)->saveConfig ( config, m_viewSpaceList.find((KateViewSpace*)obj), viewConfGrp); + // save active viewspace + if ( ((KateViewSpace*)obj)->isActiveSpace() ) { + config->setGroup(viewConfGrp); + config->writeEntry("Active Viewspace", m_viewSpaceList.find((KateViewSpace*)obj) ); + } + } + // For KateSplitters, recurse + else if ( obj->isA("KateMDI::Splitter") ) { + idx++; + saveSplitterConfig( (KateMDI::Splitter*)obj, idx, config,viewConfGrp); + n = TQString(viewConfGrp+"-Splitter %1").arg( idx ); + } + // make sure list goes in right place! + if (!n.isEmpty()) { + if ( childList.count() > 0 && ! s->isLastChild( (TQWidget*)obj ) ) + childList.prepend( n ); + else + childList.append( n ); + } + } + + // reset config group. + config->setGroup(grp); + config->writeEntry("Children", childList); +} + +void KateViewSpaceContainer::restoreSplitter( TDEConfig* config, const TQString &group, TQWidget* parent, const TQString& viewConfGrp) +{ + config->setGroup( group ); + + KateMDI::Splitter* s = new KateMDI::Splitter((Qt::Orientation)config->readNumEntry("Orientation"), parent); + + TQStringList children = config->readListEntry( "Children" ); + for (TQStringList::Iterator it=children.begin(); it!=children.end(); ++it) + { + // for a viewspace, create it and open all documents therein. + if ( (*it).startsWith(viewConfGrp+"-ViewSpace") ) + { + KateViewSpace* vs = new KateViewSpace( this, s ); + + connect(this, TQT_SIGNAL(statusChanged(Kate::View *, int, int, int, bool, int, const TQString &)), vs, TQT_SLOT(slotStatusChanged(Kate::View *, int, int, int, bool, int, const TQString &))); + + if (m_viewSpaceList.isEmpty()) + vs->setActive (true); + + m_viewSpaceList.append( vs ); + + vs->show(); + setActiveSpace( vs ); + + vs->restoreConfig (this, config, *it); + } + else + { + // for a splitter, recurse. + restoreSplitter( config, TQString(*it), s, viewConfGrp ); + } + } + + // set sizes + config->setGroup( group ); + s->setSizes( config->readIntListEntry("Sizes") ); + s->show(); +} + +KateMainWindow *KateViewSpaceContainer::mainWindow() { + return m_viewManager->mainWindow(); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/kateviewspacecontainer.h b/kate/app/kateviewspacecontainer.h new file mode 100644 index 000000000..2f1fa5372 --- /dev/null +++ b/kate/app/kateviewspacecontainer.h @@ -0,0 +1,161 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_VIEWSPACE_CONTAINER_H__ +#define __KATE_VIEWSPACE_CONTAINER_H__ + +#include "katemain.h" +#include "../interfaces/viewmanager.h" + +#include <kate/view.h> +#include <kate/document.h> + +#include "katemdi.h" + +class TDEConfig; +class KateMainWindow; + +class KateViewSpaceContainer: public TQVBox +{ + Q_OBJECT + + friend class KateViewSpace; + friend class KateVSStatusBar; + + public: + KateViewSpaceContainer (TQWidget *parent, KateViewManager *viewManager); + + ~KateViewSpaceContainer (); + + inline TQPtrList<Kate::View> &viewList () { return m_viewList; }; + + public: + /* This will save the splitter configuration */ + void saveViewConfiguration(TDEConfig *config,const TQString& group); + + /* restore it */ + void restoreViewConfiguration (TDEConfig *config,const TQString& group); + + private: + /** + * create and activate a new view for doc, if doc == 0, then + * create a new document + */ + bool createView ( Kate::Document *doc =0L ); + + bool deleteView ( Kate::View *view, bool delViewSpace = true); + + void moveViewtoSplit (Kate::View *view); + void moveViewtoStack (Kate::View *view); + + /* Save the configuration of a single splitter. + * If child splitters are found, it calls it self with those as the argument. + * If a viewspace child is found, it is asked to save its filelist. + */ + void saveSplitterConfig(KateMDI::Splitter* s, int idx=0, TDEConfig* config=0L, const TQString& viewConfGrp=""); + + /** Restore a single splitter. + * This is all the work is done for @see saveSplitterConfig() + */ + void restoreSplitter ( TDEConfig* config, const TQString &group, TQWidget* parent , const TQString& viewConfGrp); + + void removeViewSpace (KateViewSpace *viewspace); + + bool showFullPath; + + public: + Kate::View* activeView (); + KateViewSpace* activeViewSpace (); + + uint viewCount (); + uint viewSpaceCount (); + + bool isViewActivationBlocked(){return m_blockViewCreationAndActivation;}; + + public: + void closeViews(uint documentNumber); + KateMainWindow *mainWindow(); + friend class KateViewManager; + + private slots: + void activateView ( Kate::View *view ); + void activateSpace ( Kate::View* v ); + void slotViewChanged(); + void reactivateActiveView(); + void slotPendingDocumentNameChanged(); + + void documentCreated (Kate::Document *doc); + void documentDeleted (uint docNumber); + + public slots: + /* Splits a KateViewSpace into two. + * The operation is performed by creating a KateMDI::Splitter in the parent of the KateViewSpace to be split, + * which is then moved to that splitter. Then a new KateViewSpace is created and added to the splitter, + * and a KateView is created to populate the new viewspace. The new KateView is made the active one, + * because createView() does that. + * If no viewspace is provided, the result of activeViewSpace() is used. + * The isHoriz, true pr default, decides the orientation of the splitting action. + * If atTop is true, the new viewspace will be moved to the first position in the new splitter. + * If a newViewUrl is provided, the new view will show the document in that URL if any, otherwise + * the document of the current view in the viewspace to be split is used. + */ + void splitViewSpace( KateViewSpace* vs=0L, bool isHoriz=true, bool atTop=false ); + + bool getShowFullPath() const { return showFullPath; } + + void activateView ( uint documentNumber ); + void activateView ( int documentNumber ) { activateView((uint) documentNumber); }; + + /** Splits the active viewspace horizontally */ + void slotSplitViewSpaceHoriz () { splitViewSpace(); } + /** Splits the active viewspace vertically */ + void slotSplitViewSpaceVert () { splitViewSpace( 0L, false ); } + + void slotCloseCurrentViewSpace(); + + void statusMsg (); + + void setActiveSpace ( KateViewSpace* vs ); + void setActiveView ( Kate::View* view ); + + void setShowFullPath(bool enable); + + void activateNextView(); + void activatePrevView(); + + signals: + void statusChanged (Kate::View *, int, int, int, bool, int, const TQString &); + void statChanged (); + void viewChanged (); + + private: + KateViewManager *m_viewManager; + TQPtrList<KateViewSpace> m_viewSpaceList; + TQPtrList<Kate::View> m_viewList; + + bool m_blockViewCreationAndActivation; + + bool m_activeViewRunning; + + bool m_pendingViewCreation; + TQGuardedPtr<Kate::Document> m_pendingDocument; +}; + +#endif diff --git a/kate/app/kbookmarkhandler.cpp b/kate/app/kbookmarkhandler.cpp new file mode 100644 index 000000000..8dbf8461d --- /dev/null +++ b/kate/app/kbookmarkhandler.cpp @@ -0,0 +1,98 @@ +/* This file is part of the KDE project + Copyright (C) xxxx KFile Authors + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katefileselector.h" + +#include <stdio.h> +#include <stdlib.h> + +#include <tqtextstream.h> + +#include <kbookmarkimporter.h> +#include <tdepopupmenu.h> +#include <ksavefile.h> +#include <kstandarddirs.h> +#include <tdediroperator.h> +#include <tdeaction.h> + +#include "kbookmarkhandler.h" +#include "kbookmarkhandler.moc" + + +KBookmarkHandler::KBookmarkHandler( KateFileSelector *parent, TDEPopupMenu* tdepopupmenu ) + : TQObject( parent, "KBookmarkHandler" ), + KBookmarkOwner(), + mParent( parent ), + m_menu( tdepopupmenu ), + m_importStream( 0L ) +{ + if (!m_menu) + m_menu = new TDEPopupMenu( parent, "bookmark menu" ); + + TQString file = locate( "data", "kate/fsbookmarks.xml" ); + if ( file.isEmpty() ) + file = locateLocal( "data", "kate/fsbookmarks.xml" ); + + KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false); + manager->setUpdate( true ); + manager->setShowNSBookmarks( false ); + + m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu, 0, true ); +} + +KBookmarkHandler::~KBookmarkHandler() +{ + // delete m_bookmarkMenu; ### +} + +TQString KBookmarkHandler::currentURL() const +{ + return mParent->dirOperator()->url().url(); +} + + +void KBookmarkHandler::slotNewBookmark( const TQString& /*text*/, + const TQCString& url, + const TQString& additionalInfo ) +{ + *m_importStream << "<bookmark icon=\"" << KMimeType::iconForURL( KURL( url ) ); + *m_importStream << "\" href=\"" << TQString::fromUtf8(url) << "\">\n"; + *m_importStream << "<title>" << (additionalInfo.isEmpty() ? TQString(TQString::fromUtf8(url)) : additionalInfo) << "</title>\n</bookmark>\n"; +} + +void KBookmarkHandler::slotNewFolder( const TQString& text, bool /*open*/, + const TQString& /*additionalInfo*/ ) +{ + *m_importStream << "<folder icon=\"bookmark_folder\">\n<title=\""; + *m_importStream << text << "\">\n"; +} + +void KBookmarkHandler::newSeparator() +{ + *m_importStream << "<separator/>\n"; +} + +void KBookmarkHandler::endFolder() +{ + *m_importStream << "</folder>\n"; +} + +void KBookmarkHandler::virtual_hook( int id, void* data ) +{ KBookmarkOwner::virtual_hook( id, data ); } + diff --git a/kate/app/kbookmarkhandler.h b/kate/app/kbookmarkhandler.h new file mode 100644 index 000000000..612c15a18 --- /dev/null +++ b/kate/app/kbookmarkhandler.h @@ -0,0 +1,72 @@ +/* This file is part of the KDE project + Copyright (C) xxxx KFile Authors + Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KBOOKMARKHANDLER_H_ +#define _KBOOKMARKHANDLER_H_ + +#include <kbookmarkmanager.h> +#include <kbookmarkmenu.h> + +class KateFileSelector; + +class TDEActionMenu; + +class TQTextStream; +class TDEPopupMenu; + +class KBookmarkHandler : public TQObject, public KBookmarkOwner +{ + Q_OBJECT + +public: + KBookmarkHandler( KateFileSelector *parent, TDEPopupMenu *tdepopupmenu=0 ); + ~KBookmarkHandler(); + + // KBookmarkOwner interface: + virtual void openBookmarkURL( const TQString& url ) { emit openURL( url ); } + virtual TQString currentURL() const; + + TDEPopupMenu *menu() const { return m_menu; } + +signals: + void openURL( const TQString& url ); + +private slots: + void slotNewBookmark( const TQString& text, const TQCString& url, + const TQString& additionalInfo ); + void slotNewFolder( const TQString& text, bool open, + const TQString& additionalInfo ); + void newSeparator(); + void endFolder(); + +protected: + virtual void virtual_hook( int id, void* data ); + +private: + KateFileSelector *mParent; + TDEPopupMenu *m_menu; + KBookmarkMenu *m_bookmarkMenu; + + TQTextStream *m_importStream; + + //class KBookmarkHandlerPrivate *d; +}; + + +#endif // _KBOOKMARKHANDLER_H_ diff --git a/kate/app/kwritemain.cpp b/kate/app/kwritemain.cpp new file mode 100644 index 000000000..75d494832 --- /dev/null +++ b/kate/app/kwritemain.cpp @@ -0,0 +1,716 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kwritemain.h" +#include "kwritemain.moc" + +#include <kate/document.h> +#include <kate/view.h> + +#include <tdetexteditor/configinterface.h> +#include <tdetexteditor/sessionconfiginterface.h> +#include <tdetexteditor/viewcursorinterface.h> +#include <tdetexteditor/printinterface.h> +#include <tdetexteditor/encodinginterface.h> +#include <tdetexteditor/editorchooser.h> +#include <tdetexteditor/popupmenuinterface.h> + +#include <tdeio/netaccess.h> + +#include <tdeversion.h> +#include <dcopclient.h> +#include <kurldrag.h> +#include <kencodingfiledialog.h> +#include <tdediroperator.h> +#include <kiconloader.h> +#include <tdeaboutdata.h> +#include <kstatusbar.h> +#include <kstdaction.h> +#include <tdeaction.h> +#include <kdebug.h> +#include <tdeglobal.h> +#include <tdeapplication.h> +#include <tdelocale.h> +#include <kurl.h> +#include <tdeconfig.h> +#include <tdecmdlineargs.h> +#include <tdemessagebox.h> +#include <kkeydialog.h> +#include <kedittoolbar.h> +#include <tdeparts/event.h> +#include <tdemenubar.h> + +#include <tqdropsite.h> +#include <tqdragobject.h> +#include <tqvbox.h> +#include <tqtextcodec.h> +#include <tqlayout.h> + +// StatusBar field IDs +#define KWRITE_ID_GEN 1 + +TQPtrList<KTextEditor::Document> KWrite::docList; +TQPtrList<KWrite> KWrite::winList; + +KWrite::KWrite (KTextEditor::Document *doc) + : m_view(0), + m_recentFiles(0), + m_paShowPath(0), + m_paShowStatusBar(0) +{ + if ( !doc ) + { + if ( !(doc = KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document")) ) + { + KMessageBox::error(this, i18n("A TDE text-editor component could not be found;\n" + "please check your TDE installation.")); + kapp->exit(1); + } + + docList.append(doc); + } + + m_view = doc->createView (this, 0L); + + setCentralWidget(m_view); + + setupActions(); + setupStatusBar(); + + setAcceptDrops(true); + + connect(m_view,TQT_SIGNAL(newStatus()),this,TQT_SLOT(newCaption())); + connect(m_view,TQT_SIGNAL(viewStatusMsg(const TQString &)),this,TQT_SLOT(newStatus(const TQString &))); + connect(m_view->document(),TQT_SIGNAL(fileNameChanged()),this,TQT_SLOT(newCaption())); + connect(m_view->document(),TQT_SIGNAL(fileNameChanged()),this,TQT_SLOT(slotFileNameChanged())); + connect(m_view,TQT_SIGNAL(dropEventPass(TQDropEvent *)),this,TQT_SLOT(slotDropEvent(TQDropEvent *))); + + setXMLFile( "kwriteui.rc" ); + createShellGUI( true ); + guiFactory()->addClient( m_view ); + + // install a working kate part popup dialog thingy + if (static_cast<Kate::View*>(m_view->tqt_cast("Kate::View"))) + static_cast<Kate::View*>(m_view->tqt_cast("Kate::View"))->installPopup ((TQPopupMenu*)(factory()->container("tdetexteditor_popup", this)) ); + + // init with more usefull size, stolen from konq :) + if (!initialGeometrySet()) + resize( TQSize(700, 480).expandedTo(minimumSizeHint())); + + // call it as last thing, must be sure everything is already set up ;) + setAutoSaveSettings (); + + readConfig (); + + winList.append (this); + + show (); +} + +KWrite::~KWrite() +{ + winList.remove (this); + + if (m_view->document()->views().count() == 1) + { + docList.remove(m_view->document()); + delete m_view->document(); + } + + kapp->config()->sync (); +} + +void KWrite::setupActions() +{ + KStdAction::close( TQT_TQOBJECT(this), TQT_SLOT(slotFlush()), actionCollection(), "file_close" )->setWhatsThis(i18n("Use this to close the current document")); + + // setup File menu + KStdAction::print(TQT_TQOBJECT(this), TQT_SLOT(printDlg()), actionCollection())->setWhatsThis(i18n("Use this command to print the current document")); + KStdAction::openNew( TQT_TQOBJECT(this), TQT_SLOT(slotNew()), actionCollection(), "file_new" )->setWhatsThis(i18n("Use this command to create a new document")); + KStdAction::open( TQT_TQOBJECT(this), TQT_SLOT( slotOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Use this command to open an existing document for editing")); + + m_recentFiles = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_SLOT(slotOpen(const KURL&)), + actionCollection()); + m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again.")); + + TDEAction *a=new TDEAction(i18n("&New Window"), "window_new", 0, TQT_TQOBJECT(this), TQT_SLOT(newView()), + actionCollection(), "view_new_view"); + a->setWhatsThis(i18n("Create another view containing the current document")); + + a=new TDEAction(i18n("Choose Editor Component..."),0,TQT_TQOBJECT(this),TQT_SLOT(changeEditor()), + actionCollection(),"settings_choose_editor"); + a->setWhatsThis(i18n("Override the system wide setting for the default editing component")); + + KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection())->setWhatsThis(i18n("Close the current document view")); + + // setup Settings menu + setStandardToolBarMenuEnabled(true); + + m_paShowStatusBar = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_SLOT(toggleStatusBar()), actionCollection(), "settings_show_statusbar"); + m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar")); + + m_paShowPath = new TDEToggleAction(i18n("Sho&w Path"), 0, TQT_TQOBJECT(this), TQT_SLOT(newCaption()), + actionCollection(), "set_showPath"); + m_paShowPath->setCheckedState(i18n("Hide Path")); + m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption")); + a=KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(editKeys()), actionCollection()); + a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments.")); + + a=KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(editToolbars()), actionCollection()); + a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s).")); +} + +void KWrite::setupStatusBar() +{ + statusBar()->insertItem("", KWRITE_ID_GEN); +} + +// load on url +void KWrite::loadURL(const KURL &url) +{ + m_view->document()->openURL(url); +} + +// is closing the window wanted by user ? +bool KWrite::queryClose() +{ + if (m_view->document()->views().count() > 1) + return true; + + if (m_view->document()->queryClose()) + { + writeConfig(); + + return true; + } + + return false; +} + +void KWrite::changeEditor() +{ + KWriteEditorChooser choose(this); + choose.exec(); +} + +void KWrite::slotFlush () +{ + m_view->document()->closeURL(); +} + +void KWrite::slotNew() +{ + new KWrite(); +} + +void KWrite::slotOpen() +{ + if (KTextEditor::encodingInterface(m_view->document())) + { + KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding( + KTextEditor::encodingInterface(m_view->document())->encoding(), + m_view->document()->url().url(),TQString::null,this,i18n("Open File")); + + for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i) + { + encoding = r.encoding; + slotOpen ( *i ); + } + } + else + { + KURL::List l=KFileDialog::getOpenURLs(m_view->document()->url().url(),TQString::null,this,TQString::null); + for (KURL::List::Iterator i=l.begin(); i != l.end(); ++i) + { + slotOpen ( *i ); + } + } +} + +void KWrite::slotOpen( const KURL& url ) +{ + if (url.isEmpty()) return; + + if (!TDEIO::NetAccess::exists(url, true, this)) + { + KMessageBox::error (this, i18n("The given file could not be read, check if it exists or if it is readable for the current user.")); + return; + } + + if (m_view->document()->isModified() || !m_view->document()->url().isEmpty()) + { + KWrite *t = new KWrite(); + if (KTextEditor::encodingInterface(t->m_view->document())) KTextEditor::encodingInterface(t->m_view->document())->setEncoding(encoding); + t->loadURL(url); + } + else + { + if (KTextEditor::encodingInterface(m_view->document())) KTextEditor::encodingInterface(m_view->document())->setEncoding(encoding); + loadURL(url); + } +} + +void KWrite::slotFileNameChanged() +{ + if ( ! m_view->document()->url().isEmpty() ) + m_recentFiles->addURL( m_view->document()->url() ); +} + +void KWrite::newView() +{ + new KWrite(m_view->document()); +} + +void KWrite::toggleStatusBar() +{ + if( m_paShowStatusBar->isChecked() ) + statusBar()->show(); + else + statusBar()->hide(); +} + +void KWrite::editKeys() +{ + KKeyDialog dlg; + dlg.insert(actionCollection()); + if( m_view ) + dlg.insert(m_view->actionCollection()); + dlg.configure(); +} + +void KWrite::editToolbars() +{ + saveMainWindowSettings( kapp->config(), "MainWindow" ); + KEditToolbar *dlg = new KEditToolbar(guiFactory()); + connect( dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) ); + dlg->exec(); + delete dlg; +} + +void KWrite::slotNewToolbarConfig() +{ + applyMainWindowSettings( kapp->config(), "MainWindow" ); +} + + +void KWrite::printNow() +{ + KTextEditor::printInterface(m_view->document())->print (); +} + +void KWrite::printDlg() +{ + KTextEditor::printInterface(m_view->document())->printDialog (); +} + +void KWrite::newStatus(const TQString &msg) +{ + newCaption(); + + statusBar()->changeItem(msg,KWRITE_ID_GEN); +} + +void KWrite::newCaption() +{ + if (m_view->document()->url().isEmpty()) { + setCaption(i18n("Untitled"),m_view->document()->isModified()); + } + else + { + TQString c; + if (!m_paShowPath->isChecked()) + { + c = m_view->document()->url().fileName(); + + //File name shouldn't be too long - Maciek + if (c.length() > 64) + c = c.left(64) + "..."; + } + else + { + c = m_view->document()->url().prettyURL(); + + //File name shouldn't be too long - Maciek + if (c.length() > 64) + c = "..." + c.right(64); + } + + setCaption (c, m_view->document()->isModified()); + } +} + +void KWrite::dragEnterEvent( TQDragEnterEvent *event ) +{ + event->accept(KURLDrag::canDecode(event)); +} + +void KWrite::dropEvent( TQDropEvent *event ) +{ + slotDropEvent(event); +} + +void KWrite::slotDropEvent( TQDropEvent *event ) +{ + KURL::List textlist; + + if (!KURLDrag::decode(event, textlist)) + return; + + for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i) + slotOpen (*i); +} + +void KWrite::slotEnableActions( bool enable ) +{ + TQValueList<TDEAction *> actions = actionCollection()->actions(); + TQValueList<TDEAction *>::ConstIterator it = actions.begin(); + TQValueList<TDEAction *>::ConstIterator end = actions.end(); + + for (; it != end; ++it ) + (*it)->setEnabled( enable ); + + actions = m_view->actionCollection()->actions(); + it = actions.begin(); + end = actions.end(); + + for (; it != end; ++it ) + (*it)->setEnabled( enable ); +} + +//common config +void KWrite::readConfig(TDEConfig *config) +{ + config->setGroup("General Options"); + + m_paShowStatusBar->setChecked( config->readBoolEntry("ShowStatusBar") ); + m_paShowPath->setChecked( config->readBoolEntry("ShowPath") ); + + m_recentFiles->loadEntries(config, "Recent Files"); + + if (m_view && KTextEditor::configInterface(m_view->document())) + KTextEditor::configInterface(m_view->document())->readConfig(config); + + if( m_paShowStatusBar->isChecked() ) + statusBar()->show(); + else + statusBar()->hide(); +} + +void KWrite::writeConfig(TDEConfig *config) +{ + config->setGroup("General Options"); + + config->writeEntry("ShowStatusBar",m_paShowStatusBar->isChecked()); + config->writeEntry("ShowPath",m_paShowPath->isChecked()); + + m_recentFiles->saveEntries(config, "Recent Files"); + + if (m_view && KTextEditor::configInterface(m_view->document())) + KTextEditor::configInterface(m_view->document())->writeConfig(config); + + config->sync (); +} + +//config file +void KWrite::readConfig() +{ + TDEConfig *config = kapp->config(); + readConfig(config); +} + +void KWrite::writeConfig() +{ + TDEConfig *config = kapp->config(); + writeConfig(config); +} + +// session management +void KWrite::restore(TDEConfig *config, int n) +{ + readPropertiesInternal(config, n); +} + +void KWrite::readProperties(TDEConfig *config) +{ + readConfig(config); + + if (KTextEditor::sessionConfigInterface(m_view)) + KTextEditor::sessionConfigInterface(m_view)->readSessionConfig(config); +} + +void KWrite::saveProperties(TDEConfig *config) +{ + writeConfig(config); + config->writeEntry("DocumentNumber",docList.find(m_view->document()) + 1); + + if (KTextEditor::sessionConfigInterface(m_view)) + KTextEditor::sessionConfigInterface(m_view)->writeSessionConfig(config); +} + +void KWrite::saveGlobalProperties(TDEConfig *config) //save documents +{ + config->setGroup("Number"); + config->writeEntry("NumberOfDocuments",docList.count()); + + for (uint z = 1; z <= docList.count(); z++) + { + TQString buf = TQString("Document %1").arg(z); + config->setGroup(buf); + + KTextEditor::Document *doc = docList.at(z - 1); + + if (KTextEditor::configInterface(doc)) + KTextEditor::configInterface(doc)->writeSessionConfig(config); + } + + for (uint z = 1; z <= winList.count(); z++) + { + TQString buf = TQString("Window %1").arg(z); + config->setGroup(buf); + + config->writeEntry("DocumentNumber",docList.find(winList.at(z-1)->view()->document()) + 1); + } +} + +//restore session +void KWrite::restore() +{ + TDEConfig *config = kapp->sessionConfig(); + + if (!config) + return; + + int docs, windows; + TQString buf; + KTextEditor::Document *doc; + KWrite *t; + + config->setGroup("Number"); + docs = config->readNumEntry("NumberOfDocuments"); + windows = config->readNumEntry("NumberOfWindows"); + + for (int z = 1; z <= docs; z++) + { + buf = TQString("Document %1").arg(z); + config->setGroup(buf); + doc=KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document"); + + if (KTextEditor::configInterface(doc)) + KTextEditor::configInterface(doc)->readSessionConfig(config); + docList.append(doc); + } + + for (int z = 1; z <= windows; z++) + { + buf = TQString("Window %1").arg(z); + config->setGroup(buf); + t = new KWrite(docList.at(config->readNumEntry("DocumentNumber") - 1)); + t->restore(config,z); + } +} + +static TDECmdLineOptions options[] = +{ + { "stdin", I18N_NOOP("Read the contents of stdin"), 0}, + { "encoding <argument>", I18N_NOOP("Set encoding for the file to open"), 0 }, + { "line <argument>", I18N_NOOP("Navigate to this line"), 0 }, + { "column <argument>", I18N_NOOP("Navigate to this column"), 0 }, + { "+[URL]", I18N_NOOP("Document to open"), 0 }, + TDECmdLineLastOption +}; + +extern "C" KDE_EXPORT int kdemain(int argc, char **argv) +{ + Kate::Document::setFileChangedDialogsActivated (true); + + TDELocale::setMainCatalogue("kate"); //lukas: set this to have the kwritepart translated using kate message catalog + + // here we go, construct the KWrite version + // TQString kWriteVersion = TQString ("%1.%2.%3").arg(KDE::versionMajor() + 1).arg(KDE::versionMinor()).arg(KDE::versionRelease()); + /** The previous version computation scheme (commented out above) worked fine in the 3.5.x days. + With the new Trinity Rx.y.z scheme the version number gets weird. + We now hard-code the first two numbers to match the 3.5.x days and only update the last number. */ + TQString kWriteVersion = TQString ("4.5.%1").arg(KDE::versionMajor()); + + TDEAboutData aboutData ( "kwrite", + I18N_NOOP("KWrite"), + kWriteVersion.latin1(), + I18N_NOOP( "KWrite - Text Editor" ), TDEAboutData::License_LGPL_V2, + I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org" ); + + aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de"); + aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk"); + aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371"); + aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org"); + aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" ); + aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org"); + aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com"); + aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at"); + aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz"); + aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" ); + aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org"); + aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" ); + aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" ); + aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com"); + aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net"); + aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org"); + + aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it"); + aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu"); + aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),""); + aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),""); + aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),""); + aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),""); + aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),""); + aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),""); + aboutData.addCredit ("Daniel Naber","",""); + aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),""); + aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),""); + aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), ""); + aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"",""); + + aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails")); + + TDECmdLineArgs::init( argc, argv, &aboutData ); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication a; + + TDEGlobal::locale()->insertCatalogue("katepart"); + + DCOPClient *client = kapp->dcopClient(); + if (!client->isRegistered()) + { + client->attach(); + client->registerAs("kwrite"); + } + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + if (kapp->isRestored()) + { + KWrite::restore(); + } + else + { + bool nav = false; + int line = 0, column = 0; + + TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0; + + if (args->isSet ("line")) + { + line = args->getOption ("line").toInt(); + nav = true; + } + + if (args->isSet ("column")) + { + column = args->getOption ("column").toInt(); + nav = true; + } + + if ( args->count() == 0 ) + { + KWrite *t = new KWrite; + + if( args->isSet( "stdin" ) ) + { + TQTextIStream input(stdin); + + // set chosen codec + if (codec) + input.setCodec (codec); + + TQString line; + TQString text; + + do + { + line = input.readLine(); + text.append( line + "\n" ); + } while( !line.isNull() ); + + + KTextEditor::EditInterface *doc = KTextEditor::editInterface (t->view()->document()); + if( doc ) + doc->setText( text ); + } + + if (nav && KTextEditor::viewCursorInterface(t->view())) + KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column); + } + else + { + for ( int z = 0; z < args->count(); z++ ) + { + KWrite *t = new KWrite(); + + // this file is no local dir, open it, else warn + bool noDir = !args->url(z).isLocalFile() || !TQDir (args->url(z).path()).exists(); + + if (noDir) + { + if (Kate::document (t->view()->document())) + Kate::Document::setOpenErrorDialogsActivated (false); + + if (codec && KTextEditor::encodingInterface(t->view()->document())) + KTextEditor::encodingInterface(t->view()->document())->setEncoding(codec->name()); + + t->loadURL( args->url( z ) ); + + if (Kate::document (t->view()->document())) + Kate::Document::setOpenErrorDialogsActivated (true); + + if (nav && KTextEditor::viewCursorInterface(t->view())) + KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column); + } + else + KMessageBox::sorry( t, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(args->url(z).url()) ); + } + } + } + + // no window there, uh, ohh, for example borked session config !!! + // create at least one !! + if (KWrite::noWindows()) + new KWrite(); + + return a.exec (); +} + +KWriteEditorChooser::KWriteEditorChooser(TQWidget *): + KDialogBase(KDialogBase::Plain,i18n("Choose Editor Component"),KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel) +{ + (new TQVBoxLayout(plainPage()))->setAutoAdd(true); + m_chooser=new KTextEditor::EditorChooser(plainPage(),"Editor Chooser"); + setMainWidget(m_chooser); + m_chooser->readAppSetting(); +} + +KWriteEditorChooser::~KWriteEditorChooser() { +; +} + +void KWriteEditorChooser::slotOk() { + m_chooser->writeAppSetting(); + KDialogBase::slotOk(); +} +// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/kwritemain.h b/kate/app/kwritemain.h new file mode 100644 index 000000000..fc47c6522 --- /dev/null +++ b/kate/app/kwritemain.h @@ -0,0 +1,140 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> + Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> + Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KWRITE_MAIN_H__ +#define __KWRITE_MAIN_H__ + +#include <tdetexteditor/view.h> +#include <tdetexteditor/document.h> + +#include <tdeparts/mainwindow.h> + +#include <kdialogbase.h> + +namespace KTextEditor { class EditorChooser; } + +class TDEAction; +class TDEToggleAction; +class TDESelectAction; +class TDERecentFilesAction; + +class KWrite : public KParts::MainWindow +{ + Q_OBJECT + + + public: + KWrite(KTextEditor::Document * = 0L); + ~KWrite(); + + void loadURL(const KURL &url); + + KTextEditor::View *view() const { return m_view; } + + static bool noWindows () { return winList.isEmpty(); } + + private: + void setupActions(); + void setupStatusBar(); + + bool queryClose(); + + void dragEnterEvent( TQDragEnterEvent * ); + void dropEvent( TQDropEvent * ); + + public slots: + void slotNew(); + void slotFlush (); + void slotOpen(); + void slotOpen( const KURL& url); + void newView(); + void toggleStatusBar(); + void editKeys(); + void editToolbars(); + void changeEditor(); + + private slots: + void slotNewToolbarConfig(); + + public slots: + void printNow(); + void printDlg(); + + void newStatus(const TQString &msg); + void newCaption(); + + void slotDropEvent(TQDropEvent *); + + void slotEnableActions( bool enable ); + + /** + * adds a changed URL to the recent files + */ + void slotFileNameChanged(); + + //config file functions + public: + void readConfig (TDEConfig *); + void writeConfig (TDEConfig *); + + void readConfig (); + void writeConfig (); + + //session management + public: + void restore(TDEConfig *,int); + static void restore(); + + private: + void readProperties(TDEConfig *); + void saveProperties(TDEConfig *); + void saveGlobalProperties(TDEConfig *); + + private: + KTextEditor::View * m_view; + + TDERecentFilesAction * m_recentFiles; + TDEToggleAction * m_paShowPath; + TDEToggleAction * m_paShowStatusBar; + + TQString encoding; + + static TQPtrList<KTextEditor::Document> docList; + static TQPtrList<KWrite> winList; +}; + +class KWriteEditorChooser: public KDialogBase +{ + Q_OBJECT + + + public: + KWriteEditorChooser(TQWidget *parent); + virtual ~KWriteEditorChooser(); + + private: + KTextEditor::EditorChooser *m_chooser; + + protected slots: + void slotOk(); +}; + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; |