Skip to content

Commit

Permalink
Removed workaround for crash on Linux after filetree editing (#425, #464
Browse files Browse the repository at this point in the history
).

This reverts the changes in a61c9e as it's been fixed in wxwidgets 3.1 and
simplifies the changes for #815.
  • Loading branch information
pkulchenko committed Oct 13, 2017
1 parent 1c9883a commit 39e956d
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/editor/filetree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,9 @@ local function treeSetConnectorsAndIcons(tree)

local empty = ""
local function renameItem(itemsrc, target)
local cache = type(itemsrc) == 'table' and itemsrc or nil
local isdir = not cache and tree:IsDirectory(itemsrc) or cache and cache.isdir or false
local isnew = not cache and tree:GetItemText(itemsrc) == empty or cache and cache.isnew or false
local source = cache and cache.fullname or tree:GetItemFullName(itemsrc)
local isdir = tree:IsDirectory(itemsrc)
local isnew = tree:GetItemText(itemsrc) == empty
local source = tree:GetItemFullName(itemsrc)
local fn = wx.wxFileName(target)

-- check if the target is the same as the source;
Expand Down Expand Up @@ -356,7 +355,7 @@ local function treeSetConnectorsAndIcons(tree)
end
end

refreshAncestors(cache and cache.parent or tree:GetItemParent(itemsrc))
refreshAncestors(tree:GetItemParent(itemsrc))
-- load file(s) into the same editor (if any); will also refresh the tree
if #docs > 0 then
for _, doc in ipairs(docs) do
Expand Down Expand Up @@ -768,23 +767,11 @@ local function treeSetConnectorsAndIcons(tree)
local target = MergeFullPath(tree:GetItemFullName(parent), label)
if cancelled or label == empty then refreshAncestors(parent)
elseif target then
-- normally, none of this caching would be needed as `renameItem`
-- would be called to check if the item can be renamed;
-- however, as it may open a dialog box, on Linux it's causing a crash
-- (caused by the same END_LABEL_EDIT even triggered one more time),
-- so to protect from that, `renameItem` is called from IDLE event.
-- Unfortunately, by that time, the filetree item (`itemsrc`) may
-- already have incorrect state (as it's removed from the tree),
-- so its properties need to be cached to be used from IDLE event.
local cache = {
isdir = tree:IsDirectory(itemsrc),
isnew = tree:GetItemText(itemsrc) == empty,
fullname = tree:GetItemFullName(itemsrc),
parent = parent,
}
ide:DoWhenIdle(function()
if not renameItem(cache, target) then refreshAncestors(parent) end
end)
-- wxwidgets v2.9.5 and earlier crashes when the IDE loses focus
-- during renaming a file that has a conflict with an exising one
-- (caused by the same END_LABEL_EDIT even triggered one more time).
if ide.osname == "Linux" and ide.wxver <= "2.9.5" then return end
if not renameItem(itemsrc, target) then refreshAncestors(parent) end
end
end)

Expand Down

0 comments on commit 39e956d

Please sign in to comment.