summaryrefslogtreecommitdiffstats
path: root/drivers/memstick
AgeCommit message (Expand)Author
2014-06-23drivers/memstick/host/rtsx_pci_ms.c: add cancel_work when remove driverMicky Ching
2014-04-28memstick: Add realtek USB memstick host driverRoger Tseng
2014-01-23drivers/memstick/host/rtsx_pci_ms.c: fix ms card data transfer bugMicky Ching
2013-11-15tree-wide: use reinit_completion instead of INIT_COMPLETIONWolfram Sang
2013-11-15drivers/memstick/core/ms_block.c: fix spelling of MSB_RP_RECIVE_STATUS_REGAndrew Morton
2013-11-13drivers/memstick/core/ms_block.c: fix unreachable state in h_msb_read_page()Roger Tseng
2013-11-13drivers/memstick/core/mspro_block.c: fix attributes array allocationMichal Nazarewicz
2013-10-16memstick: convert bus code to use dev_groupsGreg Kroah-Hartman
2013-09-11memstick: add support for legacy memorysticksMaxim Levitsky
2013-09-11drivers/memstick/host/rtsx_pci_ms.c: remove unnecessary platform_set_drvdata()Jingoo Han
2013-08-30mmc: memstick: rtsx: Modify copyright commentsWei WANG
2013-07-03drivers/memstick/host/r592.c: convert to module_pci_driverLibo Chen
2013-07-03drivers/memstick/host/jmb38x_ms: convert to module_pci_driverLibo Chen
2013-05-07block_device_operations->release() should return voidAl Viro
2013-04-30drivers/memstick/host/r592.c: make r592_pm_ops staticJingoo Han
2013-02-27memstick: move the dereference below the NULL testWei Yongjun
2013-02-27memstick: convert to idr_alloc()Tejun Heo
2013-02-24Merge tag 'mfd-3.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/...Linus Torvalds
2013-02-14mfd: rtsx: Fix issue that booting OS with SD card insertedWei WANG
2013-01-21drivers/memstick: remove depends on CONFIG_EXPERIMENTALKees Cook
2013-01-21drivers/memstick/host: remove depends on CONFIG_EXPERIMENTALKees Cook
2012-11-15drivers/memstick: Add realtek pcie memstick host driverWei WANG
2012-03-20memstick: remove the second argument of k[un]map_atomic()Cong Wang
2012-01-13module_param: make bool parameters really bool (drivers & misc)Rusty Russell
2011-10-31drivers/memstick: Add module.h to the prev. implicit modular usersPaul Gortmaker
2011-03-31Fix common misspellingsLucas De Marchi
2011-03-28memstick: make enable_dma less generic in r592Stephen Rothwell
2011-03-25memstick: add driver for Ricoh R5C592 card readerMaxim Levitsky
2011-03-17memstick: change to new flag variablematt mooney
2011-02-16workqueue, freezer: unify spelling of 'freeze' + 'able' to 'freezable'Tejun Heo
2011-01-13memstick: factor out transfer initiating functionality in mspro_block.cAlex Dubov
2011-01-13memstick: remove mspro_block_mutexAlex Dubov
2011-01-13memstick: avert possible race condition between idr_pre_get and idr_get_newAlex Dubov
2011-01-13memstick: add support for JMicron JMB 385 and 390 controllersTakashi Iwai
2011-01-13memstick: set PMOS values propery for JMicron 38x controllersTakashi Iwai
2011-01-13memstick: fix setup for JMicron 38x controllersTakashi Iwai
2011-01-13memstick: core: fix device_register() error handlingVasiliy Kulikov
2010-10-05block: autoconvert trivial BKL users to private mutexArnd Bergmann
2010-08-12memstick: fix hangs on unexpected device removal in mspro_blkMaxim Levitsky
2010-08-12memstick: init sysfs attributesMaxim Levitsky
2010-08-07block: push down BKL into .open and .releaseArnd Bergmann
2010-08-07block: remove wrappers for request type/flagsChristoph Hellwig
2010-03-30include cleanup: Update gfp.h and slab.h includes to prepare for breaking imp...Tejun Heo
2010-02-26block: Consolidate phys_segment and hw_segment limitsMartin K. Petersen
2010-02-26block: Rename blk_queue_max_sectors to blk_queue_max_hw_sectorsMartin K. Petersen
2009-09-24memstick: move dev_dbgJiri Slaby
2009-09-22const: make block_device_operations constAlexey Dobriyan
2009-05-22block: Do away with the notion of hardsect_sizeMartin K. Petersen
2009-05-11block: implement and enforce request peek/start/fetchTejun Heo
2009-05-11block: convert to dequeueing model (easy ones)Tejun Heo
lor: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package controllers

