コード例 #1
0
func (window *GhQueuedHighlightsWindow) build() {
	window.SetTitle("Queued Highlights")
	window.bindKeys()

	scrolledWindow := gtk.ScrolledWindow(nil, nil)
	scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	treeView := gtk.TreeView()
	scrolledWindow.Add(treeView)

	store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_DOUBLE, glib.G_TYPE_STRING, glib.G_TYPE_STRING)
	treeView.SetModel(store)

	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Book", gtk.CellRendererText(), "text", 0))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Content", gtk.CellRendererText(), "text", 1))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Position", gtk.CellRendererText(), "text", 2))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Timestamp", gtk.CellRendererText(), "text", 3))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Comment", gtk.CellRendererText(), "text", 4))

	readings := models.Readings()
	highlights := models.Highlights()
	for _, highlight := range highlights.Items {
		var iter gtk.GtkTreeIter
		store.Append(&iter)

		reading := readings.FindByReadmillId(highlight.ReadingReadmillId)
		position := highlight.Position * 100
		timestamp := highlight.Timestamp.Format(time.Stamp)

		store.Set(&iter, reading.Title, highlight.Content, position, timestamp, highlight.Comment)
	}

	window.Add(scrolledWindow)
	window.SetSizeRequest(600, 400)
}
コード例 #2
0
ファイル: sync.go プロジェクト: chdorner/ghighlighter
func syncHighlights(accessToken string) {
	highlights := models.Highlights()

	tmpItems := make([]models.GhHighlight, len(highlights.Items))
	copy(tmpItems, highlights.Items)

	for _, highlight := range tmpItems {
		var highlightComment *readmillhighlights.HighlightComment
		if highlight.Comment != "" {
			highlightComment = &readmillhighlights.HighlightComment{highlight.Comment}
		}

		readmillHighlight := readmillhighlights.Highlight{highlight.Content,
			highlight.Position, highlight.Timestamp, readmillhighlights.HighlightLocators{}}

		success := readmillhighlights.PostHighlight(readmillHighlight, highlightComment, highlight.ReadingReadmillId, accessToken)

		if success {
			highlights.Delete(highlight)
		}
	}
}
コード例 #3
0
ファイル: main_window.go プロジェクト: chdorner/ghighlighter
func (window *GhMainWindow) build() {
	window.SetTitle("ghighlights")
	window.bindKeys()
	window.Connect("destroy", gtk.MainQuit)

	mainVBox := gtk.VBox(false, 1)

	menubar := window.buildMenuBar()
	mainVBox.PackStart(menubar, false, false, 0)

	scrolledTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	textView := gtkext.TextViewWithPlaceholder("Highlight")
	textView.SetSizeRequest(600, 100)
	textView.SetWrapMode(gtk.GTK_WRAP_WORD)
	textView.SetAcceptsTab(false)
	scrolledTextViewWindow.Add(textView)

	scrolledTextViewWindow.SetSizeRequest(600, 100)
	mainVBox.Add(scrolledTextViewWindow)

	scrolledCommentTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledCommentTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	commentTextView := gtkext.TextViewWithPlaceholder("Comment")
	commentTextView.SetSizeRequest(600, 40)
	commentTextView.SetWrapMode(gtk.GTK_WRAP_WORD)
	commentTextView.SetAcceptsTab(false)
	scrolledCommentTextViewWindow.Add(commentTextView)

	scrolledCommentTextViewWindow.SetSizeRequest(600, 40)
	mainVBox.Add(scrolledCommentTextViewWindow)

	readingHBox := gtk.HBox(false, 10)
	pageNumberEntry := gtk.Entry()
	pageTotalEntry := gtk.Entry()

	readingsComboBox := gtk.ComboBoxText()
	readings := models.Readings()
	for _, reading := range readings.Items {
		readingsComboBox.AppendText(reading.Title)
	}
	readingsComboBox.SetActive(0)
	readingsComboBox.Connect("changed", func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		pageNumberEntry.SetText("0")
		pageTotalEntry.SetText(strconv.Itoa(reading.TotalPages))
	})
	align := gtk.Alignment(1, 1, 1, 0)
	align.Add(readingsComboBox)
	readingHBox.Add(align)

	pageHBox := gtk.HBox(false, 1)
	pageHBox.Add(gtk.Label("Page"))

	pageNumberEntry.SetAlignment(1)
	pageNumberEntry.SetWidthChars(4)
	pageNumberEntry.SetText("0")
	pageHBox.Add(pageNumberEntry)

	pageHBox.Add(gtk.Label("of"))

	pageTotalEntry.SetAlignment(1)
	pageTotalEntry.SetWidthChars(4)
	if len(readings.Items) > 0 {
		pageTotalEntry.SetText(strconv.Itoa(readings.Items[0].TotalPages))
	}
	pageHBox.Add(pageTotalEntry)

	pageBoxAlignment := gtk.Alignment(0, 0, 0, 0)
	pageBoxAlignment.Add(pageHBox)
	readingHBox.Add(pageBoxAlignment)
	mainVBox.Add(readingHBox)

	addHighlightButton := gtk.ButtonWithLabel("Add highlight")
	window.highlights = models.Highlights()
	addHighlightButton.Clicked(func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		readingId := reading.ReadmillId

		content := textView.GetStrippedText()

		comment := commentTextView.GetStrippedText()

		pageNumber, _ := strconv.Atoi(pageNumberEntry.GetText())
		pageTotal, _ := strconv.Atoi(pageTotalEntry.GetText())
		position := float32(pageNumber) / float32(pageTotal)

		highlight := models.GhHighlight{content, readingId, position, time.Now(), comment}
		window.highlights.Add(highlight)

		readings.UpdateTotalPages(pageTotal, reading)

		textView.DeleteText()
		commentTextView.DeleteText()
	})
	readingHBox.PackEnd(addHighlightButton, false, false, 0)

	window.Add(mainVBox)
	return
}