comparison libgui/src/history-dock-widget.cc @ 17254:7fb4461997aa

Adjust history window copy/evaluate and remove carriage returns (bug #39722) * history-dock-widget.cc (history_dock_widget::handle_contextmenu_copy): Add prev_valid_row variable and only add carriage-return between valid lines of text. (history_dock_widget::handle_contextmenu_evaluate): Remove "\n" from end of line sent to Octave core. (history_dock_widget::handle_contextmenu_create_script) Add prev_valid_row variable and only add carriage-return between valid lines of text. (history_dock_widget::handle_double_click) Remove "\n" from end of line sent to Octave core. (history_dock_widget::pasteClipboard) Format consistent with elsewhere.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Wed, 07 Aug 2013 20:18:04 -0500
parents 2527bc7200ee
children d63878346099
comparison
equal deleted inserted replaced
17253:e3870f594d8b 17254:7fb4461997aa
103 { 103 {
104 QString text; 104 QString text;
105 QItemSelectionModel *selectionModel = _history_list_view->selectionModel(); 105 QItemSelectionModel *selectionModel = _history_list_view->selectionModel();
106 QModelIndexList rows = selectionModel->selectedRows(); 106 QModelIndexList rows = selectionModel->selectedRows();
107 QModelIndexList::iterator it; 107 QModelIndexList::iterator it;
108 for (it=rows.begin() ; it != rows.end(); it++) { 108 bool prev_valid_row = false;
109 if ((*it).isValid()) { 109 for (it = rows.begin(); it != rows.end(); it++)
110 text += (*it).data().toString()+"\n"; 110 {
111 } 111 if ((*it).isValid())
112 } 112 {
113 if (prev_valid_row)
114 text += "\n";
115 text += (*it).data().toString();
116 prev_valid_row = true;
117 }
118 }
113 QApplication::clipboard()->setText(text); 119 QApplication::clipboard()->setText(text);
114 } 120 }
115 121
116 void history_dock_widget::handle_contextmenu_evaluate(bool) 122 void history_dock_widget::handle_contextmenu_evaluate(bool)
117 { 123 {
118 QItemSelectionModel *selectionModel = _history_list_view->selectionModel(); 124 QItemSelectionModel *selectionModel = _history_list_view->selectionModel();
119 QModelIndexList rows = selectionModel->selectedRows(); 125 QModelIndexList rows = selectionModel->selectedRows();
120 QModelIndexList::iterator it; 126 QModelIndexList::iterator it;
121 for (it=rows.begin() ; it != rows.end(); it++) { 127 for (it = rows.begin() ; it != rows.end(); it++)
122 if ((*it).isValid()) { 128 {
123 emit command_double_clicked ((*it).data().toString()+"\n"); 129 if ((*it).isValid())
124 } 130 emit command_double_clicked ((*it).data().toString());
125 } 131 }
126 } 132 }
127 133
128 void 134 void
129 history_dock_widget::handle_contextmenu_create_script (bool) 135 history_dock_widget::handle_contextmenu_create_script (bool)
130 { 136 {
131 QString text; 137 QString text;
132 QItemSelectionModel *selectionModel = _history_list_view->selectionModel (); 138 QItemSelectionModel *selectionModel = _history_list_view->selectionModel ();
133 QModelIndexList rows = selectionModel->selectedRows (); 139 QModelIndexList rows = selectionModel->selectedRows ();
134 140
141 bool prev_valid_row = false;
135 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) 142 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
136 { 143 {
137 if ((*it).isValid ()) 144 if ((*it).isValid ())
138 text += (*it).data().toString() + "\n"; 145 {
146 if (prev_valid_row)
147 text += "\n";
148 text += (*it).data().toString();
149 prev_valid_row = true;
150 }
139 } 151 }
140 152
141 if (text.length () > 0) 153 if (text.length () > 0)
142 emit command_create_script (text); 154 emit command_create_script (text);
143 } 155 }
144 156
145 157
146 void 158 void
147 history_dock_widget::handle_double_click (QModelIndex modelIndex) 159 history_dock_widget::handle_double_click (QModelIndex modelIndex)
148 { 160 {
149 emit command_double_clicked (modelIndex.data().toString()+"\n"); 161 emit command_double_clicked (modelIndex.data().toString());
150 } 162 }
151 163
152 void 164 void
153 history_dock_widget::set_history (const QStringList& hist) 165 history_dock_widget::set_history (const QStringList& hist)
154 { 166 {
193 205
194 void 206 void
195 history_dock_widget::pasteClipboard () 207 history_dock_widget::pasteClipboard ()
196 { 208 {
197 if(_filter_line_edit->hasFocus ()) 209 if(_filter_line_edit->hasFocus ())
198 { 210 {
199 QClipboard *clipboard = QApplication::clipboard (); 211 QClipboard *clipboard = QApplication::clipboard ();
200 QString str = clipboard->text (); 212 QString str = clipboard->text ();
201 if (str.length() > 0) 213 if (str.length() > 0)
202 _filter_line_edit->insert (str); 214 _filter_line_edit->insert (str);
203 } 215 }
204 } 216 }
205 217