1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
/***************************************************************************
kateprojectmanager.cpp - description
-------------------
begin : Mon Jan 15 2001
copyright : (C) 2001 by Christoph "Crossfire" Cullmann
email : crossfire@babylon2k.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "kateprojectmanager.h"
#include "kateprojectmanager.moc"
#include "kateprojectdialog.h"
#include <kxmlgui.h>
#include <kfiledialog.h>
#include <iostream.h>
#include <qtextstream.h>
#include <kstatusbar.h>
#include <kpopupmenu.h>
#include <klocale.h>
#include <kaction.h>
#include "./piper/piper.h"
extern "C"
{
void* init_libkateprojectmanagerplugin()
{
KGlobal::locale()->insertCatalogue("kateprojectmanager");
return new KatePluginFactory;
}
}
KatePluginFactory::KatePluginFactory()
{
s_instance = new KInstance( "kate" );
}
KatePluginFactory::~KatePluginFactory()
{
delete s_instance;
}
QObject* KatePluginFactory::createObject( QObject* parent, const char* name, const char*, const QStringList & )
{
return new KateProjectManager( parent, name );
}
KInstance* KatePluginFactory::s_instance = 0L;
KateProjectManager::KateProjectManager (QObject* parent, const char* name) : Kate::Plugin(parent, name)
{
}
KateProjectManager::~KateProjectManager ()
{
}
Kate::PluginView *KateProjectManager::createView (Kate::MainWindow *win)
{
return (Kate::PluginView *) new KateProjectManagerView (this, win);
}
/*
Open a "new Project" dialog, when pressed ok
close all open windows (to have a clean workspace)
*/
void KateProjectManager::slotProjectNew()
{
KateProjectDialog* kateprojectdialog = new KateProjectDialog();
if (kateprojectdialog->exec())
{
/* Now create project here */
}
}
/* Open a project */
// TODO: close all open files
// TODO: check if the filenames in the project are valid
void KateProjectManager::slotProjectOpen()
{
KURL url = KFileDialog::getOpenURL(QString::null, QString::null, 0L, i18n("Load Project..."));
if ( url.isMalformed() )
return;
// create a QDomDocument to parse the XML file
QDomDocument doc("projectFile");
// reference the chosen file
QFile f(url.path());
f.open(IO_ReadOnly);
// set the content of the file to the QDomDocument
doc.setContent(&f);
// close file
f.close();
QDomElement docElement = doc.documentElement();
for (QDomNode n = docElement.firstChild(); !n.isNull(); n = n.nextSibling())
{
QDomElement e = n.toElement();
KURL file_url = e.attribute("path");
myApp->getViewManager()->openURL(file_url);
}
projectFile = url;
}
/*
All files opened at this point should be related to
the project, because they are saved into the project file
*/
void KateProjectManager::slotProjectSave()
{
// now generate a new XML file based on the project information
QDomDocument xml("kate_project");
QDomElement top = xml.createElement("kate_project");
top.setAttribute("name", "project_name_here");
top.setAttribute("version", "1");
for (Kate::Document* k = myApp->getDocManager()->getFirstDoc(); k != 0; k = myApp->getDocManager()->getNextDoc())
{
QDomElement file = xml.createElement("file");
file.setAttribute("path", k->url().path());
top.appendChild(file);
}
// append the whole tree
xml.appendChild(top);
QFile f(projectFile.path()); // make a file reference
f.open(IO_WriteOnly); // open it for writing
QTextStream t(&f); // access it with a textstream
t << xml.toString(); // pipe xml-doc into textstream
f.close(); // finished by closing file
}
/* get a file for this project then call save() */
void KateProjectManager::slotProjectSaveAs()
{
// KURL of the project file to save
KURL url = KFileDialog::getSaveURL(QString::null, i18n("Project File (*.prj)"), 0L, i18n("Save Project..."));
if (!url.isEmpty())
{
projectFile = url;
slotProjectSave();
}
}
void KateProjectManager::slotProjectConfigure()
{
}
void KateProjectManager::slotProjectRun()
{
}
static Piper s_aPiper;
static void readAnyErrors(FILE * fp, KStatusBar & bar)
{
string strFileName;
string strMessage ("Internal error reading message from compiler output");
size_t nLine;
s_aPiper.Reset();
while (!feof(fp))
{
int c = fgetc (fp);
if (c != EOF)
{
s_aPiper.StoreChar(c); /* sniff for diagnostics */
putchar (c);
if (c == '\n') fflush (stdout);
}
else
break;
}
fflush (stdout);
pclose (fp);
if (s_aPiper.GetNextError(strFileName, &nLine, strMessage))
{
// TODO: navigate to the document with the error...
// TODO: go to the line with the error
// TODO: make this not block...
// TODO: Get rid of this annoying error message & put something in the status bar...
bar.message(strMessage.c_str());
}
}
void KateProjectManager::slotProjectCompile()
{
// insert a line here to save all documents
FILE *fp = NULL;
// assert (myApp->statusBar());
/* assume the user changed the file & wants to compile it... */
/* tip: put 2>&1 in your script so we can see the "error" messages */
fp = popen ("./builder.sh", "r");
// if (fp)
// readAnyErrors(fp, *myApp->statusBar());
}
KateProjectManagerView::KateProjectManagerView(Kate::Plugin *plugin, Kate::MainWindow *win) : Kate::PluginView (plugin, win)
{
setXML( "plugins/kateprojectmanager/ui.rc" );
KActionMenu* pm_project = new KActionMenu(i18n("&Project"), actionCollection(), "project");
connect(pm_project->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(projectMenuAboutToShow()));
// KActions for Project
projectNew = new KAction(i18n("&New"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectNew()), actionCollection(),"project_new");
projectOpen = new KAction(i18n("&Open"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectOpen()), actionCollection(),"project_open");
projectSave = new KAction(i18n("&Save"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectSave()), actionCollection(),"project_save");
projectSaveAs = new KAction(i18n("&SaveAs"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectSaveAs()), actionCollection(),"project_save_as");
projectConfigure = new KAction(i18n("&Configure"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectConfigure()), actionCollection(),"project_configure");
projectCompile = new KAction(i18n("&Compile"), Key_F5, (KateProjectManager*)myPlugin,
SLOT(slotProjectCompile()), actionCollection(),"project_compile");
projectRun = new KAction(i18n("&Run"), 0, (KateProjectManager*)myPlugin,
SLOT(slotProjectRun()), actionCollection(),"project_run");
}
KateProjectManagerView::~KateProjectManagerView ()
{
}
void KateProjectManagerView::projectMenuAboutToShow()
{
projectConfigure->setEnabled(false);
projectRun->setEnabled(false);
if (((KateProjectManager*)myPlugin)->projectFile.isEmpty())
projectSave->setEnabled(false);
else
projectSave->setEnabled(true);
if (myPlugin->myApp->getDocManager()->docCount () == 0)
projectSaveAs->setEnabled(false);
else
projectSaveAs->setEnabled(true);
}
|