~ubuntu-branches/ubuntu/vivid/gnote/vivid-proposed

« back to all changes in this revision

Viewing changes to src/notewindow.cpp

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng
  • Date: 2014-10-04 23:29:38 UTC
  • mfrom: (1.3.22)
  • Revision ID: package-import@ubuntu.com-20141004232938-ctmgoabfgfoz27ft
Tags: 3.14.0-1
* New upstream release.
* Update Standards version to 3.9.6, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <config.h>
23
23
#endif
24
24
 
 
25
#include <boost/bind.hpp>
 
26
 
25
27
#include <glibmm/i18n.h>
26
28
#include <gtkmm/grid.h>
27
29
#include <gtkmm/image.h>
89
91
  NoteWindow::NoteWindow(Note & note)
90
92
    : m_note(note)
91
93
    , m_name(note.get_title())
92
 
    , m_height(360)
93
 
    , m_width(450)
 
94
    , m_height(450)
 
95
    , m_width(600)
94
96
    , m_find_handler(note)
95
97
    , m_global_keys(NULL)
96
98
    , m_enabled(true)
116
118
 
117
119
    // Sensitize the Link toolbar button on text selection
118
120
    m_mark_set_timeout = new utils::InterruptableTimeout();
119
 
    m_mark_set_timeout->signal_timeout.connect(
120
 
      sigc::mem_fun(*this, &NoteWindow::update_link_button_sensitivity));
 
121
    m_mark_set_timeout->signal_timeout.connect(sigc::mem_fun(*m_text_menu, &NoteTextMenu::refresh_state));
121
122
    note.get_buffer()->signal_mark_set().connect(
122
123
      sigc::mem_fun(*this, &NoteWindow::on_selection_mark_set));
123
124
 
204
205
 
205
206
  void NoteWindow::hint_size(int & width, int & height)
206
207
  {
 
208
    if (Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(
 
209
          Preferences::AUTOSIZE_NOTE_WINDOW)) {
207
210
    width = m_width;
208
211
    height = m_height;
 
212
    }
209
213
  }
210
214
 
211
215
  void NoteWindow::size_internals()
218
222
    if(!m_accel_group) {
219
223
      m_accel_group = Gtk::AccelGroup::create();
220
224
      window.add_accel_group(m_accel_group);
221
 
      m_text_menu->set_accel_group(m_accel_group);
222
 
      m_link_button->add_accelerator("clicked", m_accel_group,
223
 
                                     GDK_KEY_L, Gdk::CONTROL_MASK,
224
 
                                     Gtk::ACCEL_VISIBLE);
225
225
 
226
226
      if(!m_global_keys) {
227
227
        // NOTE: Since some of our keybindings are only
245
245
                                      Gtk::ACCEL_VISIBLE);
246
246
        m_global_keys->enabled(m_enabled);
247
247
      }
 
248
 
 
249
      m_text_menu->set_accels(*m_global_keys, m_accel_group);
248
250
    }
249
251
    else {
250
252
      window.add_accel_group(m_accel_group);
290
292
        iter != m_widget_actions.end(); ++iter) {
291
293
      res.push_back(iter->second);
292
294
    }
 
295
 
 
296
    res.push_back(Glib::RefPtr<Gtk::Action>());
 
297
    res.push_back(m_important_action);
 
298
    if(m_delete_action) {
 
299
      // Separator before delete
 
300
      res.push_back(m_delete_action);
 
301
    }
293
302
    return res;
294
303
  }
295
304
 
343
352
    }
344
353
  }
345
354
 
346
 
  void NoteWindow::update_link_button_sensitivity()
347
 
  {
348
 
    m_link_button->set_sensitive(!m_note.get_buffer()->get_selection().empty());
349
 
  }
350
 
 
351
355
  void NoteWindow::on_populate_popup(Gtk::Menu* menu)
