~nasc-team/nasc/trunk

« back to all changes in this revision

Viewing changes to src/ResultView.vala

  • Committer: Djax
  • Date: 2015-07-22 21:31:52 UTC
  • Revision ID: parnold1@gmail.com-20150722213152-c2xz4w5kvmsz1qdb
formatting

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***
2
 
  BEGIN LICENSE
3
 
 
4
 
  Copyright (C) 2014 Peter Arnold
5
 
  This program is free software: you can redistribute it and/or modify it
6
 
  under the terms of the GNU Lesser General Public License version 3, as
7
 
  published by the Free Software Foundation.
8
 
 
9
 
  This program is distributed in the hope that it will be useful, but
10
 
  WITHOUT ANY WARRANTY; without even the implied warranties of
11
 
  MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
 
  PURPOSE.  See the GNU General Public License for more details.
13
 
 
14
 
  You should have received a copy of the GNU General Public License along
15
 
  with this program.  If not, see <http://www.gnu.org/licenses>
16
 
 
17
 
  END LICENSE
18
 
***/
 
1
/*
 
2
 * Copyright (c) 2015 Peter Arnold
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this program; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
19
19
 
20
20
public class ResultView : Gtk.Box {
21
21
    private Gtk.TextView text_view;
22
22
    private Gdk.Cursor left_ptr = new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.LEFT_PTR);
23
23
    private Gdk.Cursor hand = new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.HAND2);
24
24
    private bool hovering_over_result = false;
25
 
    public Gee.ArrayList<ResultLine> result_list  { get; private set;}
 
25
    public Gee.ArrayList<ResultLine> result_list  { get; private set; }
26
26
    private const int START_WIDTH = 210;
27
27
    private int actual_width = START_WIDTH;
28
28
    private bool update_needed;
50
50
        text_view.set_can_focus (false);
51
51
        bold_tag = text_view.buffer.create_tag ("bold");
52
52
        bold_tag.weight = Pango.Weight.BOLD;
53
 
        // use 12pt font because the superscripts are displayed wrong if font is smaller!
 
53
        /* use 12pt font because the superscripts are displayed wrong if font is smaller! */
54
54
        var font_desc = text_view.get_style_context ().get_font (Gtk.StateFlags.NORMAL);
55
55
        font_desc.set_size (12 * Pango.SCALE);
56
56
        text_view.override_font (font_desc);
57
 
        // background color very light grey
 
57
        /* background color very light grey */
58
58
        var color = Gdk.RGBA ();
59
59
        color.red = 230;
60
60
        color.green = 230;
61
61
        color.blue = 230;
62
62
        color.alpha = 0;
63
63
        text_view.override_background_color (Gtk.StateFlags.NORMAL, color);
64
 
        // listen on result press
 
64
        /* listen on result press */
65
65
        text_view.set_events (Gdk.EventMask.BUTTON_PRESS_MASK);
66
66
        text_view.button_press_event.connect ((evt) => {
67
67
            if (!hovering_over_result) {
78
78
            }
79
79
 
80
80
            text_view.window_to_buffer_coords (Gtk.TextWindowType.TEXT, (int)evt.x, (int)evt.y, out x, out y);
81
 
            text_view.get_iter_at_location ( out iter, x, y);
 
81
            text_view.get_iter_at_location (out iter, x, y);
82
82
            int line_number = iter.get_line ();
83
83
            insert_variable (result_list.get (line_number));
84
84
            text_view.get_window (Gtk.TextWindowType.TEXT).set_cursor (left_ptr);
 
85
 
85
86
            return false;
86
87
        });
87
 
        // listen on result hovering
 
88
        /* listen on result hovering */
88
89
        text_view.set_events (Gdk.EventMask.POINTER_MOTION_MASK);
