create a class Edn::File that manage the modification of the falineme to get the real filename in the system ==> dit not work corectly...

This commit is contained in:
Edouard Dupin 2011-08-04 18:18:54 +02:00
parent 55681d1dac
commit ff055b88d4
12 changed files with 105 additions and 149 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ doxygen/ALL/
*.so *.so
*.pyc *.pyc
edn edn
out
edn_debug edn_debug
edn_release edn_release

View File

@ -44,7 +44,7 @@ Buffer::Buffer()
m_fileModify = true; m_fileModify = true;
m_haveName = false; m_haveName = false;
Edn::String mString = "No-Name"; Edn::String mString = "No-Name";
m_fileName.SetCompleateName(mString); SetFileName(mString);
} }
/** /**
@ -58,8 +58,7 @@ Buffer::Buffer()
Buffer::Buffer(Edn::String &newFileName) Buffer::Buffer(Edn::String &newFileName)
{ {
m_fileModify = false; m_fileModify = false;
m_haveName = true; SetFileName(newFileName);
m_fileName.SetCompleateName(newFileName);
} }
/** /**
@ -95,85 +94,6 @@ void Buffer::SetModify(bool status)
} }
} }
Edn::File Buffer::GetFileName(void)
{
return m_fileName;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
Edn::String Buffer::GetName(void)
{
// nothing to do
return m_fileName.GetCompleateName();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
Edn::String Buffer::GetShortName(void)
{
// nothing to do
return m_fileName.GetShortFilename();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
Edn::String Buffer::GetFolder(void)
{
// nothing to do
return m_fileName.GetFolder();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
bool Buffer::HaveName(void)
{
// nothing to do
return true;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void Buffer::SetName(Edn::String &newName)
{
// nothing to do
}
/** /**
* @brief * @brief
* *

View File

@ -47,13 +47,30 @@ class Buffer {
Buffer(void); Buffer(void);
Buffer(Edn::String &filename); Buffer(Edn::String &filename);
virtual ~Buffer(void); virtual ~Buffer(void);
Edn::File GetFileName(void);
virtual Edn::String GetName(void); Edn::File GetFileName(void)
virtual Edn::String GetShortName(void); {
virtual Edn::String GetFolder(void); return m_fileName;
virtual void SetName(Edn::String &newName); };
void SetFileName(Edn::File &newName)
{
m_fileName = newName;
m_haveName = true;
};
void SetFileName(Edn::String &newName)
{
m_fileName.SetCompleateName(newName);
m_haveName = true;
};
bool HaveName(void)
{
return m_haveName;
}
virtual void Save(void); virtual void Save(void);
virtual bool HaveName(void);
bool IsModify(void); bool IsModify(void);
protected: protected:
void SetModify(bool status); void SetModify(bool status);

View File

@ -242,7 +242,7 @@ int32_t BufferManager::GetId(Edn::String &filename)
for (iii=0; iii < listBuffer.Size(); iii++) { for (iii=0; iii < listBuffer.Size(); iii++) {
// check if the buffer already existed // check if the buffer already existed
if (NULL != listBuffer[iii]) { if (NULL != listBuffer[iii]) {
if ( listBuffer[iii]->GetName() == filename) { if ( listBuffer[iii]->GetFileName().GetCompleateName() == filename) {
return iii; return iii;
} }
} }

View File

@ -147,17 +147,17 @@ gboolean BufferView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, g
basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL; basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL;
basicColor_te selectBG = COLOR_LIST_BG_1; basicColor_te selectBG = COLOR_LIST_BG_1;
for (i=0; i < nbBufferOpen; i++) { for (i=0; i < nbBufferOpen; i++) {
Edn::String name; Edn::File name;
bool isModify; bool isModify;
if (self->m_bufferManager->Exist(i)) { if (self->m_bufferManager->Exist(i)) {
isModify = self->m_bufferManager->Get(i)->IsModify(); isModify = self->m_bufferManager->Get(i)->IsModify();
name = self->m_bufferManager->Get(i)->GetShortName(); name = self->m_bufferManager->Get(i)->GetFileName();
char *tmpModify = (char*)" "; char *tmpModify = (char*)" ";
if (true == isModify) { if (true == isModify) {
tmpModify = (char*)"M"; tmpModify = (char*)"M";
} }
char name2[1024] = ""; char name2[1024] = "";
sprintf(name2, "[%2d](%s) %s", i, tmpModify, name.c_str() ); sprintf(name2, "[%2d](%s) %s", i, tmpModify, name.GetShortFilename().c_str() );
if (true == isModify) { if (true == isModify) {
selectFG = COLOR_LIST_TEXT_MODIFY; selectFG = COLOR_LIST_TEXT_MODIFY;

View File

@ -93,17 +93,25 @@ MainWindows::~MainWindows(void)
} }
void MainWindows::SetTitle(Edn::String &fileName, bool isModify) void MainWindows::SetTitle(Edn::File &fileName, bool isModify)
{ {
Edn::String tmp = ""; Edn::String tmp = "";
if (fileName != "") { if (fileName.GetShortFilename() != "") {
tmp += fileName; tmp += fileName.GetShortFilename();
tmp += " - ";
tmp += fileName.GetFolder();
tmp += " - "; tmp += " - ";
} }
tmp += "Edn"; tmp += "Edn";
gtk_window_set_title(GTK_WINDOW(m_mainWindow), tmp.c_str()); gtk_window_set_title(GTK_WINDOW(m_mainWindow), tmp.c_str());
} }
void MainWindows::SetNoTitle(void)
{
Edn::String tmp = "Edn";
gtk_window_set_title(GTK_WINDOW(m_mainWindow), tmp.c_str());
}
void MainWindows::OnMessage(int32_t id, int32_t dataID) void MainWindows::OnMessage(int32_t id, int32_t dataID)
{ {
switch (id) switch (id)
@ -112,12 +120,11 @@ void MainWindows::OnMessage(int32_t id, int32_t dataID)
// change Title : // change Title :
// TODO : String error when remove the error with -1; // TODO : String error when remove the error with -1;
if (-1 == dataID) { if (-1 == dataID) {
Edn::String plop = ""; SetNoTitle();
SetTitle(plop, false );
} else { } else {
Buffer *mybuf = BufferManager::getInstance()->Get(dataID); Buffer *mybuf = BufferManager::getInstance()->Get(dataID);
if (NULL != mybuf) { if (NULL != mybuf) {
Edn::String plop = mybuf->GetName(); Edn::File plop = mybuf->GetFileName();
SetTitle(plop, mybuf->IsModify() ); SetTitle(plop, mybuf->IsModify() );
} }
} }

View File

@ -53,7 +53,8 @@ class MainWindows: public Singleton<MainWindows>, public MsgBroadcast
static bool OnQuit(GtkWidget *widget, gpointer data); static bool OnQuit(GtkWidget *widget, gpointer data);
private: private:
void SetTitle(Edn::String &fileName, bool isModify); void SetTitle(Edn::File &fileName, bool isModify);
void SetNoTitle(void);
// main windows widget : // main windows widget :
GtkWidget * m_mainWindow; GtkWidget * m_mainWindow;
BufferView m_BufferView; BufferView m_BufferView;

View File

@ -101,9 +101,9 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
if( -1 != m_currentBufferID if( -1 != m_currentBufferID
&& true == myBufferManager->Exist(m_currentBufferID) ) && true == myBufferManager->Exist(m_currentBufferID) )
{ {
Edn::String fileFolder = myBufferManager->Get(m_currentBufferID)->GetFolder(); Edn::File fileName = myBufferManager->Get(m_currentBufferID)->GetFileName();
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), fileFolder.c_str()); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), fileName.GetFolder().c_str());
//gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), "Untitled document"); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fileName.GetShortFilename().c_str());
} }
if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{ {
@ -132,7 +132,7 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
} }
Buffer *myBuffer = BufferManager::getInstance()->Get(idSelected); Buffer *myBuffer = BufferManager::getInstance()->Get(idSelected);
Edn::String tmpString = "Save as file : "; Edn::String tmpString = "Save as file : ";
tmpString += myBuffer->GetShortName().c_str(); tmpString += myBuffer->GetFileName().GetShortFilename().c_str();
GtkWidget *dialog = gtk_file_chooser_dialog_new( tmpString.c_str(), NULL, GtkWidget *dialog = gtk_file_chooser_dialog_new( tmpString.c_str(), NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, // button text GTK_STOCK_CANCEL, // button text
@ -145,7 +145,7 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
Edn::String myfilename; Edn::String myfilename;
myfilename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog)); myfilename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
myBuffer->SetName(myfilename); myBuffer->SetFileName(myfilename);
myBuffer->Save(); myBuffer->Save();
SendMessage(EDN_MSG__CURRENT_CHANGE_BUFFER_ID, idSelected); SendMessage(EDN_MSG__CURRENT_CHANGE_BUFFER_ID, idSelected);

View File

@ -159,9 +159,7 @@ void CTagsManager::AddToHistory(int32_t bufferID)
} }
// add the current element // add the current element
BufferManager *myBufferManager = BufferManager::getInstance(); BufferManager *myBufferManager = BufferManager::getInstance();
Edn::String currentFilename = myBufferManager->Get(bufferID)->GetName(); Edn::File currentFilename = myBufferManager->Get(bufferID)->GetFileName();
int32_t currentLineId = 0;
Edn::File * currentFile = new Edn::File(currentFilename);
} }

View File

@ -52,41 +52,6 @@ Edn::File::~File(void)
// nothing to do ... // nothing to do ...
} }
void Edn::File::ExtranctAndName(Edn::String &inputString)
{
m_folder = "";
m_shortFilename = "";
for (int32_t iii=inputString.Size()-1; iii >= 0 ; iii--) {
/*
if (inputString[iii] != '/') {
m_shortFilename.Insert(0, inputString[iii]);
} else {
break;
}
*/
}
/*
char tmpVal[4096];
strncpy(tmpVal, inputString.c_str(), 4096);
tmpVal[4096-1] = '\0';
char *ptr = strrchr(tmpVal, '/');
if (NULL == ptr) {
ptr = strrchr(tmpVal, '\\');
}
Edn::String out = "./";
if (NULL != ptr) {
*ptr = '\0';
out = tmpVal;
out+= '/';
}
return out;
*/
}
Edn::String Edn::File::GetFolder(void) Edn::String Edn::File::GetFolder(void)
{ {
@ -106,11 +71,28 @@ Edn::String Edn::File::GetCompleateName(void)
out += m_shortFilename; out += m_shortFilename;
} }
const Edn::File& Edn::File::operator= (const Edn::File &ednF )
{
if( this != &ednF ) // avoid copy to itself
{
m_folder = ednF.m_folder;
m_shortFilename = ednF.m_shortFilename;
m_lineNumberOpen = ednF.m_lineNumberOpen;
}
return *this;
}
void Edn::File::SetCompleateName(Edn::String &newFilename) void Edn::File::SetCompleateName(Edn::String &newFilename)
{ {
char buf[MAX_FILE_NAME]; char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME); memset(buf, 0, MAX_FILE_NAME);
char * ok; char * ok;
// Reset ALL DATA :
m_folder = "";
m_shortFilename = "";
m_lineNumberOpen = 0;
Edn::String destFilename; Edn::String destFilename;
if (newFilename.Size() == 0) { if (newFilename.Size() == 0) {
destFilename = "no-name"; destFilename = "no-name";
@ -133,14 +115,44 @@ void Edn::File::SetCompleateName(Edn::String &newFilename)
// Get the real Path of the current File // Get the real Path of the current File
ok = realpath(destFilename.c_str(), buf); ok = realpath(destFilename.c_str(), buf);
if (!ok) { if (!ok) {
EDN_ERROR("Can not find real name of \"" << destFilename.c_str() << "\""); int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) {
// Get the FileName
Edn::String tmpFilename = destFilename.Extract(lastPos+1);
destFilename.Remove(lastPos, destFilename.Size() - lastPos);
//EDN_DEBUG("try to find :\"" << destFilename.c_str() << "\" / \"" << tmpFilename.c_str() << "\" ");
ok = realpath(destFilename.c_str(), buf);
if (!ok) {
EDN_ERROR("Can not find real Path name of \"" << destFilename.c_str() << "\"");
m_shortFilename = tmpFilename;
m_folder = destFilename;
} else {
// ALL is OK ...
m_shortFilename = tmpFilename;
m_folder = destFilename;
}
} else {
EDN_WARNING("file : \"" << destFilename.c_str() << "\" ==> No data???");
// Basic ERROR ...
m_shortFilename = destFilename;
}
} else { } else {
EDN_DEBUG("file : \"" << destFilename.c_str() << "\" done:\"" << buf << "\" "); destFilename = buf;
// TODO : try again with no name int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) {
m_shortFilename = destFilename.Extract(lastPos+1);
m_folder = destFilename.Extract(0, lastPos);
} else {
// Basic ERROR ...
EDN_WARNING("file : \"" << destFilename.c_str() << "\" ==> No data???");
m_shortFilename = destFilename;
}
} }
EDN_DEBUG("Set FileName :\"" << m_folder.c_str() << "\" / \"" << m_shortFilename.c_str() << "\" ");
} }
int32_t Edn::File::GetLineNumber(void) int32_t Edn::File::GetLineNumber(void)
{ {
return m_lineNumberOpen; return m_lineNumberOpen;
} }

View File

@ -40,10 +40,10 @@ namespace Edn
Edn::String GetCompleateName(void); Edn::String GetCompleateName(void);
int32_t GetLineNumber(void); int32_t GetLineNumber(void);
const Edn::File& operator= (const Edn::File &ednF );
void SetCompleateName(Edn::String &newFilename); void SetCompleateName(Edn::String &newFilename);
private : private :
void ExtranctAndName(Edn::String &inputString);
Edn::String m_folder; Edn::String m_folder;
Edn::String m_shortFilename; Edn::String m_shortFilename;
int32_t m_lineNumberOpen; int32_t m_lineNumberOpen;

View File

@ -17,8 +17,8 @@
- Project manager phase 1 - Project manager phase 1
# action a faire (ordonner) : # action a faire (ordonner) :
- HL : Parsing caracter/caractère et plus section par section ...
- sys : real filename ... - sys : real filename ...
- HL : Parsing caracter/caractère et plus section par section ...
- ctags : Back simple et multiple - ctags : Back simple et multiple
- ctags : Multiple files - ctags : Multiple files
- sys : search complet, replace complet - sys : search complet, replace complet