[colobot] 200/390: Better handling of filenames longer than maximum allowed

Didier Raboud odyx at moszumanska.debian.org
Fri Jun 12 14:21:45 UTC 2015


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch upstream/latest
in repository colobot.

commit 97e76e630394e99d8768f2377b60a5b19304da86
Author: krzys-h <krzys_h at interia.pl>
Date:   Mon Nov 10 22:07:51 2014 +0100

    Better handling of filenames longer than maximum allowed
    
     #354
---
 src/ui/studio.cpp | 34 +++++++++++++++++++++++-----------
 src/ui/studio.h   |  2 ++
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index 7198b91..5f4ca34 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -1091,10 +1091,6 @@ void CStudio::StartDialog(StudioDialog type)
 
         pe = pw->CreateEdit(pos, dim, 0, EVENT_DIALOG_EDIT);
         pe->SetState(STATE_SHADOW);
-        if ( m_dialog == SD_SAVE )
-        {
-            pe->SetText(m_script->GetFilename());
-        }
 
         GetResource(RES_TEXT, RT_IO_DIR, name);
         pla = pw->CreateLabel(pos, dim, 0, EVENT_DIALOG_LABEL3, name);
@@ -1125,6 +1121,12 @@ void CStudio::StartDialog(StudioDialog type)
         UpdateDialogList();
         UpdateDialogPublic();
         UpdateDialogAction();
+        
+        if ( m_dialog == SD_SAVE )
+        {
+            SetFilenameField(pe, m_script->GetFilename());
+            UpdateChangeEdit();
+        }
 
         pe->SetCursor(999, 0);  // selects all
         pe->SetFocus(true);
@@ -1377,8 +1379,6 @@ void CStudio::UpdateChangeList()
     CWindow*    pw;
     CList*      pl;
     CEdit*      pe;
-    char        name[100];
-    char*       p;
 
     pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
     if ( pw == nullptr )  return;
@@ -1387,17 +1387,29 @@ void CStudio::UpdateChangeList()
     pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT));
     if ( pe == nullptr )  return;
 
-    strcpy(name, pl->GetItemName(pl->GetSelect()));
-    name[pe->GetMaxChar()] = 0;  // truncates according lg max editable
-    p = strchr(name, '\t');  // seeks first tab
-    if ( p != 0 )  *p = 0;
-    pe->SetText(name);
+    std::string name = pl->GetItemName(pl->GetSelect());
+    name = name.substr(0, name.find_first_of("\t"));
+    SetFilenameField(pe, name);
     pe->SetCursor(999, 0);  // selects all
     pe->SetFocus(true);
 
     UpdateDialogAction();
 }
 
+void CStudio::SetFilenameField(CEdit* edit, const std::string& filename)
+{
+    std::string name = filename;
+    if(name.length() > edit->GetMaxChar()) {
+        if(name.substr(name.length()-4) == ".txt")
+            name = name.substr(0, name.length()-4);
+        if(name.length() > edit->GetMaxChar()) {
+            CLogger::GetInstancePointer()->Warn("Tried to load too long filename!\n");
+            name = name.substr(0, edit->GetMaxChar());  // truncates according to max length
+        }
+    }
+    edit->SetText(name.c_str());
+}
+
 // Updates the list after a change in name.
 
 void CStudio::UpdateChangeEdit()
diff --git a/src/ui/studio.h b/src/ui/studio.h
index a11d706..c5c80f1 100644
--- a/src/ui/studio.h
+++ b/src/ui/studio.h
@@ -91,6 +91,8 @@ protected:
     std::string  SearchDirectory(bool bCreate);
     bool        ReadProgram();
     bool        WriteProgram();
+    
+    void        SetFilenameField(CEdit* edit, const std::string& filename);
 
 protected:
     Gfx::CEngine*    m_engine;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list