89
 
        text_view.motion_notify_event .connect ((evt) => {
 
90
        text_view.motion_notify_event.connect ((evt) => {
90
91
            Gtk.TextIter iter;
91
92
            int x, y;
92
93
            text_view.window_to_buffer_coords (Gtk.TextWindowType.TEXT, (int)evt.x, (int)evt.y, out x, out y);
93
 
            text_view.get_iter_at_location ( out iter, x, y);
 
94
            text_view.get_iter_at_location (out iter, x, y);
94
95
            bool hovering = false;
95
96
 
96
97
            foreach (var tag in iter.get_tags ()) {
115
116
        this.override_background_color (Gtk.StateFlags.NORMAL, color);
116
117
        this.pack_start (alignment);
117
118
        this.pack_start (spinner_box);
118
 
 
119
119
    }
120
120
 
121
121
    public void set_width (int width) {
130
130
 
131
131
    public override bool draw (Cairo.Context cr) {
132
132
        var res = base.draw (cr);
133
 
        // change cursor to normal
 
133
        /* change cursor to normal */
134
134
        text_view.get_window (Gtk.TextWindowType.TEXT).set_cursor (left_ptr);
 
135
 
135
136
        return res;
136
137
    }
137
138
 
138
 
    // shows a spinner at the line
 
139
    /* shows a spinner at the line */
139
140
    public void show_spinner (int line) {
140
141
        spinner_box.no_show_all = false;
141
142
        spinner.margin_top = Nasc.top_padding + (line * 27);
142
143
        spinner_box.show_all ();
143
 
        // for (int i = line; i < result_list.size; i++) {
144
 
        //     var res = result_list.get (i);
145
 
        //     res.set_val ("");
146
 
        // }
147
 
        // update (line, true);
 
144
        /*
 
145
         * for (int i = line; i < result_list.size; i++) {
 
146
         *     var res = result_list.get (i);
 
147
         *     res.set_val ("");
 
148
         * }
 
149
         * update (line, true);
 
150
         */
148
151
    }
149
152
 
150
153
    public void hide_spinner () {
166
169
    }
167
170
 
168
171
    public void add_line (int line, int count) {
169
 
        // add new line/lines
 
172
        /* add new line/lines */
170
173
        for (int i = 0; i < count; i++) {
171
174
            if (i + line > result_list.size) {
172
175
                string variable_name = NascSettings.variable_names + "%d".printf (result_list.size);
173
176
                result_list.add (new ResultLine (result_list.size, variable_name, "", actual_width));
174
 
 
175
177
            } else {
176
178
                string variable_name = NascSettings.variable_names + "%d".printf (i + line);
177
179
                result_list.insert (i + line, new ResultLine (i + line, variable_name, "", actual_width));
178
180
            }
179
181
        }
180
182
 
181
 
        //update all lines greater than line
182
 
        for (int i = result_list.size - 1; i >= line + count ; i--) {
 
183
        /* update all lines greater than line */
 
184
        for (int i = result_list.size - 1; i >= line + count; i--) {
183
185
            var tmp = result_list.get (i);
184
186
            tmp.line = i;
185
187
            tmp.variable_name = NascSettings.variable_names + "%d".printf (i);
189
191
    public void remove_line (int line, int count) {
190
192
        if (line <= 0 && count == result_list.size) {
191
193
            result_list.clear ();
 
194
 
192
195
            return;
193
196
        }
194
197
 
199
202
            }
200
203
        }
201
204
 
202
 
        //update all lines greater than line
 
205
        /* update all lines greater than line */
203
206
        for (int i = result_list.size - 1; i >= line; i--) {
204
207
            if (i == -1) {
205
208
                break;
228
231
        text_view.buffer.text = "";
229
232
        text_view.buffer.get_iter_at_offset (out iter, 0);
230
233
 
231
 
        // setting results
 
234
        /* setting results */
232
235
        for (int i = 0; i < result_list.size; i++) {
233
236
            var res = result_list.get (i);
234
237
            Gtk.TextTag tag = text_view.buffer.tag_table.lookup (NascSettings.variable_names + "%d".printf (i));