about summary refs log tree commit diff stats
path: root/src/common.h
Commit message (Expand)AuthorAgeFilesLines
* use `g_mkdir_with_parents()` instead of home-baked solutionSteffen Jaeckel2022-03-141-2/+1
* Refactor call_externalWilliam Wennerström2020-12-111-2/+2
* Use get_expanded_path() in cmd_senfile()Michael Vetter2020-12-091-0/+1
* Move unique_filename_from_url functions to commonWilliam Wennerström2020-12-041-0/+2
* Refactor for threaded external executable for built-in download methodsWilliam Wennerström2020-12-031-0/+1
* Get rid of str_contains()Michael Vetter2020-11-021-1/+0
* Apply coding styleMichael Vetter2020-07-071-26/+25
* Revert "Apply coding style"Michael Vetter2020-07-071-25/+26
* Apply coding styleMichael Vetter2020-07-071-26/+25
* Get output and error streams from the command spawned by external_call()Pierre Mazière2020-06-031-1/+1
* Create call_external() helper functionMichael Vetter2020-05-201-0/+2
* Remove file_getline() declarationMichael Vetter2020-04-201-1/+0
* Put getting mentions in own functionMichael Vetter2020-02-201-0/+1
* Add vim modelineMichael Vetter2019-11-131-0/+1
* Move code from jid_random_resource() into own functionMichael Vetter2019-10-161-0/+2
* Update copyright to include 2019Michael Vetter2019-01-221-1/+1
* Merge pull request #1011 from jubalh/sha1Michael Vetter2018-09-191-2/+0
|\
| * Move p_sha1_hash() to stanza.cMichael Vetter2018-09-061-2/+0
* | use gio functions for file copyPhilip Flohr2018-09-061-1/+1
|/
* Move ID generation to xmpp folderMichael Vetter2018-08-301-1/+0
* Use uuid in create_unique_id instead of counterMichael Vetter2018-08-141-1/+0
* Update copyrightJames Booth2018-01-211-1/+1
* Update Glib dependency to 2.40James Booth2017-03-251-20/+0
* Allow installing plugins from directoryJames Booth2017-02-051-0/+4
* Update CopyrightJames Booth2017-01-281-1/+1
* Move window functions to window_list.cJames Booth2016-07-241-3/+1
* Move resource conversionsJames Booth2016-07-241-6/+1
* Add config/files.cJames Booth2016-07-241-2/+0
* Update GPL link in headersJames Booth2016-07-241-1/+1
* Add /plugins install commandJames Booth2016-07-121-0/+1
* Added whole word matches for room mentionJames Booth2016-04-071-1/+2
* Added prof_strstr functionJames Booth2016-04-031-1/+2
* Updated copyrightJames Booth2016-02-141-1/+1
* Applied coding style to src/James Booth2015-10-261-2/+1
* Use consistent style for pointersMichael Vetter2015-10-211-13/+13
* Create is_notify_enabled functionMichael Vetter2015-10-121-0/+1
* Fixed OTR decryption checkJames Booth2015-08-271-1/+1
* Added str_contains_str to commonJames Booth2015-08-261-0/+1
* I removed ncurses header dependencies, removed unused codeJames Booth2015-06-151-7/+0
* Added more connect testsJames Booth2015-05-241-0/+1
* Moved _strtoi to common, strtoi_rangeJames Booth2015-03-161-0/+1
* Merge branch 'master' into readlineJames Booth2015-02-111-1/+1
|\
| * Updated copyrightJames Booth2015-02-101-1/+1
* | Merge branch 'master' into readlineJames Booth2015-02-081-0/+1
|\|
| * Moved quote stripper to common, added testsJames Booth2015-02-081-0/+1
* | Refactor inputwin.cJames Booth2015-01-181-0/+8
|/
* Added utf8_display_lenJames Booth2015-01-171-0/+1
* Simplified autocompleters and command historyJames Booth2015-01-161-1/+1
* fgets: buffer sizePeter Vilim2015-01-071-0/+5
* Follow symlinks for profrc and accounts filesJames Booth2014-10-261-0/+2
">=None, fm=None, settings=None): from ranger.gui.ui import UI if env is not None: self.env = env if fm is not None: self.fm = fm if settings is not None: self.settings = settings self.need_redraw = True self.focused = False self.visible = True self.x = 0 self.y = 0 self.wid = 0 self.hei = 0 self.paryx = (0, 0) self.parent = None self._old_visible = self.visible if win is not None: if isinstance(self, UI): self.win = win else: self.win = win.derwin(1, 1, 0, 0) def __nonzero__(self): """Always True""" return True def __contains__(self, item): """Is item inside the boundaries? item can be an iterable like [y, x] or an object with x and y methods. """ try: y, x = item.y, item.x except AttributeError: try: y, x = item except (ValueError, TypeError): return False return self.contains_point(y, x) def draw(self): """ Draw the object. Called on every main iteration if visible. Containers should call draw() on their contained objects here. Override this! """ def destroy(self): """Called when the object is destroyed. Override this! """ def contains_point(self, y, x): """ Test whether the point (with absolute coordinates) lies within the boundaries of this object. """ return (x >= self.x and x < self.x + self.wid) and \ (y >= self.y and y < self.y + self.hei) def click(self, event): """Called when a mouse key is pressed and self.focused is True. Override this! """ pass def press(self, key): """Called when a key is pressed and self.focused is True. Override this! """ pass def poke(self): """Called before drawing, even if invisible""" if self._old_visible != self.visible: self._old_visible = self.visible self.need_redraw = True if not self.visible: self.win.erase() def finalize(self): """Called after every displayable is done drawing. Override this! """ pass def resize(self, y, x, hei=None, wid=None): """Resize the widget""" do_move = False try: maxy, maxx = self.env.termsize except TypeError: pass else: if hei is None: hei = maxy - y if wid is None: wid = maxx - x if x < 0 or y < 0: raise ValueError("Starting point below zero!") #if wid < 1 or hei < 1: # raise OutOfBoundsException("WID and HEI must be >=1!") if x + wid > maxx and y + hei > maxy: raise ValueError("X and Y out of bounds!") if x + wid > maxx: raise ValueError("X out of bounds!") if y + hei > maxy: raise ValueError("Y out of bounds!") window_is_cleared = False if hei != self.hei or wid != self.wid: #log("resizing " + str(self)) self.win.erase() self.need_redraw = True window_is_cleared = True try: self.win.resize(hei, wid) except: # Not enough space for resizing... try: self.win.mvderwin(0, 0) do_move = True self.win.resize(hei, wid) except: pass #raise ValueError("Resizing Failed!") self.hei, self.wid = self.win.getmaxyx() if do_move or y != self.paryx[0] or x != self.paryx[1]: if not window_is_cleared: self.win.erase() self.need_redraw = True #log("moving " + str(self)) try: self.win.mvderwin(y, x) except: pass self.paryx = self.win.getparyx() self.y, self.x = self.paryx if self.parent: self.y += self.parent.y self.x += self.parent.x def __str__(self): return self.__class__.__name__ class DisplayableContainer(Displayable): """ DisplayableContainers are Displayables which contain other Displayables. This is also an abstract class. The methods draw, poke, finalize, click, press and destroy are extended here and will recursively call the function on all contained objects. New methods: add_child(object) -- add the object to the container. remove_child(object) -- remove the object from the container. New attributes: container -- a list with all contained objects (rw) """ def __init__(self, win, env=None, fm=None, settings=None): if env is not None: self.env = env if fm is not None: self.fm = fm if settings is not None: self.settings = settings self.container = [] Displayable.__init__(self, win) # ------------------------------------ extended or overidden methods def poke(self): """Recursively called on objects in container""" Displayable.poke(self) for displayable in self.container: displayable.poke() def draw(self): """Recursively called on visible objects in container""" for displayable in self.container: if self.need_redraw: displayable.need_redraw = True if displayable.visible: displayable.draw() self.need_redraw = False def finalize(self): """Recursively called on visible objects in container""" for displayable in self.container: if displayable.visible: displayable.finalize() def press(self, key): """Recursively called on objects in container""" focused_obj = self._get_focused_obj() if focused_obj: focused_obj.press(key) return True return False def click(self, event): """Recursively called on objects in container""" focused_obj = self._get_focused_obj() if focused_obj and focused_obj.click(event): return True for displayable in self.container: if event in displayable: if displayable.click(event): return True return False def destroy(self): """Recursively called on objects in container""" for displayable in self.container: displayable.destroy() # ----------------------------------------------- new methods def add_child(self, obj): """Add the objects to the container.""" if obj.parent: obj.parent.remove_child(obj) self.container.append(obj) obj.parent = self def remove_child(self, obj): """Remove the object from the container.""" try: container.remove(obj) except ValueError: pass else: obj.parent = None def _get_focused_obj(self): # Finds a focused displayable object in the container. for displayable in self.container: if displayable.focused: return displayable try: obj = displayable._get_focused_obj() except AttributeError: pass else: if obj is not None: return obj return None