import (
	"errors"

	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

// Embed this into your list controller to get some convenience methods for
// ensuring a single item is selected, etc.

type ListControllerTrait[T comparable] struct {
	c                *ControllerCommon
	context          types.IListContext
	getSelectedItem  func() T
	getSelectedItems func() ([]T, int, int)
}

func NewListControllerTrait[T comparable](
	c *ControllerCommon,
	context types.IListContext,
	getSelected func() T,
	getSelectedItems func() ([]T, int, int),
) *ListControllerTrait[T] {
	return &ListControllerTrait[T]{
		c:                c,
		context:          context,
		getSelectedItem:  getSelected,
		getSelectedItems: getSelectedItems,
	}
}

// Convenience function for combining multiple disabledReason callbacks.
// The first callback to return a disabled reason will be the one returned.
func (self *ListControllerTrait[T]) require(callbacks ...func() *types.DisabledReason) func() *types.DisabledReason {
	return func() *types.DisabledReason {
		for _, callback := range callbacks {
			if disabledReason := callback(); disabledReason != nil {
				return disabledReason
			}
		}

		return nil
	}
}

// Convenience function for enforcing that a single item is selected.
// Also takes callbacks for additional disabled reasons, and passes the selected
// item into each one.
func (self *ListControllerTrait[T]) singleItemSelected(callbacks ...func(T) *types.DisabledReason) func() *types.DisabledReason {
	return func() *types.DisabledReason {
		if self.context.GetList().AreMultipleItemsSelected() {
			return &types.DisabledReason{Text: self.c.Tr.RangeSelectNotSupported}
		}

		var zeroValue T
		item := self.getSelectedItem()
		if item == zeroValue {
			return &types.DisabledReason{Text: self.c.Tr.NoItemSelected}
		}

		for _, callback := range callbacks {
			if reason := callback(item); reason != nil {
				return reason
			}
		}

		return nil
	}
}

// Ensures that at least one item is selected.
func (self *ListControllerTrait[T]) itemRangeSelected(callbacks ...func([]T, int, int) *types.DisabledReason) func() *types.DisabledReason {
	return func() *types.DisabledReason {
		items, startIdx, endIdx := self.getSelectedItems()
		if len(items) == 0 {
			return &types.DisabledReason{Text: self.c.Tr.NoItemSelected}
		}

		for _, callback := range callbacks {
			if reason := callback(items, startIdx, endIdx); reason != nil {
				return reason
			}
		}

		return nil
	}
}

func (self *ListControllerTrait[T]) itemsSelected(callbacks ...func([]T) *types.DisabledReason) func() *types.DisabledReason { //nolint:unused
	return func() *types.DisabledReason {
		items, _, _ := self.getSelectedItems()
		if len(items) == 0 {
			return &types.DisabledReason{Text: self.c.Tr.NoItemSelected}
		}

		for _, callback := range callbacks {
			if reason := callback(items); reason != nil {
				return reason
			}
		}

		return nil
	}
}

// Passes the selected item to the callback. Used for handler functions.
func (self *ListControllerTrait[T]) withItem(callback func(T) error) func() error {
	return func() error {
		var zeroValue T
		commit := self.getSelectedItem()
		if commit == zeroValue {
			return errors.New(self.c.Tr.NoItemSelected)
		}

		return callback(commit)
	}
}

func (self *ListControllerTrait[T]) withItems(callback func([]T) error) func() error {
	return func() error {
		items, _, _ := self.getSelectedItems()
		if len(items) == 0 {
			return errors.New(self.c.Tr.NoItemSelected)
		}

		return callback(items)
	}
}

// like withItems but also passes the start and end index of the selection
func (self *ListControllerTrait[T]) withItemsRange(callback func([]T, int, int) error) func() error {
	return func() error {
		items, startIdx, endIdx := self.getSelectedItems()
		if len(items) == 0 {
			return errors.New(self.c.Tr.NoItemSelected)
		}

		return callback(items, startIdx, endIdx)
	}
}

// Like withItem, but doesn't show an error message if no item is selected.
// Use this for click actions (it's a no-op to click empty space)
func (self *ListControllerTrait[T]) withItemGraceful(callback func(T) error) func() error {
	return func() error {
		var zeroValue T
		commit := self.getSelectedItem()
		if commit == zeroValue {
			return nil
		}

		return callback(commit)
	}
}

// All controllers must implement this method so we're defining it here for convenience
func (self *ListControllerTrait[T]) Context() types.Context {
	return self.context
}