352
356
  {
353
357
    menu->set_accel_group(m_accel_group);
400
404
    Gtk::Grid *grid = manage(new Gtk::Grid);
401
405
    int grid_col = 0;
402
406
 
403
 
    m_pin_image = manage(new Gtk::Image);
404
 
    m_pin_button = manage(new Gtk::ToolButton(*m_pin_image, _("Pin")));
405
 
 
406
 
    if(m_note.is_pinned()) {
407
 
      m_pin_image->property_gicon() = get_icon_pin_down();
408
 
      m_pin_button->set_tooltip_text(_("Remove from important notes"));
409
 
    }
410
 
    else {
411
 
      m_pin_image->property_gicon() = get_icon_pin_active();
412
 
      m_pin_button->set_tooltip_text(_("Mark note as important"));
413
 
    }
414
 
 
415
 
    m_pin_button->signal_clicked().connect(sigc::mem_fun(*this, &NoteWindow::on_pin_button_clicked));
416
 
    grid->attach(*m_pin_button, grid_col++, 0, 1, 1);
417
 
    notebooks::NotebookManager::obj().signal_note_pin_status_changed
418
 
      .connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
419
 
 
420
 
    m_link_button = manage(new Gtk::ToolButton(
421
 
                             *manage(new Gtk::Image(Gtk::Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)),
422
 
                             _("Link")));
423
 
    m_link_button->set_use_underline(true);
424
 
    m_link_button->set_is_important(true);
425
 
    m_link_button->set_sensitive(!m_note.get_buffer()->get_selection().empty());
426
 
    m_link_button->signal_clicked().connect(
427
 
      sigc::mem_fun(*this, &NoteWindow::link_button_clicked));
428
 
    m_link_button->set_tooltip_text(_("Link selected text to a new note (Ctrl-L)"));
429
 
    m_link_button->show_all();
430
 
    grid->attach(*m_link_button, grid_col++, 0, 1, 1);
431
 
 
432
 
    utils::ToolMenuButton *text_button = manage(new utils::ToolMenuButton(
433
 
        *manage(new Gtk::Image(Gtk::Stock::SELECT_FONT, Gtk::ICON_SIZE_SMALL_TOOLBAR)),
434
 
        _("_Text"), m_text_menu));
435
 
    text_button->set_use_underline(true);
436
 
    text_button->set_is_important(true);
 
407
    Gtk::Button *text_button = manage(new Gtk::Button);
 
408
    Gtk::Image *image = manage(new Gtk::Image);
 
409
    image->property_icon_name() = "insert-text-symbolic";
 
410
    image->property_icon_size() = GTK_ICON_SIZE_MENU;
 
411
    text_button->set_image(*image);
 
412
    text_button->signal_clicked()
 
413
      .connect(sigc::mem_fun(*this, &NoteWindow::on_text_button_clicked));
 
414
    text_button->property_margin_left() = 12;
437
415
    text_button->show_all();
438
416
    grid->attach(*text_button, grid_col++, 0, 1, 1);
439
417
    text_button->set_tooltip_text(_("Set properties of text"));
440
 
 
441
 
    grid->attach(*manage(new Gtk::SeparatorToolItem()), grid_col++, 0, 1, 1);
442
 
 
443
 
    m_delete_button = manage(new Gtk::ToolButton(Gtk::Stock::DELETE));
444
 
    m_delete_button->set_use_underline(true);
445
 
    m_delete_button->signal_clicked().connect(
446
 
      sigc::mem_fun(*this, &NoteWindow::on_delete_button_clicked));
447
 
    m_delete_button->show_all();
448
 
    grid->attach(*m_delete_button, grid_col++, 0, 1, 1);
449
 
    m_delete_button->set_tooltip_text(_("Delete this note"));
 
418
    m_text_menu->property_attach_widget() = text_button;
 
419
 
 
420
    m_important_action = utils::CheckAction::create("mark-important");
 
421
    m_important_action->set_label(_("Is Important"));
 
422
    m_important_action->set_tooltip(_("Toggle notes presence in Important Notes notebook"));
 
423
    m_important_action->checked(m_note.is_pinned());
 
424
    m_important_action->signal_activate().connect(sigc::mem_fun(*this, &NoteWindow::on_pin_button_clicked));
 
425
    notebooks::NotebookManager::obj().signal_note_pin_status_changed
 
426
      .connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
450
427
 
451
428
      // Don't allow deleting the "Start Here" note...
452
 
    if (m_note.is_special()) {
453
 
      m_delete_button->set_sensitive(false);
 
429
    if(!m_note.is_special()) {
 
430
      m_delete_action = Gtk::Action::create("delete-note", _("_Delete"), _("Delete this note"));
 
431
      m_delete_action->signal_activate()
 
432
        .connect(sigc::mem_fun(*this, &NoteWindow::on_delete_button_clicked));
454
433
    }
455
 
    grid->attach(*manage(new Gtk::SeparatorToolItem()), grid_col++, 0, 1, 1);
456
434
 
 
435
    grid->property_margin_left() = 12;
457
436
    grid->show_all();
458
437
    return grid;
459
438
  }
616
595
    if(&m_note != &note) {
617
596
      return;
618
597
    }
619
 
    if(pinned) {
620
 
      m_pin_image->property_gicon() = get_icon_pin_down();
621
 
      m_pin_button->set_tooltip_text(_("Remove from important notes"));
622
 
    }
623
 
    else {
624
 
      m_pin_image->property_gicon() = get_icon_pin_active();
625
 
      m_pin_button->set_tooltip_text(_("Mark note as important"));
626
 
    }
 
598
    m_important_action->checked(pinned);
627
599
  }
