void BugzillaNoteAddin::initialize() { if(!get_note()->get_tag_table()->is_dynamic_tag_registered(TAG_NAME)) { get_note()->get_tag_table() ->register_dynamic_tag(TAG_NAME, sigc::ptr_fun(&BugzillaLink::create)); } }
void NotebookNoteAddin::on_new_notebook_menu_item() { Note::List noteList; noteList.push_back(get_note()); NotebookManager::obj().prompt_create_new_notebook( dynamic_cast<Gtk::Window*>(get_note()->get_window()->host()), noteList); }
void TableofcontentsNoteAddin::get_toc_items(std::vector<TocItem> & items) const { Gtk::TextIter iter, iter_end, eol; //for each line of the buffer, //check if the full line has bold and (large or huge) tags iter = get_note()->get_buffer()->begin(); iter_end = get_note()->get_buffer()->end(); while (iter != iter_end) { eol = iter; eol.forward_to_line_end(); TocItem item; item.heading_level = get_heading_level_for_range (iter, eol); if (item.heading_level == Heading::Level_1 || item.heading_level == Heading::Level_2) { item.heading_position = iter.get_offset(); item.heading = iter.get_text(eol); items.push_back(item); } iter.forward_visible_line(); //next line } }
void NotebookNoteAddin::initialize_tool_button() { gint icon_size = 16; gtk_icon_size_lookup(GTK_ICON_SIZE_SMALL_TOOLBAR, &icon_size, NULL); Gtk::Grid *grid = manage(new Gtk::Grid); grid->attach(*manage(new Gtk::Image( IconManager::obj().get_icon(IconManager::NOTEBOOK, icon_size))), 0, 0, 1, 1); m_label_widget = manage(new Gtk::Label); m_label_widget->set_vexpand(true); m_label_widget->set_valign(Gtk::ALIGN_CENTER); grid->attach(*m_label_widget, 1, 0, 1, 1); m_toolButton = Gtk::manage(new gnote::utils::ToolMenuButton(*grid, m_menu)); m_toolButton->set_tooltip_text(_("Place this note into a notebook")); m_show_menu_cid = m_menu->signal_show() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_menu_shown)); m_toolButton->show_all(); add_tool_item(m_toolButton, -1); update_notebook_button_label(); m_note_added_cid = NotebookManager::obj().signal_note_added_to_notebook() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_added_to_notebook)); m_note_removed_cid = NotebookManager::obj().signal_note_removed_from_notebook() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_removed_from_notebook)); get_note()->signal_tag_added() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_tag_added)); // TODO: Make sure this is handled in NotebookNoteAddin, too get_note()->signal_tag_removed() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_tag_removed)); }
Note get_note (Operation operation, NoteKey key) { if (operation.is_phi_handle()) return get_note(*operation.get_phi_handle(), key); else return get_note(*operation.get_instr_handle(), key); }
void NotebookNoteAddin::update_menu() { // // Clear out the old list // for(std::list<Gtk::MenuItem *>::const_iterator iter = m_menu_items.begin(); iter != m_menu_items.end(); ++iter) { m_menu->remove (**iter); } m_menu_items.clear(); // // Build a new menu // // Add the "New Notebook..." Gtk::ImageMenuItem *newNotebookMenuItem = manage(new Gtk::ImageMenuItem (_("_New notebook..."), true)); newNotebookMenuItem->set_image(*manage(new Gtk::Image( IconManager::obj().get_icon(IconManager::NOTEBOOK_NEW, 16)))); newNotebookMenuItem->signal_activate() .connect(sigc::mem_fun(*this,&NotebookNoteAddin::on_new_notebook_menu_item)); newNotebookMenuItem->show (); m_menu->append (*newNotebookMenuItem); m_menu_items.push_back(newNotebookMenuItem); // Add the "(no notebook)" item at the top of the list NotebookMenuItem *noNotebookMenuItem = manage(new NotebookMenuItem (m_radio_group, get_note(), Notebook::Ptr())); noNotebookMenuItem->show_all (); m_menu->append (*noNotebookMenuItem); m_menu_items.push_back(noNotebookMenuItem); NotebookMenuItem *active_menu_item = noNotebookMenuItem; Notebook::Ptr current_notebook = NotebookManager::obj().get_notebook_from_note(get_note()); // Add in all the real notebooks std::list<NotebookMenuItem*> notebookMenuItems; get_notebook_menu_items (notebookMenuItems); if (!notebookMenuItems.empty()) { Gtk::SeparatorMenuItem *separator = manage(new Gtk::SeparatorMenuItem ()); separator->show_all (); m_menu->append (*separator); m_menu_items.push_back(separator); for(std::list<NotebookMenuItem*>::const_iterator iter = notebookMenuItems.begin(); iter != notebookMenuItems.end(); ++iter) { NotebookMenuItem* item = *iter; item->show_all (); m_menu->append (*item); m_menu_items.push_back(item); if(current_notebook == item->get_notebook()) active_menu_item = item; } } active_menu_item->set_active(true); }
void TableofcontentsNoteAddin::populate_toc_menu (Gtk::Menu *toc_menu, bool has_action_entries) //populate a menu with Note's table of contents { // Clear out the old list std::vector<Gtk::Widget*> menu_items = toc_menu->get_children(); for(std::vector<Gtk::Widget*>::reverse_iterator iter = menu_items.rbegin(); iter != menu_items.rend(); ++iter) { toc_menu->remove(**iter); } // Build a new list std::list<TableofcontentsMenuItem*> items; get_tableofcontents_menu_items(items); for(std::list<TableofcontentsMenuItem*>::iterator iter = items.begin(); iter != items.end(); ++iter) { TableofcontentsMenuItem *item(*iter); item->show_all(); toc_menu->append(*item); } // Action menu items, or nothing if (has_action_entries == false) { if (toc_menu->get_children().size() == 0) { // no toc items, and no action entries = empty menu Gtk::MenuItem *item = manage(new Gtk::MenuItem(_("(empty table of contents)"))); item->set_sensitive(false); item->show(); toc_menu->append(*item); } } else { Gtk::MenuItem *item; if (toc_menu->get_children().size() != 0) { //there are toc items, we add a separator item = manage(new Gtk::SeparatorMenuItem ()); item->show (); toc_menu->append(*item); } item = manage(new Gtk::MenuItem (_("Heading 1"))); item->add_accelerator("activate", get_note()->get_window()->get_accel_group(), GDK_KEY_1, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); item->signal_activate().connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_1_activated)); item->show (); toc_menu->append(*item); item = manage(new Gtk::MenuItem (_("Heading 2"))); item->add_accelerator("activate", get_note()->get_window()->get_accel_group(), GDK_KEY_2, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); item->signal_activate().connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_2_activated)); item->show (); toc_menu->append(*item); item = manage(new Gtk::MenuItem (_("Table of Contents Help"))); item->signal_activate().connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_toc_help_activated)); item->show (); toc_menu->append(*item); } }
void UnderlineNoteAddin::initialize () { // If a tag of this name already exists, don't install. if (!get_note()->get_tag_table()->lookup ("underline")) { m_tag = Glib::RefPtr<Gtk::TextTag>(new UnderlineTag ()); get_note()->get_tag_table()->add (m_tag); } }
void FixedWidthNoteAddin::initialize () { // If a tag of this name already exists, don't install. if (!get_note()->get_tag_table()->lookup ("monospace")) { m_tag = Glib::RefPtr<Gtk::TextTag>(new FixedWidthTag ()); get_note()->get_tag_table()->add (m_tag); } }
void PrintNotesNoteAddin::print_button_clicked(const Glib::VariantBase&) { try { m_print_op = Gtk::PrintOperation::create(); m_print_op->set_job_name(get_note()->get_title()); Glib::RefPtr<Gtk::PrintSettings> settings = Gtk::PrintSettings::create(); Glib::ustring dir = Glib::get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); if (dir.empty()) { dir = Glib::get_home_dir(); } Glib::ustring ext; if (settings->get(Gtk::PrintSettings::Keys::OUTPUT_FILE_FORMAT) == "ps") { ext = ".ps"; } else { ext = ".pdf"; } Glib::ustring uri = "file://"; uri += dir + "/gnotes" + ext; settings->set (Gtk::PrintSettings::Keys::OUTPUT_URI, uri); m_print_op->set_print_settings (settings); m_print_op->signal_begin_print().connect( sigc::mem_fun(*this, &PrintNotesNoteAddin::on_begin_print)); m_print_op->signal_draw_page().connect( sigc::mem_fun(*this, &PrintNotesNoteAddin::on_draw_page)); m_print_op->signal_end_print().connect( sigc::mem_fun(*this, &PrintNotesNoteAddin::on_end_print)); m_print_op->run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, *get_host_window()); } catch (const sharp::Exception & e) { DBG_OUT("Exception while printing %s: %s", get_note()->get_title().c_str(), e.what()); gnote::utils::HIGMessageDialog dlg(get_host_window(), GTK_DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, _("Error printing note"), e.what()); dlg.run (); } m_print_op.clear(); // yeah I really mean clear the pointer. }
void NotebookNoteAddin::on_note_added_to_notebook(const Note & note, const Notebook::Ptr & notebook) { if(¬e == get_note().get()) { update_notebook_button_label(notebook); } }
/* This routine walks the procedure's instruction list, records what * virtual registers are encounters and what are their types, and then * produces a bunch of declarations for these virtual registers. */ void M2c::process_vr_decls(ProcDef *pd) { int i; // initialize the vr_table OneNote<long> note = get_note(pd, k_vr_count); int vr_count = note.get_value(); vr_table = new TypeId[vr_count]; for (i = 0; i < vr_count; i++) vr_table[i] = NULL; VrFilter filter(vr_table); // record the type for each vr found as a destination while (cur_handle != end(cur_body)) { map_dst_opnds(*cur_handle, filter); ++cur_handle; } // print declaration for each vr used in procedure fprintf(out, "\n\n/* Virtual register declarations */\n"); for (i = 0; i < vr_count; i++) { if (vr_table[i]) { char buf[1024]; sprintf(buf, " _vr%d", i); printer->print_sym_decl(buf, vr_table[i]); fputs(";\n", out); } } fprintf(out, "\n"); delete [] vr_table; }
void TableofcontentsNoteAddin::get_toc_popover_items(std::vector<Gtk::Widget*> & items) const { std::vector<TocItem> toc_items; get_toc_items(toc_items); if(toc_items.size()) { auto item = dynamic_cast<Gtk::ModelButton*>(gnote::utils::create_popover_button("win.tableofcontents-goto-heading", "")); Gtk::Label *label = (Gtk::Label*)item->get_child(); label->set_markup("<b>" + get_note()->get_title() + "</b>"); gtk_actionable_set_action_target_value(GTK_ACTIONABLE(item->gobj()), g_variant_new_int32(0)); item->property_role() = Gtk::BUTTON_ROLE_NORMAL; item->property_inverted() = true; item->property_centered() = false; items.push_back(item); } for(auto & toc_item : toc_items) { if(toc_item.heading_level == Heading::Level_2) { toc_item.heading = "→ " + toc_item.heading; } auto item = dynamic_cast<Gtk::ModelButton*>(gnote::utils::create_popover_button("win.tableofcontents-goto-heading", toc_item.heading)); if(toc_item.heading_level == Heading::Level_1) { item->set_image(*manage(new Gtk::Image(Gtk::Stock::GO_FORWARD, Gtk::ICON_SIZE_MENU))); } gtk_actionable_set_action_target_value(GTK_ACTIONABLE(item->gobj()), g_variant_new_int32(toc_item.heading_position)); item->property_role() = Gtk::BUTTON_ROLE_NORMAL; item->property_inverted() = true; item->property_centered() = false; items.push_back(item); } }
void NotebookNoteAddin::on_note_tag_added(const Note & note, const Tag::Ptr & tag) { Note::Ptr taggedNote = const_cast<Note&>(note).shared_from_this(); if(taggedNote == get_note() && tag == get_template_tag()) { update_button_sensitivity(true); } }
void NotebookNoteAddin::on_note_removed_from_notebook(const Note & note, const Notebook::Ptr &) { if(¬e == get_note().get()) { update_notebook_button_label(); } }
void UnderlineNoteAddin::shutdown () { // Remove the tag only if we installed it. if (m_tag) { get_note()->get_tag_table()->remove (m_tag); } }
bool BugzillaNoteAddin::insert_bug(int x, int y, const std::string & uri, int id) { try { BugzillaLink::Ptr link_tag = BugzillaLink::Ptr::cast_dynamic(get_note()->get_tag_table()->create_dynamic_tag(TAG_NAME)); link_tag->set_bug_url(uri); // Place the cursor in the position where the uri was // dropped, adjusting x,y by the TextView's VisibleRect. Gdk::Rectangle rect; get_window()->editor()->get_visible_rect(rect); x = x + rect.get_x(); y = y + rect.get_y(); Gtk::TextIter cursor; gnote::NoteBuffer::Ptr buffer = get_buffer(); get_window()->editor()->get_iter_at_location(cursor, x, y); buffer->place_cursor (cursor); std::string string_id = boost::lexical_cast<std::string>(id); buffer->undoer().add_undo_action (new InsertBugAction (cursor, string_id, link_tag)); std::vector<Glib::RefPtr<Gtk::TextTag> > tags; tags.push_back(link_tag); buffer->insert_with_tags (cursor, string_id, tags); return true; } catch (...) { } return false; }
void add_note(char *path){ char *new_note = (char *)malloc(NOTE_SIZE); if (get_note(new_note) == true){ //note passed the check FILE *f; if ((f = fopen(path, "a")) == NULL){ puts("Cannot write note."); fflush(stdout); free(new_note); exit(1); } fputs(new_note, f); fclose(f); puts("Note added."); fflush(stdout); }else{ puts("Your note contained invalid characters. Please try again."); fflush(stdout); } free(new_note); }
void mode_list(note_db_t *db, int longout, enum sort_policy sort, int invert_order, char *tag){ int i; note_t note; sort_notes(db, sort); for(i=0;i<db->len;i++){ int tag_i; if(invert_order) note=*get_note(db, db->len-1-i); else note=*get_note(db, i); if(tag!=NULL && !has_tag(¬e, tag)) continue; if(note.importance>5){ //ANSI red printf("\x1b[31m"); if(note.importance>7) //ANSI bright printf("\x1b[1m"); } if(longout){ char date_string[20]; struct tm *time=localtime(¬e.created); strftime(date_string, 20, "%F %H:%M:%S",time); printf("%2d %d %s %s", note.id, note.importance, date_string, note.text); }else{ printf("%2d %s", note.id, note.text); } //Disable all ANSI printf("\x1b[0m"); for(tag_i=0;tag_i<note.ntags;tag_i++){ int fg, bg; putchar(' '); fg=(hash_str(note.tags[tag_i], 22))%8; bg=(hash_str(note.tags[tag_i], 19))%8; if(fg==bg) bg=(bg==7 ? bg+1 : bg-1); //ANSI: set foreground and background colors printf("\x1b[%dm\x1b[%dm", 30+fg, 40+bg); printf("#%s", note.tags[tag_i]); printf("\x1b[0m"); //Disable all ANSI } putchar('\n'); } }
void BacklinksNoteAddin::get_backlink_menu_items(std::list<Gtk::Widget*> & items) const { gnote::NoteBase::List notes = get_note()->manager().get_notes_linking_to(get_note()->get_title()); FOREACH(const gnote::NoteBase::Ptr & note, notes) { if(note != get_note()) { // don't match ourself auto button = manage(gnote::utils::create_popover_button("win.backlinks-open-note", note->get_title())); gtk_actionable_set_action_target_value(GTK_ACTIONABLE(button->gobj()), Glib::Variant<Glib::ustring>::create(note->uri()).gobj()); items.push_back(button); } } items.sort([](Gtk::Widget *x, Gtk::Widget *y) { return dynamic_cast<Gtk::ModelButton*>(x)->get_label() < dynamic_cast<Gtk::ModelButton*>(y)->get_label(); }); }
void TableofcontentsNoteAddin::on_note_changed() { auto win = get_note()->get_window(); if(!win) { return; } win->signal_popover_widgets_changed(); }
void Summarize::do_opt_unit(OptUnit *unit) { const char *unit_name = get_name(unit).chars(); LineNote note = get_note(unit, k_line); claim(!is_null(note), "Missing `line' annotation on unit `%s'", unit_name); const char *file_name = note.get_file().chars(); debug(1, "Processing procedure `%s' from file `%s'", unit_name, file_name); // This pass requires a unit's body to be a CFG. Be sure that a // preceding pass has left it in that form. claim(is_kind_of<Cfg>(get_body(unit)), "Body is not in CFG form"); Cfg *unit_cfg = static_cast<Cfg*>(get_body(unit)); if_debug(5) fprint(stdout, unit_cfg, false, true); // no layout, just code for (int i = 0; i < nodes_size(unit_cfg); ++i) { CfgNode *block = get_node(unit_cfg, i); for (InstrHandle h = start(block); h != end(block); ++h) if (HaltLabelNote note = get_note(*h, k_halt)) switch (note.get_kind()) { case halt::CBR: summarize_branch('c', out, block, note, max_event_id); break; case halt::MBR: summarize_branch('m', out, block, note, max_event_id); break; case halt::ENTRY: fprintf(out, "p %ld 1 %d %s:%s\n", note.get_unique_id(), find_branch_id(block, max_event_id), file_name, unit_name); break; case halt::EXIT: fprintf(out, "r %ld 0\n", note.get_unique_id()); break; } } }
int copy_note(struct notes_tree *t, const unsigned char *from_obj, const unsigned char *to_obj, int force, combine_notes_fn combine_notes) { const unsigned char *note = get_note(t, from_obj); const unsigned char *existing_note = get_note(t, to_obj); if (!force && existing_note) return 1; if (note) return add_note(t, to_obj, note, combine_notes); else if (existing_note) return add_note(t, to_obj, null_sha1, combine_notes); return 0; }
int copy_note(struct notes_tree *t, const struct object_id *from_obj, const struct object_id *to_obj, int force, combine_notes_fn combine_notes) { const struct object_id *note = get_note(t, from_obj); const struct object_id *existing_note = get_note(t, to_obj); if (!force && existing_note) return 1; if (note) return add_note(t, to_obj, note, combine_notes); else if (existing_note) return add_note(t, to_obj, &null_oid, combine_notes); return 0; }
Context* target_context(FileBlock* file_block) { OneNote<IdString> libnote = get_note(file_block, k_target_lib); claim(!is_null(libnote), "expected target_lib annotation on file block"); IdString libname = libnote.get_value(); return find_context(libname); }
void focus(OptUnit *local_unit) { the_local_unit = local_unit; the_local_scope = local_unit->get_symbol_table(); OneNote<long> note = get_note(local_unit, k_vr_count); the_vr_count = is_null(note) ? 0 : note.get_value(); }
void BacklinksNoteAddin::on_open_note(const Glib::VariantBase & param) { Glib::ustring uri = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(param).get(); gnote::NoteBase::Ptr note = get_note()->manager().find_by_uri(uri); if(note) { gnote::MainWindow::present_in_new_window(static_pointer_cast<gnote::Note>(note), gnote::Preferences::obj().get_schema_settings(gnote::Preferences::SCHEMA_GNOTE)-> get_boolean(gnote::Preferences::ENABLE_CLOSE_NOTE_ON_ESCAPE)); } }
void TableofcontentsNoteAddin::get_tableofcontents_menu_items(std::list<TableofcontentsMenuItem*> & items) //go through the note text, and list all lines tagged as heading, //and for each heading, create a new TableofcontentsMenuItem. { TableofcontentsMenuItem *item = NULL; std::vector<TocItem> toc_items; get_toc_items(toc_items); if(toc_items.size()) { //If we have at least one heading //we also insert an entry linked to the Note's title: item = manage(new TableofcontentsMenuItem(get_note(), get_note()->get_title(), Heading::Title, 0)); items.push_back(item); } for(auto & toc_item : toc_items) { item = manage(new TableofcontentsMenuItem(get_note(), toc_item.heading, toc_item.heading_level, toc_item.heading_position)); items.push_back(item); } }
void NotebookNoteAddin::on_note_opened () { if(!m_menu) { m_menu = manage(new Gtk::Menu()); m_menu->show_all(); } if(!m_toolButton) { initialize_tool_button(); update_button_sensitivity(get_note()->contains_tag(get_template_tag())); } }
/** * Parse notes */ void note() { struct note_t note; note_init(¬e); note.note = get_note(); note.octave = (int)abcNoteOctave(scn); /* Convert durations from ABC format to a simpler one (1/2^x) -> (1/x) */ note.duration = (int)pow(2, abcNoteDuration(scn) + 1); note_write(¬e); }