Simplified grouping by advancing/declining

master
Michael Dvorkin 11 years ago
parent fd1e3b9089
commit af77896323
  1. 4
      column_editor.go
  2. 3
      mop/mop.go
  3. 18
      profile.go
  4. 20
      yahoo_quotes.go

@ -72,9 +72,7 @@ func (self *ColumnEditor) select_right_column() *ColumnEditor {
//-----------------------------------------------------------------------------
func (self *ColumnEditor) execute() *ColumnEditor {
if updated,_ := self.quotes.UpdateSortOrder(); updated {
self.screen.Draw(self.quotes)
}
self.screen.Draw(self.quotes.Reorder())
return self
}

@ -58,8 +58,7 @@ loop:
} else if event.Ch == 'o' || event.Ch == 'O' {
column_editor = new(mop.ColumnEditor).Initialize(screen, quotes)
} else if event.Ch == 'g' || event.Ch == 'G' {
profile.Regroup()
screen.Draw(quotes)
screen.Draw(quotes.Regroup())
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' {
showing_help = true
screen.Clear().Draw(help)

@ -56,12 +56,6 @@ func (self *Profile) ListOfTickers() string {
return strings.Join(self.Tickers, `+`)
}
//-----------------------------------------------------------------------------
func (self *Profile) Regroup() error {
self.Grouped = !self.Grouped
return self.Save()
}
//-----------------------------------------------------------------------------
func (self *Profile) AddTickers(tickers []string) (added int, err error) {
added = 0
@ -98,15 +92,19 @@ func (self *Profile) RemoveTickers(tickers []string) (removed int, err error) {
}
//-----------------------------------------------------------------------------
func (self *Profile) UpdateSortOrder() (updated bool, err error) {
func (self *Profile) Reorder() error {
if self.selected_column == self.SortColumn {
self.Ascending = !self.Ascending
} else {
self.SortColumn = self.selected_column
}
err = self.Save()
updated = (err == nil)
return
return self.Save()
}
//-----------------------------------------------------------------------------
func (self *Profile) Regroup() error {
self.Grouped = !self.Grouped
return self.Save()
}
// private

@ -109,7 +109,7 @@ func (self *Quotes) Format() string {
//-----------------------------------------------------------------------------
func (self *Quotes) AddTickers(tickers []string) (added int, err error) {
if added, err = self.profile.AddTickers(tickers); added > 0 {
if added, err = self.profile.AddTickers(tickers); err == nil && added > 0 {
self.stocks = nil // Force fetch.
}
return
@ -117,18 +117,28 @@ func (self *Quotes) AddTickers(tickers []string) (added int, err error) {
//-----------------------------------------------------------------------------
func (self *Quotes) RemoveTickers(tickers []string) (removed int, err error) {
if removed, err = self.profile.RemoveTickers(tickers); removed > 0 {
if removed, err = self.profile.RemoveTickers(tickers); err == nil && removed > 0 {
self.stocks = nil // Force fetch.
}
return
}
//-----------------------------------------------------------------------------
func (self *Quotes) UpdateSortOrder() (updated bool, err error) {
if updated, err = self.profile.UpdateSortOrder(); updated {
func (self *Quotes) Reorder() *Quotes {
if self.profile.Reorder() == nil {
self.stocks = nil // Force fetch.
}
return
return self
}
//-----------------------------------------------------------------------------
func (self *Quotes) Regroup() *Quotes {
if self.profile.Regroup() == nil {
self.stocks = nil // Force fetch.
}
return self
}
//-----------------------------------------------------------------------------

Loading…
Cancel
Save