628
600
 
629
601
  void NoteWindow::on_pin_button_clicked()
631
603
    m_note.set_pinned(!m_note.is_pinned());
632
604
  }
633
605
 
 
606
  void NoteWindow::on_text_button_clicked()
 
607
  {
 
608
    m_text_menu->show_all();
 
609
    utils::popup_menu(*m_text_menu, NULL);
 
610
  }
 
611
 
634
612
  void NoteWindow::enabled(bool enable)
635
613
  {
636
614
    m_enabled = enable;
846
824
    : Gtk::Menu()
847
825
    , m_buffer(buffer)
848
826
    , m_undo_manager(undo_manager)
 
827
    , m_link(_("_Link"), true)
849
828
    , m_bold(_("<b>_Bold</b>"), true)
850
829
    , m_italic(_("<i>_Italic</i>"), true)
851
830
    , m_strikeout(_("<s>_Strikeout</s>"), true)
863
842
    , m_bullets(_("Bullets"))
864
843
    , m_increase_indent(Gtk::Stock::INDENT)
865
844
    , m_decrease_indent(Gtk::Stock::UNINDENT)
866
 
    , m_increase_font(_("Increase Font Size"), true)
867
 
    , m_decrease_font(_("Decrease Font Size"), true)
868
845
    {
869
846
      m_undo = manage(new Gtk::ImageMenuItem (Gtk::Stock::UNDO));
870
847
      m_undo->signal_activate().connect(sigc::mem_fun(*this, &NoteTextMenu::undo_clicked));
884
861
      undo_manager.signal_undo_changed().connect(sigc::mem_fun(*this, &NoteTextMenu::undo_changed));
885
862
 
886
863
      Glib::Quark tag_quark("Tag");
 
864
      markup_label(m_link);
 
865
      m_link.signal_activate()
 
866
        .connect(sigc::mem_fun(*this, &NoteTextMenu::link_clicked));
 
867
 
887
868
      markup_label(m_bold);
888
869
      m_bold.set_data(tag_quark, const_cast<char*>("bold"));
889
870
      m_bold.signal_activate()
904
885
      m_highlight.signal_activate()
905
886
        .connect(sigc::bind(sigc::mem_fun(*this, &NoteTextMenu::font_style_clicked), &m_highlight));
906
887
 
907
 
      Gtk::SeparatorMenuItem *spacer1 = manage(new Gtk::SeparatorMenuItem());
908
 
 
909
888
      markup_label(m_normal);
910
889
      m_normal.set_active(true);
911
890
      m_normal.signal_activate()
928
907
 
929
908
      m_hidden_no_size.hide();
930
909
 
931
 
      m_increase_font.signal_activate()
932
 
        .connect(sigc::mem_fun(*this, &NoteTextMenu::increase_font_clicked));
933
 
 
934
 
      m_decrease_font.signal_activate()
935
 
        .connect(sigc::mem_fun(*this, &NoteTextMenu::decrease_font_clicked));
936
 
 
937
 
      Gtk::SeparatorMenuItem *spacer2 = manage(new Gtk::SeparatorMenuItem());
938
 
 
939
910
      m_bullets_clicked_cid = m_bullets.signal_activate()
940
911
        .connect(sigc::mem_fun(*this, &NoteTextMenu::toggle_bullets_clicked));
941
912
 
949
920
 
950
921
      refresh_state();
951
922
 
 
923
      append(m_link);
 
924
      append(*manage(new Gtk::SeparatorMenuItem()));
952
925
      append(m_bold);
953
926
      append(m_italic);
954
927
      append(m_strikeout);
955
928
      append(m_highlight);
956
 
      append(*spacer1);
 
929
      append(*manage(new Gtk::SeparatorMenuItem()));
957
930
      append(m_small);
958
931
      append(m_normal);
959
932
      append(m_large);
960
933
      append(m_huge);
961
 
      append(m_increase_font);
962
 
      append(m_decrease_font);
963
 
      append(*spacer2);
 
934
      append(*manage(new Gtk::SeparatorMenuItem()));
964
935
      append(m_bullets);
965
936
      append(m_increase_indent);
966
937
      append(m_decrease_indent);
967
938
      show_all ();
968
939
    }
969
940
 
970
 
  void NoteTextMenu::set_accel_group(const Glib::RefPtr<Gtk::AccelGroup> & accel_group)
 
941
  void NoteTextMenu::set_accels(utils::GlobalKeybinder & keybinder,
 
942
                                const Glib::RefPtr<Gtk::AccelGroup> & accel_group)
971
943
  {
 
944
    set_accel_group(accel_group);
972
945
    m_undo->add_accelerator("activate", accel_group,
973
946
                            GDK_KEY_Z,
974
947
                            Gdk::CONTROL_MASK,
977
950
                            GDK_KEY_Z,
978
951
                            Gdk::CONTROL_MASK | Gdk::SHIFT_MASK,
979
952
                            Gtk::ACCEL_VISIBLE);
 
953
    m_link.add_accelerator("activate", accel_group,
 
954
                           GDK_KEY_L, Gdk::CONTROL_MASK,
 
955
                           Gtk::ACCEL_VISIBLE);
980
956
    m_bold.add_accelerator("activate", accel_group,
981
957
                           GDK_KEY_B,
982
958
                           Gdk::CONTROL_MASK,
993
969
                                GDK_KEY_H,
994
970
                                Gdk::CONTROL_MASK,
995
971
                                Gtk::ACCEL_VISIBLE);
996
 
    m_increase_font.add_accelerator("activate", accel_group,
997
 
                                    GDK_KEY_plus,
998
 
                                    Gdk::CONTROL_MASK,
999
 
                                    Gtk::ACCEL_VISIBLE);
1000
 
    m_decrease_font.add_accelerator("activate", accel_group,
1001
 
                                    GDK_KEY_minus,
1002
 
                                    Gdk::CONTROL_MASK,
1003
 
                                    Gtk::ACCEL_VISIBLE);
 
972
    keybinder.add_accelerator(sigc::mem_fun(*this, &NoteTextMenu::increase_font_clicked),
 
973
                              GDK_KEY_plus, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
 
974
    keybinder.add_accelerator(sigc::mem_fun(*this, &NoteTextMenu::decrease_font_clicked),
 
975
                              GDK_KEY_minus, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
1004
976
    m_increase_indent.add_accelerator("activate", accel_group,
1005
977
                                      GDK_KEY_Right,
1006
978
                                      Gdk::MOD1_MASK,
1058
1030
  {
1059
1031
    m_event_freeze = true;
1060
1032
 
 
1033
    Gtk::TextIter start, end;
 
1034
    m_link.set_sensitive(m_buffer->get_selection_bounds(start, end));
1061
1035
    m_bold.set_active(m_buffer->is_active_tag("bold"));
1062
1036
    m_italic.set_active(m_buffer->is_active_tag("italic"));
1063
1037
    m_strikeout.set_active(m_buffer->is_active_tag("strikethrough"));
1080
1054
    m_event_freeze = false;
1081
1055
  }
1082
1056
 
 
1057
  void NoteTextMenu::link_clicked()
 
1058
  {
 
1059
    if(m_event_freeze) {
 
1060
      return;
 
1061
    }
 
1062
 
 
1063
    Glib::ustring select = m_buffer->get_selection();
 
1064
    if(select.empty()) {
 
1065
      return;
 
1066
    }
 
1067
 
 
1068
    Glib::ustring body_unused;
 
1069
    Glib::ustring title = NoteManagerBase::split_title_from_content(select, body_unused);
 
1070
    if(title.empty()) {
 
1071
      return;
 
1072
    }
 
1073
 
 
1074
    NoteManagerBase & manager(m_buffer->note().manager());
 
1075
    NoteBase::Ptr match = manager.find(title);
 
1076
    if(!match) {
 
1077
      try {
 
1078
        match = manager.create(select);
 
1079
      }
 
1080
      catch(const sharp::Exception & e) {
 
1081
        utils::HIGMessageDialog dialog(dynamic_cast<Gtk::Window*>(m_buffer->note().get_window()->host()),
 
1082
          GTK_DIALOG_DESTROY_WITH_PARENT,
 
1083
          Gtk::MESSAGE_ERROR,  Gtk::BUTTONS_OK,
 
1084
          _("Cannot create note"), e.what());
 
1085
        dialog.run();
 
1086
        return;
 
1087
      }
 
1088
    }
 
1089
    else {
 
1090
      Gtk::TextIter start, end;
 
1091
      m_buffer->get_selection_bounds(start, end);
 
1092
      m_buffer->remove_tag(m_buffer->note().get_tag_table()->get_broken_link_tag(), start, end);
 
1093
      m_buffer->apply_tag(m_buffer->note().get_tag_table()->get_link_tag(), start, end);
 
1094
    }
 
1095
 
 
1096
    m_buffer->note().get_window()->host()->embed_widget(*static_pointer_cast<Note>(match)->get_window());
 
1097
  }
 
1098
 
1083
1099
  //
1084
1100
  // Font-style menu item activate
1085
1101
  //