[Aptitude-svn-commit] r3471 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Sun, 26 Jun 2005 17:57:40 +0000


Author: dburrows
Date: Sun Jun 26 17:57:37 2005
New Revision: 3471

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h
Log:
Allow wide character strings to be passed as the input to vs_file_pager::load_file.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun Jun 26 17:57:37 2005
@@ -1,5 +1,13 @@
 2005-06-26  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/vs_pager.cc:
+
+	  Allow wide character strings to be used for the filename of a
+	  vs_file_pager, to make it easy to bind the vs_editline's
+	  "entered" signal to vs_file_pager::load_file.  Is this a hack?
+	  (and for that matter, why is vs_file_pager still separate from
+	  vs_pager?)
+
 	* src/vscreen/columnify.cc:
 
 	  Use the new transcoder, so transcoding errors can be reported at

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc	Sun Jun 26 17:57:37 2005
@@ -4,6 +4,10 @@
 
 #include "vs_pager.h"
 
+// For _()
+#include "../aptitude.h"
+
+#include "transcode.h"
 #include "vscreen.h"
 #include "vs_minibuf_win.h"
 #include "vs_editline.h"
@@ -285,6 +289,11 @@
   load_file(filename);
 }
 
+vs_file_pager::vs_file_pager(wstring filename):vs_pager("")
+{
+  load_file(filename);
+}
+
 vs_file_pager::vs_file_pager(const char *text, int size)
   :vs_pager(text, size)
 {
@@ -333,3 +342,19 @@
 	}
     }
 }
+
+void vs_file_pager::load_file(wstring filename)
+{
+  string mbfilename;
+
+  if(transcode(filename, mbfilename))
+    load_file(mbfilename);
+  else
+    {
+      char buf[512];
+
+      snprintf(buf, sizeof(buf),
+	       _("Unable to load filename: the string %ls has no multibyte representation."), filename.c_str());
+      set_text(buf);
+    }
+}

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h	Sun Jun 26 17:57:37 2005
@@ -136,14 +136,28 @@
   static void init_bindings();
 };
 
+/** Load a file from disk; it's assumed to be ASCII for now. */
 class vs_file_pager:public vs_pager
 {
 public:
   vs_file_pager();
   vs_file_pager(std::string filename);
+
+  /** Attempts to convert the string to a multibyte representation and
+   *  then load it; a nonconvertible string is treated as any other
+   *  load failure would be.
+   */
+  vs_file_pager(std::wstring filename);
+
   vs_file_pager(const char *text, int len);
 
   void load_file(std::string filename);
+
+  /** Attempts to convert the string to a multibyte representation and
+   *  then load it; a nonconvertible string is treated as any other
+   *  load failure would be.
+   */
+  void load_file(std::wstring filename);
 };
 
 #endif