add a __tostring method to every object (#1534)
* added a stupid __tostring to every object * moved every __tostring to just after the :extend() call --------- Co-authored-by: Adam <adamdharrison@gmail.com> (cherry picked from commit 880e7f1fa1521cdf176f44627a27c901e187058e)
This commit is contained in:
@@ -10,6 +10,8 @@ local View = require "core.view"
|
|||||||
---@field super core.doc
|
---@field super core.doc
|
||||||
local SingleLineDoc = Doc:extend()
|
local SingleLineDoc = Doc:extend()
|
||||||
|
|
||||||
|
function SingleLineDoc:__tostring() return "SingleLineDoc" end
|
||||||
|
|
||||||
function SingleLineDoc:insert(line, col, text)
|
function SingleLineDoc:insert(line, col, text)
|
||||||
SingleLineDoc.super.insert(self, line, col, text:gsub("\n", ""))
|
SingleLineDoc.super.insert(self, line, col, text:gsub("\n", ""))
|
||||||
end
|
end
|
||||||
@@ -18,6 +20,8 @@ end
|
|||||||
---@field super core.docview
|
---@field super core.docview
|
||||||
local CommandView = DocView:extend()
|
local CommandView = DocView:extend()
|
||||||
|
|
||||||
|
function CommandView:__tostring() return "CommandView" end
|
||||||
|
|
||||||
CommandView.context = "application"
|
CommandView.context = "application"
|
||||||
|
|
||||||
local max_suggestions = 10
|
local max_suggestions = 10
|
||||||
@@ -391,5 +395,4 @@ function CommandView:draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return CommandView
|
return CommandView
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ local DIVIDER = {}
|
|||||||
---@field current_scale number
|
---@field current_scale number
|
||||||
local ContextMenu = Object:extend()
|
local ContextMenu = Object:extend()
|
||||||
|
|
||||||
|
function ContextMenu:__tostring() return "ContextMenu" end
|
||||||
|
|
||||||
---A unique value representing the divider in a context menu.
|
---A unique value representing the divider in a context menu.
|
||||||
ContextMenu.DIVIDER = DIVIDER
|
ContextMenu.DIVIDER = DIVIDER
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ local Object = require "core.object"
|
|||||||
|
|
||||||
local Highlighter = Object:extend()
|
local Highlighter = Object:extend()
|
||||||
|
|
||||||
|
function Highlighter:__tostring() return "Highlighter" end
|
||||||
|
|
||||||
function Highlighter:new(doc)
|
function Highlighter:new(doc)
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
@@ -126,5 +127,4 @@ function Highlighter:each_token(idx)
|
|||||||
return tokenizer.each_token(self:get_line(idx).tokens)
|
return tokenizer.each_token(self:get_line(idx).tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return Highlighter
|
return Highlighter
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local common = require "core.common"
|
|||||||
---@class core.doc : core.object
|
---@class core.doc : core.object
|
||||||
local Doc = Object:extend()
|
local Doc = Object:extend()
|
||||||
|
|
||||||
|
function Doc:__tostring() return "Doc" end
|
||||||
|
|
||||||
local function split_lines(text)
|
local function split_lines(text)
|
||||||
local res = {}
|
local res = {}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local View = require "core.view"
|
|||||||
---@field super core.view
|
---@field super core.view
|
||||||
local DocView = View:extend()
|
local DocView = View:extend()
|
||||||
|
|
||||||
|
function DocView:__tostring() return "DocView" end
|
||||||
|
|
||||||
DocView.context = "session"
|
DocView.context = "session"
|
||||||
|
|
||||||
local function move_to_line_offset(dv, line, col, offset)
|
local function move_to_line_offset(dv, line, col, offset)
|
||||||
@@ -591,5 +593,4 @@ function DocView:draw()
|
|||||||
self:draw_scrollbar()
|
self:draw_scrollbar()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return DocView
|
return DocView
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ local View = require "core.view"
|
|||||||
---@field super core.view
|
---@field super core.view
|
||||||
local EmptyView = View:extend()
|
local EmptyView = View:extend()
|
||||||
|
|
||||||
|
function EmptyView:__tostring() return "EmptyView" end
|
||||||
|
|
||||||
function EmptyView:get_name()
|
function EmptyView:get_name()
|
||||||
return "Get Started"
|
return "Get Started"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ local function get_item_height(item)
|
|||||||
return h
|
return h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local LogView = View:extend()
|
local LogView = View:extend()
|
||||||
|
|
||||||
|
function LogView:__tostring() return "LogView" end
|
||||||
|
|
||||||
LogView.context = "session"
|
LogView.context = "session"
|
||||||
|
|
||||||
|
|
||||||
@@ -222,5 +223,4 @@ function LogView:draw()
|
|||||||
LogView.super.draw_scrollbar(self)
|
LogView.super.draw_scrollbar(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return LogView
|
return LogView
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ local noop = function() end
|
|||||||
---@field super core.view
|
---@field super core.view
|
||||||
local NagView = View:extend()
|
local NagView = View:extend()
|
||||||
|
|
||||||
|
function NagView:__tostring() return "NagView" end
|
||||||
|
|
||||||
function NagView:new()
|
function NagView:new()
|
||||||
NagView.super.new(self)
|
NagView.super.new(self)
|
||||||
self.size.y = 0
|
self.size.y = 0
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ local View = require "core.view"
|
|||||||
---@class core.node : core.object
|
---@class core.node : core.object
|
||||||
local Node = Object:extend()
|
local Node = Object:extend()
|
||||||
|
|
||||||
|
function Node:__tostring() return "Node" end
|
||||||
|
|
||||||
function Node:new(type)
|
function Node:new(type)
|
||||||
self.type = type or "leaf"
|
self.type = type or "leaf"
|
||||||
self.position = { x = 0, y = 0 }
|
self.position = { x = 0, y = 0 }
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local DocView = require "core.docview"
|
|||||||
---@field mouse core.view.position
|
---@field mouse core.view.position
|
||||||
local RootView = View:extend()
|
local RootView = View:extend()
|
||||||
|
|
||||||
|
function RootView:__tostring() return "RootView" end
|
||||||
|
|
||||||
function RootView:new()
|
function RootView:new()
|
||||||
RootView.super.new(self)
|
RootView.super.new(self)
|
||||||
self.root_node = Node()
|
self.root_node = Node()
|
||||||
@@ -494,5 +496,4 @@ function RootView:draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return RootView
|
return RootView
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ local Object = require "core.object"
|
|||||||
---@class core.scrollbar : core.object
|
---@class core.scrollbar : core.object
|
||||||
local Scrollbar = Object:extend()
|
local Scrollbar = Object:extend()
|
||||||
|
|
||||||
|
function Scrollbar:__tostring() return "Scrollbar" end
|
||||||
|
|
||||||
---@class ScrollbarOptions
|
---@class ScrollbarOptions
|
||||||
---@field direction "v" | "h" @Vertical or Horizontal
|
---@field direction "v" | "h" @Vertical or Horizontal
|
||||||
---@field alignment "s" | "e" @Start or End (left to right, top to bottom)
|
---@field alignment "s" | "e" @Start or End (left to right, top to bottom)
|
||||||
@@ -339,5 +341,4 @@ function Scrollbar:draw()
|
|||||||
self:draw_thumb()
|
self:draw_thumb()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return Scrollbar
|
return Scrollbar
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ local Object = require "core.object"
|
|||||||
---@field hide_messages boolean
|
---@field hide_messages boolean
|
||||||
local StatusView = View:extend()
|
local StatusView = View:extend()
|
||||||
|
|
||||||
|
function StatusView:__tostring() return "StatusView" end
|
||||||
|
|
||||||
---Space separator
|
---Space separator
|
||||||
---@type string
|
---@type string
|
||||||
StatusView.separator = " "
|
StatusView.separator = " "
|
||||||
@@ -72,6 +74,8 @@ StatusView.separator2 = " | "
|
|||||||
---@field cached_item core.statusview.styledtext
|
---@field cached_item core.statusview.styledtext
|
||||||
local StatusViewItem = Object:extend()
|
local StatusViewItem = Object:extend()
|
||||||
|
|
||||||
|
function StatusViewItem:__tostring() return "StatusViewItem" end
|
||||||
|
|
||||||
---Available StatusViewItem options.
|
---Available StatusViewItem options.
|
||||||
---@class core.statusview.item.options : table
|
---@class core.statusview.item.options : table
|
||||||
---A condition to evaluate if the item should be displayed. If a string
|
---A condition to evaluate if the item should be displayed. If a string
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ local title_commands = {
|
|||||||
---@field super core.view
|
---@field super core.view
|
||||||
local TitleView = View:extend()
|
local TitleView = View:extend()
|
||||||
|
|
||||||
|
function TitleView:__tostring() return "TitleView" end
|
||||||
|
|
||||||
local function title_view_height()
|
local function title_view_height()
|
||||||
return style.font:get_height() + style.padding.y * 2
|
return style.font:get_height() + style.padding.y * 2
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-1
@@ -48,6 +48,8 @@ local Scrollbar = require "core.scrollbar"
|
|||||||
---@field current_scale number
|
---@field current_scale number
|
||||||
local View = Object:extend()
|
local View = Object:extend()
|
||||||
|
|
||||||
|
function View:__tostring() return "View" end
|
||||||
|
|
||||||
-- context can be "application" or "session". The instance of objects
|
-- context can be "application" or "session". The instance of objects
|
||||||
-- with context "session" will be closed when a project session is
|
-- with context "session" will be closed when a project session is
|
||||||
-- terminated. The context "application" is for functional UI elements.
|
-- terminated. The context "application" is for functional UI elements.
|
||||||
@@ -307,5 +309,4 @@ end
|
|||||||
function View:draw()
|
function View:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return View
|
return View
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ local View = require "core.view"
|
|||||||
---@class plugins.projectsearch.resultsview : core.view
|
---@class plugins.projectsearch.resultsview : core.view
|
||||||
local ResultsView = View:extend()
|
local ResultsView = View:extend()
|
||||||
|
|
||||||
|
function ResultsView:__tostring() return "ResultsView" end
|
||||||
|
|
||||||
ResultsView.context = "session"
|
ResultsView.context = "session"
|
||||||
|
|
||||||
function ResultsView:new(path, text, fn)
|
function ResultsView:new(path, text, fn)
|
||||||
@@ -237,7 +239,6 @@ function ResultsView:draw()
|
|||||||
self:draw_scrollbar()
|
self:draw_scrollbar()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param fn fun(line_text:string):...
|
---@param fn fun(line_text:string):...
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local View = require "core.view"
|
|||||||
|
|
||||||
local ToolbarView = View:extend()
|
local ToolbarView = View:extend()
|
||||||
|
|
||||||
|
function ToolbarView:__tostring() return "ToolbarView" end
|
||||||
|
|
||||||
function ToolbarView:new()
|
function ToolbarView:new()
|
||||||
ToolbarView.super.new(self)
|
ToolbarView.super.new(self)
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ end
|
|||||||
|
|
||||||
local TreeView = View:extend()
|
local TreeView = View:extend()
|
||||||
|
|
||||||
|
function TreeView:__tostring() return "TreeView" end
|
||||||
|
|
||||||
function TreeView:new()
|
function TreeView:new()
|
||||||
TreeView.super.new(self)
|
TreeView.super.new(self)
|
||||||
self.scrollable = true
|
self.scrollable = true
|
||||||
|
|||||||
Reference in New Issue
Block a user