[haiku-commits] haiku: hrev51601 - src/apps/deskcalc

  • From: humdingerb@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 22 Nov 2017 19:26:16 +0100 (CET)

hrev51601 adds 1 changeset to branch 'master'
old head: df9bc792e0551aaeab6c9f3cabf8127b40d028d8
new head: 6a35420117e7c247dec632b330c0796b1dae02ac
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6a35420117e7+%5Edf9bc792e055

----------------------------------------------------------------------------

6a35420117e7: DeskCalc: remove trailing newlines of dropped files
  
  Initialize the buffer.
  Remove trailing newlines. Before, the dropped expression would
  'scroll' out of view if it happened to have a newline at the
  end.
  Thanks to DeadYak for helpful input which pretty much changed
  my original code about 98%...

                                        [ Humdinger <humdingerb@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51601
Commit:      6a35420117e7c247dec632b330c0796b1dae02ac
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6a35420117e7
Author:      Humdinger <humdingerb@xxxxxxxxx>
Date:        Wed Nov 22 18:21:11 2017 UTC

----------------------------------------------------------------------------

1 file changed, 10 insertions(+), 2 deletions(-)
src/apps/deskcalc/CalcView.cpp | 12 ++++++++++--

----------------------------------------------------------------------------

diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp
index 77cceb6..c9579f4 100644
--- a/src/apps/deskcalc/CalcView.cpp
+++ b/src/apps/deskcalc/CalcView.cpp
@@ -771,12 +771,20 @@ CalcView::Paste(BMessage* message)
                ssize_t read;
                BFile file;
                char buffer[256];
+               memset(buffer, 0, sizeof(buffer));
                for (int32 i = 0; i < count; i++) {
                        if (message->FindRef("refs", i, &ref) == B_OK) {
                                if (file.SetTo(&ref, B_READ_ONLY) == B_OK) {
                                        read = file.Read(buffer, 255);
-                                       buffer[read] = 0;
-                                       fExpressionTextView->Insert(buffer);
+                                       if (read <= 0)
+                                               continue;
+                                       BString expression(buffer);
+                                       while (expression.Length() > 0
+                                               && 
expression[expression.Length() - 1] == '\n') {
+                                               expression.RemoveLast("\n");
+                                       }
+                                       if (expression.Length() > 0)
+                                               
fExpressionTextView->Insert(expression.String());
                                }
                        }
                }


Other related posts: