From ff055b88d438f8acdeb090af5a0840898f005d7c Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Thu, 4 Aug 2011 18:18:54 +0200 Subject: [PATCH] create a class Edn::File that manage the modification of the falineme to get the real filename in the system ==> dit not work corectly... --- .gitignore | 1 + Sources/Buffer/Buffer.cpp | 84 +---------------- Sources/Buffer/Buffer.h | 29 ++++-- Sources/Buffer/BufferManager.cpp | 2 +- .../CustumWidget/BufferView/BufferView.cpp | 6 +- Sources/GuiTools/MainWindows/MainWindows.cpp | 19 ++-- Sources/GuiTools/MainWindows/MainWindows.h | 3 +- .../WindowsManager/WindowsManager.cpp | 10 +- Sources/ctags/CTagsManager.cpp | 4 +- Sources/tools/NameSpaceEdn/File.cpp | 92 +++++++++++-------- Sources/tools/NameSpaceEdn/File.h | 2 +- avancement.boo | 2 +- 12 files changed, 105 insertions(+), 149 deletions(-) diff --git a/.gitignore b/.gitignore index fca4dea..4fc7320 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ doxygen/ALL/ *.so *.pyc edn +out edn_debug edn_release diff --git a/Sources/Buffer/Buffer.cpp b/Sources/Buffer/Buffer.cpp index 82a88b7..4982ba9 100644 --- a/Sources/Buffer/Buffer.cpp +++ b/Sources/Buffer/Buffer.cpp @@ -44,7 +44,7 @@ Buffer::Buffer() m_fileModify = true; m_haveName = false; Edn::String mString = "No-Name"; - m_fileName.SetCompleateName(mString); + SetFileName(mString); } /** @@ -58,8 +58,7 @@ Buffer::Buffer() Buffer::Buffer(Edn::String &newFileName) { m_fileModify = false; - m_haveName = true; - m_fileName.SetCompleateName(newFileName); + SetFileName(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 * diff --git a/Sources/Buffer/Buffer.h b/Sources/Buffer/Buffer.h index e470a07..0ada829 100644 --- a/Sources/Buffer/Buffer.h +++ b/Sources/Buffer/Buffer.h @@ -47,13 +47,30 @@ class Buffer { Buffer(void); Buffer(Edn::String &filename); virtual ~Buffer(void); - Edn::File GetFileName(void); - virtual Edn::String GetName(void); - virtual Edn::String GetShortName(void); - virtual Edn::String GetFolder(void); - virtual void SetName(Edn::String &newName); + + Edn::File GetFileName(void) + { + return m_fileName; + }; + + 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 bool HaveName(void); bool IsModify(void); protected: void SetModify(bool status); diff --git a/Sources/Buffer/BufferManager.cpp b/Sources/Buffer/BufferManager.cpp index 0e6ebbc..04d90a9 100644 --- a/Sources/Buffer/BufferManager.cpp +++ b/Sources/Buffer/BufferManager.cpp @@ -242,7 +242,7 @@ int32_t BufferManager::GetId(Edn::String &filename) for (iii=0; iii < listBuffer.Size(); iii++) { // check if the buffer already existed if (NULL != listBuffer[iii]) { - if ( listBuffer[iii]->GetName() == filename) { + if ( listBuffer[iii]->GetFileName().GetCompleateName() == filename) { return iii; } } diff --git a/Sources/CustumWidget/BufferView/BufferView.cpp b/Sources/CustumWidget/BufferView/BufferView.cpp index 3ef07e8..601010d 100644 --- a/Sources/CustumWidget/BufferView/BufferView.cpp +++ b/Sources/CustumWidget/BufferView/BufferView.cpp @@ -147,17 +147,17 @@ gboolean BufferView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, g basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL; basicColor_te selectBG = COLOR_LIST_BG_1; for (i=0; i < nbBufferOpen; i++) { - Edn::String name; + Edn::File name; bool isModify; if (self->m_bufferManager->Exist(i)) { isModify = self->m_bufferManager->Get(i)->IsModify(); - name = self->m_bufferManager->Get(i)->GetShortName(); + name = self->m_bufferManager->Get(i)->GetFileName(); char *tmpModify = (char*)" "; if (true == isModify) { tmpModify = (char*)"M"; } 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) { selectFG = COLOR_LIST_TEXT_MODIFY; diff --git a/Sources/GuiTools/MainWindows/MainWindows.cpp b/Sources/GuiTools/MainWindows/MainWindows.cpp index 207f61b..38f29a2 100644 --- a/Sources/GuiTools/MainWindows/MainWindows.cpp +++ b/Sources/GuiTools/MainWindows/MainWindows.cpp @@ -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 = ""; - if (fileName != "") { - tmp += fileName; + if (fileName.GetShortFilename() != "") { + tmp += fileName.GetShortFilename(); + tmp += " - "; + tmp += fileName.GetFolder(); tmp += " - "; } tmp += "Edn"; 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) { switch (id) @@ -112,12 +120,11 @@ void MainWindows::OnMessage(int32_t id, int32_t dataID) // change Title : // TODO : String error when remove the error with -1; if (-1 == dataID) { - Edn::String plop = ""; - SetTitle(plop, false ); + SetNoTitle(); } else { Buffer *mybuf = BufferManager::getInstance()->Get(dataID); if (NULL != mybuf) { - Edn::String plop = mybuf->GetName(); + Edn::File plop = mybuf->GetFileName(); SetTitle(plop, mybuf->IsModify() ); } } diff --git a/Sources/GuiTools/MainWindows/MainWindows.h b/Sources/GuiTools/MainWindows/MainWindows.h index f67159e..f4c65ad 100644 --- a/Sources/GuiTools/MainWindows/MainWindows.h +++ b/Sources/GuiTools/MainWindows/MainWindows.h @@ -53,7 +53,8 @@ class MainWindows: public Singleton, public MsgBroadcast static bool OnQuit(GtkWidget *widget, gpointer data); private: - void SetTitle(Edn::String &fileName, bool isModify); + void SetTitle(Edn::File &fileName, bool isModify); + void SetNoTitle(void); // main windows widget : GtkWidget * m_mainWindow; BufferView m_BufferView; diff --git a/Sources/GuiTools/WindowsManager/WindowsManager.cpp b/Sources/GuiTools/WindowsManager/WindowsManager.cpp index 4413eb6..a10c34a 100644 --- a/Sources/GuiTools/WindowsManager/WindowsManager.cpp +++ b/Sources/GuiTools/WindowsManager/WindowsManager.cpp @@ -101,9 +101,9 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID) if( -1 != m_currentBufferID && true == myBufferManager->Exist(m_currentBufferID) ) { - Edn::String fileFolder = myBufferManager->Get(m_currentBufferID)->GetFolder(); - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), fileFolder.c_str()); - //gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), "Untitled document"); + Edn::File fileName = myBufferManager->Get(m_currentBufferID)->GetFileName(); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), fileName.GetFolder().c_str()); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fileName.GetShortFilename().c_str()); } 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); 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, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, // button text @@ -145,7 +145,7 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID) Edn::String myfilename; myfilename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog)); - myBuffer->SetName(myfilename); + myBuffer->SetFileName(myfilename); myBuffer->Save(); SendMessage(EDN_MSG__CURRENT_CHANGE_BUFFER_ID, idSelected); diff --git a/Sources/ctags/CTagsManager.cpp b/Sources/ctags/CTagsManager.cpp index 15d532b..8097f01 100644 --- a/Sources/ctags/CTagsManager.cpp +++ b/Sources/ctags/CTagsManager.cpp @@ -159,9 +159,7 @@ void CTagsManager::AddToHistory(int32_t bufferID) } // add the current element BufferManager *myBufferManager = BufferManager::getInstance(); - Edn::String currentFilename = myBufferManager->Get(bufferID)->GetName(); - int32_t currentLineId = 0; - Edn::File * currentFile = new Edn::File(currentFilename); + Edn::File currentFilename = myBufferManager->Get(bufferID)->GetFileName(); } diff --git a/Sources/tools/NameSpaceEdn/File.cpp b/Sources/tools/NameSpaceEdn/File.cpp index 8de3a7c..e680232 100644 --- a/Sources/tools/NameSpaceEdn/File.cpp +++ b/Sources/tools/NameSpaceEdn/File.cpp @@ -52,41 +52,6 @@ Edn::File::~File(void) // 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) { @@ -106,11 +71,28 @@ Edn::String Edn::File::GetCompleateName(void) 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) { char buf[MAX_FILE_NAME]; memset(buf, 0, MAX_FILE_NAME); char * ok; + // Reset ALL DATA : + m_folder = ""; + m_shortFilename = ""; + m_lineNumberOpen = 0; + Edn::String destFilename; if (newFilename.Size() == 0) { destFilename = "no-name"; @@ -128,19 +110,49 @@ void Edn::File::SetCompleateName(Edn::String &newFilename) destFilename = cCurrentPath; destFilename += '/'; destFilename += tmpFilename; - } + } // Get the real Path of the current File ok = realpath(destFilename.c_str(), buf); 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 { - EDN_DEBUG("file : \"" << destFilename.c_str() << "\" done:\"" << buf << "\" "); - // TODO : try again with no name + destFilename = buf; + 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) { return m_lineNumberOpen; -} \ No newline at end of file +} + diff --git a/Sources/tools/NameSpaceEdn/File.h b/Sources/tools/NameSpaceEdn/File.h index 2c804ea..c3ec62b 100644 --- a/Sources/tools/NameSpaceEdn/File.h +++ b/Sources/tools/NameSpaceEdn/File.h @@ -40,10 +40,10 @@ namespace Edn Edn::String GetCompleateName(void); int32_t GetLineNumber(void); + const Edn::File& operator= (const Edn::File &ednF ); void SetCompleateName(Edn::String &newFilename); private : - void ExtranctAndName(Edn::String &inputString); Edn::String m_folder; Edn::String m_shortFilename; int32_t m_lineNumberOpen; diff --git a/avancement.boo b/avancement.boo index d3b73c0..9453b3a 100644 --- a/avancement.boo +++ b/avancement.boo @@ -17,8 +17,8 @@ - Project manager phase 1 # action a faire (ordonner) : - - HL : Parsing caracter/caractère et plus section par section ... - sys : real filename ... + - HL : Parsing caracter/caractère et plus section par section ... - ctags : Back simple et multiple - ctags : Multiple files - sys : search complet, replace complet